mirror of https://github.com/GNOME/gimp.git
new function which takes menu_paths with mnemonics and removes them so
2003-07-02 Michael Natterer <mitch@gimp.org> * app/widgets/gimpwidgets-utils.[ch] (gimp_menu_path_strip_uline): new function which takes menu_paths with mnemonics and removes them so they can be used as identifiers. * app/gui/plug-in-menus.c: use the new function. Enables mnemonics for plug-in menu entries. Removed plug_in_escape_uline() which implemented disabling them. * app/widgets/gimptoolbox.c (toolbox_create_tools): use it here too, made the function more robust.
This commit is contained in:
parent
d46b87b1e4
commit
9f530a3021
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2003-07-02 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/widgets/gimpwidgets-utils.[ch] (gimp_menu_path_strip_uline):
|
||||
new function which takes menu_paths with mnemonics and removes
|
||||
them so they can be used as identifiers.
|
||||
|
||||
* app/gui/plug-in-menus.c: use the new function. Enables mnemonics
|
||||
for plug-in menu entries. Removed plug_in_escape_uline() which
|
||||
implemented disabling them.
|
||||
|
||||
* app/widgets/gimptoolbox.c (toolbox_create_tools): use it here
|
||||
too, made the function more robust.
|
||||
|
||||
2003-07-02 Manish Singh <yosh@gimp.org>
|
||||
|
||||
* tools/pdbgen/lib.pl: constify input strings, colors, and arrays
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "plug-in/plug-in-run.h"
|
||||
|
||||
#include "widgets/gimpitemfactory.h"
|
||||
#include "widgets/gimpwidgets-utils.h"
|
||||
|
||||
#include "plug-in-commands.h"
|
||||
#include "plug-in-menus.h"
|
||||
|
@ -57,7 +58,6 @@ struct _PlugInMenuEntry
|
|||
static gboolean plug_in_menu_tree_traverse_func (gpointer foo,
|
||||
PlugInMenuEntry *menu_entry,
|
||||
GimpItemFactory *item_factory);
|
||||
static gchar * plug_in_escape_uline (const gchar *menu_path);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -172,7 +172,6 @@ plug_in_menus_create_entry (GimpItemFactory *item_factory,
|
|||
const gchar *help_path)
|
||||
{
|
||||
GimpItemFactoryEntry entry;
|
||||
gchar *menu_path;
|
||||
gchar *help_page;
|
||||
gchar *basename;
|
||||
gchar *lowercase_page;
|
||||
|
@ -204,9 +203,7 @@ plug_in_menus_create_entry (GimpItemFactory *item_factory,
|
|||
|
||||
g_free (help_page);
|
||||
|
||||
menu_path = plug_in_escape_uline (strstr (proc_def->menu_path, "/"));
|
||||
|
||||
entry.entry.path = menu_path;
|
||||
entry.entry.path = strstr (proc_def->menu_path, "/");
|
||||
entry.entry.accelerator = proc_def->accelerator;
|
||||
entry.entry.callback = plug_in_run_cmd_callback;
|
||||
entry.entry.callback_action = 0;
|
||||
|
@ -249,7 +246,6 @@ plug_in_menus_create_entry (GimpItemFactory *item_factory,
|
|||
}
|
||||
}
|
||||
|
||||
g_free (menu_path);
|
||||
g_free (lowercase_page);
|
||||
}
|
||||
|
||||
|
@ -257,42 +253,48 @@ void
|
|||
plug_in_menus_delete_entry (const gchar *menu_path)
|
||||
{
|
||||
GList *list;
|
||||
gchar *path;
|
||||
|
||||
g_return_if_fail (menu_path != NULL);
|
||||
|
||||
path = gimp_menu_path_strip_uline (menu_path);
|
||||
|
||||
for (list = gimp_item_factories_from_path (menu_path);
|
||||
list;
|
||||
list = g_list_next (list))
|
||||
{
|
||||
GtkItemFactory *item_factory = list->data;
|
||||
|
||||
gtk_item_factory_delete_item (GTK_ITEM_FACTORY (item_factory), menu_path);
|
||||
gtk_item_factory_delete_item (GTK_ITEM_FACTORY (item_factory), path);
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
void
|
||||
plug_in_menus_update (GimpItemFactory *item_factory,
|
||||
GimpImageType type)
|
||||
{
|
||||
PlugInProcDef *proc_def;
|
||||
GSList *tmp;
|
||||
GSList *list;
|
||||
gchar *factory_path;
|
||||
gint factory_path_len;
|
||||
gboolean is_image_factory = FALSE;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ITEM_FACTORY (item_factory));
|
||||
|
||||
factory_path = GTK_ITEM_FACTORY (item_factory)->path;
|
||||
factory_path_len = strlen (factory_path);
|
||||
|
||||
if (! strcmp (factory_path, "<Image>"))
|
||||
is_image_factory = TRUE;
|
||||
|
||||
for (tmp = item_factory->gimp->plug_in_proc_defs;
|
||||
tmp;
|
||||
tmp = g_slist_next (tmp))
|
||||
for (list = item_factory->gimp->plug_in_proc_defs;
|
||||
list;
|
||||
list = g_slist_next (list))
|
||||
{
|
||||
proc_def = tmp->data;
|
||||
PlugInProcDef *proc_def = list->data;
|
||||
|
||||
if (proc_def->image_types_val && proc_def->menu_path)
|
||||
if (proc_def->menu_path && proc_def->image_types_val)
|
||||
{
|
||||
gboolean sensitive;
|
||||
|
||||
|
@ -321,12 +323,17 @@ plug_in_menus_update (GimpItemFactory *item_factory,
|
|||
break;
|
||||
}
|
||||
|
||||
if (! strncmp (proc_def->menu_path, factory_path,
|
||||
strlen (factory_path)))
|
||||
if (! strncmp (proc_def->menu_path, factory_path, factory_path_len))
|
||||
{
|
||||
gchar *menu_path;
|
||||
|
||||
menu_path = gimp_menu_path_strip_uline (proc_def->menu_path);
|
||||
|
||||
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (item_factory),
|
||||
proc_def->menu_path,
|
||||
menu_path,
|
||||
sensitive);
|
||||
|
||||
g_free (menu_path);
|
||||
}
|
||||
|
||||
if (is_image_factory &&
|
||||
|
@ -407,33 +414,3 @@ plug_in_menu_tree_traverse_func (gpointer foo,
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
plug_in_escape_uline (const gchar *menu_path)
|
||||
{
|
||||
gchar *uline;
|
||||
gchar *escaped;
|
||||
gchar *tmp;
|
||||
|
||||
escaped = g_strdup (menu_path);
|
||||
|
||||
uline = strchr (escaped, '_');
|
||||
|
||||
while (uline)
|
||||
{
|
||||
tmp = escaped;
|
||||
escaped = g_new (gchar, strlen (tmp) + 2);
|
||||
|
||||
if (uline > tmp)
|
||||
strncpy (escaped, tmp, (uline - tmp));
|
||||
|
||||
escaped[uline - tmp] = '_';
|
||||
strcpy (&escaped[uline - tmp + 1], uline);
|
||||
|
||||
uline = strchr (escaped + (uline - tmp) + 2, '_');
|
||||
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
return escaped;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "plug-in/plug-in-run.h"
|
||||
|
||||
#include "widgets/gimpitemfactory.h"
|
||||
#include "widgets/gimpwidgets-utils.h"
|
||||
|
||||
#include "plug-in-commands.h"
|
||||
#include "plug-in-menus.h"
|
||||
|
@ -57,7 +58,6 @@ struct _PlugInMenuEntry
|
|||
static gboolean plug_in_menu_tree_traverse_func (gpointer foo,
|
||||
PlugInMenuEntry *menu_entry,
|
||||
GimpItemFactory *item_factory);
|
||||
static gchar * plug_in_escape_uline (const gchar *menu_path);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -172,7 +172,6 @@ plug_in_menus_create_entry (GimpItemFactory *item_factory,
|
|||
const gchar *help_path)
|
||||
{
|
||||
GimpItemFactoryEntry entry;
|
||||
gchar *menu_path;
|
||||
gchar *help_page;
|
||||
gchar *basename;
|
||||
gchar *lowercase_page;
|
||||
|
@ -204,9 +203,7 @@ plug_in_menus_create_entry (GimpItemFactory *item_factory,
|
|||
|
||||
g_free (help_page);
|
||||
|
||||
menu_path = plug_in_escape_uline (strstr (proc_def->menu_path, "/"));
|
||||
|
||||
entry.entry.path = menu_path;
|
||||
entry.entry.path = strstr (proc_def->menu_path, "/");
|
||||
entry.entry.accelerator = proc_def->accelerator;
|
||||
entry.entry.callback = plug_in_run_cmd_callback;
|
||||
entry.entry.callback_action = 0;
|
||||
|
@ -249,7 +246,6 @@ plug_in_menus_create_entry (GimpItemFactory *item_factory,
|
|||
}
|
||||
}
|
||||
|
||||
g_free (menu_path);
|
||||
g_free (lowercase_page);
|
||||
}
|
||||
|
||||
|
@ -257,42 +253,48 @@ void
|
|||
plug_in_menus_delete_entry (const gchar *menu_path)
|
||||
{
|
||||
GList *list;
|
||||
gchar *path;
|
||||
|
||||
g_return_if_fail (menu_path != NULL);
|
||||
|
||||
path = gimp_menu_path_strip_uline (menu_path);
|
||||
|
||||
for (list = gimp_item_factories_from_path (menu_path);
|
||||
list;
|
||||
list = g_list_next (list))
|
||||
{
|
||||
GtkItemFactory *item_factory = list->data;
|
||||
|
||||
gtk_item_factory_delete_item (GTK_ITEM_FACTORY (item_factory), menu_path);
|
||||
gtk_item_factory_delete_item (GTK_ITEM_FACTORY (item_factory), path);
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
void
|
||||
plug_in_menus_update (GimpItemFactory *item_factory,
|
||||
GimpImageType type)
|
||||
{
|
||||
PlugInProcDef *proc_def;
|
||||
GSList *tmp;
|
||||
GSList *list;
|
||||
gchar *factory_path;
|
||||
gint factory_path_len;
|
||||
gboolean is_image_factory = FALSE;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ITEM_FACTORY (item_factory));
|
||||
|
||||
factory_path = GTK_ITEM_FACTORY (item_factory)->path;
|
||||
factory_path_len = strlen (factory_path);
|
||||
|
||||
if (! strcmp (factory_path, "<Image>"))
|
||||
is_image_factory = TRUE;
|
||||
|
||||
for (tmp = item_factory->gimp->plug_in_proc_defs;
|
||||
tmp;
|
||||
tmp = g_slist_next (tmp))
|
||||
for (list = item_factory->gimp->plug_in_proc_defs;
|
||||
list;
|
||||
list = g_slist_next (list))
|
||||
{
|
||||
proc_def = tmp->data;
|
||||
PlugInProcDef *proc_def = list->data;
|
||||
|
||||
if (proc_def->image_types_val && proc_def->menu_path)
|
||||
if (proc_def->menu_path && proc_def->image_types_val)
|
||||
{
|
||||
gboolean sensitive;
|
||||
|
||||
|
@ -321,12 +323,17 @@ plug_in_menus_update (GimpItemFactory *item_factory,
|
|||
break;
|
||||
}
|
||||
|
||||
if (! strncmp (proc_def->menu_path, factory_path,
|
||||
strlen (factory_path)))
|
||||
if (! strncmp (proc_def->menu_path, factory_path, factory_path_len))
|
||||
{
|
||||
gchar *menu_path;
|
||||
|
||||
menu_path = gimp_menu_path_strip_uline (proc_def->menu_path);
|
||||
|
||||
gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (item_factory),
|
||||
proc_def->menu_path,
|
||||
menu_path,
|
||||
sensitive);
|
||||
|
||||
g_free (menu_path);
|
||||
}
|
||||
|
||||
if (is_image_factory &&
|
||||
|
@ -407,33 +414,3 @@ plug_in_menu_tree_traverse_func (gpointer foo,
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
plug_in_escape_uline (const gchar *menu_path)
|
||||
{
|
||||
gchar *uline;
|
||||
gchar *escaped;
|
||||
gchar *tmp;
|
||||
|
||||
escaped = g_strdup (menu_path);
|
||||
|
||||
uline = strchr (escaped, '_');
|
||||
|
||||
while (uline)
|
||||
{
|
||||
tmp = escaped;
|
||||
escaped = g_new (gchar, strlen (tmp) + 2);
|
||||
|
||||
if (uline > tmp)
|
||||
strncpy (escaped, tmp, (uline - tmp));
|
||||
|
||||
escaped[uline - tmp] = '_';
|
||||
strcpy (&escaped[uline - tmp + 1], uline);
|
||||
|
||||
uline = strchr (escaped + (uline - tmp) + 2, '_');
|
||||
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
return escaped;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "gimptoolbox-color-area.h"
|
||||
#include "gimptoolbox-dnd.h"
|
||||
#include "gimptoolbox-indicator-area.h"
|
||||
#include "gimpwidgets-utils.h"
|
||||
#include "gtkhwrapbox.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
@ -622,8 +623,6 @@ toolbox_create_tools (GimpToolbox *toolbox,
|
|||
GimpToolInfo *tool_info;
|
||||
GtkWidget *button;
|
||||
GtkWidget *image;
|
||||
GtkWidget *menu_item;
|
||||
GList *accel_closures;
|
||||
const gchar *stock_id;
|
||||
|
||||
tool_info = (GimpToolInfo *) list->data;
|
||||
|
@ -662,11 +661,23 @@ toolbox_create_tools (GimpToolbox *toolbox,
|
|||
G_CALLBACK (toolbox_tool_button_press),
|
||||
toolbox);
|
||||
|
||||
if (! item_factory)
|
||||
continue;
|
||||
if (item_factory)
|
||||
{
|
||||
GtkWidget *menu_item;
|
||||
gchar *menu_path;
|
||||
|
||||
menu_path = gimp_menu_path_strip_uline (tool_info->menu_path);
|
||||
|
||||
menu_item =
|
||||
gtk_item_factory_get_widget (GTK_ITEM_FACTORY (item_factory),
|
||||
menu_path);
|
||||
|
||||
g_free (menu_path);
|
||||
|
||||
if (menu_item)
|
||||
{
|
||||
GList *accel_closures;
|
||||
|
||||
menu_item = gtk_item_factory_get_widget (GTK_ITEM_FACTORY (item_factory),
|
||||
tool_info->menu_path);
|
||||
accel_closures = gtk_widget_list_accel_closures (menu_item);
|
||||
|
||||
if (g_list_length (accel_closures) != 1)
|
||||
|
@ -693,12 +704,13 @@ toolbox_create_tools (GimpToolbox *toolbox,
|
|||
0, 0,
|
||||
accel_closure,
|
||||
button);
|
||||
|
||||
}
|
||||
|
||||
g_list_free (accel_closures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
toolbox_create_color_area (GimpToolbox *toolbox,
|
||||
|
|
|
@ -565,3 +565,35 @@ gimp_rgb_get_gdk_color (const GimpRGB *color,
|
|||
gdk_color->green = (g << 8) | g;
|
||||
gdk_color->blue = (b << 8) | b;
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_menu_path_strip_uline (const gchar *menu_path)
|
||||
{
|
||||
gchar *escaped;
|
||||
gchar *p;
|
||||
|
||||
if (! menu_path)
|
||||
return NULL;
|
||||
|
||||
p = escaped = g_strdup (menu_path);
|
||||
|
||||
while (*menu_path)
|
||||
{
|
||||
if (*menu_path == '_')
|
||||
{
|
||||
/* "__" means a literal "_" in the menu path */
|
||||
if (menu_path[1] == '_')
|
||||
*p++ = *menu_path++;
|
||||
|
||||
menu_path++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = *menu_path++;
|
||||
}
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
|
||||
return escaped;
|
||||
}
|
||||
|
|
|
@ -61,5 +61,7 @@ void gimp_get_screen_resolution (GdkScreen *screen,
|
|||
void gimp_rgb_get_gdk_color (const GimpRGB *rgb,
|
||||
GdkColor *gdk_color);
|
||||
|
||||
gchar * gimp_menu_path_strip_uline (const gchar *menu_path);
|
||||
|
||||
|
||||
#endif /* __GIMP_WIDGETS_UTILS_H__ */
|
||||
|
|
Loading…
Reference in New Issue