1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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);
}
|