Commit 7d7ef188 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

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.
parent 9f549614
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
......
......@@ -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);
GList *list;
gint n_children = 0;
gint i;
if (menu)
for (i = 0; ; i++)
{
GList *list;
gint num_children;
gchar *action_name;
GtkAction *action;
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);
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);
if (! action)
break;
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
}
num_children = gimp_container_num_children (presets);
if (presets)
n_children = gimp_container_num_children (presets);
if (num_children > 0)
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;
for (list = GIMP_LIST (presets)->list, i = 0;
list;
list = g_list_next (list), i++)
{
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);
}
GimpToolOptions *options = list->data;
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
......@@ -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;
GimpEditor *editor = GIMP_EDITOR (data);
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);
......@@ -95,42 +79,95 @@ tool_options_save_new_cmd_callback (GtkAction *action,
gtk_widget_show (qbox);
}
void
tool_options_save_to_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)
{
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)
{
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);
gimp_config_sync (GIMP_CONFIG (options),
GIMP_CONFIG (options->tool_info->tool_options), 0);
if (options)
gimp_config_sync (GIMP_CONFIG (options),
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);
GtkWidget *qbox;
qbox = gimp_query_string_box (_("Rename Saved Tool Options"),
NULL /* FIXME */,
gimp_standard_help_func,
GIMP_HELP_TOOL_OPTIONS_DIALOG,
_("Enter a new name for the saved options"),
GIMP_OBJECT (options)->name,
NULL, NULL,
tool_options_rename_callback, options);
gtk_widget_show (qbox);
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"),
NULL /* FIXME */,
gimp_standard_help_func,
GIMP_HELP_TOOL_OPTIONS_DIALOG,
_("Enter a new name for the saved options"),
GIMP_OBJECT (options)->name,
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;
options = (GimpToolOptions *)
gimp_container_get_child_by_index (tool_info->options_presets, value);
gimp_container_remove (options->tool_info->options_presets,
GIMP_OBJECT (options));
if (options)
gimp_container_remove (tool_info->options_presets, GIMP_OBJECT (options));
}
void
......
......@@ -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,
......
......@@ -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);
}
......
......@@ -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"
/* local function prototypes */
#define MENU_BRANCH(path) \
{ { (path), NULL, NULL, 0, "<Branch>" }, NULL, NULL, NULL }
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,
const gchar *action_prefix,
GimpContainer *presets);
/* local function prototypes */
/* public functions */
static void tool_options_menu_update_presets (GtkItemFactory *factory,
const gchar *menu_path,
gint keep_n,
gboolean has_none,
GtkItemFactoryCallback callback,
const gchar *stock_id,
const gchar *help_id,
GimpContainer *presets);
void
tool_options_menu_setup (GimpUIManager *manager,
const gchar *ui_path)
{
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);
}
/* global variables */
/* private functions */
GimpItemFactoryEntry tool_options_menu_entries[] =
static void
tool_options_menu_update (GimpUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
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);
guint merge_id;
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
"tool-options-merge-id"));
/* public functions */
if (merge_id)
{
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager), merge_id);
void
tool_options_menu_setup (GimpItemFactory *factory,
gpointer callback_data)
{
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_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
GINT_TO_POINTER (0));
#define SET_VISIBLE(menu,condition) \
gimp_item_factory_set_visible (factory, menu, (condition) != 0)
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
}
}
void
tool_options_menu_update (GtkItemFactory *factory,
gpointer data)
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,
tool_info->options_presets);
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
GUINT_TO_POINTER (merge_id));
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-save-menu",
"tool-options-save-",
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-restore-menu",
"tool-options-restore-",
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-rename-menu",
"tool-options-rename-",
tool_info->options_presets);
}
tool_options_menu_update_presets (manager, merge_id, ui_path,
"tool-options-delete-menu",
"tool-options-delete-",
tool_info->options_presets);
/* privat function */
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
}
static void