diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:23:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:23:22 +0000 |
commit | e42129241681dde7adae7d20697e7b421682fbb4 (patch) | |
tree | af1fe815a5e639e68e59fabd8395ec69458b3e5e /app/plug-in/plug-in-menu-path.c | |
parent | Initial commit. (diff) | |
download | gimp-ea37a4141e911d96afe705183d5bf292fb1941af.tar.xz gimp-ea37a4141e911d96afe705183d5bf292fb1941af.zip |
Adding upstream version 2.10.22.upstream/2.10.22upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'app/plug-in/plug-in-menu-path.c')
-rw-r--r-- | app/plug-in/plug-in-menu-path.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/app/plug-in/plug-in-menu-path.c b/app/plug-in/plug-in-menu-path.c new file mode 100644 index 0000000..fa6fa16 --- /dev/null +++ b/app/plug-in/plug-in-menu-path.c @@ -0,0 +1,141 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * plug-in-menu-path.c + * + * 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 <gio/gio.h> + +#include "libgimpbase/gimpbase.h" + +#include "plug-in-types.h" + +#include "plug-in-menu-path.h" + + +typedef struct _MenuPathMapping MenuPathMapping; + +struct _MenuPathMapping +{ + const gchar *orig_path; + const gchar *label; + const gchar *mapped_path; +}; + + +static const MenuPathMapping menu_path_mappings[] = +{ + { "<Toolbox>/Xtns/Languages", NULL, "<Image>/Filters/Languages" }, + { "<Toolbox>/Xtns/Extensions", NULL, "<Image>/Filters/Extensions" }, + + { "<Toolbox>/Xtns/Buttons", NULL, "<Image>/File/Create/Buttons" }, + { "<Toolbox>/Xtns/Logos", NULL, "<Image>/File/Create/Logos" }, + { "<Toolbox>/Xtns/Misc", NULL, "<Image>/File/Create/Misc" }, + { "<Toolbox>/Xtns/Patterns", NULL, "<Image>/File/Create/Patterns" }, + { "<Toolbox>/Xtns/Web Page Themes", NULL, "<Image>/File/Create/Web Page Themes" }, + + { "<Toolbox>/Xtns", "Buttons", "<Image>/File/Create" }, + { "<Toolbox>/Xtns", "Logos", "<Image>/File/Create" }, + { "<Toolbox>/Xtns", "Misc", "<Image>/File/Create" }, + { "<Toolbox>/Xtns", "Patterns", "<Image>/File/Create" }, + { "<Toolbox>/Xtns", "Web Page Themes", "<Image>/File/Create" }, + + { "<Toolbox>/Xtns", NULL, "<Image>/Filters/Extensions" }, + { "<Toolbox>/Help", NULL, "<Image>/Help" }, + + { "<Toolbox>/File/Acquire", NULL, "<Image>/File/Create/Acquire" }, + { "<Toolbox>", NULL, "<Image>" }, + { "<Image>/File/Acquire", NULL, "<Image>/File/Create/Acquire" }, + { "<Image>/File/New", NULL, "<Image>/File/Create" }, + { "<Image>/Image/Mode/Color Profile", NULL, "<Image>/Image/Color Management" }, + { NULL, NULL, NULL } +}; + + +gchar * +plug_in_menu_path_map (const gchar *menu_path, + const gchar *menu_label) +{ + const MenuPathMapping *mapping; + gchar *stripped_label = NULL; + + g_return_val_if_fail (menu_path != NULL, NULL); + + if (menu_label) + stripped_label = gimp_strip_uline (menu_label); + + for (mapping = menu_path_mappings; mapping->orig_path; mapping++) + { + if (g_str_has_prefix (menu_path, mapping->orig_path)) + { + gint orig_len = strlen (mapping->orig_path); + gchar *mapped_path; + + /* if the mapping has a label, only map if the passed label + * is identical and the paths' lengths match exactly. + */ + if (mapping->label && + (! stripped_label || + strlen (menu_path) != orig_len || + strcmp (mapping->label, stripped_label))) + { + continue; + } + + if (strlen (menu_path) > orig_len) + mapped_path = g_strconcat (mapping->mapped_path, + menu_path + orig_len, + NULL); + else + mapped_path = g_strdup (mapping->mapped_path); + +#if GIMP_UNSTABLE + { + gchar *orig; + gchar *mapped; + + if (menu_label) + { + orig = g_strdup_printf ("%s/%s", menu_path, stripped_label); + mapped = g_strdup_printf ("%s/%s", mapped_path, stripped_label); + } + else + { + orig = g_strdup (menu_path); + mapped = g_strdup (mapped_path); + } + + g_printerr (" mapped '%s' to '%s'\n", orig, mapped); + + g_free (orig); + g_free (mapped); + } +#endif + + g_free (stripped_label); + + return mapped_path; + } + } + + g_free (stripped_label); + + return g_strdup (menu_path); +} |