[Glade-devel] [patch, glade3] same project file passed more than once on cmd line



--=-Px7oJUB+pJ8EDotOTgOS
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

The patch attached fixes the (unlikely) case where the same file is
passed more than once on the command line, e.g.

glade-3 foo.glade2 foo.glade2

From the file selector we don't allow to have the same project opened
more than once.

While fixing this I took the chance to make glade_project_open_from_file
private to glade_project.c.
Some micro cleanups along the way.

If you don't like the patch, you probably want to fix a little leak that
is present in glade_project_open(): "path" is not freed on error.

ciao
        paolo

--=-Px7oJUB+pJ8EDotOTgOS
Content-Disposition: attachment; filename=same_project_cmd_line.patch
Content-Type: text/x-patch; name=same_project_cmd_line.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -rup gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog     2003-03-26 10:28:20.000000000 +0100
+++ glade3/ChangeLog    2003-03-27 20:38:13.000000000 +0100
@@ -1,3 +1,9 @@
+2003-03-27  Paolo Borelli
+
+       * src/glade-project.[ch]: make glade_project_open_from_file() static
+       and fix the callers. This fixes the (unlikely) case of passing the 
+       same file more than once on the command line.
+
 2003-03-25  Joaquin Cuenca Abela  <e98cuenc yahoo com>
 
        * src/glade-gtk.c: create a "Edit Menus..." button that... surprise!
diff -rup gnome2/glade3/src/glade-project.c glade3/src/glade-project.c
--- gnome2/glade3/src/glade-project.c   2003-03-15 15:36:43.000000000 +0100
+++ glade3/src/glade-project.c  2003-03-27 20:18:23.000000000 +0100
@@ -150,7 +150,7 @@ glade_project_destroy (GtkObject *object
 }
 
 static GladeProject *
-glade_project_check_previously_loaded (gchar *path)
+glade_project_check_previously_loaded (const gchar *path)
 {
        GladeProjectWindow *gpw;
        GladeProject *project;
@@ -163,7 +163,7 @@ glade_project_check_previously_loaded (g
                project = GLADE_PROJECT (list->data);
 
                if (project->path != NULL && !strcmp (project->path, path))
-                               return project;
+                       return project;
        }
 
        return NULL;
@@ -497,7 +497,7 @@ glade_project_write_widgets (const Glade
  * glade_project_write:
  * @project: 
  * 
- * Retrns the root node of a newly created xml representation of the project and its contents
+ * Returns the root node of a newly created xml representation of the project and its contents
  * 
  * Return Value: 
  **/
@@ -527,7 +527,7 @@ glade_project_write (GladeXmlContext *co
  **/
 static gboolean
 glade_project_save_to_file (GladeProject *project,
-                           const gchar * full_path)
+                           const gchar *full_path)
 {
        GladeXmlContext *context;
        GladeXmlNode *root;
@@ -555,7 +555,6 @@ glade_project_save_to_file (GladeProject
        return TRUE;
 }
 
-
 static GladeProject *
 glade_project_new_from_node (GladeXmlNode *node)
 {
@@ -584,7 +583,7 @@ glade_project_new_from_node (GladeXmlNod
        return project; 
 }
 
-GladeProject *
+static GladeProject *
 glade_project_open_from_file (const gchar *path)
 {
        GladeXmlContext *context;
@@ -699,41 +698,48 @@ glade_project_save_as (GladeProject *pro
 
 /**
  * glade_project_open:
- * @: 
+ * @path: 
  * 
- * Open a project. Launches a file selector
+ * Open a project. If @path is NULL launches a file selector
  * 
  * Return Value: TRUE on success false on error.
  **/
 gboolean
-glade_project_open (void)
+glade_project_open (const gchar *path)
 {
        GladeProjectWindow *gpw;
        GladeProject *project;
-       gchar *path;
-       
+       gchar *file_path = NULL;
+
        gpw = glade_project_window_get ();
-       path = glade_project_ui_get_path (_("Open ..."));
 
        if (!path)
+               file_path = glade_project_ui_get_path (_("Open ..."));
+       else
+               file_path = g_strdup (path);
+
+       /* If the user hit cancel, return */
+       if (!file_path)
                return FALSE;
 
        /* If the project is previously loaded, don't re-load */
        if ((project = glade_project_check_previously_loaded (path)) != NULL) {
                glade_project_window_set_project (gpw, project);
+               g_free (file_path);
                return TRUE;
        }
 
-       project = glade_project_open_from_file (path);
+       project = glade_project_open_from_file (file_path);
 
        if (!project) {
                glade_util_ui_warn (_("Could not open project."));
-               g_free (path);
+               g_free (file_path);
                return FALSE;
        }
 
        glade_project_window_add_project (gpw, project);
-       g_free (path);
+       g_free (file_path);
 
        return TRUE;
 }
+
diff -rup gnome2/glade3/src/glade-project.h glade3/src/glade-project.h
--- gnome2/glade3/src/glade-project.h   2002-04-23 19:13:30.000000000 +0200
+++ glade3/src/glade-project.h  2003-03-27 20:11:14.000000000 +0100
@@ -66,7 +66,6 @@ GladeProject * glade_project_new (gboole
 gboolean       glade_project_save (GladeProject *project);
 gboolean       glade_project_save_as (GladeProject *project);
 gboolean       glade_project_open ();
-GladeProject * glade_project_open_from_file (const gchar *path);
 
 
 /* Widget related stuff */
diff -rup gnome2/glade3/src/glade-project-window.c glade3/src/glade-project-window.c
--- gnome2/glade3/src/glade-project-window.c    2003-03-26 10:28:21.000000000 +0100
+++ glade3/src/glade-project-window.c   2003-03-27 20:15:36.000000000 +0100
@@ -61,7 +61,7 @@ static void gpw_about_cb (void) {}
 static void
 gpw_open_cb (void)
 {
-       glade_project_open ();
+       glade_project_open (NULL);
 }
 
 static void
diff -rup gnome2/glade3/src/main.c glade3/src/main.c
--- gnome2/glade3/src/main.c    2003-03-08 17:23:41.000000000 +0100
+++ glade3/src/main.c   2003-03-27 20:13:42.000000000 +0100
@@ -98,7 +98,6 @@ int
 main (int argc, char *argv[])
 {
        GladeProjectWindow *gpw;
-       GladeProject *project;
        poptContext popt_context;
        GList *files;
 
@@ -114,7 +113,7 @@ main (int argc, char *argv[])
        poptFreeContext (popt_context);
 
        gtk_init (&argc, &argv);
-       
+
        if (!glade_init ())
                return -1;
 
@@ -131,10 +130,10 @@ main (int argc, char *argv[])
 
        if (files) {
                for (; files != NULL; files = files->next) {
-                       project = glade_project_open_from_file (files->data);
-                       glade_project_window_add_project (gpw, project);
+                       glade_project_open (files->data);
                }
        } else {
+               GladeProject *project;
                project = glade_project_new (TRUE);
                glade_project_window_add_project (gpw, project);
        }
@@ -144,7 +143,6 @@ main (int argc, char *argv[])
        return 0;
 }
 
-
 static GList *
 parse_command_line (poptContext pctx)
 {

--=-Px7oJUB+pJ8EDotOTgOS--





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]