[nautilus-actions] MainNotebook: let the user set his preferred tabs position
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] MainNotebook: let the user set his preferred tabs position
- Date: Thu, 2 Feb 2012 21:43:13 +0000 (UTC)
commit 945cc398da66409f6c12b85655adec87fa7aa2ee
Author: Pierre Wieser <pwieser trychlos org>
Date: Thu Feb 2 19:50:11 2012 +0100
MainNotebook: let the user set his preferred tabs position
ChangeLog | 21 ++++++++
src/core/na-iprefs.c | 12 ++--
src/nact/nact-main-tab.c | 56 +++++---------------
src/nact/nact-main-window.c | 6 ++
src/nact/nact-menubar-priv.h | 67 +++++++++++++------------
src/nact/nact-menubar-view.c | 21 ++++++++
src/nact/nact-menubar.c | 53 ++++++++++++++++----
src/nact/nautilus-actions-config-tool.actions | 6 ++
8 files changed, 152 insertions(+), 90 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b8abe12..9641dac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2012-02-02 Pierre Wieser <pwieser trychlos org>
+
+ * src/core/na-iprefs.c: Fix enumeration maps as it only works for data
+ greater than zero.
+
+ * src/nact/nact-main-tab.c: No more try to open a popup menu on the
+ notebook as the standard GtkNotebook already has its own popup.
+
+ * src/nact/nact-main-window.c (on_base_initialize_gtk):
+ Enable the standard GtkNotebook context menu.
+
+ * src/nact/nact-menubar-priv.h:
+ * src/nact/nact-menubar.c:
+ Define a new notebook action group.
+ Define new radio action entries.
+
+ * src/nact/nact-menubar-view.c (nact_menubar_view_on_tabs_pos_changed):
+ New function.
+
+ * src/nact/nautilus-actions-config-tool.actions: Define menu actions.
+
2012-02-01 Pierre Wieser <pwieser trychlos org>
* src/nact/nact-main-window.c:
diff --git a/src/core/na-iprefs.c b/src/core/na-iprefs.c
index c4d2d55..548d1fc 100644
--- a/src/core/na-iprefs.c
+++ b/src/core/na-iprefs.c
@@ -61,10 +61,10 @@ static EnumMap st_order_mode[] = {
};
static EnumMap st_tabs_pos[] = {
- { GTK_POS_LEFT, "Left" },
- { GTK_POS_RIGHT, "Right" },
- { GTK_POS_TOP, "Top" },
- { GTK_POS_BOTTOM, "Bottom" },
+ { 1+GTK_POS_LEFT, "Left" },
+ { 1+GTK_POS_RIGHT, "Right" },
+ { 1+GTK_POS_TOP, "Top" },
+ { 1+GTK_POS_BOTTOM, "Bottom" },
{ 0 }
};
@@ -144,7 +144,7 @@ na_iprefs_get_tabs_pos( gboolean *mandatory )
tabs_pos = enum_map_id_from_string( st_tabs_pos, tabs_pos_str );
g_free( tabs_pos_str );
- return( tabs_pos );
+ return( tabs_pos-1 );
}
/*
@@ -158,7 +158,7 @@ na_iprefs_set_tabs_pos( guint position )
{
const gchar *tabs_pos_str;
- tabs_pos_str = enum_map_string_from_id( st_tabs_pos, position );
+ tabs_pos_str = enum_map_string_from_id( st_tabs_pos, 1+position );
na_settings_set_string( NA_IPREFS_MAIN_TABS_POS, tabs_pos_str );
}
diff --git a/src/nact/nact-main-tab.c b/src/nact/nact-main-tab.c
index 665ccce..e886329 100644
--- a/src/nact/nact-main-tab.c
+++ b/src/nact/nact-main-tab.c
@@ -36,9 +36,7 @@
#include "nact-main-tab.h"
-static void on_tab_initialize_window( NactMainWindow *window, gpointer p_page );
-static gboolean on_button_press_event( GtkWidget *widget, GdkEventButton *event, NactMainWindow *window );
-static void open_popup( NactMainWindow *window, GdkEventButton *event );
+static void on_tab_initialize_window( NactMainWindow *window, gpointer p_page );
/**
* nact_main_tab_init:
@@ -104,53 +102,27 @@ nact_main_tab_is_page_enabled( NactMainWindow *window, gint num_page )
return( is_sensitive );
}
+/*
+ * a commoon initialization for each page of the notebook
+ * (provided that the page has itself called nact_main_tab_init()
+ * *before* the BASE_SIGNAL_INITIALIZE_WINDOW has been emitted)
+ */
static void
on_tab_initialize_window( NactMainWindow *window, gpointer p_page )
{
GtkNotebook *notebook;
- GtkWidget *page, *label;
+ GtkWidget *page;
+ const gchar *text;
guint num_page;
notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
num_page = GPOINTER_TO_UINT( p_page );
page = gtk_notebook_get_nth_page( notebook, num_page );
- label = gtk_notebook_get_tab_label( notebook, page );
-
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( label ),
- "button-press-event",
- G_CALLBACK( on_button_press_event ));
-}
-
-static gboolean
-on_button_press_event( GtkWidget *widget, GdkEventButton *event, NactMainWindow *window )
-{
- gboolean stop = FALSE;
- /* single click on right button */
- if( event->type == GDK_BUTTON_PRESS && event->button == 3 ){
- open_popup( window, event );
- stop = TRUE;
- }
-
- return( stop );
-}
-
-static void
-open_popup( NactMainWindow *window, GdkEventButton *event )
-{
-#if 0
- NactTreeView *items_view;
- GtkTreePath *path;
-
- items_view = NACT_TREE_VIEW( g_object_get_data( G_OBJECT( window ), WINDOW_DATA_TREE_VIEW ));
-
- if( gtk_tree_view_get_path_at_pos( items_view->private->tree_view, event->x, event->y, &path, NULL, NULL, NULL )){
- nact_tree_view_select_row_at_path( items_view, path );
- gtk_tree_path_free( path );
- }
-
- g_signal_emit_by_name( window, MAIN_SIGNAL_CONTEXT_MENU, event, "popup" );
-#endif
+ /* popup menu is enabled in NactMainWindow::on_base_initialize_window()
+ * but the displayed labels default to be those of the tab, i.e. embed
+ * an underscore as an accelerator - so get ride of this
+ */
+ text = gtk_notebook_get_tab_label_text( notebook, page );
+ gtk_notebook_set_menu_label_text( notebook, page, text );
}
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 2f00b33..38ad685 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -846,6 +846,7 @@ on_base_initialize_gtk( NactMainWindow *window, GtkWindow *toplevel, gpointer us
{
static const gchar *thisfn = "nact_main_window_on_base_initialize_gtk";
GtkWidget *tree_parent;
+ GtkNotebook *notebook;
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
@@ -876,6 +877,11 @@ on_base_initialize_gtk( NactMainWindow *window, GtkWindow *toplevel, gpointer us
G_CALLBACK( on_tree_view_modified_status_changed ));
nact_main_statusbar_initialize_gtk_toplevel( window );
+
+ /* enable popup menu on the notebook
+ */
+ notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
+ gtk_notebook_popup_enable( notebook );
}
}
diff --git a/src/nact/nact-menubar-priv.h b/src/nact/nact-menubar-priv.h
index 730b318..a120be7 100644
--- a/src/nact/nact-menubar-priv.h
+++ b/src/nact/nact-menubar-priv.h
@@ -61,6 +61,7 @@ struct _NactMenubarPrivate {
NactSortButtons *sort_buttons;
GtkUIManager *ui_manager;
GtkActionGroup *action_group;
+ GtkActionGroup *notebook_group;
gboolean is_level_zero_writable;
gboolean has_writable_providers;
@@ -124,36 +125,36 @@ struct _NactMenubarPrivate {
/* These functions should only be called from a nact-menubar-derived file
*/
-void nact_menubar_enable_item( const NactMenubar *bar, const gchar *name, gboolean enabled );
+void nact_menubar_enable_item ( const NactMenubar *bar, const gchar *name, gboolean enabled );
-void nact_menubar_edit_on_update_sensitivities( const NactMenubar *bar );
+void nact_menubar_edit_on_update_sensitivities ( const NactMenubar *bar );
-void nact_menubar_edit_on_cut ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_copy ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_paste ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_paste_into ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_duplicate ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_delete ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_reload ( GtkAction *action, BaseWindow *window );
-void nact_menubar_edit_on_prefererences( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_cut ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_copy ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_paste ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_paste_into ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_duplicate ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_delete ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_reload ( GtkAction *action, BaseWindow *window );
+void nact_menubar_edit_on_prefererences ( GtkAction *action, BaseWindow *window );
-void nact_menubar_file_initialize ( NactMenubar *bar );
-void nact_menubar_file_on_update_sensitivities( const NactMenubar *bar );
+void nact_menubar_file_initialize ( NactMenubar *bar );
+void nact_menubar_file_on_update_sensitivities ( const NactMenubar *bar );
-void nact_menubar_file_on_new_menu ( GtkAction *action, BaseWindow *window );
-void nact_menubar_file_on_new_action ( GtkAction *action, BaseWindow *window );
-void nact_menubar_file_on_new_profile( GtkAction *action, BaseWindow *window );
-void nact_menubar_file_on_save ( GtkAction *action, BaseWindow *window );
-void nact_menubar_file_on_quit ( GtkAction *action, BaseWindow *window );
+void nact_menubar_file_on_new_menu ( GtkAction *action, BaseWindow *window );
+void nact_menubar_file_on_new_action ( GtkAction *action, BaseWindow *window );
+void nact_menubar_file_on_new_profile ( GtkAction *action, BaseWindow *window );
+void nact_menubar_file_on_save ( GtkAction *action, BaseWindow *window );
+void nact_menubar_file_on_quit ( GtkAction *action, BaseWindow *window );
-void nact_menubar_file_save_items ( BaseWindow *window );
+void nact_menubar_file_save_items ( BaseWindow *window );
-void nact_menubar_help_on_update_sensitivities( const NactMenubar *bar );
+void nact_menubar_help_on_update_sensitivities ( const NactMenubar *bar );
-void nact_menubar_help_on_help ( GtkAction *action, BaseWindow *window );
-void nact_menubar_help_on_about( GtkAction *action, BaseWindow *window );
+void nact_menubar_help_on_help ( GtkAction *action, BaseWindow *window );
+void nact_menubar_help_on_about ( GtkAction *action, BaseWindow *window );
-void nact_menubar_maintainer_on_update_sensitivities( const NactMenubar *bar );
+void nact_menubar_maintainer_on_update_sensitivities ( const NactMenubar *bar );
void nact_menubar_maintainer_on_dump_selection ( GtkAction *action, BaseWindow *window );
void nact_menubar_maintainer_on_brief_tree_store_dump( GtkAction *action, BaseWindow *window );
@@ -161,19 +162,21 @@ void nact_menubar_maintainer_on_list_modified_items ( GtkAction *action, BaseWi
void nact_menubar_maintainer_on_dump_clipboard ( GtkAction *action, BaseWindow *window );
void nact_menubar_maintainer_on_test_function ( GtkAction *action, BaseWindow *window );
-void nact_menubar_tools_on_update_sensitivities( const NactMenubar *bar );
+void nact_menubar_tools_on_update_sensitivities ( const NactMenubar *bar );
-void nact_menubar_tools_on_import( GtkAction *action, BaseWindow *window );
-void nact_menubar_tools_on_export( GtkAction *action, BaseWindow *window );
+void nact_menubar_tools_on_import ( GtkAction *action, BaseWindow *window );
+void nact_menubar_tools_on_export ( GtkAction *action, BaseWindow *window );
-void nact_menubar_view_on_update_sensitivities( const NactMenubar *bar );
+void nact_menubar_view_on_update_sensitivities ( const NactMenubar *bar );
-void nact_menubar_view_on_expand_all ( GtkAction *action, BaseWindow *window );
-void nact_menubar_view_on_collapse_all ( GtkAction *action, BaseWindow *window );
-void nact_menubar_view_on_toolbar_file ( GtkToggleAction *action, BaseWindow *window );
-void nact_menubar_view_on_toolbar_edit ( GtkToggleAction *action, BaseWindow *window );
-void nact_menubar_view_on_toolbar_tools( GtkToggleAction *action, BaseWindow *window );
-void nact_menubar_view_on_toolbar_help ( GtkToggleAction *action, BaseWindow *window );
+void nact_menubar_view_on_expand_all ( GtkAction *action, BaseWindow *window );
+void nact_menubar_view_on_collapse_all ( GtkAction *action, BaseWindow *window );
+void nact_menubar_view_on_toolbar_file ( GtkToggleAction *action, BaseWindow *window );
+void nact_menubar_view_on_toolbar_edit ( GtkToggleAction *action, BaseWindow *window );
+void nact_menubar_view_on_toolbar_tools ( GtkToggleAction *action, BaseWindow *window );
+void nact_menubar_view_on_toolbar_help ( GtkToggleAction *action, BaseWindow *window );
+
+void nact_menubar_view_on_tabs_pos_changed ( GtkRadioAction *action, GtkRadioAction *current, BaseWindow *window );
G_END_DECLS
diff --git a/src/nact/nact-menubar-view.c b/src/nact/nact-menubar-view.c
index 3b7b9e6..fabc02f 100644
--- a/src/nact/nact-menubar-view.c
+++ b/src/nact/nact-menubar-view.c
@@ -153,3 +153,24 @@ on_view_toolbar_activated( GtkToggleAction *action, BaseWindow *window, int tool
nact_main_toolbar_activate( NACT_MAIN_WINDOW( window ), toolbar_id, bar->private->ui_manager, is_active );
}
+
+/*
+ * When activating one of the GtkRadioAction which handles the position
+ * of the notebook tabs
+ * @action: the first GtkRadioAction of the group
+ * @current: the activated GtkRadioAction
+ *
+ * This function is triggered once each time we are activating an item of
+ * the menu, after having set the "current_value" to the new value. All
+ * GtkRadioButtons items share the same "current_value".
+ */
+void
+nact_menubar_view_on_tabs_pos_changed( GtkRadioAction *action, GtkRadioAction *current, BaseWindow *window )
+{
+ GtkNotebook *notebook;
+ guint new_pos;
+
+ notebook = GTK_NOTEBOOK( base_window_get_widget( BASE_WINDOW( window ), "MainNotebook" ));
+ new_pos = gtk_radio_action_get_current_value( action );
+ gtk_notebook_set_tab_pos( notebook, new_pos );
+}
diff --git a/src/nact/nact-menubar.c b/src/nact/nact-menubar.c
index 733fd88..78b5fe8 100644
--- a/src/nact/nact-menubar.c
+++ b/src/nact/nact-menubar.c
@@ -35,6 +35,7 @@
#include <glib/gi18n.h>
#include <core/na-io-provider.h>
+#include <core/na-iprefs.h>
#include "nact-application.h"
#include "nact-main-statusbar.h"
@@ -56,13 +57,14 @@ struct _NactMenubarClassPrivate {
static const GtkActionEntry entries[] = {
- { "FileMenu", NULL, N_( "_File" ) },
- { "EditMenu", NULL, N_( "_Edit" ) },
- { "ViewMenu", NULL, N_( "_View" ) },
- { "ViewToolbarMenu", NULL, N_( "_Toolbars" ) },
- { "ToolsMenu", NULL, N_( "_Tools" ) },
- { "MaintainerMenu", NULL, N_( "_Maintainer" ) },
- { "HelpMenu", NULL, N_( "_Help" ) },
+ { "FileMenu", NULL, N_( "_File" ) },
+ { "EditMenu", NULL, N_( "_Edit" ) },
+ { "ViewMenu", NULL, N_( "_View" ) },
+ { "ViewToolbarMenu", NULL, N_( "_Toolbars" ) },
+ { "ToolsMenu", NULL, N_( "_Tools" ) },
+ { "MaintainerMenu", NULL, N_( "_Maintainer" ) },
+ { "HelpMenu", NULL, N_( "_Help" ) },
+ { "NotebookLabelMenu", NULL, N_( "Notebook _tabs" ) },
{ "NewMenuItem", NULL, N_( "New _menu" ), NULL,
/* i18n: tooltip displayed in the status bar when selecting the 'New menu' item */
@@ -184,6 +186,26 @@ static const GtkToggleActionEntry toolbar_entries[] = {
G_CALLBACK( nact_menubar_view_on_toolbar_help ), FALSE },
};
+static const GtkRadioActionEntry tabs_pos_entries[] = {
+
+ { "TabsPosLeftItem", NULL, N_( "On the _left" ), NULL,
+ /* i18n: tooltip displayed in the status bar when selecting the 'Set tabs position on the left' item */
+ N_( "Display the notebook tabs on the left side" ),
+ GTK_POS_LEFT },
+ { "TabsPosRightItem", NULL, N_( "On the _right" ), NULL,
+ /* i18n: tooltip displayed in the status bar when selecting the 'Set tabs position on the right' item */
+ N_( "Display the notebook tabs on the right side" ),
+ GTK_POS_RIGHT },
+ { "TabsPosTopItem", NULL, N_( "On the _top" ), NULL,
+ /* i18n: tooltip displayed in the status bar when selecting 'Set tabs position on the top' item */
+ N_( "Display the notebook tabs on the top side" ),
+ GTK_POS_TOP },
+ { "TabsPosBottomItem", NULL, N_( "On the _bottom" ), NULL,
+ /* i18n: tooltip displayed in the status bar when selecting 'Set tabs position on the bottom' item */
+ N_( "Display the notebook tabs on the bottom side" ),
+ GTK_POS_BOTTOM },
+};
+
#define MENUBAR_PROP_STATUS_CONTEXT "menubar-status-context"
#define MENUBAR_PROP_MAIN_STATUS_CONTEXT "menubar-main-status-context"
@@ -331,6 +353,7 @@ instance_dispose( GObject *object )
self->private->dispose_has_run = TRUE;
g_object_unref( self->private->action_group );
+ g_object_unref( self->private->notebook_group );
g_object_unref( self->private->ui_manager );
g_object_unref( self->private->sort_buttons );
@@ -409,12 +432,16 @@ on_base_initialize_window( BaseWindow *window, gpointer user_data )
GtkWindow *toplevel;
gboolean has_maintainer_menu;
NactApplication *application;
+ guint tabs_pos;
BAR_WINDOW_VOID( window );
if( !bar->private->dispose_has_run ){
- g_debug( "%s: window=%p (%s), user_data=%p", thisfn,
- ( void * ) window, G_OBJECT_TYPE_NAME( window ), ( void * ) user_data );
+
+ g_debug( "%s: window=%p (%s), user_data=%p",
+ thisfn,
+ ( void * ) window, G_OBJECT_TYPE_NAME( window ),
+ ( void * ) user_data );
/* create the menubar:
* - create action group, and insert list of actions in it
@@ -434,9 +461,15 @@ on_base_initialize_window( BaseWindow *window, gpointer user_data )
"connect-proxy",
G_CALLBACK( on_ui_manager_proxy_connect ));
+ tabs_pos = na_iprefs_get_tabs_pos( NULL );
+ bar->private->notebook_group = gtk_action_group_new( "NotebookActions" );
+ g_debug( "%s: notebook_group=%p", thisfn, ( void * ) bar->private->notebook_group );
+ gtk_action_group_set_translation_domain( bar->private-> notebook_group, GETTEXT_PACKAGE );
+ gtk_action_group_add_radio_actions( bar->private->notebook_group, tabs_pos_entries, G_N_ELEMENTS( tabs_pos_entries ), tabs_pos, G_CALLBACK( nact_menubar_view_on_tabs_pos_changed ), window );
+ gtk_ui_manager_insert_action_group( bar->private->ui_manager, bar->private->notebook_group, 0 );
+
bar->private->action_group = gtk_action_group_new( "MenubarActions" );
g_debug( "%s: action_group=%p", thisfn, ( void * ) bar->private->action_group );
-
gtk_action_group_set_translation_domain( bar->private->action_group, GETTEXT_PACKAGE );
gtk_action_group_add_actions( bar->private->action_group, entries, G_N_ELEMENTS( entries ), window );
gtk_action_group_add_toggle_actions( bar->private->action_group, toolbar_entries, G_N_ELEMENTS( toolbar_entries ), window );
diff --git a/src/nact/nautilus-actions-config-tool.actions b/src/nact/nautilus-actions-config-tool.actions
index abdbd16..c3e9748 100644
--- a/src/nact/nautilus-actions-config-tool.actions
+++ b/src/nact/nautilus-actions-config-tool.actions
@@ -31,6 +31,12 @@
<menuitem action="ViewToolsToolbarItem" />
<menuitem action="ViewHelpToolbarItem" />
</menu>
+ <menu action="NotebookLabelMenu">
+ <menuitem action="TabsPosLeftItem" />
+ <menuitem action="TabsPosRightItem" />
+ <menuitem action="TabsPosTopItem" />
+ <menuitem action="TabsPosBottomItem" />
+ </menu>
</menu>
<menu action="ToolsMenu">
<menuitem action="ImportItem" />
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]