[gimp/wip/Jehan/issue-498-quick-brush-edit: 19/26] app: add a page in Preferences to set the canvas modifiers up.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/issue-498-quick-brush-edit: 19/26] app: add a page in Preferences to set the canvas modifiers up.
- Date: Wed, 17 Aug 2022 12:20:46 +0000 (UTC)
commit 89f55336a293cd04e7d212da4243524785ea3673
Author: Jehan <jehan girinstud io>
Date: Thu Aug 11 14:46:27 2022 +0200
app: add a page in Preferences to set the canvas modifiers up.
Finally everything is getting assembled with this commit. It is now
possible to customize the modifiers which will be used on canvas.
app/dialogs/preferences-dialog.c | 42 ++++++++-
app/display/gimpmodifiersmanager.c | 8 ++
app/display/gimpmodifiersmanager.h | 1 +
app/widgets/gimphelp-ids.h | 1 +
app/widgets/gimpmodifierseditor.c | 174 +++++++++++++++++++++----------------
app/widgets/gimpmodifierseditor.h | 2 +
6 files changed, 153 insertions(+), 75 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 5d46d7ca0c..7f201c1520 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -38,6 +38,8 @@
#include "core/gimptemplate.h"
#include "core/gimp-utils.h"
+#include "display/gimpmodifiersmanager.h"
+
#include "plug-in/gimppluginmanager.h"
#include "widgets/gimpaction-history.h"
@@ -56,6 +58,7 @@
#include "widgets/gimppluginview.h"
#include "widgets/gimpprefsbox.h"
#include "widgets/gimppropwidgets.h"
+#include "widgets/gimpmodifierseditor.h"
#include "widgets/gimpstrokeeditor.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimptooleditor.h"
@@ -65,8 +68,9 @@
#include "tools/gimp-tools.h"
-#include "gui/session.h"
#include "gui/icon-themes.h"
+#include "gui/session.h"
+#include "gui/modifiers.h"
#include "gui/themes.h"
#include "preferences-dialog.h"
@@ -130,6 +134,8 @@ static void prefs_devices_save_callback (GtkWidget *widget,
Gimp *gimp);
static void prefs_devices_clear_callback (GtkWidget *widget,
Gimp *gimp);
+static void prefs_modifiers_clear_callback (GtkWidget *widget,
+ GimpModifiersEditor *editor);
static void prefs_search_clear_callback (GtkWidget *widget,
Gimp *gimp);
static void prefs_tool_options_save_callback (GtkWidget *widget,
@@ -770,6 +776,13 @@ prefs_devices_clear_callback (GtkWidget *widget,
}
}
+static void
+prefs_modifiers_clear_callback (GtkWidget *widget,
+ GimpModifiersEditor *editor)
+{
+ gimp_modifiers_editor_clear (editor);
+}
+
#ifdef G_OS_WIN32
static gboolean
@@ -2957,6 +2970,33 @@ prefs_dialog_new (Gimp *gimp,
_("Drag-to-zoom spe_ed:"),
GTK_GRID (grid), 0, size_group);
+
+ /************************************/
+ /* Canvas Interaction / Modifiers */
+ /************************************/
+ vbox = gimp_prefs_box_add_page (GIMP_PREFS_BOX (prefs_box),
+ /* TODO: custom icon. */
+ "gimp-prefs-image-windows",
+ _("Modifiers"),
+ _("Modifiers"),
+ GIMP_HELP_PREFS_CANVAS_MODIFIERS,
+ &top_iter,
+ &child_iter);
+
+ vbox2 = gimp_modifiers_editor_new (GIMP_MODIFIERS_MANAGER (display_config->modifiers_manager));
+ gtk_widget_show (vbox2);
+ gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
+
+ button2 = prefs_button_add (GIMP_ICON_RESET,
+ _("_Reset Saved Modifiers Settings to "
+ "Default Values"),
+ GTK_BOX (vbox));
+ g_signal_connect (button2, "clicked",
+ G_CALLBACK (prefs_modifiers_clear_callback),
+ vbox2);
+
+ g_object_set_data (G_OBJECT (button), "clear-button", button2);
+
/***********************************/
/* Canvas Interaction / Snapping */
/***********************************/
diff --git a/app/display/gimpmodifiersmanager.c b/app/display/gimpmodifiersmanager.c
index 9b31560cb4..c2b86958fa 100644
--- a/app/display/gimpmodifiersmanager.c
+++ b/app/display/gimpmodifiersmanager.c
@@ -461,6 +461,14 @@ gimp_modifiers_manager_remove (GimpModifiersManager *manager,
GIMP_MODIFIER_ACTION_NONE);
}
+void
+gimp_modifiers_manager_clear (GimpModifiersManager *manager)
+{
+ g_hash_table_remove_all (manager->p->actions);
+ g_list_free_full (manager->p->buttons, g_free);
+ manager->p->buttons = NULL;
+}
+
/* Private functions */
static void
diff --git a/app/display/gimpmodifiersmanager.h b/app/display/gimpmodifiersmanager.h
index 420efd66f9..8cffdc2e4d 100644
--- a/app/display/gimpmodifiersmanager.h
+++ b/app/display/gimpmodifiersmanager.h
@@ -75,6 +75,7 @@ void gimp_modifiers_manager_remove (GimpModifiersManage
GdkDevice *device,
guint button,
GdkModifierType modifiers);
+void gimp_modifiers_manager_clear (GimpModifiersManager *manager);
#endif /* __GIMP_MODIFIERS_MANAGER_H__ */
diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h
index 24a6845157..13f9cd6224 100644
--- a/app/widgets/gimphelp-ids.h
+++ b/app/widgets/gimphelp-ids.h
@@ -646,6 +646,7 @@
#define GIMP_HELP_PREFS_DISPLAY "gimp-prefs-display"
#define GIMP_HELP_PREFS_WINDOW_MANAGEMENT "gimp-prefs-window-management"
#define GIMP_HELP_PREFS_CANVAS_INTERACTION "gimp-prefs-canvas-interaction"
+#define GIMP_HELP_PREFS_CANVAS_MODIFIERS "gimp-prefs-canvas-modifiers"
#define GIMP_HELP_PREFS_IMAGE_WINDOW "gimp-prefs-image-window"
#define GIMP_HELP_PREFS_IMAGE_WINDOW_APPEARANCE "gimp-prefs-image-window-appearance"
#define GIMP_HELP_PREFS_IMAGE_WINDOW_TITLE "gimp-prefs-image-window-title"
diff --git a/app/widgets/gimpmodifierseditor.c b/app/widgets/gimpmodifierseditor.c
index 9e7acf1790..b11224bd0c 100644
--- a/app/widgets/gimpmodifierseditor.c
+++ b/app/widgets/gimpmodifierseditor.c
@@ -87,6 +87,9 @@ static void gimp_modifiers_editor_notify_accelerator (GtkWidget
const GParamSpec *pspec,
GimpModifiersEditor *editor);
+static void gimp_modifiers_editor_show_settings (GimpModifiersEditor *editor,
+ GdkDevice *device,
+ guint button);
static void gimp_modifiers_editor_add_mapping (GimpModifiersEditor *editor,
GdkModifierType modifiers,
GimpModifierAction mod_action);
@@ -251,6 +254,102 @@ gimp_modifiers_editor_new (GimpModifiersManager *manager)
return GTK_WIDGET (editor);
}
+void
+gimp_modifiers_editor_clear (GimpModifiersEditor *editor)
+{
+ gimp_modifiers_manager_clear (editor->priv->manager);
+ gtk_container_foreach (GTK_CONTAINER (editor->priv->stack),
+ (GtkCallback) gtk_widget_destroy,
+ NULL);
+ gimp_modifiers_editor_show_settings (editor, editor->priv->device, editor->priv->button);
+}
+
+/* private functions */
+
+static void
+gimp_modifiers_editor_show_settings (GimpModifiersEditor *editor,
+ GdkDevice *device,
+ guint button)
+{
+ const gchar *vendor_id;
+ const gchar *product_id;
+ gchar *title;
+ gchar *text;
+
+ vendor_id = gdk_device_get_vendor_id (device);
+ product_id = gdk_device_get_product_id (device);
+
+ if (device != editor->priv->device)
+ {
+ g_clear_object (&editor->priv->device);
+ editor->priv->device = g_object_ref (device);
+ }
+ editor->priv->button = button;
+
+ /* Update header. */
+ if (gdk_device_get_name (device) != NULL)
+ text = g_strdup_printf (_("Editing modifiers for button %d of %s"),
+ editor->priv->button,
+ gdk_device_get_name (device));
+ else
+ text = g_strdup_printf (_("Editing modifiers for button %d"),
+ editor->priv->button);
+
+ title = g_strdup_printf ("<b><big>%s</big></b>", text);
+ gtk_label_set_markup (GTK_LABEL (editor->priv->header), title);
+
+ g_free (title);
+ g_free (text);
+
+ /* Update modifier settings. */
+ text = g_strdup_printf ("%s:%s-%d",
+ vendor_id ? vendor_id : "*",
+ product_id ? product_id : "*",
+ button);
+ editor->priv->current_settings = gtk_stack_get_child_by_name (GTK_STACK (editor->priv->stack), text);
+
+ if (! editor->priv->current_settings)
+ {
+ GtkWidget *plus_button;
+ GList *modifiers;
+ GList *iter;
+
+ editor->priv->current_settings = gtk_list_box_new ();
+ gtk_stack_add_named (GTK_STACK (editor->priv->stack), editor->priv->current_settings, text);
+
+ modifiers = gimp_modifiers_manager_get_modifiers (editor->priv->manager,
+ device, editor->priv->button);
+ for (iter = modifiers; iter; iter = iter->next)
+ {
+ GdkModifierType mods = GPOINTER_TO_INT (iter->data);
+ GimpModifierAction action;
+
+ action = gimp_modifiers_manager_get_action (editor->priv->manager, device,
+ editor->priv->button, mods);
+ gimp_modifiers_editor_add_mapping (editor, mods, action);
+ }
+
+ plus_button = gtk_button_new_from_icon_name ("list-add", GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_list_box_insert (GTK_LIST_BOX (editor->priv->current_settings), plus_button, -1);
+ gtk_widget_show (plus_button);
+
+ g_signal_connect (plus_button, "clicked",
+ G_CALLBACK (gimp_modifiers_editor_plus_button_clicked),
+ editor);
+ g_object_set_data (G_OBJECT (editor->priv->current_settings), "plus-button", plus_button);
+
+ if (g_list_length (modifiers) == 0)
+ gimp_modifiers_editor_plus_button_clicked (GTK_BUTTON (plus_button), editor);
+
+ gtk_widget_show (editor->priv->current_settings);
+ g_list_free (modifiers);
+ }
+
+ gtk_stack_set_visible_child (GTK_STACK (editor->priv->stack), editor->priv->current_settings);
+
+ g_free (text);
+}
+
static gboolean
gimp_modifiers_editor_button_press_event (GtkWidget *widget,
GdkEventButton *event,
@@ -258,11 +357,6 @@ gimp_modifiers_editor_button_press_event (GtkWidget *widget,
{
GimpModifiersEditor *editor = GIMP_MODIFIERS_EDITOR (user_data);
GdkDevice *device = gdk_event_get_source_device ((GdkEvent *) event);
- const gchar *vendor_id;
- const gchar *product_id;
-
- vendor_id = gdk_device_get_vendor_id (device);
- product_id = gdk_device_get_product_id (device);
/* Update warning. */
if (event->button == GDK_BUTTON_PRIMARY)
@@ -283,75 +377,7 @@ gimp_modifiers_editor_button_press_event (GtkWidget *widget,
g_strcmp0 (gdk_device_get_product_id (editor->priv->device),
gdk_device_get_product_id (device)) != 0))
{
- gchar *title;
- gchar *text;
-
- g_clear_object (&editor->priv->device);
- editor->priv->device = g_object_ref (device);
- editor->priv->button = event->button;
-
- /* Update header. */
- if (gdk_device_get_name (device) != NULL)
- text = g_strdup_printf (_("Editing modifiers for button %d of %s"),
- editor->priv->button,
- gdk_device_get_name (device));
- else
- text = g_strdup_printf (_("Editing modifiers for button %d"),
- editor->priv->button);
-
- title = g_strdup_printf ("<b><big>%s</big></b>", text);
- gtk_label_set_markup (GTK_LABEL (editor->priv->header), title);
-
- g_free (title);
- g_free (text);
-
- /* Update modifier settings. */
- text = g_strdup_printf ("%s:%s-%d",
- vendor_id ? vendor_id : "*",
- product_id ? product_id : "*",
- event->button);
- editor->priv->current_settings = gtk_stack_get_child_by_name (GTK_STACK (editor->priv->stack), text);
-
- if (! editor->priv->current_settings)
- {
- GtkWidget *plus_button;
- GList *modifiers;
- GList *iter;
-
- editor->priv->current_settings = gtk_list_box_new ();
- gtk_stack_add_named (GTK_STACK (editor->priv->stack), editor->priv->current_settings, text);
-
- modifiers = gimp_modifiers_manager_get_modifiers (editor->priv->manager,
- device, editor->priv->button);
- for (iter = modifiers; iter; iter = iter->next)
- {
- GdkModifierType mods = GPOINTER_TO_INT (iter->data);
- GimpModifierAction action;
-
- action = gimp_modifiers_manager_get_action (editor->priv->manager, device,
- editor->priv->button, mods);
- gimp_modifiers_editor_add_mapping (editor, mods, action);
- }
-
- plus_button = gtk_button_new_from_icon_name ("list-add", GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_list_box_insert (GTK_LIST_BOX (editor->priv->current_settings), plus_button, -1);
- gtk_widget_show (plus_button);
-
- g_signal_connect (plus_button, "clicked",
- G_CALLBACK (gimp_modifiers_editor_plus_button_clicked),
- editor);
- g_object_set_data (G_OBJECT (editor->priv->current_settings), "plus-button", plus_button);
-
- if (g_list_length (modifiers) == 0)
- gimp_modifiers_editor_plus_button_clicked (GTK_BUTTON (plus_button), editor);
-
- gtk_widget_show (editor->priv->current_settings);
- g_list_free (modifiers);
- }
-
- gtk_stack_set_visible_child (GTK_STACK (editor->priv->stack), editor->priv->current_settings);
-
- g_free (text);
+ gimp_modifiers_editor_show_settings (editor, device, event->button);
}
return FALSE;
diff --git a/app/widgets/gimpmodifierseditor.h b/app/widgets/gimpmodifierseditor.h
index 32179c10ad..275f88d78f 100644
--- a/app/widgets/gimpmodifierseditor.h
+++ b/app/widgets/gimpmodifierseditor.h
@@ -50,5 +50,7 @@ GType gimp_modifiers_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_modifiers_editor_new (GimpModifiersManager *manager);
+void gimp_modifiers_editor_clear (GimpModifiersEditor *editor);
+
#endif /* __GIMP_MODIFIERS_EDITOR_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]