Commit 2075f1e7 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added parameter "const gchar *select_action" and preselect the passed

2004-10-26  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpactionview.[ch] (gimp_action_view_new): added
	parameter "const gchar *select_action" and preselect the passed
	action if non-NULL. Made the column enum public to users of this
	widget can get data from its tree store.

	* app/dialogs/preferences-dialog.c (prefs_keyboard_shortcuts_dialog):
	pass NULL because we don't want a preselected action here.

	* app/widgets/gimpcontrollereditor.[ch]: added "Edit" and "Delete"
	buttons to change the event -> action mapping. Implement a action
	chooser dialog using GimpActionView. Fixes bug #106920.
parent cdea36c6
2004-10-26 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpactionview.[ch] (gimp_action_view_new): added
parameter "const gchar *select_action" and preselect the passed
action if non-NULL. Made the column enum public to users of this
widget can get data from its tree store.
* app/dialogs/preferences-dialog.c (prefs_keyboard_shortcuts_dialog):
pass NULL because we don't want a preselected action here.
* app/widgets/gimpcontrollereditor.[ch]: added "Edit" and "Delete"
buttons to change the event -> action mapping. Implement a action
chooser dialog using GimpActionView. Fixes bug #106920.
2004-10-26 Sven Neumann <sven@gimp.org>
 
* app/actions/channels-commands.c
......
......@@ -523,7 +523,7 @@ prefs_keyboard_shortcuts_dialog (GtkWidget *widget,
gtk_widget_show (scrolled_window);
view = gimp_action_view_new (gimp_ui_managers_from_name ("<Image>")->data,
TRUE);
NULL, TRUE);
gtk_widget_set_size_request (view, 300, 400);
gtk_container_add (GTK_CONTAINER (scrolled_window), view);
gtk_widget_show (view);
......
......@@ -42,19 +42,6 @@
#include "gimp-intl.h"
enum
{
COLUMN_ACTION,
COLUMN_STOCK_ID,
COLUMN_LABEL,
COLUMN_NAME,
COLUMN_ACCEL_KEY,
COLUMN_ACCEL_MASK,
COLUMN_MENU_ITEM,
NUM_COLUMNS
};
/* local function prototypes */
static void gimp_action_view_class_init (GimpActionViewClass *klass);
......@@ -151,6 +138,7 @@ gimp_action_view_dispose (GObject *object)
GtkWidget *
gimp_action_view_new (GimpUIManager *manager,
const gchar *select_action,
gboolean show_shortcuts)
{
GtkTreeView *view;
......@@ -159,10 +147,11 @@ gimp_action_view_new (GimpUIManager *manager,
GtkTreeStore *store;
GtkAccelGroup *accel_group;
GList *list;
GtkTreePath *select_path = NULL;
g_return_val_if_fail (GIMP_IS_UI_MANAGER (manager), NULL);
store = gtk_tree_store_new (NUM_COLUMNS,
store = gtk_tree_store_new (GIMP_ACTION_VIEW_NUM_COLUMNS,
GTK_TYPE_ACTION, /* COLUMN_ACTION */
G_TYPE_STRING, /* COLUMN_STOCK_ID */
G_TYPE_STRING, /* COLUMN_LABEL */
......@@ -185,8 +174,8 @@ gimp_action_view_new (GimpUIManager *manager,
gtk_tree_store_append (store, &group_iter, NULL);
gtk_tree_store_set (store, &group_iter,
COLUMN_STOCK_ID, group->stock_id,
COLUMN_LABEL, group->label,
GIMP_ACTION_VIEW_COLUMN_STOCK_ID, group->stock_id,
GIMP_ACTION_VIEW_COLUMN_LABEL, group->label,
-1);
actions = gtk_action_group_list_actions (GTK_ACTION_GROUP (group));
......@@ -262,13 +251,13 @@ gimp_action_view_new (GimpUIManager *manager,
gtk_tree_store_append (store, &action_iter, &group_iter);
gtk_tree_store_set (store, &action_iter,
COLUMN_ACTION, action,
COLUMN_STOCK_ID, stock_id,
COLUMN_LABEL, stripped,
COLUMN_NAME, name,
COLUMN_ACCEL_KEY, accel_key,
COLUMN_ACCEL_MASK, accel_mask,
COLUMN_MENU_ITEM, menu_item,
GIMP_ACTION_VIEW_COLUMN_ACTION, action,
GIMP_ACTION_VIEW_COLUMN_STOCK_ID, stock_id,
GIMP_ACTION_VIEW_COLUMN_LABEL, stripped,
GIMP_ACTION_VIEW_COLUMN_NAME, name,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, accel_key,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, accel_mask,
GIMP_ACTION_VIEW_COLUMN_MENU_ITEM, menu_item,
-1);
g_free (stock_id);
......@@ -277,6 +266,12 @@ gimp_action_view_new (GimpUIManager *manager,
if (menu_item)
g_object_unref (menu_item);
if (select_action && ! strcmp (select_action, name))
{
select_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store),
&action_iter);
}
}
}
......@@ -299,13 +294,15 @@ gimp_action_view_new (GimpUIManager *manager,
cell = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, cell, FALSE);
gtk_tree_view_column_set_attributes (column, cell,
"stock-id", COLUMN_STOCK_ID,
"stock-id",
GIMP_ACTION_VIEW_COLUMN_STOCK_ID,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_attributes (column, cell,
"text", COLUMN_LABEL,
"text",
GIMP_ACTION_VIEW_COLUMN_LABEL,
NULL);
gtk_tree_view_append_column (view, column);
......@@ -324,8 +321,10 @@ gimp_action_view_new (GimpUIManager *manager,
GTK_CELL_RENDERER_TEXT (cell)->editable = TRUE;
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_attributes (column, cell,
"accel-key", COLUMN_ACCEL_KEY,
"accel-mask", COLUMN_ACCEL_MASK,
"accel-key",
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY,
"accel-mask",
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK,
NULL);
g_signal_connect (cell, "accel-edited",
......@@ -342,12 +341,31 @@ gimp_action_view_new (GimpUIManager *manager,
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_attributes (column, cell,
"text", COLUMN_NAME,
"text",
GIMP_ACTION_VIEW_COLUMN_NAME,
NULL);
gtk_tree_view_append_column (view, column);
}
if (select_path)
{
GtkTreeSelection *sel = gtk_tree_view_get_selection (view);
GtkTreePath *expand;
expand = gtk_tree_path_copy (select_path);
gtk_tree_path_up (expand);
gtk_tree_view_expand_row (view, expand, FALSE);
gtk_tree_selection_select_path (sel, select_path);
gtk_tree_view_scroll_to_cell (view, select_path, NULL,
FALSE, 0.0, 0.0);
gtk_tree_path_free (select_path);
gtk_tree_path_free (expand);
}
return GTK_WIDGET (view);
}
......@@ -392,7 +410,7 @@ gimp_action_view_accel_changed (GtkAccelGroup *accel_group,
GtkWidget *menu_item;
gtk_tree_model_get (model, &child_iter,
COLUMN_MENU_ITEM, &menu_item,
GIMP_ACTION_VIEW_COLUMN_MENU_ITEM, &menu_item,
-1);
if (menu_item)
......@@ -424,8 +442,10 @@ gimp_action_view_accel_changed (GtkAccelGroup *accel_group,
}
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
COLUMN_ACCEL_KEY, accel_key,
COLUMN_ACCEL_MASK, accel_mask,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY,
accel_key,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK,
accel_mask,
-1);
return;
......@@ -554,7 +574,7 @@ gimp_action_view_accel_edited (GimpCellRendererAccel *accel,
gchar *accel_path;
gtk_tree_model_get (model, &iter,
COLUMN_ACTION, &action,
GIMP_ACTION_VIEW_COLUMN_ACTION, &action,
-1);
if (! action)
......@@ -618,15 +638,18 @@ gimp_action_view_accel_edited (GimpCellRendererAccel *accel,
GdkModifierType child_accel_mask;
gtk_tree_model_get (model, &child_iter,
COLUMN_ACCEL_KEY, &child_accel_key,
COLUMN_ACCEL_MASK, &child_accel_mask,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY,
&child_accel_key,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK,
&child_accel_mask,
-1);
if (accel_key == child_accel_key &&
accel_mask == child_accel_mask)
{
gtk_tree_model_get (model, &child_iter,
COLUMN_ACTION, &conflict_action,
GIMP_ACTION_VIEW_COLUMN_ACTION,
&conflict_action,
-1);
break;
}
......
......@@ -26,6 +26,19 @@
#include <gtk/gtktreeview.h>
enum
{
GIMP_ACTION_VIEW_COLUMN_ACTION,
GIMP_ACTION_VIEW_COLUMN_STOCK_ID,
GIMP_ACTION_VIEW_COLUMN_LABEL,
GIMP_ACTION_VIEW_COLUMN_NAME,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK,
GIMP_ACTION_VIEW_COLUMN_MENU_ITEM,
GIMP_ACTION_VIEW_NUM_COLUMNS
};
#define GIMP_TYPE_ACTION_VIEW (gimp_action_view_get_type ())
#define GIMP_ACTION_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ACTION_VIEW, GimpActionView))
#define GIMP_ACTION_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ACTION_VIEW, GimpActionViewClass))
......@@ -55,6 +68,7 @@ struct _GimpActionViewClass
GType gimp_action_view_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_action_view_new (GimpUIManager *manager,
const gchar *select_action,
gboolean show_shortcuts);
......
......@@ -28,9 +28,12 @@
#include "widgets-types.h"
#include "gimpactionview.h"
#include "gimpcontrollereditor.h"
#include "gimpcontrollerinfo.h"
#include "gimphelp-ids.h"
#include "gimppropwidgets.h"
#include "gimpuimanager.h"
#include "gimp-intl.h"
......@@ -44,6 +47,7 @@ enum
enum
{
COLUMN_EVENT,
COLUMN_BLURB,
COLUMN_ACTION,
NUM_COLUMNS
};
......@@ -52,19 +56,42 @@ enum
static void gimp_controller_editor_class_init (GimpControllerEditorClass *klass);
static void gimp_controller_editor_init (GimpControllerEditor *editor);
static GObject * gimp_controller_editor_constructor (GType type,
guint n_params,
static GObject * gimp_controller_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_controller_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_controller_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_controller_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_controller_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_controller_editor_finalize (GObject *object);
static void gimp_controller_editor_finalize (GObject *object);
static void gimp_controller_editor_unmap (GtkWidget *widget);
static void gimp_controller_editor_sel_changed (GtkTreeSelection *sel,
GimpControllerEditor *editor);
static void gimp_controller_editor_row_activated (GtkTreeView *tv,
GtkTreePath *path,
GtkTreeViewColumn *column,
GimpControllerEditor *editor);
static void gimp_controller_editor_edit_clicked (GtkWidget *button,
GimpControllerEditor *editor);
static void gimp_controller_editor_delete_clicked (GtkWidget *button,
GimpControllerEditor *editor);
static void gimp_controller_editor_edit_activated (GtkTreeView *tv,
GtkTreePath *path,
GtkTreeViewColumn *column,
GimpControllerEditor *editor);
static void gimp_controller_editor_edit_response (GtkWidget *dialog,
gint response_id,
GimpControllerEditor *editor);
static GtkVBoxClass *parent_class = NULL;
......@@ -101,7 +128,8 @@ gimp_controller_editor_get_type (void)
static void
gimp_controller_editor_class_init (GimpControllerEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......@@ -110,6 +138,8 @@ gimp_controller_editor_class_init (GimpControllerEditorClass *klass)
object_class->get_property = gimp_controller_editor_get_property;
object_class->finalize = gimp_controller_editor_finalize;
widget_class->unmap = gimp_controller_editor_unmap;
g_object_class_install_property (object_class, PROP_CONTROLLER_INFO,
g_param_spec_object ("controller-info",
NULL, NULL,
......@@ -138,6 +168,7 @@ gimp_controller_editor_constructor (GType type,
GtkWidget *frame;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *tv;
GtkWidget *sw;
......@@ -249,6 +280,7 @@ gimp_controller_editor_constructor (GType type,
g_free (property_specs);
store = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
......@@ -263,6 +295,16 @@ gimp_controller_editor_constructor (GType type,
gtk_container_add (GTK_CONTAINER (vbox), sw);
gtk_widget_show (sw);
g_signal_connect (tv, "row-activated",
G_CALLBACK (gimp_controller_editor_row_activated),
editor);
editor->sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
g_signal_connect (editor->sel, "changed",
G_CALLBACK (gimp_controller_editor_sel_changed),
editor);
n_events = gimp_controller_get_n_events (controller);
for (i = 0; i < n_events; i++)
......@@ -279,7 +321,8 @@ gimp_controller_editor_constructor (GType type,
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COLUMN_EVENT, event_blurb,
COLUMN_EVENT, event_name,
COLUMN_BLURB, event_blurb,
COLUMN_ACTION, event_action,
-1);
}
......@@ -287,7 +330,7 @@ gimp_controller_editor_constructor (GType type,
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), 0,
_("Event"),
gtk_cell_renderer_text_new (),
"text", COLUMN_EVENT,
"text", COLUMN_BLURB,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), 2,
_("Action"),
......@@ -295,6 +338,29 @@ gimp_controller_editor_constructor (GType type,
"text", COLUMN_ACTION,
NULL);
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
editor->edit_button = gtk_button_new_from_stock (GIMP_STOCK_EDIT);
gtk_box_pack_start (GTK_BOX (hbox), editor->edit_button, TRUE, TRUE, 0);
gtk_widget_show (editor->edit_button);
g_signal_connect (editor->edit_button, "clicked",
G_CALLBACK (gimp_controller_editor_edit_clicked),
editor);
editor->delete_button = gtk_button_new_from_stock (GTK_STOCK_DELETE);
gtk_box_pack_start (GTK_BOX (hbox), editor->delete_button, TRUE, TRUE, 0);
gtk_widget_show (editor->delete_button);
g_signal_connect (editor->delete_button, "clicked",
G_CALLBACK (gimp_controller_editor_delete_clicked),
editor);
gtk_widget_set_sensitive (editor->edit_button, FALSE);
gtk_widget_set_sensitive (editor->delete_button, FALSE);
return object;
}
......@@ -347,9 +413,27 @@ gimp_controller_editor_finalize (GObject *object)
editor->info = NULL;
}
if (editor->edit_dialog)
gtk_widget_destroy (editor->edit_dialog);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_controller_editor_unmap (GtkWidget *widget)
{
GimpControllerEditor *editor = GIMP_CONTROLLER_EDITOR (widget);
if (editor->edit_dialog)
gtk_dialog_response (GTK_DIALOG (editor->edit_dialog),
GTK_RESPONSE_CANCEL);
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
}
/* public functions */
GtkWidget *
gimp_controller_editor_new (GimpControllerInfo *info)
{
......@@ -359,3 +443,192 @@ gimp_controller_editor_new (GimpControllerInfo *info)
"controller-info", info,
NULL);
}
/* private functions */
static void
gimp_controller_editor_sel_changed (GtkTreeSelection *sel,
GimpControllerEditor *editor)
{
GtkTreeModel *model;
GtkTreeIter iter;
gboolean edit_sensitive = FALSE;
gboolean delete_sensitive = FALSE;
if (gtk_tree_selection_get_selected (sel, &model, &iter))
{
gchar *action = NULL;
gtk_tree_model_get (model, &iter,
COLUMN_ACTION, &action,
-1);
if (action)
{
g_free (action);
delete_sensitive = TRUE;
}
edit_sensitive = TRUE;
}
gtk_widget_set_sensitive (editor->edit_button, edit_sensitive);
gtk_widget_set_sensitive (editor->delete_button, delete_sensitive);
}
static void
gimp_controller_editor_row_activated (GtkTreeView *tv,
GtkTreePath *path,
GtkTreeViewColumn *column,
GimpControllerEditor *editor)
{
if (GTK_WIDGET_IS_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
}
static void
gimp_controller_editor_edit_clicked (GtkWidget *button,
GimpControllerEditor *editor)
{
GtkTreeModel *model;
GtkTreeIter iter;
gchar *event_name = NULL;
gchar *action_name = NULL;
if (gtk_tree_selection_get_selected (editor->sel, &model, &iter))
gtk_tree_model_get (model, &iter,
COLUMN_EVENT, &event_name,
COLUMN_ACTION, &action_name,
-1);
if (event_name)
{
GtkWidget *scrolled_window;
GtkWidget *view;
editor->edit_dialog =
gimp_dialog_new (_("Select Controller Event Action"),
"gimp-controller-action-dialog",
GTK_WIDGET (editor), 0,
gimp_standard_help_func,
GIMP_HELP_PREFS_INPUT_CONTROLLERS,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_object_add_weak_pointer (G_OBJECT (editor->edit_dialog),
(gpointer) &editor->edit_dialog);
g_signal_connect (editor->edit_dialog, "response",
G_CALLBACK (gimp_controller_editor_edit_response),
editor);
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 (editor->edit_dialog)->vbox),
scrolled_window);
gtk_widget_show (scrolled_window);
view = gimp_action_view_new (gimp_ui_managers_from_name ("<Image>")->data,
action_name, FALSE);
gtk_widget_set_size_request (view, 300, 400);
gtk_container_add (GTK_CONTAINER (scrolled_window), view);
gtk_widget_show (view);
g_signal_connect (view, "row-activated",
G_CALLBACK (gimp_controller_editor_edit_activated),
editor);
editor->edit_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
g_object_add_weak_pointer (G_OBJECT (editor->edit_sel),
(gpointer) &editor->edit_sel);
gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
gtk_widget_show (editor->edit_dialog);
g_free (event_name);
g_free (action_name);
}
}
static void
gimp_controller_editor_delete_clicked (GtkWidget *button,
GimpControllerEditor *editor)
{
GtkTreeModel *model;
GtkTreeIter iter;
gchar *event_name = NULL;
if (gtk_tree_selection_get_selected (editor->sel, &model, &iter))
gtk_tree_model_get (model, &iter,
COLUMN_EVENT, &event_name,
-1);
if (event_name)
{
g_hash_table_remove (editor->info->mapping, event_name);
g_free (event_name);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_ACTION, NULL,
-1);
}
}
static void
gimp_controller_editor_edit_activated (GtkTreeView *tv,
GtkTreePath *path,
GtkTreeViewColumn *column,
GimpControllerEditor *editor)
{
gtk_dialog_response (GTK_DIALOG (editor->edit_dialog), GTK_RESPONSE_OK);
}
static void
gimp_controller_editor_edit_response (GtkWidget *dialog,
gint response_id,
GimpControllerEditor *editor)
{
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
if (response_id == GTK_RESPONSE_OK)
{
GtkTreeModel *model;
GtkTreeIter iter;
gchar *event_name = NULL;
gchar *action_name = NULL;
if (gtk_tree_selection_get_selected (editor->edit_sel, &model, &iter))
gtk_tree_model_get (model, &iter,
GIMP_ACTION_VIEW_COLUMN_NAME, &action_name,
-1);
if (gtk_tree_selection_get_selected (editor->sel, &model, &iter))