[nautilus-actions] Focus on tab



commit 4be234a70d4365042e74a630aa3239311f895c76
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jul 31 22:56:07 2009 +0200

    Focus on tab

 src/nact/nact-iaction-tab.c              |   45 ++++++++++++++++++++++++++++++
 src/nact/nact-iaction-tab.h              |    1 +
 src/nact/nact-iadvanced-tab.c            |   30 ++++++++++++++++++++
 src/nact/nact-iadvanced-tab.h            |    1 +
 src/nact/nact-icommand-tab.c             |   30 ++++++++++++++++++++
 src/nact/nact-icommand-tab.h             |    1 +
 src/nact/nact-iconditions-tab.c          |   30 ++++++++++++++++++++
 src/nact/nact-iconditions-tab.h          |    1 +
 src/nact/nact-main-window.c              |    5 +++
 src/nact/nact-main-window.h              |    7 ++++
 src/nact/nautilus-actions-config-tool.ui |   13 +++++---
 11 files changed, 159 insertions(+), 5 deletions(-)
---
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index 032043f..aaa4e99 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -36,6 +36,7 @@
 #include <string.h>
 
 #include "nact-application.h"
+#include "nact-main-window.h"
 #include "nact-iaction-tab.h"
 
 /* private interface data
@@ -83,6 +84,8 @@ static void          hide_status( NactWindow *window );
 static guint         get_status_context( NactWindow *window );
 static void          set_status_context( NactWindow *window, guint context );
 
+static void          on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window );
+static gboolean      on_focus_in( GtkWidget *widget, GdkEventFocus *event, NactWindow *window );
 GType
 nact_iaction_tab_get_type( void )
 {
@@ -177,14 +180,20 @@ nact_iaction_tab_runtime_init( NactWindow *dialog )
 	static const gchar *thisfn = "nact_iaction_tab_runtime_init";
 	g_debug( "%s: dialog=%p", thisfn, dialog );
 
+	GtkWidget *notebook = base_window_get_widget( BASE_WINDOW( dialog ), "MainNotebook" );
+	nact_window_signal_connect( dialog, G_OBJECT( notebook ), "switch-page", G_CALLBACK( on_switch_page ));
+
 	GtkWidget *label_widget = base_window_get_widget( BASE_WINDOW( dialog ), "ActionLabelEntry" );
 	nact_window_signal_connect( dialog, G_OBJECT( label_widget ), "changed", G_CALLBACK( on_label_changed ));
+	nact_window_signal_connect( dialog, G_OBJECT( label_widget ), "focus-in-event", G_CALLBACK( on_focus_in ));
 
 	GtkWidget *tooltip_widget = base_window_get_widget( BASE_WINDOW( dialog ), "ActionTooltipEntry" );
 	nact_window_signal_connect( dialog, G_OBJECT( tooltip_widget ), "changed", G_CALLBACK( on_tooltip_changed ));
+	nact_window_signal_connect( dialog, G_OBJECT( tooltip_widget ), "focus-in-event", G_CALLBACK( on_focus_in ));
 
 	GtkWidget *icon_widget = base_window_get_widget( BASE_WINDOW( dialog ), "ActionIconComboBoxEntry" );
 	nact_window_signal_connect( dialog, G_OBJECT( GTK_BIN( icon_widget )->child ), "changed", G_CALLBACK( on_icon_changed ));
+	nact_window_signal_connect( dialog, G_OBJECT( GTK_BIN( icon_widget )->child ), "focus-in-event", G_CALLBACK( on_focus_in ));
 
 	GtkWidget *button = base_window_get_widget( BASE_WINDOW( dialog ), "ActionIconBrowseButton" );
 	nact_window_signal_connect( dialog, G_OBJECT( button ), "clicked", G_CALLBACK( on_icon_browse ));
@@ -210,6 +219,12 @@ nact_iaction_tab_dispose( NactWindow *dialog )
 	g_debug( "%s: dialog=%p", thisfn, dialog );
 }
 
+void
+nact_iaction_tab_reset_last_focus( NactWindow *dialog )
+{
+	g_object_set_data( G_OBJECT( dialog ), "nact-iaction-tab-last-focus", NULL );
+}
+
 /*
  * disable the tab if current row is a profile and the action has more
  * than one profile
@@ -631,3 +646,33 @@ set_status_context( NactWindow *window, guint context )
 {
 	g_object_set_data( G_OBJECT( window ), PROP_IACTION_TAB_STATUS_CONTEXT, GUINT_TO_POINTER( context ));
 }
+
+/*
+ * this callback is triggered once when we enter the page (page_num = 0..n)
+ * all tabs which are connected to this signal are triggered with same parameters
+ * at runtime initialization, we are not triggered when page 0 is displayed
+ * (or we are connecting too late ?)
+ */
+static void
+on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window )
+{
+	static const gchar *thisfn = "nact_iaction_tab_on_switch_page";
+
+	if( page_num == ACTION_TAB ){
+		g_debug( "%s: notebook=%p, page=%p, page_num=%d, window=%p", thisfn, notebook, page, page_num, window );
+		GtkWidget *widget = GTK_WIDGET( g_object_get_data( G_OBJECT( window ), "nact-iaction-tab-last-focus" ));
+		if( !widget ){
+			widget = base_window_get_widget( BASE_WINDOW( window ), "ActionLabelEntry" );
+		}
+		gtk_widget_grab_focus( widget );
+	}
+}
+
+static gboolean
+on_focus_in( GtkWidget *widget, GdkEventFocus *event, NactWindow *window )
+{
+	g_object_set_data( G_OBJECT( window ), "nact-iaction-tab-last-focus", widget );
+	gtk_label_set_mnemonic_widget( GTK_LABEL( base_window_get_widget( BASE_WINDOW( window ), "ActionTabLabel" )), widget );
+
+	return( FALSE );
+}
diff --git a/src/nact/nact-iaction-tab.h b/src/nact/nact-iaction-tab.h
index 4939879..cfc5483 100644
--- a/src/nact/nact-iaction-tab.h
+++ b/src/nact/nact-iaction-tab.h
@@ -68,6 +68,7 @@ void     nact_iaction_tab_initial_load( NactWindow *dialog );
 void     nact_iaction_tab_runtime_init( NactWindow *dialog );
 void     nact_iaction_tab_all_widgets_showed( NactWindow *dialog );
 void     nact_iaction_tab_dispose( NactWindow *dialog );
+void     nact_iaction_tab_reset_last_focus( NactWindow *dialog );
 
 void     nact_iaction_tab_set_action( NactWindow *dialog, const NAAction *action );
 gboolean nact_iaction_tab_has_label( NactWindow *window );
diff --git a/src/nact/nact-iadvanced-tab.c b/src/nact/nact-iadvanced-tab.c
index b5ee421..9fc20d7 100644
--- a/src/nact/nact-iadvanced-tab.c
+++ b/src/nact/nact-iadvanced-tab.c
@@ -37,6 +37,7 @@
 
 #include <common/na-utils.h>
 
+#include "nact-main-window.h"
 #include "nact-iadvanced-tab.h"
 #include "nact-iprefs.h"
 
@@ -78,6 +79,8 @@ static void             set_action_schemes( gchar *scheme, GtkTreeModel *model )
 static GtkButton       *get_add_button( NactWindow *window );
 static GtkButton       *get_remove_button( NactWindow *window );
 
+static void             on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window );
+
 GType
 nact_iadvanced_tab_get_type( void )
 {
@@ -163,6 +166,9 @@ nact_iadvanced_tab_runtime_init( NactWindow *dialog )
 	static const gchar *thisfn = "nact_iadvanced_tab_runtime_init";
 	g_debug( "%s: dialog=%p", thisfn, dialog );
 
+	GtkWidget *notebook = base_window_get_widget( BASE_WINDOW( dialog ), "MainNotebook" );
+	nact_window_signal_connect( dialog, G_OBJECT( notebook ), "switch-page", G_CALLBACK( on_switch_page ));
+
 	GtkTreeView *scheme_widget = get_schemes_tree_view( dialog );
 
 	GtkTreeViewColumn *column = gtk_tree_view_get_column( scheme_widget, SCHEMES_CHECKBOX_COLUMN );
@@ -200,6 +206,12 @@ nact_iadvanced_tab_dispose( NactWindow *dialog )
 }
 
 void
+nact_iadvanced_tab_reset_last_focus( NactWindow *dialog )
+{
+	g_object_set_data( G_OBJECT( dialog ), "nact-iadvanced-tab-last-focus", NULL );
+}
+
+void
 nact_iadvanced_tab_set_profile( NactWindow *dialog, NAActionProfile *profile )
 {
 	static const gchar *thisfn = "nact_iadvanced_tab_set_profile";
@@ -588,3 +600,21 @@ get_remove_button( NactWindow *window )
 {
 	return( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window ), "RemoveSchemeButton" )));
 }
+
+/*
+ * rationale: cf. nact-iaction-tab:on_swotch_page()
+ */
+static void
+on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window )
+{
+	static const gchar *thisfn = "nact_iadvanced_tab_on_switch_page";
+
+	if( page_num == ADVANCED_TAB ){
+		g_debug( "%s: notebook=%p, page=%p, page_num=%d, window=%p", thisfn, notebook, page, page_num, window );
+		GtkWidget *widget = GTK_WIDGET( g_object_get_data( G_OBJECT( window ), "nact-iadvanced-tab-last-focus" ));
+		if( !widget ){
+			widget = GTK_WIDGET( get_schemes_tree_view( window ));
+		}
+		gtk_widget_grab_focus( widget );
+	}
+}
diff --git a/src/nact/nact-iadvanced-tab.h b/src/nact/nact-iadvanced-tab.h
index 7e50656..13f69b1 100644
--- a/src/nact/nact-iadvanced-tab.h
+++ b/src/nact/nact-iadvanced-tab.h
@@ -67,6 +67,7 @@ void    nact_iadvanced_tab_initial_load( NactWindow *dialog );
 void    nact_iadvanced_tab_runtime_init( NactWindow *dialog );
 void    nact_iadvanced_tab_all_widgets_showed( NactWindow *dialog );
 void    nact_iadvanced_tab_dispose( NactWindow *dialog );
+void    nact_iadvanced_tab_reset_last_focus( NactWindow *dialog );
 
 void    nact_iadvanced_tab_set_profile( NactWindow *window, NAActionProfile *profile );
 GSList *nact_iadvanced_tab_get_schemes( NactWindow *window );
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index 70028b0..f49fecf 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -38,6 +38,7 @@
 #include <common/na-utils.h>
 
 #include "nact-application.h"
+#include "nact-main-window.h"
 #include "nact-icommand-tab.h"
 #include "nact-iprefs.h"
 
@@ -93,6 +94,8 @@ static void             hide_status( NactWindow *window );
 static guint            get_status_context( NactWindow *window );
 static void             set_status_context( NactWindow *window, guint context );
 
+static void             on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window );
+
 GType
 nact_icommand_tab_get_type( void )
 {
@@ -183,6 +186,9 @@ nact_icommand_tab_runtime_init( NactWindow *dialog )
 	static const gchar *thisfn = "nact_icommand_tab_runtime_init";
 	g_debug( "%s: dialog=%p", thisfn, dialog );
 
+	GtkWidget *notebook = base_window_get_widget( BASE_WINDOW( dialog ), "MainNotebook" );
+	nact_window_signal_connect( dialog, G_OBJECT( notebook ), "switch-page", G_CALLBACK( on_switch_page ));
+
 	GtkWidget *label_entry = get_label_entry( dialog );
 	nact_window_signal_connect( dialog, G_OBJECT( label_entry ), "changed", G_CALLBACK( on_label_changed ));
 
@@ -219,6 +225,12 @@ nact_icommand_tab_dispose( NactWindow *dialog )
 }
 
 void
+nact_icommand_tab_reset_last_focus( NactWindow *dialog )
+{
+	g_object_set_data( G_OBJECT( dialog ), "nact-icommand-tab-last-focus", NULL );
+}
+
+void
 nact_icommand_tab_set_profile( NactWindow *dialog, const NAActionProfile *profile )
 {
 	static const gchar *thisfn = "nact_icommand_tab_set_profile";
@@ -767,3 +779,21 @@ set_status_context( NactWindow *window, guint context )
 {
 	g_object_set_data( G_OBJECT( window ), PROP_ICOMMAND_TAB_STATUS_CONTEXT, GUINT_TO_POINTER( context ));
 }
+
+/*
+ * rationale: cf. nact-iaction-tab:on_swotch_page()
+ */
+static void
+on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window )
+{
+	static const gchar *thisfn = "nact_icommand_tab_on_switch_page";
+
+	if( page_num == COMMAND_TAB ){
+		g_debug( "%s: notebook=%p, page=%p, page_num=%d, window=%p", thisfn, notebook, page, page_num, window );
+		GtkWidget *widget = GTK_WIDGET( g_object_get_data( G_OBJECT( window ), "nact-icommand-tab-last-focus" ));
+		if( !widget ){
+			widget = get_label_entry( window );
+		}
+		gtk_widget_grab_focus( widget );
+	}
+}
diff --git a/src/nact/nact-icommand-tab.h b/src/nact/nact-icommand-tab.h
index 4fa8ff1..eb8e64f 100644
--- a/src/nact/nact-icommand-tab.h
+++ b/src/nact/nact-icommand-tab.h
@@ -70,6 +70,7 @@ void     nact_icommand_tab_initial_load( NactWindow *window );
 void     nact_icommand_tab_runtime_init( NactWindow *window );
 void     nact_icommand_tab_all_widgets_showed( NactWindow *window );
 void     nact_icommand_tab_dispose( NactWindow *window );
+void     nact_icommand_tab_reset_last_focus( NactWindow *dialog );
 
 void     nact_icommand_tab_set_profile( NactWindow *window, const NAActionProfile *profile );
 gboolean nact_icommand_tab_has_label( NactWindow *window );
diff --git a/src/nact/nact-iconditions-tab.c b/src/nact/nact-iconditions-tab.c
index 3c1033c..9676e19 100644
--- a/src/nact/nact-iconditions-tab.c
+++ b/src/nact/nact-iconditions-tab.c
@@ -37,6 +37,7 @@
 
 #include <common/na-utils.h>
 
+#include "nact-main-window.h"
 #include "nact-iconditions-tab.h"
 #include "nact-iprefs.h"
 
@@ -66,6 +67,8 @@ static GtkButton       *get_both_button( NactWindow *window );
 static void             on_multiple_toggled( GtkToggleButton *button, gpointer user_data );
 static GtkButton       *get_multiple_button( NactWindow *window );
 
+static void             on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window );
+
 GType
 nact_iconditions_tab_get_type( void )
 {
@@ -149,6 +152,9 @@ nact_iconditions_tab_runtime_init( NactWindow *dialog )
 	static const gchar *thisfn = "nact_iconditions_tab_runtime_init";
 	g_debug( "%s: dialog=%p", thisfn, dialog );
 
+	GtkWidget *notebook = base_window_get_widget( BASE_WINDOW( dialog ), "MainNotebook" );
+	nact_window_signal_connect( dialog, G_OBJECT( notebook ), "switch-page", G_CALLBACK( on_switch_page ));
+
 	GtkWidget *basenames_widget = get_basenames_entry( dialog );
 	nact_window_signal_connect( dialog, G_OBJECT( basenames_widget ), "changed", G_CALLBACK( on_basenames_changed ));
 
@@ -184,6 +190,12 @@ nact_iconditions_tab_dispose( NactWindow *dialog )
 }
 
 void
+nact_iconditions_tab_reset_last_focus( NactWindow *dialog )
+{
+	g_object_set_data( G_OBJECT( dialog ), "nact-iconditions-tab-last-focus", NULL );
+}
+
+void
 nact_iconditions_tab_set_profile( NactWindow *dialog, NAActionProfile *profile )
 {
 	static const gchar *thisfn = "nact_iconditions_tab_set_profile";
@@ -408,3 +420,21 @@ get_multiple_button( NactWindow *window )
 {
 	return( GTK_BUTTON( base_window_get_widget( BASE_WINDOW( window ), "ConditionsMultipleButton" )));
 }
+
+/*
+ * rationale: cf. nact-iaction-tab:on_swotch_page()
+ */
+static void
+on_switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, NactWindow *window )
+{
+	static const gchar *thisfn = "nact_iconditions_tab_on_switch_page";
+
+	if( page_num == CONDITIONS_TAB ){
+		g_debug( "%s: notebook=%p, page=%p, page_num=%d, window=%p", thisfn, notebook, page, page_num, window );
+		GtkWidget *widget = GTK_WIDGET( g_object_get_data( G_OBJECT( window ), "nact-iconditions-tab-last-focus" ));
+		if( !widget ){
+			widget = get_basenames_entry( window );
+		}
+		gtk_widget_grab_focus( widget );
+	}
+}
diff --git a/src/nact/nact-iconditions-tab.h b/src/nact/nact-iconditions-tab.h
index 664d245..5acbb47 100644
--- a/src/nact/nact-iconditions-tab.h
+++ b/src/nact/nact-iconditions-tab.h
@@ -67,6 +67,7 @@ void     nact_iconditions_tab_initial_load( NactWindow *dialog );
 void     nact_iconditions_tab_runtime_init( NactWindow *dialog );
 void     nact_iconditions_tab_all_widgets_showed( NactWindow *dialog );
 void     nact_iconditions_tab_dispose( NactWindow *dialog );
+void     nact_iconditions_tab_reset_last_focus( NactWindow *dialog );
 
 void     nact_iconditions_tab_set_profile( NactWindow *window, NAActionProfile *profile );
 void     nact_iconditions_tab_get_isfiledir( NactWindow *window, gboolean *isfile, gboolean *isdir );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 232dcca..53cc657 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -624,6 +624,11 @@ on_actions_list_selection_changed( GtkTreeSelection *selection, gpointer user_da
 	static const gchar *thisfn = "nact_main_window_on_actions_list_selection_changed";
 	g_debug( "%s: selection=%p, user_data=%p", thisfn, selection, user_data );
 
+	nact_iaction_tab_reset_last_focus( NACT_WINDOW( user_data ));
+	nact_icommand_tab_reset_last_focus( NACT_WINDOW( user_data ));
+	nact_iconditions_tab_reset_last_focus( NACT_WINDOW( user_data ));
+	nact_iadvanced_tab_reset_last_focus( NACT_WINDOW( user_data ));
+
 	g_assert( NACT_IS_MAIN_WINDOW( user_data ));
 	NactMainWindow *window = NACT_MAIN_WINDOW( user_data );
 
diff --git a/src/nact/nact-main-window.h b/src/nact/nact-main-window.h
index fa2c923..6058e9f 100644
--- a/src/nact/nact-main-window.h
+++ b/src/nact/nact-main-window.h
@@ -71,6 +71,13 @@ NactMainWindow *nact_main_window_new( BaseApplication *application );
 GSList         *nact_main_window_get_actions( const NactMainWindow *window );
 gboolean        nact_main_window_action_exists( const NactMainWindow *window, const gchar *uuid );
 
+enum {
+	ACTION_TAB = 0,
+	COMMAND_TAB,
+	CONDITIONS_TAB,
+	ADVANCED_TAB
+};
+
 G_END_DECLS
 
 #endif /* __NACT_MAIN_WINDOW_H__ */
diff --git a/src/nact/nautilus-actions-config-tool.ui b/src/nact/nautilus-actions-config-tool.ui
index 025bb77..7880cc0 100644
--- a/src/nact/nautilus-actions-config-tool.ui
+++ b/src/nact/nautilus-actions-config-tool.ui
@@ -342,7 +342,7 @@
                       </object>
                     </child>
                     <child type="tab">
-                      <object class="GtkLabel" id="label5">
+                      <object class="GtkLabel" id="ActionTabLabel">
                         <property name="visible">True</property>
                         <property name="tooltip_text" translatable="yes">This tab lets you enter main characteristics of the action, as it will be displayed in the Nautilus context menu : label, tooltip, icon.</property>
                         <property name="label" translatable="yes">_Action</property>
@@ -1011,6 +1011,9 @@ Defining several profiles lets you have several commands, each applying with a d
         <property name="select_multiple">True</property>
         <property name="use_preview_label">False</property>
         <property name="local_only">False</property>
+        <property name="preview_widget_active">False</property>
+        <property name="use_preview_label">False</property>
+        <property name="select_multiple">True</property>
       </object>
     </child>
     <child>
@@ -1721,16 +1724,16 @@ The exported file may later be imported via :
   </object>
   <object class="GtkSizeGroup" id="CommandLabelSizeGroup">
     <widgets>
-      <widget name="CommandExamplePreLabel"/>
-      <widget name="CommandParametersLabel"/>
-      <widget name="CommandPathLabel"/>
       <widget name="ProfileLabelLabel"/>
+      <widget name="CommandPathLabel"/>
+      <widget name="CommandParametersLabel"/>
+      <widget name="CommandExamplePreLabel"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="CommandButtonSizeGroup">
     <widgets>
-      <widget name="CommandLegendButton"/>
       <widget name="CommandPathButton"/>
+      <widget name="CommandLegendButton"/>
     </widgets>
   </object>
 </interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]