[gimp/wip/Jehan/layers-dockable-refresh: 54/58] app: add a preferences for choosing your prefered search pattern format.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/layers-dockable-refresh: 54/58] app: add a preferences for choosing your prefered search pattern format.
- Date: Fri, 22 Oct 2021 21:36:51 +0000 (UTC)
commit fb1829b95ba1301c8a4c4987f2c0295cabde233d
Author: Jehan <jehan girinstud io>
Date: Tue Oct 5 01:56:51 2021 +0200
app: add a preferences for choosing your prefered search pattern format.
The 3 available formats are: simple text search, regular expressions and
glob patterns (cf. previous commit). I did a small step back from
previous commit by getting "is-pattern" property back in GimpItemList
instead of having this case as a value of GimpSelectMethod. The reason
is that it would render a useless value in the Preferences combo box.
Text search is the default.
app/config/gimpcoreconfig.c | 15 +++++++++
app/config/gimpcoreconfig.h | 1 +
app/config/gimprc-blurbs.h | 3 ++
app/core/core-enums.h | 1 -
app/core/gimpitemlist.c | 73 +++++++++++++++++++++++++---------------
app/dialogs/preferences-dialog.c | 7 ++++
app/widgets/gimplayertreeview.c | 72 ++++++++++++++++++++++++++++++++++-----
7 files changed, 134 insertions(+), 38 deletions(-)
---
diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c
index 428c996943..7d8f250353 100644
--- a/app/config/gimpcoreconfig.c
+++ b/app/config/gimpcoreconfig.c
@@ -138,6 +138,7 @@ enum
#ifdef G_OS_WIN32
PROP_WIN32_POINTER_INPUT_API,
#endif
+ PROP_ITEMS_SELECT_METHOD,
/* ignored, only for backward compatibility: */
PROP_INSTALL_COLORMAP,
@@ -845,6 +846,14 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
GIMP_CONFIG_PARAM_RESTART);
#endif
+ GIMP_CONFIG_PROP_ENUM (object_class, PROP_ITEMS_SELECT_METHOD,
+ "items-select-method",
+ _("Pattern syntax for searching and selecting items:"),
+ ITEMS_SELECT_METHOD_BLURB,
+ GIMP_TYPE_SELECT_METHOD,
+ GIMP_SELECT_PLAIN_TEXT,
+ GIMP_PARAM_STATIC_STRINGS);
+
/* only for backward compatibility: */
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_INSTALL_COLORMAP,
"install-colormap",
@@ -1215,6 +1224,9 @@ gimp_core_config_set_property (GObject *object,
}
break;
#endif
+ case PROP_ITEMS_SELECT_METHOD:
+ core_config->items_select_method = g_value_get_enum (value);
+ break;
case PROP_INSTALL_COLORMAP:
case PROP_MIN_COLORS:
@@ -1452,6 +1464,9 @@ gimp_core_config_get_property (GObject *object,
g_value_set_enum (value, core_config->win32_pointer_input_api);
break;
#endif
+ case PROP_ITEMS_SELECT_METHOD:
+ g_value_set_enum (value, core_config->items_select_method);
+ break;
case PROP_INSTALL_COLORMAP:
case PROP_MIN_COLORS:
diff --git a/app/config/gimpcoreconfig.h b/app/config/gimpcoreconfig.h
index acac7e8675..ec2c80bdc9 100644
--- a/app/config/gimpcoreconfig.h
+++ b/app/config/gimpcoreconfig.h
@@ -107,6 +107,7 @@ struct _GimpCoreConfig
#ifdef G_OS_WIN32
GimpWin32PointerInputAPI win32_pointer_input_api;
#endif
+ GimpSelectMethod items_select_method;
gboolean check_updates;
gint64 check_update_timestamp;
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 5522014142..127d414ef0 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -576,6 +576,9 @@ _("Sets the default set of layers to resize for the 'Canvas Size' dialog.")
#define IMAGE_RESIZE_RESIZE_TEXT_LAYERS_BLURB \
_("Sets the default 'Resize text layers' state for the 'Canvas Size' dialog.")
+# define ITEMS_SELECT_METHOD_BLURB \
+_("Sets how items are searched and selected from a textual pattern.")
+
#define LAYER_NEW_NAME_BLURB \
_("Sets the default layer name for the 'New Layer' dialog.")
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index 6a5aabc44d..77145b5bf3 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -671,7 +671,6 @@ GType gimp_select_method_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
{
- GIMP_SELECT_FIXED, /*< desc="Selection of fixed list of items" >*/
GIMP_SELECT_PLAIN_TEXT, /*< desc="Selection by basic text search" >*/
GIMP_SELECT_REGEX_PATTERN, /*< desc="Selection by regular expression search" >*/
GIMP_SELECT_GLOB_PATTERN, /*< desc="Selection by glob pattern search" >*/
diff --git a/app/core/gimpitemlist.c b/app/core/gimpitemlist.c
index 361378dcd0..7dd5c08e89 100644
--- a/app/core/gimpitemlist.c
+++ b/app/core/gimpitemlist.c
@@ -51,6 +51,7 @@ enum
{
PROP_0,
PROP_IMAGE,
+ PROP_IS_PATTERN,
PROP_SELECT_METHOD,
PROP_ITEMS,
PROP_ITEM_TYPE,
@@ -64,11 +65,12 @@ struct _GimpItemListPrivate
{
GimpImage *image;
- gchar *label; /* Item set name or pattern. */
- GimpSelectMethod select_method; /* Named fixed set or a pattern-search. */
+ gchar *label; /* Item set name or pattern. */
+ gboolean is_pattern; /* Whether a named fixed set or a pattern-search. */
+ GimpSelectMethod select_method; /* Pattern format if is_pattern is TRUE */
- GList *items; /* Fixed item list if select_method is GIMP_SELECT_FIXED. */
- GList *deleted_items; /* Removed item list kept for undoes. */
+ GList *items; /* Fixed item list if is_pattern is TRUE. */
+ GList *deleted_items; /* Removed item list kept for undoes. */
GType item_type;
};
@@ -145,6 +147,10 @@ gimp_item_list_class_init (GimpItemListClass *klass)
GIMP_TYPE_IMAGE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
+ gimp_item_list_props[PROP_IS_PATTERN] = g_param_spec_boolean ("is-pattern", NULL, NULL,
+ FALSE,
+ GIMP_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY);
gimp_item_list_props[PROP_SELECT_METHOD] = g_param_spec_enum ("select-method", NULL, NULL,
GIMP_TYPE_SELECT_METHOD,
GIMP_SELECT_PLAIN_TEXT,
@@ -170,7 +176,8 @@ gimp_item_list_init (GimpItemList *set)
set->p->label = NULL;
set->p->items = NULL;
- set->p->select_method = GIMP_SELECT_FIXED;
+ set->p->select_method = GIMP_SELECT_PLAIN_TEXT;
+ set->p->is_pattern = FALSE;
}
static void
@@ -181,12 +188,12 @@ gimp_item_list_constructed (GObject *object)
G_OBJECT_CLASS (parent_class)->constructed (object);
gimp_assert (GIMP_IS_IMAGE (set->p->image));
- gimp_assert (set->p->items != NULL || set->p->select_method != GIMP_SELECT_FIXED);
+ gimp_assert (set->p->items != NULL || set->p->is_pattern);
gimp_assert (set->p->item_type == GIMP_TYPE_LAYER ||
set->p->item_type == GIMP_TYPE_VECTORS ||
set->p->item_type == GIMP_TYPE_CHANNEL);
- if (set->p->select_method == GIMP_SELECT_FIXED)
+ if (! set->p->is_pattern)
{
GimpContainer *container;
@@ -210,7 +217,7 @@ gimp_item_list_dispose (GObject *object)
{
GimpItemList *set = GIMP_ITEM_LIST (object);
- if (set->p->select_method == GIMP_SELECT_FIXED)
+ if (! set->p->is_pattern)
{
GimpContainer *container;
@@ -255,6 +262,9 @@ gimp_item_list_set_property (GObject *object,
case PROP_IMAGE:
set->p->image = g_value_get_object (value);
break;
+ case PROP_IS_PATTERN:
+ set->p->is_pattern = g_value_get_boolean (value);
+ break;
case PROP_SELECT_METHOD:
set->p->select_method = g_value_get_enum (value);
break;
@@ -284,6 +294,9 @@ gimp_item_list_get_property (GObject *object,
case PROP_IMAGE:
g_value_set_object (value, set->p->image);
break;
+ case PROP_IS_PATTERN:
+ g_value_set_boolean (value, set->p->is_pattern);
+ break;
case PROP_SELECT_METHOD:
g_value_set_enum (value, set->p->select_method);
break;
@@ -380,13 +393,13 @@ gimp_item_list_pattern_new (GimpImage *image,
GimpItemList *set;
g_return_val_if_fail (g_type_is_a (item_type, GIMP_TYPE_ITEM), NULL);
- g_return_val_if_fail (pattern_syntax != GIMP_SELECT_FIXED, NULL);
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
/* TODO: check pattern first and fail if invalid. */
set = g_object_new (GIMP_TYPE_ITEM_LIST,
"image", image,
"name", pattern,
+ "is-pattern", TRUE,
"select-method", pattern_syntax,
"item-type", item_type,
NULL);
@@ -418,26 +431,30 @@ gimp_item_list_get_items (GimpItemList *set,
g_return_val_if_fail (GIMP_IS_ITEM_LIST (set), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- switch (set->p->select_method)
+ if (set->p->is_pattern)
+ {
+ switch (set->p->select_method)
+ {
+ case GIMP_SELECT_PLAIN_TEXT:
+ items = gimp_item_list_get_items_by_substr (set,
+ gimp_object_get_name (set),
+ error);
+ break;
+ case GIMP_SELECT_GLOB_PATTERN:
+ items = gimp_item_list_get_items_by_glob (set,
+ gimp_object_get_name (set),
+ error);
+ break;
+ case GIMP_SELECT_REGEX_PATTERN:
+ items = gimp_item_list_get_items_by_regexp (set,
+ gimp_object_get_name (set),
+ error);
+ break;
+ }
+ }
+ else
{
- case GIMP_SELECT_FIXED:
items = g_list_copy (set->p->items);
- break;
- case GIMP_SELECT_PLAIN_TEXT:
- items = gimp_item_list_get_items_by_substr (set,
- gimp_object_get_name (set),
- error);
- break;
- case GIMP_SELECT_GLOB_PATTERN:
- items = gimp_item_list_get_items_by_glob (set,
- gimp_object_get_name (set),
- error);
- break;
- case GIMP_SELECT_REGEX_PATTERN:
- items = gimp_item_list_get_items_by_regexp (set,
- gimp_object_get_name (set),
- error);
- break;
}
return items;
@@ -448,7 +465,7 @@ gimp_item_list_is_pattern (GimpItemList *set)
{
g_return_val_if_fail (GIMP_IS_ITEM_LIST (set), FALSE);
- return (set->p->select_method != GIMP_SELECT_FIXED);
+ return (set->p->is_pattern);
}
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 27e9a60060..befabb40bb 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1892,6 +1892,13 @@ prefs_dialog_new (Gimp *gimp,
_("Na_vigation preview size:"),
GTK_GRID (grid), 2, NULL);
+ /* Item */
+ vbox2 = prefs_frame_new (_("Item search"), GTK_CONTAINER (vbox), FALSE);
+ grid = prefs_grid_new (GTK_CONTAINER (vbox2));
+ prefs_enum_combo_box_add (object, "items-select-method", 0, 0,
+ _("Pattern syntax for searching and selecting items:"),
+ GTK_GRID (grid), 0, NULL);
+
/* Keyboard Shortcuts */
vbox2 = prefs_frame_new (_("Keyboard Shortcuts"),
GTK_CONTAINER (vbox), FALSE);
diff --git a/app/widgets/gimplayertreeview.c b/app/widgets/gimplayertreeview.c
index 9433cdeb72..de4f78d3b9 100644
--- a/app/widgets/gimplayertreeview.c
+++ b/app/widgets/gimplayertreeview.c
@@ -151,6 +151,8 @@ static void gimp_layer_tree_view_layer_links_changed (GimpImage
static gboolean gimp_layer_tree_view_link_clicked (GtkWidget *box,
GdkEvent *event,
GimpLayerTreeView *view);
+static void gimp_layer_tree_view_link_popover_shown (GtkPopover *popover,
+ GimpLayerTreeView *view);
static void gimp_layer_tree_view_regexp_modified (GtkEntry *entry,
const GParamSpec *pspec,
GimpLayerTreeView *view);
@@ -428,6 +430,8 @@ gimp_layer_tree_view_constructed (GObject *object)
/* Link popover menu. */
layer_view->priv->link_button = gtk_menu_button_new ();
+ gtk_widget_set_tooltip_text (layer_view->priv->link_button,
+ _("Select layers by patterns and store layer sets"));
gtk_widget_style_get (GTK_WIDGET (layer_view),
"button-icon-size", &button_size,
NULL);
@@ -451,6 +455,11 @@ gimp_layer_tree_view_constructed (GObject *object)
gtk_menu_button_set_popover (GTK_MENU_BUTTON (layer_view->priv->link_button),
layer_view->priv->link_popover);
+ g_signal_connect (layer_view->priv->link_popover,
+ "show",
+ G_CALLBACK (gimp_layer_tree_view_link_popover_shown),
+ layer_view);
+
grid = gtk_grid_new ();
/* Link popover: regexp search. */
@@ -458,8 +467,6 @@ gimp_layer_tree_view_constructed (GObject *object)
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (layer_view->priv->link_regexp_entry),
GTK_ENTRY_ICON_SECONDARY,
"system-search");
- gtk_entry_set_placeholder_text (GTK_ENTRY (layer_view->priv->link_regexp_entry),
- _("Regular Expression search"));
gtk_grid_attach (GTK_GRID (grid),
layer_view->priv->link_regexp_entry,
0, 0, 2, 1);
@@ -1208,36 +1215,83 @@ gimp_layer_tree_view_link_clicked (GtkWidget *box,
return FALSE;
}
+static void
+gimp_layer_tree_view_link_popover_shown (GtkPopover *popover,
+ GimpLayerTreeView *view)
+{
+ GimpImage *image;
+ GimpSelectMethod pattern_syntax;
+
+ image = gimp_item_tree_view_get_image (GIMP_ITEM_TREE_VIEW (view));
+
+ if (! image)
+ {
+ gtk_widget_set_tooltip_text (view->priv->link_regexp_entry,
+ _("Select layers by text search"));
+ gtk_entry_set_placeholder_text (GTK_ENTRY (view->priv->link_regexp_entry),
+ _("Text search"));
+ return;
+ }
+
+ g_object_get (image->gimp->config,
+ "items-select-method", &pattern_syntax,
+ NULL);
+ switch (pattern_syntax)
+ {
+ case GIMP_SELECT_PLAIN_TEXT:
+ gtk_widget_set_tooltip_text (view->priv->link_regexp_entry,
+ _("Select layers by text search"));
+ gtk_entry_set_placeholder_text (GTK_ENTRY (view->priv->link_regexp_entry),
+ _("Text search"));
+ break;
+ case GIMP_SELECT_GLOB_PATTERN:
+ gtk_widget_set_tooltip_text (view->priv->link_regexp_entry,
+ _("Select layers by glob patterns"));
+ gtk_entry_set_placeholder_text (GTK_ENTRY (view->priv->link_regexp_entry),
+ _("Glob pattern search"));
+ break;
+ case GIMP_SELECT_REGEX_PATTERN:
+ gtk_widget_set_tooltip_text (view->priv->link_regexp_entry,
+ _("Select layers by regular expressions"));
+ gtk_entry_set_placeholder_text (GTK_ENTRY (view->priv->link_regexp_entry),
+ _("Regular Expression search"));
+ break;
+ }
+}
+
static void
gimp_layer_tree_view_regexp_modified (GtkEntry *entry,
const GParamSpec *pspec,
GimpLayerTreeView *view)
{
- GimpImage *image;
- const gchar *pattern;
+ GimpImage *image;
+ const gchar *pattern;
+ GimpSelectMethod pattern_syntax;
gtk_entry_set_attributes (GTK_ENTRY (view->priv->link_regexp_entry),
NULL);
- gtk_widget_set_tooltip_text (view->priv->link_regexp_entry,
- _("Select layers by regular expressions"));
+
image = gimp_item_tree_view_get_image (GIMP_ITEM_TREE_VIEW (view));
g_clear_object (&view->priv->link_regexp);
if (! image)
return;
+ g_object_get (image->gimp->config,
+ "items-select-method", &pattern_syntax,
+ NULL);
pattern = gtk_entry_get_text (GTK_ENTRY (view->priv->link_regexp_entry));
if (pattern && strlen (pattern) > 0)
{
- GList *items;
- GError *error = NULL;
+ GList *items;
+ GError *error = NULL;
gtk_entry_set_text (GTK_ENTRY (view->priv->link_entry), "");
gtk_widget_set_sensitive (view->priv->link_entry, FALSE);
view->priv->link_regexp = gimp_item_list_pattern_new (image,
GIMP_TYPE_LAYER,
- GIMP_SELECT_REGEX_PATTERN,
+ pattern_syntax,
pattern);
items = gimp_item_list_get_items (view->priv->link_regexp, &error);
if (error)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]