alexandervdm / gummi

Simple LaTeX editor
https://gummi.app
MIT License
750 stars 95 forks source link

Open/created projects are not properly closed and prevents opening or creating new ones. #165

Open neoh4x0r opened 2 years ago

neoh4x0r commented 2 years ago

Describe the bug When closing a project the project filename is never cleared.

This means that when a project is opened, and then closed. No new projects can be created or existing ones opened.

System: Debian 10 Buster / Gummi 0.8.2 (compiled from 8c82e69bc0fe3a8f14b906871654c3f22374c60f)

To Reproduce Steps to reproduce the behavior:

  1. Save a .tex file
  2. click Project -> Create Project
  3. Give the new project a filename (and click save)
  4. Click Project -> Close

Notice that you are now unable to open or create a new project.

here is a proposed patch to fix this problem

When on_menu_projclose_activate() fires and calls project_close() the project filename is never set to NULL.

The NULL state of the project filename is used by on_menu_project_activate() to determine which menuitems to show under the project menu.

This patch ensures that the project structure (GuProject) is properly reset (setting all members to NULL).

diff --git a/src/environment.c b/src/environment.c
index f260598..ccf5cd4 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -53,7 +53,7 @@ Gummi* gummi_init (GuMotion* mo, GuIOFunc* io, GuLatex* latex, GuBiblio* bib,
 }

 gboolean gummi_project_active (void) {
-    if (gummi->project->projfile) return TRUE;
+    if (gummi_get_projectfile()) return TRUE;
     return FALSE;
 }

@@ -61,6 +61,14 @@ gchar* gummi_get_projectfile (void) {
     return gummi->project->projfile;
 }

+void gummi_cear_projectfile (void) {
+    if (gummi_get_projectfile()) {
+       gummi->project->projfile = NULL;
+       gummi->project->rootfile = NULL;
+       gummi->project->nroffiles = 1;
+    }
+}
+
 GuEditor* gummi_new_environment (const gchar* filename) {
     GuEditor* ec = editor_new (gummi->motion);
     editor_fileinfo_update (ec, filename);
diff --git a/src/environment.h b/src/environment.h
index ec66213..757925a 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -81,6 +81,9 @@ GuEditor* gummi_new_environment (const gchar* filename);
  */

 gboolean gummi_project_active (void);
+gchar* gummi_get_projectfile (void);
+void gummi_cear_projectfile (void);
+

 GummiGui* gummi_get_gui (void);
 GuEditor* gummi_get_active_editor (void);
diff --git a/src/project.c b/src/project.c
index 62e556c..3868f83 100644
--- a/src/project.c
+++ b/src/project.c
@@ -37,6 +37,8 @@
 #include "gui/gui-project.h"
 #include "utils.h"

+
+
 // TODO needs refactor, non gui classes should not 
 // directly access gui and gummi structure
 extern GummiGui* gui;
@@ -117,6 +119,7 @@ gboolean project_close (void) {
         tabmanager_set_active_tab(0);
     motion_start_compile_thread(gummi->motion);

+    gummi_cear_projectfile();
     return TRUE;
 }