[Glade-devel] [patch, glade3] glade_util_flash_message()
- From: pborelli katamail com (paolo borelli)
- Subject: [Glade-devel] [patch, glade3] glade_util_flash_message()
- Date: 28 Mar 2003 18:35:06 +0100
--=-pGVpAOY2pkAAEhDFPdzb
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi!
The patch attached implements a utility function to display messages in
the statusbar and uses it to display the "Project Saved" message.
Note: I'm not sure that this patch is ready for inclusion, so don't
apply it unless you reviewed it carefully and you are confident it's ok.
I'm sending it out for review and maybe to get some advices, because I
have at least a couple of doubts:
First thing, I'm not sure if I got the gtk_timeout behaviur right.
Second, I'm quite puzzled by this whole context_id thing used for the
statusbar. I thought that assigning a different context id for each
project you would get the following beahviour:
suppose you save a project, a "Project Saved" message is displayed; then
you change project (before the message is removed by the timeout); I
thought that at this point the message would be hidden because in the
statusbar is disaplyed the message stack relative to the current
project. This does not happen, so now I wonder why I have to set up
different context_ids when the resulting behavoiur is the same as when
you simply pass "1" every time you need a context_id.
ciao
paolo
PS: I'd like to thank to Joaquin for having applied (and corrected!) my
previous patches
--=-pGVpAOY2pkAAEhDFPdzb
Content-Disposition: attachment; filename=flash-message.patch
Content-Type: text/x-patch; name=flash-message.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit
diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog 2003-03-28 13:27:15.000000000 +0100
+++ glade3/ChangeLog 2003-03-28 17:20:42.000000000 +0100
@@ -1,3 +1,9 @@
+2003-03-28 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-27 Paolo Borelli
* src/glade-project.[ch]: make glade_project_open_from_file() static
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-28 15:10:10.000000000 +0100
@@ -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);
@@ -149,6 +150,19 @@ glade_project_destroy (GtkObject *object
}
+static void
+glade_project_set_context_id (GladeProject *project)
+{
+ GladeProjectWindow *gpw;
+ static guint i = 1;
+
+ gpw = glade_project_window_get ();
+
+ /* We do not want our context id to collide with the menu context id */
+ project->context_id = (gpw->statusbar_menu_context_id) + i;
+ i++;
+}
+
static GladeProject *
glade_project_check_previously_loaded (const gchar *path)
{
@@ -204,6 +218,7 @@ glade_project_new (gboolean untitled)
if (untitled)
project->name = g_strdup_printf ("Untitled %i", i++);
+ glade_project_set_context_id (project);
glade_project_update_menu_path (project);
return project;
@@ -601,6 +616,7 @@ glade_project_open_from_file (const gcha
project->path = g_strdup_printf ("%s", path);
g_free (project->name);
project->name = g_path_get_basename (project->path);
+ glade_project_set_context_id (project);
/* Setup the menu item to be shown in the /Project menu. */
glade_project_update_menu_path (project);
}
@@ -649,6 +665,7 @@ glade_project_save (GladeProject *projec
}
glade_project_refresh_menu_item (project);
+ glade_util_flash_message (project->context_id, _("Project Saved"));
return TRUE;
}
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-03-28 14:56:49.000000000 +0100
@@ -18,6 +18,8 @@ struct _GladeProject
gchar *name; /* The name of the project like network-conf */
gchar *path; /* The full path of the xml file for this project*/
+
+ guint context_id; /* the context_id for statusbar messages */
GtkItemFactoryEntry entry; /* The menu entry in the /Project menu */
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-28 17:18:08.000000000 +0100
@@ -95,6 +95,49 @@ 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);
+
+ return FALSE; /* removes the timeout */
+}
+
+/**
+ * glade_utils_flash:
+ * @msg: Message to flash on the statusbar
+ *
+ * Flash a temporary message on the statusbar.
+ **/
+void
+glade_util_flash_message (guint context_id, const gchar *message)
+{
+ GladeProjectWindow *gpw;
+ FlashInfo *fi;
+
+ g_return_if_fail (message != NULL);
+
+ gpw = glade_project_window_get ();
+
+ fi = g_new (FlashInfo, 1);
+ fi->statusbar = GTK_STATUSBAR (gpw->statusbar);
+ fi->context_id = context_id;
+ fi->message_id = gtk_statusbar_push (fi->statusbar, context_id, message);
+
+ gtk_timeout_add (flash_length,
+ (GtkFunction) remove_message_timeout,
+ fi);
+}
+
static gint
glade_util_compare_uline_labels (const gchar *labela, const gchar *labelb)
{
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-28 13:09:46.000000000 +0100
@@ -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, const gchar *message);
/* This is a GCompareFunc for comparing the labels of 2 stock items, ignoring
any '_' characters. It isn't particularly efficient. */
--=-pGVpAOY2pkAAEhDFPdzb--
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]