More unused action stuff:
2004-04-21 Michael Natterer <mitch@gimp.org> More unused action stuff: * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpactionfactory.[ch]: added a simple factory which produces GimpActionGroups. * app/widgets/gimpactiongroup.[ch]: added an "update_func" member to the GimpActionGroup struct. Added it as parameter to gimp_action_group_new(). Added function gimp_action_group_update(). * app/widgets/gimpmenufactory.[ch]: added an "action_factory" member and constructor parameter. Added code to create GtkUIManagers from registered action group identifiers. * app/actions/Makefile.am * app/actions/actions.[ch]: new files: create a "global_action_factory" and register all action groups with it. * app/actions/edit-actions.c: s/edit_action_update/edit_actions_update/ * app/actions/plug-in-actions.[ch]: added API to add/remove plug-in procedure actions dynamically (unfinished). * app/gui/menus.c (menus_init): call actions_init(). (menus_exit): call actions_exit().
This commit is contained in:

committed by
Michael Natterer

parent
732fc05fa7
commit
27a2c8c0e6
29
ChangeLog
29
ChangeLog
@ -1,3 +1,32 @@
|
||||
2004-04-21 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
More unused action stuff:
|
||||
|
||||
* app/widgets/Makefile.am
|
||||
* app/widgets/widgets-types.h
|
||||
* app/widgets/gimpactionfactory.[ch]: added a simple factory which
|
||||
produces GimpActionGroups.
|
||||
|
||||
* app/widgets/gimpactiongroup.[ch]: added an "update_func" member
|
||||
to the GimpActionGroup struct. Added it as parameter to
|
||||
gimp_action_group_new(). Added function gimp_action_group_update().
|
||||
|
||||
* app/widgets/gimpmenufactory.[ch]: added an "action_factory"
|
||||
member and constructor parameter. Added code to create
|
||||
GtkUIManagers from registered action group identifiers.
|
||||
|
||||
* app/actions/Makefile.am
|
||||
* app/actions/actions.[ch]: new files: create a
|
||||
"global_action_factory" and register all action groups with it.
|
||||
|
||||
* app/actions/edit-actions.c: s/edit_action_update/edit_actions_update/
|
||||
|
||||
* app/actions/plug-in-actions.[ch]: added API to add/remove
|
||||
plug-in procedure actions dynamically (unfinished).
|
||||
|
||||
* app/gui/menus.c (menus_init): call actions_init().
|
||||
(menus_exit): call actions_exit().
|
||||
|
||||
2004-04-21 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/Lighting/lighting_ui.c
|
||||
|
@ -4,6 +4,8 @@ noinst_LIBRARIES = libappactions.a
|
||||
|
||||
libappactions_a_SOURCES = \
|
||||
actions-types.h \
|
||||
actions.c \
|
||||
actions.h \
|
||||
\
|
||||
brushes-actions.c \
|
||||
brushes-actions.h \
|
||||
|
192
app/actions/actions.c
Normal file
192
app/actions/actions.c
Normal file
@ -0,0 +1,192 @@
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "actions-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
|
||||
#include "widgets/gimpactionfactory.h"
|
||||
|
||||
#include "brushes-actions.h"
|
||||
#include "buffers-actions.h"
|
||||
#include "channels-actions.h"
|
||||
#include "colormap-editor-actions.h"
|
||||
#include "debug-actions.h"
|
||||
#include "dialogs-actions.h"
|
||||
#include "dockable-actions.h"
|
||||
#include "documents-actions.h"
|
||||
#include "drawable-actions.h"
|
||||
#include "edit-actions.h"
|
||||
#include "error-console-actions.h"
|
||||
#include "file-actions.h"
|
||||
#include "fonts-actions.h"
|
||||
#include "gradient-editor-actions.h"
|
||||
#include "gradients-actions.h"
|
||||
#include "help-actions.h"
|
||||
#include "image-actions.h"
|
||||
#include "images-actions.h"
|
||||
#include "layers-actions.h"
|
||||
#include "palette-editor-actions.h"
|
||||
#include "palettes-actions.h"
|
||||
#include "patterns-actions.h"
|
||||
#include "plug-in-actions.h"
|
||||
#include "qmask-actions.h"
|
||||
#include "select-actions.h"
|
||||
#include "templates-actions.h"
|
||||
#include "tool-options-actions.h"
|
||||
#include "tools-actions.h"
|
||||
#include "vectors-actions.h"
|
||||
#include "view-actions.h"
|
||||
|
||||
|
||||
/* global variables */
|
||||
|
||||
GimpActionFactory *global_action_factory = NULL;
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
||||
static GimpActionFactoryEntry action_groups[] =
|
||||
{
|
||||
{ "brushes",
|
||||
brushes_actions_setup,
|
||||
brushes_actions_update },
|
||||
{ "buffers",
|
||||
buffers_actions_setup,
|
||||
buffers_actions_update },
|
||||
{ "channels",
|
||||
channels_actions_setup,
|
||||
channels_actions_update },
|
||||
{ "colormap-editor",
|
||||
colormap_editor_actions_setup,
|
||||
colormap_editor_actions_update },
|
||||
{ "debug",
|
||||
debug_actions_setup,
|
||||
debug_actions_update },
|
||||
{ "dialogs",
|
||||
dialogs_actions_setup,
|
||||
dialogs_actions_update },
|
||||
{ "dockable",
|
||||
dockable_actions_setup,
|
||||
dockable_actions_update },
|
||||
{ "documents",
|
||||
documents_actions_setup,
|
||||
documents_actions_update },
|
||||
{ "drawable",
|
||||
drawable_actions_setup,
|
||||
drawable_actions_update },
|
||||
{ "edit",
|
||||
edit_actions_setup,
|
||||
edit_actions_update },
|
||||
{ "error-console",
|
||||
error_console_actions_setup,
|
||||
error_console_actions_update },
|
||||
{ "file",
|
||||
file_actions_setup,
|
||||
file_actions_update },
|
||||
{ "fonts",
|
||||
fonts_actions_setup,
|
||||
fonts_actions_update },
|
||||
{ "gradient-editor",
|
||||
gradient_editor_actions_setup,
|
||||
gradient_editor_actions_update },
|
||||
{ "gradients",
|
||||
gradients_actions_setup,
|
||||
gradients_actions_update },
|
||||
{ "help",
|
||||
help_actions_setup,
|
||||
help_actions_update },
|
||||
{ "image",
|
||||
image_actions_setup,
|
||||
image_actions_update },
|
||||
{ "images",
|
||||
images_actions_setup,
|
||||
images_actions_update },
|
||||
{ "layers",
|
||||
layers_actions_setup,
|
||||
layers_actions_update },
|
||||
{ "palette-editor",
|
||||
palette_editor_actions_setup,
|
||||
palette_editor_actions_update },
|
||||
{ "palettes",
|
||||
palettes_actions_setup,
|
||||
palettes_actions_update },
|
||||
{ "plug-in",
|
||||
plug_in_actions_setup,
|
||||
plug_in_actions_update },
|
||||
{ "qmask",
|
||||
qmask_actions_setup,
|
||||
qmask_actions_update },
|
||||
{ "select",
|
||||
select_actions_setup,
|
||||
select_actions_update },
|
||||
{ "templates",
|
||||
templates_actions_setup,
|
||||
templates_actions_update },
|
||||
{ "tool-options",
|
||||
tool_options_actions_setup,
|
||||
tool_options_actions_update },
|
||||
{ "tools",
|
||||
tools_actions_setup,
|
||||
tools_actions_update },
|
||||
{ "vectors",
|
||||
vectors_actions_setup,
|
||||
vectors_actions_update },
|
||||
{ "view",
|
||||
view_actions_setup,
|
||||
view_actions_update }
|
||||
};
|
||||
|
||||
static gboolean actions_initialized = FALSE;
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
void
|
||||
actions_init (Gimp *gimp)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
g_return_if_fail (actions_initialized == FALSE);
|
||||
|
||||
actions_initialized = TRUE;
|
||||
|
||||
global_action_factory = gimp_action_factory_new (gimp);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (action_groups); i++)
|
||||
gimp_action_factory_group_register (global_action_factory,
|
||||
action_groups[i].identifier,
|
||||
action_groups[i].setup_func,
|
||||
action_groups[i].update_func);
|
||||
}
|
||||
|
||||
void
|
||||
actions_exit (Gimp *gimp)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
|
||||
g_object_unref (global_action_factory);
|
||||
global_action_factory = NULL;
|
||||
}
|
30
app/actions/actions.h
Normal file
30
app/actions/actions.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __ACTIONS_H__
|
||||
#define __ACTIONS_H__
|
||||
|
||||
|
||||
extern GimpActionFactory *global_action_factory;
|
||||
|
||||
|
||||
void actions_init (Gimp *gimp);
|
||||
void actions_exit (Gimp *gimp);
|
||||
|
||||
|
||||
#endif /* __ACTIONS_H__ */
|
@ -187,7 +187,7 @@ edit_actions_setup (GimpActionGroup *group,
|
||||
}
|
||||
|
||||
void
|
||||
edit_action_update (GimpActionGroup *group,
|
||||
edit_actions_update (GimpActionGroup *group,
|
||||
gpointer data)
|
||||
{
|
||||
GimpDisplay *gdisp = NULL;
|
||||
|
@ -18,35 +18,50 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "actions-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpchannel.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimplayer.h"
|
||||
#include "core/gimplist.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
#include "core/gimpundostack.h"
|
||||
|
||||
#include "pdb/procedural_db.h"
|
||||
|
||||
#include "plug-in/plug-ins.h"
|
||||
#include "plug-in/plug-in-proc.h"
|
||||
|
||||
#include "widgets/gimpactiongroup.h"
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
|
||||
#include "plug-in-actions.h"
|
||||
#include "plug-in-commands.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
typedef struct _PlugInActionEntry PlugInActionEntry;
|
||||
|
||||
struct _PlugInActionEntry
|
||||
{
|
||||
PlugInProcDef *proc_def;
|
||||
const gchar *locale_domain;
|
||||
const gchar *help_domain;
|
||||
};
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static gboolean plug_in_actions_tree_traverse_func (gpointer foo,
|
||||
PlugInActionEntry *entry,
|
||||
GimpActionGroup *group);
|
||||
|
||||
|
||||
static GimpActionEntry plug_in_actions[] =
|
||||
{
|
||||
{ "plug-in-menu", NULL, N_("/Filte_rs") },
|
||||
@ -86,10 +101,15 @@ static GimpEnumActionEntry plug_in_repeat_actions[] =
|
||||
};
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
void
|
||||
plug_in_actions_setup (GimpActionGroup *group,
|
||||
gpointer data)
|
||||
{
|
||||
GSList *procs;
|
||||
GTree *action_entries;
|
||||
|
||||
gimp_action_group_add_actions (group,
|
||||
plug_in_actions,
|
||||
G_N_ELEMENTS (plug_in_actions),
|
||||
@ -100,6 +120,51 @@ plug_in_actions_setup (GimpActionGroup *group,
|
||||
G_N_ELEMENTS (plug_in_repeat_actions),
|
||||
G_CALLBACK (plug_in_repeat_cmd_callback),
|
||||
data);
|
||||
|
||||
action_entries = g_tree_new_full ((GCompareDataFunc) g_utf8_collate, NULL,
|
||||
g_free, g_free);
|
||||
|
||||
for (procs = group->gimp->plug_in_proc_defs;
|
||||
procs;
|
||||
procs = procs->next)
|
||||
{
|
||||
PlugInProcDef *proc_def = procs->data;
|
||||
|
||||
if (proc_def->prog &&
|
||||
proc_def->menu_path &&
|
||||
! proc_def->extensions &&
|
||||
! proc_def->prefixes &&
|
||||
! proc_def->magics)
|
||||
{
|
||||
PlugInActionEntry *entry;
|
||||
const gchar *progname;
|
||||
const gchar *locale_domain;
|
||||
const gchar *help_domain;
|
||||
gchar *key;
|
||||
|
||||
progname = plug_in_proc_def_get_progname (proc_def);
|
||||
|
||||
locale_domain = plug_ins_locale_domain (group->gimp,
|
||||
progname, NULL);
|
||||
help_domain = plug_ins_help_domain (group->gimp,
|
||||
progname, NULL);
|
||||
|
||||
entry = g_new0 (PlugInActionEntry, 1);
|
||||
|
||||
entry->proc_def = proc_def;
|
||||
entry->locale_domain = locale_domain;
|
||||
entry->help_domain = help_domain;
|
||||
|
||||
key = gimp_strip_uline (dgettext (locale_domain,
|
||||
proc_def->menu_path));
|
||||
g_tree_insert (action_entries, key, entry);
|
||||
}
|
||||
}
|
||||
|
||||
g_tree_foreach (action_entries,
|
||||
(GTraverseFunc) plug_in_actions_tree_traverse_func,
|
||||
group);
|
||||
g_tree_destroy (action_entries);
|
||||
}
|
||||
|
||||
void
|
||||
@ -107,3 +172,62 @@ plug_in_actions_update (GimpActionGroup *group,
|
||||
gpointer data)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
plug_in_actions_add_proc (GimpActionGroup *group,
|
||||
PlugInProcDef *proc_def,
|
||||
const gchar *locale_domain,
|
||||
const gchar *help_domain)
|
||||
{
|
||||
GimpActionEntry entry;
|
||||
gchar *help_id;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
|
||||
g_return_if_fail (proc_def != NULL);
|
||||
|
||||
help_id = plug_in_proc_def_get_help_id (proc_def, help_domain);
|
||||
|
||||
entry.name = proc_def->db_info.name;
|
||||
entry.stock_id = NULL;
|
||||
entry.label = strrchr (proc_def->menu_path, '/') + 1;
|
||||
entry.accelerator = proc_def->accelerator;
|
||||
entry.tooltip = NULL;
|
||||
entry.callback = G_CALLBACK (plug_in_run_cmd_callback);
|
||||
entry.help_id = help_id;
|
||||
|
||||
gimp_action_group_add_actions (group, &entry, 1, &proc_def->db_info);
|
||||
|
||||
g_free (help_id);
|
||||
}
|
||||
|
||||
void
|
||||
plug_in_actions_remove_proc (GimpActionGroup *group,
|
||||
PlugInProcDef *proc_def)
|
||||
{
|
||||
GtkAction *action;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
|
||||
g_return_if_fail (proc_def != NULL);
|
||||
|
||||
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
|
||||
proc_def->db_info.name);
|
||||
|
||||
if (action)
|
||||
gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static gboolean
|
||||
plug_in_actions_tree_traverse_func (gpointer foo,
|
||||
PlugInActionEntry *entry,
|
||||
GimpActionGroup *group)
|
||||
{
|
||||
plug_in_actions_add_proc (group,
|
||||
entry->proc_def,
|
||||
entry->locale_domain,
|
||||
entry->help_domain);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -25,5 +25,12 @@ void plug_in_actions_setup (GimpActionGroup *group,
|
||||
void plug_in_actions_update (GimpActionGroup *group,
|
||||
gpointer data);
|
||||
|
||||
void plug_in_actions_add_proc (GimpActionGroup *group,
|
||||
PlugInProcDef *proc_def,
|
||||
const gchar *locale_domain,
|
||||
const gchar *help_domain);
|
||||
void plug_in_actions_remove_proc (GimpActionGroup *group,
|
||||
PlugInProcDef *proc_def);
|
||||
|
||||
|
||||
#endif /* __PLUG_IN_ACTIONS_H__ */
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "widgets/gimpitemfactory.h"
|
||||
#include "widgets/gimpmenufactory.h"
|
||||
|
||||
#include "actions/actions.h"
|
||||
#include "actions/file-commands.h"
|
||||
|
||||
#include "brushes-menu.h"
|
||||
@ -100,6 +101,8 @@ menus_init (Gimp *gimp)
|
||||
|
||||
menus_initialized = TRUE;
|
||||
|
||||
actions_init (gimp);
|
||||
|
||||
/* We need to make sure the property is installed before using it */
|
||||
g_type_class_ref (GTK_TYPE_MENU);
|
||||
|
||||
@ -108,7 +111,7 @@ menus_init (Gimp *gimp)
|
||||
g_signal_connect (gimp->config, "notify::can-change-accels",
|
||||
G_CALLBACK (menu_can_change_accels), NULL);
|
||||
|
||||
global_menu_factory = gimp_menu_factory_new (gimp);
|
||||
global_menu_factory = gimp_menu_factory_new (gimp, global_action_factory);
|
||||
|
||||
gimp_menu_factory_menu_register (global_menu_factory, "<Toolbox>",
|
||||
_("Toolbox Menu"),
|
||||
@ -285,6 +288,8 @@ menus_exit (Gimp *gimp)
|
||||
g_signal_handlers_disconnect_by_func (gimp->config,
|
||||
menu_can_change_accels,
|
||||
NULL);
|
||||
|
||||
actions_exit (gimp);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "widgets/gimpitemfactory.h"
|
||||
#include "widgets/gimpmenufactory.h"
|
||||
|
||||
#include "actions/actions.h"
|
||||
#include "actions/file-commands.h"
|
||||
|
||||
#include "brushes-menu.h"
|
||||
@ -100,6 +101,8 @@ menus_init (Gimp *gimp)
|
||||
|
||||
menus_initialized = TRUE;
|
||||
|
||||
actions_init (gimp);
|
||||
|
||||
/* We need to make sure the property is installed before using it */
|
||||
g_type_class_ref (GTK_TYPE_MENU);
|
||||
|
||||
@ -108,7 +111,7 @@ menus_init (Gimp *gimp)
|
||||
g_signal_connect (gimp->config, "notify::can-change-accels",
|
||||
G_CALLBACK (menu_can_change_accels), NULL);
|
||||
|
||||
global_menu_factory = gimp_menu_factory_new (gimp);
|
||||
global_menu_factory = gimp_menu_factory_new (gimp, global_action_factory);
|
||||
|
||||
gimp_menu_factory_menu_register (global_menu_factory, "<Toolbox>",
|
||||
_("Toolbox Menu"),
|
||||
@ -285,6 +288,8 @@ menus_exit (Gimp *gimp)
|
||||
g_signal_handlers_disconnect_by_func (gimp->config,
|
||||
menu_can_change_accels,
|
||||
NULL);
|
||||
|
||||
actions_exit (gimp);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -19,6 +19,8 @@ noinst_LIBRARIES = libappwidgets.a
|
||||
libappwidgets_a_sources = \
|
||||
widgets-enums.h \
|
||||
widgets-types.h \
|
||||
gimpactionfactory.c \
|
||||
gimpactionfactory.h \
|
||||
gimpactiongroup.c \
|
||||
gimpactiongroup.h \
|
||||
gimpbrusheditor.c \
|
||||
|
182
app/widgets/gimpactionfactory.c
Normal file
182
app/widgets/gimpactionfactory.c
Normal file
@ -0,0 +1,182 @@
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpactionfactory.c
|
||||
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "widgets-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
|
||||
#include "gimpactionfactory.h"
|
||||
#include "gimpactiongroup.h"
|
||||
|
||||
|
||||
static void gimp_action_factory_class_init (GimpActionFactoryClass *klass);
|
||||
static void gimp_action_factory_init (GimpActionFactory *factory);
|
||||
|
||||
static void gimp_action_factory_finalize (GObject *object);
|
||||
|
||||
|
||||
static GimpObjectClass *parent_class = NULL;
|
||||
|
||||
|
||||
GType
|
||||
gimp_action_factory_get_type (void)
|
||||
{
|
||||
static GType factory_type = 0;
|
||||
|
||||
if (! factory_type)
|
||||
{
|
||||
static const GTypeInfo factory_info =
|
||||
{
|
||||
sizeof (GimpActionFactoryClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) gimp_action_factory_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GimpActionFactory),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gimp_action_factory_init,
|
||||
};
|
||||
|
||||
factory_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
||||
"GimpActionFactory",
|
||||
&factory_info, 0);
|
||||
}
|
||||
|
||||
return factory_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_action_factory_class_init (GimpActionFactoryClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_action_factory_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_action_factory_init (GimpActionFactory *factory)
|
||||
{
|
||||
factory->gimp = NULL;
|
||||
factory->registered_groups = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_action_factory_finalize (GObject *object)
|
||||
{
|
||||
GimpActionFactory *factory = GIMP_ACTION_FACTORY (object);
|
||||
GList *list;
|
||||
|
||||
for (list = factory->registered_groups; list; list = g_list_next (list))
|
||||
{
|
||||
GimpActionFactoryEntry *entry = list->data;
|
||||
|
||||
g_free (entry->identifier);
|
||||
g_free (entry);
|
||||
}
|
||||
|
||||
g_list_free (factory->registered_groups);
|
||||
factory->registered_groups = NULL;
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
GimpActionFactory *
|
||||
gimp_action_factory_new (Gimp *gimp)
|
||||
{
|
||||
GimpActionFactory *factory;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
|
||||
factory = g_object_new (GIMP_TYPE_ACTION_FACTORY, NULL);
|
||||
|
||||
factory->gimp = gimp;
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_factory_group_register (GimpActionFactory *factory,
|
||||
const gchar *identifier,
|
||||
GimpActionGroupSetupFunc setup_func,
|
||||
GimpActionGroupUpdateFunc update_func)
|
||||
{
|
||||
GimpActionFactoryEntry *entry;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ACTION_FACTORY (factory));
|
||||
g_return_if_fail (identifier != NULL);
|
||||
g_return_if_fail (setup_func != NULL);
|
||||
g_return_if_fail (update_func != NULL);
|
||||
|
||||
entry = g_new0 (GimpActionFactoryEntry, 1);
|
||||
|
||||
entry->identifier = g_strdup (identifier);
|
||||
entry->setup_func = setup_func;
|
||||
entry->update_func = update_func;
|
||||
|
||||
factory->registered_groups = g_list_prepend (factory->registered_groups,
|
||||
entry);
|
||||
}
|
||||
|
||||
GimpActionGroup *
|
||||
gimp_action_factory_group_new (GimpActionFactory *factory,
|
||||
const gchar *identifier,
|
||||
gpointer setup_data)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_ACTION_FACTORY (factory), NULL);
|
||||
g_return_val_if_fail (identifier != NULL, NULL);
|
||||
|
||||
for (list = factory->registered_groups; list; list = g_list_next (list))
|
||||
{
|
||||
GimpActionFactoryEntry *entry = list->data;
|
||||
|
||||
if (! strcmp (entry->identifier, identifier))
|
||||
{
|
||||
GimpActionGroup *group;
|
||||
|
||||
group = gimp_action_group_new (factory->gimp,
|
||||
entry->identifier,
|
||||
entry->update_func);
|
||||
|
||||
if (entry->setup_func)
|
||||
entry->setup_func (group, setup_data);
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
g_warning ("%s: no entry registered for \"%s\"",
|
||||
G_GNUC_FUNCTION, identifier);
|
||||
|
||||
return NULL;
|
||||
}
|
77
app/widgets/gimpactionfactory.h
Normal file
77
app/widgets/gimpactionfactory.h
Normal file
@ -0,0 +1,77 @@
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpactionfactory.h
|
||||
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_ACTION_FACTORY_H__
|
||||
#define __GIMP_ACTION_FACTORY_H__
|
||||
|
||||
|
||||
#include "core/gimpobject.h"
|
||||
|
||||
|
||||
typedef struct _GimpActionFactoryEntry GimpActionFactoryEntry;
|
||||
|
||||
struct _GimpActionFactoryEntry
|
||||
{
|
||||
gchar *identifier;
|
||||
GimpActionGroupSetupFunc setup_func;
|
||||
GimpActionGroupUpdateFunc update_func;
|
||||
};
|
||||
|
||||
|
||||
#define GIMP_TYPE_ACTION_FACTORY (gimp_action_factory_get_type ())
|
||||
#define GIMP_ACTION_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ACTION_FACTORY, GimpActionFactory))
|
||||
#define GIMP_ACTION_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ACTION_FACTORY, GimpActionFactoryClass))
|
||||
#define GIMP_IS_ACTION_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ACTION_FACTORY))
|
||||
#define GIMP_IS_ACTION_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ACTION_FACTORY))
|
||||
#define GIMP_ACTION_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ACTION_FACTORY, GimpActionFactoryClass))
|
||||
|
||||
|
||||
typedef struct _GimpActionFactoryClass GimpActionFactoryClass;
|
||||
|
||||
struct _GimpActionFactory
|
||||
{
|
||||
GimpObject parent_instance;
|
||||
|
||||
Gimp *gimp;
|
||||
GList *registered_groups;
|
||||
};
|
||||
|
||||
struct _GimpActionFactoryClass
|
||||
{
|
||||
GimpObjectClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GType gimp_action_factory_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GimpActionFactory * gimp_action_factory_new (Gimp *gimp);
|
||||
|
||||
void gimp_action_factory_group_register (GimpActionFactory *factory,
|
||||
const gchar *identifier,
|
||||
GimpActionGroupSetupFunc setup_func,
|
||||
GimpActionGroupUpdateFunc update_func);
|
||||
|
||||
GimpActionGroup * gimp_action_factory_group_new (GimpActionFactory *factory,
|
||||
const gchar *identifier,
|
||||
gpointer setup_data);
|
||||
|
||||
|
||||
#endif /* __GIMP_ACTION_FACTORY_H__ */
|
@ -191,15 +191,32 @@ gimp_action_group_get_property (GObject *object,
|
||||
*/
|
||||
GimpActionGroup *
|
||||
gimp_action_group_new (Gimp *gimp,
|
||||
const gchar *name)
|
||||
const gchar *name,
|
||||
GimpActionGroupUpdateFunc update_func)
|
||||
{
|
||||
GimpActionGroup *group;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
return g_object_new (GIMP_TYPE_ACTION_GROUP,
|
||||
group = g_object_new (GIMP_TYPE_ACTION_GROUP,
|
||||
"gimp", gimp,
|
||||
"name", name,
|
||||
NULL);
|
||||
|
||||
group->update_func = update_func;
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_action_group_update (GimpActionGroup *group,
|
||||
gpointer update_data)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
|
||||
|
||||
if (group->update_func)
|
||||
group->update_func (group, update_data);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -41,6 +41,8 @@ struct _GimpActionGroup
|
||||
|
||||
Gimp *gimp;
|
||||
gchar *translation_domain;
|
||||
|
||||
GimpActionGroupUpdateFunc update_func;
|
||||
};
|
||||
|
||||
struct _GimpActionGroupClass
|
||||
@ -112,7 +114,11 @@ struct _GimpStringActionEntry
|
||||
|
||||
GType gimp_action_group_get_type (void);
|
||||
GimpActionGroup *gimp_action_group_new (Gimp *gimp,
|
||||
const gchar *name);
|
||||
const gchar *name,
|
||||
GimpActionGroupUpdateFunc );
|
||||
|
||||
void gimp_action_group_update (GimpActionGroup *group,
|
||||
gpointer update_data);
|
||||
|
||||
void gimp_action_group_add_actions (GimpActionGroup *group,
|
||||
GimpActionEntry *entries,
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "core/gimp.h"
|
||||
|
||||
#include "gimpactionfactory.h"
|
||||
#include "gimpmenufactory.h"
|
||||
#include "gimpitemfactory.h"
|
||||
|
||||
@ -75,9 +76,7 @@ gimp_menu_factory_get_type (void)
|
||||
static void
|
||||
gimp_menu_factory_class_init (GimpMenuFactoryClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
@ -94,20 +93,20 @@ gimp_menu_factory_init (GimpMenuFactory *factory)
|
||||
static void
|
||||
gimp_menu_factory_finalize (GObject *object)
|
||||
{
|
||||
GimpMenuFactory *factory;
|
||||
GimpMenuFactory *factory = GIMP_MENU_FACTORY (object);
|
||||
GList *list;
|
||||
|
||||
factory = GIMP_MENU_FACTORY (object);
|
||||
|
||||
for (list = factory->registered_menus; list; list = g_list_next (list))
|
||||
{
|
||||
GimpMenuFactoryEntry *entry;
|
||||
|
||||
entry = (GimpMenuFactoryEntry *) list->data;
|
||||
GimpMenuFactoryEntry *entry = list->data;
|
||||
|
||||
g_free (entry->identifier);
|
||||
g_free (entry->title);
|
||||
g_free (entry->help_id);
|
||||
|
||||
g_list_foreach (entry->action_groups, (GFunc) g_free, NULL);
|
||||
g_list_free (entry->action_groups);
|
||||
|
||||
g_free (entry);
|
||||
}
|
||||
|
||||
@ -118,15 +117,18 @@ gimp_menu_factory_finalize (GObject *object)
|
||||
}
|
||||
|
||||
GimpMenuFactory *
|
||||
gimp_menu_factory_new (Gimp *gimp)
|
||||
gimp_menu_factory_new (Gimp *gimp,
|
||||
GimpActionFactory *action_factory)
|
||||
{
|
||||
GimpMenuFactory *factory;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_ACTION_FACTORY (action_factory), NULL);
|
||||
|
||||
factory = g_object_new (GIMP_TYPE_MENU_FACTORY, NULL);
|
||||
|
||||
factory->gimp = gimp;
|
||||
factory->action_factory = action_factory;
|
||||
|
||||
return factory;
|
||||
}
|
||||
@ -209,3 +211,94 @@ gimp_menu_factory_menu_new (GimpMenuFactory *factory,
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_menu_factory_manager_register (GimpMenuFactory *factory,
|
||||
const gchar *identifier,
|
||||
const gchar *first_group,
|
||||
...)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_MENU_FACTORY (factory));
|
||||
g_return_if_fail (identifier != NULL);
|
||||
g_return_if_fail (first_group != NULL);
|
||||
|
||||
for (list = factory->registered_menus; list; list = g_list_next (list))
|
||||
{
|
||||
GimpMenuFactoryEntry *entry = list->data;
|
||||
|
||||
if (! strcmp (entry->identifier, identifier))
|
||||
{
|
||||
const gchar *group;
|
||||
va_list args;
|
||||
|
||||
g_return_if_fail (entry->action_groups == NULL);
|
||||
|
||||
va_start (args, first_group);
|
||||
|
||||
for (group = first_group;
|
||||
group;
|
||||
group = va_arg (args, const gchar *))
|
||||
{
|
||||
entry->action_groups = g_list_prepend (entry->action_groups,
|
||||
g_strdup (group));
|
||||
}
|
||||
|
||||
va_end (args);
|
||||
|
||||
entry->action_groups = g_list_reverse (entry->action_groups);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_warning ("%s: no entry registered for \"%s\"",
|
||||
G_GNUC_FUNCTION, identifier);
|
||||
}
|
||||
|
||||
GtkUIManager *
|
||||
gimp_menu_factory_manager_new (GimpMenuFactory *factory,
|
||||
const gchar *identifier,
|
||||
gpointer callback_data,
|
||||
gboolean create_tearoff)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (factory), NULL);
|
||||
g_return_val_if_fail (identifier != NULL, NULL);
|
||||
|
||||
for (list = factory->registered_menus; list; list = g_list_next (list))
|
||||
{
|
||||
GimpMenuFactoryEntry *entry = list->data;
|
||||
|
||||
if (! strcmp (entry->identifier, identifier))
|
||||
{
|
||||
GtkUIManager *manager;
|
||||
GList *list;
|
||||
|
||||
manager = gtk_ui_manager_new ();
|
||||
gtk_ui_manager_set_add_tearoffs (manager, create_tearoff);
|
||||
|
||||
for (list = entry->action_groups; list; list = g_list_next (list))
|
||||
{
|
||||
GimpActionGroup *group;
|
||||
|
||||
group = gimp_action_factory_group_new (factory->action_factory,
|
||||
(const gchar *) list->data,
|
||||
callback_data);
|
||||
gtk_ui_manager_insert_action_group (manager,
|
||||
GTK_ACTION_GROUP (group),
|
||||
-1);
|
||||
g_object_unref (group);
|
||||
}
|
||||
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
|
||||
g_warning ("%s: no entry registered for \"%s\"",
|
||||
G_GNUC_FUNCTION, identifier);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ struct _GimpMenuFactoryEntry
|
||||
gboolean update_on_popup;
|
||||
guint n_entries;
|
||||
GimpItemFactoryEntry *entries;
|
||||
|
||||
GList *action_groups;
|
||||
};
|
||||
|
||||
|
||||
@ -56,6 +58,7 @@ struct _GimpMenuFactory
|
||||
GimpObject parent_instance;
|
||||
|
||||
Gimp *gimp;
|
||||
GimpActionFactory *action_factory;
|
||||
GList *registered_menus;
|
||||
};
|
||||
|
||||
@ -67,7 +70,8 @@ struct _GimpMenuFactoryClass
|
||||
|
||||
GType gimp_menu_factory_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GimpMenuFactory * gimp_menu_factory_new (Gimp *gimp);
|
||||
GimpMenuFactory * gimp_menu_factory_new (Gimp *gimp,
|
||||
GimpActionFactory *action_factory);
|
||||
|
||||
void gimp_menu_factory_menu_register (GimpMenuFactory *factory,
|
||||
const gchar *identifier,
|
||||
@ -86,4 +90,15 @@ GimpItemFactory * gimp_menu_factory_menu_new (GimpMenuFactory *factory,
|
||||
gboolean create_tearoff);
|
||||
|
||||
|
||||
void gimp_menu_factory_manager_register (GimpMenuFactory *factory,
|
||||
const gchar *identifier,
|
||||
const gchar *first_group,
|
||||
...);
|
||||
|
||||
GtkUIManager * gimp_menu_factory_manager_new (GimpMenuFactory *factory,
|
||||
const gchar *identifier,
|
||||
gpointer callback_data,
|
||||
gboolean create_tearoff);
|
||||
|
||||
|
||||
#endif /* __GIMP_MENU_FACTORY_H__ */
|
||||
|
@ -33,6 +33,7 @@ typedef struct _GimpDeviceInfo GimpDeviceInfo;
|
||||
typedef struct _GimpDialogFactory GimpDialogFactory;
|
||||
typedef struct _GimpMenuFactory GimpMenuFactory;
|
||||
|
||||
typedef struct _GimpActionFactory GimpActionFactory;
|
||||
typedef struct _GimpActionGroup GimpActionGroup;
|
||||
typedef struct _GimpEnumAction GimpEnumAction;
|
||||
typedef struct _GimpStringAction GimpStringAction;
|
||||
|
Reference in New Issue
Block a user