[glade3/glade-3-8] * plugins/Makefile.am, plugins/glade-tool-item-group-editor.[ch], plugins/gtk+.xml.in, plugins/gla



commit 88d395d0082cc37ffa0efe0e5b5f619a11bc4fb9
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sun Jan 9 01:06:10 2011 +0900

    	* plugins/Makefile.am, plugins/glade-tool-item-group-editor.[ch], plugins/gtk+.xml.in,
    	plugins/glade-gtk.c: Added support for editing GtkToolPalette.
    
    Conflicts:
    
    	ChangeLog
    	plugins/gtk+/Makefile.am
    	plugins/gtk+/glade-gtk.c
    	plugins/gtk+/gtk+.xml.in

 ChangeLog                                   |    5 +
 plugins/gtk+/Makefile.am                    |    5 +-
 plugins/gtk+/glade-gtk.c                    |  456 +++++++++++++++++++++++----
 plugins/gtk+/glade-tool-item-group-editor.c |  330 +++++++++++++++++++
 plugins/gtk+/glade-tool-item-group-editor.h |   65 ++++
 plugins/gtk+/gtk+.xml.in                    |   70 ++++-
 6 files changed, 856 insertions(+), 75 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e719269..b264833 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-01-08  Tristan Van Berkom <tristanvb openismus com>
+
+	* plugins/Makefile.am, plugins/glade-tool-item-group-editor.[ch], plugins/gtk+.xml.in,
+	plugins/glade-gtk.c: Added support for editing GtkToolPalette.
+
 2011-01-06  Tristan Van Berkom <tristanvb openismus com>
 
 	* NEWS: Rolling 3.7.3
diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am
index 8d21b7f..d70ade1 100644
--- a/plugins/gtk+/Makefile.am
+++ b/plugins/gtk+/Makefile.am
@@ -24,7 +24,8 @@ 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-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-activatable-editor.c
+	glade-cell-renderer-editor.c glade-treeview-editor.c glade-entry-editor.c glade-activatable-editor.c \
+	glade-tool-item-group-editor.c
 
 libgladegtk_la_LDFLAGS     = -module -avoid-version $(AM_LDFLAGS)
 libgladegtk_la_LIBADD      = $(libgladeui) $(GTK_LIBS)
@@ -34,7 +35,7 @@ libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h glade
 	glade-text-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-activatable-editor.h
+	glade-entry-editor.h glade-activatable-editor.h glade-tool-item-group-editor.h
 
 if PLATFORM_WIN32
 libgladegtk_la_LDFLAGS += -no-undefined
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 30c6a43..e864ef9 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -43,6 +43,7 @@
 #include "glade-treeview-editor.h"
 #include "glade-entry-editor.h"
 #include "glade-activatable-editor.h"
+#include "glade-tool-item-group-editor.h"
 
 #include <gladeui/glade-editor-property.h>
 #include <gladeui/glade-base-editor.h>
@@ -6541,24 +6542,25 @@ glade_gtk_menu_shell_tool_item_get_display_name (GladeBaseEditor *editor,
 						 GladeWidget *gchild,
 						 gpointer user_data)
 {
-	GObject *child = glade_widget_get_object (gchild);
-	gchar *name;
-	
-	if (GTK_IS_SEPARATOR_MENU_ITEM (child) ||
-	    GTK_IS_SEPARATOR_TOOL_ITEM (child))
-		name = _("<separator>");
-	else if (GTK_IS_MENU_ITEM (child))
-		glade_widget_property_get (gchild, "label", &name);
-	else if (GTK_IS_TOOL_BUTTON (child))
-	{
-		glade_widget_property_get (gchild, "label", &name);
-		if (name == NULL || strlen (name) == 0)
-			glade_widget_property_get (gchild, "stock-id", &name);
-	}
-	else
-		name = _("<custom>");
-	
-	return g_strdup (name);
+  GObject *child = glade_widget_get_object (gchild);
+  gchar *name;
+
+  if (GTK_IS_SEPARATOR_MENU_ITEM (child) || GTK_IS_SEPARATOR_TOOL_ITEM (child))
+    name = _("<separator>");
+  else if (GTK_IS_MENU_ITEM (child))
+    glade_widget_property_get (gchild, "label", &name);
+  else if (GTK_IS_TOOL_BUTTON (child))
+    {
+      glade_widget_property_get (gchild, "label", &name);
+      if (name == NULL || strlen (name) == 0)
+        glade_widget_property_get (gchild, "stock-id", &name);
+    }
+  else if (GTK_IS_TOOL_ITEM_GROUP (child))
+    glade_widget_property_get (gchild, "label", &name);
+  else
+    name = _("<custom>");
+
+  return g_strdup (name);
 }
 
 static GladeWidget *
@@ -6571,11 +6573,13 @@ glade_gtk_menu_shell_item_get_parent (GladeWidget *gparent, GObject *parent)
 	else if (GTK_IS_MENU_ITEM (parent))
 		submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (parent));
 
-	if (submenu)
+	if (submenu && glade_widget_get_from_gobject (submenu))
 		gparent = glade_widget_get_from_gobject (submenu);
 	else
-		gparent = glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_MENU),
-						gparent, NULL, glade_widget_get_project (gparent));
+		gparent =
+			glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_MENU),
+					      gparent, NULL,
+					      glade_widget_get_project (gparent));
 
 	return gparent;
 }
@@ -6647,49 +6651,69 @@ glade_gtk_menu_shell_move_child (GladeBaseEditor *editor,
 				 GladeWidget *gchild,
 				 gpointer data)
 {	
-	GObject *parent = glade_widget_get_object (gparent);
-	GObject *child  = glade_widget_get_object (gchild);
-	GladeWidget *old_parent = gchild->parent;
-	GList list = {0, };
-	
-	if (GTK_IS_SEPARATOR_MENU_ITEM (parent) ||
-	    GTK_IS_SEPARATOR_TOOL_ITEM (parent)) 
-		return FALSE;
-
-	if (GTK_IS_MENU_ITEM (child) && GTK_IS_TOOLBAR (parent))
-		return FALSE;
-
-	if (GTK_IS_TOOL_ITEM (child) && 
-	    (GTK_IS_MENU (parent) || GTK_IS_MENU_BAR (parent) || GTK_IS_MENU_ITEM (parent)))
-		return FALSE;
-
-	if (GTK_IS_TOOL_ITEM (parent) && 
-	    (!GTK_IS_MENU_TOOL_BUTTON (parent) || !GTK_IS_MENU_ITEM (child)))
-		return FALSE;
-
-	if (GTK_IS_MENU_ITEM (parent) || GTK_IS_MENU_TOOL_BUTTON (parent))
-		gparent = glade_gtk_menu_shell_item_get_parent (gparent, parent);
-	
-	if (gparent != glade_widget_get_parent (gchild))
-	{
-		list.data = gchild;
-		glade_command_dnd (&list, gparent, NULL);
-	}
-
-	/* Delete dangling childless menus */
-	if (GTK_IS_MENU (old_parent->object) && 
-	    old_parent->parent && GTK_IS_MENU_ITEM (old_parent->parent->object))
-	{
-		GList del = { 0, }, *children;
-
-		children = gtk_container_get_children (GTK_CONTAINER (old_parent->object));
-		if (!children)
-		{
-			del.data = old_parent;
-			glade_command_delete (&del);
-		}
-		g_list_free (children);
-	}
+  GObject     *parent     = glade_widget_get_object (gparent);
+  GObject     *child      = glade_widget_get_object (gchild);
+  GladeWidget *old_parent = glade_widget_get_parent (gchild);
+  GladeWidget *old_parent_parent;
+  GList list = { 0, };
+
+  if (GTK_IS_SEPARATOR_MENU_ITEM (parent) ||
+      GTK_IS_SEPARATOR_TOOL_ITEM (parent))
+    return FALSE;
+
+  /* Moving a menu item child */
+  if (GTK_IS_MENU_ITEM (child))
+    {
+      if (GTK_IS_TOOLBAR (parent))         return FALSE;
+      if (GTK_IS_TOOL_ITEM_GROUP (parent)) return FALSE;
+      if (GTK_IS_TOOL_PALETTE (parent))    return FALSE;
+
+      if (GTK_IS_TOOL_ITEM (parent) && !GTK_IS_MENU_TOOL_BUTTON (parent))
+	return FALSE;
+    }
+
+  /* Moving a toolitem child */
+  if (GTK_IS_TOOL_ITEM (child))
+    {
+      if (GTK_IS_MENU (parent))         return FALSE;
+      if (GTK_IS_MENU_BAR (parent))     return FALSE;
+      if (GTK_IS_MENU_ITEM (parent))    return FALSE;
+      if (GTK_IS_TOOL_PALETTE (parent)) return FALSE;
+      if (GTK_IS_TOOL_ITEM (parent))    return FALSE;
+    }
+
+  /* Moving a toolitem group */
+  if (GTK_IS_TOOL_ITEM_GROUP (child))
+    {
+      if (!GTK_IS_TOOL_PALETTE (parent)) return FALSE;
+    }
+
+  if (GTK_IS_MENU_ITEM (parent) || GTK_IS_MENU_TOOL_BUTTON (parent))
+    gparent = glade_gtk_menu_shell_item_get_parent (gparent, parent);
+
+  if (gparent != glade_widget_get_parent (gchild))
+    {
+      list.data = gchild;
+      glade_command_dnd (&list, gparent, NULL);
+    }
+
+  /* Delete dangling childless menus */
+  old_parent_parent = glade_widget_get_parent (old_parent);
+  if (GTK_IS_MENU (glade_widget_get_object (old_parent)) &&
+      old_parent_parent && 
+      GTK_IS_MENU_ITEM (glade_widget_get_object (old_parent_parent)))
+    {
+      GList del = { 0, }, *children;
+
+      children =
+	gtk_container_get_children (GTK_CONTAINER (glade_widget_get_object (old_parent)));
+      if (!children)
+        {
+          del.data = old_parent;
+          glade_command_delete (&del);
+        }
+      g_list_free (children);
+    }
 
 	return TRUE;
 }
@@ -6733,6 +6757,8 @@ glade_gtk_toolbar_child_selected (GladeBaseEditor *editor,
 				  gpointer data)
 {
 	GObject *child = glade_widget_get_object (gchild);
+	GladeWidget *gparent = glade_widget_get_parent (gchild);
+	GObject *parent = glade_widget_get_object (gparent);
 	GType type = G_OBJECT_TYPE (child);
 	
 	glade_base_editor_add_label (editor, _("Tool Item"));
@@ -6745,9 +6771,31 @@ glade_gtk_toolbar_child_selected (GladeBaseEditor *editor,
 	if (type == GTK_TYPE_SEPARATOR_TOOL_ITEM) return;
 
 	glade_base_editor_add_label (editor, _("Packing"));
-	glade_base_editor_add_properties (editor, gchild, TRUE,
-					  "expand", "homogeneous", NULL);
+	if (GTK_IS_TOOLBAR (parent))
+		glade_base_editor_add_properties (editor, gchild, TRUE,
+						  "expand", "homogeneous", NULL);
+	else if (GTK_IS_TOOL_ITEM_GROUP (parent))
+		glade_base_editor_add_properties (editor, gchild, TRUE,
+						  "expand", "fill", "homogeneous", "new-row", NULL);
+}
 
+static void
+glade_gtk_tool_palette_child_selected (GladeBaseEditor * editor,
+				       GladeWidget * gchild, gpointer data)
+{
+  glade_base_editor_add_label (editor, _("Tool Item Group"));
+
+  glade_base_editor_add_default_properties (editor, gchild);
+
+  glade_base_editor_add_label (editor, _("Properties"));
+  glade_base_editor_add_properties (editor, gchild, FALSE, 
+				    "tooltip-text",
+				    NULL);
+  glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL);
+
+  glade_base_editor_add_label (editor, _("Packing"));
+  glade_base_editor_add_properties (editor, gchild, TRUE,
+                                    "exclusive", "expand", NULL);
 }
 
 static void
@@ -6763,6 +6811,13 @@ glade_gtk_menu_shell_tool_item_child_selected (GladeBaseEditor *editor,
 		glade_gtk_toolbar_child_selected (editor, gchild, data);
 		return;
 	}	
+
+	if (GTK_IS_TOOL_ITEM_GROUP (child))
+	{
+		glade_gtk_tool_palette_child_selected (editor, gchild, data);
+		return;
+	}
+
 	glade_base_editor_add_label (editor, _("Menu Item"));
 	
 	glade_base_editor_add_default_properties (editor, gchild);
@@ -7860,6 +7915,270 @@ glade_gtk_toolbar_action_activate (GladeWidgetAdaptor *adaptor,
 								     action_path);
 }
 
+/* ----------------------------- GtkToolPalette ------------------------------ */
+void
+glade_gtk_tool_palette_get_child_property (GladeWidgetAdaptor * adaptor,
+                                      GObject * container,
+                                      GObject * child,
+                                      const gchar * property_name,
+                                      GValue * value)
+{
+  g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
+  if (GTK_IS_TOOL_ITEM_GROUP (child) == FALSE)
+    return;
+
+  if (strcmp (property_name, "position") == 0)
+    {
+      g_value_set_int (value,
+                       gtk_tool_palette_get_group_position (GTK_TOOL_PALETTE (container),
+							    GTK_TOOL_ITEM_GROUP (child)));
+    }
+  else
+    {                           /* Chain Up */
+      GWA_GET_CLASS
+          (GTK_TYPE_CONTAINER)->child_get_property (adaptor,
+                                                    container, child,
+                                                    property_name, value);
+    }
+}
+
+void
+glade_gtk_tool_palette_set_child_property (GladeWidgetAdaptor * adaptor,
+					   GObject * container,
+					   GObject * child,
+					   const gchar * property_name,
+					   GValue * value)
+{
+  g_return_if_fail (GTK_IS_TOOL_PALETTE (container));
+  g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
+
+  g_return_if_fail (property_name != NULL || value != NULL);
+
+  if (strcmp (property_name, "position") == 0)
+    {
+      GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
+      GList *children;
+      gint position, size;
+
+      children = glade_util_container_get_all_children (GTK_CONTAINER (palette));
+      size = g_list_length (children);
+      g_list_free (children);
+
+      position = g_value_get_int (value);
+
+      if (position >= size)
+        position = size - 1;
+
+      gtk_tool_palette_set_group_position (palette, GTK_TOOL_ITEM_GROUP (child), position);
+    }
+  else
+    /* Chain Up */
+    GWA_GET_CLASS
+        (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
+                                                  container, child,
+                                                  property_name, value);
+}
+
+void
+glade_gtk_tool_palette_add_child (GladeWidgetAdaptor * adaptor,
+				  GObject * object, GObject * child)
+{
+  GtkToolPalette *palette;
+  GtkToolItemGroup *group;
+
+  g_return_if_fail (GTK_IS_TOOL_PALETTE (object));
+  g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));
+
+  palette = GTK_TOOL_PALETTE (object);
+  group   = GTK_TOOL_ITEM_GROUP (child);
+
+  gtk_container_add (GTK_CONTAINER (palette), GTK_WIDGET (group));
+
+  if (glade_util_object_is_loading (object))
+    {
+      GladeWidget *gchild = glade_widget_get_from_gobject (child);
+
+      /* Packing props arent around when parenting during a glade_widget_dup() */
+      if (gchild && gchild->packing_properties)
+	glade_widget_pack_property_set (gchild, "position",
+					gtk_tool_palette_get_group_position (palette, group));
+    }
+}
+
+void
+glade_gtk_tool_palette_remove_child (GladeWidgetAdaptor * adaptor,
+				     GObject * object, GObject * child)
+{
+  gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+}
+
+static void
+glade_gtk_tool_palette_launch_editor (GladeWidgetAdaptor * adaptor,
+				      GObject * palette)
+{
+  GladeBaseEditor *editor;
+  GtkWidget *window;
+
+  /* Editor */
+  editor = glade_base_editor_new (palette, NULL,
+				  _("Group"), GTK_TYPE_TOOL_ITEM_GROUP,
+				  NULL);
+
+  glade_base_editor_append_types (editor, GTK_TYPE_TOOL_ITEM_GROUP,
+                                  _("Button"), GTK_TYPE_TOOL_BUTTON,
+                                  _("Toggle"), GTK_TYPE_TOGGLE_TOOL_BUTTON,
+                                  _("Radio"), GTK_TYPE_RADIO_TOOL_BUTTON,
+                                  _("Menu"), GTK_TYPE_MENU_TOOL_BUTTON,
+                                  _("Custom"), GTK_TYPE_TOOL_ITEM,
+                                  _("Separator"), GTK_TYPE_SEPARATOR_TOOL_ITEM,
+                                  NULL);
+
+  glade_base_editor_append_types (editor, GTK_TYPE_MENU_TOOL_BUTTON,
+                                  _("Normal"), GTK_TYPE_MENU_ITEM,
+                                  _("Image"), GTK_TYPE_IMAGE_MENU_ITEM,
+                                  _("Check"), GTK_TYPE_CHECK_MENU_ITEM,
+                                  _("Radio"), GTK_TYPE_RADIO_MENU_ITEM,
+                                  _("Separator"), GTK_TYPE_SEPARATOR_MENU_ITEM,
+                                  NULL);
+
+  glade_base_editor_append_types (editor, GTK_TYPE_MENU_ITEM,
+                                  _("Normal"), GTK_TYPE_MENU_ITEM,
+                                  _("Image"), GTK_TYPE_IMAGE_MENU_ITEM,
+                                  _("Check"), GTK_TYPE_CHECK_MENU_ITEM,
+                                  _("Radio"), GTK_TYPE_RADIO_MENU_ITEM,
+                                  _("Separator"), GTK_TYPE_SEPARATOR_MENU_ITEM,
+                                  NULL);
+
+  g_signal_connect (editor, "get-display-name",
+                    G_CALLBACK (glade_gtk_menu_shell_tool_item_get_display_name), NULL);
+  g_signal_connect (editor, "child-selected",
+                    G_CALLBACK (glade_gtk_menu_shell_tool_item_child_selected),
+                    NULL);
+  g_signal_connect (editor, "change-type",
+                    G_CALLBACK (glade_gtk_menu_shell_change_type), NULL);
+  g_signal_connect (editor, "build-child",
+                    G_CALLBACK (glade_gtk_menu_shell_build_child), NULL);
+  g_signal_connect (editor, "delete-child",
+                    G_CALLBACK (glade_gtk_menu_shell_delete_child), NULL);
+  g_signal_connect (editor, "move-child",
+                    G_CALLBACK (glade_gtk_menu_shell_move_child), NULL);
+
+  gtk_widget_show (GTK_WIDGET (editor));
+
+  window =
+      glade_base_editor_pack_new_window (editor, _("Tool Palette Editor"), NULL);
+  gtk_widget_show (window);
+}
+
+void
+glade_gtk_tool_palette_action_activate (GladeWidgetAdaptor * adaptor,
+					GObject * object, const gchar * action_path)
+{
+  if (strcmp (action_path, "launch_editor") == 0)
+    {
+      glade_gtk_tool_palette_launch_editor (adaptor, object);
+    }
+  else
+    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor,
+                                                         object, action_path);
+}
+
+/* ----------------------------- GtkToolItemGroup ------------------------------ */
+void
+glade_gtk_tool_item_group_add_child (GladeWidgetAdaptor * adaptor,
+				     GObject * object, GObject * child)
+{
+  gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
+}
+
+void
+glade_gtk_tool_item_group_remove_child (GladeWidgetAdaptor * adaptor,
+				     GObject * object, GObject * child)
+{
+  gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+}
+
+static void
+glade_gtk_tool_item_group_parse_finished (GladeProject * project,
+					  GladeWidget * widget)
+{
+  GtkWidget *label_widget = NULL;
+
+  glade_widget_property_get (widget, "label-widget", &label_widget);
+
+  if (label_widget)
+    glade_widget_property_set (widget, "custom-label", TRUE);
+  else
+    glade_widget_property_set (widget, "custom-label", FALSE);
+}
+
+void
+glade_gtk_tool_item_group_read_widget (GladeWidgetAdaptor * adaptor,
+				       GladeWidget * widget, GladeXmlNode * node)
+{
+  if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET(glade_project_get_format(widget->project))))
+    return;
+
+  /* First chain up and read in all the normal properties.. */
+  GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->read_widget (adaptor, widget, node);
+
+  /* Run this after the load so that icon-widget is resolved. */
+  g_signal_connect (glade_widget_get_project (widget),
+                    "parse-finished",
+                    G_CALLBACK (glade_gtk_tool_item_group_parse_finished), widget);
+}
+
+static void
+glade_gtk_tool_item_group_set_custom_label (GObject * object, const GValue * value)
+{
+  GladeWidget *gbutton;
+
+  gbutton = glade_widget_get_from_gobject (object);
+
+  glade_widget_property_set_sensitive (gbutton, "label", FALSE,
+                                       NOT_SELECTED_MSG);
+  glade_widget_property_set_sensitive (gbutton, "label-widget", FALSE,
+                                       NOT_SELECTED_MSG);
+
+  if (g_value_get_boolean (value))
+    glade_widget_property_set_sensitive (gbutton, "label-widget", TRUE, NULL);
+  else
+    glade_widget_property_set_sensitive (gbutton, "label", TRUE, NULL);
+}
+
+void
+glade_gtk_tool_item_group_set_property (GladeWidgetAdaptor * adaptor,
+                                        GObject * object,
+                                        const gchar * id, const GValue * value)
+{
+  if (!strcmp (id, "custom-label"))
+    glade_gtk_tool_item_group_set_custom_label (object, value);
+  else if (!strcmp (id, "label-widget"))
+    {
+      if (g_value_get_object (value) != NULL)
+	gtk_tool_item_group_set_label_widget (GTK_TOOL_ITEM_GROUP (object),
+					      (GtkWidget *)g_value_get_object (value));
+    }
+  else
+    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value);
+}
+
+GladeEditable *
+glade_gtk_tool_item_group_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_tool_item_group_editor_new (adaptor, editable);
+
+  return editable;
+}
+
 /* ----------------------------- GtkToolItem ------------------------------ */
 GObject *
 glade_gtk_tool_item_constructor (GType                  type,
@@ -8149,9 +8468,8 @@ glade_gtk_menu_tool_button_add_child (GladeWidgetAdaptor *adaptor,
 				      GObject *child)
 {
 	if (GTK_IS_MENU (child))
-	{
-		gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (object), GTK_WIDGET (child));
-	}
+		gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (object),
+					       GTK_WIDGET (child));
 	else
 		GWA_GET_CLASS (GTK_TYPE_TOOL_BUTTON)->add (adaptor, object, child);
 }
diff --git a/plugins/gtk+/glade-tool-item-group-editor.c b/plugins/gtk+/glade-tool-item-group-editor.c
new file mode 100644
index 0000000..2f5ebaa
--- /dev/null
+++ b/plugins/gtk+/glade-tool-item-group-editor.c
@@ -0,0 +1,330 @@
+/*
+ * Copyright (C) 2010 Openismus GmbH
+ *
+ * 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 <tristanvb openismus com>
+ */
+
+#include <config.h>
+#include <gladeui/glade.h>
+#include <glib/gi18n-lib.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "glade-tool-item-group-editor.h"
+
+
+static void glade_tool_item_group_editor_finalize (GObject * object);
+
+static void glade_tool_item_group_editor_editable_init (GladeEditableIface * iface);
+
+static void glade_tool_item_group_editor_grab_focus (GtkWidget * widget);
+
+G_DEFINE_TYPE_WITH_CODE (GladeToolItemGroupEditor, glade_tool_item_group_editor, GTK_TYPE_VBOX,
+                         G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
+                                                glade_tool_item_group_editor_editable_init));
+
+
+static void
+glade_tool_item_group_editor_class_init (GladeToolItemGroupEditorClass * klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = glade_tool_item_group_editor_finalize;
+  widget_class->grab_focus = glade_tool_item_group_editor_grab_focus;
+}
+
+static void
+glade_tool_item_group_editor_init (GladeToolItemGroupEditor * self)
+{
+}
+
+
+static void
+project_changed (GladeProject      *project,
+		 GladeCommand      *command,
+		 gboolean           execute,
+		 GladeToolItemGroupEditor *group_editor)
+{
+	if (!gtk_widget_get_mapped (GTK_WIDGET (group_editor)))
+		return;
+
+	/* Reload on all commands */
+	glade_editable_load (GLADE_EDITABLE (group_editor), group_editor->loaded_widget);
+}
+
+
+static void
+project_finalized (GladeToolItemGroupEditor *group_editor,
+		   GladeProject       *where_project_was)
+{
+	group_editor->loaded_widget = NULL;
+
+	glade_editable_load (GLADE_EDITABLE (group_editor), NULL);
+}
+
+static void
+glade_tool_item_group_editor_load (GladeEditable * editable, GladeWidget * widget)
+{
+  GladeToolItemGroupEditor *group_editor = GLADE_TOOL_ITEM_GROUP_EDITOR (editable);
+  gboolean custom_label = FALSE;
+  GList *l;
+
+  group_editor->loading = TRUE;
+
+  /* Since we watch the project*/
+  if (group_editor->loaded_widget)
+    {
+      g_signal_handlers_disconnect_by_func (G_OBJECT (group_editor->loaded_widget->project),
+					    G_CALLBACK (project_changed), group_editor);
+      
+      /* The widget could die unexpectedly... */
+      g_object_weak_unref (G_OBJECT (group_editor->loaded_widget->project),
+			   (GWeakNotify)project_finalized,
+			   group_editor);
+    }
+  
+  /* Mark our widget... */
+  group_editor->loaded_widget = widget;
+
+  if (group_editor->loaded_widget)
+    {
+      /* This fires for undo/redo */
+      g_signal_connect (G_OBJECT (group_editor->loaded_widget->project), "changed",
+			G_CALLBACK (project_changed), group_editor);
+      
+      /* The widget/project could die unexpectedly... */
+      g_object_weak_ref (G_OBJECT (group_editor->loaded_widget->project),
+			 (GWeakNotify)project_finalized,
+			 group_editor);
+    }
+
+  /* load the embedded editable... */
+  if (group_editor->embed)
+    glade_editable_load (GLADE_EDITABLE (group_editor->embed), widget);
+
+  for (l = group_editor->properties; l; l = l->next)
+    glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data),
+                                          widget);
+
+
+  if (widget)
+    {
+      glade_widget_property_get (widget, "custom-label", &custom_label);
+
+      if (custom_label)
+        gtk_toggle_button_set_active
+            (GTK_TOGGLE_BUTTON (group_editor->label_widget_radio), TRUE);
+      else
+        gtk_toggle_button_set_active
+            (GTK_TOGGLE_BUTTON (group_editor->label_radio), TRUE);
+    }
+
+  group_editor->loading = FALSE;
+}
+
+static void
+glade_tool_item_group_editor_set_show_name (GladeEditable * editable, gboolean show_name)
+{
+  GladeToolItemGroupEditor *group_editor = GLADE_TOOL_ITEM_GROUP_EDITOR (editable);
+
+  glade_editable_set_show_name (GLADE_EDITABLE (group_editor->embed),
+                                show_name);
+}
+
+static void
+glade_tool_item_group_editor_editable_init (GladeEditableIface * iface)
+{
+
+  iface->load = glade_tool_item_group_editor_load;
+  iface->set_show_name = glade_tool_item_group_editor_set_show_name;
+}
+
+static void
+glade_tool_item_group_editor_finalize (GObject * object)
+{
+  GladeToolItemGroupEditor *group_editor = GLADE_TOOL_ITEM_GROUP_EDITOR (object);
+
+  if (group_editor->properties)
+    g_list_free (group_editor->properties);
+  group_editor->properties = NULL;
+  group_editor->embed = NULL;
+
+  glade_editable_load (GLADE_EDITABLE (object), NULL);
+
+  G_OBJECT_CLASS (glade_tool_item_group_editor_parent_class)->finalize (object);
+}
+
+static void
+glade_tool_item_group_editor_grab_focus (GtkWidget * widget)
+{
+  GladeToolItemGroupEditor *group_editor = GLADE_TOOL_ITEM_GROUP_EDITOR (widget);
+
+  gtk_widget_grab_focus (group_editor->embed);
+}
+
+
+static void
+label_toggled (GtkWidget * widget,
+	       GladeToolItemGroupEditor *group_editor)
+{
+  GladeProperty *property;
+  GValue value = { 0, };
+
+  if (group_editor->loading || !group_editor->loaded_widget)
+    return;
+
+  if (!gtk_toggle_button_get_active
+      (GTK_TOGGLE_BUTTON (group_editor->label_radio)))
+    return;
+
+  glade_command_push_group (_("Setting %s to use standard label text"),
+                            glade_widget_get_name (group_editor->loaded_widget));
+
+  property =
+      glade_widget_get_property (group_editor->loaded_widget, "label-widget");
+  glade_command_set_property (property, NULL);
+
+  property = glade_widget_get_property (group_editor->loaded_widget, "label");
+  glade_property_get_default (property, &value);
+  glade_command_set_property_value (property, &value);
+  g_value_unset (&value);
+  property =
+      glade_widget_get_property (group_editor->loaded_widget, "custom-label");
+  glade_command_set_property (property, FALSE);
+
+  glade_command_pop_group ();
+
+  /* reload buttons and sensitivity and stuff... */
+  glade_editable_load (GLADE_EDITABLE (group_editor), group_editor->loaded_widget);
+}
+
+static void
+label_widget_toggled (GtkWidget * widget, GladeToolItemGroupEditor * group_editor)
+{
+  GladeProperty *property;
+
+  if (group_editor->loading || !group_editor->loaded_widget)
+    return;
+
+  if (!gtk_toggle_button_get_active
+      (GTK_TOGGLE_BUTTON (group_editor->label_widget_radio)))
+    return;
+
+  glade_command_push_group (_("Setting %s to use a custom label widget"),
+                            glade_widget_get_name (group_editor->loaded_widget));
+
+  property = glade_widget_get_property (group_editor->loaded_widget, "label");
+  glade_command_set_property (property, NULL);
+  property =
+      glade_widget_get_property (group_editor->loaded_widget, "custom-label");
+  glade_command_set_property (property, TRUE);
+
+  glade_command_pop_group ();
+
+  /* reload buttons and sensitivity and stuff... */
+  glade_editable_load (GLADE_EDITABLE (group_editor), group_editor->loaded_widget);
+}
+
+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);
+}
+
+GtkWidget *
+glade_tool_item_group_editor_new (GladeWidgetAdaptor *adaptor, 
+				  GladeEditable      *embed)
+{
+  GladeToolItemGroupEditor *group_editor;
+  GladeEditorProperty *eprop;
+  GtkWidget *table, *frame, *label, *hbox;
+  gchar *str;
+  gint row = 0;
+  GtkSizeGroup *group;
+
+  g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+  g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL);
+
+  group_editor = g_object_new (GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR, NULL);
+  group_editor->embed = GTK_WIDGET (embed);
+
+  /* Pack the parent on top... */
+  gtk_box_pack_start (GTK_BOX (group_editor), GTK_WIDGET (embed), FALSE, FALSE, 0);
+
+  group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+  str = g_strdup_printf ("<b>%s</b>", _("Group Header"));
+  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 (group_editor), frame, FALSE, FALSE, 0);
+
+  table = gtk_table_new (0, 0, FALSE);
+  gtk_container_add (GTK_CONTAINER (frame), table);
+
+  /* label */
+  eprop =
+      glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE,
+                                                 TRUE);
+  hbox = gtk_hbox_new (FALSE, 0);
+  group_editor->label_radio = gtk_radio_button_new (NULL);
+  gtk_box_pack_start (GTK_BOX (hbox), group_editor->label_radio, FALSE, FALSE,
+                      2);
+  gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2);
+  table_attach (table, hbox, 0, row, group);
+  table_attach (table, GTK_WIDGET (eprop), 1, row++, group);
+  group_editor->properties = g_list_prepend (group_editor->properties, eprop);
+
+  /* label-widget ... */
+  eprop =
+      glade_widget_adaptor_create_eprop_by_name (adaptor, "label-widget",
+                                                 FALSE, TRUE);
+  hbox = gtk_hbox_new (FALSE, 0);
+  group_editor->label_widget_radio = gtk_radio_button_new_from_widget
+      (GTK_RADIO_BUTTON (group_editor->label_radio));
+  gtk_box_pack_start (GTK_BOX (hbox), group_editor->label_widget_radio, FALSE,
+                      FALSE, 2);
+  gtk_box_pack_start (GTK_BOX (hbox), eprop->item_label, TRUE, TRUE, 2);
+  table_attach (table, hbox, 0, row, group);
+  table_attach (table, GTK_WIDGET (eprop), 1, row++, group);
+  group_editor->properties = g_list_prepend (group_editor->properties, eprop);
+
+  g_object_unref (group);
+
+  g_signal_connect (G_OBJECT (group_editor->label_widget_radio), "toggled",
+                    G_CALLBACK (label_widget_toggled), group_editor);
+  g_signal_connect (G_OBJECT (group_editor->label_radio), "toggled",
+                    G_CALLBACK (label_toggled), group_editor);
+
+  gtk_widget_show_all (GTK_WIDGET (group_editor));
+
+  return GTK_WIDGET (group_editor);
+}
diff --git a/plugins/gtk+/glade-tool-item-group-editor.h b/plugins/gtk+/glade-tool-item-group-editor.h
new file mode 100644
index 0000000..cc0f925
--- /dev/null
+++ b/plugins/gtk+/glade-tool-item-group-editor.h
@@ -0,0 +1,65 @@
+/*
+ * 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_TOOL_ITEM_GROUP_EDITOR_H_
+#define _GLADE_TOOL_ITEM_GROUP_EDITOR_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR	            (glade_tool_item_group_editor_get_type ())
+#define GLADE_TOOL_ITEM_GROUP_EDITOR(obj)		    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR, GladeToolItemGroupEditor))
+#define GLADE_TOOL_ITEM_GROUP_EDITOR_CLASS(klass)	    (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR, GladeToolItemGroupEditorClass))
+#define GLADE_IS_TOOL_ITEM_GROUP_EDITOR(obj)	    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR))
+#define GLADE_IS_TOOL_ITEM_GROUP_EDITOR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR))
+#define GLADE_TOOL_ITEM_GROUP_EDITOR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_TOOL_ITEM_GROUP_EDITOR, GladeToolItemGroupEditorClass))
+
+typedef struct _GladeToolItemGroupEditor        GladeToolItemGroupEditor;
+typedef struct _GladeToolItemGroupEditorClass   GladeToolItemGroupEditorClass;
+
+struct _GladeToolItemGroupEditor
+{
+	GtkVBox  parent;
+
+	GladeWidget *loaded_widget; /* A handy pointer to the loaded widget ... */
+
+	GtkWidget *embed;
+
+	GtkWidget *label_radio;         /* Set the label directly */
+	GtkWidget *label_widget_radio;  /* Use the custom label widget */
+
+	GList *properties;         /* A list of eprops to update at load() time */
+
+	gboolean loading;          /* Loading flag for loading widgets in the editor */
+};
+
+struct _GladeToolItemGroupEditorClass
+{
+	GtkVBoxClass parent;
+};
+
+GType            glade_tool_item_group_editor_get_type (void) G_GNUC_CONST;
+GtkWidget       *glade_tool_item_group_editor_new      (GladeWidgetAdaptor *adaptor,
+							GladeEditable      *editable);
+
+G_END_DECLS
+
+#endif  /* _GLADE_TOOL_ITEM_GROUP_EDITOR_H_ */
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 3aee116..4cfb1a1 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -615,6 +615,66 @@ embedded in another object</_tooltip>
       </packing-defaults>
     </glade-widget-class>
     
+    <glade-widget-class name="GtkToolPalette" generic-name="toolpalette" _title="Tool Palette" 
+			use-placeholders="False" since="2.20">
+      <post-create-function>glade_gtk_toolbar_post_create</post-create-function>
+      <add-child-function>glade_gtk_tool_palette_add_child</add-child-function>
+      <remove-child-function>glade_gtk_tool_palette_remove_child</remove-child-function>
+      <child-set-property-function>glade_gtk_tool_palette_set_child_property</child-set-property-function>
+      <child-get-property-function>glade_gtk_tool_palette_get_child_property</child-get-property-function>
+      <action-activate-function>glade_gtk_tool_palette_action_activate</action-activate-function>
+
+      <actions>
+        <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
+      </actions>
+      <properties>
+      	<property id="icon-size-set" disabled="True"/>
+      	<property id="toolbar-style" save-always="True" optional="True" optional-default="False" weight="0.4"/>
+      	<property id="icon-size" optional="True" optional-default="False" weight="0.5"/>
+      </properties>
+
+      <packing-properties>
+        <property id="position" _name="Position" default="-1" save="False">
+	  <parameter-spec>
+	    <type>GParamInt</type>
+	    <min>-1</min>
+	  </parameter-spec>
+          <_tooltip>The position of the tool item group in the palette</_tooltip>
+        </property>
+	<property id="expand" transfer-on-paste="True" save-always="True"/>
+        <property id="exclusive" transfer-on-paste="True"/>
+      </packing-properties>
+    </glade-widget-class>
+
+    <glade-widget-class name="GtkToolItemGroup" generic-name="toolitemgroup" _title="Tool Item Group" 
+			use-placeholders="False" since="2.20">
+      <post-create-function>empty</post-create-function>
+      <set-property-function>glade_gtk_tool_item_group_set_property</set-property-function>
+      <add-child-function>glade_gtk_tool_item_group_add_child</add-child-function>
+      <remove-child-function>glade_gtk_tool_item_group_remove_child</remove-child-function>
+      <create-editable-function>glade_gtk_tool_item_group_create_editable</create-editable-function>
+      <read-widget-function>glade_gtk_tool_item_group_read_widget</read-widget-function>
+
+      <properties>
+        <property id="label" translatable="True" default="toolitemgroup" custom-layout="True"/>
+	<property id="label-widget" parentless-widget="True" create-type="GtkLabel" custom-layout="True"/>
+
+	<!-- Virtual label type property -->
+        <property id="custom-label" visible="False" save="False">
+	  <parameter-spec>
+	    <type>GParamBoolean</type>
+	  </parameter-spec>
+        </property>
+      </properties>
+
+      <packing-properties>
+	<property id="expand" transfer-on-paste="True"/>
+        <property id="fill" transfer-on-paste="True"/>
+        <property id="row-new" transfer-on-paste="True"/>
+        <property id="homogeneous" transfer-on-paste="True"/>
+      </packing-properties>
+    </glade-widget-class>
+
     <glade-widget-class name="GtkToolItem" generic-name="toolitem" title="GtkToolItem">
       <post-create-function>glade_gtk_tool_item_post_create</post-create-function>
       <constructor-function>glade_gtk_tool_item_constructor</constructor-function>
@@ -629,9 +689,9 @@ embedded in another object</_tooltip>
       </properties>
 
     </glade-widget-class>
-    
-    <glade-widget-class name="GtkSeparatorToolItem" generic-name="separatortoolitem" _title="Separator Tool Item"/>
-	
+
+    <glade-widget-class name="GtkSeparatorToolItem" generic-name="separatortoolitem" 
+			_title="Separator Tool Item"/>
 
     <glade-widget-class name="GtkToolButton" generic-name="toolbutton" _title="Tool Button">
       <create-editable-function>glade_gtk_tool_button_create_editable</create-editable-function>
@@ -675,7 +735,8 @@ embedded in another object</_tooltip>
     
     <glade-widget-class name="GtkRadioToolButton" generic-name="radiotoolbutton" _title="Radio Tool Button"/>
     
-    <glade-widget-class name="GtkMenuToolButton" generic-name="menutoolbutton" _title="Menu Tool Button">
+    <glade-widget-class name="GtkMenuToolButton" generic-name="menutoolbutton" use-placeholders="False"
+			_title="Menu Tool Button">
       <add-child-function>glade_gtk_menu_tool_button_add_child</add-child-function>
       <remove-child-function>glade_gtk_menu_tool_button_remove_child</remove-child-function>
       <get-children-function>glade_gtk_menu_tool_button_get_children</get-children-function>
@@ -3444,6 +3505,7 @@ embedded in another object</_tooltip>
     <glade-widget-class-ref name="GtkAspectFrame"/>
     <glade-widget-class-ref name="GtkMenuBar"/>
     <glade-widget-class-ref name="GtkToolbar"/>
+    <glade-widget-class-ref name="GtkToolPalette"/>
     <glade-widget-class-ref name="GtkHPaned"/>
     <glade-widget-class-ref name="GtkVPaned"/>
     <glade-widget-class-ref name="GtkHButtonBox"/>



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