diff options
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | gladeui/glade-editor-property.c | 53 | ||||
-rw-r--r-- | gladeui/glade-editor-property.h | 2 | ||||
-rw-r--r-- | gladeui/glade-marshallers.list | 1 | ||||
-rw-r--r-- | gladeui/glade-property-class.h | 2 | ||||
-rw-r--r-- | plugins/gtk+/Makefile.am | 5 | ||||
-rw-r--r-- | plugins/gtk+/glade-activatable-editor.c | 434 | ||||
-rw-r--r-- | plugins/gtk+/glade-activatable-editor.h | 64 | ||||
-rw-r--r-- | plugins/gtk+/glade-button-editor.c | 45 | ||||
-rw-r--r-- | plugins/gtk+/glade-gtk.c | 102 | ||||
-rw-r--r-- | plugins/gtk+/glade-tool-button-editor.c | 18 | ||||
-rw-r--r-- | plugins/gtk+/glade-tool-button-editor.h | 3 | ||||
-rw-r--r-- | plugins/gtk+/gtk+.xml.in | 35 | ||||
-rw-r--r-- | po/POTFILES.in | 1 |
14 files changed, 728 insertions, 54 deletions
@@ -1,3 +1,20 @@ +2009-02-05 Tristan Van Berkom <tvb@gnome.org> + + * gladeui/glade-editor-property.c: Added "commit" signal to allow custom editors to do + command group/macros serialized around property changes. + + * plugins/gtk+/glade-activatable-editor.[ch], plugins/gtk+/Makefile.am, po/POTFILES.in: + New activatable editor to handle activatable properties in smart ways. + + * plugins/gtk+/glade-gtk.c: Made various properties insensitive when activatable + properties are in effect. + + * plugins/gtk+/glade-tool-button-editor.c: Made tables insensitive when activatable + properties are in effect. + + * plugins/gtk+/glade-button-editor.c: Allow use of use-stock choice while activatable + properties are in effect. + 2009-01-27 Tristan Van Berkom <tvb@gnome.org> * configure.ac: Bumping version for Anjuta dependancy diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c index 2cd3c26b..4adba614 100644 --- a/gladeui/glade-editor-property.c +++ b/gladeui/glade-editor-property.c @@ -59,6 +59,7 @@ enum { enum { CHANGED, + COMMIT, LAST_SIGNAL }; @@ -80,22 +81,12 @@ static guint glade_eprop_signals[LAST_SIGNAL] = { 0, }; static void glade_editor_property_load_common (GladeEditorProperty *eprop, GladeProperty *property); -/** - * glade_editor_property_commit: - * @eprop: A #GladeEditorProperty - * @value: The #GValue - * - * Commits the value onto the widget and glade-command interface - * (for use in GladeEditorProperty implementations) - */ -void -glade_editor_property_commit (GladeEditorProperty *eprop, - GValue *value) +static void +glade_editor_property_commit_common (GladeEditorProperty *eprop, + GValue *value) { GladeProject *project; GladeProjectFormat fmt; - - g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); if (eprop->use_command == FALSE) glade_property_set_value (eprop->property, value); @@ -113,7 +104,7 @@ glade_editor_property_commit (GladeEditorProperty *eprop, GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)->load (eprop, eprop->property); else /* publish a value change to those interested */ - g_signal_emit (G_OBJECT (eprop), glade_eprop_signals [CHANGED], 0, eprop->property); + g_signal_emit (G_OBJECT (eprop), glade_eprop_signals[CHANGED], 0, eprop->property); } void @@ -563,6 +554,7 @@ glade_editor_property_class_init (GladeEditorPropertyClass *eprop_class) /* Class methods */ eprop_class->load = glade_editor_property_load_common; + eprop_class->commit = glade_editor_property_commit_common; eprop_class->create_input = NULL; @@ -582,6 +574,22 @@ glade_editor_property_class_init (GladeEditorPropertyClass *eprop_class) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GLADE_TYPE_PROPERTY); + /** + * GladeEditorProperty::commit: + * @gladeeditorproperty: the #GladeEditorProperty which changed value + * @arg1: the new #GValue to commit. + * + * Emitted when a property's value is committed, can be useful to serialize + * commands before and after the property's commit command from custom editors. + */ + glade_eprop_signals[COMMIT] = + g_signal_new ("commit", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GladeEditorPropertyClass, commit), + NULL, NULL, + glade_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); /* Properties */ g_object_class_install_property @@ -3527,6 +3535,23 @@ glade_eprop_adjustment_create_input (GladeEditorProperty *eprop) /******************************************************************************* API *******************************************************************************/ +/** + * glade_editor_property_commit: + * @eprop: A #GladeEditorProperty + * @value: The #GValue to commit + * + * Commits @value to the property currently being edited by @eprop. + * + */ +void +glade_editor_property_commit (GladeEditorProperty *eprop, + GValue *value) +{ + g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); + g_return_if_fail (G_IS_VALUE (value)); + + g_signal_emit (G_OBJECT (eprop), glade_eprop_signals[COMMIT], 0, value); +} /** * glade_editor_property_load: diff --git a/gladeui/glade-editor-property.h b/gladeui/glade-editor-property.h index 43bd8cbb..ee7811d3 100644 --- a/gladeui/glade-editor-property.h +++ b/gladeui/glade-editor-property.h @@ -126,6 +126,8 @@ struct _GladeEditorPropertyClass { GtkWidget *(* create_input) (GladeEditorProperty *); + void (* commit) (GladeEditorProperty *, GValue *); + void *(* changed) (GladeEditorProperty *, GladeProperty *); }; diff --git a/gladeui/glade-marshallers.list b/gladeui/glade-marshallers.list index 302072bf..26b5c556 100644 --- a/gladeui/glade-marshallers.list +++ b/gladeui/glade-marshallers.list @@ -1,4 +1,5 @@ VOID:POINTER,POINTER +VOID:POINTER VOID:STRING,ULONG,UINT,STRING VOID:OBJECT VOID:OBJECT,BOOLEAN diff --git a/gladeui/glade-property-class.h b/gladeui/glade-property-class.h index a7767971..c7247d27 100644 --- a/gladeui/glade-property-class.h +++ b/gladeui/glade-property-class.h @@ -165,7 +165,7 @@ struct _GladePropertyClass */ guint stock_icon : 1; /* String properties can also denote stock icons, including * icons from icon factories... - */ + */ guint stock : 1; /* ... or a narrower list of "items" from gtk builtin stock items. */ diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am index fa616ad0..4147986a 100644 --- a/plugins/gtk+/Makefile.am +++ b/plugins/gtk+/Makefile.am @@ -27,7 +27,7 @@ libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-attributes.c glade glade-column-types.c glade-model-data.c glade-text-button.c glade-cell-renderer-button.c \ glade-icon-sources.c glade-button-editor.c glade-tool-button-editor.c glade-image-editor.c \ glade-image-item-editor.c glade-icon-factory-editor.c glade-store-editor.c glade-label-editor.c \ - glade-cell-renderer-editor.c glade-treeview-editor.c glade-entry-editor.c + glade-cell-renderer-editor.c glade-treeview-editor.c glade-entry-editor.c glade-activatable-editor.c libgladegtk_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) libgladegtk_la_LIBADD = $(libgladeui) $(GTK_LIBS) @@ -36,7 +36,8 @@ libgladegtkincludedir= $(includedir)/libgladeui-1.0/gladeui libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h glade-column-types.h glade-model-data.h \ glade-text-button.h glade-cell-renderer-button.h glade-icon-sources.h glade-button-editor.h \ glade-tool-button-editor.h glade-image-editor.h glade-image-item-editor.h glade-icon-factory-editor.h \ - glade-store-editor.h glade-label-editor.h glade-cell-renderer-editor.h glade-treeview-editor.h glade-entry-editor.h + glade-store-editor.h glade-label-editor.h glade-cell-renderer-editor.h glade-treeview-editor.h \ + glade-entry-editor.h glade-activatable-editor.h if PLATFORM_WIN32 libgladegtk_la_LDFLAGS += -no-undefined diff --git a/plugins/gtk+/glade-activatable-editor.c b/plugins/gtk+/glade-activatable-editor.c new file mode 100644 index 00000000..d651f71d --- /dev/null +++ b/plugins/gtk+/glade-activatable-editor.c @@ -0,0 +1,434 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Tristan Van Berkom. + * + * This library is free software; you can redistribute it and/or it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Authors: + * Tristan Van Berkom <tvb@gnome.org> + */ + +#include <config.h> +#include <gladeui/glade.h> +#include <glib/gi18n-lib.h> +#include <gdk/gdkkeysyms.h> + +#include "glade-activatable-editor.h" + + +static void glade_activatable_editor_finalize (GObject *object); + +static void glade_activatable_editor_editable_init (GladeEditableIface *iface); + +static void glade_activatable_editor_grab_focus (GtkWidget *widget); + + +G_DEFINE_TYPE_WITH_CODE (GladeActivatableEditor, glade_activatable_editor, GTK_TYPE_VBOX, + G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, + glade_activatable_editor_editable_init)); + + +static void +glade_activatable_editor_class_init (GladeActivatableEditorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = glade_activatable_editor_finalize; + widget_class->grab_focus = glade_activatable_editor_grab_focus; +} + +static void +glade_activatable_editor_init (GladeActivatableEditor *self) +{ +} + +static void +project_changed (GladeProject *project, + GladeCommand *command, + gboolean execute, + GladeActivatableEditor *activatable_editor) +{ + if (activatable_editor->modifying || + !GTK_WIDGET_MAPPED (activatable_editor)) + return; + + /* Reload on all commands */ + glade_editable_load (GLADE_EDITABLE (activatable_editor), activatable_editor->loaded_widget); +} + + +static void +project_finalized (GladeActivatableEditor *activatable_editor, + GladeProject *where_project_was) +{ + activatable_editor->loaded_widget = NULL; + + glade_editable_load (GLADE_EDITABLE (activatable_editor), NULL); +} + +static void +glade_activatable_editor_load (GladeEditable *editable, + GladeWidget *widget) +{ + GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (editable); + GList *l; + + activatable_editor->loading = TRUE; + + /* Since we watch the project*/ + if (activatable_editor->loaded_widget) + { + /* watch custom-child and use-stock properties here for reloads !!! */ + + g_signal_handlers_disconnect_by_func (G_OBJECT (activatable_editor->loaded_widget->project), + G_CALLBACK (project_changed), activatable_editor); + + /* The widget could die unexpectedly... */ + g_object_weak_unref (G_OBJECT (activatable_editor->loaded_widget->project), + (GWeakNotify)project_finalized, + activatable_editor); + } + + /* Mark our widget... */ + activatable_editor->loaded_widget = widget; + + if (activatable_editor->loaded_widget) + { + /* This fires for undo/redo */ + g_signal_connect (G_OBJECT (activatable_editor->loaded_widget->project), "changed", + G_CALLBACK (project_changed), activatable_editor); + + /* The widget/project could die unexpectedly... */ + g_object_weak_ref (G_OBJECT (activatable_editor->loaded_widget->project), + (GWeakNotify)project_finalized, + activatable_editor); + } + + /* load the embedded editable... */ + if (activatable_editor->embed) + glade_editable_load (GLADE_EDITABLE (activatable_editor->embed), widget); + + for (l = activatable_editor->properties; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); + + if (widget) + { + } + activatable_editor->loading = FALSE; +} + +static void +glade_activatable_editor_set_show_name (GladeEditable *editable, + gboolean show_name) +{ + GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (editable); + + glade_editable_set_show_name (GLADE_EDITABLE (activatable_editor->embed), show_name); +} + +static void +glade_activatable_editor_editable_init (GladeEditableIface *iface) +{ + iface->load = glade_activatable_editor_load; + iface->set_show_name = glade_activatable_editor_set_show_name; +} + +static void +glade_activatable_editor_finalize (GObject *object) +{ + GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (object); + + if (activatable_editor->properties) + g_list_free (activatable_editor->properties); + activatable_editor->properties = NULL; + activatable_editor->embed = NULL; + + glade_editable_load (GLADE_EDITABLE (object), NULL); + + G_OBJECT_CLASS (glade_activatable_editor_parent_class)->finalize (object); +} + +static void +glade_activatable_editor_grab_focus (GtkWidget *widget) +{ + GladeActivatableEditor *activatable_editor = GLADE_ACTIVATABLE_EDITOR (widget); + + gtk_widget_grab_focus (activatable_editor->embed); +} + +static void +table_attach (GtkWidget *table, + GtkWidget *child, + gint pos, gint row, + GtkSizeGroup *group) +{ + gtk_table_attach (GTK_TABLE (table), child, + pos, pos+1, row, row +1, + pos ? 0 : GTK_EXPAND | GTK_FILL, + GTK_EXPAND | GTK_FILL, + 3, 1); + + if (pos) + gtk_size_group_add_widget (group, child); +} + +static void +reset_property (GladeWidget *gwidget, + const gchar *property_name) +{ + GladeProperty *property; + GValue value = { 0, }; + + if ((property = glade_widget_get_property (gwidget, property_name)) != NULL) + { + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + } +} + +static GladeWidget * +get_image_widget (GladeWidget *widget) +{ + GtkWidget *image = NULL; + + if (GTK_IS_IMAGE_MENU_ITEM (widget->object)) + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget->object)); + return image ? glade_widget_get_from_gobject (image) : NULL; +} + +static void +reset_properties (GladeWidget *gwidget, + GtkAction *action, + gboolean use_appearance, + gboolean use_appearance_changed) +{ + reset_property (gwidget, "visible"); + reset_property (gwidget, "sensitive"); + + if (GTK_IS_MENU_ITEM (gwidget->object)) + { + if (!use_appearance_changed) + reset_property (gwidget, "accel-group"); + + if (use_appearance) + { + GladeWidget *image; + GladeProperty *property; + + /* Delete image... */ + if ((image = get_image_widget (gwidget)) != NULL) + { + GList list = { 0, }; + list.data = image; + glade_command_unlock_widget (image); + glade_command_delete (&list); + glade_project_selection_set (gwidget->project, gwidget->object, TRUE); + } + + property = glade_widget_get_property (gwidget, "label"); + glade_command_set_property (property, NULL); + + reset_property (gwidget, "stock"); + reset_property (gwidget, "use-underline"); + reset_property (gwidget, "use-stock"); + + } + else if (use_appearance_changed) + { + reset_property (gwidget, "stock"); + reset_property (gwidget, "use-underline"); + reset_property (gwidget, "use-stock"); + + reset_property (gwidget, "label"); + + } + } + else if (GTK_IS_TOOL_ITEM (gwidget->object)) + { + reset_property (gwidget, "visible-horizontal"); + reset_property (gwidget, "visible-vertical"); + reset_property (gwidget, "is-important"); + + if (use_appearance || use_appearance_changed) + { + reset_property (gwidget, "label-widget"); + reset_property (gwidget, "custom-label"); + reset_property (gwidget, "stock-id"); + reset_property (gwidget, "icon-name"); + reset_property (gwidget, "icon"); + reset_property (gwidget, "icon-widget"); + reset_property (gwidget, "image-mode"); + } + } + else if (GTK_IS_BUTTON (gwidget->object)) + { + reset_property (gwidget, "active"); + + + if (use_appearance) + { + + GtkWidget *button, *child; + GladeWidget *gchild = NULL; + GladeProperty *property; + + /* If theres a widget customly inside... command remove it first... */ + button = GTK_WIDGET (gwidget->object); + child = GTK_BIN (button)->child; + if (child) + gchild = glade_widget_get_from_gobject (child); + + if (gchild && gchild->parent == gwidget) + { + GList widgets = { 0, }; + widgets.data = gchild; + glade_command_delete (&widgets); + } + + reset_property (gwidget, "custom-child"); + reset_property (gwidget, "stock"); + //reset_property (gwidget, "use-stock"); + + property = glade_widget_get_property (gwidget, "label"); + glade_command_set_property (property, ""); + + } else if (use_appearance_changed) { + reset_property (gwidget, "label"); + reset_property (gwidget, "custom-child"); + reset_property (gwidget, "stock"); + //reset_property (gwidget, "use-stock"); + } + } +} + +static void +related_action_pre_commit (GladeEditorProperty *property, + GValue *value, + GladeActivatableEditor *activatable_editor) +{ + GladeWidget *gwidget = activatable_editor->loaded_widget; + GtkAction *action = g_value_get_object (value); + gboolean use_appearance = FALSE; + + glade_widget_property_get (gwidget, "use-action-appearance", &use_appearance); + + glade_command_push_group (_("Setting %s action"), gwidget->name); + + reset_properties (gwidget, action, use_appearance, FALSE); + +} + +static void +related_action_post_commit (GladeEditorProperty *property, + GValue *value, + GladeActivatableEditor *activatable_editor) +{ + + glade_command_pop_group (); +} + + +static void +use_appearance_pre_commit (GladeEditorProperty *property, + GValue *value, + GladeActivatableEditor *activatable_editor) +{ + GladeWidget *gwidget = activatable_editor->loaded_widget; + GtkAction *action = NULL; + gboolean use_appearance = g_value_get_boolean (value); + + glade_widget_property_get (gwidget, "related-action", &action); + + glade_command_push_group (use_appearance ? + _("Setting %s to use action appearance") : + _("Setting %s to not use action appearance"), + gwidget->name); + + reset_properties (gwidget, action, use_appearance, TRUE); +} + +static void +use_appearance_post_commit (GladeEditorProperty *property, + GValue *value, + GladeActivatableEditor *activatable_editor) +{ + + glade_command_pop_group (); +} + +GtkWidget * +glade_activatable_editor_new (GladeWidgetAdaptor *adaptor, + GladeEditable *embed) +{ + GladeActivatableEditor *activatable_editor; + GladeEditorProperty *eprop; + GtkWidget *table, *frame, *alignment, *label, *hbox; + GtkSizeGroup *group; + gchar *str; + gint row = 0; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL); + + activatable_editor = g_object_new (GLADE_TYPE_ACTIVATABLE_EDITOR, NULL); + activatable_editor->embed = GTK_WIDGET (embed); + + /* Pack the parent on top... */ + gtk_box_pack_start (GTK_BOX (activatable_editor), GTK_WIDGET (embed), FALSE, FALSE, 0); + + str = g_strdup_printf ("<b>%s</b>", _("Action")); + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + g_free (str); + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (activatable_editor), frame, FALSE, FALSE, 4); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + table = gtk_table_new (0, 0, FALSE); + gtk_container_add (GTK_CONTAINER (alignment), table); + + group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "related-action", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, row, group); + table_attach (table, GTK_WIDGET (eprop), 1, row++, group); + activatable_editor->properties = g_list_prepend (activatable_editor->properties, eprop); + + g_signal_connect (G_OBJECT (eprop), "commit", + G_CALLBACK (related_action_pre_commit), activatable_editor); + g_signal_connect_after (G_OBJECT (eprop), "commit", + G_CALLBACK (related_action_post_commit), activatable_editor); + + eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "use-action-appearance", FALSE, TRUE); + table_attach (table, eprop->item_label, 0, row, group); + table_attach (table, GTK_WIDGET (eprop), 1, row++, group); + activatable_editor->properties = g_list_prepend (activatable_editor->properties, eprop); + + gtk_widget_show_all (GTK_WIDGET (activatable_editor)); + + g_signal_connect (G_OBJECT (eprop), "commit", + G_CALLBACK (use_appearance_pre_commit), activatable_editor); + g_signal_connect_after (G_OBJECT (eprop), "commit", + G_CALLBACK (use_appearance_post_commit), activatable_editor); + + return GTK_WIDGET (activatable_editor); +} diff --git a/plugins/gtk+/glade-activatable-editor.h b/plugins/gtk+/glade-activatable-editor.h new file mode 100644 index 00000000..1a666972 --- /dev/null +++ b/plugins/gtk+/glade-activatable-editor.h @@ -0,0 +1,64 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Tristan Van Berkom. + * + * This library is free software; you can redistribute it and/or it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Authors: + * Tristan Van Berkom <tvb@gnome.org> + */ +#ifndef _GLADE_ACTIVATABLE_EDITOR_H_ +#define _GLADE_ACTIVATABLE_EDITOR_H_ + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define GLADE_TYPE_ACTIVATABLE_EDITOR (glade_activatable_editor_get_type ()) +#define GLADE_ACTIVATABLE_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_ACTIVATABLE_EDITOR, GladeActivatableEditor)) +#define GLADE_ACTIVATABLE_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_ACTIVATABLE_EDITOR, GladeActivatableEditorClass)) +#define GLADE_IS_ACTIVATABLE_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_ACTIVATABLE_EDITOR)) +#define GLADE_IS_ACTIVATABLE_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_ACTIVATABLE_EDITOR)) +#define GLADE_ACTIVATABLE_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_ACTIVATABLE_EDITOR, GladeActivatableEditorClass)) + +typedef struct _GladeActivatableEditor GladeActivatableEditor; +typedef struct _GladeActivatableEditorClass GladeActivatableEditorClass; + +struct _GladeActivatableEditor +{ + GtkVBox parent; + + GladeWidget *loaded_widget; /* A handy pointer to the loaded widget ... */ + + GtkWidget *embed; + + GList *properties; /* A list of eprops to update at load() time */ + + gboolean loading; /* Loading flag for loading widgets in the editor */ + gboolean modifying; /* Flag for monitoring project changes */ +}; + +struct _GladeActivatableEditorClass +{ + GtkVBoxClass parent; +}; + +GType glade_activatable_editor_get_type (void) G_GNUC_CONST; +GtkWidget *glade_activatable_editor_new (GladeWidgetAdaptor *adaptor, + GladeEditable *editable); + +G_END_DECLS + +#endif /* _GLADE_ACTIVATABLE_EDITOR_H_ */ diff --git a/plugins/gtk+/glade-button-editor.c b/plugins/gtk+/glade-button-editor.c index 53560a17..06d7da7f 100644 --- a/plugins/gtk+/glade-button-editor.c +++ b/plugins/gtk+/glade-button-editor.c @@ -86,7 +86,7 @@ glade_button_editor_load (GladeEditable *editable, GladeButtonEditor *button_editor = GLADE_BUTTON_EDITOR (editable); GladeWidget *gchild = NULL; GtkWidget *child, *button; - gboolean use_stock = FALSE; + gboolean use_stock = FALSE, use_appearance = FALSE; GList *l; button_editor->loading = TRUE; @@ -130,6 +130,8 @@ glade_button_editor_load (GladeEditable *editable, if (widget) { + glade_widget_property_get (widget, "use-action-appearance", &use_appearance); + button = GTK_WIDGET (widget->object); child = GTK_BIN (button)->child; if (child) @@ -164,6 +166,12 @@ glade_button_editor_load (GladeEditable *editable, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->label_radio), TRUE); } } + + if (use_appearance) + gtk_widget_set_sensitive (button_editor->custom_radio, FALSE); + else + gtk_widget_set_sensitive (button_editor->custom_radio, TRUE); + } button_editor->loading = FALSE; } @@ -216,6 +224,7 @@ standard_toggled (GtkWidget *widget, GladeWidget *gchild = NULL; GtkWidget *child, *button; GValue value; + gboolean use_appearance = FALSE; if (button_editor->loading || !button_editor->loaded_widget) return; @@ -251,10 +260,14 @@ standard_toggled (GtkWidget *widget, property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); glade_command_set_property (property, FALSE); - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); + glade_widget_property_get (button_editor->loaded_widget, "use-action-appearance", &use_appearance); + if (!use_appearance) + { + property = glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + } glade_command_pop_group (); @@ -313,6 +326,7 @@ stock_toggled (GtkWidget *widget, GladeButtonEditor *button_editor) { GladeProperty *property; + gboolean use_appearance = FALSE; if (button_editor->loading || !button_editor->loaded_widget) return; @@ -328,8 +342,12 @@ stock_toggled (GtkWidget *widget, property = glade_widget_get_property (button_editor->loaded_widget, "image"); glade_command_set_property (property, NULL); - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_command_set_property (property, NULL); + glade_widget_property_get (button_editor->loaded_widget, "use-action-appearance", &use_appearance); + if (!use_appearance) + { + property = glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_command_set_property (property, ""); + } property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); glade_command_set_property (property, TRUE); @@ -352,6 +370,7 @@ label_toggled (GtkWidget *widget, { GladeProperty *property; GValue value = { 0, }; + gboolean use_appearance = FALSE; if (button_editor->loading || !button_editor->loaded_widget) return; @@ -369,10 +388,14 @@ label_toggled (GtkWidget *widget, property = glade_widget_get_property (button_editor->loaded_widget, "use-stock"); glade_command_set_property (property, FALSE); - property = glade_widget_get_property (button_editor->loaded_widget, "label"); - glade_property_get_default (property, &value); - glade_command_set_property_value (property, &value); - g_value_unset (&value); + glade_widget_property_get (button_editor->loaded_widget, "use-action-appearance", &use_appearance); + if (!use_appearance) + { + property = glade_widget_get_property (button_editor->loaded_widget, "label"); + glade_property_get_default (property, &value); + glade_command_set_property_value (property, &value); + g_value_unset (&value); + } glade_command_pop_group (); diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c index 95147e07..d756186d 100644 --- a/plugins/gtk+/glade-gtk.c +++ b/plugins/gtk+/glade-gtk.c @@ -42,6 +42,7 @@ #include "glade-cell-renderer-editor.h" #include "glade-treeview-editor.h" #include "glade-entry-editor.h" +#include "glade-activatable-editor.h" #include <gladeui/glade-editor-property.h> #include <gladeui/glade-base-editor.h> @@ -59,7 +60,8 @@ #define MNEMONIC_INSENSITIVE_MSG _("This property does not apply unless Use Underline is set.") #define NOT_SELECTED_MSG _("Property not selected") -#define RESPID_INSENSITIVE_MSG _("this property is only for use in dialog action buttons") +#define RESPID_INSENSITIVE_MSG _("This property is only for use in dialog action buttons") +#define ACTION_APPEARANCE_MSG _("This property is set to be controled by an Action") /* -------------------------------- ParamSpecs ------------------------------ */ /* GtkImageMenuItem GnomeUI "stock_item" property special case: @@ -4786,7 +4788,7 @@ glade_gtk_entry_set_property (GladeWidgetAdaptor *adaptor, } } else if (property->klass->version_since_major <= gtk_major_version && - property->klass->version_since_minor <= gtk_minor_version) + property->klass->version_since_minor <= (gtk_minor_version + 1)) GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor, object, id, value); } @@ -5691,6 +5693,66 @@ glade_gtk_color_button_refresh_color (GtkColorButton *button, /* ----------------------------- GtkButton ------------------------------ */ +/* shared between menuitems and toolitems too */ +static void +evaluate_activatable_property_sensitivity (GObject *object, + const gchar *id, + const GValue *value) +{ + GladeWidget *gwidget = glade_widget_get_from_gobject (object); + + if (!strcmp (id, "related-action")) + { + GtkAction *action = g_value_get_object (value); + + if (action) + { + glade_widget_property_set_sensitive (gwidget, "visible", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "sensitive", FALSE, ACTION_APPEARANCE_MSG); + + glade_widget_property_set_sensitive (gwidget, "accel-group", FALSE, ACTION_APPEARANCE_MSG); + } else { + glade_widget_property_set_sensitive (gwidget, "visible", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "sensitive", TRUE, NULL); + + glade_widget_property_set_sensitive (gwidget, "accel-group", TRUE, NULL); + } + + } + else if (!strcmp (id, "use-action-appearance")) + { + gboolean use_appearance = g_value_get_boolean (value); + + + if (use_appearance) + { + glade_widget_property_set_sensitive (gwidget, "label", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "use-underline", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "stock", FALSE, ACTION_APPEARANCE_MSG); + //glade_widget_property_set_sensitive (gwidget, "use-stock", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "image", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "custom-child", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "stock-id", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "label-widget", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "icon-name", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "icon-widget", FALSE, ACTION_APPEARANCE_MSG); + glade_widget_property_set_sensitive (gwidget, "icon", FALSE, ACTION_APPEARANCE_MSG); + } else { + glade_widget_property_set_sensitive (gwidget, "label", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "use-underline", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "stock", TRUE, NULL); + //glade_widget_property_set_sensitive (gwidget, "use-stock", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "image", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "custom-child", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "stock-id", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "label-widget", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "icon-name", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "icon-widget", TRUE, NULL); + glade_widget_property_set_sensitive (gwidget, "icon", TRUE, NULL); + } + } +} + GladeEditable * glade_gtk_button_create_editable (GladeWidgetAdaptor *adaptor, GladeEditorPageType type) @@ -5701,8 +5763,10 @@ glade_gtk_button_create_editable (GladeWidgetAdaptor *adaptor, editable = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); if (type == GLADE_PAGE_GENERAL) + { + editable = (GladeEditable *)glade_activatable_editor_new (adaptor, editable); return (GladeEditable *)glade_button_editor_new (adaptor, editable); - + } return editable; } @@ -5740,6 +5804,8 @@ glade_gtk_button_set_property (GladeWidgetAdaptor *adaptor, GladeWidget *widget = glade_widget_get_from_gobject (object); GladeProperty *property = glade_widget_get_property (widget, id); + evaluate_activatable_property_sensitivity (object, id, value); + if (strcmp (id, "custom-child") == 0) { if (g_value_get_boolean (value)) @@ -5763,7 +5829,7 @@ glade_gtk_button_set_property (GladeWidgetAdaptor *adaptor, gtk_button_set_label (GTK_BUTTON (object), g_value_get_string (value)); } else if (property->klass->version_since_major <= gtk_major_version && - property->klass->version_since_minor <= gtk_minor_version) + property->klass->version_since_minor <= (gtk_minor_version + 1)) GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value); } @@ -6482,6 +6548,23 @@ glade_gtk_menu_shell_action_activate (GladeWidgetAdaptor *adaptor, } /* ----------------------------- GtkMenuItem ------------------------------ */ + +/* ... shared with toolitems ... */ +GladeEditable * +glade_gtk_activatable_create_editable (GladeWidgetAdaptor *adaptor, + GladeEditorPageType type) +{ + GladeEditable *editable; + + /* Get base editable */ + editable = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); + + if (type == GLADE_PAGE_GENERAL) + return (GladeEditable *)glade_activatable_editor_new (adaptor, editable); + + return editable; +} + void glade_gtk_menu_item_action_activate (GladeWidgetAdaptor *adaptor, GObject *object, @@ -6618,6 +6701,7 @@ glade_gtk_menu_item_set_use_underline (GObject *object, const GValue *value) gtk_label_set_use_underline (GTK_LABEL (label), g_value_get_boolean (value)); } + void glade_gtk_menu_item_set_property (GladeWidgetAdaptor *adaptor, GObject *object, @@ -6626,13 +6710,15 @@ glade_gtk_menu_item_set_property (GladeWidgetAdaptor *adaptor, { GladeWidget *gwidget = glade_widget_get_from_gobject (object); GladeProperty *property = glade_widget_get_property (gwidget, id); + + evaluate_activatable_property_sensitivity (object, id, value); if (!strcmp (id, "use-underline")) glade_gtk_menu_item_set_use_underline (object, value); else if (!strcmp (id, "label")) glade_gtk_menu_item_set_label (object, value); else if (property->klass->version_since_major <= gtk_major_version && - property->klass->version_since_minor <= gtk_minor_version) + property->klass->version_since_minor <= (gtk_minor_version + 1)) GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value); } @@ -7500,8 +7586,10 @@ glade_gtk_tool_item_set_property (GladeWidgetAdaptor *adaptor, GladeWidget *gwidget = glade_widget_get_from_gobject (object); GladeProperty *property = glade_widget_get_property (gwidget, id); + //evaluate_activatable_property_sensitivity (object, id, value); + if (property->klass->version_since_major <= gtk_major_version && - property->klass->version_since_minor <= gtk_minor_version) + property->klass->version_since_minor <= (gtk_minor_version + 1)) GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value); @@ -7515,7 +7603,7 @@ glade_gtk_tool_button_create_editable (GladeWidgetAdaptor *adaptor, GladeEditable *editable; /* Get base editable */ - editable = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type); + editable = GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->create_editable (adaptor, type); if (type == GLADE_PAGE_GENERAL) return (GladeEditable *)glade_tool_button_editor_new (adaptor, editable); diff --git a/plugins/gtk+/glade-tool-button-editor.c b/plugins/gtk+/glade-tool-button-editor.c index cbb4e36a..51593641 100644 --- a/plugins/gtk+/glade-tool-button-editor.c +++ b/plugins/gtk+/glade-tool-button-editor.c @@ -84,7 +84,7 @@ glade_tool_button_editor_load (GladeEditable *editable, GladeWidget *widget) { GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (editable); - gboolean custom_label = FALSE; + gboolean custom_label = FALSE, use_appearance = FALSE; GladeToolButtonImageMode image_mode = 0; GList *l; @@ -128,6 +128,7 @@ glade_tool_button_editor_load (GladeEditable *editable, { glade_widget_property_get (widget, "image-mode", &image_mode); glade_widget_property_get (widget, "custom-label", &custom_label); + glade_widget_property_get (widget, "use-action-appearance", &use_appearance); if (custom_label) gtk_toggle_button_set_active @@ -153,6 +154,17 @@ glade_tool_button_editor_load (GladeEditable *editable, default: break; } + + if (use_appearance) + { + gtk_widget_set_sensitive (button_editor->label_table, FALSE); + gtk_widget_set_sensitive (button_editor->image_table, FALSE); + } + else + { + gtk_widget_set_sensitive (button_editor->label_table, TRUE); + gtk_widget_set_sensitive (button_editor->image_table, TRUE); + } } button_editor->loading = FALSE; } @@ -450,7 +462,7 @@ glade_tool_button_editor_new (GladeWidgetAdaptor *adaptor, gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); gtk_container_add (GTK_CONTAINER (frame), alignment); - table = gtk_table_new (0, 0, FALSE); + button_editor->label_table = table = gtk_table_new (0, 0, FALSE); gtk_container_add (GTK_CONTAINER (alignment), table); group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); @@ -492,7 +504,7 @@ glade_tool_button_editor_new (GladeWidgetAdaptor *adaptor, gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); gtk_container_add (GTK_CONTAINER (frame), alignment); - table = gtk_table_new (0, 0, FALSE); + button_editor->image_table = table = gtk_table_new (0, 0, FALSE); gtk_container_add (GTK_CONTAINER (alignment), table); gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); diff --git a/plugins/gtk+/glade-tool-button-editor.h b/plugins/gtk+/glade-tool-button-editor.h index ec55389a..aa29cb4a 100644 --- a/plugins/gtk+/glade-tool-button-editor.h +++ b/plugins/gtk+/glade-tool-button-editor.h @@ -52,15 +52,18 @@ struct _GladeToolButtonEditor GtkWidget *embed; /* Embedded parent class editor */ + GtkWidget *label_table; GtkWidget *standard_label_radio; /* Set label with label property */ GtkWidget *custom_label_radio; /* Set a widget to be placed as the tool button's label */ + GtkWidget *image_table; GtkWidget *stock_radio; /* Create the image from stock-id */ GtkWidget *icon_radio; /* Create the image with the icon theme */ GtkWidget *file_radio; /* Create the image from filename (libglade only) */ GtkWidget *custom_radio; /* Set a widget to be used in the image position */ + GList *properties; /* A list of eprops to update at load() time */ gboolean loading; /* Loading flag for loading widgets in the editor */ diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in index 234c7dca..248d79c4 100644 --- a/plugins/gtk+/gtk+.xml.in +++ b/plugins/gtk+/gtk+.xml.in @@ -447,6 +447,7 @@ embedded in another object</_tooltip> <remove-child-function>glade_gtk_menu_item_remove_child</remove-child-function> <action-activate-function>glade_gtk_menu_item_action_activate</action-activate-function> <write-child-function>glade_gtk_menu_item_write_child</write-child-function> + <create-editable-function>glade_gtk_activatable_create_editable</create-editable-function> <special-child-type>submenu</special-child-type> <actions> @@ -470,13 +471,13 @@ embedded in another object</_tooltip> </property> <!-- GtkActivatable --> - <property id="related-action" _name="Related Action" since="2.16"> + <property id="related-action" _name="Related Action" custom-layout="True" since="2.16"> <parameter-spec> <type>GParamObject</type> <value-type>GtkAction</value-type> </parameter-spec> </property> - <property id="use-action-appearance" _name="Use Action Appearance" default="False" since="2.16"> + <property id="use-action-appearance" _name="Use Action Appearance" custom-layout="True" default="False" since="2.16"> <parameter-spec> <type>GParamBoolean</type> </parameter-spec> @@ -641,16 +642,17 @@ embedded in another object</_tooltip> <post-create-function>glade_gtk_tool_item_post_create</post-create-function> <constructor-function>glade_gtk_tool_item_constructor</constructor-function> <set-property-function>glade_gtk_tool_item_set_property</set-property-function> + <create-editable-function>glade_gtk_activatable_create_editable</create-editable-function> <properties> <!-- GtkActivatable --> - <property id="related-action" _name="Related Action" since="2.16"> + <property id="related-action" _name="Related Action" custom-layout="True" since="2.16"> <parameter-spec> <type>GParamObject</type> <value-type>GtkAction</value-type> </parameter-spec> </property> - <property id="use-action-appearance" _name="Use Action Appearance" default="False" since="2.16"> + <property id="use-action-appearance" _name="Use Action Appearance" custom-layout="True" default="False" since="2.16"> <parameter-spec> <type>GParamBoolean</type> </parameter-spec> @@ -987,7 +989,7 @@ embedded in another object</_tooltip> <visible-lines>2</visible-lines> </property> <property id="use-underline" custom-layout="True"/> - <property id="stock" _name="Stock Button" stock="True" save="False" custom-layout="True"> + <property id="stock" _name="Stock Button" stock-icon="True" save="False" custom-layout="True"> <parameter-spec> <type>GParamString</type> </parameter-spec> @@ -1014,13 +1016,13 @@ embedded in another object</_tooltip> </property> <!-- GtkActivatable --> - <property id="related-action" _name="Related Action" since="2.16"> + <property id="related-action" _name="Related Action" custom-layout="True" since="2.16"> <parameter-spec> <type>GParamObject</type> <value-type>GtkAction</value-type> </parameter-spec> </property> - <property id="use-action-appearance" _name="Use Action Appearance" default="False" since="2.16"> + <property id="use-action-appearance" _name="Use Action Appearance" custom-layout="True" default="False" since="2.16"> <parameter-spec> <type>GParamBoolean</type> </parameter-spec> @@ -3291,6 +3293,16 @@ embedded in another object</_tooltip> libglade-unsupported="True" toplevel="True"/> </glade-widget-classes> + + <glade-widget-group name="gtk-actions" _title="Actions"> + + <glade-widget-class-ref name="GtkActionGroup"/> + <glade-widget-class-ref name="GtkAction"/> + <glade-widget-class-ref name="GtkToggleAction"/> + <glade-widget-class-ref name="GtkRadioAction"/> + <glade-widget-class-ref name="GtkRecentAction"/> + </glade-widget-group> + <glade-widget-group name="gtk-toplevels" _title="Toplevels"> <glade-widget-class-ref name="GtkWindow"/> <glade-widget-class-ref name="GtkDialog"/> @@ -3380,15 +3392,6 @@ embedded in another object</_tooltip> <glade-widget-class-ref name="GtkFileChooserWidget"/> </glade-widget-group> - <glade-widget-group name="gtk-actions" _title="Actions"> - - <glade-widget-class-ref name="GtkActionGroup"/> - <glade-widget-class-ref name="GtkAction"/> - <glade-widget-class-ref name="GtkToggleAction"/> - <glade-widget-class-ref name="GtkRadioAction"/> - <glade-widget-class-ref name="GtkRecentAction"/> - </glade-widget-group> - <glade-widget-group name="gtk-model" title="Tree Model"> <default-palette-state expanded="False"/> diff --git a/po/POTFILES.in b/po/POTFILES.in index 6b342d60..8e749d5e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -62,6 +62,7 @@ plugins/gtk+/glade-label-editor.c plugins/gtk+/glade-cell-renderer-editor.c plugins/gtk+/glade-treeview-editor.c plugins/gtk+/glade-entry-editor.c +plugins/gtk+/glade-activatable-editor.c # gnome plugin backend plugins/gnome/glade-gnome.c |