summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <jpu@src.gnome.org>2007-06-27 20:23:01 +0000
committerJuan Pablo Ugarte <jpu@src.gnome.org>2007-06-27 20:23:01 +0000
commit312c7bca0c37850f374625633a313e09e04db6b8 (patch)
treeab72bc493b62624f8478c5dec0bd6873d9669992
parent7b0823643b71f0cd8e4c9fb194e2ca9c2ff0f7ec (diff)
downloadglade-312c7bca0c37850f374625633a313e09e04db6b8.tar.gz
gladeui/glade-popup.[ch] - added packing actions to placeholders
* gladeui/glade-popup.[ch] - added packing actions to placeholders * gladeui/glade-widget-action.[ch]: added "important" flag to GWActionClass * gladeui/glade-widget-adaptor.[ch]: - parse important tag in gwa_action_update_from_node() - added new "important" parameter to glade_widget_adaptor_pack_action_add() and glade_widget_adaptor_action_add() * gladeui/glade-xml-utils.h: addded GLADE_TAG_IMPORTANT tag * plugins/gtk+/gtk+.xml.in: marked launch_editor actions as important * gladeui/glade-inspector.c: make inspector popup include only normal actions. * src/glade-project-window.c: added important actions to the toolbar. svn path=/trunk/; revision=1403
-rw-r--r--ChangeLog21
-rw-r--r--gladeui/glade-inspector.c5
-rw-r--r--gladeui/glade-popup.c18
-rw-r--r--gladeui/glade-popup.h18
-rw-r--r--gladeui/glade-widget-action.c1
-rw-r--r--gladeui/glade-widget-action.h2
-rw-r--r--gladeui/glade-widget-adaptor.c28
-rw-r--r--gladeui/glade-widget-adaptor.h6
-rw-r--r--gladeui/glade-widget.c4
-rw-r--r--gladeui/glade-xml-utils.h1
-rw-r--r--plugins/gtk+/gtk+.xml.in8
-rw-r--r--src/glade-project-window.c113
12 files changed, 192 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index bdb8c6dc..ad95b519 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2007-06-27 Juan Pablo Ugarte <juanpablougarte@gmail.com>
+
+ * gladeui/glade-popup.[ch]
+ - added packing actions to placeholders
+
+ * gladeui/glade-widget-action.[ch]: added "important" flag to GWActionClass
+
+ * gladeui/glade-widget-adaptor.[ch]:
+ - parse important tag in gwa_action_update_from_node()
+
+ - added new "important" parameter to glade_widget_adaptor_pack_action_add() and
+ glade_widget_adaptor_action_add()
+
+ * gladeui/glade-xml-utils.h: addded GLADE_TAG_IMPORTANT tag
+
+ * plugins/gtk+/gtk+.xml.in: marked launch_editor actions as important
+
+ * gladeui/glade-inspector.c: make inspector popup include only normal actions.
+
+ * src/glade-project-window.c: added important actions to the toolbar.
+
2007-06-26 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* gladeui/glade-property-class.c: print a message for missing displayable values in
diff --git a/gladeui/glade-inspector.c b/gladeui/glade-inspector.c
index 5d271b66..4d1d9a59 100644
--- a/gladeui/glade-inspector.c
+++ b/gladeui/glade-inspector.c
@@ -525,10 +525,9 @@ button_press_cb (GtkWidget *widget,
*/
gtk_tree_model_get (GTK_TREE_MODEL (inspector->priv->model), &iter,
WIDGET_COLUMN, &widget, -1);
- if (widget != NULL &&
- event->button == 3)
+ if (widget != NULL && event->button == 3)
{
- glade_popup_widget_pop (widget, event);
+ glade_popup_widget_pop (widget, event, FALSE);
handled = TRUE;
}
gtk_tree_path_free (path);
diff --git a/gladeui/glade-popup.c b/gladeui/glade-popup.c
index 7264af2c..b4416eef 100644
--- a/gladeui/glade-popup.c
+++ b/gladeui/glade-popup.c
@@ -261,6 +261,7 @@ glade_popup_action_populate_menu_real (GtkWidget *menu,
* @menu: a GtkMenu to put the actions menu items.
* @widget: A #GladeWidget
* @action: a @widget subaction or NULL to include all actions.
+ * @packing: TRUE to include packing actions
*
* Populate a GtkMenu with widget's actions
*
@@ -269,7 +270,8 @@ glade_popup_action_populate_menu_real (GtkWidget *menu,
gint
glade_popup_action_populate_menu (GtkWidget *menu,
GladeWidget *widget,
- GladeWidgetAction *action)
+ GladeWidgetAction *action,
+ gboolean packing)
{
gint n;
@@ -299,7 +301,7 @@ glade_popup_action_populate_menu (GtkWidget *menu,
G_CALLBACK (glade_popup_menuitem_activated),
widget);
- if (widget->packing_actions)
+ if (packing && widget->packing_actions)
{
if (n)
{
@@ -317,7 +319,7 @@ glade_popup_action_populate_menu (GtkWidget *menu,
}
static GtkWidget *
-glade_popup_create_menu (GladeWidget *widget)
+glade_popup_create_menu (GladeWidget *widget, gboolean packing)
{
GtkWidget *popup_menu;
gboolean sensitive;
@@ -338,13 +340,13 @@ glade_popup_create_menu (GladeWidget *widget)
glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, TRUE,
glade_popup_delete_cb, widget);
- if (widget->actions || widget->packing_actions)
+ if (widget->actions || (packing && widget->packing_actions))
{
GtkWidget *separator = gtk_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator);
gtk_widget_show (separator);
- glade_popup_action_populate_menu (popup_menu, widget, NULL);
+ glade_popup_action_populate_menu (popup_menu, widget, NULL, packing);
}
return popup_menu;
@@ -399,7 +401,9 @@ glade_popup_create_clipboard_menu (GladeWidget *widget)
}
void
-glade_popup_widget_pop (GladeWidget *widget, GdkEventButton *event)
+glade_popup_widget_pop (GladeWidget *widget,
+ GdkEventButton *event,
+ gboolean packing)
{
GtkWidget *popup_menu;
gint button;
@@ -407,7 +411,7 @@ glade_popup_widget_pop (GladeWidget *widget, GdkEventButton *event)
g_return_if_fail (GLADE_IS_WIDGET (widget));
- popup_menu = glade_popup_create_menu (widget);
+ popup_menu = glade_popup_create_menu (widget, packing);
if (event)
{
diff --git a/gladeui/glade-popup.h b/gladeui/glade-popup.h
index 8a1025ef..313240b7 100644
--- a/gladeui/glade-popup.h
+++ b/gladeui/glade-popup.h
@@ -4,10 +4,20 @@
G_BEGIN_DECLS
-void glade_popup_widget_pop (GladeWidget *widget, GdkEventButton *event);
-void glade_popup_placeholder_pop (GladePlaceholder *placeholder, GdkEventButton *event);
-void glade_popup_clipboard_pop (GladeWidget *widget, GdkEventButton *event);
-gint glade_popup_action_populate_menu (GtkWidget *menu, GladeWidget *widget, GladeWidgetAction *action);
+void glade_popup_widget_pop (GladeWidget *widget,
+ GdkEventButton *event,
+ gboolean packing);
+
+void glade_popup_placeholder_pop (GladePlaceholder *placeholder,
+ GdkEventButton *event);
+
+void glade_popup_clipboard_pop (GladeWidget *widget,
+ GdkEventButton *event);
+
+gint glade_popup_action_populate_menu (GtkWidget *menu,
+ GladeWidget *widget,
+ GladeWidgetAction *action,
+ gboolean packing);
G_END_DECLS
diff --git a/gladeui/glade-widget-action.c b/gladeui/glade-widget-action.c
index 443a2bb0..a041e2a5 100644
--- a/gladeui/glade-widget-action.c
+++ b/gladeui/glade-widget-action.c
@@ -199,6 +199,7 @@ glade_widget_action_class_clone (GWActionClass *action)
copy->path = g_strdup (action->path);
copy->label = g_strdup (action->label);
copy->stock = g_strdup (action->stock);
+ copy->important = action->important;
/* id points to path! */
copy->id = copy->path + (action->id - action->path);
diff --git a/gladeui/glade-widget-action.h b/gladeui/glade-widget-action.h
index ca76716c..7cb66606 100644
--- a/gladeui/glade-widget-action.h
+++ b/gladeui/glade-widget-action.h
@@ -45,6 +45,8 @@ struct _GWActionClass
gchar *label; /* A translated label to show in the UI for this action */
gchar *stock; /* If set, this stock item will be shown in the UI along side
* the label */
+ gboolean important; /* If this action is important */
+
GList *actions; /* Recursive list of child actions */
};
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index 6b7cd74f..5246f129 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -1324,7 +1324,7 @@ gwa_action_update_from_node (GladeWidgetAdaptor *adaptor,
{
GladeXmlNode *child;
gchar *id, *label, *stock, *action_path;
- gboolean group;
+ gboolean group, important;
for (child = glade_xml_node_get_children (node);
child; child = glade_xml_node_next (child))
@@ -1344,11 +1344,12 @@ gwa_action_update_from_node (GladeWidgetAdaptor *adaptor,
label = glade_xml_get_property_string (child, GLADE_TAG_NAME);
stock = glade_xml_get_property_string (child, GLADE_TAG_STOCK);
-
+ important = glade_xml_get_property_boolean (child, GLADE_TAG_IMPORTANT, FALSE);
+
if (is_packing)
- glade_widget_adaptor_pack_action_add (adaptor, action_path, label, stock);
+ glade_widget_adaptor_pack_action_add (adaptor, action_path, label, stock, important);
else
- glade_widget_adaptor_action_add (adaptor, action_path, label, stock);
+ glade_widget_adaptor_action_add (adaptor, action_path, label, stock, important);
if (group) gwa_action_update_from_node (adaptor, is_packing, child, action_path);
@@ -2428,7 +2429,8 @@ static gboolean
glade_widget_adaptor_action_add_real (GList **list,
const gchar *action_path,
const gchar *label,
- const gchar *stock)
+ const gchar *stock,
+ gboolean important)
{
GWActionClass *action, *group;
const gchar *id;
@@ -2468,6 +2470,8 @@ glade_widget_adaptor_action_add_real (GList **list,
action->stock = (stock) ? g_strdup (stock) : NULL;
}
+ action->important = important;
+
*list = g_list_append (*list, action);
return TRUE;
@@ -2479,6 +2483,7 @@ glade_widget_adaptor_action_add_real (GList **list,
* @action_path: The identifier of this action in the action tree
* @label: A translated label to show in the UI for this action
* @stock: If set, this stock item will be shown in the UI along side the label.
+ * @important: if this action is important.
*
* Add an action to @adaptor.
* If the action is present then it overrides label and stock
@@ -2489,7 +2494,8 @@ gboolean
glade_widget_adaptor_action_add (GladeWidgetAdaptor *adaptor,
const gchar *action_path,
const gchar *label,
- const gchar *stock)
+ const gchar *stock,
+ gboolean important)
{
g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE);
g_return_val_if_fail (action_path != NULL, FALSE);
@@ -2497,7 +2503,8 @@ glade_widget_adaptor_action_add (GladeWidgetAdaptor *adaptor,
return glade_widget_adaptor_action_add_real (&adaptor->actions,
action_path,
label,
- stock);
+ stock,
+ important);
}
/**
@@ -2506,6 +2513,7 @@ glade_widget_adaptor_action_add (GladeWidgetAdaptor *adaptor,
* @action_path: The identifier of this action in the action tree
* @label: A translated label to show in the UI for this action
* @stock: If set, this stock item will be shown in the UI along side the label.
+ * @important: if this action is important.
*
* Add a packing action to @adaptor.
* If the action is present then it overrides label and stock
@@ -2516,7 +2524,8 @@ gboolean
glade_widget_adaptor_pack_action_add (GladeWidgetAdaptor *adaptor,
const gchar *action_path,
const gchar *label,
- const gchar *stock)
+ const gchar *stock,
+ gboolean important)
{
g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE);
g_return_val_if_fail (action_path != NULL, FALSE);
@@ -2524,7 +2533,8 @@ glade_widget_adaptor_pack_action_add (GladeWidgetAdaptor *adaptor,
return glade_widget_adaptor_action_add_real (&adaptor->packing_actions,
action_path,
label,
- stock);
+ stock,
+ important);
}
static gboolean
diff --git a/gladeui/glade-widget-adaptor.h b/gladeui/glade-widget-adaptor.h
index e063f859..b876f4d6 100644
--- a/gladeui/glade-widget-adaptor.h
+++ b/gladeui/glade-widget-adaptor.h
@@ -590,12 +590,14 @@ gboolean glade_widget_adaptor_is_container (GladeWidgetAdaptor
gboolean glade_widget_adaptor_action_add (GladeWidgetAdaptor *adaptor,
const gchar *action_path,
const gchar *label,
- const gchar *stock);
+ const gchar *stock,
+ gboolean important);
gboolean glade_widget_adaptor_pack_action_add (GladeWidgetAdaptor *adaptor,
const gchar *action_path,
const gchar *label,
- const gchar *stock);
+ const gchar *stock,
+ gboolean important);
gboolean glade_widget_adaptor_action_remove (GladeWidgetAdaptor *adaptor,
const gchar *action_path);
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index 465c5cc6..892fe09b 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -317,7 +317,7 @@ glade_widget_button_press_event_impl (GladeWidget *gwidget,
}
else if (event->button == 3)
{
- glade_popup_widget_pop (gwidget, event);
+ glade_popup_widget_pop (gwidget, event, TRUE);
handled = TRUE;
}
@@ -3961,7 +3961,7 @@ glade_widget_create_action_menu (GladeWidget *widget, const gchar *action_path)
}
menu = gtk_menu_new ();
- if (glade_popup_action_populate_menu (menu, widget, action))
+ if (glade_popup_action_populate_menu (menu, widget, action, TRUE))
return menu;
g_object_unref (G_OBJECT (menu));
diff --git a/gladeui/glade-xml-utils.h b/gladeui/glade-xml-utils.h
index 2311460d..42651f55 100644
--- a/gladeui/glade-xml-utils.h
+++ b/gladeui/glade-xml-utils.h
@@ -116,6 +116,7 @@ typedef struct _GladeXmlDoc GladeXmlDoc;
#define GLADE_TAG_NO "No"
#define GLADE_TAG_ICON_PREFIX "icon-prefix"
#define GLADE_TAG_ICON_NAME "icon-name"
+#define GLADE_TAG_IMPORTANT "important"
#define GLADE_ENUM_DATA_TAG "GladeEnumDataTag"
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 6fda04e6..46f16e46 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -315,7 +315,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>
<actions>
- <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit"/>
+ <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
<properties>
<property id="label" _name="Label" translatable="True">
@@ -378,7 +378,7 @@ embedded in another object</_tooltip>
<post-create-function>glade_gtk_menu_bar_post_create</post-create-function>
<!-- menubar is a container you can't add placeholders to it -->
<actions>
- <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit"/>
+ <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
<properties>
<property id="child-pack-direction">
@@ -414,7 +414,7 @@ embedded in another object</_tooltip>
<action-activate-function>glade_gtk_toolbar_action_activate</action-activate-function>
<actions>
- <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit"/>
+ <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
<properties>
<property id="orientation">
@@ -1077,7 +1077,7 @@ embedded in another object</_tooltip>
<!-- We do not want glade_gtk_container_post_create be executed -->
<post-create-function>empty</post-create-function>
<actions>
- <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit"/>
+ <action id="launch_editor" _name="Edit&#8230;" stock="gtk-edit" important="True"/>
</actions>
</glade-widget-class>
diff --git a/src/glade-project-window.c b/src/glade-project-window.c
index 5c5a87e9..3714f16d 100644
--- a/src/glade-project-window.c
+++ b/src/glade-project-window.c
@@ -30,6 +30,7 @@
#include <gladeui/glade.h>
#include <gladeui/glade-design-view.h>
#include <gladeui/glade-binding.h>
+#include <gladeui/glade-popup.h>
#include <gladeui/glade-inspector.h>
#include <string.h>
@@ -89,6 +90,9 @@ struct _GladeProjectWindowPrivate
GtkToolItem *undo; /* customized buttons for undo/redo with history */
GtkToolItem *redo;
+
+ GtkWidget *toolbar; /* Actions are added to the toolbar */
+ gint actions_start; /* start of action items */
};
static GladeAppClass *parent_class = NULL;
@@ -494,6 +498,107 @@ gpw_window_screen_changed_cb (GtkWidget *widget,
}
static void
+glade_project_window_activate_action (GtkToolButton *toolbutton,
+ GladeWidgetAction *action)
+{
+ GladeWidget *widget;
+
+ if ((widget = g_object_get_data (G_OBJECT (toolbutton), "glade-widget")))
+ glade_widget_adaptor_action_activate (widget->adaptor,
+ widget->object,
+ action->klass->path);
+}
+
+static void
+glade_project_window_action_notify_sensitive (GObject *gobject,
+ GParamSpec *arg1,
+ GtkWidget *item)
+{
+ GladeWidgetAction *action = GLADE_WIDGET_ACTION (gobject);
+ gtk_widget_set_sensitive (item, action->sensitive);
+}
+
+static void
+glade_project_window_action_disconnect (gpointer data, GClosure *closure)
+{
+ g_signal_handlers_disconnect_matched (data, G_SIGNAL_MATCH_FUNC,
+ 0, 0, NULL,
+ glade_project_window_action_notify_sensitive,
+ NULL);
+}
+
+static void
+glade_project_window_clean_actions (GladeProjectWindow *gpw)
+{
+ GtkContainer *container = GTK_CONTAINER (gpw->priv->toolbar);
+ GtkToolbar *bar = GTK_TOOLBAR (gpw->priv->toolbar);
+ GtkToolItem *item;
+
+ if (gpw->priv->actions_start)
+ {
+ while ((item = gtk_toolbar_get_nth_item (bar, gpw->priv->actions_start)))
+ gtk_container_remove (container, GTK_WIDGET (item));
+ }
+}
+
+static void
+glade_project_window_add_actions (GladeProjectWindow *gpw,
+ GladeWidget *widget,
+ GList *actions)
+{
+ GtkToolbar *bar = GTK_TOOLBAR (gpw->priv->toolbar);
+ GtkToolItem *item = gtk_separator_tool_item_new ();
+ gint n = 0;
+ GList *l;
+
+ gtk_toolbar_insert (bar, item, -1);
+ gtk_widget_show (GTK_WIDGET (item));
+
+ if (gpw->priv->actions_start == 0)
+ gpw->priv->actions_start = gtk_toolbar_get_item_index (bar, item);
+
+ for (l = actions; l; l = g_list_next (l))
+ {
+ GladeWidgetAction *a = l->data;
+
+ if (!a->klass->important) continue;
+
+ if (a->actions)
+ {
+ g_warning ("Trying to add a group action to the toolbar is unsupported");
+ continue;
+ }
+
+ item = gtk_tool_button_new_from_stock ((a->klass->stock) ? a->klass->stock : "gtk-execute");
+ if (a->klass->label)
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON (item),
+ a->klass->label);
+
+ g_object_set_data (G_OBJECT (item), "glade-widget", widget);
+ /* We use destroy_data to keep track of notify::sensitive callbacks
+ * on the action object and disconnect them when the toolbar item
+ * gets destroyed.
+ */
+ g_signal_connect_data (item, "clicked",
+ G_CALLBACK (glade_project_window_activate_action),
+ a, glade_project_window_action_disconnect, 0);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (item), a->sensitive);
+
+ g_signal_connect (a, "notify::sensitive",
+ G_CALLBACK (glade_project_window_activate_action),
+ GTK_WIDGET (item));
+
+ gtk_toolbar_insert (bar, item, -1);
+ gtk_tool_item_set_homogeneous (item, FALSE);
+ gtk_widget_show (GTK_WIDGET (item));
+ n++;
+ }
+
+ if (n == 0) glade_project_window_clean_actions (gpw);
+}
+
+static void
project_selection_changed_cb (GladeProject *project, GladeProjectWindow *gpw)
{
GladeWidget *glade_widget = NULL;
@@ -528,12 +633,15 @@ project_selection_changed_cb (GladeProject *project, GladeProjectWindow *gpw)
gtk_label_set_text (label, text);
g_free (text);
+ glade_project_window_clean_actions (gpw);
+ if (glade_widget->actions)
+ glade_project_window_add_actions (gpw, glade_widget,
+ glade_widget->actions);
}
else
{
gtk_label_set_text (label, _("Properties"));
}
-
}
}
@@ -2271,9 +2379,10 @@ glade_project_window_create (GladeProjectWindow *gpw)
gtk_widget_show (menubar);
/* toolbar */
- toolbar = gtk_ui_manager_get_widget (gpw->priv->ui, "/ToolBar");
+ gpw->priv->toolbar = toolbar = gtk_ui_manager_get_widget (gpw->priv->ui, "/ToolBar");
gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0);
gtk_widget_show (toolbar);
+ gpw->priv->actions_start = 0;
/* tooltips object */
gpw->priv->tooltips = gtk_tooltips_new ();