[Glade-devel] [patch, glade3] rework file selectors



--=-wsncJs4PMSYaRZmHf7AA
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

The patch attached reworks the way we dispaly file selectors, leading to
a nice simplification of the code (diffstat says +225 -300). Beside
after this patch, glade-project-ui.[ch] may be removed.

Note: the patch is diffed against cvs, but since it touches the menu
editor it will probably conflict with your local tree. It also conflicts
with the last patch I sent wich displayed flash messages on "Save".
If you like this patch and you want me to rediff it aginst something
else just let me know.

Since the patch isn't small: I'll briefly describe the changes:

- It uses the same method to display the various filesel (Open, Save,
Save as and Icon in the menu editor); to do this I have created
glade_util_file_selection_new in glade-util.c

- The various callers create a filesel with the above and connect a
callback to the ok button; once the filesel is closed it's destroyed.
(the icon filesel has been removed from the menu editor struct)

- I've moved the open/save file selectors directly in the open/save
callbacks in glade-project-window.c

- glade-project now only exposes glade_project_open and
glade_project_save and those have been simplyfied.

- glade-project-ui can at this point be removed (I don't know how to
actually remove them with a patch, I just deleted the code)

Here it seems to work, but keep in mind that since the patch is more
than 5 lines I probably screwed up somewher ;-)

ciao
        paolo

--=-wsncJs4PMSYaRZmHf7AA
Content-Disposition: attachment; filename=filesel.patch
Content-Type: text/x-patch; name=filesel.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog     2003-03-30 10:47:06.000000000 +0200
+++ glade3/ChangeLog    2003-04-01 20:43:58.000000000 +0200
@@ -1,3 +1,12 @@
+2003-04-1  Paolo Borelli
+
+       * src/glade-utils.[ch]: iplement glade_util_file_selection_new()
+       * src/glade-project-window.[ch]: use the above Open, Save, Save as.
+       * src/glade-project.[ch]: file selection moved to glade-project-window,
+       clean-ups and fixes.
+       * src/glade-project-ui.[ch]: is no more.
+       * src/glade-menu-editor.[ch]: adapt the icon file selector. 
+
 2003-03-29  Joaquin Cuenca Abela  <e98cuenc yahoo com>
 
        * src/glade-editor.c: Now we don't create a new "Edit Menus..." button
diff -upr gnome2/glade3/src/glade-menu-editor.c glade3/src/glade-menu-editor.c
--- gnome2/glade3/src/glade-menu-editor.c       2003-03-30 10:47:07.000000000 +0200
+++ glade3/src/glade-menu-editor.c      2003-04-01 20:43:58.000000000 +0200
@@ -62,6 +62,7 @@
 #include "glade-menu-editor.h"
 #include "glade-keys-dialog.h"
 #include "glade-project.h"
+#include "glade-utils.h"
 
 #define GladeMenuEditorIndexKey "glade-menu-editor-index-key"
 #define GladeMenuEditorStockIDKey "glade-menu-editor-stock-id"
@@ -164,8 +165,6 @@ static void on_entry_changed (GtkWidget 
                              gpointer user_data);
 static void on_icon_button_clicked (GtkWidget * button,
                                    gpointer user_data);
-static void on_icon_filesel_ok (GtkWidget * widget,
-                               GladeMenuEditor *menued);
 static void on_stock_item_entry_changed (GtkWidget * entry,
                                         gpointer user_data);
 static gboolean on_label_entry_key_press (GtkWidget * widget,
@@ -327,7 +326,6 @@ static void
 glade_menu_editor_init (GladeMenuEditor * menued)
 {
        menued->keys_dialog = NULL;
-       menued->filesel = NULL;
        menued->project = NULL;
        menued->menu = NULL;
        menued->updating_widgets = FALSE;
@@ -1185,11 +1183,6 @@ glade_menu_editor_destroy (GtkObject *ob
                menued->keys_dialog = NULL;
        }
 
-       if (menued->filesel) {
-               gtk_widget_destroy (menued->filesel);
-               menued->filesel = NULL;
-       }
-
        for (elem = menued->stock_items; elem; elem = elem->next)
                g_free (elem->data);
        g_slist_free (menued->stock_items);
@@ -1901,54 +1894,16 @@ on_delete_button_clicked (GtkWidget * wi
 /**************************************************************************
  * File Selection for selecting icon xpm files.
  **************************************************************************/
-static void
-on_icon_button_clicked (GtkWidget * widget,
-                       gpointer user_data)
-{
-       GladeMenuEditor *menued;
-       gchar *icon;
-
-       menued = GLADE_MENU_EDITOR (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
-
-       if (menued->filesel == NULL) {
-               menued->filesel = gtk_file_selection_new (_("Select icon"));
-               gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (menued->filesel)->ok_button),
-                                   "clicked", GTK_SIGNAL_FUNC (on_icon_filesel_ok),
-                                   menued);
-               gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (menued->filesel)->cancel_button),
-                                          "clicked",
-                                          GTK_SIGNAL_FUNC (glade_util_hide_window),
-                                          GTK_OBJECT (menued->filesel));
-               gtk_signal_connect (GTK_OBJECT (menued->filesel), "delete_event",
-                                   GTK_SIGNAL_FUNC (glade_util_hide_window_on_delete),
-                                   NULL);
-               gtk_signal_connect (GTK_OBJECT (menued->filesel), "key_press_event",
-                                   GTK_SIGNAL_FUNC (glade_util_check_key_is_esc),
-                                   GINT_TO_POINTER (GladeEscCloses));
-       }
-
-       icon = (gchar*) gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (menued->icon_widget)->entry));
-       gtk_file_selection_set_filename (GTK_FILE_SELECTION (menued->filesel), icon);
-  
-       if (GTK_IS_WINDOW (menued))
-               gtk_window_set_transient_for (GTK_WINDOW (menued->filesel),
-                                             GTK_WINDOW (menued));
-       gtk_widget_show (menued->filesel);
-       gdk_window_show (menued->filesel->window);
-       gdk_window_raise (menued->filesel->window);
-}
-
 
 static void
-on_icon_filesel_ok (GtkWidget * widget,
-                   GladeMenuEditor *menued)
+on_icon_filesel_ok (GtkWidget *widget, GladeMenuEditor *menued)
 {
        GtkWidget *filesel;
-       gchar *filename;
+       const gchar *filename;
        gint filename_len;
 
        filesel = gtk_widget_get_toplevel (widget);
-       filename = (gchar*) gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+       filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
 
        /* If the filename ends in '/' it means the user wants to reset the
           pixmap to NULL. */
@@ -1959,9 +1914,28 @@ on_icon_filesel_ok (GtkWidget * widget,
        set_entry_text (GTK_ENTRY (GTK_COMBO (menued->icon_widget)->entry),
                        filename);
 
-       glade_util_hide_window (menued->filesel);
+       gtk_widget_destroy (filesel);
 }
 
+static void
+on_icon_button_clicked (GtkWidget *widget, gpointer user_data)
+{
+       GladeMenuEditor *menued;
+       GtkWidget *filesel;
+       const gchar *icon;
+
+       menued = GLADE_MENU_EDITOR (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
+
+       filesel = glade_util_file_selection_new (_("Select icon"), GTK_WINDOW (menued));
+       g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
+                         "clicked", G_CALLBACK (on_icon_filesel_ok),
+                         menued);
+
+       icon = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (menued->icon_widget)->entry));
+       gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), icon);
+
+       gtk_widget_show (filesel);
+}
 
 /**************************************************************************
  * Utility functions
diff -upr gnome2/glade3/src/glade-menu-editor.h glade3/src/glade-menu-editor.h
--- gnome2/glade3/src/glade-menu-editor.h       2003-03-20 22:42:08.000000000 +0100
+++ glade3/src/glade-menu-editor.h      2003-04-01 20:43:58.000000000 +0200
@@ -93,9 +93,6 @@ struct _GladeMenuEditor
        /* This is our key selection dialog, used for selecting accelerator keys. */
        GtkWidget *keys_dialog;
 
-       /* This is our file selection dialog, used for selecting icons. */
-       GtkWidget *filesel;
-
        /* This is the menu widget we are editing and the project it is in. */
        GladeProject *project;
        GtkMenuShell *menu;
diff -upr gnome2/glade3/src/glade-project.c glade3/src/glade-project.c
--- gnome2/glade3/src/glade-project.c   2003-03-28 13:27:16.000000000 +0100
+++ glade3/src/glade-project.c  2003-04-01 20:55:54.000000000 +0200
@@ -28,12 +28,12 @@
 
 #include "glade.h"
 #include "glade-project.h"
-#include "glade-project-ui.h"
 #include "glade-project-window.h"
 #include "glade-widget.h"
 #include "glade-widget-class.h"
 #include "glade-xml-utils.h"
 #include "glade-widget.h"
+#include "glade-utils.h"
 
 static void glade_project_class_init (GladeProjectClass * klass);
 static void glade_project_init (GladeProject *project);
@@ -516,45 +516,6 @@ glade_project_write (GladeXmlContext *co
        return node;
 }
 
-/**
- * glade_project_save_to_file:
- * @project: 
- * @file_name: 
- * 
- * Save a project
- * 
- * Return Value: TRUE on success, FALSE otherwise
- **/
-static gboolean
-glade_project_save_to_file (GladeProject *project,
-                           const gchar *full_path)
-{
-       GladeXmlContext *context;
-       GladeXmlNode *root;
-       GladeXmlDoc *xml_doc;
-       gboolean ret;
-
-       xml_doc = glade_xml_doc_new ();
-       if (xml_doc == NULL) {
-               g_warning ("Could not create xml document\n");
-               return FALSE;
-       }
-       context = glade_xml_context_new (xml_doc, NULL);
-       root = glade_project_write (context, project);
-       glade_xml_context_destroy (context);
-       if (root == NULL)
-               return FALSE;
-
-       glade_xml_doc_set_root (xml_doc, root);
-       ret = glade_xml_doc_save (xml_doc, full_path);
-       glade_xml_doc_free (xml_doc);
-
-       if (ret < 0)
-               return FALSE;
-
-       return TRUE;
-}
-
 static GladeProject *
 glade_project_new_from_node (GladeXmlNode *node)
 {
@@ -579,7 +540,7 @@ glade_project_new_from_node (GladeXmlNod
                        return NULL;
        }
        project->widgets = g_list_reverse (project->widgets);
-       
+
        return project; 
 }
 
@@ -608,138 +569,94 @@ glade_project_open_from_file (const gcha
        return project;
 }
 
-
-/**
- * glade_project_save:
- * @project: 
- * 
- * Save the project, query the user for a project name if necessary
- * 
- * Return Value: TRUE if the project was saved, FALSE if the user cancelled
- *               the operation or an error was encountered while saving
- **/
-gboolean
-glade_project_save (GladeProject *project)
+static gboolean
+glade_project_save_to_file (GladeProject *project, const gchar *full_path)
 {
-       gchar *backup;
-
-       g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
-
-       backup = project->path;
-
-       if (project->path == NULL) {
-               g_free (project->name);
-               project->path = glade_project_ui_get_path (_("Save ..."));
-
-               /* If the user hit cancel, restore its previous name and return */
-               if (project->path == NULL) {
-                       project->path = backup;
-                       return FALSE;
-               }
-
-               project->name = g_path_get_basename (project->path);
-               g_free (backup);
-       }
+       GladeXmlContext *context;
+       GladeXmlNode *root;
+       GladeXmlDoc *xml_doc;
+       gboolean ret;
 
-       if (!glade_project_save_to_file (project, project->path)) {
-               glade_util_ui_warn (_("Invalid file name"));
-               g_free (project->path);
-               project->path = backup;
+       xml_doc = glade_xml_doc_new ();
+       if (xml_doc == NULL) {
+               g_warning ("Could not create xml document\n");
                return FALSE;
        }
-
-       glade_project_refresh_menu_item (project);
-
-       return TRUE;
-}
-
-
-/**
- * glade_project_save_as:
- * @project: 
- * 
- * Query the user for a new file name and save it.
- * 
- * Return Value: TRUE if the project was saved. FALSE on error.
- **/
-gboolean
-glade_project_save_as (GladeProject *project)
-{
-       gchar *backup;
-
-       g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
-
-       /* Keep the previous path */
-       backup = project->path;
-       project->path = glade_project_ui_get_path (_("Save as ..."));
-
-       /* If the user hit cancel, restore its previous name and return */
-       if (project->path == NULL) {
-               project->path = backup;
+       context = glade_xml_context_new (xml_doc, NULL);
+       root = glade_project_write (context, project);
+       glade_xml_context_destroy (context);
+       if (root == NULL)
                return FALSE;
-       }
 
-       /* On error, warn and restore its previous name and return */
-       if (!glade_project_save_to_file (project, project->path)) {
-               glade_util_ui_warn (_("Invalid file name"));
-               g_free (project->path);
-               project->path = backup;
+       glade_xml_doc_set_root (xml_doc, root);
+       ret = glade_xml_doc_save (xml_doc, full_path);
+       glade_xml_doc_free (xml_doc);
+
+       if (ret < 0)
                return FALSE;
-       }
 
-       /* Free the backup and return; */
+       g_free (project->path);
+       project->path = g_strdup_printf ("%s", full_path);
        g_free (project->name);
        project->name = g_path_get_basename (project->path);
-       glade_project_refresh_menu_item (project);
-       g_free (backup);
 
        return TRUE;
-}      
+}
 
 /**
  * glade_project_open:
  * @path: 
  * 
- * Open a project. If @path is NULL launches a file selector
- * 
- * Return Value: TRUE on success false on error.
+ * Open a project at the given path.
  **/
-gboolean
+void
 glade_project_open (const gchar *path)
 {
        GladeProjectWindow *gpw;
        GladeProject *project;
-       gchar *file_path = NULL;
-
-       gpw = glade_project_window_get ();
 
-       if (!path)
-               file_path = glade_project_ui_get_path (_("Open ..."));
-       else
-               file_path = g_strdup (path);
+       g_return_if_fail (path != NULL);
 
-       /* If the user hit cancel, return */
-       if (!file_path)
-               return FALSE;
+       gpw = glade_project_window_get ();
 
        /* 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;
+               return;
        }
 
-       project = glade_project_open_from_file (file_path);
-
+       project = glade_project_open_from_file (path);
        if (!project) {
                glade_util_ui_warn (_("Could not open project."));
-               g_free (file_path);
-               return FALSE;
+               return;
        }
 
        glade_project_window_add_project (gpw, project);
-       g_free (file_path);
+}
 
-       return TRUE;
+/**
+ * glade_project_save:
+ * @project:
+ * @path 
+ * 
+ * Save the project to the given path
+ **/
+void
+glade_project_save (GladeProject *project, const gchar *path)
+{
+       GladeProjectWindow *gpw;
+
+       g_return_if_fail (GLADE_IS_PROJECT (project));
+       g_return_if_fail (path != NULL);
+
+       gpw = glade_project_window_get ();
+
+       if (!glade_project_save_to_file (project, path)) {
+               glade_util_ui_warn (_("Invalid file name"));
+               return;
+       }
+
+       glade_project_refresh_menu_item (project);
+       glade_project_window_refresh_title (gpw);       
 }
 
Only in glade3/src: glade-project.c~
diff -upr gnome2/glade3/src/glade-project.h glade3/src/glade-project.h
--- gnome2/glade3/src/glade-project.h   2003-03-28 13:27:16.000000000 +0100
+++ glade3/src/glade-project.h  2003-04-01 20:43:58.000000000 +0200
@@ -63,9 +63,8 @@ GladeProject * glade_project_new (gboole
 
 
 /* Project operations */
-gboolean       glade_project_save (GladeProject *project);
-gboolean       glade_project_save_as (GladeProject *project);
-gboolean       glade_project_open ();
+void glade_project_save (GladeProject *project, const gchar *path);
+void glade_project_open (const gchar *path);
 
 
 /* Widget related stuff */
diff -upr gnome2/glade3/src/glade-project-ui.c glade3/src/glade-project-ui.c
--- gnome2/glade3/src/glade-project-ui.c        2002-05-02 11:11:09.000000000 +0200
+++ glade3/src/glade-project-ui.c       2003-04-01 20:43:58.000000000 +0200
@@ -21,68 +21,3 @@
  */
 
 
-#include "glade.h"
-#include "glade-project.h"
-#include "glade-project-ui.h"
-
-#define GLADE_SELECTOR_FILENAME "GladeFileSelectorFilename"
-
-static gint
-glade_project_ui_delete_event_cb (GtkWidget *selector, GdkEventAny *event)
-{
-       gtk_main_quit ();
-
-       gtk_object_set_user_data (GTK_OBJECT (selector), NULL);
-
-       gtk_widget_hide (selector);
-       
-       return TRUE;
-}
-
-static gint
-glade_project_ui_selector_clicked (GtkWidget *button, GtkWidget *selector)
-{
-       g_return_val_if_fail (GTK_IS_FILE_SELECTION (selector), FALSE);
-
-       if (button == GTK_FILE_SELECTION (selector)->ok_button) {
-               const gchar *file;
-               file = gtk_file_selection_get_filename (GTK_FILE_SELECTION (selector));
-               gtk_object_set_user_data (GTK_OBJECT (selector), g_strdup (file));
-       } else 
-               gtk_object_set_user_data (GTK_OBJECT (selector), NULL);
-               
-       gtk_main_quit ();
-
-       gtk_widget_hide (selector);
-       
-       return TRUE;
-}
-
-gchar *
-glade_project_ui_get_path (const gchar *title)
-{
-       GtkWidget *selector;
-
-       selector = gtk_file_selection_new (title);
-
-       gtk_window_set_modal (GTK_WINDOW (selector), TRUE);
-
-       gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(selector)->ok_button),
-                           "clicked",
-                           GTK_SIGNAL_FUNC (glade_project_ui_selector_clicked),
-                           selector);
-       gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(selector)->cancel_button),
-                           "clicked",
-                           GTK_SIGNAL_FUNC (glade_project_ui_selector_clicked),
-                           selector);
-       
-       gtk_signal_connect (GTK_OBJECT(selector), "delete_event",
-                           GTK_SIGNAL_FUNC (glade_project_ui_delete_event_cb),
-                           NULL);
-       
-       gtk_widget_show (selector);
-
-       gtk_main ();
-
-       return gtk_object_get_user_data (GTK_OBJECT (selector));
-}
diff -upr gnome2/glade3/src/glade-project-ui.h glade3/src/glade-project-ui.h
--- gnome2/glade3/src/glade-project-ui.h        2002-05-02 11:11:09.000000000 +0200
+++ glade3/src/glade-project-ui.h       2003-04-01 20:43:58.000000000 +0200
@@ -4,8 +4,6 @@
 
 G_BEGIN_DECLS
 
-gchar * glade_project_ui_get_path (const gchar *title);
-
 G_END_DECLS
 
 #endif /* __GLADE_PROJECT_UI_H__ */
diff -upr gnome2/glade3/src/glade-project-window.c glade3/src/glade-project-window.c
--- gnome2/glade3/src/glade-project-window.c    2003-03-28 13:27:15.000000000 +0100
+++ glade3/src/glade-project-window.c   2003-04-01 20:43:58.000000000 +0200
@@ -58,57 +58,68 @@ static void gpw_undo_cb (void);
 static void gpw_redo_cb (void);
 static void gpw_about_cb (void) {}
 
+
 static void
-gpw_open_cb (void)
+gpw_new_cb (void)
 {
-       glade_project_open (NULL);
+       GladeProjectWindow *gpw;
+       GladeProject *project;
+
+       project = glade_project_new (TRUE);
+       gpw = glade_project_window_get ();
+       glade_project_window_add_project (gpw, project);
 }
 
 static void
-gpw_delete_cb (void)
+gpw_on_open_filesel_ok (GtkWidget *widget, gpointer not_used)
 {
-       GladeProject *project;
-       GList *selection;
-       GList *free_me;
-       GList *list;
+       GtkWidget *filesel;
+       const gchar *path;
 
-       project = glade_project_window_get_project ();
-       if (!project) {
-               g_warning ("Why is delete sensitive ? it shouldn't not be because "
-                          "we don't have a project");
-               return;
-       }
-       
-       selection = glade_project_selection_get (project);
+       filesel = gtk_widget_get_toplevel (widget);
 
-       /* We have to be carefull when deleting widgets from the selection
-        * because when we delete each widget, the ->selection pointer changes
-        * by the g_list_remove. Copy the list and free it after we are done
-        */
-       list = g_list_copy (selection);
-       free_me = list;
-       for (; list; list = list->next)
-               glade_widget_delete (list->data);
-       g_list_free (free_me);
+       /* Get the filename and destroy the dialog */
+       path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+       gtk_widget_destroy (filesel);
 
-       /* Right now deleting widgets like this is not a problem, cause we
-        * don't support multiple selection. When we do, it would be nice
-        * to have glade_project_selction_freeze the remove all the widgets
-        * and then call glade_project_selection_thaw. This will trigger
-        * only one selection changed signal rather than multiple ones
-        * Chema
-        */
+       if (!path)
+               return;
+
+       glade_project_open (path);
 }
 
 static void
-gpw_new_cb (void)
+gpw_open_cb (void)
 {
        GladeProjectWindow *gpw;
-       GladeProject *project;
+       GtkWidget *filesel;
 
-       project = glade_project_new (TRUE);
        gpw = glade_project_window_get ();
-       glade_project_window_add_project (gpw, project);
+
+       filesel = glade_util_file_selection_new (_("Open ..."), GTK_WINDOW (gpw->window));
+       g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
+                         "clicked", G_CALLBACK (gpw_on_open_filesel_ok),
+                         NULL);
+
+       gtk_widget_show (filesel);
+}
+
+static void
+gpw_on_save_filesel_ok (GtkWidget *widget, GladeProject *project)
+{
+       GtkWidget *filesel;
+       const gchar *path;
+
+       filesel = gtk_widget_get_toplevel (widget);
+
+       /* Get the filename and hide the dialog */
+       path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
+       gtk_widget_destroy (filesel);
+
+       if (!path)
+               return;
+
+       glade_project_save (project, path);
 }
 
 static void
@@ -116,11 +127,23 @@ gpw_save_cb (void)
 {
        GladeProjectWindow *gpw;
        GladeProject *project;
+       GtkWidget *filesel;
 
        gpw = glade_project_window_get ();
        project = glade_project_window_get_project ();
-       if (glade_project_save (project))
-               glade_project_window_refresh_title (gpw);
+
+       if (project->path != NULL) {
+               glade_project_save (project, project->path);
+               return;
+       }
+
+       /* If instead we dont have a path yet, fire up a file selector */
+       filesel = glade_util_file_selection_new (_("Save ..."), GTK_WINDOW (gpw->window));
+       g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
+                         "clicked", G_CALLBACK (gpw_on_save_filesel_ok),
+                         project);
+
+       gtk_widget_show (filesel);
 }
 
 static void
@@ -128,11 +151,17 @@ gpw_save_as_cb (void)
 {
        GladeProjectWindow *gpw;
        GladeProject *project;
+       GtkWidget *filesel;
 
        gpw = glade_project_window_get ();
        project = glade_project_window_get_project ();
-       if (glade_project_save_as (project))
-               glade_project_window_refresh_title (gpw);
+
+       filesel = glade_util_file_selection_new (_("Save as ..."), GTK_WINDOW (gpw->window));
+       g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
+                         "clicked", G_CALLBACK (gpw_on_save_filesel_ok),
+                         project);
+
+       gtk_widget_show (filesel);
 }
 
 static void
@@ -177,6 +206,42 @@ gpw_paste_cb (void)
 }
 
 static void
+gpw_delete_cb (void)
+{
+       GladeProject *project;
+       GList *selection;
+       GList *free_me;
+       GList *list;
+
+       project = glade_project_window_get_project ();
+       if (!project) {
+               g_warning ("Why is delete sensitive ? it shouldn't not be because "
+                          "we don't have a project");
+               return;
+       }
+       
+       selection = glade_project_selection_get (project);
+
+       /* We have to be carefull when deleting widgets from the selection
+        * because when we delete each widget, the ->selection pointer changes
+        * by the g_list_remove. Copy the list and free it after we are done
+        */
+       list = g_list_copy (selection);
+       free_me = list;
+       for (; list; list = list->next)
+               glade_widget_delete (list->data);
+       g_list_free (free_me);
+
+       /* Right now deleting widgets like this is not a problem, cause we
+        * don't support multiple selection. When we do, it would be nice
+        * to have glade_project_selction_freeze the remove all the widgets
+        * and then call glade_project_selection_thaw. This will trigger
+        * only one selection changed signal rather than multiple ones
+        * Chema
+        */
+}
+
+static void
 gpw_undo_cb (void)
 {
        glade_command_undo ();
diff -upr gnome2/glade3/src/glade-utils.c glade3/src/glade-utils.c
--- gnome2/glade3/src/glade-utils.c     2003-03-20 21:48:02.000000000 +0100
+++ glade3/src/glade-utils.c    2003-04-01 20:43:58.000000000 +0200
@@ -269,3 +269,32 @@ gint glade_util_check_key_is_esc (GtkWid
        else
                return FALSE;
 }
+
+/**
+ * glade_util_file_selection_new:
+ * @title: dialog title
+ * @parent: the window the dialog is set transient for
+ *
+ * Returns a file selection dialog. It's up to the caller to set up a
+ * callback for the OK button and then to show the dialog
+ **/
+GtkWidget *
+glade_util_file_selection_new (const gchar *title, GtkWindow *parent)
+{
+       GtkWidget *filesel;
+
+       filesel = gtk_file_selection_new (title);
+       g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION(filesel)->cancel_button),
+                                 "clicked", G_CALLBACK (gtk_widget_destroy),
+                                 filesel);
+       g_signal_connect_swapped (G_OBJECT (filesel), "delete_event",
+                                 G_CALLBACK (gtk_widget_destroy),
+                                 filesel);
+
+       if (GTK_IS_WINDOW (parent))
+               gtk_window_set_transient_for (GTK_WINDOW (filesel), GTK_WINDOW (parent));
+
+       return filesel;
+}
+ 
+ 
diff -upr gnome2/glade3/src/glade-utils.h glade3/src/glade-utils.h
--- gnome2/glade3/src/glade-utils.h     2003-03-20 21:48:02.000000000 +0100
+++ glade3/src/glade-utils.h    2003-04-01 20:43:58.000000000 +0200
@@ -32,6 +32,8 @@ gint   glade_util_check_key_is_esc    (GtkWi
 gchar  *glade_util_gtk_combo_func      (gpointer data);
 gpointer glade_util_gtk_combo_find     (GtkCombo *combo);
 
+GtkWidget *glade_util_file_selection_new (const gchar *title, GtkWindow *parent);
+
 G_END_DECLS
 
 #endif /* __GLADE_UTILS_H__ */

--=-wsncJs4PMSYaRZmHf7AA--





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