[Glade-devel] [patch, glade3] glade_util_flash_message()



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

On Sat, 2003-03-29 at 14:34, Joaquin Cuenca Abela wrote:
IMO, just one context_id for event messages, independent of the current
project.

Here it is an updated patch. I also made the flash util take a formatted
argument.

ciao
        paolo

--=-qKlp1HPLy2D3h/hZosx2
Content-Disposition: attachment; filename=flash-message-2.patch
Content-Type: text/x-patch; name=flash-message-2.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-03-30 14:45:44.000000000 +0200
@@ -1,3 +1,9 @@
+2003-03-30  Paolo Borelli
+
+       * src/glade-utils.[ch]: implement glade_util_flash_message()
+       * src/glade-project.[ch]: use the above to display "Project Saved"
+       in the statusbar.
+
 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-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-03-30 14:45:44.000000000 +0200
@@ -34,6 +34,7 @@
 #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);
@@ -621,10 +622,13 @@ glade_project_open_from_file (const gcha
 gboolean
 glade_project_save (GladeProject *project)
 {
+       GladeProjectWindow *gpw;
        gchar *backup;
 
        g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
 
+       gpw = glade_project_window_get ();
+
        backup = project->path;
 
        if (project->path == NULL) {
@@ -649,6 +653,8 @@ glade_project_save (GladeProject *projec
        }
 
        glade_project_refresh_menu_item (project);
+       glade_util_flash_message (gpw->statusbar_actions_context_id,
+                                 _("Project '%s' saved"), project->name);
 
        return TRUE;
 }
@@ -665,10 +671,13 @@ glade_project_save (GladeProject *projec
 gboolean
 glade_project_save_as (GladeProject *project)
 {
+       GladeProjectWindow *gpw;
        gchar *backup;
 
        g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
 
+       gpw = glade_project_window_get ();
+
        /* Keep the previous path */
        backup = project->path;
        project->path = glade_project_ui_get_path (_("Save as ..."));
@@ -688,10 +697,13 @@ glade_project_save_as (GladeProject *pro
        }
 
        /* Free the backup and return; */
+       g_free (backup);
        g_free (project->name);
        project->name = g_path_get_basename (project->path);
+
        glade_project_refresh_menu_item (project);
-       g_free (backup);
+       glade_util_flash_message (gpw->statusbar_actions_context_id,
+                                 _("Project saved as '%s'"), project->name);
 
        return TRUE;
 }      
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-03-30 14:45:44.000000000 +0200
@@ -366,6 +366,7 @@ gpw_construct_statusbar (GladeProjectWin
        statusbar = gtk_statusbar_new ();
        gpw->statusbar = statusbar;
        gpw->statusbar_menu_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "menu");
+       gpw->statusbar_actions_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), 
"actions");
                
        gtk_box_pack_end_defaults (GTK_BOX (gpw->main_vbox), statusbar);        
 }
diff -upr gnome2/glade3/src/glade-project-window.h glade3/src/glade-project-window.h
--- gnome2/glade3/src/glade-project-window.h    2003-03-26 10:28:21.000000000 +0100
+++ glade3/src/glade-project-window.h   2003-03-30 14:45:44.000000000 +0200
@@ -15,8 +15,10 @@ struct _GladeProjectWindow
 {
        GtkWidget *window; /* Main window */
        GtkWidget *main_vbox;
+
        GtkWidget *statusbar; /* A pointer to the status bar. */
        guint statusbar_menu_context_id; /* The context id of the menu bar */
+       guint statusbar_actions_context_id; /* The context id of actions messages */
        
        GtkItemFactory *item_factory; /* A pointer to the Item factory.
                                       * We need it to be able to later add
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-03-30 14:46:38.000000000 +0200
@@ -95,6 +95,57 @@ glade_util_ui_warn (const gchar *warning
        gtk_widget_destroy (dialog);
 }
 
+typedef struct {
+       GtkStatusbar *statusbar;
+       guint context_id;
+       guint message_id;
+} FlashInfo;
+
+static const guint32 flash_length = 3000;
+
+static gboolean
+remove_message_timeout (FlashInfo * fi) 
+{
+       gtk_statusbar_remove (fi->statusbar, fi->context_id, fi->message_id);
+       g_free (fi);
+
+       /* remove the timeout */
+       return FALSE;
+}
+
+/**
+ * glade_utils_flash_message:
+ * @context_id: The message context_id
+ * @format: The message to flash on the statusbar
+ *
+ * Flash a temporary message on the statusbar.
+ **/
+void
+glade_util_flash_message (guint context_id, gchar *format, ...)
+{
+       va_list args;
+       GladeProjectWindow *gpw;
+       FlashInfo *fi;
+       gchar *message;
+       
+       g_return_if_fail (format != NULL);
+
+       gpw = glade_project_window_get ();
+
+       va_start (args, format);
+       message = g_strdup_vprintf (format, args);
+       va_end (args);
+
+       fi = g_new (FlashInfo, 1);
+       fi->statusbar = GTK_STATUSBAR (gpw->statusbar);
+       fi->context_id = context_id;    
+       fi->message_id = gtk_statusbar_push (fi->statusbar, fi->context_id, message);
+
+       gtk_timeout_add (flash_length, (GtkFunction) remove_message_timeout, fi);
+
+       g_free (message);
+}
+
 static gint
 glade_util_compare_uline_labels (const gchar *labela, const gchar *labelb)
 {
Only in glade3/src: glade-utils.c~
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-03-30 14:45:44.000000000 +0200
@@ -20,6 +20,7 @@ typedef enum
 void     glade_util_widget_set_tooltip (GtkWidget *widget, const gchar *str);
 GType    glade_util_get_type_from_name (const gchar *name);
 void     glade_util_ui_warn            (const gchar *warning);
+void     glade_util_flash_message      (guint context_id, gchar *format, ...);
 
 /* This is a GCompareFunc for comparing the labels of 2 stock items, ignoring
    any '_' characters. It isn't particularly efficient. */

--=-qKlp1HPLy2D3h/hZosx2--




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