[nautilus-actions] Let the label be edited in place in treeview
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Let the label be edited in place in treeview
- Date: Sun, 11 Oct 2009 19:17:20 +0000 (UTC)
commit a68a9b247114dc30668286e95d138ff44c45e5d3
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Oct 9 19:00:48 2009 +0200
Let the label be edited in place in treeview
ChangeLog | 5 +++
src/nact/nact-iaction-tab.c | 24 ++++++++++++
src/nact/nact-iactions-list.c | 77 +++++++++++++++++++++++++++++++++++++++-
src/nact/nact-iactions-list.h | 1 +
src/nact/nact-icommand-tab.c | 24 ++++++++++++
src/nact/nact-main-statusbar.c | 2 +
src/nact/nact-marshal.list | 1 +
src/nact/nact-tree-model.c | 2 +
8 files changed, 135 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cd77164..72154bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,11 @@
Briefly dump the tree store content.
(nact_iactions_list_runtime_init_toplevel): Grab the focus at start.
(on_focus_in, on_focus_out): Track the focus in the treeview.
+ Let the label be edited in place.
+
+ * src/nact/nact-iaction-tab.c (on_iactions_list_column_edited):
+ * src/nact/nact-icommand-tab.c (on_iactions_list_column_edited):
+ New functions.
* src/nact/nact-main-menubar.c (nact_main_menubar_runtime_init):
Display a Maintainer menu when in maintainer mode.
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index 936df13..88967aa 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -40,6 +40,7 @@
#include "base-window.h"
#include "nact-application.h"
#include "nact-main-statusbar.h"
+#include "nact-iactions-list.h"
#include "nact-main-tab.h"
#include "nact-iaction-tab.h"
@@ -68,6 +69,7 @@ static GType register_type( void );
static void interface_base_init( NactIActionTabInterface *klass );
static void interface_base_finalize( NactIActionTabInterface *klass );
+static void on_iactions_list_column_edited( NactIActionTab *instance, NAObject *object, gchar *text, gint column );
static void on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selected );
static void check_for_label( NactIActionTab *instance, GtkEntry *entry, const gchar *label );
static GtkTreeModel *create_stock_icon_model( void );
@@ -220,6 +222,12 @@ nact_iaction_tab_runtime_init_toplevel( NactIActionTab *instance )
TAB_UPDATABLE_SIGNAL_SELECTION_CHANGED,
G_CALLBACK( on_tab_updatable_selection_changed ),
instance );
+
+ g_signal_connect(
+ G_OBJECT( instance ),
+ IACTIONS_LIST_SIGNAL_COLUMN_EDITED,
+ G_CALLBACK( on_iactions_list_column_edited ),
+ instance );
}
}
@@ -275,6 +283,22 @@ nact_iaction_tab_has_label( NactIActionTab *instance )
}
static void
+on_iactions_list_column_edited( NactIActionTab *instance, NAObject *object, gchar *text, gint column )
+{
+ GtkWidget *label_widget;
+
+ g_return_if_fail( NACT_IS_IACTION_TAB( instance ));
+
+ if( st_initialized && !st_finalized ){
+
+ if( NA_IS_OBJECT_ACTION( object )){
+ label_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionLabelEntry" );
+ gtk_entry_set_text( GTK_ENTRY( label_widget ), text );
+ }
+ }
+}
+
+static void
on_tab_updatable_selection_changed( NactIActionTab *instance, gint count_selected )
{
static const gchar *thisfn = "nact_iaction_tab_on_tab_updatable_selection_changed";
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 3efe487..125948d 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -82,6 +82,7 @@ enum {
SELECTION_CHANGED,
FOCUS_IN,
FOCUS_OUT,
+ COLUMN_EDITED,
LAST_SIGNAL
};
@@ -135,6 +136,7 @@ static void interface_base_init( NactIActionsListInterface *klass );
static void interface_base_finalize( NactIActionsListInterface *klass );
static void free_items_callback( NactIActionsList *instance, GList *items );
+static void free_column_edited_callback( NactIActionsList *instance, NAObject *object, gchar *text, gint column );
static void decrement_counters( NactIActionsList *instance, IActionsListInstanceData *ialid, GList *items );
static GtkTreePath *get_selection_first_path( GtkTreeView *treeview );
static void do_insert_items( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTreePath *path, GList **parents );
@@ -164,6 +166,7 @@ static void on_edition_status_changed( NactIActionsList *instance, NAIDu
static gboolean on_focus_in( GtkWidget *widget, GdkEventFocus *event, NactIActionsList *instance );
static gboolean on_focus_out( GtkWidget *widget, GdkEventFocus *event, NactIActionsList *instance );
static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIActionsList *instance );
+static void on_label_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, NactIActionsList *instance );
static void on_treeview_selection_changed( GtkTreeSelection *selection, NactIActionsList *instance );
static void on_tab_updatable_item_updated( NactIActionsList *instance, NAObject *object );
static void on_iactions_list_selection_changed( NactIActionsList *instance, GSList *selected_items );
@@ -315,6 +318,27 @@ interface_base_init( NactIActionsListInterface *klass )
1,
G_TYPE_POINTER );
+ /**
+ * nact-iactions-list-column-edited:
+ *
+ * This signal is emitted byIActionsList when there has been an
+ * inline edition in one of the columns.
+ * The edition tabs should updates their own entries.
+ */
+ st_signals[ COLUMN_EDITED ] = g_signal_new_class_handler(
+ IACTIONS_LIST_SIGNAL_COLUMN_EDITED,
+ G_TYPE_OBJECT,
+ G_SIGNAL_RUN_CLEANUP,
+ G_CALLBACK( free_column_edited_callback ),
+ NULL,
+ NULL,
+ nact_marshal_VOID__POINTER_POINTER_INT,
+ G_TYPE_NONE,
+ 3,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER,
+ G_TYPE_INT );
+
st_initialized = TRUE;
}
}
@@ -322,11 +346,24 @@ interface_base_init( NactIActionsListInterface *klass )
static void
free_items_callback( NactIActionsList *instance, GList *items )
{
- g_debug( "free_items_callback: selection=%p (%d items)", ( void * ) items, g_list_length( items ));
+ g_debug( "nact_iactions_list_free_items_callback: selection=%p (%d items)",
+ ( void * ) items, g_list_length( items ));
+
na_object_free_items_list( items );
}
static void
+free_column_edited_callback( NactIActionsList *instance, NAObject *object, gchar *text, gint column )
+{
+ static const gchar *thisfn = "nact_iactions_list_free_column_edited_callback";
+
+ g_debug( "%s: instance=%p, object=%p (%s), text=%s, column=%d",
+ thisfn, ( void * ) instance, ( void * ) object, G_OBJECT_TYPE_NAME( object ), text, column );
+
+ g_free( text );
+}
+
+static void
interface_base_finalize( NactIActionsListInterface *klass )
{
static const gchar *thisfn = "nact_iactions_list_interface_base_finalize";
@@ -395,6 +432,7 @@ nact_iactions_list_initial_load_toplevel( NactIActionsList *instance )
gtk_tree_view_column_set_title( column, _( "Label" ));
gtk_tree_view_column_set_sort_column_id( column, IACTIONS_LIST_LABEL_COLUMN );
renderer = gtk_cell_renderer_text_new();
+ g_object_set( G_OBJECT( renderer ), "editable", TRUE, NULL );
gtk_tree_view_column_pack_start( column, renderer, TRUE );
gtk_tree_view_column_set_cell_data_func(
column, renderer, ( GtkTreeCellDataFunc ) display_label, instance, NULL );
@@ -420,6 +458,8 @@ nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GList *ite
gboolean is_proxy;
GtkTreeSelection *selection;
IActionsListInstanceData *ialid;
+ GtkTreeViewColumn *column;
+ GList *renderers;
g_debug( "%s: instance=%p, items=%p (%d items)",
thisfn, ( void * ) instance, ( void * ) items, g_list_length( items ));
@@ -490,6 +530,15 @@ nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance, GList *ite
"focus-out-event",
G_CALLBACK( on_focus_out ));
+ /* label edition: inform the corresponding tab */
+ column = gtk_tree_view_get_column( treeview, IACTIONS_LIST_LABEL_COLUMN );
+ renderers = gtk_tree_view_column_get_cell_renderers( column );
+ base_window_signal_connect(
+ BASE_WINDOW( instance ),
+ G_OBJECT( renderers->data ),
+ "edited",
+ G_CALLBACK( on_label_edited ));
+
/* records NactIActionsList as a proxy for edition status
* modification */
is_proxy = is_iduplicable_proxy( instance, ialid );
@@ -1803,6 +1852,32 @@ on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIActionsList *i
}
/*
+ * path: path of the edited row, as a string
+ * text: new text
+ *
+ * - inform tabs so that they can update their fields
+ * data = object_at_row + new_label
+ * this will trigger set the object content, and other updates
+ */
+static void
+on_label_edited( GtkCellRendererText *renderer, const gchar *path_str, const gchar *text, NactIActionsList *instance )
+{
+ GtkTreeView *treeview;
+ NactTreeModel *model;
+ NAObject *object;
+ GtkTreePath *path;
+ gchar *new_text;
+
+ treeview = get_actions_list_treeview( instance );
+ model = NACT_TREE_MODEL( gtk_tree_view_get_model( treeview ));
+ path = gtk_tree_path_new_from_string( path_str );
+ object = nact_tree_model_object_at_path( model, path );
+ new_text = g_strdup( text );
+
+ g_signal_emit_by_name( instance, IACTIONS_LIST_SIGNAL_COLUMN_EDITED, object, new_text, IACTIONS_LIST_LABEL_COLUMN );
+}
+
+/*
* this is our handler of "changed" signal emitted by the treeview
* it is inhibited while filling the list (usually only at runtime init)
* and while deleting a selection
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index 443e43a..f8c0347 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -107,6 +107,7 @@ typedef struct {
#define IACTIONS_LIST_SIGNAL_SELECTION_CHANGED "nact-iactions-list-selection-changed"
#define IACTIONS_LIST_SIGNAL_FOCUS_IN "nact-iactions-list-focus-in"
#define IACTIONS_LIST_SIGNAL_FOCUS_OUT "nact-iactions-list-focus-out"
+#define IACTIONS_LIST_SIGNAL_COLUMN_EDITED "nact-iactions-list-column-edited"
/* management modes
* - edition: dnd, filter, multiple selection, item updated signal
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index bd2609c..ab8fc87 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -43,6 +43,7 @@
#include "base-iprefs.h"
#include "nact-application.h"
#include "nact-main-statusbar.h"
+#include "nact-iactions-list.h"
#include "nact-main-tab.h"
#include "nact-icommand-tab.h"
#include "nact-iconditions-tab.h"
@@ -72,6 +73,7 @@ static GType register_type( void );
static void interface_base_init( NactICommandTabInterface *klass );
static void interface_base_finalize( NactICommandTabInterface *klass );
+static void on_iactions_list_column_edited( NactICommandTab *instance, NAObject *object, gchar *text, gint column );
static void on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_selected );
static void check_for_label( NactICommandTab *instance, GtkEntry *entry, const gchar *label );
static GtkWidget *get_label_entry( NactICommandTab *instance );
@@ -248,6 +250,12 @@ nact_icommand_tab_runtime_init_toplevel( NactICommandTab *instance )
TAB_UPDATABLE_SIGNAL_SELECTION_CHANGED,
G_CALLBACK( on_tab_updatable_selection_changed ),
instance );
+
+ g_signal_connect(
+ G_OBJECT( instance ),
+ IACTIONS_LIST_SIGNAL_COLUMN_EDITED,
+ G_CALLBACK( on_iactions_list_column_edited ),
+ instance );
}
}
@@ -306,6 +314,22 @@ nact_icommand_tab_has_label( NactICommandTab *instance )
}
static void
+on_iactions_list_column_edited( NactICommandTab *instance, NAObject *object, gchar *text, gint column )
+{
+ GtkWidget *label_widget;
+
+ g_return_if_fail( NACT_IS_ICOMMAND_TAB( instance ));
+
+ if( st_initialized && !st_finalized ){
+
+ if( NA_IS_OBJECT_PROFILE( object )){
+ label_widget = get_label_entry( instance );
+ gtk_entry_set_text( GTK_ENTRY( label_widget ), text );
+ }
+ }
+}
+
+static void
on_tab_updatable_selection_changed( NactICommandTab *instance, gint count_selected )
{
static const gchar *thisfn = "nact_icommand_tab_on_tab_updatable_selection_changed";
diff --git a/src/nact/nact-main-statusbar.c b/src/nact/nact-main-statusbar.c
index eaa0ce2..eecf12a 100644
--- a/src/nact/nact-main-statusbar.c
+++ b/src/nact/nact-main-statusbar.c
@@ -135,5 +135,7 @@ display_timeout( StatusbarTimeoutDisplayStruct *stds )
static void
display_timeout_free( StatusbarTimeoutDisplayStruct *stds )
{
+ g_debug( "nact_main_statusbar_display_timeout_free: stds=%p", ( void * ) stds );
+
g_free( stds );
}
diff --git a/src/nact/nact-marshal.list b/src/nact/nact-marshal.list
index 11ef833..5622cff 100644
--- a/src/nact/nact-marshal.list
+++ b/src/nact/nact-marshal.list
@@ -1 +1,2 @@
VOID:INT,INT,INT
+VOID:POINTER,POINTER,INT
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 774186c..62921da 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -902,6 +902,8 @@ nact_tree_model_iter( NactTreeModel *model, FnIterOnStore fn, gpointer user_data
* @path: the #GtkTreePath to be searched.
*
* Returns: the #NAObject at the given @path if any, or NULL.
+ *
+ * The reference count of the object is not modified.
*/
NAObject *
nact_tree_model_object_at_path( NactTreeModel *model, GtkTreePath *path )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]