2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-09-30 04:26:09 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-09-30 04:26:09 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-09-30 04:26:09 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-09-30 04:26:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2003-09-30 04:26:09 +08:00
|
|
|
#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)
|
|
|
|
{
|
2019-07-02 09:54:38 +08:00
|
|
|
gimp_ui_manager_remove_ui (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
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gimp_ui_manager_ensure_update (manager);
|
2004-04-30 23:29:11 +08:00
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
|
2006-12-11 03:13:58 +08:00
|
|
|
if (! tool_info->presets)
|
2003-09-30 04:26:09 +08:00
|
|
|
return;
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
merge_id = gimp_ui_manager_new_merge_id (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",
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_info->presets);
|
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
|
|
|
"Restore", "restore",
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_info->presets);
|
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,
|
2011-03-23 16:27:29 +08:00
|
|
|
"Edit", "edit",
|
|
|
|
tool_info->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",
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_info->presets);
|
2003-09-30 04:26:09 +08:00
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gimp_ui_manager_ensure_update (manager);
|
2004-04-30 23:29:11 +08:00
|
|
|
}
|
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
|
|
|
|
2008-11-21 06:45:19 +08:00
|
|
|
n_children = gimp_container_get_n_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;
|
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
action_name = g_strdup_printf ("tool-options-%s-preset-%03d",
|
|
|
|
which_action, i);
|
2004-04-30 23:29:11 +08:00
|
|
|
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
|
|
|
|
|
2019-07-02 09:54:38 +08:00
|
|
|
gimp_ui_manager_add_ui (manager, merge_id,
|
|
|
|
path, action_name, action_name,
|
|
|
|
GTK_UI_MANAGER_MENUITEM,
|
|
|
|
FALSE);
|
2004-04-30 23:29:11 +08:00
|
|
|
|
|
|
|
g_free (action_name);
|
|
|
|
g_free (path);
|
2003-09-30 04:26:09 +08:00
|
|
|
}
|
2003-10-01 02:33:46 +08:00
|
|
|
}
|