[gimp] pdb: add gimp_pdb_set_proc_menu_label()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb: add gimp_pdb_set_proc_menu_label()
- Date: Sun, 8 Sep 2019 15:34:11 +0000 (UTC)
commit 453b4f4aa2178766bbfbba3d79e6800fdf839e62
Author: Michael Natterer <mitch gimp org>
Date: Sun Sep 8 17:30:54 2019 +0200
pdb: add gimp_pdb_set_proc_menu_label()
and all the needed code in libgimp/ and app/ to set a plug-in
procedure's menu label using the new API. Remove the menu label from
GPProcInstall.
app/pdb/internal-procs.c | 2 +-
app/pdb/pdb-cmds.c | 63 ++++++++++++++++++++++++++++++++
app/plug-in/gimpplugin-message.c | 19 ----------
app/plug-in/gimpplugin-proc.c | 67 +++++++++++++++++++++++++++++++++--
app/plug-in/gimpplugin-proc.h | 3 ++
app/plug-in/gimppluginprocedure.c | 35 ++++++++++++++++++
app/plug-in/gimppluginprocedure.h | 4 +++
libgimp/gimppdb_pdb.c | 38 ++++++++++++++++++++
libgimp/gimppdb_pdb.h | 2 ++
libgimp/gimpprocedure.c | 10 +++++-
libgimpbase/gimpprotocol.c | 8 -----
libgimpbase/gimpprotocol.h | 3 +-
pdb/groups/pdb.pdb | 37 +++++++++++++++++++
plug-ins/script-fu/script-fu-script.c | 2 +-
14 files changed, 258 insertions(+), 35 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index cbc9b7f935..b28c50fb30 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 750 procedures registered total */
+/* 751 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/pdb-cmds.c b/app/pdb/pdb-cmds.c
index 97042ed1b9..902a969da2 100644
--- a/app/pdb/pdb-cmds.c
+++ b/app/pdb/pdb-cmds.c
@@ -338,6 +338,39 @@ pdb_get_proc_image_types_invoker (GimpProcedure *procedure,
return return_vals;
}
+static GimpValueArray *
+pdb_set_proc_menu_label_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ const gchar *procedure_name;
+ const gchar *menu_label;
+
+ procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
+ menu_label = g_value_get_string (gimp_value_array_index (args, 1));
+
+ if (success)
+ {
+ GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
+
+ if (plug_in &&
+ gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ success = gimp_plug_in_set_proc_menu_label (plug_in, procedure_name,
+ menu_label);
+ }
+ else
+ success = FALSE;
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
static GimpValueArray *
pdb_get_proc_menu_label_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -1074,6 +1107,36 @@ register_pdb_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+ /*
+ * gimp-pdb-set-proc-menu-label
+ */
+ procedure = gimp_procedure_new (pdb_set_proc_menu_label_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-pdb-set-proc-menu-label");
+ gimp_procedure_set_static_strings (procedure,
+ "Set the menu label for a plug-in procedure.",
+ "This procedure sets the menu label for the given procedure.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2019",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("procedure-name",
+ "procedure name",
+ "The procedure for which to install the menu path",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("menu-label",
+ "menu label",
+ "The procedure's menu label",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
/*
* gimp-pdb-get-proc-menu-label
*/
diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c
index ba7e09ce2f..806fa386ec 100644
--- a/app/plug-in/gimpplugin-message.c
+++ b/app/plug-in/gimpplugin-message.c
@@ -756,7 +756,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
#define VALIDATE_OR_NULL(str) ((str) == NULL || g_utf8_validate ((str), -1, NULL))
if (VALIDATE (proc_install->name) &&
- VALIDATE_OR_NULL (proc_install->menu_label) &&
VALIDATE_OR_NULL (proc_install->blurb) &&
VALIDATE_OR_NULL (proc_install->help) &&
VALIDATE_OR_NULL (proc_install->help_id) &&
@@ -823,21 +822,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
return;
}
- if (proc_install->menu_label && strlen (proc_install->menu_label) &&
- proc_install->menu_label[0] == '<')
- {
- gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
- "Plug-in \"%s\"\n(%s)\n\n"
- "attempted to install procedure \"%s\" with a full "
- "menu path \"%s\" as menu label, this is not supported "
- "any longer.",
- gimp_object_get_name (plug_in),
- gimp_file_get_utf8_name (plug_in->file),
- proc_install->name,
- proc_install->menu_label);
- return;
- }
-
/* Create the procedure object */
switch (proc_install->type)
@@ -867,9 +851,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
proc_install->date,
NULL);
- if (proc_install->menu_label && strlen (proc_install->menu_label))
- proc->menu_label = g_strdup (proc_install->menu_label);
-
gimp_plug_in_procedure_set_help_id (proc, proc_install->help_id);
for (i = 0; i < proc_install->nparams; i++)
diff --git a/app/plug-in/gimpplugin-proc.c b/app/plug-in/gimpplugin-proc.c
index ff7ab5a495..c25335c665 100644
--- a/app/plug-in/gimpplugin-proc.c
+++ b/app/plug-in/gimpplugin-proc.c
@@ -38,9 +38,9 @@
gboolean
-gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
- const gchar *proc_name,
- const gchar *image_types)
+gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
+ const gchar *proc_name,
+ const gchar *image_types)
{
GimpPlugInProcedure *proc = NULL;
@@ -89,6 +89,67 @@ gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
return TRUE;
}
+gboolean
+gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
+ const gchar *proc_name,
+ const gchar *menu_label)
+{
+ GimpPlugInProcedure *proc = NULL;
+ GError *error = NULL;
+
+ g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
+ g_return_val_if_fail (proc_name != NULL, FALSE);
+ g_return_val_if_fail (menu_label != NULL && strlen (menu_label), FALSE);
+
+ if (plug_in->plug_in_def)
+ proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures,
+ proc_name);
+
+ if (! proc)
+ proc = gimp_plug_in_procedure_find (plug_in->temp_procedures, proc_name);
+
+ if (! proc)
+ {
+ gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
+ "Plug-in \"%s\"\n(%s)\n"
+ "attempted to register the menu label \"%s\" "
+ "for the procedure \"%s\".\n"
+ "It has however not installed that procedure. "
+ "This is not allowed.",
+ gimp_object_get_name (plug_in),
+ gimp_file_get_utf8_name (plug_in->file),
+ menu_label, proc_name);
+
+ return FALSE;
+ }
+
+ switch (GIMP_PROCEDURE (proc)->proc_type)
+ {
+ case GIMP_PDB_PROC_TYPE_INTERNAL:
+ return FALSE;
+
+ case GIMP_PDB_PROC_TYPE_PLUGIN:
+ case GIMP_PDB_PROC_TYPE_EXTENSION:
+ if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
+ plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
+ return FALSE;
+
+ case GIMP_PDB_PROC_TYPE_TEMPORARY:
+ break;
+ }
+
+ if (! gimp_plug_in_procedure_set_menu_label (proc, menu_label, &error))
+ {
+ gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
+ error->message);
+ g_clear_error (&error);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gboolean
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
diff --git a/app/plug-in/gimpplugin-proc.h b/app/plug-in/gimpplugin-proc.h
index 6cd5fb70cb..91f818d612 100644
--- a/app/plug-in/gimpplugin-proc.h
+++ b/app/plug-in/gimpplugin-proc.h
@@ -24,6 +24,9 @@
gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *image_types);
+gboolean gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
+ const gchar *proc_name,
+ const gchar *menu_label);
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path);
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index 92cc5274aa..bfac6edbd8 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -602,6 +602,41 @@ gimp_plug_in_procedure_get_help_domain (GimpPlugInProcedure *proc)
return g_quark_to_string (proc->help_domain);
}
+gboolean
+gimp_plug_in_procedure_set_menu_label (GimpPlugInProcedure *proc,
+ const gchar *menu_label,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE);
+ g_return_val_if_fail (menu_label != NULL && strlen (menu_label), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (menu_label[0] == '<')
+ {
+ gchar *basename = g_path_get_basename (gimp_file_get_utf8_name (proc->file));
+
+ g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_FAILED,
+ "Plug-in \"%s\"\n(%s)\n\n"
+ "attempted to install procedure \"%s\" with a full "
+ "menu path \"%s\" as menu label, this is not supported "
+ "any longer.",
+ basename, gimp_file_get_utf8_name (proc->file),
+ gimp_object_get_name (proc),
+ menu_label);
+
+ g_free (basename);
+
+ return FALSE;
+ }
+
+ g_clear_pointer (&proc->label, g_free);
+
+ g_free (proc->menu_label);
+ proc->menu_label = g_strdup (menu_label);
+
+ return TRUE;
+}
+
gboolean
gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc,
const gchar *menu_path,
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index bf61358710..d1221f93ba 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -107,6 +107,10 @@ const gchar * gimp_plug_in_procedure_get_help_domain (GimpPlugInProcedure *pro
void gimp_plug_in_procedure_set_help_id (GimpPlugInProcedure *proc,
const gchar *help_id);
+gboolean gimp_plug_in_procedure_set_menu_label (GimpPlugInProcedure *proc,
+ const gchar *menu_label,
+ GError **error);
+
gboolean gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc,
const gchar *menu_path,
GError **error);
diff --git a/libgimp/gimppdb_pdb.c b/libgimp/gimppdb_pdb.c
index 8a4a2ad2d9..7739309805 100644
--- a/libgimp/gimppdb_pdb.c
+++ b/libgimp/gimppdb_pdb.c
@@ -340,6 +340,44 @@ _gimp_pdb_get_proc_image_types (const gchar *procedure_name)
return image_types;
}
+/**
+ * _gimp_pdb_set_proc_menu_label:
+ * @procedure_name: The procedure for which to install the menu path.
+ * @menu_label: The procedure's menu label.
+ *
+ * Set the menu label for a plug-in procedure.
+ *
+ * This procedure sets the menu label for the given procedure.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+_gimp_pdb_set_proc_menu_label (const gchar *procedure_name,
+ const gchar *menu_label)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gboolean success = TRUE;
+
+ args = gimp_value_array_new_from_types (NULL,
+ G_TYPE_STRING, procedure_name,
+ G_TYPE_STRING, menu_label,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-pdb-set-proc-menu-label",
+ args);
+ gimp_value_array_unref (args);
+
+ success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+ gimp_value_array_unref (return_vals);
+
+ return success;
+}
+
/**
* _gimp_pdb_get_proc_menu_label:
* @procedure_name: The procedure name.
diff --git a/libgimp/gimppdb_pdb.h b/libgimp/gimppdb_pdb.h
index 41bc5766a0..4ddd4eb107 100644
--- a/libgimp/gimppdb_pdb.h
+++ b/libgimp/gimppdb_pdb.h
@@ -51,6 +51,8 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_info (const gchar
G_GNUC_INTERNAL gboolean _gimp_pdb_set_proc_image_types (const gchar *procedure_name,
const gchar *image_types);
G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_image_types (const gchar *procedure_name);
+G_GNUC_INTERNAL gboolean _gimp_pdb_set_proc_menu_label (const gchar *procedure_name,
+ const gchar *menu_label);
G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_menu_label (const gchar *procedure_name);
G_GNUC_INTERNAL gboolean _gimp_pdb_add_proc_menu_path (const gchar *procedure_name,
const gchar *menu_path);
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index 10e48120d3..a89b2f8bbc 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -371,7 +371,6 @@ gimp_procedure_real_install (GimpProcedure *procedure)
proc_install.authors = (gchar *) gimp_procedure_get_authors (procedure);
proc_install.copyright = (gchar *) gimp_procedure_get_copyright (procedure);
proc_install.date = (gchar *) gimp_procedure_get_date (procedure);
- proc_install.menu_label = (gchar *) gimp_procedure_get_menu_label (procedure);
proc_install.type = gimp_procedure_get_proc_type (procedure);
proc_install.nparams = n_args;
proc_install.nreturn_vals = n_return_vals;
@@ -404,6 +403,10 @@ gimp_procedure_real_install (GimpProcedure *procedure)
_gimp_pdb_set_proc_image_types (gimp_procedure_get_name (procedure),
procedure->priv->image_types);
+ if (procedure->priv->menu_label)
+ _gimp_pdb_set_proc_menu_label (gimp_procedure_get_name (procedure),
+ procedure->priv->menu_label);
+
for (list = gimp_procedure_get_menu_paths (procedure);
list;
list = g_list_next (list))
@@ -638,9 +641,14 @@ gimp_procedure_set_menu_label (GimpProcedure *procedure,
const gchar *menu_label)
{
g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
+ g_return_if_fail (menu_label != NULL && strlen (menu_label));
g_clear_pointer (&procedure->priv->menu_label, g_free);
procedure->priv->menu_label = g_strdup (menu_label);
+
+ if (procedure->priv->installed)
+ _gimp_pdb_set_proc_menu_label (gimp_procedure_get_name (procedure),
+ procedure->priv->menu_label);
}
/**
diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c
index 4d1c62223b..e4fbc9c748 100644
--- a/libgimpbase/gimpprotocol.c
+++ b/libgimpbase/gimpprotocol.c
@@ -1221,9 +1221,6 @@ _gp_proc_install_read (GIOChannel *channel,
if (! _gimp_wire_read_string (channel,
&proc_install->date, 1, user_data))
goto cleanup;
- if (! _gimp_wire_read_string (channel,
- &proc_install->menu_label, 1, user_data))
- goto cleanup;
if (! _gimp_wire_read_int32 (channel,
&proc_install->type, 1, user_data))
@@ -1266,7 +1263,6 @@ _gp_proc_install_read (GIOChannel *channel,
g_free (proc_install->authors);
g_free (proc_install->copyright);
g_free (proc_install->date);
- g_free (proc_install->menu_label);
if (proc_install->params)
{
@@ -1465,9 +1461,6 @@ _gp_proc_install_write (GIOChannel *channel,
if (! _gimp_wire_write_string (channel,
&proc_install->date, 1, user_data))
return;
- if (! _gimp_wire_write_string (channel,
- &proc_install->menu_label, 1, user_data))
- return;
if (! _gimp_wire_write_int32 (channel,
&proc_install->type, 1, user_data))
@@ -1512,7 +1505,6 @@ _gp_proc_install_destroy (GimpWireMessage *msg)
g_free (proc_install->authors);
g_free (proc_install->copyright);
g_free (proc_install->date);
- g_free (proc_install->menu_label);
for (i = 0; i < proc_install->nparams; i++)
{
diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h
index a0727bc54e..722735baa3 100644
--- a/libgimpbase/gimpprotocol.h
+++ b/libgimpbase/gimpprotocol.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
/* Increment every time the protocol changes
*/
-#define GIMP_PROTOCOL_VERSION 0x010A
+#define GIMP_PROTOCOL_VERSION 0x010B
enum
@@ -288,7 +288,6 @@ struct _GPProcInstall
gchar *authors;
gchar *copyright;
gchar *date;
- gchar *menu_label;
guint32 type;
guint32 nparams;
guint32 nreturn_vals;
diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb
index b87e5b3ed9..599c6c2827 100644
--- a/pdb/groups/pdb.pdb
+++ b/pdb/groups/pdb.pdb
@@ -328,6 +328,42 @@ CODE
);
}
+sub pdb_set_proc_menu_label {
+ $blurb = "Set the menu label for a plug-in procedure.";
+
+ $help = <<HELP;
+This procedure sets the menu label for the given procedure.
+HELP
+
+ &mitch_pdb_misc('2019', '3.0');
+
+ $lib_private = 1;
+
+ @inargs = (
+ { name => 'procedure_name', type => 'string', non_empty => 1,
+ desc => 'The procedure for which to install the menu path' },
+ { name => 'menu_label', type => 'string', non_empty => 1,
+ desc => "The procedure's menu label" }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
+
+ if (plug_in &&
+ gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ success = gimp_plug_in_set_proc_menu_label (plug_in, procedure_name,
+ menu_label);
+ }
+ else
+ success = FALSE;
+}
+CODE
+ );
+}
+
sub pdb_get_proc_menu_label {
$blurb = <<'BLURB';
Queries the procedural database for the procedure's menu label.
@@ -889,6 +925,7 @@ CODE
pdb_get_proc_info
pdb_set_proc_image_types
pdb_get_proc_image_types
+ pdb_set_proc_menu_label
pdb_get_proc_menu_label
pdb_add_proc_menu_path
pdb_get_proc_menu_paths
diff --git a/plug-ins/script-fu/script-fu-script.c b/plug-ins/script-fu/script-fu-script.c
index d181f2ed7f..d9fa92eb6a 100644
--- a/plug-ins/script-fu/script-fu-script.c
+++ b/plug-ins/script-fu/script-fu-script.c
@@ -189,7 +189,7 @@ script_fu_script_install_proc (GimpPlugIn *plug_in,
gimp_procedure_set_image_types (procedure, script->image_types);
- if (menu_label)
+ if (menu_label && strlen (menu_label))
gimp_procedure_set_menu_label (procedure, menu_label);
gimp_procedure_set_documentation (procedure,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]