2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-04-19 22:54:24 +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
|
2004-04-19 22:54:24 +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
|
2004-04-19 22:54:24 +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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-04-19 22:54:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2004-04-19 22:54:24 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "actions-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
|
|
|
#include "widgets/gimpactiongroup.h"
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
|
|
|
#include "tool-options-actions.h"
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "tool-options-commands.h"
|
2004-04-19 22:54:24 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void tool_options_actions_update_presets (GimpActionGroup *group,
|
2004-04-30 23:29:11 +08:00
|
|
|
const gchar *action_prefix,
|
2004-04-19 22:54:24 +08:00
|
|
|
GCallback callback,
|
|
|
|
const gchar *help_id,
|
2012-02-07 05:04:34 +08:00
|
|
|
GimpContainer *presets,
|
|
|
|
gboolean need_writable,
|
|
|
|
gboolean need_deletable);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* global variables */
|
|
|
|
|
2006-04-10 16:06:18 +08:00
|
|
|
static const GimpActionEntry tool_options_actions[] =
|
2004-04-19 22:54:24 +08:00
|
|
|
{
|
2004-10-18 19:29:58 +08:00
|
|
|
{ "tool-options-popup", GIMP_STOCK_TOOL_OPTIONS,
|
2008-12-03 23:27:42 +08:00
|
|
|
NC_("tool-options-action", "Tool Options Menu"), NULL, NULL, NULL,
|
2004-05-02 16:56:07 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_DIALOG },
|
2004-04-23 00:16:43 +08:00
|
|
|
|
2014-05-12 04:49:22 +08:00
|
|
|
{ "tool-options-save-preset-menu", "document-save",
|
2011-03-23 16:27:29 +08:00
|
|
|
NC_("tool-options-action", "_Save Tool Preset"), "", NULL, NULL,
|
2004-10-18 19:29:58 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_SAVE },
|
|
|
|
|
2014-05-12 04:49:22 +08:00
|
|
|
{ "tool-options-restore-preset-menu", "document-revert",
|
2011-03-23 16:27:29 +08:00
|
|
|
NC_("tool-options-action", "_Restore Tool Preset"), "", NULL, NULL,
|
2004-10-18 19:29:58 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_RESTORE },
|
|
|
|
|
2014-05-12 04:49:22 +08:00
|
|
|
{ "tool-options-edit-preset-menu", "gtk-edit",
|
2011-03-23 16:27:29 +08:00
|
|
|
NC_("tool-options-action", "E_dit Tool Preset"), NULL, NULL, NULL,
|
|
|
|
GIMP_HELP_TOOL_OPTIONS_EDIT },
|
2004-10-18 19:29:58 +08:00
|
|
|
|
2014-05-12 04:49:22 +08:00
|
|
|
{ "tool-options-delete-preset-menu", "edit-delete",
|
2011-03-23 16:27:29 +08:00
|
|
|
NC_("tool-options-action", "_Delete Tool Preset"), "", NULL, NULL,
|
2004-10-18 19:29:58 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_DELETE },
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2014-05-12 04:49:22 +08:00
|
|
|
{ "tool-options-save-new-preset", "document-new",
|
2011-03-23 16:27:29 +08:00
|
|
|
NC_("tool-options-action", "_New Tool Preset..."), "", NULL,
|
|
|
|
G_CALLBACK (tool_options_save_new_preset_cmd_callback),
|
2004-04-19 22:54:24 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_SAVE },
|
|
|
|
|
|
|
|
{ "tool-options-reset", GIMP_STOCK_RESET,
|
2014-05-12 04:49:22 +08:00
|
|
|
NC_("tool-options-action", "R_eset Tool Options"), NULL,
|
2008-12-03 23:27:42 +08:00
|
|
|
NC_("tool-options-action", "Reset to default values"),
|
2004-04-19 22:54:24 +08:00
|
|
|
G_CALLBACK (tool_options_reset_cmd_callback),
|
|
|
|
GIMP_HELP_TOOL_OPTIONS_RESET },
|
|
|
|
|
|
|
|
{ "tool-options-reset-all", GIMP_STOCK_RESET,
|
2014-05-12 04:49:22 +08:00
|
|
|
NC_("tool-options-action", "Reset _all Tool Options"), NULL,
|
2008-12-04 18:32:20 +08:00
|
|
|
NC_("tool-options-action", "Reset all tool options"),
|
2004-04-19 22:54:24 +08:00
|
|
|
G_CALLBACK (tool_options_reset_all_cmd_callback),
|
|
|
|
GIMP_HELP_TOOL_OPTIONS_RESET }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
#define SET_VISIBLE(action,condition) \
|
|
|
|
gimp_action_group_set_action_visible (group, action, (condition) != 0)
|
2012-02-07 05:04:34 +08:00
|
|
|
#define SET_SENSITIVE(action,condition) \
|
|
|
|
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
|
2005-09-24 07:41:43 +08:00
|
|
|
#define SET_HIDE_EMPTY(action,condition) \
|
|
|
|
gimp_action_group_set_action_hide_empty (group, action, (condition) != 0)
|
2004-04-19 22:54:24 +08:00
|
|
|
|
|
|
|
void
|
2004-04-27 21:55:26 +08:00
|
|
|
tool_options_actions_setup (GimpActionGroup *group)
|
2004-04-19 22:54:24 +08:00
|
|
|
{
|
2008-12-03 23:27:42 +08:00
|
|
|
gimp_action_group_add_actions (group, "tool-options-action",
|
2004-04-19 22:54:24 +08:00
|
|
|
tool_options_actions,
|
2004-04-27 21:55:26 +08:00
|
|
|
G_N_ELEMENTS (tool_options_actions));
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
SET_HIDE_EMPTY ("tool-options-restore-preset-menu", FALSE);
|
|
|
|
SET_HIDE_EMPTY ("tool-options-edit-preset-menu", FALSE);
|
|
|
|
SET_HIDE_EMPTY ("tool-options-delete-preset-menu", FALSE);
|
2004-04-19 22:54:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tool_options_actions_update (GimpActionGroup *group,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-10-18 19:29:58 +08:00
|
|
|
GimpContext *context = gimp_get_user_context (group->gimp);
|
|
|
|
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
SET_VISIBLE ("tool-options-save-preset-menu", tool_info->presets);
|
|
|
|
SET_VISIBLE ("tool-options-restore-preset-menu", tool_info->presets);
|
|
|
|
SET_VISIBLE ("tool-options-edit-preset-menu", tool_info->presets);
|
|
|
|
SET_VISIBLE ("tool-options-delete-preset-menu", tool_info->presets);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_options_actions_update_presets (group, "tool-options-save-preset",
|
|
|
|
G_CALLBACK (tool_options_save_preset_cmd_callback),
|
2004-04-19 22:54:24 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_SAVE,
|
2012-02-07 05:04:34 +08:00
|
|
|
tool_info->presets,
|
|
|
|
TRUE /* writable */,
|
|
|
|
FALSE /* deletable */);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_options_actions_update_presets (group, "tool-options-restore-preset",
|
|
|
|
G_CALLBACK (tool_options_restore_preset_cmd_callback),
|
2004-04-19 22:54:24 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_RESTORE,
|
2012-02-07 05:04:34 +08:00
|
|
|
tool_info->presets,
|
|
|
|
FALSE /* writable */,
|
|
|
|
FALSE /* deletable */);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_options_actions_update_presets (group, "tool-options-edit-preset",
|
|
|
|
G_CALLBACK (tool_options_edit_preset_cmd_callback),
|
|
|
|
GIMP_HELP_TOOL_OPTIONS_EDIT,
|
2012-02-07 05:04:34 +08:00
|
|
|
tool_info->presets,
|
|
|
|
FALSE /* writable */,
|
|
|
|
FALSE /* deletable */);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
tool_options_actions_update_presets (group, "tool-options-delete-preset",
|
|
|
|
G_CALLBACK (tool_options_delete_preset_cmd_callback),
|
2004-04-19 22:54:24 +08:00
|
|
|
GIMP_HELP_TOOL_OPTIONS_DELETE,
|
2012-02-07 05:04:34 +08:00
|
|
|
tool_info->presets,
|
|
|
|
FALSE /* writable */,
|
|
|
|
TRUE /* deletable */);
|
2004-04-19 22:54:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-20 22:19:22 +08:00
|
|
|
/* private function */
|
2004-04-19 22:54:24 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
tool_options_actions_update_presets (GimpActionGroup *group,
|
2004-04-30 23:29:11 +08:00
|
|
|
const gchar *action_prefix,
|
2004-04-19 22:54:24 +08:00
|
|
|
GCallback callback,
|
|
|
|
const gchar *help_id,
|
2012-02-07 05:04:34 +08:00
|
|
|
GimpContainer *presets,
|
|
|
|
gboolean need_writable,
|
|
|
|
gboolean need_deletable)
|
2004-04-19 22:54:24 +08:00
|
|
|
{
|
2004-04-30 23:29:11 +08:00
|
|
|
GList *list;
|
|
|
|
gint n_children = 0;
|
|
|
|
gint i;
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
for (i = 0; ; i++)
|
2004-04-19 22:54:24 +08:00
|
|
|
{
|
2004-04-30 23:29:11 +08:00
|
|
|
gchar *action_name;
|
|
|
|
GtkAction *action;
|
|
|
|
|
2011-03-23 16:27:29 +08:00
|
|
|
action_name = g_strdup_printf ("%s-%03d", action_prefix, i);
|
2004-04-30 23:29:11 +08:00
|
|
|
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
|
|
|
|
action_name);
|
|
|
|
g_free (action_name);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
if (! action)
|
|
|
|
break;
|
|
|
|
|
|
|
|
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
|
|
|
|
}
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
if (presets)
|
2008-11-21 06:45:19 +08:00
|
|
|
n_children = gimp_container_get_n_children (presets);
|
2004-04-19 22:54:24 +08:00
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
if (n_children > 0)
|
|
|
|
{
|
|
|
|
GimpEnumActionEntry entry;
|
|
|
|
|
2004-12-03 02:29:56 +08:00
|
|
|
entry.name = NULL;
|
|
|
|
entry.label = NULL;
|
|
|
|
entry.accelerator = "";
|
|
|
|
entry.tooltip = NULL;
|
|
|
|
entry.value = 0;
|
|
|
|
entry.value_variable = FALSE;
|
|
|
|
entry.help_id = help_id;
|
2004-04-30 23:29:11 +08:00
|
|
|
|
|
|
|
for (list = GIMP_LIST (presets)->list, i = 0;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list), i++)
|
2004-04-19 22:54:24 +08:00
|
|
|
{
|
2012-02-07 05:04:34 +08:00
|
|
|
GimpObject *preset = list->data;
|
2004-04-30 23:29:11 +08:00
|
|
|
|
2014-05-07 05:47:38 +08:00
|
|
|
entry.name = g_strdup_printf ("%s-%03d", action_prefix, i);
|
|
|
|
entry.label = gimp_object_get_name (preset);
|
2014-05-07 07:01:56 +08:00
|
|
|
entry.icon_name = gimp_viewable_get_icon_name (GIMP_VIEWABLE (preset));
|
2014-05-07 05:47:38 +08:00
|
|
|
entry.value = i;
|
2004-04-30 23:29:11 +08:00
|
|
|
|
2008-12-03 23:27:42 +08:00
|
|
|
gimp_action_group_add_enum_actions (group, NULL, &entry, 1, callback);
|
2004-04-30 23:29:11 +08:00
|
|
|
|
2012-02-07 05:04:34 +08:00
|
|
|
if (need_writable)
|
|
|
|
SET_SENSITIVE (entry.name,
|
|
|
|
gimp_data_is_writable (GIMP_DATA (preset)));
|
|
|
|
|
|
|
|
if (need_deletable)
|
|
|
|
SET_SENSITIVE (entry.name,
|
|
|
|
gimp_data_is_deletable (GIMP_DATA (preset)));
|
|
|
|
|
2004-04-30 23:29:11 +08:00
|
|
|
g_free ((gchar *) entry.name);
|
2004-04-19 22:54:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef SET_VISIBLE
|
2012-02-07 05:04:34 +08:00
|
|
|
#undef SET_SENSITIVE
|
2005-09-24 07:41:43 +08:00
|
|
|
#undef SET_HIDE_EMPTY
|