[nautilus-actions] Implement accelerators in Folders listview
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Implement accelerators in Folders listview
- Date: Mon, 26 Oct 2009 22:12:42 +0000 (UTC)
commit 912813f2e10a33bd08db5baef24effc2c636f7d1
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Oct 26 23:12:11 2009 +0100
Implement accelerators in Folders listview
ChangeLog | 10 ++
TODO | 1 +
src/common/na-object-profile-fn.h | 2 +
src/common/na-object-profile.c | 20 ++++
src/nact/nact-ibackground-tab.c | 194 +++++++++++++++++++++++++++++------
src/runtime/na-object-profile-fn.h | 1 -
src/runtime/na-object-profile.c | 20 ----
7 files changed, 193 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4224c91..814256b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2009-10-26 Pierre Wieser <pwieser trychlos org>
+ * src/common/na-object-profile-fn.h:
+ * src/common/na-object-profile.c:
+ * src/runtime/na-object-profile-fn.h:
+ * src/runtime/na-object-profile.c:
+ na_object_profile_replace_folder_uri moved from runtime to common
+ library.
+
+ * src/nact/nact-ibackground-tab.c:
+ Implements F2, Insert and Del keyboard accelerators.
+
* src/nact/nact-iadvanced-tab.c (runtime_init_connect_signals):
* src/nact/nact-ibackground-tab.c
(nact_ibackground_tab_runtime_init_toplevel):
diff --git a/TODO b/TODO
index 5063ae4..2ef3978 100644
--- a/TODO
+++ b/TODO
@@ -89,3 +89,4 @@
str->action = NA_OBJECT_ACTION( na_iduplicable_get_origin( NA_IDUPLICABLE( ia->data )));
to gnome-2-28
+- gtk_list_store_insert_before doesn't work ? see ibackground-tab::insert_new_row
diff --git a/src/common/na-object-profile-fn.h b/src/common/na-object-profile-fn.h
index 5fbb6e4..e0249ae 100644
--- a/src/common/na-object-profile-fn.h
+++ b/src/common/na-object-profile-fn.h
@@ -44,6 +44,8 @@
G_BEGIN_DECLS
+void na_object_profile_replace_folder_uri( NAObjectProfile *profile, const gchar *old, const gchar *new );
+
void na_object_profile_set_scheme( NAObjectProfile *profile, const gchar *scheme, gboolean selected );
G_END_DECLS
diff --git a/src/common/na-object-profile.c b/src/common/na-object-profile.c
index c521b0d..88c2692 100644
--- a/src/common/na-object-profile.c
+++ b/src/common/na-object-profile.c
@@ -43,6 +43,26 @@
#include "na-utils.h"
/**
+ * na_object_profile_replace_folder_uri:
+ * @profile: the #NAObjectProfile to be updated.
+ * @old: the old uri.
+ * @new: the new uri.
+ *
+ * Replaces the @old URI by the @new one.
+ */
+void
+na_object_profile_replace_folder_uri( NAObjectProfile *profile, const gchar *old, const gchar *new )
+{
+ g_return_if_fail( NA_IS_OBJECT_PROFILE( profile ));
+
+ if( !profile->private->dispose_has_run ){
+
+ profile->private->folders = na_utils_remove_from_string_list( profile->private->folders, old );
+ profile->private->folders = g_slist_append( profile->private->folders, ( gpointer ) g_strdup( new ));
+ }
+}
+
+/**
* na_object_profile_set_scheme:
* @profile: the #NAObjectProfile to be updated.
* @scheme: name of the scheme.
diff --git a/src/nact/nact-ibackground-tab.c b/src/nact/nact-ibackground-tab.c
index eacd923..8b61f3a 100644
--- a/src/nact/nact-ibackground-tab.c
+++ b/src/nact/nact-ibackground-tab.c
@@ -32,6 +32,7 @@
#include <config.h>
#endif
+#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
#include <string.h>
@@ -74,6 +75,11 @@ static void on_tab_updatable_selection_changed( NactIBackgroundTab *inst
static void on_tab_updatable_enable_tab( NactIBackgroundTab *instance, NAObjectItem *item );
static gboolean tab_set_sensitive( NactIBackgroundTab *instance );
+static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIBackgroundTab *instance );
+static void inline_edition( NactIBackgroundTab *instance );
+static void insert_new_row( NactIBackgroundTab *instance );
+static void delete_row( NactIBackgroundTab *instance );
+
static void add_row( NactIBackgroundTab *instance, GtkTreeView *listview, const gchar *uri );
static void add_uri_to_folders( NactIBackgroundTab *instance, const gchar *uri );
static GtkTreeView *get_folders_treeview( NactIBackgroundTab *instance );
@@ -81,6 +87,7 @@ static void on_folder_uri_edited( GtkCellRendererText *renderer, const g
static void on_folders_selection_changed( GtkTreeSelection *selection, NactIBackgroundTab *instance );
static void on_add_folder_clicked( GtkButton *button, NactIBackgroundTab *instance );
static void on_remove_folder_clicked( GtkButton *button, NactIBackgroundTab *instance );
+static void remove_uri_from_folders( NactIBackgroundTab *instance, const gchar *uri );
static void reset_folders( NactIBackgroundTab *instance );
static void setup_folders( NactIBackgroundTab *instance );
static void treeview_cell_edited( NactIBackgroundTab *instance, const gchar *path_string, const gchar *text, gint column, gchar **old_text );
@@ -160,6 +167,7 @@ nact_ibackground_tab_initial_load_toplevel( NactIBackgroundTab *instance )
GtkListStore *model;
GtkTreeViewColumn *column;
GtkCellRenderer *text_cell;
+ GtkTreeSelection *selection;
g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
@@ -182,6 +190,9 @@ nact_ibackground_tab_initial_load_toplevel( NactIBackgroundTab *instance )
gtk_tree_view_append_column( listview, column );
gtk_tree_view_set_headers_visible( listview, FALSE );
+
+ selection = gtk_tree_view_get_selection( listview );
+ gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
}
}
@@ -239,6 +250,12 @@ nact_ibackground_tab_runtime_init_toplevel( NactIBackgroundTab *instance )
G_OBJECT( gtk_tree_view_get_selection( listview )),
"changed",
G_CALLBACK( on_folders_selection_changed ));
+
+ base_window_signal_connect(
+ BASE_WINDOW( instance ),
+ G_OBJECT( listview ),
+ "key-press-event",
+ G_CALLBACK( on_key_pressed_event ));
}
}
@@ -332,6 +349,134 @@ tab_set_sensitive( NactIBackgroundTab *instance )
return( enable_tab );
}
+static gboolean
+on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIBackgroundTab *instance )
+{
+ gboolean stop = FALSE;
+
+ if( event->keyval == GDK_F2 ){
+ inline_edition( instance );
+ stop = TRUE;
+ }
+
+ if( event->keyval == GDK_Insert || event->keyval == GDK_KP_Insert ){
+ insert_new_row( instance );
+ stop = TRUE;
+ }
+
+ if( event->keyval == GDK_Delete || event->keyval == GDK_KP_Delete ){
+ delete_row( instance );
+ stop = TRUE;
+ }
+
+ return( stop );
+}
+
+static void
+inline_edition( NactIBackgroundTab *instance )
+{
+ GtkTreeView *listview;
+ GtkTreeSelection *selection;
+ GList *listrows;
+ GtkTreePath *path;
+ GtkTreeViewColumn *column;
+
+ listview = get_folders_treeview( instance );
+ selection = gtk_tree_view_get_selection( listview );
+ listrows = gtk_tree_selection_get_selected_rows( selection, NULL );
+
+ if( g_list_length( listrows ) == 1 ){
+ path = ( GtkTreePath * ) listrows->data;
+ column = gtk_tree_view_get_column( listview, BACKGROUND_URI_COLUMN );
+ gtk_tree_view_set_cursor( listview, path, column, TRUE );
+ }
+
+ g_list_foreach( listrows, ( GFunc ) gtk_tree_path_free, NULL );
+ g_list_free( listrows );
+}
+
+static void
+insert_new_row( NactIBackgroundTab *instance )
+{
+ GtkTreeView *listview;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ GList *listrows;
+ GtkTreePath *path;
+ GtkTreeIter iter, sibling;
+ gboolean inserted;
+ const gchar *uri = "file:///";
+
+ listview = get_folders_treeview( instance );
+ model = gtk_tree_view_get_model( listview );
+ selection = gtk_tree_view_get_selection( listview );
+ listrows = gtk_tree_selection_get_selected_rows( selection, NULL );
+ inserted = FALSE;
+
+ if( g_list_length( listrows ) == 1 ){
+ path = ( GtkTreePath * ) listrows->data;
+ if( gtk_tree_model_get_iter( model, &sibling, path )){
+ /* though the path of sibling is correct, the new row is always
+ * inserted at path=0 !
+ */
+ /*g_debug( "insert_new_row: sibling=%s", gtk_tree_model_get_string_from_iter( &sibling ));*/
+ gtk_list_store_insert_before( GTK_LIST_STORE( model ), &iter, &sibling );
+ inserted = TRUE;
+ }
+ }
+
+ if( !inserted ){
+ gtk_list_store_append( GTK_LIST_STORE( model ), &iter );
+ }
+
+ path = gtk_tree_model_get_path( model, &iter );
+ gtk_tree_view_set_cursor( listview, path, NULL, FALSE );
+ gtk_list_store_set( GTK_LIST_STORE( model ), &iter, BACKGROUND_URI_COLUMN, uri, -1 );
+ add_uri_to_folders( instance, uri );
+ gtk_tree_path_free( path );
+
+ g_list_foreach( listrows, ( GFunc ) gtk_tree_path_free, NULL );
+ g_list_free( listrows );
+
+ inline_edition( instance );
+}
+
+static void
+delete_row( NactIBackgroundTab *instance )
+{
+ GtkTreeView *listview;
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ GList *rows;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ gchar *uri;
+
+ listview = get_folders_treeview( instance );
+ model = gtk_tree_view_get_model( listview );
+ selection = gtk_tree_view_get_selection( listview );
+ rows = gtk_tree_selection_get_selected_rows( selection, NULL );
+
+ if( g_list_length( rows ) == 1 ){
+ path = ( GtkTreePath * ) rows->data;
+ gtk_tree_model_get_iter( model, &iter, path );
+ gtk_tree_model_get( model, &iter, BACKGROUND_URI_COLUMN, &uri, -1 );
+
+ gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
+ remove_uri_from_folders( instance, uri );
+ g_free( uri );
+
+ if( gtk_tree_model_get_iter( model, &iter, path ) ||
+ gtk_tree_path_prev( path )){
+
+ gtk_tree_view_set_cursor( listview, path, NULL, FALSE );
+ }
+ }
+
+ g_list_foreach( rows, ( GFunc ) gtk_tree_path_free, NULL );
+ g_list_free( rows );
+}
+
static void
add_row( NactIBackgroundTab *instance, GtkTreeView *listview, const gchar *uri )
{
@@ -450,46 +595,27 @@ on_folders_selection_changed( GtkTreeSelection *selection, NactIBackgroundTab *i
static void
on_remove_folder_clicked( GtkButton *button, NactIBackgroundTab *instance )
{
- GtkTreeView *listview;
- GtkTreeModel *model;
- GtkTreeSelection *selection;
- GList *selected_path, *isp;
- GtkTreePath *path;
- GtkTreeIter iter;
- gchar *uri;
- NAObjectAction *action;
+ delete_row( instance );
+}
+
+static void
+remove_uri_from_folders( NactIBackgroundTab *instance, const gchar *uri )
+{
NAObjectProfile *edited;
GSList *folders;
- listview = get_folders_treeview( instance );
- model = gtk_tree_view_get_model( listview );
- selection = gtk_tree_view_get_selection( listview );
- selected_path = gtk_tree_selection_get_selected_rows( selection, NULL );
-
- for( isp = selected_path ; isp ; isp = isp->next ){
- path = ( GtkTreePath * ) isp->data;
- gtk_tree_model_get_iter( model, &iter, path );
- gtk_tree_model_get( model, &iter, BACKGROUND_URI_COLUMN, &uri, -1 );
- gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
-
- g_object_get(
- G_OBJECT( instance ),
- TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
- TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
- NULL );
-
- folders = na_object_profile_get_folders( edited );
- folders = na_utils_remove_from_string_list( folders, uri );
- na_object_profile_set_folders( edited, folders );
+ g_object_get(
+ G_OBJECT( instance ),
+ TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
+ NULL );
- na_utils_free_string_list( folders );
- g_free( uri );
+ folders = na_object_profile_get_folders( edited );
+ folders = na_utils_remove_from_string_list( folders, uri );
+ na_object_profile_set_folders( edited, folders );
- g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
- }
+ na_utils_free_string_list( folders );
- g_list_foreach( selected_path, ( GFunc ) gtk_tree_path_free, NULL );
- g_list_free( selected_path );
+ g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
}
static void
diff --git a/src/runtime/na-object-profile-fn.h b/src/runtime/na-object-profile-fn.h
index 6a74373..c873d1d 100644
--- a/src/runtime/na-object-profile-fn.h
+++ b/src/runtime/na-object-profile-fn.h
@@ -76,7 +76,6 @@ void na_object_profile_set_isdir( NAObjectProfile *profile, gboolean
void na_object_profile_set_isfiledir( NAObjectProfile *profile, gboolean isfile, gboolean isdir );
void na_object_profile_set_multiple( NAObjectProfile *profile, gboolean multiple );
void na_object_profile_set_schemes( NAObjectProfile *profile, GSList *schemes );
-void na_object_profile_replace_folder_uri( NAObjectProfile *profile, const gchar *old, const gchar *new );
void na_object_profile_set_folders( NAObjectProfile *profile, GSList *folders );
gboolean na_object_profile_is_candidate( const NAObjectProfile *profile, gint target, GList *files );
diff --git a/src/runtime/na-object-profile.c b/src/runtime/na-object-profile.c
index f570762..f440e69 100644
--- a/src/runtime/na-object-profile.c
+++ b/src/runtime/na-object-profile.c
@@ -923,26 +923,6 @@ na_object_profile_set_schemes( NAObjectProfile *profile, GSList *schemes )
}
/**
- * na_object_profile_replace_folder_uri:
- * @profile: the #NAObjectProfile to be updated.
- * @old: the old uri.
- * @new: the new uri.
- *
- * Replaces the @old URI by the @new one.
- */
-void
-na_object_profile_replace_folder_uri( NAObjectProfile *profile, const gchar *old, const gchar *new )
-{
- g_return_if_fail( NA_IS_OBJECT_PROFILE( profile ));
-
- if( !profile->private->dispose_has_run ){
-
- profile->private->folders = na_utils_remove_from_string_list( profile->private->folders, old );
- profile->private->folders = g_slist_append( profile->private->folders, ( gpointer ) new );
- }
-}
-
-/**
* na_object_profile_set_folders:
* @profile: the #NAObjectProfile to be updated.
* @folders: list of folders which apply.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]