[nautilus-actions] Have a statefull menu for notebook tabs position
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Have a statefull menu for notebook tabs position
- Date: Wed, 15 Feb 2017 22:45:00 +0000 (UTC)
commit 68b55a39b8beed120f3e6784a69e316834bbd538
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Sep 7 12:36:03 2015 +0200
Have a statefull menu for notebook tabs position
src/nact/nact-menu-view.c | 129 +++++++++++++++++++++++--
src/nact/nact-menu-view.h | 4 +
src/nact/nact-menu.c | 86 ++++++++++++-----
src/nact/nautilus-actions-config-tool.actions | 18 ++--
4 files changed, 198 insertions(+), 39 deletions(-)
---
diff --git a/src/nact/nact-menu-view.c b/src/nact/nact-menu-view.c
index 237615f..f8e5f58 100644
--- a/src/nact/nact-menu-view.c
+++ b/src/nact/nact-menu-view.c
@@ -32,6 +32,7 @@
#endif
#include "core/na-gtk-utils.h"
+#include "core/na-iprefs.h"
#include "nact-main-window.h"
#include "nact-menu.h"
@@ -57,24 +58,45 @@ static sToolbarProps st_toolbar_props[] = {
static const gchar *st_toolbar_ui = PKGUIDIR "/nact-toolbar.ui";
-static void setup_toolbars_submenu( NactMainWindow *window );
-static void setup_toolbar( NactMainWindow *window, GtkBuilder *builder, guint toolbar_id );
-static sToolbarProps *get_toolbar_properties_by_id( guint toolbar_id );
-static sToolbarProps *get_toolbar_properties_by_name( const gchar *action_name );
+/* associates the target string (from the XML ui definition)
+ * to the desired GTK_POS
+ */
+typedef struct {
+ const gchar *target;
+ guint pos;
+}
+ sNotebookTabsProps;
+
+static sNotebookTabsProps st_notebook_tabs_props[] = {
+ { "top", GTK_POS_TOP },
+ { "right", GTK_POS_RIGHT },
+ { "bottom", GTK_POS_BOTTOM },
+ { "left", GTK_POS_LEFT },
+};
+
+static void setup_toolbars_submenu( NactMainWindow *window );
+static void setup_toolbar( NactMainWindow *window, GtkBuilder *builder, guint toolbar_id );
+static sToolbarProps *get_toolbar_properties_by_id( guint toolbar_id );
+static sToolbarProps *get_toolbar_properties_by_name( const gchar *action_name );
#if 0
-static void reorder_toolbars( GtkWidget *hbox, sToolbarProps *props );
+static void reorder_toolbars( GtkWidget *hbox, sToolbarProps *props );
#endif
+static void setup_notebook_tab_position_submenu( NactMainWindow *window );
+static sNotebookTabsProps *get_notebook_tabs_properties_by_target( const gchar *target );
+static sNotebookTabsProps *get_notebook_tabs_properties_by_pos( guint pos );
+void set_notebook_tabs_position( NactMainWindow *main_window, guint pos );
/**
* nact_menu_view_init:
* @window: the #NactMainWindow main window.
*
- * Update sensitivity of items of the View menu.
+ * Setup the toolbars menu at creation time.
*/
void
nact_menu_view_init( NactMainWindow *window )
{
setup_toolbars_submenu( window );
+ setup_notebook_tab_position_submenu( window );
}
/**
@@ -245,6 +267,32 @@ reorder_toolbars( GtkWidget *hbox, sToolbarProps *props )
#endif
/*
+ * Setup the initial display of the notebook tabs labels.
+ *
+ * ***
+ * This actually only setup the initial state of the toggle options in
+ * View > Toolbars menu; when an option is activated, this will trigger
+ * the 'on_view_toolbar_activated()' which will actually display the
+ * toolbar.
+ * ***
+ */
+void
+setup_notebook_tab_position_submenu( NactMainWindow *window )
+{
+ guint pos;
+ sNotebookTabsProps *props;
+ GAction *action;
+
+ pos = na_iprefs_get_tabs_pos( NULL );
+ props = get_notebook_tabs_properties_by_pos( pos );
+ g_return_if_fail( props );
+
+ action = g_action_map_lookup_action( G_ACTION_MAP( window ), "tab-position" );
+ g_action_change_state( action, g_variant_new_string( props->target ));
+}
+
+#if 0
+/*
* When activating one of the GtkRadioAction which handles the position
* of the notebook tabs
* @action: the first GtkRadioAction of the group
@@ -254,7 +302,6 @@ reorder_toolbars( GtkWidget *hbox, sToolbarProps *props )
* the menu, after having set the "current_value" to the new value. All
* GtkRadioButtons items share the same "current_value".
*/
-#if 0
void
nact_menu_view_on_tabs_pos_changed( GtkRadioAction *action, GtkRadioAction *current, BaseWindow *window )
{
@@ -266,3 +313,71 @@ nact_menu_view_on_tabs_pos_changed( GtkRadioAction *action, GtkRadioAction *curr
gtk_notebook_set_tab_pos( notebook, new_pos );
}
#endif
+
+/**
+ * nact_menu_view_notebook_tab_display:
+ * @main_window: the #NactMainWindow main window.
+ * @action_name: the action name.
+ * @target: the targeted position.
+ */
+void
+nact_menu_view_notebook_tab_display( NactMainWindow *main_window, const gchar *action_name, const gchar
*target )
+{
+ sNotebookTabsProps *props;
+
+ props = get_notebook_tabs_properties_by_target( target );
+ g_return_if_fail( props );
+ set_notebook_tabs_position( main_window, props->pos );
+}
+
+/*
+ * returns the sNotebookTabsProperties structure for the specified target
+ * which should be top, right, bottom or left
+ */
+static sNotebookTabsProps *
+get_notebook_tabs_properties_by_target( const gchar *target )
+{
+ static const gchar *thisfn = "nact_menu_view_get_notebook_tabs_properties_by_target";
+ guint i;
+
+ for( i=0 ; i<G_N_ELEMENTS( st_notebook_tabs_props ) ; ++i ){
+ if( g_utf8_collate( st_notebook_tabs_props[i].target, target ) == 0 ){
+ return( &st_notebook_tabs_props[i] );
+ }
+ }
+
+ g_warning( "%s: unable to find properties for target=%s", thisfn, target );
+ return( NULL );
+}
+
+/*
+ * returns the sNotebookTabsProperties structure for the specified position
+ */
+static sNotebookTabsProps *
+get_notebook_tabs_properties_by_pos( guint pos )
+{
+ static const gchar *thisfn = "nact_menu_view_get_notebook_tabs_properties_by_pos";
+ guint i;
+
+ for( i=0 ; i<G_N_ELEMENTS( st_notebook_tabs_props ) ; ++i ){
+ if( st_notebook_tabs_props[i].pos == pos ){
+ return( &st_notebook_tabs_props[i] );
+ }
+ }
+
+ g_warning( "%s: unable to find properties for pos=%u", thisfn, pos );
+ return( NULL );
+}
+
+/*
+ * Set the position of the main notebook tabs
+ */
+void
+set_notebook_tabs_position( NactMainWindow *main_window, guint pos )
+{
+ GtkNotebook *notebook;
+
+ notebook = GTK_NOTEBOOK( na_gtk_utils_find_widget_by_name( GTK_CONTAINER( main_window ),
"main-notebook" ));
+ gtk_notebook_set_tab_pos( notebook, pos );
+ na_iprefs_set_tabs_pos( pos );
+}
diff --git a/src/nact/nact-menu-view.h b/src/nact/nact-menu-view.h
index 90efa7b..c0ef0b5 100644
--- a/src/nact/nact-menu-view.h
+++ b/src/nact/nact-menu-view.h
@@ -49,6 +49,10 @@ void nact_menu_view_toolbar_display ( NactMainWindow *main_window,
const gchar
*action_name,
gboolean
visible );
+void nact_menu_view_notebook_tab_display( NactMainWindow *main_window,
+ const gchar
*action_name,
+ const gchar
*target );
+
void nact_menu_view_set_notebook_label ( NactMainWindow *main_window );
G_END_DECLS
diff --git a/src/nact/nact-menu.c b/src/nact/nact-menu.c
index b7e9845..18414b1 100644
--- a/src/nact/nact-menu.c
+++ b/src/nact/nact-menu.c
@@ -78,6 +78,8 @@ static void on_win_save( GSimpleAction *action, GVariant *parameter, gpointer us
static void on_win_test_function( GSimpleAction *action, GVariant *parameter, gpointer user_data );
static void on_win_toolbar_activate( GSimpleAction *action, GVariant *parameter, gpointer user_data );
static void on_win_toolbar_changed_state( GSimpleAction *action, GVariant *parameter, gpointer user_data );
+static void on_win_notebook_tab_position_activate( GSimpleAction *action, GVariant *parameter, gpointer
user_data );
+static void on_win_notebook_tab_position_changed_state( GSimpleAction *action, GVariant *parameter, gpointer
user_data );
/* since the deprecation of GtkAction, I no more know how to display
* menu item tooltips - but they have been translated and I don't want
@@ -90,58 +92,58 @@ typedef struct {
sActionEntry;
static sActionEntry st_app_entries[] = {
- {{ "about", on_app_about, NULL, NULL, NULL },
+ {{ "about", on_app_about },
/* i18n: status bar tooltip displayed on 'About' item navigation */
N_( "Display informations about this program" )},
- {{ "help", on_app_help, NULL, NULL, NULL },
+ {{ "help", on_app_help },
/* i18n: status bar tooltip displayed on 'Help' item navigation */
N_( "Display help about this program" )},
- {{ "preferences", on_app_preferences, NULL, NULL, NULL },
+ {{ "preferences", on_app_preferences },
/* i18n: status bar tooltip displayed on 'Preferences' item navigation */
N_( "Edit your preferences" )},
- {{ "quit", on_app_quit, NULL, NULL, NULL },
+ {{ "quit", on_app_quit },
/* i18n: status bar tooltip displayed on 'Quit' item navigation */
N_( "Quit the application" )},
};
static sActionEntry st_menubar_entries[] = {
- {{ "new-menu", on_win_new_menu, NULL, NULL, NULL },
+ {{ "new-menu", on_win_new_menu },
/* i18n: status bar tooltip displayed on 'New menu' item navigation */
N_( "Insert a new menu at the current position" )},
- {{ "new-action", on_win_new_action, NULL, NULL, NULL },
+ {{ "new-action", on_win_new_action },
/* i18n: status bar tooltip displayed on 'New action' item navigation */
N_( "Define a new action" )},
- {{ "new-profile", on_win_new_profile, NULL, NULL, NULL },
+ {{ "new-profile", on_win_new_profile },
/* i18n: status bar tooltip displayed on 'New profile' item navigation */
N_( "Define a new profile attached to the current action" )},
- {{ "save", on_win_save, NULL, NULL, NULL },
+ {{ "save", on_win_save },
/* i18n: status bar tooltip displayed on 'Save' item navigation */
N_( "Record all the modified actions. Invalid actions will be silently
ignored" )},
- {{ "cut", on_win_cut, NULL, NULL, NULL },
+ {{ "cut", on_win_cut },
/* i18n: status bar tooltip displayed on 'Cut' item navigation */
N_( "Cut the selected item(s) to the clipboard" )},
- {{ "copy", on_win_copy, NULL, NULL, NULL },
+ {{ "copy", on_win_copy },
/* i18n: status bar tooltip displayed on 'Copy' item navigation */
N_( "Copy the selected item(s) to the clipboard" )},
- {{ "paste", on_win_paste, NULL, NULL, NULL },
+ {{ "paste", on_win_paste },
/* i18n: status bar tooltip displayed on 'Paste' item navigation */
N_( "Insert the content of the clipboard just before the current position" )},
- {{ "paste-into", on_win_paste_into, NULL, NULL, NULL },
+ {{ "paste-into", on_win_paste_into },
/* i18n: status bar tooltip displayed on 'Paste into' item navigation */
N_( "Insert the content of the clipboard as first child of the current item"
)},
- {{ "duplicate", on_win_duplicate, NULL, NULL, NULL },
+ {{ "duplicate", on_win_duplicate },
/* i18n: status bar tooltip displayed on 'Duplicate' item navigation */
N_( "Duplicate the selected item(s)" )},
- {{ "delete", on_win_delete, NULL, NULL, NULL },
+ {{ "delete", on_win_delete },
/* i18n: status bar tooltip displayed on 'Delete' item navigation */
N_( "Delete the selected item(s)" )},
- {{ "reload", on_win_reload, NULL, NULL, NULL },
+ {{ "reload", on_win_reload },
/* i18n: status bar tooltip displayed on 'Reload items' item navigation */
N_( "Cancel your current modifications and reload the initial list of menus
and actions" )},
- {{ "expand", on_win_expand_all, NULL, NULL, NULL },
+ {{ "expand", on_win_expand_all },
/* i18n: status bar tooltip displayed on 'Expand all' item navigation */
N_( "Entirely expand the items hierarchy" )},
- {{ "collapse", on_win_collapse_all, NULL, NULL, NULL },
+ {{ "collapse", on_win_collapse_all },
/* i18n: status bar tooltip displayed on 'Collapse all' item navigation */
N_( "Entirely collapse the items hierarchy" )},
{{ "toolbar-file", on_win_toolbar_activate, NULL, "false", on_win_toolbar_changed_state },
@@ -156,21 +158,24 @@ static sActionEntry st_menubar_entries[] = {
{{ "toolbar-help", on_win_toolbar_activate, NULL, "false", on_win_toolbar_changed_state },
/* i18n: status bar tooltip displayed on 'Toolbars/Help' item navigation */
N_( "Display the Help toolbar" )},
- {{ "import", on_win_import, NULL, NULL, NULL },
+ {{ "tab-position", on_win_notebook_tab_position_activate, "s", "string 'left'",
on_win_notebook_tab_position_changed_state },
+ /* i18n: status bar tooltip displayed on 'Notebook labels' items navigation */
+ N_( "Switch the position of the notebook tabs" )},
+ {{ "import", on_win_import },
/* i18n: status bar tooltip displayed on 'Import' item navigation */
N_( "Import one or more actions from external files into your configuration"
)},
- {{ "export", on_win_export, NULL, NULL, NULL },
+ {{ "export", on_win_export },
/* i18n: status bar tooltip displayed on 'Export' item navigation */
N_( "Export one or more actions from your configuration to external files" )},
- {{ "dump-selection", on_win_dump_selection, NULL, NULL, NULL },
+ {{ "dump-selection", on_win_dump_selection },
"Recursively dump selected items" },
- {{ "tree-store-dump", on_win_brief_tree_store_dump, NULL, NULL, NULL },
+ {{ "tree-store-dump", on_win_brief_tree_store_dump },
"Briefly dump the tree store" },
- {{ "list-modified", on_win_list_modified_items, NULL, NULL, NULL },
+ {{ "list-modified", on_win_list_modified_items },
"List the modified item(s)" },
- {{ "dump-clipboard", on_win_dump_clipboard, NULL, NULL, NULL },
+ {{ "dump-clipboard", on_win_dump_clipboard },
"Dump the content of the clipboard object" },
- {{ "fntest", on_win_test_function, NULL, NULL, NULL },
+ {{ "fntest", on_win_test_function },
"Test a function (see nact-menubar-maintainer.c" },
};
@@ -364,7 +369,8 @@ nact_menu_win( NactMainWindow *main_window )
/* install autosave */
nact_menu_file_init( main_window );
- /* install toolbar submenu */
+ /* install toolbar submenu
+ * + notebook labels position submenu */
nact_menu_view_init( main_window );
}
@@ -837,6 +843,36 @@ on_win_toolbar_changed_state( GSimpleAction *action, GVariant *state, gpointer u
g_simple_action_set_state( action, state );
}
+/*
+ * the menu item is activated
+ * just toggle the state of the corresponding action
+ */
+static void
+on_win_notebook_tab_position_activate( GSimpleAction *action, GVariant *parameter, gpointer user_data )
+{
+ g_return_if_fail( user_data && NACT_IS_MAIN_WINDOW( user_data ));
+
+ g_action_change_state( G_ACTION( action ),
+ g_variant_new_string( g_variant_get_string( parameter, NULL )));
+}
+
+/*
+ * the state of the action has been toggled, either directly or by
+ * activating the menu item
+ */
+static void
+on_win_notebook_tab_position_changed_state( GSimpleAction *action, GVariant *state, gpointer user_data )
+{
+ g_return_if_fail( user_data && NACT_IS_MAIN_WINDOW( user_data ));
+
+ nact_menu_view_notebook_tab_display(
+ NACT_MAIN_WINDOW( user_data ),
+ g_action_get_name( G_ACTION( action )),
+ g_variant_get_string( state, NULL ));
+
+ g_simple_action_set_state( action, state );
+}
+
/**
* nact_menu_enable_item:
* @main_window: this #NactMainWindow main window.
diff --git a/src/nact/nautilus-actions-config-tool.actions b/src/nact/nautilus-actions-config-tool.actions
index f0a8366..c8086ad 100644
--- a/src/nact/nautilus-actions-config-tool.actions
+++ b/src/nact/nautilus-actions-config-tool.actions
@@ -131,20 +131,24 @@
<attribute name="label" translatable="yes">_Notebook labels</attribute>
<section>
<item>
- <attribute name="label" translatable="yes">_Left</attribute>
- <attribute name="action">win.tab-left</attribute>
+ <attribute name="label" translatable="yes">_Top</attribute>
+ <attribute name="action">win.tab-position</attribute>
+ <attribute name="target">top</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Right</attribute>
- <attribute name="action">win.tab-right</attribute>
+ <attribute name="action">win.tab-position</attribute>
+ <attribute name="target">right</attribute>
</item>
<item>
- <attribute name="label" translatable="yes">_Top</attribute>
- <attribute name="action">win.tab-top</attribute>
+ <attribute name="label" translatable="yes">_Bottom</attribute>
+ <attribute name="action">win.tab-position</attribute>
+ <attribute name="target">bottom</attribute>
</item>
<item>
- <attribute name="label" translatable="yes">_Bottom</attribute>
- <attribute name="action">win.tab-bottom</attribute>
+ <attribute name="label" translatable="yes">_Left</attribute>
+ <attribute name="action">win.tab-position</attribute>
+ <attribute name="target">left</attribute>
</item>
</section>
</submenu>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]