Commit c5818e11 authored by Tristan Van Berkom's avatar Tristan Van Berkom

undo/redo buttons cleanup. Use of "destroy" signal instead of week


	* glade-app.c: undo/redo buttons cleanup.
	  Use of "destroy" signal instead of week pointers and
	  use update-ui default handler to update buttons.

	* glade-project-window.c: glade_project_window_update_ui() chain up
	  with GLADE_APP_CLASS update-ui handler.
parent f36d7869
2006-01-25 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* glade-app.c: undo/redo buttons cleanup.
Use of "destroy" signal instead of week pointers and
use update-ui default handler to update buttons.
* glade-project-window.c: glade_project_window_update_ui() chain up
with GLADE_APP_CLASS update-ui handler.
2006-01-25 Tristan Van Berkom <tvb@gnome.org>
* configure.in: Bumping required gtk version to 2.8
2006-01-24 Tristan Van Berkom <tvb@gnome.org> 2006-01-24 Tristan Van Berkom <tvb@gnome.org>
* src/glade-project-window.c: use glade_project_display_name (), * src/glade-project-window.c: use glade_project_display_name (),
......
...@@ -49,7 +49,7 @@ AM_GLIB_GNU_GETTEXT ...@@ -49,7 +49,7 @@ AM_GLIB_GNU_GETTEXT
dnl ================================================================ dnl ================================================================
dnl Start of pkg-config checks dnl Start of pkg-config checks
dnl ================================================================ dnl ================================================================
PKG_CHECK_MODULES(GLADE, gtk+-2.0 >= 2.4.0 libxml-2.0 >= 2.4.0) PKG_CHECK_MODULES(GLADE, gtk+-2.0 >= 2.6.0 libxml-2.0 >= 2.4.0)
AC_SUBST(GLADE_LIBS) AC_SUBST(GLADE_LIBS)
AC_SUBST(GLADE_CFLAGS) AC_SUBST(GLADE_CFLAGS)
......
...@@ -150,6 +150,51 @@ glade_app_finalize (GObject *app) ...@@ -150,6 +150,51 @@ glade_app_finalize (GObject *app)
parent_class->finalize (app); parent_class->finalize (app);
} }
static void
glade_app_refresh_undo_redo_button (GladeApp *app,
GtkWidget *button,
gboolean undo)
{
GladeCommand *command = NULL;
static GtkTooltips *button_tips = NULL;
GladeProject *project;
gchar *desc;
if (button_tips == NULL)
button_tips = gtk_tooltips_new ();
if ((project = glade_app_get_active_project (app)) != NULL)
{
if (undo)
command = glade_command_next_undo_item (project);
else
command = glade_command_next_redo_item (project);
}
/* Change tooltips */
desc = g_strdup_printf ((undo) ? _("Undo: %s") : _("Redo: %s"),
command ? command->description : _("the last action"));
gtk_tooltips_set_tip (GTK_TOOLTIPS (button_tips), button, desc, NULL);
g_free (desc);
/* Set sensitivity on the button */
gtk_widget_set_sensitive (button, command != NULL);
}
void
glade_app_update_ui_default (GladeApp *app)
{
GList *list;
for (list = app->priv->undo_list; list; list = list->next)
if (list->data)
glade_app_refresh_undo_redo_button (app, list->data, TRUE);
for (list = app->priv->redo_list; list; list = list->next)
if (list->data)
glade_app_refresh_undo_redo_button (app, list->data, FALSE);
}
static void static void
glade_app_class_init (GladeAppClass * klass) glade_app_class_init (GladeAppClass * klass)
{ {
...@@ -162,7 +207,7 @@ glade_app_class_init (GladeAppClass * klass) ...@@ -162,7 +207,7 @@ glade_app_class_init (GladeAppClass * klass)
object_class->dispose = glade_app_dispose; object_class->dispose = glade_app_dispose;
object_class->finalize = glade_app_finalize; object_class->finalize = glade_app_finalize;
klass->update_ui_signal = NULL; klass->update_ui_signal = glade_app_update_ui_default;
klass->show_properties = NULL; klass->show_properties = NULL;
klass->hide_properties = NULL; klass->hide_properties = NULL;
...@@ -332,64 +377,6 @@ glade_app_get_transient_parent (GladeApp *app) ...@@ -332,64 +377,6 @@ glade_app_get_transient_parent (GladeApp *app)
return app->priv->transient_parent; return app->priv->transient_parent;
} }
static void
glade_app_refresh_undo_redo_button (GladeApp *app,
GtkWidget *button,
gboolean undo)
{
GladeCommand *command = NULL;
static GtkTooltips *button_tips = NULL;
GladeProject *project;
gchar *desc;
if (button_tips == NULL)
button_tips = gtk_tooltips_new ();
if ((project = glade_app_get_active_project (app)) != NULL)
{
if (undo)
command = glade_command_next_undo_item (project);
else
command = glade_command_next_redo_item (project);
}
/* Change tooltips */
desc = g_strdup_printf ((undo) ? _("Undo: %s") : _("Redo: %s"),
command ? command->description : _("the last action"));
gtk_tooltips_set_tip (GTK_TOOLTIPS (button_tips), button, desc, NULL);
g_free (desc);
/* Set sensitivity on the button */
gtk_widget_set_sensitive (button, command != NULL);
}
void
glade_app_undo_redo_button_update_ui (GladeApp *app)
{
GList *list;
gboolean clean_undo_list = FALSE, clean_redo_list = FALSE;
for (list = app->priv->undo_list; list; list = list->next)
{
if (list->data)
glade_app_refresh_undo_redo_button (app, list->data, TRUE);
else
clean_undo_list = TRUE;
}
if (clean_undo_list)
app->priv->undo_list = g_list_remove_all (app->priv->undo_list, NULL);
for (list = app->priv->redo_list; list; list = list->next)
{
if (list->data)
glade_app_refresh_undo_redo_button (app, list->data, FALSE);
else
clean_redo_list = TRUE;
}
if (clean_redo_list)
app->priv->redo_list = g_list_remove_all (app->priv->redo_list, NULL);
}
static void static void
glade_app_init (GladeApp *app) glade_app_init (GladeApp *app)
{ {
...@@ -456,9 +443,6 @@ glade_app_init (GladeApp *app) ...@@ -456,9 +443,6 @@ glade_app_init (GladeApp *app)
/* Undo/Redo button list */ /* Undo/Redo button list */
app->priv->undo_list = app->priv->redo_list = NULL; app->priv->undo_list = app->priv->redo_list = NULL;
g_signal_connect (app, "update-ui",
G_CALLBACK (glade_app_undo_redo_button_update_ui),
NULL);
} }
GType GType
...@@ -872,6 +856,20 @@ glade_app_set_accel_group (GladeApp *app, GtkAccelGroup *accel_group) ...@@ -872,6 +856,20 @@ glade_app_set_accel_group (GladeApp *app, GtkAccelGroup *accel_group)
app->priv->accel_group = accel_group; app->priv->accel_group = accel_group;
} }
static gboolean
glade_app_undo_button_destroyed (GtkWidget *button, GladeApp *app)
{
app->priv->undo_list = g_list_remove (app->priv->undo_list, button);
return FALSE;
}
static gboolean
glade_app_redo_button_destroyed (GtkWidget *button, GladeApp *app)
{
app->priv->redo_list = g_list_remove (app->priv->redo_list, button);
return FALSE;
}
static GtkWidget * static GtkWidget *
glade_app_undo_redo_button_new (GladeApp *app, gboolean undo) glade_app_undo_redo_button_new (GladeApp *app, gboolean undo)
{ {
...@@ -889,12 +887,16 @@ glade_app_undo_redo_button_new (GladeApp *app, gboolean undo) ...@@ -889,12 +887,16 @@ glade_app_undo_redo_button_new (GladeApp *app, gboolean undo)
if (undo) if (undo)
{ {
app->priv->undo_list = g_list_prepend (app->priv->undo_list, button); app->priv->undo_list = g_list_prepend (app->priv->undo_list, button);
g_object_add_weak_pointer (G_OBJECT (button), &app->priv->undo_list->data); g_signal_connect (button, "destroy",
G_CALLBACK (glade_app_undo_button_destroyed),
app);
} }
else else
{ {
app->priv->redo_list = g_list_prepend (app->priv->redo_list, button); app->priv->redo_list = g_list_prepend (app->priv->redo_list, button);
g_object_add_weak_pointer (G_OBJECT (button), &app->priv->redo_list->data); g_signal_connect (button, "destroy",
G_CALLBACK (glade_app_redo_button_destroyed),
app);
} }
glade_app_refresh_undo_redo_button (app, button, undo); glade_app_refresh_undo_redo_button (app, button, undo);
...@@ -902,12 +904,24 @@ glade_app_undo_redo_button_new (GladeApp *app, gboolean undo) ...@@ -902,12 +904,24 @@ glade_app_undo_redo_button_new (GladeApp *app, gboolean undo)
return button; return button;
} }
/*
* glade_app_undo_button_new:
*
* Creates a new GtkButton undo widget.
* The button will be automatically updated with @app's undo stack.
*/
GtkWidget * GtkWidget *
glade_app_undo_button_new (GladeApp *app) glade_app_undo_button_new (GladeApp *app)
{ {
return glade_app_undo_redo_button_new (app, TRUE); return glade_app_undo_redo_button_new (app, TRUE);
} }
/*
* glade_app_redo_button_new:
*
* Creates a new GtkButton redo widget.
* The button will be automatically updated with @app's redo stack.
*/
GtkWidget * GtkWidget *
glade_app_redo_button_new (GladeApp *app) glade_app_redo_button_new (GladeApp *app)
{ {
......
...@@ -1592,6 +1592,10 @@ static void ...@@ -1592,6 +1592,10 @@ static void
glade_project_window_update_ui (GladeApp *app) glade_project_window_update_ui (GladeApp *app)
{ {
GladeProjectWindow *gpw = GLADE_PROJECT_WINDOW (app); GladeProjectWindow *gpw = GLADE_PROJECT_WINDOW (app);
/* Chain Up */
GLADE_APP_CLASS (parent_class)->update_ui_signal (app);
gpw_refresh_title (gpw); gpw_refresh_title (gpw);
glade_project_window_refresh_undo_redo (gpw); glade_project_window_refresh_undo_redo (gpw);
} }
......
...@@ -725,7 +725,7 @@ glade_util_draw_nodes_idle (GdkWindow *expose_win) ...@@ -725,7 +725,7 @@ glade_util_draw_nodes_idle (GdkWindow *expose_win)
goto out; goto out;
/* Find the corresponding GtkWidget */ /* Find the corresponding GtkWidget */
gdk_window_get_user_data (expose_win, (gpointer *)&expose_widget); gdk_window_get_user_data (expose_win, (gpointer)&expose_widget);
gc = expose_widget->style->black_gc; gc = expose_widget->style->black_gc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment