[gimp/gimp-2-10] app: when a plug-in procedure is not sensitive, show the reason in the tooltip
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: when a plug-in procedure is not sensitive, show the reason in the tooltip
- Date: Fri, 22 Jun 2018 11:58:40 +0000 (UTC)
commit cf4ef427b32aac97c39cbc5b94d0fec42391954f
Author: Michael Natterer <mitch gimp org>
Date: Fri Jun 22 13:29:52 2018 +0200
app: when a plug-in procedure is not sensitive, show the reason in the tooltip
Return an optional tooltip from gimp_procedure_get_sensitive(), in
GimpPlugInProcedure, build that tooltip from the image types the
procedure works on.
(cherry picked from commit 63817485c0638739a892dcc7078762e69a96662b)
app/actions/filters-actions.c | 6 ++-
app/actions/plug-in-actions.c | 26 ++++++++--
app/pdb/gimpprocedure.c | 26 +++++++---
app/pdb/gimpprocedure.h | 6 ++-
app/plug-in/gimppluginprocedure.c | 99 +++++++++++++++++++++++++++++++++++++--
app/plug-in/gimppluginprocedure.h | 1 +
6 files changed, 146 insertions(+), 18 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index 3d8c706e9f..18c0c3b51b 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -957,7 +957,8 @@ filters_actions_update (GimpActionGroup *group,
GimpProcedure *proc = gimp_filter_history_nth (group->gimp, 0);
gint i;
- if (proc && gimp_procedure_get_sensitive (proc, GIMP_OBJECT (drawable)))
+ if (proc &&
+ gimp_procedure_get_sensitive (proc, GIMP_OBJECT (drawable), NULL))
{
gimp_action_group_set_action_sensitive (group, "filters-repeat", TRUE);
gimp_action_group_set_action_sensitive (group, "filters-reshow", TRUE);
@@ -975,7 +976,8 @@ filters_actions_update (GimpActionGroup *group,
proc = gimp_filter_history_nth (group->gimp, i);
- sensitive = gimp_procedure_get_sensitive (proc, GIMP_OBJECT (drawable));
+ sensitive = gimp_procedure_get_sensitive (proc, GIMP_OBJECT (drawable),
+ NULL);
gimp_action_group_set_action_sensitive (group, name, sensitive);
diff --git a/app/actions/plug-in-actions.c b/app/actions/plug-in-actions.c
index 9632a0d4c6..f8fc94216f 100644
--- a/app/actions/plug-in-actions.c
+++ b/app/actions/plug-in-actions.c
@@ -156,13 +156,24 @@ plug_in_actions_update (GimpActionGroup *group,
! proc->file_proc &&
proc->image_types_val)
{
- gboolean sensitive =
- gimp_procedure_get_sensitive (GIMP_PROCEDURE (proc),
- GIMP_OBJECT (drawable));
+ GimpProcedure *procedure = GIMP_PROCEDURE (proc);
+ gboolean sensitive;
+ const gchar *tooltip;
+
+ sensitive = gimp_procedure_get_sensitive (procedure,
+ GIMP_OBJECT (drawable),
+ &tooltip);
gimp_action_group_set_action_sensitive (group,
gimp_object_get_name (proc),
sensitive);
+
+ if (sensitive || ! drawable || ! tooltip)
+ tooltip = gimp_procedure_get_blurb (procedure);
+
+ gimp_action_group_set_action_tooltip (group,
+ gimp_object_get_name (proc),
+ tooltip);
}
}
}
@@ -368,16 +379,23 @@ plug_in_actions_add_proc (GimpActionGroup *group,
GimpImage *image = gimp_context_get_image (context);
GimpDrawable *drawable = NULL;
gboolean sensitive;
+ const gchar *tooltip;
if (image)
drawable = gimp_image_get_active_drawable (image);
sensitive = gimp_procedure_get_sensitive (GIMP_PROCEDURE (proc),
- GIMP_OBJECT (drawable));
+ GIMP_OBJECT (drawable),
+ &tooltip);
gimp_action_group_set_action_sensitive (group,
gimp_object_get_name (proc),
sensitive);
+
+ if (! sensitive && drawable && tooltip)
+ gimp_action_group_set_action_tooltip (group,
+ gimp_object_get_name (proc),
+ tooltip);
}
}
diff --git a/app/pdb/gimpprocedure.c b/app/pdb/gimpprocedure.c
index c94f98de36..cbb2492ad3 100644
--- a/app/pdb/gimpprocedure.c
+++ b/app/pdb/gimpprocedure.c
@@ -53,7 +53,8 @@ static const gchar * gimp_procedure_real_get_menu_label (GimpProcedure *proced
static const gchar * gimp_procedure_real_get_blurb (GimpProcedure *procedure);
static const gchar * gimp_procedure_real_get_help_id (GimpProcedure *procedure);
static gboolean gimp_procedure_real_get_sensitive (GimpProcedure *procedure,
- GimpObject *object);
+ GimpObject *object,
+ const gchar **tooltip);
static GimpValueArray * gimp_procedure_real_execute (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
@@ -193,8 +194,9 @@ gimp_procedure_real_get_help_id (GimpProcedure *procedure)
}
static gboolean
-gimp_procedure_real_get_sensitive (GimpProcedure *procedure,
- GimpObject *object)
+gimp_procedure_real_get_sensitive (GimpProcedure *procedure,
+ GimpObject *object,
+ const gchar **tooltip)
{
return TRUE /* random fallback */;
}
@@ -370,14 +372,24 @@ gimp_procedure_get_help_id (GimpProcedure *procedure)
}
gboolean
-gimp_procedure_get_sensitive (GimpProcedure *procedure,
- GimpObject *object)
+gimp_procedure_get_sensitive (GimpProcedure *procedure,
+ GimpObject *object,
+ const gchar **tooltip)
{
+ const gchar *my_tooltip = NULL;
+ gboolean sensitive;
+
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), FALSE);
g_return_val_if_fail (object == NULL || GIMP_IS_OBJECT (object), FALSE);
- return GIMP_PROCEDURE_GET_CLASS (procedure)->get_sensitive (procedure,
- object);
+ sensitive = GIMP_PROCEDURE_GET_CLASS (procedure)->get_sensitive (procedure,
+ object,
+ &my_tooltip);
+
+ if (tooltip)
+ *tooltip = my_tooltip;
+
+ return sensitive;
}
GimpValueArray *
diff --git a/app/pdb/gimpprocedure.h b/app/pdb/gimpprocedure.h
index a7f5bbbe82..450b90605f 100644
--- a/app/pdb/gimpprocedure.h
+++ b/app/pdb/gimpprocedure.h
@@ -74,7 +74,8 @@ struct _GimpProcedureClass
const gchar * (* get_blurb) (GimpProcedure *procedure);
const gchar * (* get_help_id) (GimpProcedure *procedure);
gboolean (* get_sensitive) (GimpProcedure *procedure,
- GimpObject *object);
+ GimpObject *object,
+ const gchar **tooltip);
GimpValueArray * (* execute) (GimpProcedure *procedure,
Gimp *gimp,
@@ -125,7 +126,8 @@ const gchar * gimp_procedure_get_menu_label (GimpProcedure *procedure)
const gchar * gimp_procedure_get_blurb (GimpProcedure *procedure);
const gchar * gimp_procedure_get_help_id (GimpProcedure *procedure);
gboolean gimp_procedure_get_sensitive (GimpProcedure *procedure,
- GimpObject *object);
+ GimpObject *object,
+ const gchar **tooltip);
void gimp_procedure_add_argument (GimpProcedure *procedure,
GParamSpec *pspec);
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index 2e048429f4..6556640bba 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -69,7 +69,8 @@ static const gchar * gimp_plug_in_procedure_get_menu_label
static const gchar * gimp_plug_in_procedure_get_blurb (GimpProcedure *procedure);
static const gchar * gimp_plug_in_procedure_get_help_id(GimpProcedure *procedure);
static gboolean gimp_plug_in_procedure_get_sensitive (GimpProcedure *procedure,
- GimpObject *object);
+ GimpObject *object,
+ const gchar **tooltip);
static GimpValueArray * gimp_plug_in_procedure_execute (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
@@ -159,6 +160,7 @@ gimp_plug_in_procedure_finalize (GObject *object)
g_free (proc->icon_data);
g_free (proc->image_types);
+ g_free (proc->image_types_tooltip);
g_free (proc->extensions);
g_free (proc->prefixes);
@@ -338,8 +340,9 @@ gimp_plug_in_procedure_get_help_id (GimpProcedure *procedure)
}
static gboolean
-gimp_plug_in_procedure_get_sensitive (GimpProcedure *procedure,
- GimpObject *object)
+gimp_plug_in_procedure_get_sensitive (GimpProcedure *procedure,
+ GimpObject *object,
+ const gchar **tooltip)
{
GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (procedure);
GimpDrawable *drawable;
@@ -381,6 +384,9 @@ gimp_plug_in_procedure_get_sensitive (GimpProcedure *procedure,
break;
}
+ if (! sensitive)
+ *tooltip = proc->image_types_tooltip;
+
return sensitive ? TRUE : FALSE;
}
@@ -985,6 +991,8 @@ void
gimp_plug_in_procedure_set_image_types (GimpPlugInProcedure *proc,
const gchar *image_types)
{
+ GList *types = NULL;
+
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
if (proc->image_types)
@@ -993,6 +1001,91 @@ gimp_plug_in_procedure_set_image_types (GimpPlugInProcedure *proc,
proc->image_types = g_strdup (image_types);
proc->image_types_val = image_types_parse (gimp_object_get_name (proc),
proc->image_types);
+
+ g_clear_pointer (&proc->image_types_tooltip, g_free);
+
+ if (proc->image_types_val &
+ (GIMP_PLUG_IN_RGB_IMAGE | GIMP_PLUG_IN_RGBA_IMAGE))
+ {
+ if ((proc->image_types_val & GIMP_PLUG_IN_RGB_IMAGE) &&
+ (proc->image_types_val & GIMP_PLUG_IN_RGBA_IMAGE))
+ {
+ types = g_list_prepend (types, _("RGB"));
+ }
+ else if (proc->image_types_val & GIMP_PLUG_IN_RGB_IMAGE)
+ {
+ types = g_list_prepend (types, _("RGB without alpha"));
+ }
+ else
+ {
+ types = g_list_prepend (types, _("RGB with alpha"));
+ }
+ }
+
+ if (proc->image_types_val &
+ (GIMP_PLUG_IN_GRAY_IMAGE | GIMP_PLUG_IN_GRAYA_IMAGE))
+ {
+ if ((proc->image_types_val & GIMP_PLUG_IN_GRAY_IMAGE) &&
+ (proc->image_types_val & GIMP_PLUG_IN_GRAYA_IMAGE))
+ {
+ types = g_list_prepend (types, _("Grayscale"));
+ }
+ else if (proc->image_types_val & GIMP_PLUG_IN_GRAY_IMAGE)
+ {
+ types = g_list_prepend (types, _("Grayscale without alpha"));
+ }
+ else
+ {
+ types = g_list_prepend (types, _("Grayscale with alpha"));
+ }
+ }
+
+ if (proc->image_types_val &
+ (GIMP_PLUG_IN_INDEXED_IMAGE | GIMP_PLUG_IN_INDEXEDA_IMAGE))
+ {
+ if ((proc->image_types_val & GIMP_PLUG_IN_INDEXED_IMAGE) &&
+ (proc->image_types_val & GIMP_PLUG_IN_INDEXEDA_IMAGE))
+ {
+ types = g_list_prepend (types, _("Indexed"));
+ }
+ else if (proc->image_types_val & GIMP_PLUG_IN_INDEXED_IMAGE)
+ {
+ types = g_list_prepend (types, _("Indexed without alpha"));
+ }
+ else
+ {
+ types = g_list_prepend (types, _("Indexed with alpha"));
+ }
+ }
+
+ if (types)
+ {
+ GString *string;
+ GList *list;
+
+ types = g_list_reverse (types);
+
+ string = g_string_new (gimp_procedure_get_blurb (GIMP_PROCEDURE (proc)));
+
+ g_string_append (string, "\n\n");
+ g_string_append (string, _("This plug-in only works on the "
+ "following layer types:"));
+ g_string_append (string, "\n");
+
+ for (list = types; list; list = g_list_next (list))
+ {
+ g_string_append (string, list->data);
+
+ if (list->next)
+ g_string_append (string, ", ");
+ else
+ g_string_append (string, ".");
+ }
+
+ g_list_free (types);
+
+ proc->image_types_tooltip = g_string_free (string, FALSE);
+ }
}
static GSList *
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index 7f5412b352..96ac13b816 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -51,6 +51,7 @@ struct _GimpPlugInProcedure
guint8 *icon_data;
gchar *image_types;
GimpPlugInImageType image_types_val;
+ gchar *image_types_tooltip;
gint64 mtime;
gboolean installed_during_init;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]