gimp/app/actions/tool-options-commands.c

268 lines
8.8 KiB
C
Raw Normal View History

/* GIMP - The GNU 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 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
2005-01-26 03:11:26 +08:00
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpdatafactory.h"
#include "core/gimptoolinfo.h"
#include "core/gimptooloptions.h"
#include "core/gimptoolpreset.h"
#include "widgets/gimpdataeditor.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpeditor.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "widgets/gimptooloptionseditor.h"
Switch from GtkItemFactory to GtkUIManager. The migration is almost 2004-04-29 Michael Natterer <mitch@gimp.org> Switch from GtkItemFactory to GtkUIManager. The migration is almost complete, still stuff missing/incomplete, definitely added a bunch of new bugs... * app/actions/*-commands.[ch]: converted all callback from GtkItemFactory callbacks to GtkAction callbacks. * app/actions/debug-actions.c * app/actions/gradient-editor-actions.c * app/actions/help-actions.c * app/actions/plug-in-actions.c * app/actions/qmask-actions.c * app/actions/tool-options-actions.c: various fixes. * app/display/gimpdisplay.[ch] * app/display/gimpdisplayshell-appearance.[ch] * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell.[ch]: move everything from GtkItemFactory to GtkUIManager. * app/gui/dialogs.[ch]: added new function dialogs_get_toolbox(). Needed because the action callbacks don't have a widget parameter and sometimes we need a parent window for showing dialogs. * app/gui/Makefile.am * app/gui/brushes-menu.[ch] * app/gui/buffers-menu.[ch] * app/gui/channels-menu.[ch] * app/gui/colormap-editor-menu.[ch] * app/gui/dialogs-menu.[ch] * app/gui/documents-menu.[ch] * app/gui/error-console-menu.[ch] * app/gui/fonts-menu.[ch] * app/gui/gradient-editor-menu.[ch] * app/gui/gradients-menu.[ch] * app/gui/images-menu.[ch] * app/gui/layers-menu.[ch] * app/gui/palette-editor-menu.[ch] * app/gui/palettes-menu.[ch] * app/gui/patterns-menu.[ch] * app/gui/qmask-menu.[ch] * app/gui/templates-menu.[ch] * app/gui/vectors-menu.[ch]: removed these files. * app/gui/gui.c: create a global UI manager for the image popup menu and the toolbox menubar. * app/gui/menus.[ch]: removed all GtkItemFactory code. * app/gui/image-menu.[ch] * app/gui/toolbox-menu.[ch]: removed everything except the trivial setup_funcs. * app/gui/file-open-menu.c * app/gui/file-save-menu.c * app/gui/tool-options-menu.c: don't use the macros from menus.h any more, they are gone. * app/gui/gui-vtable.c * app/gui/plug-in-menus.[ch]: create/destroy the dynamic plug-in menu entries. * app/tools/gimpimagemaptool.c: s/gimp_item_factory_update/ gimp_ui_manager_update/g * app/widgets/gimpuimanager.[ch]: added API to get an action group by name. * app/widgets/gimpmenufactory.c: don't choke on the item_factory entries being NULL. * app/widgets/gimpactiongroup.c: make sure booleans set using g_object_set() only have TRUE or FALSE values. * app/widgets/gimpcolormapeditor.c * app/widgets/gimpcomponenteditor.c * app/widgets/gimpcontainereditor.[ch] * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainertreeview.c * app/widgets/gimpdockable.[ch] * app/widgets/gimpdocked.[ch] * app/widgets/gimpeditor.[ch] * app/widgets/gimperrorconsole.c * app/widgets/gimpgradienteditor.c * app/widgets/gimpitemtreeview.c * app/widgets/gimppaletteeditor.c * app/widgets/gimptoolbox.c * app/widgets/gimptooloptionseditor.c: removed all GtkItemFactory code and enable the #if 0'ed UI manager stuff. * menus/gradient-editor-menu.xml: fixed typos. * menus/image-menu.xml: duplicate everything so we have both an image menubar and an image popup menu. Badly cries for an XSL processor. * menus/toolbox-menu.xml: added an "Extensions" placeholder.
2004-04-29 20:52:29 +08:00
#include "widgets/gimpuimanager.h"
#include "widgets/gimpwidgets-utils.h"
#include "widgets/gimpwindowstrategy.h"
#include "dialogs/data-delete-dialog.h"
#include "tool-options-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void tool_options_show_preset_editor (Gimp *gimp,
GimpEditor *editor,
GimpToolPreset *preset);
/* public functions */
void
tool_options_save_new_preset_cmd_callback (GimpAction *action,
GVariant *value,
gpointer user_data)
{
GimpEditor *editor = GIMP_EDITOR (user_data);
Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp;
GimpContext *context = gimp_get_user_context (gimp);
GimpData *data;
data = gimp_data_factory_data_new (context->gimp->tool_preset_factory,
context, _("Untitled"));
tool_options_show_preset_editor (gimp, editor, GIMP_TOOL_PRESET (data));
}
void
tool_options_save_preset_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp;
GimpContext *context = gimp_get_user_context (gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolPreset *preset;
gint index;
index = g_variant_get_int32 (value);
preset = (GimpToolPreset *)
gimp_container_get_child_by_index (tool_info->presets, index);
if (preset)
{
gimp_config_sync (G_OBJECT (tool_info->tool_options),
G_OBJECT (preset->tool_options), 0);
tool_options_show_preset_editor (gimp, editor, preset);
}
}
void
tool_options_restore_preset_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp;
GimpContext *context = gimp_get_user_context (gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolPreset *preset;
gint index;
index = g_variant_get_int32 (value);
preset = (GimpToolPreset *)
gimp_container_get_child_by_index (tool_info->presets, index);
if (preset)
{
if (gimp_context_get_tool_preset (context) != preset)
gimp_context_set_tool_preset (context, preset);
else
gimp_context_tool_preset_changed (context);
}
}
void
tool_options_edit_preset_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp;
GimpContext *context = gimp_get_user_context (gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolPreset *preset;
gint index;
index = g_variant_get_int32 (value);
preset = (GimpToolPreset *)
gimp_container_get_child_by_index (tool_info->presets, index);
if (preset)
{
tool_options_show_preset_editor (gimp, editor, preset);
}
}
void
tool_options_delete_preset_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (gimp_editor_get_ui_manager (editor)->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
GimpToolPreset *preset;
gint index;
index = g_variant_get_int32 (value);
preset = (GimpToolPreset *)
gimp_container_get_child_by_index (tool_info->presets, index);
if (preset &&
gimp_data_is_deletable (GIMP_DATA (preset)))
{
GimpDataFactory *factory = context->gimp->tool_preset_factory;
GtkWidget *dialog;
dialog = data_delete_dialog_new (factory, GIMP_DATA (preset), NULL,
GTK_WIDGET (editor));
gtk_widget_show (dialog);
}
}
void
tool_options_reset_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
GimpContext *context = gimp_get_user_context (gimp_editor_get_ui_manager (editor)->gimp);
GimpToolInfo *tool_info = gimp_context_get_tool (context);
gimp_config_reset (GIMP_CONFIG (tool_info->tool_options));
}
void
tool_options_reset_all_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpEditor *editor = GIMP_EDITOR (data);
GtkWidget *dialog;
dialog = gimp_message_dialog_new (_("Reset All Tool Options"),
GIMP_ICON_DIALOG_QUESTION,
GTK_WIDGET (editor),
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func, NULL,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Reset"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
g_signal_connect_object (gtk_widget_get_toplevel (GTK_WIDGET (editor)),
"unmap",
G_CALLBACK (gtk_widget_destroy),
dialog, G_CONNECT_SWAPPED);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Do you really want to reset all "
"tool options to default values?"));
if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK)
{
Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp;
GList *list;
for (list = gimp_get_tool_info_iter (gimp);
list;
list = g_list_next (list))
{
GimpToolInfo *tool_info = list->data;
gimp_config_reset (GIMP_CONFIG (tool_info->tool_options));
}
}
gtk_widget_destroy (dialog);
}
/* private functions */
static void
tool_options_show_preset_editor (Gimp *gimp,
GimpEditor *editor,
GimpToolPreset *preset)
{
GtkWidget *dockable;
dockable =
gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (gimp)),
gimp,
gimp_dialog_factory_get_singleton (),
gimp_widget_get_monitor (GTK_WIDGET (editor)),
"gimp-tool-preset-editor");
gimp_data_editor_set_data (GIMP_DATA_EDITOR (gtk_bin_get_child (GTK_BIN (dockable))),
GIMP_DATA (preset));
}