Commit 312c7bca authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

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
parent 7b082364
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
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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
......
......@@ -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);
......
......@@ -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 */
};
......
......@@ -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
......
......@@ -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);
......
......@@ -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));
......
......@@ -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"
......
......@@ -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>
......
......@@ -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;
......@@ -493,6 +497,107 @@ gpw_window_screen_changed_cb (GtkWidget *widget,
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), gpw->priv->recent_menu);
}
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)
{
......@@ -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 ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment