mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
app: remove the old tool presets system
Instead, keep around a GimpFilteredContainer in GimpToolInfo that maintains a per-tool list of presets from the global preset factory. Turn the tool options dialog's preset Save/Restore/Edit/Delete menus and buttons into shortcuts for managing the active tool's presets.
This commit is contained in:
parent
f3a99ed8f7
commit
91195e8593
14 changed files with 206 additions and 690 deletions
|
@ -42,7 +42,6 @@
|
||||||
static void tool_options_actions_update_presets (GimpActionGroup *group,
|
static void tool_options_actions_update_presets (GimpActionGroup *group,
|
||||||
const gchar *action_prefix,
|
const gchar *action_prefix,
|
||||||
GCallback callback,
|
GCallback callback,
|
||||||
const gchar *stock_id,
|
|
||||||
const gchar *help_id,
|
const gchar *help_id,
|
||||||
GimpContainer *presets);
|
GimpContainer *presets);
|
||||||
|
|
||||||
|
@ -55,25 +54,25 @@ static const GimpActionEntry tool_options_actions[] =
|
||||||
NC_("tool-options-action", "Tool Options Menu"), NULL, NULL, NULL,
|
NC_("tool-options-action", "Tool Options Menu"), NULL, NULL, NULL,
|
||||||
GIMP_HELP_TOOL_OPTIONS_DIALOG },
|
GIMP_HELP_TOOL_OPTIONS_DIALOG },
|
||||||
|
|
||||||
{ "tool-options-save-menu", GTK_STOCK_SAVE,
|
{ "tool-options-save-preset-menu", GTK_STOCK_SAVE,
|
||||||
NC_("tool-options-action", "_Save Options To"), "", NULL, NULL,
|
NC_("tool-options-action", "_Save Tool Preset"), "", NULL, NULL,
|
||||||
GIMP_HELP_TOOL_OPTIONS_SAVE },
|
GIMP_HELP_TOOL_OPTIONS_SAVE },
|
||||||
|
|
||||||
{ "tool-options-restore-menu", GTK_STOCK_REVERT_TO_SAVED,
|
{ "tool-options-restore-preset-menu", GTK_STOCK_REVERT_TO_SAVED,
|
||||||
NC_("tool-options-action", "_Restore Options From"), "", NULL, NULL,
|
NC_("tool-options-action", "_Restore Tool Preset"), "", NULL, NULL,
|
||||||
GIMP_HELP_TOOL_OPTIONS_RESTORE },
|
GIMP_HELP_TOOL_OPTIONS_RESTORE },
|
||||||
|
|
||||||
{ "tool-options-rename-menu", GTK_STOCK_EDIT,
|
{ "tool-options-edit-preset-menu", GTK_STOCK_EDIT,
|
||||||
NC_("tool-options-action", "Re_name Saved Options"), NULL, NULL, NULL,
|
NC_("tool-options-action", "E_dit Tool Preset"), NULL, NULL, NULL,
|
||||||
GIMP_HELP_TOOL_OPTIONS_RENAME },
|
GIMP_HELP_TOOL_OPTIONS_EDIT },
|
||||||
|
|
||||||
{ "tool-options-delete-menu", GTK_STOCK_DELETE,
|
{ "tool-options-delete-preset-menu", GTK_STOCK_DELETE,
|
||||||
NC_("tool-options-action", "_Delete Saved Options"), "", NULL, NULL,
|
NC_("tool-options-action", "_Delete Tool Preset"), "", NULL, NULL,
|
||||||
GIMP_HELP_TOOL_OPTIONS_DELETE },
|
GIMP_HELP_TOOL_OPTIONS_DELETE },
|
||||||
|
|
||||||
{ "tool-options-save-new", GTK_STOCK_NEW,
|
{ "tool-options-save-new-preset", GTK_STOCK_NEW,
|
||||||
NC_("tool-options-action", "_New Entry..."), "", NULL,
|
NC_("tool-options-action", "_New Tool Preset..."), "", NULL,
|
||||||
G_CALLBACK (tool_options_save_new_cmd_callback),
|
G_CALLBACK (tool_options_save_new_preset_cmd_callback),
|
||||||
GIMP_HELP_TOOL_OPTIONS_SAVE },
|
GIMP_HELP_TOOL_OPTIONS_SAVE },
|
||||||
|
|
||||||
{ "tool-options-reset", GIMP_STOCK_RESET,
|
{ "tool-options-reset", GIMP_STOCK_RESET,
|
||||||
|
@ -104,9 +103,9 @@ tool_options_actions_setup (GimpActionGroup *group)
|
||||||
tool_options_actions,
|
tool_options_actions,
|
||||||
G_N_ELEMENTS (tool_options_actions));
|
G_N_ELEMENTS (tool_options_actions));
|
||||||
|
|
||||||
SET_HIDE_EMPTY ("tool-options-restore-menu", FALSE);
|
SET_HIDE_EMPTY ("tool-options-restore-preset-menu", FALSE);
|
||||||
SET_HIDE_EMPTY ("tool-options-rename-menu", FALSE);
|
SET_HIDE_EMPTY ("tool-options-edit-preset-menu", FALSE);
|
||||||
SET_HIDE_EMPTY ("tool-options-delete-menu", FALSE);
|
SET_HIDE_EMPTY ("tool-options-delete-preset-menu", FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -116,34 +115,30 @@ tool_options_actions_update (GimpActionGroup *group,
|
||||||
GimpContext *context = gimp_get_user_context (group->gimp);
|
GimpContext *context = gimp_get_user_context (group->gimp);
|
||||||
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
||||||
|
|
||||||
SET_VISIBLE ("tool-options-save-menu", tool_info->presets);
|
SET_VISIBLE ("tool-options-save-preset-menu", tool_info->presets);
|
||||||
SET_VISIBLE ("tool-options-restore-menu", tool_info->presets);
|
SET_VISIBLE ("tool-options-restore-preset-menu", tool_info->presets);
|
||||||
SET_VISIBLE ("tool-options-rename-menu", tool_info->presets);
|
SET_VISIBLE ("tool-options-edit-preset-menu", tool_info->presets);
|
||||||
SET_VISIBLE ("tool-options-delete-menu", tool_info->presets);
|
SET_VISIBLE ("tool-options-delete-preset-menu", tool_info->presets);
|
||||||
|
|
||||||
tool_options_actions_update_presets (group, "tool-options-save-",
|
tool_options_actions_update_presets (group, "tool-options-save-preset",
|
||||||
G_CALLBACK (tool_options_save_to_cmd_callback),
|
G_CALLBACK (tool_options_save_preset_cmd_callback),
|
||||||
GTK_STOCK_SAVE,
|
|
||||||
GIMP_HELP_TOOL_OPTIONS_SAVE,
|
GIMP_HELP_TOOL_OPTIONS_SAVE,
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
|
|
||||||
tool_options_actions_update_presets (group, "tool-options-restore-",
|
tool_options_actions_update_presets (group, "tool-options-restore-preset",
|
||||||
G_CALLBACK (tool_options_restore_from_cmd_callback),
|
G_CALLBACK (tool_options_restore_preset_cmd_callback),
|
||||||
GTK_STOCK_REVERT_TO_SAVED,
|
|
||||||
GIMP_HELP_TOOL_OPTIONS_RESTORE,
|
GIMP_HELP_TOOL_OPTIONS_RESTORE,
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
|
|
||||||
tool_options_actions_update_presets (group, "tool-options-rename-",
|
tool_options_actions_update_presets (group, "tool-options-edit-preset",
|
||||||
G_CALLBACK (tool_options_rename_saved_cmd_callback),
|
G_CALLBACK (tool_options_edit_preset_cmd_callback),
|
||||||
GTK_STOCK_EDIT,
|
GIMP_HELP_TOOL_OPTIONS_EDIT,
|
||||||
GIMP_HELP_TOOL_OPTIONS_RENAME,
|
tool_info->presets);
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
|
||||||
|
|
||||||
tool_options_actions_update_presets (group, "tool-options-delete-",
|
tool_options_actions_update_presets (group, "tool-options-delete-preset",
|
||||||
G_CALLBACK (tool_options_delete_saved_cmd_callback),
|
G_CALLBACK (tool_options_delete_preset_cmd_callback),
|
||||||
GTK_STOCK_DELETE,
|
|
||||||
GIMP_HELP_TOOL_OPTIONS_DELETE,
|
GIMP_HELP_TOOL_OPTIONS_DELETE,
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,7 +148,6 @@ static void
|
||||||
tool_options_actions_update_presets (GimpActionGroup *group,
|
tool_options_actions_update_presets (GimpActionGroup *group,
|
||||||
const gchar *action_prefix,
|
const gchar *action_prefix,
|
||||||
GCallback callback,
|
GCallback callback,
|
||||||
const gchar *stock_id,
|
|
||||||
const gchar *help_id,
|
const gchar *help_id,
|
||||||
GimpContainer *presets)
|
GimpContainer *presets)
|
||||||
{
|
{
|
||||||
|
@ -166,7 +160,7 @@ tool_options_actions_update_presets (GimpActionGroup *group,
|
||||||
gchar *action_name;
|
gchar *action_name;
|
||||||
GtkAction *action;
|
GtkAction *action;
|
||||||
|
|
||||||
action_name = g_strdup_printf ("%s%03d", action_prefix, i);
|
action_name = g_strdup_printf ("%s-%03d", action_prefix, i);
|
||||||
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
|
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
|
||||||
action_name);
|
action_name);
|
||||||
g_free (action_name);
|
g_free (action_name);
|
||||||
|
@ -185,7 +179,6 @@ tool_options_actions_update_presets (GimpActionGroup *group,
|
||||||
GimpEnumActionEntry entry;
|
GimpEnumActionEntry entry;
|
||||||
|
|
||||||
entry.name = NULL;
|
entry.name = NULL;
|
||||||
entry.stock_id = stock_id;
|
|
||||||
entry.label = NULL;
|
entry.label = NULL;
|
||||||
entry.accelerator = "";
|
entry.accelerator = "";
|
||||||
entry.tooltip = NULL;
|
entry.tooltip = NULL;
|
||||||
|
@ -197,11 +190,12 @@ tool_options_actions_update_presets (GimpActionGroup *group,
|
||||||
list;
|
list;
|
||||||
list = g_list_next (list), i++)
|
list = g_list_next (list), i++)
|
||||||
{
|
{
|
||||||
GimpToolOptions *options = list->data;
|
GimpObject *options = list->data;
|
||||||
|
|
||||||
entry.name = g_strdup_printf ("%s%03d", action_prefix, i);
|
entry.name = g_strdup_printf ("%s-%03d", action_prefix, i);
|
||||||
entry.label = gimp_object_get_name (options);
|
entry.label = gimp_object_get_name (options);
|
||||||
entry.value = i;
|
entry.stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (options));
|
||||||
|
entry.value = i;
|
||||||
|
|
||||||
gimp_action_group_add_enum_actions (group, NULL, &entry, 1, callback);
|
gimp_action_group_add_enum_actions (group, NULL, &entry, 1, callback);
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,14 @@
|
||||||
#include "actions-types.h"
|
#include "actions-types.h"
|
||||||
|
|
||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
|
#include "core/gimpcontainer.h"
|
||||||
|
#include "core/gimpdatafactory.h"
|
||||||
#include "core/gimptoolinfo.h"
|
#include "core/gimptoolinfo.h"
|
||||||
#include "core/gimptooloptions.h"
|
#include "core/gimptooloptions.h"
|
||||||
#include "core/gimptoolpresets.h"
|
#include "core/gimptoolpreset.h"
|
||||||
|
|
||||||
|
#include "widgets/gimpdataeditor.h"
|
||||||
|
#include "widgets/gimpdialogfactory.h"
|
||||||
#include "widgets/gimpeditor.h"
|
#include "widgets/gimpeditor.h"
|
||||||
#include "widgets/gimphelp-ids.h"
|
#include "widgets/gimphelp-ids.h"
|
||||||
#include "widgets/gimpmessagebox.h"
|
#include "widgets/gimpmessagebox.h"
|
||||||
|
@ -45,123 +49,109 @@
|
||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
|
|
||||||
static void tool_options_save_callback (GtkWidget *widget,
|
static void tool_options_show_preset_editor (GimpEditor *editor,
|
||||||
const gchar *name,
|
GimpToolPreset *preset);
|
||||||
gpointer data);
|
|
||||||
static void tool_options_rename_callback (GtkWidget *widget,
|
|
||||||
const gchar *name,
|
|
||||||
gpointer data);
|
|
||||||
|
|
||||||
|
|
||||||
/* public functions */
|
/* public functions */
|
||||||
|
|
||||||
void
|
void
|
||||||
tool_options_save_new_cmd_callback (GtkAction *action,
|
tool_options_save_new_preset_cmd_callback (GtkAction *action,
|
||||||
gpointer data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GimpEditor *editor = GIMP_EDITOR (data);
|
GimpEditor *editor = GIMP_EDITOR (user_data);
|
||||||
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
||||||
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
GimpData *data;
|
||||||
GtkWidget *dialog;
|
|
||||||
|
|
||||||
context = gimp_get_user_context (editor->ui_manager->gimp);
|
data = gimp_data_factory_data_new (context->gimp->tool_preset_factory,
|
||||||
tool_info = gimp_context_get_tool (context);
|
context, _("Untitled"));
|
||||||
|
|
||||||
dialog = gimp_query_string_box (_("Save Tool Options"),
|
tool_options_show_preset_editor (editor, GIMP_TOOL_PRESET (data));
|
||||||
gtk_widget_get_toplevel (GTK_WIDGET (editor)),
|
|
||||||
gimp_standard_help_func,
|
|
||||||
GIMP_HELP_TOOL_OPTIONS_DIALOG,
|
|
||||||
_("Enter a name for the saved options"),
|
|
||||||
_("Saved Options"),
|
|
||||||
NULL, NULL,
|
|
||||||
tool_options_save_callback, tool_info);
|
|
||||||
gtk_widget_show (dialog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tool_options_save_to_cmd_callback (GtkAction *action,
|
tool_options_save_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GimpEditor *editor = GIMP_EDITOR (data);
|
GimpEditor *editor = GIMP_EDITOR (data);
|
||||||
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
||||||
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
||||||
GimpToolOptions *options;
|
GimpToolPreset *preset;
|
||||||
|
|
||||||
options = gimp_tool_presets_get_options (tool_info->presets, value);
|
preset = (GimpToolPreset *)
|
||||||
|
gimp_container_get_child_by_index (tool_info->presets, value);
|
||||||
|
|
||||||
if (options)
|
if (preset)
|
||||||
{
|
{
|
||||||
gchar *name = g_strdup (gimp_object_get_name (options));
|
|
||||||
|
|
||||||
gimp_config_sync (G_OBJECT (tool_info->tool_options),
|
gimp_config_sync (G_OBJECT (tool_info->tool_options),
|
||||||
G_OBJECT (options),
|
G_OBJECT (preset->tool_options), 0);
|
||||||
GIMP_CONFIG_PARAM_SERIALIZE);
|
|
||||||
gimp_object_take_name (GIMP_OBJECT (options), name);
|
tool_options_show_preset_editor (editor, preset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tool_options_restore_from_cmd_callback (GtkAction *action,
|
tool_options_restore_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GimpEditor *editor = GIMP_EDITOR (data);
|
GimpEditor *editor = GIMP_EDITOR (data);
|
||||||
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
||||||
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
||||||
GimpToolOptions *options;
|
GimpToolPreset *preset;
|
||||||
|
|
||||||
options = gimp_tool_presets_get_options (tool_info->presets, value);
|
preset = (GimpToolPreset *)
|
||||||
|
gimp_container_get_child_by_index (tool_info->presets, value);
|
||||||
|
|
||||||
if (options)
|
if (preset)
|
||||||
gimp_config_sync (G_OBJECT (options),
|
|
||||||
G_OBJECT (tool_info->tool_options),
|
|
||||||
GIMP_CONFIG_PARAM_SERIALIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
tool_options_rename_saved_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 = gimp_tool_presets_get_options (tool_info->presets, value);
|
|
||||||
|
|
||||||
if (options)
|
|
||||||
{
|
{
|
||||||
GtkWidget *dialog;
|
if (gimp_context_get_tool_preset (context) != preset)
|
||||||
|
gimp_context_set_tool_preset (context, preset);
|
||||||
dialog = gimp_query_string_box (_("Rename Saved Tool Options"),
|
else
|
||||||
gtk_widget_get_toplevel (GTK_WIDGET (editor)),
|
gimp_context_tool_preset_changed (context);
|
||||||
gimp_standard_help_func,
|
|
||||||
GIMP_HELP_TOOL_OPTIONS_DIALOG,
|
|
||||||
_("Enter a new name for the saved options"),
|
|
||||||
gimp_object_get_name (options),
|
|
||||||
NULL, NULL,
|
|
||||||
tool_options_rename_callback, options);
|
|
||||||
gtk_widget_show (dialog);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tool_options_delete_saved_cmd_callback (GtkAction *action,
|
tool_options_edit_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GimpEditor *editor = GIMP_EDITOR (data);
|
GimpEditor *editor = GIMP_EDITOR (data);
|
||||||
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
GimpContext *context = gimp_get_user_context (editor->ui_manager->gimp);
|
||||||
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
GimpToolInfo *tool_info = gimp_context_get_tool (context);
|
||||||
GimpToolOptions *options;
|
GimpToolPreset *preset;
|
||||||
|
|
||||||
options = gimp_tool_presets_get_options (tool_info->presets, value);
|
preset = (GimpToolPreset *)
|
||||||
|
gimp_container_get_child_by_index (tool_info->presets, value);
|
||||||
|
|
||||||
if (options)
|
if (preset)
|
||||||
gimp_container_remove (GIMP_CONTAINER (tool_info->presets),
|
{
|
||||||
GIMP_OBJECT (options));
|
tool_options_show_preset_editor (editor, preset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tool_options_delete_preset_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);
|
||||||
|
GimpToolPreset *preset;
|
||||||
|
|
||||||
|
preset = (GimpToolPreset *)
|
||||||
|
gimp_container_get_child_by_index (tool_info->presets, value);
|
||||||
|
|
||||||
|
if (preset)
|
||||||
|
{
|
||||||
|
GimpDataFactory *preset_factory = context->gimp->tool_preset_factory;
|
||||||
|
|
||||||
|
gimp_container_remove (gimp_data_factory_get_container (preset_factory),
|
||||||
|
GIMP_OBJECT (preset));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -230,34 +220,16 @@ tool_options_reset_all_cmd_callback (GtkAction *action,
|
||||||
/* private functions */
|
/* private functions */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tool_options_save_callback (GtkWidget *widget,
|
tool_options_show_preset_editor (GimpEditor *editor,
|
||||||
const gchar *name,
|
GimpToolPreset *preset)
|
||||||
gpointer data)
|
|
||||||
{
|
{
|
||||||
GimpToolInfo *tool_info = GIMP_TOOL_INFO (data);
|
GtkWidget *dockable;
|
||||||
GimpConfig *copy;
|
|
||||||
|
|
||||||
copy = gimp_config_duplicate (GIMP_CONFIG (tool_info->tool_options));
|
dockable =
|
||||||
|
gimp_dialog_factory_dialog_raise (gimp_dialog_factory_get_singleton (),
|
||||||
|
gtk_widget_get_screen (GTK_WIDGET (editor)),
|
||||||
|
"gimp-tool-preset-editor", -1);
|
||||||
|
|
||||||
if (name && strlen (name))
|
gimp_data_editor_set_data (GIMP_DATA_EDITOR (gtk_bin_get_child (GTK_BIN (dockable))),
|
||||||
gimp_object_set_name (GIMP_OBJECT (copy), name);
|
GIMP_DATA (preset));
|
||||||
else
|
|
||||||
gimp_object_set_static_name (GIMP_OBJECT (copy), _("Saved Options"));
|
|
||||||
|
|
||||||
gimp_container_insert (GIMP_CONTAINER (tool_info->presets),
|
|
||||||
GIMP_OBJECT (copy), -1);
|
|
||||||
g_object_unref (copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
tool_options_rename_callback (GtkWidget *widget,
|
|
||||||
const gchar *name,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GimpToolOptions *options = GIMP_TOOL_OPTIONS (data);
|
|
||||||
|
|
||||||
if (name && strlen (name))
|
|
||||||
gimp_object_set_name (GIMP_OBJECT (options), name);
|
|
||||||
else
|
|
||||||
gimp_object_set_static_name (GIMP_OBJECT (options), _("Saved Options"));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,26 +19,26 @@
|
||||||
#define __TOOL_OPTIONS_COMMANDS_H__
|
#define __TOOL_OPTIONS_COMMANDS_H__
|
||||||
|
|
||||||
|
|
||||||
void tool_options_save_new_cmd_callback (GtkAction *action,
|
void tool_options_save_new_preset_cmd_callback (GtkAction *action,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
void tool_options_save_to_cmd_callback (GtkAction *action,
|
void tool_options_save_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
void tool_options_restore_from_cmd_callback (GtkAction *action,
|
void tool_options_restore_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
void tool_options_rename_saved_cmd_callback (GtkAction *action,
|
void tool_options_edit_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
void tool_options_delete_saved_cmd_callback (GtkAction *action,
|
void tool_options_delete_preset_cmd_callback (GtkAction *action,
|
||||||
gint value,
|
gint value,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
void tool_options_reset_cmd_callback (GtkAction *action,
|
void tool_options_reset_cmd_callback (GtkAction *action,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
void tool_options_reset_all_cmd_callback (GtkAction *action,
|
void tool_options_reset_all_cmd_callback (GtkAction *action,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __TOOL_OPTIONS_COMMANDS_H__ */
|
#endif /* __TOOL_OPTIONS_COMMANDS_H__ */
|
||||||
|
|
|
@ -367,8 +367,6 @@ libappcore_a_sources = \
|
||||||
gimptoolpreset-load.h \
|
gimptoolpreset-load.h \
|
||||||
gimptoolpreset-save.c \
|
gimptoolpreset-save.c \
|
||||||
gimptoolpreset-save.h \
|
gimptoolpreset-save.h \
|
||||||
gimptoolpresets.c \
|
|
||||||
gimptoolpresets.h \
|
|
||||||
gimptreehandler.c \
|
gimptreehandler.c \
|
||||||
gimptreehandler.h \
|
gimptreehandler.h \
|
||||||
gimpunit.c \
|
gimpunit.c \
|
||||||
|
|
|
@ -73,7 +73,6 @@ typedef struct _GimpDrawableStack GimpDrawableStack;
|
||||||
typedef struct _GimpFilteredContainer GimpFilteredContainer;
|
typedef struct _GimpFilteredContainer GimpFilteredContainer;
|
||||||
typedef struct _GimpItemStack GimpItemStack;
|
typedef struct _GimpItemStack GimpItemStack;
|
||||||
typedef struct _GimpTaggedContainer GimpTaggedContainer;
|
typedef struct _GimpTaggedContainer GimpTaggedContainer;
|
||||||
typedef struct _GimpToolPresets GimpToolPresets;
|
|
||||||
|
|
||||||
|
|
||||||
/* not really a container */
|
/* not really a container */
|
||||||
|
|
|
@ -29,13 +29,12 @@
|
||||||
#include "base/temp-buf.h"
|
#include "base/temp-buf.h"
|
||||||
|
|
||||||
#include "gimp.h"
|
#include "gimp.h"
|
||||||
#include "gimpcontainer.h"
|
#include "gimpdatafactory.h"
|
||||||
#include "gimpcontext.h"
|
#include "gimpfilteredcontainer.h"
|
||||||
#include "gimplist.h"
|
|
||||||
#include "gimppaintinfo.h"
|
#include "gimppaintinfo.h"
|
||||||
#include "gimptoolinfo.h"
|
#include "gimptoolinfo.h"
|
||||||
#include "gimptooloptions.h"
|
#include "gimptooloptions.h"
|
||||||
#include "gimptoolpresets.h"
|
#include "gimptoolpreset.h"
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -214,6 +213,16 @@ gimp_tool_info_get_description (GimpViewable *viewable,
|
||||||
return g_strdup (tool_info->blurb);
|
return g_strdup (tool_info->blurb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gimp_tool_info_filter_preset (const GimpObject *object,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GimpToolPreset *preset = GIMP_TOOL_PRESET (object);
|
||||||
|
GimpToolInfo *tool_info = user_data;
|
||||||
|
|
||||||
|
return preset->tool_options->tool_info == tool_info;
|
||||||
|
}
|
||||||
|
|
||||||
GimpToolInfo *
|
GimpToolInfo *
|
||||||
gimp_tool_info_new (Gimp *gimp,
|
gimp_tool_info_new (Gimp *gimp,
|
||||||
GType tool_type,
|
GType tool_type,
|
||||||
|
@ -294,7 +303,14 @@ gimp_tool_info_new (Gimp *gimp,
|
||||||
|
|
||||||
if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
|
if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
|
||||||
{
|
{
|
||||||
tool_info->presets = gimp_tool_presets_new (tool_info);
|
GimpContainer *presets;
|
||||||
|
|
||||||
|
presets = gimp_data_factory_get_container (gimp->tool_preset_factory);
|
||||||
|
|
||||||
|
tool_info->presets =
|
||||||
|
gimp_filtered_container_new (presets,
|
||||||
|
gimp_tool_info_filter_preset,
|
||||||
|
tool_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tool_info;
|
return tool_info;
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct _GimpToolInfo
|
||||||
GimpToolOptions *tool_options;
|
GimpToolOptions *tool_options;
|
||||||
GimpPaintInfo *paint_info;
|
GimpPaintInfo *paint_info;
|
||||||
|
|
||||||
GimpToolPresets *presets;
|
GimpContainer *presets;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpToolInfoClass
|
struct _GimpToolInfoClass
|
||||||
|
|
|
@ -1,320 +0,0 @@
|
||||||
/* GIMP - The GNU Image Manipulation Program
|
|
||||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
||||||
*
|
|
||||||
* gimptoolpresets.c
|
|
||||||
* Copyright (C) 2006 Sven Neumann <sven@gimp.org>
|
|
||||||
*
|
|
||||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <glib-object.h>
|
|
||||||
#include <glib/gstdio.h>
|
|
||||||
|
|
||||||
#include "libgimpbase/gimpbase.h"
|
|
||||||
#include "libgimpconfig/gimpconfig.h"
|
|
||||||
|
|
||||||
#include "core-types.h"
|
|
||||||
|
|
||||||
#include "gimp.h"
|
|
||||||
#include "gimpmarshal.h"
|
|
||||||
#include "gimptoolinfo.h"
|
|
||||||
#include "gimptooloptions.h"
|
|
||||||
#include "gimptoolpresets.h"
|
|
||||||
|
|
||||||
#include "gimp-intl.h"
|
|
||||||
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
CHANGED,
|
|
||||||
LAST_SIGNAL
|
|
||||||
};
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
PROP_0,
|
|
||||||
PROP_TOOL_INFO
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void gimp_tool_presets_finalize (GObject *object);
|
|
||||||
static void gimp_tool_presets_set_property (GObject *object,
|
|
||||||
guint property_id,
|
|
||||||
const GValue *value,
|
|
||||||
GParamSpec *pspec);
|
|
||||||
static void gimp_tool_presets_get_property (GObject *object,
|
|
||||||
guint property_id,
|
|
||||||
GValue *value,
|
|
||||||
GParamSpec *pspec);
|
|
||||||
static void gimp_tool_presets_add (GimpContainer *container,
|
|
||||||
GimpObject *object);
|
|
||||||
static void gimp_tool_presets_remove (GimpContainer *container,
|
|
||||||
GimpObject *object);
|
|
||||||
static void gimp_tool_presets_notify (GimpToolPresets *presets);
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpToolPresets, gimp_tool_presets, GIMP_TYPE_LIST)
|
|
||||||
|
|
||||||
#define parent_class gimp_tool_presets_parent_class
|
|
||||||
|
|
||||||
static guint gimp_tool_presets_signals[LAST_SIGNAL] = { 0 };
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_class_init (GimpToolPresetsClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
||||||
GimpContainerClass *container_class = GIMP_CONTAINER_CLASS (klass);
|
|
||||||
|
|
||||||
gimp_tool_presets_signals[CHANGED] =
|
|
||||||
g_signal_new ("changed",
|
|
||||||
G_TYPE_FROM_CLASS (klass),
|
|
||||||
G_SIGNAL_RUN_FIRST,
|
|
||||||
G_STRUCT_OFFSET (GimpToolPresetsClass, changed),
|
|
||||||
NULL, NULL,
|
|
||||||
gimp_marshal_VOID__VOID,
|
|
||||||
G_TYPE_NONE, 0);
|
|
||||||
|
|
||||||
object_class->set_property = gimp_tool_presets_set_property;
|
|
||||||
object_class->get_property = gimp_tool_presets_get_property;
|
|
||||||
object_class->finalize = gimp_tool_presets_finalize;
|
|
||||||
|
|
||||||
container_class->add = gimp_tool_presets_add;
|
|
||||||
container_class->remove = gimp_tool_presets_remove;
|
|
||||||
|
|
||||||
klass->changed = NULL;
|
|
||||||
|
|
||||||
g_object_class_install_property (object_class, PROP_TOOL_INFO,
|
|
||||||
g_param_spec_object ("tool-info",
|
|
||||||
NULL, NULL,
|
|
||||||
GIMP_TYPE_TOOL_INFO,
|
|
||||||
G_PARAM_CONSTRUCT_ONLY |
|
|
||||||
GIMP_PARAM_READWRITE));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_init (GimpToolPresets *presets)
|
|
||||||
{
|
|
||||||
presets->tool_info = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_finalize (GObject *object)
|
|
||||||
{
|
|
||||||
GimpToolPresets *presets = GIMP_TOOL_PRESETS (object);
|
|
||||||
|
|
||||||
if (presets->tool_info)
|
|
||||||
{
|
|
||||||
g_object_unref (presets->tool_info);
|
|
||||||
presets->tool_info = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_set_property (GObject *object,
|
|
||||||
guint property_id,
|
|
||||||
const GValue *value,
|
|
||||||
GParamSpec *pspec)
|
|
||||||
{
|
|
||||||
GimpToolPresets *presets = GIMP_TOOL_PRESETS (object);
|
|
||||||
|
|
||||||
switch (property_id)
|
|
||||||
{
|
|
||||||
case PROP_TOOL_INFO:
|
|
||||||
presets->tool_info = g_value_dup_object (value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_get_property (GObject *object,
|
|
||||||
guint property_id,
|
|
||||||
GValue *value,
|
|
||||||
GParamSpec *pspec)
|
|
||||||
{
|
|
||||||
GimpToolPresets *presets = GIMP_TOOL_PRESETS (object);
|
|
||||||
|
|
||||||
switch (property_id)
|
|
||||||
{
|
|
||||||
case PROP_TOOL_INFO:
|
|
||||||
g_value_set_object (value, presets->tool_info);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_add (GimpContainer *container,
|
|
||||||
GimpObject *object)
|
|
||||||
{
|
|
||||||
GIMP_CONTAINER_CLASS (parent_class)->add (container, object);
|
|
||||||
|
|
||||||
g_signal_connect_swapped (object, "notify",
|
|
||||||
G_CALLBACK (gimp_tool_presets_notify),
|
|
||||||
container);
|
|
||||||
|
|
||||||
g_signal_emit (container, gimp_tool_presets_signals[CHANGED], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_remove (GimpContainer *container,
|
|
||||||
GimpObject *object)
|
|
||||||
{
|
|
||||||
g_signal_handlers_disconnect_by_func (object,
|
|
||||||
G_CALLBACK (gimp_tool_presets_notify),
|
|
||||||
container);
|
|
||||||
|
|
||||||
GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
|
|
||||||
|
|
||||||
g_signal_emit (container, gimp_tool_presets_signals[CHANGED], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_presets_notify (GimpToolPresets *presets)
|
|
||||||
{
|
|
||||||
g_signal_emit (presets, gimp_tool_presets_signals[CHANGED], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
GimpToolPresets *
|
|
||||||
gimp_tool_presets_new (GimpToolInfo *tool_info)
|
|
||||||
{
|
|
||||||
GimpToolPresets *presets;
|
|
||||||
gchar *name;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GIMP_IS_TOOL_INFO (tool_info), NULL);
|
|
||||||
|
|
||||||
presets = g_object_new (GIMP_TYPE_TOOL_PRESETS,
|
|
||||||
"tool-info", tool_info,
|
|
||||||
"children-type", tool_info->tool_options_type,
|
|
||||||
"policy", GIMP_CONTAINER_POLICY_STRONG,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
name = g_strdup_printf ("%s options", gimp_object_get_name (tool_info));
|
|
||||||
|
|
||||||
gimp_object_take_name (GIMP_OBJECT (presets), name);
|
|
||||||
|
|
||||||
return presets;
|
|
||||||
}
|
|
||||||
|
|
||||||
GimpToolOptions *
|
|
||||||
gimp_tool_presets_get_options (GimpToolPresets *presets,
|
|
||||||
gint index)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (GIMP_IS_TOOL_PRESETS (presets), NULL);
|
|
||||||
|
|
||||||
return (GimpToolOptions *)
|
|
||||||
gimp_container_get_child_by_index (GIMP_CONTAINER (presets), index);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
gimp_tool_presets_save (GimpToolPresets *presets,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
Gimp *gimp;
|
|
||||||
gchar *filename;
|
|
||||||
gboolean retval = TRUE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GIMP_IS_TOOL_PRESETS (presets), FALSE);
|
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
||||||
|
|
||||||
gimp = presets->tool_info->gimp;
|
|
||||||
|
|
||||||
filename = gimp_tool_info_build_options_filename (presets->tool_info,
|
|
||||||
".presets");
|
|
||||||
|
|
||||||
if (! gimp_container_is_empty (GIMP_CONTAINER (presets)))
|
|
||||||
{
|
|
||||||
gchar *footer;
|
|
||||||
|
|
||||||
if (gimp->be_verbose)
|
|
||||||
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
|
|
||||||
|
|
||||||
gimp_tool_options_create_folder ();
|
|
||||||
|
|
||||||
footer = g_strdup_printf ("end of %s", gimp_object_get_name (presets));
|
|
||||||
|
|
||||||
retval = gimp_config_serialize_to_file (GIMP_CONFIG (presets), filename,
|
|
||||||
gimp_object_get_name (presets),
|
|
||||||
footer,
|
|
||||||
NULL, error);
|
|
||||||
|
|
||||||
g_free (footer);
|
|
||||||
}
|
|
||||||
else if (g_file_test (filename, G_FILE_TEST_EXISTS))
|
|
||||||
{
|
|
||||||
if (gimp->be_verbose)
|
|
||||||
g_print ("Deleting '%s'\n", gimp_filename_to_utf8 (filename));
|
|
||||||
|
|
||||||
if (g_unlink (filename) != 0 && errno != ENOENT)
|
|
||||||
{
|
|
||||||
retval = FALSE;
|
|
||||||
|
|
||||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
||||||
_("Could not delete '%s': %s"),
|
|
||||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (filename);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
gimp_tool_presets_load (GimpToolPresets *presets,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
Gimp *gimp;
|
|
||||||
GList *list;
|
|
||||||
gchar *filename;
|
|
||||||
gboolean retval = TRUE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GIMP_IS_TOOL_PRESETS (presets), FALSE);
|
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
||||||
|
|
||||||
gimp = presets->tool_info->gimp;
|
|
||||||
|
|
||||||
gimp_container_clear (GIMP_CONTAINER (presets));
|
|
||||||
|
|
||||||
filename = gimp_tool_info_build_options_filename (presets->tool_info,
|
|
||||||
".presets");
|
|
||||||
|
|
||||||
if (gimp->be_verbose)
|
|
||||||
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
|
|
||||||
|
|
||||||
retval = gimp_config_deserialize_file (GIMP_CONFIG (presets), filename, gimp,
|
|
||||||
error);
|
|
||||||
|
|
||||||
g_free (filename);
|
|
||||||
|
|
||||||
gimp_list_reverse (GIMP_LIST (presets));
|
|
||||||
|
|
||||||
for (list = GIMP_LIST (presets)->list; list; list = g_list_next (list))
|
|
||||||
g_object_set (list->data, "tool-info", presets->tool_info, NULL);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
/* GIMP - The GNU Image Manipulation Program
|
|
||||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
||||||
*
|
|
||||||
* gimptoolpresets.h
|
|
||||||
* Copyright (C) 2006 Sven Neumann <sven@gimp.org>
|
|
||||||
*
|
|
||||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GIMP_TOOL_PRESETS_H__
|
|
||||||
#define __GIMP_TOOL_PRESETS_H__
|
|
||||||
|
|
||||||
|
|
||||||
#include "core/gimplist.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define GIMP_TYPE_TOOL_PRESETS (gimp_tool_presets_get_type ())
|
|
||||||
#define GIMP_TOOL_PRESETS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_PRESETS, GimpToolPresets))
|
|
||||||
#define GIMP_TOOL_PRESETS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_PRESETS, GimpToolPresetsClass))
|
|
||||||
#define GIMP_IS_TOOL_PRESETS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_PRESETS))
|
|
||||||
#define GIMP_IS_TOOL_PRESETS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_PRESETS))
|
|
||||||
#define GIMP_TOOL_PRESETS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_PRESETS, GimpToolPresetsClass))
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GimpToolPresetsClass GimpToolPresetsClass;
|
|
||||||
|
|
||||||
struct _GimpToolPresets
|
|
||||||
{
|
|
||||||
GimpList parent_instance;
|
|
||||||
|
|
||||||
GimpToolInfo *tool_info;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _GimpToolPresetsClass
|
|
||||||
{
|
|
||||||
GimpListClass parent_class;
|
|
||||||
|
|
||||||
void (* changed) (GimpToolPresets *presets);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
GType gimp_tool_presets_get_type (void) G_GNUC_CONST;
|
|
||||||
|
|
||||||
GimpToolPresets * gimp_tool_presets_new (GimpToolInfo *tool_info);
|
|
||||||
|
|
||||||
GimpToolOptions * gimp_tool_presets_get_options (GimpToolPresets *presets,
|
|
||||||
gint index);
|
|
||||||
|
|
||||||
gboolean gimp_tool_presets_save (GimpToolPresets *presets,
|
|
||||||
GError **error);
|
|
||||||
gboolean gimp_tool_presets_load (GimpToolPresets *presets,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_TOOL_PRESETS_H__ */
|
|
|
@ -110,19 +110,19 @@ tool_options_menu_update_after (GimpUIManager *manager,
|
||||||
|
|
||||||
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
||||||
"Save", "save",
|
"Save", "save",
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
|
|
||||||
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
||||||
"Restore", "restore",
|
"Restore", "restore",
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
|
|
||||||
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
||||||
"Rename", "rename",
|
"Edit", "edit",
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
|
|
||||||
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
tool_options_menu_update_presets (manager, merge_id, ui_path,
|
||||||
"Delete", "delete",
|
"Delete", "delete",
|
||||||
GIMP_CONTAINER (tool_info->presets));
|
tool_info->presets);
|
||||||
|
|
||||||
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
|
gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager));
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,8 @@ tool_options_menu_update_presets (GimpUIManager *manager,
|
||||||
gchar *action_name;
|
gchar *action_name;
|
||||||
gchar *path;
|
gchar *path;
|
||||||
|
|
||||||
action_name = g_strdup_printf ("tool-options-%s-%03d", which_action, i);
|
action_name = g_strdup_printf ("tool-options-%s-preset-%03d",
|
||||||
|
which_action, i);
|
||||||
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
|
path = g_strdup_printf ("%s/%s", ui_path, menu_path);
|
||||||
|
|
||||||
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
|
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
|
||||||
|
|
|
@ -30,9 +30,9 @@
|
||||||
|
|
||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
#include "core/gimp-contexts.h"
|
#include "core/gimp-contexts.h"
|
||||||
|
#include "core/gimplist.h"
|
||||||
#include "core/gimptoolinfo.h"
|
#include "core/gimptoolinfo.h"
|
||||||
#include "core/gimptooloptions.h"
|
#include "core/gimptooloptions.h"
|
||||||
#include "core/gimptoolpresets.h"
|
|
||||||
|
|
||||||
#include "gimp-tools.h"
|
#include "gimp-tools.h"
|
||||||
#include "gimptooloptions-gui.h"
|
#include "gimptooloptions-gui.h"
|
||||||
|
@ -359,9 +359,6 @@ gimp_tools_restore (Gimp *gimp)
|
||||||
|
|
||||||
gimp_tools_set_tool_options_gui (tool_info->tool_options,
|
gimp_tools_set_tool_options_gui (tool_info->tool_options,
|
||||||
g_object_ref_sink (options_gui));
|
g_object_ref_sink (options_gui));
|
||||||
|
|
||||||
if (tool_info->presets)
|
|
||||||
gimp_tool_presets_load (tool_info->presets, NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -414,7 +414,7 @@
|
||||||
#define GIMP_HELP_TOOL_OPTIONS_DIALOG "gimp-tool-options-dialog"
|
#define GIMP_HELP_TOOL_OPTIONS_DIALOG "gimp-tool-options-dialog"
|
||||||
#define GIMP_HELP_TOOL_OPTIONS_SAVE "gimp-tool-options-save"
|
#define GIMP_HELP_TOOL_OPTIONS_SAVE "gimp-tool-options-save"
|
||||||
#define GIMP_HELP_TOOL_OPTIONS_RESTORE "gimp-tool-options-restore"
|
#define GIMP_HELP_TOOL_OPTIONS_RESTORE "gimp-tool-options-restore"
|
||||||
#define GIMP_HELP_TOOL_OPTIONS_RENAME "gimp-tool-options-rename"
|
#define GIMP_HELP_TOOL_OPTIONS_EDIT "gimp-tool-options-edit"
|
||||||
#define GIMP_HELP_TOOL_OPTIONS_DELETE "gimp-tool-options-delete"
|
#define GIMP_HELP_TOOL_OPTIONS_DELETE "gimp-tool-options-delete"
|
||||||
#define GIMP_HELP_TOOL_OPTIONS_RESET "gimp-tool-options-reset"
|
#define GIMP_HELP_TOOL_OPTIONS_RESET "gimp-tool-options-reset"
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "core/gimplist.h"
|
#include "core/gimplist.h"
|
||||||
#include "core/gimptoolinfo.h"
|
#include "core/gimptoolinfo.h"
|
||||||
#include "core/gimptooloptions.h"
|
#include "core/gimptooloptions.h"
|
||||||
#include "core/gimptoolpresets.h"
|
|
||||||
|
|
||||||
#include "gimpdnd.h"
|
#include "gimpdnd.h"
|
||||||
#include "gimpdocked.h"
|
#include "gimpdocked.h"
|
||||||
|
@ -66,9 +65,6 @@ struct _GimpToolOptionsEditorPrivate
|
||||||
GtkWidget *reset_button;
|
GtkWidget *reset_button;
|
||||||
|
|
||||||
GimpToolOptions *visible_tool_options;
|
GimpToolOptions *visible_tool_options;
|
||||||
|
|
||||||
GList *save_queue;
|
|
||||||
guint save_idle_id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,11 +99,7 @@ static void gimp_tool_options_editor_drop_tool (GtkWidget
|
||||||
static void gimp_tool_options_editor_tool_changed (GimpContext *context,
|
static void gimp_tool_options_editor_tool_changed (GimpContext *context,
|
||||||
GimpToolInfo *tool_info,
|
GimpToolInfo *tool_info,
|
||||||
GimpToolOptionsEditor *editor);
|
GimpToolOptionsEditor *editor);
|
||||||
static void gimp_tool_options_editor_presets_changed (GimpToolPresets *presets,
|
static void gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor);
|
||||||
GimpToolOptionsEditor *editor);
|
|
||||||
static void gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor,
|
|
||||||
GimpToolPresets *presets);
|
|
||||||
static void gimp_tool_options_editor_save_presets (GimpToolOptionsEditor *editor);
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GimpToolOptionsEditor, gimp_tool_options_editor,
|
G_DEFINE_TYPE_WITH_CODE (GimpToolOptionsEditor, gimp_tool_options_editor,
|
||||||
|
@ -194,9 +186,6 @@ gimp_tool_options_editor_init (GimpToolOptionsEditor *editor)
|
||||||
editor->p->options_vbox = gtk_vbox_new (FALSE, 0);
|
editor->p->options_vbox = gtk_vbox_new (FALSE, 0);
|
||||||
gtk_container_add (GTK_CONTAINER (viewport), editor->p->options_vbox);
|
gtk_container_add (GTK_CONTAINER (viewport), editor->p->options_vbox);
|
||||||
gtk_widget_show (editor->p->options_vbox);
|
gtk_widget_show (editor->p->options_vbox);
|
||||||
|
|
||||||
editor->p->save_queue = NULL;
|
|
||||||
editor->p->save_idle_id = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -210,7 +199,7 @@ gimp_tool_options_editor_constructed (GObject *object)
|
||||||
|
|
||||||
editor->p->save_button =
|
editor->p->save_button =
|
||||||
gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_SAVE,
|
gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_SAVE,
|
||||||
_("Save options to..."),
|
_("Save Tool Preset..."),
|
||||||
GIMP_HELP_TOOL_OPTIONS_SAVE,
|
GIMP_HELP_TOOL_OPTIONS_SAVE,
|
||||||
G_CALLBACK (gimp_tool_options_editor_save_clicked),
|
G_CALLBACK (gimp_tool_options_editor_save_clicked),
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -218,7 +207,7 @@ gimp_tool_options_editor_constructed (GObject *object)
|
||||||
|
|
||||||
editor->p->restore_button =
|
editor->p->restore_button =
|
||||||
gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_REVERT_TO_SAVED,
|
gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_REVERT_TO_SAVED,
|
||||||
_("Restore options from..."),
|
_("Restore Tool Preset..."),
|
||||||
GIMP_HELP_TOOL_OPTIONS_RESTORE,
|
GIMP_HELP_TOOL_OPTIONS_RESTORE,
|
||||||
G_CALLBACK (gimp_tool_options_editor_restore_clicked),
|
G_CALLBACK (gimp_tool_options_editor_restore_clicked),
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -226,7 +215,7 @@ gimp_tool_options_editor_constructed (GObject *object)
|
||||||
|
|
||||||
editor->p->delete_button =
|
editor->p->delete_button =
|
||||||
gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_DELETE,
|
gimp_editor_add_button (GIMP_EDITOR (editor), GTK_STOCK_DELETE,
|
||||||
_("Delete saved options..."),
|
_("Delete Tool Preset..."),
|
||||||
GIMP_HELP_TOOL_OPTIONS_DELETE,
|
GIMP_HELP_TOOL_OPTIONS_DELETE,
|
||||||
G_CALLBACK (gimp_tool_options_editor_delete_clicked),
|
G_CALLBACK (gimp_tool_options_editor_delete_clicked),
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -275,8 +264,6 @@ gimp_tool_options_editor_dispose (GObject *object)
|
||||||
editor->p->options_vbox = NULL;
|
editor->p->options_vbox = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gimp_tool_options_editor_save_presets (editor);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +417,7 @@ gimp_tool_options_editor_save_clicked (GtkWidget *widget,
|
||||||
{
|
{
|
||||||
gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
|
gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
|
||||||
"tool-options",
|
"tool-options",
|
||||||
"tool-options-save-new");
|
"tool-options-save-new-preset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,8 +457,8 @@ gimp_tool_options_editor_tool_changed (GimpContext *context,
|
||||||
GimpToolInfo *tool_info,
|
GimpToolInfo *tool_info,
|
||||||
GimpToolOptionsEditor *editor)
|
GimpToolOptionsEditor *editor)
|
||||||
{
|
{
|
||||||
GimpToolPresets *presets;
|
GimpContainer *presets;
|
||||||
GtkWidget *options_gui;
|
GtkWidget *options_gui;
|
||||||
|
|
||||||
if (tool_info && tool_info->tool_options == editor->p->visible_tool_options)
|
if (tool_info && tool_info->tool_options == editor->p->visible_tool_options)
|
||||||
return;
|
return;
|
||||||
|
@ -482,7 +469,7 @@ gimp_tool_options_editor_tool_changed (GimpContext *context,
|
||||||
|
|
||||||
if (presets)
|
if (presets)
|
||||||
g_signal_handlers_disconnect_by_func (presets,
|
g_signal_handlers_disconnect_by_func (presets,
|
||||||
gimp_tool_options_editor_presets_changed,
|
gimp_tool_options_editor_presets_update,
|
||||||
editor);
|
editor);
|
||||||
|
|
||||||
options_gui = gimp_tools_get_tool_options_gui (editor->p->visible_tool_options);
|
options_gui = gimp_tools_get_tool_options_gui (editor->p->visible_tool_options);
|
||||||
|
@ -498,9 +485,17 @@ gimp_tool_options_editor_tool_changed (GimpContext *context,
|
||||||
presets = tool_info->presets;
|
presets = tool_info->presets;
|
||||||
|
|
||||||
if (presets)
|
if (presets)
|
||||||
g_signal_connect_object (presets, "changed",
|
{
|
||||||
G_CALLBACK (gimp_tool_options_editor_presets_changed),
|
g_signal_connect_object (presets, "add",
|
||||||
G_OBJECT (editor), 0);
|
G_CALLBACK (gimp_tool_options_editor_presets_update),
|
||||||
|
G_OBJECT (editor), G_CONNECT_SWAPPED);
|
||||||
|
g_signal_connect_object (presets, "remove",
|
||||||
|
G_CALLBACK (gimp_tool_options_editor_presets_update),
|
||||||
|
G_OBJECT (editor), G_CONNECT_SWAPPED);
|
||||||
|
g_signal_connect_object (presets, "thaw",
|
||||||
|
G_CALLBACK (gimp_tool_options_editor_presets_update),
|
||||||
|
G_OBJECT (editor), G_CONNECT_SWAPPED);
|
||||||
|
}
|
||||||
|
|
||||||
options_gui = gimp_tools_get_tool_options_gui (tool_info->tool_options);
|
options_gui = gimp_tools_get_tool_options_gui (tool_info->tool_options);
|
||||||
|
|
||||||
|
@ -515,12 +510,8 @@ gimp_tool_options_editor_tool_changed (GimpContext *context,
|
||||||
gimp_help_set_help_data (editor->p->scrolled_window, NULL,
|
gimp_help_set_help_data (editor->p->scrolled_window, NULL,
|
||||||
tool_info->help_id);
|
tool_info->help_id);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
presets = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gimp_tool_options_editor_presets_update (editor, presets);
|
gimp_tool_options_editor_presets_update (editor);
|
||||||
|
|
||||||
if (editor->p->title_label != NULL)
|
if (editor->p->title_label != NULL)
|
||||||
{
|
{
|
||||||
|
@ -534,87 +525,21 @@ gimp_tool_options_editor_tool_changed (GimpContext *context,
|
||||||
gimp_docked_title_changed (GIMP_DOCKED (editor));
|
gimp_docked_title_changed (GIMP_DOCKED (editor));
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gimp_tool_options_editor_save_presets_idle (GimpToolOptionsEditor *editor)
|
|
||||||
{
|
|
||||||
editor->p->save_idle_id = 0;
|
|
||||||
|
|
||||||
gimp_tool_options_editor_save_presets (editor);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_tool_options_editor_queue_save_presets (GimpToolOptionsEditor *editor,
|
gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor)
|
||||||
GimpToolPresets *presets)
|
|
||||||
{
|
{
|
||||||
if (g_list_find (editor->p->save_queue, presets))
|
GimpToolInfo *tool_info = editor->p->visible_tool_options->tool_info;
|
||||||
return;
|
gboolean save_sensitive = FALSE;
|
||||||
|
gboolean restore_sensitive = FALSE;
|
||||||
|
gboolean delete_sensitive = FALSE;
|
||||||
|
gboolean reset_sensitive = FALSE;
|
||||||
|
|
||||||
editor->p->save_queue = g_list_append (editor->p->save_queue, presets);
|
if (tool_info->presets)
|
||||||
|
|
||||||
if (! editor->p->save_idle_id)
|
|
||||||
{
|
|
||||||
editor->p->save_idle_id =
|
|
||||||
g_idle_add ((GSourceFunc) gimp_tool_options_editor_save_presets_idle,
|
|
||||||
editor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_options_editor_save_presets (GimpToolOptionsEditor *editor)
|
|
||||||
{
|
|
||||||
GList *list;
|
|
||||||
|
|
||||||
if (editor->p->save_idle_id)
|
|
||||||
{
|
|
||||||
g_source_remove (editor->p->save_idle_id);
|
|
||||||
editor->p->save_idle_id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (list = editor->p->save_queue; list; list = list->next)
|
|
||||||
{
|
|
||||||
GimpToolPresets *presets = list->data;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
if (! gimp_tool_presets_save (presets, &error))
|
|
||||||
{
|
|
||||||
gimp_message (editor->p->gimp, G_OBJECT (editor), GIMP_MESSAGE_ERROR,
|
|
||||||
_("Error saving tool options presets: %s"),
|
|
||||||
error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free (editor->p->save_queue);
|
|
||||||
|
|
||||||
editor->p->save_queue = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_options_editor_presets_changed (GimpToolPresets *presets,
|
|
||||||
GimpToolOptionsEditor *editor)
|
|
||||||
{
|
|
||||||
gimp_tool_options_editor_queue_save_presets (editor, presets);
|
|
||||||
|
|
||||||
gimp_tool_options_editor_presets_update (editor, presets);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_tool_options_editor_presets_update (GimpToolOptionsEditor *editor,
|
|
||||||
GimpToolPresets *presets)
|
|
||||||
{
|
|
||||||
gboolean save_sensitive = FALSE;
|
|
||||||
gboolean restore_sensitive = FALSE;
|
|
||||||
gboolean delete_sensitive = FALSE;
|
|
||||||
gboolean reset_sensitive = FALSE;
|
|
||||||
|
|
||||||
if (presets)
|
|
||||||
{
|
{
|
||||||
save_sensitive = TRUE;
|
save_sensitive = TRUE;
|
||||||
reset_sensitive = TRUE;
|
reset_sensitive = TRUE;
|
||||||
|
|
||||||
if (! gimp_container_is_empty (GIMP_CONTAINER (presets)))
|
if (! gimp_container_is_empty (tool_info->presets))
|
||||||
{
|
{
|
||||||
restore_sensitive = TRUE;
|
restore_sensitive = TRUE;
|
||||||
delete_sensitive = TRUE;
|
delete_sensitive = TRUE;
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
<ui>
|
<ui>
|
||||||
<popup action="tool-options-popup">
|
<popup action="tool-options-popup">
|
||||||
<menu action="tool-options-save-menu" name="Save">
|
<menu action="tool-options-save-preset-menu" name="Save">
|
||||||
<menuitem action="tool-options-save-new" />
|
<menuitem action="tool-options-save-new-preset" />
|
||||||
<separator />
|
<separator />
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="tool-options-restore-menu" name="Restore" />
|
<menu action="tool-options-restore-preset-menu" name="Restore" />
|
||||||
<menu action="tool-options-rename-menu" name="Rename" />
|
<menu action="tool-options-edit-preset-menu" name="Edit" />
|
||||||
<menu action="tool-options-delete-menu" name="Delete" />
|
<menu action="tool-options-delete-preset-menu" name="Delete" />
|
||||||
<separator />
|
<separator />
|
||||||
<menuitem action="tool-options-reset" />
|
<menuitem action="tool-options-reset" />
|
||||||
<menuitem action="tool-options-reset-all" />
|
<menuitem action="tool-options-reset-all" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue