Commit 94fc8f15 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/widgets/gimpactionfactory.[ch] added "label" and "stock-id" properties

2004-07-20  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpactionfactory.[ch]
	* app/widgets/gimpactiongroup.[ch]: added "label" and "stock-id"
	properties to GtkActionGroup and allow to register them in the
	GimpActionFactory.

	* app/actions/actions.c: register user visible labels and icons
	with all action groups.

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpactionview.[ch]: new widget which shows a
	treeview of action groups and their actions & shortcuts.

	* app/widgets/gimpaction.[ch]: added gimp_action_name_compare()
	utility function.

	* app/widgets/gimpwidgets-utils.[ch]: added
	gimp_get_accel_string() utility function.

	* app/widgets/gimpcontrollers.[ch]: added
	gimp_controllers_get_ui_manager() which will be used for setting
	up the controller mapping dialog.

	* app/gui/preferences-dialog.c: added a "Configure Keyboard
	Shortcuts" button which pops up a GimpControllerView. Work in
	progress...
parent 868bee65
2004-07-20 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpactionfactory.[ch]
* app/widgets/gimpactiongroup.[ch]: added "label" and "stock-id"
properties to GtkActionGroup and allow to register them in the
GimpActionFactory.
* app/actions/actions.c: register user visible labels and icons
with all action groups.
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpactionview.[ch]: new widget which shows a
treeview of action groups and their actions & shortcuts.
* app/widgets/gimpaction.[ch]: added gimp_action_name_compare()
utility function.
* app/widgets/gimpwidgets-utils.[ch]: added
gimp_get_accel_string() utility function.
* app/widgets/gimpcontrollers.[ch]: added
gimp_controllers_get_ui_manager() which will be used for setting
up the controller mapping dialog.
* app/gui/preferences-dialog.c: added a "Configure Keyboard
Shortcuts" button which pops up a GimpControllerView. Work in
progress...
2004-07-20 Michael Natterer <mitch@gimp.org>
* app/actions/image-actions.c: make sure that the "image-new" and
......
......@@ -74,6 +74,8 @@
#include "vectors-actions.h"
#include "view-actions.h"
#include "gimp-intl.h"
/* global variables */
......@@ -84,97 +86,97 @@ GimpActionFactory *global_action_factory = NULL;
static GimpActionFactoryEntry action_groups[] =
{
{ "brushes",
{ "brushes", N_("Brushes"), GIMP_STOCK_BRUSH,
brushes_actions_setup,
brushes_actions_update },
{ "buffers",
{ "buffers", N_("Buffers"), GIMP_STOCK_BUFFER,
buffers_actions_setup,
buffers_actions_update },
{ "channels",
{ "channels", N_("Channels"), GIMP_STOCK_CHANNEL,
channels_actions_setup,
channels_actions_update },
{ "colormap-editor",
{ "colormap-editor", N_("Colormap Editor"), GIMP_STOCK_INDEXED_PALETTE,
colormap_editor_actions_setup,
colormap_editor_actions_update },
{ "context",
{ "context", N_("Context"), NULL,
context_actions_setup,
context_actions_update },
{ "debug",
{ "debug", N_("Debug"), NULL,
debug_actions_setup,
debug_actions_update },
{ "dialogs",
{ "dialogs", N_("Dialogs"), NULL,
dialogs_actions_setup,
dialogs_actions_update },
{ "dockable",
{ "dockable", N_("Dockable"), NULL,
dockable_actions_setup,
dockable_actions_update },
{ "documents",
{ "documents", N_("Document History"), NULL,
documents_actions_setup,
documents_actions_update },
{ "drawable",
{ "drawable", N_("Drawable"), GIMP_STOCK_LAYER,
drawable_actions_setup,
drawable_actions_update },
{ "edit",
{ "edit", N_("Edit"), GIMP_STOCK_EDIT,
edit_actions_setup,
edit_actions_update },
{ "error-console",
{ "error-console", N_("Error Console"), GIMP_STOCK_WARNING,
error_console_actions_setup,
error_console_actions_update },
{ "file",
{ "file", N_("File"), GTK_STOCK_OPEN,
file_actions_setup,
file_actions_update },
{ "fonts",
{ "fonts", N_("Fonts"), GIMP_STOCK_FONT,
fonts_actions_setup,
fonts_actions_update },
{ "gradient-editor",
{ "gradient-editor", N_("Gradient Editor"), GIMP_STOCK_GRADIENT,
gradient_editor_actions_setup,
gradient_editor_actions_update },
{ "gradients",
{ "gradients", N_("Gradients"), GIMP_STOCK_GRADIENT,
gradients_actions_setup,
gradients_actions_update },
{ "help",
{ "help", N_("Help"), GTK_STOCK_HELP,
help_actions_setup,
help_actions_update },
{ "image",
{ "image", N_("Image"), GIMP_STOCK_IMAGE,
image_actions_setup,
image_actions_update },
{ "images",
{ "images", N_("Images"), GIMP_STOCK_IMAGE,
images_actions_setup,
images_actions_update },
{ "layers",
{ "layers", N_("Layers"), GIMP_STOCK_LAYER,
layers_actions_setup,
layers_actions_update },
{ "palette-editor",
{ "palette-editor", N_("Palette Editor"), GIMP_STOCK_PALETTE,
palette_editor_actions_setup,
palette_editor_actions_update },
{ "palettes",
{ "palettes", N_("Palettes"), GIMP_STOCK_PALETTE,
palettes_actions_setup,
palettes_actions_update },
{ "patterns",
{ "patterns", N_("Patterns"), GIMP_STOCK_PATTERN,
patterns_actions_setup,
patterns_actions_update },
{ "plug-in",
{ "plug-in", N_("Plug-Ins"), GIMP_STOCK_PLUGIN,
plug_in_actions_setup,
plug_in_actions_update },
{ "qmask",
{ "qmask", N_("QuickMask"), GIMP_STOCK_QMASK_ON,
qmask_actions_setup,
qmask_actions_update },
{ "select",
{ "select", N_("Select"), GIMP_STOCK_SELECTION,
select_actions_setup,
select_actions_update },
{ "templates",
{ "templates", N_("Templates"), GIMP_STOCK_TEMPLATE,
templates_actions_setup,
templates_actions_update },
{ "tool-options",
{ "tool-options", N_("Tool Options"), GIMP_STOCK_TOOL_OPTIONS,
tool_options_actions_setup,
tool_options_actions_update },
{ "tools",
{ "tools", N_("Tools"), GIMP_STOCK_TOOLS,
tools_actions_setup,
tools_actions_update },
{ "vectors",
{ "vectors", N_("Paths"), GIMP_STOCK_PATH,
vectors_actions_setup,
vectors_actions_update },
{ "view",
{ "view", N_("View"), NULL,
view_actions_setup,
view_actions_update }
};
......@@ -195,6 +197,8 @@ actions_init (Gimp *gimp)
for (i = 0; i < G_N_ELEMENTS (action_groups); i++)
gimp_action_factory_group_register (global_action_factory,
action_groups[i].identifier,
gettext (action_groups[i].label),
action_groups[i].stock_id,
action_groups[i].setup_func,
action_groups[i].update_func);
}
......
......@@ -38,6 +38,7 @@
#include "core/gimplist.h"
#include "core/gimptemplate.h"
#include "widgets/gimpactionview.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpcontainercombobox.h"
#include "widgets/gimpcontainerview.h"
......@@ -49,6 +50,7 @@
#include "widgets/gimpgrideditor.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpuimanager.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimpwidgets-utils.h"
......@@ -80,10 +82,12 @@ static void prefs_resolution_source_callback (GtkWidget *widget,
static void prefs_resolution_calibrate_callback (GtkWidget *widget,
GtkWidget *sizeentry);
static void prefs_input_devices_dialog (GtkWidget *widget,
gpointer user_data);
Gimp *gimp);
static void prefs_input_dialog_able_callback (GtkWidget *widget,
GdkDevice *device,
gpointer data);
static void prefs_keyboard_shortcuts_dialog (GtkWidget *widget,
Gimp *gimp);
/* private variables */
......@@ -407,12 +411,10 @@ prefs_resolution_calibrate_callback (GtkWidget *widget,
static void
prefs_input_devices_dialog (GtkWidget *widget,
gpointer user_data)
Gimp *gimp)
{
static GtkWidget *input_dialog = NULL;
Gimp *gimp = GIMP (user_data);
if (input_dialog)
{
gtk_window_present (GTK_WINDOW (input_dialog));
......@@ -456,6 +458,46 @@ prefs_input_dialog_able_callback (GtkWidget *widget,
gimp_device_info_changed_by_device (device);
}
static void
prefs_keyboard_shortcuts_dialog (GtkWidget *widget,
Gimp *gimp)
{
GtkWidget *dialog;
GtkWidget *scrolled_window;
GtkWidget *view;
dialog = gimp_dialog_new (_("Configure Keyboard Shortcuts"),
"gimp-keyboard-shortcuts-dialog",
gtk_widget_get_toplevel (widget),
GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func,
GIMP_HELP_PREFS_INTERFACE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_SHADOW_IN);
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), scrolled_window);
gtk_widget_show (scrolled_window);
view = gimp_action_view_new (gimp_ui_managers_from_name ("<Image>")->data,
TRUE);
gtk_widget_set_size_request (view, 300, 400);
gtk_container_add (GTK_CONTAINER (scrolled_window), view);
gtk_widget_show (view);
gtk_widget_show (dialog);
}
static GtkWidget *
prefs_notebook_append_page (Gimp *gimp,
GtkNotebook *notebook,
......@@ -1166,6 +1208,13 @@ prefs_dialog_new (Gimp *gimp,
vbox2 = prefs_frame_new (_("Keyboard Shortcuts"),
GTK_CONTAINER (vbox), FALSE);
button = prefs_button_add (GTK_STOCK_PREFERENCES,
_("Configure Keyboard Shortcuts..."),
GTK_BOX (vbox2));
g_signal_connect (button, "clicked",
G_CALLBACK (prefs_keyboard_shortcuts_dialog),
gimp);
prefs_check_button_add (object, "can-change-accels",
_("Use dynamic _keyboard shortcuts"),
GTK_BOX (vbox2));
......
......@@ -38,6 +38,7 @@
#include "core/gimplist.h"
#include "core/gimptemplate.h"
#include "widgets/gimpactionview.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpcontainercombobox.h"
#include "widgets/gimpcontainerview.h"
......@@ -49,6 +50,7 @@
#include "widgets/gimpgrideditor.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpuimanager.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimpwidgets-utils.h"
......@@ -80,10 +82,12 @@ static void prefs_resolution_source_callback (GtkWidget *widget,
static void prefs_resolution_calibrate_callback (GtkWidget *widget,
GtkWidget *sizeentry);
static void prefs_input_devices_dialog (GtkWidget *widget,
gpointer user_data);
Gimp *gimp);
static void prefs_input_dialog_able_callback (GtkWidget *widget,
GdkDevice *device,
gpointer data);
static void prefs_keyboard_shortcuts_dialog (GtkWidget *widget,
Gimp *gimp);
/* private variables */
......@@ -407,12 +411,10 @@ prefs_resolution_calibrate_callback (GtkWidget *widget,
static void
prefs_input_devices_dialog (GtkWidget *widget,
gpointer user_data)
Gimp *gimp)
{
static GtkWidget *input_dialog = NULL;
Gimp *gimp = GIMP (user_data);
if (input_dialog)
{
gtk_window_present (GTK_WINDOW (input_dialog));
......@@ -456,6 +458,46 @@ prefs_input_dialog_able_callback (GtkWidget *widget,
gimp_device_info_changed_by_device (device);
}
static void
prefs_keyboard_shortcuts_dialog (GtkWidget *widget,
Gimp *gimp)
{
GtkWidget *dialog;
GtkWidget *scrolled_window;
GtkWidget *view;
dialog = gimp_dialog_new (_("Configure Keyboard Shortcuts"),
"gimp-keyboard-shortcuts-dialog",
gtk_widget_get_toplevel (widget),
GTK_DIALOG_DESTROY_WITH_PARENT,
gimp_standard_help_func,
GIMP_HELP_PREFS_INTERFACE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_SHADOW_IN);
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), scrolled_window);
gtk_widget_show (scrolled_window);
view = gimp_action_view_new (gimp_ui_managers_from_name ("<Image>")->data,
TRUE);
gtk_widget_set_size_request (view, 300, 400);
gtk_container_add (GTK_CONTAINER (scrolled_window), view);
gtk_widget_show (view);
gtk_widget_show (dialog);
}
static GtkWidget *
prefs_notebook_append_page (Gimp *gimp,
GtkNotebook *notebook,
......@@ -1166,6 +1208,13 @@ prefs_dialog_new (Gimp *gimp,
vbox2 = prefs_frame_new (_("Keyboard Shortcuts"),
GTK_CONTAINER (vbox), FALSE);
button = prefs_button_add (GTK_STOCK_PREFERENCES,
_("Configure Keyboard Shortcuts..."),
GTK_BOX (vbox2));
g_signal_connect (button, "clicked",
G_CALLBACK (prefs_keyboard_shortcuts_dialog),
gimp);
prefs_check_button_add (object, "can-change-accels",
_("Use dynamic _keyboard shortcuts"),
GTK_BOX (vbox2));
......
......@@ -25,6 +25,8 @@ libappwidgets_a_sources = \
gimpactionfactory.h \
gimpactiongroup.c \
gimpactiongroup.h \
gimpactionview.c \
gimpactionview.h \
gimpbrusheditor.c \
gimpbrusheditor.h \
gimpbrushfactoryview.c \
......
......@@ -21,6 +21,8 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
......@@ -241,6 +243,14 @@ gimp_action_new (const gchar *name,
NULL);
}
gint
gimp_action_name_compare (GimpAction *action1,
GimpAction *action2)
{
return strcmp (gtk_action_get_name ((GtkAction *) action1),
gtk_action_get_name ((GtkAction *) action2));
}
/* private functions */
......
......@@ -50,11 +50,14 @@ struct _GimpActionClass
};
GType gimp_action_get_type (void);
GimpAction * gimp_action_new (const gchar *name,
const gchar *label,
const gchar *tooltip,
const gchar *stock_id);
GType gimp_action_get_type (void);
GimpAction * gimp_action_new (const gchar *name,
const gchar *label,
const gchar *tooltip,
const gchar *stock_id);
gint gimp_action_name_compare (GimpAction *action1,
GimpAction *action2);
#endif /* __GIMP_ACTION_H__ */
......@@ -100,6 +100,8 @@ gimp_action_factory_finalize (GObject *object)
GimpActionFactoryEntry *entry = list->data;
g_free (entry->identifier);
g_free (entry->label);
g_free (entry->stock_id);
g_free (entry);
}
......@@ -126,6 +128,8 @@ gimp_action_factory_new (Gimp *gimp)
void
gimp_action_factory_group_register (GimpActionFactory *factory,
const gchar *identifier,
const gchar *label,
const gchar *stock_id,
GimpActionGroupSetupFunc setup_func,
GimpActionGroupUpdateFunc update_func)
{
......@@ -133,12 +137,15 @@ gimp_action_factory_group_register (GimpActionFactory *factory,
g_return_if_fail (GIMP_IS_ACTION_FACTORY (factory));
g_return_if_fail (identifier != NULL);
g_return_if_fail (label != 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->label = g_strdup (label);
entry->stock_id = g_strdup (stock_id);
entry->setup_func = setup_func;
entry->update_func = update_func;
......@@ -166,6 +173,8 @@ gimp_action_factory_group_new (GimpActionFactory *factory,
group = gimp_action_group_new (factory->gimp,
entry->identifier,
entry->label,
entry->stock_id,
user_data,
entry->update_func);
......
......@@ -31,6 +31,8 @@ typedef struct _GimpActionFactoryEntry GimpActionFactoryEntry;
struct _GimpActionFactoryEntry
{
gchar *identifier;
gchar *label;
gchar *stock_id;
GimpActionGroupSetupFunc setup_func;
GimpActionGroupUpdateFunc update_func;
};
......@@ -66,6 +68,8 @@ GimpActionFactory * gimp_action_factory_new (Gimp *gimp);
void gimp_action_factory_group_register (GimpActionFactory *factory,
const gchar *identifier,
const gchar *label,
const gchar *stock_id,
GimpActionGroupSetupFunc setup_func,
GimpActionGroupUpdateFunc update_func);
......
......@@ -43,7 +43,9 @@
enum
{
PROP_0,
PROP_GIMP
PROP_GIMP,
PROP_LABEL,
PROP_STOCK_ID
};
......@@ -54,6 +56,7 @@ static GObject * gimp_action_group_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_action_group_dispose (GObject *object);
static void gimp_action_group_finalize (GObject *object);
static void gimp_action_group_set_property (GObject *object,
guint prop_id,
const GValue *value,
......@@ -104,6 +107,7 @@ gimp_action_group_class_init (GimpActionGroupClass *klass)
object_class->constructor = gimp_action_group_constructor;
object_class->dispose = gimp_action_group_dispose;
object_class->finalize = gimp_action_group_finalize;
object_class->set_property = gimp_action_group_set_property;
object_class->get_property = gimp_action_group_get_property;
......@@ -114,6 +118,20 @@ gimp_action_group_class_init (GimpActionGroupClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_LABEL,
g_param_spec_string ("label",
NULL, NULL,
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_STOCK_ID,
g_param_spec_string ("stock-id",
NULL, NULL,
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
klass->groups = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
}
......@@ -185,6 +203,26 @@ gimp_action_group_dispose (GObject *object)
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_action_group_finalize (GObject *object)
{
GimpActionGroup *group = GIMP_ACTION_GROUP (object);
if (group->label)
{
g_free (group->label);
group->label = NULL;
}
if (group->stock_id)
{
g_free (group->stock_id);
group->stock_id = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_action_group_set_property (GObject *object,
guint prop_id,
......@@ -198,6 +236,12 @@ gimp_action_group_set_property (GObject *object,
case PROP_GIMP:
group->gimp = g_value_get_object (value);
break;
case PROP_LABEL:
group->label = g_value_dup_string (value);
break;
case PROP_STOCK_ID:
group->stock_id = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -217,6 +261,12 @@ gimp_action_group_get_property (GObject *object,
case PROP_GIMP:
g_value_set_object (value, group->gimp);
break;
case PROP_LABEL:
g_value_set_string (value, group->label);
break;
case PROP_STOCK_ID:
g_value_set_string (value, group->stock_id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -227,6 +277,8 @@ gimp_action_group_get_property (GObject *object,
* gimp_action_group_new:
* @gimp: the @Gimp instance this action group belongs to
* @name: the name of the action group.
* @label: the user visible label of the action group.
* @stock_id: the icon of the action group.
* @user_data: the user_data for #GtkAction callbacks.
* @update_func: the function that will be called on
* gimp_action_group_update().
......@@ -240,6 +292,8 @@ gimp_action_group_get_property (GObject *object,
GimpActionGroup *
gimp_action_group_new (Gimp *gimp,
const gchar *name,
const gchar *label,
const gchar *stock_id,
gpointer user_data,
GimpActionGroupUpdateFunc update_func)
{
......@@ -249,8 +303,10 @@ gimp_action_group_new (Gimp *gimp,
g_return_val_if_fail (name != NULL, NULL);
group = g_object_new (GIMP_TYPE_ACTION_GROUP,
"gimp", gimp,
"na