2003-09-30 04:26:09 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-05-06 15:41:53 +08:00
|
|
|
#include "menus-types.h"
|
2003-09-30 04:26:09 +08:00
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
2004-04-30 23:29:11 +08:00
|
|
|
#include "widgets/gimpuimanager.h"
|
2003-09-30 04:26:09 +08:00
|
|
|
|
|
|
|
#include "tool-options-menu.h"
|
|
|
|
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
/* local function prototypes */
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
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,
|
2004-05-13 23:50:55 +08:00
|
|
|
const gchar *which_action,
|
2004-04-30 23:29:11 +08:00
|
|
|
GimpContainer *presets);
|
2004-04-29 20:52:29 +08:00
|
|
|
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
/* public functions */
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
void
|
|
|
|
tool_options_menu_setup (GimpUIManager *manager,
|
|
|
|
const gchar *ui_path)
|
|
|
|
{
|
|
|
|
g_signal_connect (manager, "update",
|
|
|
|
G_CALLBACK (tool_options_menu_update),
|
2004-05-01 01:11:07 +08:00
|
|
|
(gpointer) ui_path);
|
2004-04-30 23:29:11 +08:00
|
|
|
g_signal_connect_after (manager, "update",
|
|
|
|
G_CALLBACK (tool_options_menu_update_after),
|
2004-05-01 01:11:07 +08:00
|
|
|
(gpointer) ui_path);
|
2004-04-30 23:29:11 +08:00
|
|
|
}
|
2003-10-01 02:33:46 +08:00
|
|
|
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
/* private functions */
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
static void
|
|
|
|
tool_options_menu_update (GimpUIManager *manager,
|
|
|
|
gpointer update_data,
|
|
|
|
const gchar *ui_path)
|
2003-09-30 04:26:09 +08:00
|
|
|
{
|
2004-04-30 23:29:11 +08:00
|
|
|
guint merge_id;
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
|
|
|
|
"tool-options-merge-id"));
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
if (merge_id)
|
|
|
|
{
|
|
|
|
gtk_ui_manager_remove_ui (GTK_UI_MANAGER (manager), merge_id);
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
|
|
|
|
GINT_TO_POINTER (0));
|
2003-09-30 06:23:44 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
|
|
|
|
}
|
|
|
|
}
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
static void
|
|
|
|
tool_options_menu_update_after (GimpUIManager *manager,
|
|
|
|
gpointer update_data,
|
|
|
|
const gchar *ui_path)
|
2003-09-30 04:26:09 +08:00
|
|
|
{
|
|
|
|
GimpContext *context;
|
|
|
|
GimpToolInfo *tool_info;
|
2004-04-30 23:29:11 +08:00
|
|
|
guint merge_id;
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
context = gimp_get_user_context (manager->gimp);
|
2003-09-30 04:26:09 +08:00
|
|
|
tool_info = gimp_context_get_tool (context);
|
|
|
|
|
|
|
|
if (! tool_info->options_presets)
|
|
|
|
return;
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
g_object_set_data (G_OBJECT (manager), "tool-options-merge-id",
|
|
|
|
GUINT_TO_POINTER (merge_id));
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
2004-05-13 23:50:55 +08:00
|
|
|
"Save", "save",
|
2003-10-01 02:33:46 +08:00
|
|
|
tool_info->options_presets);
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
2004-05-13 23:50:55 +08:00
|
|
|
"Restore", "restore",
|
2003-10-01 02:33:46 +08:00
|
|
|
tool_info->options_presets);
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
2004-05-13 23:50:55 +08:00
|
|
|
"Rename", "rename",
|
2003-10-01 02:33:46 +08:00
|
|
|
tool_info->options_presets);
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
2004-05-13 23:50:55 +08:00
|
|
|
"Delete", "delete",
|
2004-04-30 23:29:11 +08:00
|
|
|
tool_info->options_presets);
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
|
|
|
|
}
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2003-10-01 02:33:46 +08:00
|
|
|
static void
|
2004-04-30 23:29:11 +08:00
|
|
|
tool_options_menu_update_presets (GimpUIManager *manager,
|
|
|
|
guint merge_id,
|
|
|
|
const gchar *ui_path,
|
|
|
|
const gchar *menu_path,
|
2004-05-13 23:50:55 +08:00
|
|
|
const gchar *which_action,
|
2004-04-30 23:29:11 +08:00
|
|
|
GimpContainer *presets)
|
2003-10-01 02:33:46 +08:00
|
|
|
{
|
2004-05-13 23:50:55 +08:00
|
|
|
gint n_children;
|
|
|
|
gint i;
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
n_children = gimp_container_num_children (presets);
|
2003-10-01 02:33:46 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
for (i = 0; i < n_children; i++)
|
2003-09-30 04:26:09 +08:00
|
|
|
{
|
2004-04-30 23:29:11 +08:00
|
|
|
gchar *action_name;
|
|
|
|
gchar *path;
|
|
|
|
|
2004-05-13 23:50:55 +08:00
|
|
|
action_name = g_strdup_printf ("tool-options-%s-%03d", which_action, i);
|
2004-04-30 23:29:11 +08:00
|
|
|
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
|
|
|
|
|
|
|
|
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
|
|
|
|
path, action_name, action_name,
|
|
|
|
GTK_UI_MANAGER_MENUITEM,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
g_free (action_name);
|
|
|
|
g_free (path);
|
2003-09-30 04:26:09 +08:00
|
|
|
}
|
2003-10-01 02:33:46 +08:00
|
|
|
}
|