added signal "update" which is G_SIGNAL_RUN_LAST, so handlers can hook in

2004-04-30  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpuimanager.[ch]: added signal "update" which
	is G_SIGNAL_RUN_LAST, so handlers can hook in before and after
	the default implementation. Update the action groups
	in the default implementations.

	(gimp_ui_manager_ui_get): make sure we always return a widget
	by calling gtk_ui_manager_ensure_update().

	* app/widgets/gimpdockable.c (gimp_dockable_show_menu): make
	sure the dockable menu is loaded before trying to access its
	widgets/actions.

	Resurrected the dynamic tool options menus:

	* app/actions/tool-options-actions.c: dynamically destroy/create
	actions for the tool options' presets.

	* app/actions/tool-options-commands.[ch]: all callbacks are
	GimpEnumAction::selected() callbacks now.

	* app/gui/tool-options-menu.[ch]: connect and connect_after to
	GimpUIManager::update(). Remove the old preset menu items
	in the former callback, create the new ones in the latter.
	Removed the last item factory entries.

	* app/gui/menus.c
	* app/widgets/gimptooloptionseditor.c: changed accordingly.
This commit is contained in:
Michael Natterer
2004-04-30 15:29:11 +00:00
committed by Michael Natterer
parent 9f5496147d
commit 7d7ef188fa
14 changed files with 422 additions and 505 deletions

View File

@ -1,3 +1,33 @@
2004-04-30 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpuimanager.[ch]: added signal "update" which
is G_SIGNAL_RUN_LAST, so handlers can hook in before and after
the default implementation. Update the action groups
in the default implementations.
(gimp_ui_manager_ui_get): make sure we always return a widget
by calling gtk_ui_manager_ensure_update().
* app/widgets/gimpdockable.c (gimp_dockable_show_menu): make
sure the dockable menu is loaded before trying to access its
widgets/actions.
Resurrected the dynamic tool options menus:
* app/actions/tool-options-actions.c: dynamically destroy/create
actions for the tool options' presets.
* app/actions/tool-options-commands.[ch]: all callbacks are
GimpEnumAction::selected() callbacks now.
* app/gui/tool-options-menu.[ch]: connect and connect_after to
GimpUIManager::update(). Remove the old preset menu items
in the former callback, create the new ones in the latter.
Removed the last item factory entries.
* app/gui/menus.c
* app/widgets/gimptooloptionseditor.c: changed accordingly.
2004-04-29 Simon Budig <simon@gimp.org>
* app/main.c: when glibc is used, call mallopt, so that memory

View File

@ -41,8 +41,7 @@
/* local function prototypes */
static void tool_options_actions_update_presets (GimpActionGroup *group,
const gchar *menu,
gint keep_n,
const gchar *action_prefix,
GCallback callback,
const gchar *stock_id,
const gchar *help_id,
@ -81,8 +80,6 @@ static GimpActionEntry tool_options_actions[] =
#define SET_VISIBLE(action,condition) \
gimp_action_group_set_action_visible (group, action, (condition) != 0)
#define SET_SENSITIVE(action,condition) \
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
#define SET_IMPORTANT(action,condition) \
gimp_action_group_set_action_important (group, action, (condition) != 0)
@ -113,28 +110,25 @@ tool_options_actions_update (GimpActionGroup *group,
SET_VISIBLE ("tool-options-rename-menu", tool_info->options_presets);
SET_VISIBLE ("tool-options-delete-menu", tool_info->options_presets);
if (! tool_info->options_presets)
return;
tool_options_actions_update_presets (group, "tool-options-save-menu", 2,
tool_options_actions_update_presets (group, "tool-options-save-",
G_CALLBACK (tool_options_save_to_cmd_callback),
GTK_STOCK_SAVE,
GIMP_HELP_TOOL_OPTIONS_SAVE,
tool_info->options_presets);
tool_options_actions_update_presets (group, "tool-options-restore-menu", 1,
tool_options_actions_update_presets (group, "tool-options-restore-",
G_CALLBACK (tool_options_restore_from_cmd_callback),
GTK_STOCK_REVERT_TO_SAVED,
GIMP_HELP_TOOL_OPTIONS_RESTORE,
tool_info->options_presets);
tool_options_actions_update_presets (group, "tool-options-rename-menu", 1,
tool_options_actions_update_presets (group, "tool-options-rename-",
G_CALLBACK (tool_options_rename_saved_cmd_callback),
GIMP_STOCK_EDIT,
GIMP_HELP_TOOL_OPTIONS_RENAME,
tool_info->options_presets);
tool_options_actions_update_presets (group, "tool-options-delete-menu", 1,
tool_options_actions_update_presets (group, "tool-options-delete-",
G_CALLBACK (tool_options_delete_saved_cmd_callback),
GTK_STOCK_DELETE,
GIMP_HELP_TOOL_OPTIONS_DELETE,
@ -146,61 +140,63 @@ tool_options_actions_update (GimpActionGroup *group,
static void
tool_options_actions_update_presets (GimpActionGroup *group,
const gchar *menu,
gint keep_n,
const gchar *action_prefix,
GCallback callback,
const gchar *stock_id,
const gchar *help_id,
GimpContainer *presets)
{
#if 0
GtkWidget *menu;
menu = gtk_item_factory_get_widget (factory, menu);
if (menu)
{
GList *list;
gint num_children;
gint n_children = 0;
gint i;
list = g_list_nth (GTK_MENU_SHELL (menu)->children, keep_n - 1);
while (g_list_next (list))
gtk_widget_destroy (g_list_next (list)->data);
num_children = gimp_container_num_children (presets);
if (num_children > 0)
for (i = 0; ; i++)
{
GimpItemFactoryEntry entry;
gchar *action_name;
GtkAction *action;
entry.entry.path = NULL;
entry.entry.accelerator = "";
entry.entry.callback = callback;
entry.entry.callback_action = 0;
entry.entry.item_type = stock_id ? "<StockItem>" : "<Item>";
entry.entry.extra_data = stock_id;
entry.quark_string = NULL;
action_name = g_strdup_printf ("%s%03d", action_prefix, i);
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
action_name);
g_free (action_name);
if (! action)
break;
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
}
if (presets)
n_children = gimp_container_num_children (presets);
if (n_children > 0)
{
GimpEnumActionEntry entry;
entry.name = NULL;
entry.stock_id = stock_id;
entry.label = NULL;
entry.accelerator = "";
entry.tooltip = NULL;
entry.value = 0;
entry.help_id = help_id;
entry.description = NULL;
for (list = GIMP_LIST (presets)->list;
for (list = GIMP_LIST (presets)->list, i = 0;
list;
list = g_list_next (list))
list = g_list_next (list), i++)
{
GimpToolOptions *options = list->data;
entry.entry.path = g_strdup_printf ("%s/%s",
menu_path,
GIMP_OBJECT (options)->name);
gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory),
&entry, NULL,
options, 2, FALSE);
g_free (entry.entry.path);
entry.name = g_strdup_printf ("%s%03d", action_prefix, i);
entry.label = gimp_object_get_name (GIMP_OBJECT (options));
entry.value = i;
gimp_action_group_add_enum_actions (group, &entry, 1, callback);
g_free ((gchar *) entry.name);
}
}
}
#endif
}
#undef SET_SENSITIVE
#undef SET_VISIBLE
#undef SET_IMPORTANT

View File

@ -56,29 +56,13 @@ static void tool_options_rename_callback (GtkWidget *widget,
/* public functions */
void
tool_options_save_to_cmd_callback (GtkAction *action,
gpointer data)
{
GimpToolOptions *options = GIMP_TOOL_OPTIONS (data);
gchar *name;
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (options)));
gimp_config_sync (GIMP_CONFIG (options->tool_info->tool_options),
GIMP_CONFIG (options), 0);
gimp_object_set_name (GIMP_OBJECT (options), name);
g_free (name);
}
void
tool_options_save_new_cmd_callback (GtkAction *action,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context;
GimpToolInfo *tool_info;
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GtkWidget *qbox;
context = gimp_get_user_context (editor->ui_manager->gimp);
@ -96,20 +80,65 @@ tool_options_save_new_cmd_callback (GtkAction *action,
}
void
tool_options_restore_from_cmd_callback (GtkAction *action,
tool_options_save_to_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpToolOptions *options = GIMP_TOOL_OPTIONS (data);
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolOptions *options;
options = (GimpToolOptions *)
gimp_container_get_child_by_index (tool_info->options_presets, value);
if (options)
{
gchar *name;
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (options)));
gimp_config_sync (GIMP_CONFIG (tool_info->tool_options),
GIMP_CONFIG (options), 0);
gimp_object_set_name (GIMP_OBJECT (options), name);
g_free (name);
}
}
void
tool_options_restore_from_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolOptions *options;
options = (GimpToolOptions *)
gimp_container_get_child_by_index (tool_info->options_presets, value);
if (options)
gimp_config_sync (GIMP_CONFIG (options),
GIMP_CONFIG (options->tool_info->tool_options), 0);
GIMP_CONFIG (tool_info->tool_options), 0);
}
void
tool_options_rename_saved_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpToolOptions *options = GIMP_TOOL_OPTIONS (data);
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolOptions *options;
options = (GimpToolOptions *)
gimp_container_get_child_by_index (tool_info->options_presets, value);
if (options)
{
GtkWidget *qbox;
qbox = gimp_query_string_box (_("Rename Saved Tool Options"),
@ -121,16 +150,24 @@ tool_options_rename_saved_cmd_callback (GtkAction *action,
NULL, NULL,
tool_options_rename_callback, options);
gtk_widget_show (qbox);
}
}
void
tool_options_delete_saved_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpToolOptions *options = GIMP_TOOL_OPTIONS (data);
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolOptions *options;
gimp_container_remove (options->tool_info->options_presets,
GIMP_OBJECT (options));
options = (GimpToolOptions *)
gimp_container_get_child_by_index (tool_info->options_presets, value);
if (options)
gimp_container_remove (tool_info->options_presets, GIMP_OBJECT (options));
}
void

View File

@ -20,16 +20,22 @@
#define __TOOL_OPTIONS_COMMANDS_H__
void tool_options_save_to_cmd_callback (GtkAction *action,
gpointer data);
void tool_options_save_new_cmd_callback (GtkAction *action,
gpointer data);
void tool_options_save_to_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void tool_options_restore_from_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void tool_options_rename_saved_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void tool_options_delete_saved_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void tool_options_reset_cmd_callback (GtkAction *action,
gpointer data);
void tool_options_reset_all_cmd_callback (GtkAction *action,

View File

@ -361,14 +361,14 @@ menus_init (Gimp *gimp)
gimp_menu_factory_menu_register (global_menu_factory, "<ToolOptions>",
_("Tool Options Menu"),
GIMP_HELP_TOOL_OPTIONS_DIALOG,
tool_options_menu_setup,
tool_options_menu_update, TRUE,
NULL, NULL, TRUE,
0, NULL);
gimp_menu_factory_manager_register (global_menu_factory, "<ToolOptions>",
"tool-options",
NULL,
"/tool-options-popup",
"tool-options-menu.xml", NULL,
"tool-options-menu.xml",
tool_options_menu_setup,
NULL);
}

View File

@ -30,222 +30,135 @@
#include "core/gimptoolinfo.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpuimanager.h"
#include "actions/tool-options-commands.h"
#include "menus.h"
#include "tool-options-menu.h"
#include "gimp-intl.h"
#define MENU_BRANCH(path) \
{ { (path), NULL, NULL, 0, "<Branch>" }, NULL, NULL, NULL }
/* local function prototypes */
static void tool_options_menu_update_presets (GtkItemFactory *factory,
static void tool_options_menu_update (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path);
static void tool_options_menu_update_after (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path);
static void tool_options_menu_update_presets (GimpUIManager *manager,
guint merge_id,
const gchar *ui_path,
const gchar *menu_path,
gint keep_n,
gboolean has_none,
GtkItemFactoryCallback callback,
const gchar *stock_id,
const gchar *help_id,
const gchar *action_prefix,
GimpContainer *presets);
/* global variables */
GimpItemFactoryEntry tool_options_menu_entries[] =
{
MENU_BRANCH (N_("/_Save Options to")),
{ { N_("/Save Options to/_New Entry..."), "",
tool_options_save_new_cmd_callback, 0,
"<StockItem>", GTK_STOCK_NEW },
NULL,
GIMP_HELP_TOOL_OPTIONS_SAVE, NULL },
{ { "/Save Options to/new-separator", "",
NULL, 0,
"<Separator>", NULL },
NULL,
NULL, NULL },
MENU_BRANCH (N_("/_Restore Options from")),
{ { N_("/Restore Options from/(None)"), "",
NULL, 0,
"<Item>", NULL },
NULL,
NULL, NULL },
MENU_BRANCH (N_("/Re_name Saved Options")),
{ { N_("/Rename Saved Options/(None)"), "",
NULL, 0,
"<Item>", NULL },
NULL,
NULL, NULL },
MENU_BRANCH (N_("/_Delete Saved Options")),
{ { N_("/Delete Saved Options/(None)"), "",
NULL, 0,
"<Item>", NULL },
NULL,
NULL, NULL },
{ { "/reset-separator", NULL, NULL, 0, "<Separator>", NULL },
NULL, NULL, NULL },
{ { N_("/R_eset Tool Options"), "",
tool_options_reset_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_RESET },
NULL,
GIMP_HELP_TOOL_OPTIONS_RESET, NULL },
{ { N_("/Reset _all Tool Options..."), "",
tool_options_reset_all_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_RESET },
NULL,
GIMP_HELP_TOOL_OPTIONS_RESET, NULL }
};
gint n_tool_options_menu_entries = G_N_ELEMENTS (tool_options_menu_entries);
/* public functions */
void
tool_options_menu_setup (GimpItemFactory *factory,
gpointer callback_data)
tool_options_menu_setup (GimpUIManager *manager,
const gchar *ui_path)
{
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (factory),
"/Restore Options from/(None)", FALSE);
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (factory),
"/Rename Saved Options/(None)", FALSE);
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (factory),
"/Delete Saved Options/(None)", FALSE);
g_signal_connect (manager, "update",
G_CALLBACK (tool_options_menu_update),
ui_path);
g_signal_connect_after (manager, "update",
G_CALLBACK (tool_options_menu_update_after),
ui_path);
}
#define SET_VISIBLE(menu,condition) \
gimp_item_factory_set_visible (factory, menu, (condition) != 0)
void
tool_options_menu_update (GtkItemFactory *factory,
gpointer data)
/* private functions */
static void
tool_options_menu_update (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
guint merge_id;
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
"tool-options-merge-id"));
if (merge_id)
{
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager), merge_id);
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
GINT_TO_POINTER (0));
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
}
}
static void
tool_options_menu_update_after (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
GimpContext *context;
GimpToolInfo *tool_info;
guint merge_id;
context = gimp_get_user_context (GIMP_ITEM_FACTORY (factory)->gimp);
context = gimp_get_user_context (manager->gimp);
tool_info = gimp_context_get_tool (context);
SET_VISIBLE ("/Save Options to", tool_info->options_presets);
SET_VISIBLE ("/Restore Options from", tool_info->options_presets);
SET_VISIBLE ("/Rename Saved Options", tool_info->options_presets);
SET_VISIBLE ("/Delete Saved Options", tool_info->options_presets);
SET_VISIBLE ("/reset-separator", tool_info->options_presets);
if (! tool_info->options_presets)
return;
SET_VISIBLE ("/Save Options to/new-separator",
gimp_container_num_children (tool_info->options_presets) > 0);
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
tool_options_menu_update_presets (factory, "/Save Options to", 2, FALSE,
tool_options_save_to_cmd_callback,
GTK_STOCK_SAVE,
GIMP_HELP_TOOL_OPTIONS_SAVE,
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
GUINT_TO_POINTER (merge_id));
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-save-menu",
"tool-options-save-",
tool_info->options_presets);
tool_options_menu_update_presets (factory, "/Restore Options from", 1, TRUE,
tool_options_restore_from_cmd_callback,
GTK_STOCK_REVERT_TO_SAVED,
GIMP_HELP_TOOL_OPTIONS_RESTORE,
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-restore-menu",
"tool-options-restore-",
tool_info->options_presets);
tool_options_menu_update_presets (factory, "/Rename Saved Options", 1, TRUE,
tool_options_rename_saved_cmd_callback,
GIMP_STOCK_EDIT,
GIMP_HELP_TOOL_OPTIONS_RENAME,
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-rename-menu",
"tool-options-rename-",
tool_info->options_presets);
tool_options_menu_update_presets (factory, "/Delete Saved Options", 1, TRUE,
tool_options_delete_saved_cmd_callback,
GTK_STOCK_DELETE,
GIMP_HELP_TOOL_OPTIONS_DELETE,
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-delete-menu",
"tool-options-delete-",
tool_info->options_presets);
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
}
/* privat function */
static void
tool_options_menu_update_presets (GtkItemFactory *factory,
tool_options_menu_update_presets (GimpUIManager *manager,
guint merge_id,
const gchar *ui_path,
const gchar *menu_path,
gint keep_n,
gboolean has_none,
GtkItemFactoryCallback callback,
const gchar *stock_id,
const gchar *help_id,
const gchar *action_prefix,
GimpContainer *presets)
{
GtkWidget *menu;
gint n_children;
gint i;
menu = gtk_item_factory_get_widget (factory, menu_path);
n_children = gimp_container_num_children (presets);
if (menu)
for (i = 0; i < n_children; i++)
{
GList *list;
gint num_children;
gchar *action_name;
gchar *path;
list = g_list_nth (GTK_MENU_SHELL (menu)->children, keep_n - 1);
while (g_list_next (list))
gtk_widget_destroy (g_list_next (list)->data);
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
action_name = g_strdup_printf ("%s%03d", action_prefix, i);
num_children = gimp_container_num_children (presets);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
path, action_name, action_name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
if (has_none)
{
gchar *none;
none = g_strdup_printf ("%s/(None)", menu_path);
SET_VISIBLE (none, num_children == 0);
g_free (none);
}
if (num_children > 0)
{
GimpItemFactoryEntry entry;
entry.entry.path = NULL;
entry.entry.accelerator = "";
entry.entry.callback = callback;
entry.entry.callback_action = 0;
entry.entry.item_type = stock_id ? "<StockItem>" : "<Item>";
entry.entry.extra_data = stock_id;
entry.quark_string = NULL;
entry.help_id = help_id;
entry.description = NULL;
for (list = GIMP_LIST (presets)->list;
list;
list = g_list_next (list))
{
GimpToolOptions *options = list->data;
entry.entry.path = g_strdup_printf ("%s/%s",
menu_path,
GIMP_OBJECT (options)->name);
gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory),
&entry, NULL,
options, 2, FALSE);
g_free (entry.entry.path);
}
}
g_free (action_name);
g_free (path);
}
}
#undef SET_VISIBLE

View File

@ -20,14 +20,8 @@
#define __TOOL_OPTIONS_MENU_H__
extern GimpItemFactoryEntry tool_options_menu_entries[];
extern gint n_tool_options_menu_entries;
void tool_options_menu_setup (GimpItemFactory *factory,
gpointer callback_data);
void tool_options_menu_update (GtkItemFactory *factory,
gpointer update_data);
void tool_options_menu_setup (GimpUIManager *manager,
const gchar *ui_path);
#endif /* __TOOL_OPTIONS_MENU_H__ */

View File

@ -361,14 +361,14 @@ menus_init (Gimp *gimp)
gimp_menu_factory_menu_register (global_menu_factory, "<ToolOptions>",
_("Tool Options Menu"),
GIMP_HELP_TOOL_OPTIONS_DIALOG,
tool_options_menu_setup,
tool_options_menu_update, TRUE,
NULL, NULL, TRUE,
0, NULL);
gimp_menu_factory_manager_register (global_menu_factory, "<ToolOptions>",
"tool-options",
NULL,
"/tool-options-popup",
"tool-options-menu.xml", NULL,
"tool-options-menu.xml",
tool_options_menu_setup,
NULL);
}

View File

@ -30,222 +30,135 @@
#include "core/gimptoolinfo.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpuimanager.h"
#include "actions/tool-options-commands.h"
#include "menus.h"
#include "tool-options-menu.h"
#include "gimp-intl.h"
#define MENU_BRANCH(path) \
{ { (path), NULL, NULL, 0, "<Branch>" }, NULL, NULL, NULL }
/* local function prototypes */
static void tool_options_menu_update_presets (GtkItemFactory *factory,
static void tool_options_menu_update (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path);
static void tool_options_menu_update_after (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path);
static void tool_options_menu_update_presets (GimpUIManager *manager,
guint merge_id,
const gchar *ui_path,
const gchar *menu_path,
gint keep_n,
gboolean has_none,
GtkItemFactoryCallback callback,
const gchar *stock_id,
const gchar *help_id,
const gchar *action_prefix,
GimpContainer *presets);
/* global variables */
GimpItemFactoryEntry tool_options_menu_entries[] =
{
MENU_BRANCH (N_("/_Save Options to")),
{ { N_("/Save Options to/_New Entry..."), "",
tool_options_save_new_cmd_callback, 0,
"<StockItem>", GTK_STOCK_NEW },
NULL,
GIMP_HELP_TOOL_OPTIONS_SAVE, NULL },
{ { "/Save Options to/new-separator", "",
NULL, 0,
"<Separator>", NULL },
NULL,
NULL, NULL },
MENU_BRANCH (N_("/_Restore Options from")),
{ { N_("/Restore Options from/(None)"), "",
NULL, 0,
"<Item>", NULL },
NULL,
NULL, NULL },
MENU_BRANCH (N_("/Re_name Saved Options")),
{ { N_("/Rename Saved Options/(None)"), "",
NULL, 0,
"<Item>", NULL },
NULL,
NULL, NULL },
MENU_BRANCH (N_("/_Delete Saved Options")),
{ { N_("/Delete Saved Options/(None)"), "",
NULL, 0,
"<Item>", NULL },
NULL,
NULL, NULL },
{ { "/reset-separator", NULL, NULL, 0, "<Separator>", NULL },
NULL, NULL, NULL },
{ { N_("/R_eset Tool Options"), "",
tool_options_reset_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_RESET },
NULL,
GIMP_HELP_TOOL_OPTIONS_RESET, NULL },
{ { N_("/Reset _all Tool Options..."), "",
tool_options_reset_all_cmd_callback, 0,
"<StockItem>", GIMP_STOCK_RESET },
NULL,
GIMP_HELP_TOOL_OPTIONS_RESET, NULL }
};
gint n_tool_options_menu_entries = G_N_ELEMENTS (tool_options_menu_entries);
/* public functions */
void
tool_options_menu_setup (GimpItemFactory *factory,
gpointer callback_data)
tool_options_menu_setup (GimpUIManager *manager,
const gchar *ui_path)
{
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (factory),
"/Restore Options from/(None)", FALSE);
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (factory),
"/Rename Saved Options/(None)", FALSE);
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (factory),
"/Delete Saved Options/(None)", FALSE);
g_signal_connect (manager, "update",
G_CALLBACK (tool_options_menu_update),
ui_path);
g_signal_connect_after (manager, "update",
G_CALLBACK (tool_options_menu_update_after),
ui_path);
}
#define SET_VISIBLE(menu,condition) \
gimp_item_factory_set_visible (factory, menu, (condition) != 0)
void
tool_options_menu_update (GtkItemFactory *factory,
gpointer data)
/* private functions */
static void
tool_options_menu_update (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
guint merge_id;
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
"tool-options-merge-id"));
if (merge_id)
{
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager), merge_id);
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
GINT_TO_POINTER (0));
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
}
}
static void
tool_options_menu_update_after (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
GimpContext *context;
GimpToolInfo *tool_info;
guint merge_id;
context = gimp_get_user_context (GIMP_ITEM_FACTORY (factory)->gimp);
context = gimp_get_user_context (manager->gimp);
tool_info = gimp_context_get_tool (context);
SET_VISIBLE ("/Save Options to", tool_info->options_presets);
SET_VISIBLE ("/Restore Options from", tool_info->options_presets);
SET_VISIBLE ("/Rename Saved Options", tool_info->options_presets);
SET_VISIBLE ("/Delete Saved Options", tool_info->options_presets);
SET_VISIBLE ("/reset-separator", tool_info->options_presets);
if (! tool_info->options_presets)
return;
SET_VISIBLE ("/Save Options to/new-separator",
gimp_container_num_children (tool_info->options_presets) > 0);
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
tool_options_menu_update_presets (factory, "/Save Options to", 2, FALSE,
tool_options_save_to_cmd_callback,
GTK_STOCK_SAVE,
GIMP_HELP_TOOL_OPTIONS_SAVE,
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
GUINT_TO_POINTER (merge_id));
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-save-menu",
"tool-options-save-",
tool_info->options_presets);
tool_options_menu_update_presets (factory, "/Restore Options from", 1, TRUE,
tool_options_restore_from_cmd_callback,
GTK_STOCK_REVERT_TO_SAVED,
GIMP_HELP_TOOL_OPTIONS_RESTORE,
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-restore-menu",
"tool-options-restore-",
tool_info->options_presets);
tool_options_menu_update_presets (factory, "/Rename Saved Options", 1, TRUE,
tool_options_rename_saved_cmd_callback,
GIMP_STOCK_EDIT,
GIMP_HELP_TOOL_OPTIONS_RENAME,
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-rename-menu",
"tool-options-rename-",
tool_info->options_presets);
tool_options_menu_update_presets (factory, "/Delete Saved Options", 1, TRUE,
tool_options_delete_saved_cmd_callback,
GTK_STOCK_DELETE,
GIMP_HELP_TOOL_OPTIONS_DELETE,
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-delete-menu",
"tool-options-delete-",
tool_info->options_presets);
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
}
/* privat function */
static void
tool_options_menu_update_presets (GtkItemFactory *factory,
tool_options_menu_update_presets (GimpUIManager *manager,
guint merge_id,
const gchar *ui_path,
const gchar *menu_path,
gint keep_n,
gboolean has_none,
GtkItemFactoryCallback callback,
const gchar *stock_id,
const gchar *help_id,
const gchar *action_prefix,
GimpContainer *presets)
{
GtkWidget *menu;
gint n_children;
gint i;
menu = gtk_item_factory_get_widget (factory, menu_path);
n_children = gimp_container_num_children (presets);
if (menu)
for (i = 0; i < n_children; i++)
{
GList *list;
gint num_children;
gchar *action_name;
gchar *path;
list = g_list_nth (GTK_MENU_SHELL (menu)->children, keep_n - 1);
while (g_list_next (list))
gtk_widget_destroy (g_list_next (list)->data);
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
action_name = g_strdup_printf ("%s%03d", action_prefix, i);
num_children = gimp_container_num_children (presets);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
path, action_name, action_name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
if (has_none)
{
gchar *none;
none = g_strdup_printf ("%s/(None)", menu_path);
SET_VISIBLE (none, num_children == 0);
g_free (none);
}
if (num_children > 0)
{
GimpItemFactoryEntry entry;
entry.entry.path = NULL;
entry.entry.accelerator = "";
entry.entry.callback = callback;
entry.entry.callback_action = 0;
entry.entry.item_type = stock_id ? "<StockItem>" : "<Item>";
entry.entry.extra_data = stock_id;
entry.quark_string = NULL;
entry.help_id = help_id;
entry.description = NULL;
for (list = GIMP_LIST (presets)->list;
list;
list = g_list_next (list))
{
GimpToolOptions *options = list->data;
entry.entry.path = g_strdup_printf ("%s/%s",
menu_path,
GIMP_OBJECT (options)->name);
gimp_item_factory_create_item (GIMP_ITEM_FACTORY (factory),
&entry, NULL,
options, 2, FALSE);
g_free (entry.entry.path);
}
}
g_free (action_name);
g_free (path);
}
}
#undef SET_VISIBLE

View File

@ -20,14 +20,8 @@
#define __TOOL_OPTIONS_MENU_H__
extern GimpItemFactoryEntry tool_options_menu_entries[];
extern gint n_tool_options_menu_entries;
void tool_options_menu_setup (GimpItemFactory *factory,
gpointer callback_data);
void tool_options_menu_update (GtkItemFactory *factory,
gpointer update_data);
void tool_options_menu_setup (GimpUIManager *manager,
const gchar *ui_path);
#endif /* __TOOL_OPTIONS_MENU_H__ */

View File

@ -937,26 +937,35 @@ gimp_dockable_show_menu (GimpDockable *dockable)
if (! dockbook_ui_manager)
return FALSE;
gimp_ui_manager_ui_get (dockbook_ui_manager, "/dockable-popup");
dialog_ui_manager = gimp_dockable_get_menu (dockable,
&dialog_ui_path,
&dialog_popup_data);
if (dialog_ui_manager)
{
GtkAction *parent_menu_action;
GtkWidget *child_menu_widget;
GtkAction *child_menu_action;
GtkWidget *parent_menu_widget;
GtkWidget *child_menu_widget;
GtkAction *parent_menu_action;
const gchar *label;
parent_menu_action =
gtk_ui_manager_get_action (GTK_UI_MANAGER (dockbook_ui_manager),
"/dockable-popup/dockable-menu");
child_menu_widget =
gimp_ui_manager_ui_get (dialog_ui_manager, dialog_ui_path);
child_menu_action =
gtk_ui_manager_get_action (GTK_UI_MANAGER (dialog_ui_manager),
dialog_ui_path);
parent_menu_widget =
gtk_ui_manager_get_widget (GTK_UI_MANAGER (dockbook_ui_manager),
"/dockable-popup/dockable-menu");
parent_menu_action =
gtk_ui_manager_get_action (GTK_UI_MANAGER (dockbook_ui_manager),
"/dockable-popup/dockable-menu");
g_object_get (child_menu_action,
"label", &label,
NULL);
@ -967,13 +976,6 @@ gimp_dockable_show_menu (GimpDockable *dockable)
"visible", TRUE,
NULL);
parent_menu_widget =
gtk_ui_manager_get_widget (GTK_UI_MANAGER (dockbook_ui_manager),
"/dockable-popup/dockable-menu");
child_menu_widget =
gimp_ui_manager_ui_get (dialog_ui_manager, dialog_ui_path);
if (! GTK_IS_MENU (child_menu_widget))
{
g_warning ("%s: child_menu_widget (%p) is not a GtkMenu",

View File

@ -126,9 +126,7 @@ gimp_tool_options_editor_get_type (void)
static void
gimp_tool_options_editor_class_init (GimpToolOptionsEditorClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -318,29 +316,22 @@ gimp_tool_options_editor_menu_popup (GimpToolOptionsEditor *editor,
const gchar *path)
{
GimpEditor *gimp_editor = GIMP_EDITOR (editor);
GtkWidget *menu;
GtkWidget *menu_item;
gimp_ui_manager_update (gimp_editor->ui_manager,
gimp_editor->popup_data);
gimp_ui_manager_ui_popup (gimp_editor->ui_manager,
gimp_editor->ui_path,
gimp_editor->popup_data,
GTK_WIDGET (button),
NULL, NULL, NULL);
gimp_ui_manager_ui_get (gimp_editor->ui_manager, gimp_editor->ui_path);
gimp_ui_manager_update (gimp_editor->ui_manager, gimp_editor->popup_data);
#if 0
gimp_item_factory_update (gimp_editor->item_factory,
gimp_editor->popup_data);
menu_item =
gtk_ui_manager_get_widget (GTK_UI_MANAGER (gimp_editor->ui_manager), path);
menu =
gtk_item_factory_get_widget (GTK_ITEM_FACTORY (gimp_editor->item_factory),
path);
if (GTK_IS_MENU_ITEM (menu_item))
{
GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item));
if (menu)
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
gimp_tool_options_editor_menu_pos, button,
0, GDK_CURRENT_TIME);
#endif
}
}
static void
@ -349,7 +340,9 @@ gimp_tool_options_editor_save_clicked (GtkWidget *widget,
{
if (GTK_WIDGET_SENSITIVE (editor->restore_button) /* evil but correct */)
{
gimp_tool_options_editor_menu_popup (editor, widget, "/Save Options to");
gimp_tool_options_editor_menu_popup (editor, widget,
"/tool-options-popup"
"/tool-options-save-menu");
}
else
{
@ -372,14 +365,18 @@ static void
gimp_tool_options_editor_restore_clicked (GtkWidget *widget,
GimpToolOptionsEditor *editor)
{
gimp_tool_options_editor_menu_popup (editor, widget, "/Restore Options from");
gimp_tool_options_editor_menu_popup (editor, widget,
"/tool-options-popup"
"/tool-options-restore-menu");
}
static void
gimp_tool_options_editor_delete_clicked (GtkWidget *widget,
GimpToolOptionsEditor *editor)
{
gimp_tool_options_editor_menu_popup (editor, widget, "/Delete Saved Options");
gimp_tool_options_editor_menu_popup (editor, widget,
"/tool-options-popup"
"/tool-options-delete-menu");
}
static void

View File

@ -30,6 +30,7 @@
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpmarshal.h"
#include "gimpactiongroup.h"
#include "gimpuimanager.h"
@ -42,6 +43,12 @@ enum
PROP_GIMP
};
enum
{
UPDATE,
LAST_SIGNAL
};
static void gimp_ui_manager_init (GimpUIManager *manager);
static void gimp_ui_manager_class_init (GimpUIManagerClass *klass);
@ -59,8 +66,12 @@ static void gimp_ui_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gimp_ui_manager_real_update (GimpUIManager *manager,
gpointer update_data);
static guint manager_signals[LAST_SIGNAL] = { 0 };
static GtkUIManagerClass *parent_class = NULL;
@ -105,6 +116,18 @@ gimp_ui_manager_class_init (GimpUIManagerClass *klass)
object_class->set_property = gimp_ui_manager_set_property;
object_class->get_property = gimp_ui_manager_get_property;
klass->update = gimp_ui_manager_real_update;
manager_signals[UPDATE] =
g_signal_new ("update",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpUIManagerClass, update),
NULL, NULL,
gimp_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
g_object_class_install_property (object_class, PROP_NAME,
g_param_spec_string ("name",
NULL, NULL,
@ -264,6 +287,20 @@ gimp_ui_manager_get_property (GObject *object,
}
}
static void
gimp_ui_manager_real_update (GimpUIManager *manager,
gpointer update_data)
{
GList *list;
for (list = gtk_ui_manager_get_action_groups (GTK_UI_MANAGER (manager));
list;
list = g_list_next (list))
{
gimp_action_group_update (list->data, update_data);
}
}
/**
* gimp_ui_manager_new:
* @gimp: the @Gimp instance this ui manager belongs to
@ -309,16 +346,9 @@ void
gimp_ui_manager_update (GimpUIManager *manager,
gpointer update_data)
{
GList *list;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
for (list = gtk_ui_manager_get_action_groups (GTK_UI_MANAGER (manager));
list;
list = g_list_next (list))
{
gimp_action_group_update (list->data, update_data);
}
g_signal_emit (manager, manager_signals[UPDATE], 0, update_data);
}
GimpActionGroup *
@ -409,6 +439,8 @@ gimp_ui_manager_ui_get (GimpUIManager *manager,
if (! entry->widget)
{
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
entry->widget =
gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager),
entry->ui_path);

View File

@ -61,6 +61,9 @@ struct _GimpUIManagerClass
GtkUIManagerClass parent_class;
GHashTable *managers;
void (* update) (GimpUIManager *manager,
gpointer update_data);
};