[gedit/wip/redesign: 6/9] Add statusbar/side/bottom panel settings to app menu
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/redesign: 6/9] Add statusbar/side/bottom panel settings to app menu
- Date: Mon, 6 May 2013 12:30:42 +0000 (UTC)
commit 08ef871a00c308118879ba96baff6cbc828c81a3
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon May 6 10:33:24 2013 +0200
Add statusbar/side/bottom panel settings to app menu
gedit/gedit-app.c | 25 ++++-
gedit/gedit-commands-view.c | 67 ------------
gedit/gedit-commands.h | 8 --
gedit/gedit-menu.ui | 16 +++
gedit/gedit-ui.h | 17 ---
gedit/gedit-ui.xml | 5 -
gedit/gedit-window.c | 238 +++++++------------------------------------
7 files changed, 75 insertions(+), 301 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 3f9c51e..5de2d8b 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -85,6 +85,7 @@ struct _GeditAppPrivate
GtkPrintSettings *print_settings;
GObject *settings;
+ GSettings *ui_settings;
GSettings *window_settings;
PeasExtensionSet *extensions;
@@ -194,6 +195,7 @@ gedit_app_dispose (GObject *object)
{
GeditApp *app = GEDIT_APP (object);
+ g_clear_object (&app->priv->ui_settings);
g_clear_object (&app->priv->window_settings);
g_clear_object (&app->priv->settings);
@@ -454,6 +456,7 @@ gedit_app_startup (GApplication *application)
/* Load settings */
app->priv->settings = gedit_settings_new ();
+ app->priv->ui_settings = g_settings_new ("org.gnome.gedit.preferences.ui");
app->priv->window_settings = g_settings_new ("org.gnome.gedit.state.window");
/* initial lockdown state */
@@ -463,12 +466,28 @@ gedit_app_startup (GApplication *application)
if (_gedit_app_has_app_menu (app))
{
GtkBuilder *builder;
+ GAction *action;
GError *error = NULL;
g_action_map_add_action_entries (G_ACTION_MAP (app),
- app_entries,
- G_N_ELEMENTS (app_entries),
- app);
+ app_entries,
+ G_N_ELEMENTS (app_entries),
+ app);
+
+ action = g_settings_create_action (app->priv->ui_settings,
+ "statusbar-visible");
+ g_action_map_add_action (G_ACTION_MAP (app), action);
+ g_object_unref (action);
+
+ action = g_settings_create_action (app->priv->ui_settings,
+ "side-panel-visible");
+ g_action_map_add_action (G_ACTION_MAP (app), action);
+ g_object_unref (action);
+
+ action = g_settings_create_action (app->priv->ui_settings,
+ "bottom-panel-visible");
+ g_action_map_add_action (G_ACTION_MAP (app), action);
+ g_object_unref (action);
builder = gtk_builder_new ();
if (!gtk_builder_add_from_resource (builder,
diff --git a/gedit/gedit-commands-view.c b/gedit/gedit-commands-view.c
index 2e53995..6cc41e4 100644
--- a/gedit/gedit-commands-view.c
+++ b/gedit/gedit-commands-view.c
@@ -41,73 +41,6 @@
#include "gedit-window.h"
#include "gedit-window-private.h"
-
-void
-_gedit_cmd_view_show_toolbar (GtkAction *action,
- GeditWindow *window)
-{
- gboolean visible;
-
- gedit_debug (DEBUG_COMMANDS);
-
- visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-
- gtk_widget_set_visible (window->priv->toolbar, visible);
-}
-
-void
-_gedit_cmd_view_show_statusbar (GtkAction *action,
- GeditWindow *window)
-{
- gboolean visible;
-
- gedit_debug (DEBUG_COMMANDS);
-
- visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-
- gtk_widget_set_visible (window->priv->statusbar, visible);
-}
-
-void
-_gedit_cmd_view_show_side_panel (GtkAction *action,
- GeditWindow *window)
-{
- gboolean visible;
- GeditPanel *panel;
-
- gedit_debug (DEBUG_COMMANDS);
-
- visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
- panel = gedit_window_get_side_panel (window);
-
- gtk_widget_set_visible (GTK_WIDGET (panel), visible);
-
- if (visible)
- {
- gtk_widget_grab_focus (GTK_WIDGET (panel));
- }
-}
-
-void
-_gedit_cmd_view_show_bottom_panel (GtkAction *action,
- GeditWindow *window)
-{
- gboolean visible;
- GeditPanel *panel;
-
- gedit_debug (DEBUG_COMMANDS);
-
- visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
- panel = gedit_window_get_bottom_panel (window);
-
- gtk_widget_set_visible (GTK_WIDGET (panel), visible);
-
- if (visible)
- {
- gtk_widget_grab_focus (GTK_WIDGET (panel));
- }
-}
-
void
_gedit_cmd_view_toggle_fullscreen_mode (GtkAction *action,
GeditWindow *window)
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 1c11c8f..07a2c15 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -120,14 +120,6 @@ void _gedit_cmd_edit_select_all (GtkAction *action,
void _gedit_cmd_edit_preferences (GtkAction *action,
GeditWindow *window);
-void _gedit_cmd_view_show_toolbar (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_view_show_statusbar (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_view_show_side_panel (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_view_show_bottom_panel (GtkAction *action,
- GeditWindow *window);
void _gedit_cmd_view_toggle_fullscreen_mode (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_view_leave_fullscreen_mode (GtkAction *action,
diff --git a/gedit/gedit-menu.ui b/gedit/gedit-menu.ui
index 11da064..27d563a 100644
--- a/gedit/gedit-menu.ui
+++ b/gedit/gedit-menu.ui
@@ -10,6 +10,22 @@
</section>
<section>
<item>
+ <attribute name="label" translatable="yes">_Statusbar</attribute>
+ <attribute name="action">app.statusbar-visible</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Side _Panel</attribute>
+ <attribute name="action">app.side-panel-visible</attribute>
+ <attribute name="accel">F9</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Bottom Panel</attribute>
+ <attribute name="action">app.bottom-panel-visible</attribute>
+ <attribute name="accel"><Primary>F9</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
</item>
diff --git a/gedit/gedit-ui.h b/gedit/gedit-ui.h
index d182fad..2a507d2 100644
--- a/gedit/gedit-ui.h
+++ b/gedit/gedit-ui.h
@@ -113,28 +113,11 @@ static const GtkActionEntry gedit_quit_menu_entries[] =
static const GtkToggleActionEntry gedit_always_sensitive_toggle_menu_entries[] =
{
- { "ViewToolbar", NULL, N_("_Toolbar"), NULL,
- N_("Show or hide the toolbar in the current window"),
- G_CALLBACK (_gedit_cmd_view_show_toolbar), TRUE },
- { "ViewStatusbar", NULL, N_("_Statusbar"), NULL,
- N_("Show or hide the statusbar in the current window"),
- G_CALLBACK (_gedit_cmd_view_show_statusbar), TRUE },
{ "ViewFullscreen", GTK_STOCK_FULLSCREEN, NULL, "F11",
N_("Edit text in fullscreen"),
G_CALLBACK (_gedit_cmd_view_toggle_fullscreen_mode), FALSE }
};
-/* separate group, should be always sensitive except when there are no panels */
-static const GtkToggleActionEntry gedit_panels_toggle_menu_entries[] =
-{
- { "ViewSidePanel", NULL, N_("Side _Panel"), "F9",
- N_("Show or hide the side panel in the current window"),
- G_CALLBACK (_gedit_cmd_view_show_side_panel), FALSE },
- { "ViewBottomPanel", NULL, N_("_Bottom Panel"), "<control>F9",
- N_("Show or hide the bottom panel in the current window"),
- G_CALLBACK (_gedit_cmd_view_show_bottom_panel), FALSE }
-};
-
static GActionEntry win_entries[] = {
{ "open", _gedit_cmd_file_open },
{ "new_tab", _gedit_cmd_file_new },
diff --git a/gedit/gedit-ui.xml b/gedit/gedit-ui.xml
index dc60df9..16bafcf 100644
--- a/gedit/gedit-ui.xml
+++ b/gedit/gedit-ui.xml
@@ -64,11 +64,6 @@
</menu>
<menu name="ViewMenu" action="View">
- <menuitem name="ViewToolbarMenu" action="ViewToolbar"/>
- <menuitem name="ViewStatusbarMenu" action="ViewStatusbar"/>
- <menuitem name="ViewSidePaneMenu" action="ViewSidePanel"/>
- <menuitem name="ViewBottomPaneMenu" action="ViewBottomPanel"/>
- <separator/>
<menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/>
<separator/>
<menu name="ViewHighlightModeMenu" action="ViewHighlightMode">
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 0e9acb4..bf4787a 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -439,38 +439,6 @@ gedit_window_class_init (GeditWindowClass *klass)
g_type_class_add_private (object_class, sizeof (GeditWindowPrivate));
}
-/* Returns TRUE if toolbar is visible */
-static gboolean
-set_toolbar_visibility (GeditWindow *window,
- GeditWindow *origin)
-{
- gboolean visible;
- GtkAction *action;
-
- if (origin == NULL)
- {
- visible = g_settings_get_boolean (window->priv->ui_settings,
- GEDIT_SETTINGS_TOOLBAR_VISIBLE);
- }
- else
- {
- visible = gtk_widget_get_visible (origin->priv->toolbar);
- }
-
- /* Set visibility */
- gtk_widget_set_visible (window->priv->toolbar, visible);
-
- action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
- "ViewToolbar");
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
- {
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
- }
-
- return visible;
-}
-
static void
update_next_prev_doc_sensitivity (GeditWindow *window,
GeditTab *tab)
@@ -1152,26 +1120,6 @@ set_non_homogeneus (GtkWidget *widget,
}
static void
-toolbar_visibility_changed (GtkWidget *toolbar,
- GParamSpec *pspec,
- GeditWindow *window)
-{
- gboolean visible;
- GtkAction *action;
-
- visible = gtk_widget_get_visible (toolbar);
-
- g_settings_set_boolean (window->priv->ui_settings,
- GEDIT_SETTINGS_TOOLBAR_VISIBLE, visible);
-
- action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
- "ViewToolbar");
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
-}
-
-static void
setup_toolbar_open_button (GeditWindow *window)
{
GtkMenu *recent_menu;
@@ -1246,17 +1194,6 @@ create_menu_bar_and_toolbar (GeditWindow *window)
g_object_unref (action_group);
window->priv->quit_action_group = action_group;
- action_group = gtk_action_group_new ("GeditWindowPanelsActions");
- gtk_action_group_set_translation_domain (action_group, NULL);
- gtk_action_group_add_toggle_actions (action_group,
- gedit_panels_toggle_menu_entries,
- G_N_ELEMENTS (gedit_panels_toggle_menu_entries),
- window);
-
- gtk_ui_manager_insert_action_group (manager, action_group, 0);
- g_object_unref (action_group);
- window->priv->panels_action_group = action_group;
-
gtk_ui_manager_add_ui_from_resource (manager,
"/org/gnome/gedit/ui/gedit-ui.xml",
&error);
@@ -1309,18 +1246,11 @@ create_menu_bar_and_toolbar (GeditWindow *window)
#else
gtk_toolbar_unset_style (GTK_TOOLBAR (window->priv->toolbar));
#endif
- set_toolbar_visibility (window, NULL);
-
setup_toolbar_open_button (window);
gtk_container_foreach (GTK_CONTAINER (window->priv->toolbar),
(GtkCallback)set_non_homogeneus,
NULL);
-
- g_signal_connect_after (G_OBJECT (window->priv->toolbar),
- "notify::visible",
- G_CALLBACK (toolbar_visibility_changed),
- window);
}
static void
@@ -1561,55 +1491,6 @@ activate_documents_list_item (GeditWindow *window,
g_free (action_name);
}
-/* Returns TRUE if status bar is visible */
-static gboolean
-set_statusbar_style (GeditWindow *window,
- GeditWindow *origin)
-{
- GtkAction *action;
- gboolean visible;
-
- if (origin == NULL)
- {
- visible = g_settings_get_boolean (window->priv->ui_settings,
- GEDIT_SETTINGS_STATUSBAR_VISIBLE);
- }
- else
- {
- visible = gtk_widget_get_visible (origin->priv->statusbar);
- }
-
- gtk_widget_set_visible (window->priv->statusbar, visible);
-
- action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
- "ViewStatusbar");
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
-
- return visible;
-}
-
-static void
-statusbar_visibility_changed (GtkWidget *statusbar,
- GParamSpec *pspec,
- GeditWindow *window)
-{
- gboolean visible;
- GtkAction *action;
-
- visible = gtk_widget_get_visible (statusbar);
-
- g_settings_set_boolean (window->priv->ui_settings,
- GEDIT_SETTINGS_STATUSBAR_VISIBLE, visible);
-
- action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
- "ViewStatusbar");
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
-}
-
static void
tab_width_combo_item_activated (GtkMenuItem *item,
GeditWindow *window)
@@ -1802,12 +1683,11 @@ setup_statusbar (GeditWindow *window)
create_tab_width_combo (window);
create_language_combo (window);
- g_signal_connect_after (G_OBJECT (window->priv->statusbar),
- "notify::visible",
- G_CALLBACK (statusbar_visibility_changed),
- window);
-
- set_statusbar_style (window, NULL);
+ g_settings_bind (window->priv->ui_settings,
+ "statusbar-visible",
+ window->priv->statusbar,
+ "visible",
+ G_SETTINGS_BIND_GET);
}
static GeditWindow *
@@ -1852,14 +1732,6 @@ clone_window (GeditWindow *origin)
_gedit_panel_set_active_item_by_id (GEDIT_PANEL (window->priv->bottom_panel),
panel_page);
- gtk_widget_set_visible (window->priv->side_panel,
- gtk_widget_get_visible (origin->priv->side_panel));
- gtk_widget_set_visible (window->priv->bottom_panel,
- gtk_widget_get_visible (origin->priv->bottom_panel));
-
- set_statusbar_style (window, origin);
- set_toolbar_visibility (window, origin);
-
return window;
}
@@ -3376,27 +3248,22 @@ vpaned_restore_position (GtkWidget *widget,
}
static void
-side_panel_visibility_changed (GtkWidget *side_panel,
- GParamSpec *pspec,
- GeditWindow *window)
+side_panel_visibility_changed (GSettings *settings,
+ const gchar *key,
+ GeditWindow *window)
{
gboolean visible;
- GtkAction *action;
-
- visible = gtk_widget_get_visible (side_panel);
-
- g_settings_set_boolean (window->priv->ui_settings,
- GEDIT_SETTINGS_SIDE_PANEL_VISIBLE,
- visible);
- action = gtk_action_group_get_action (window->priv->panels_action_group,
- "ViewSidePanel");
+ visible = g_settings_get_boolean (settings, key);
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
+ gtk_widget_set_visible (window->priv->side_panel, visible);
- /* focus the document */
- if (!visible)
+ /* focus the right widget */
+ if (visible)
+ {
+ gtk_widget_grab_focus (window->priv->side_panel);
+ }
+ else
{
gtk_widget_grab_focus (GTK_WIDGET (window->priv->multi_notebook));
}
@@ -3409,10 +3276,10 @@ setup_side_panel (GeditWindow *window)
gedit_debug (DEBUG_WINDOW);
- g_signal_connect_after (window->priv->side_panel,
- "notify::visible",
- G_CALLBACK (side_panel_visibility_changed),
- window);
+ g_signal_connect (window->priv->ui_settings,
+ "changed::side-panel-visible",
+ G_CALLBACK (side_panel_visibility_changed),
+ window);
documents_panel = gedit_documents_panel_new (window);
gedit_panel_add_item_with_stock_icon (GEDIT_PANEL (window->priv->side_panel),
@@ -3423,27 +3290,23 @@ setup_side_panel (GeditWindow *window)
}
static void
-bottom_panel_visibility_changed (GeditPanel *bottom_panel,
- GParamSpec *pspec,
+bottom_panel_visibility_changed (GSettings *settings,
+ const gchar *key,
GeditWindow *window)
{
gboolean visible;
- GtkAction *action;
- visible = gtk_widget_get_visible (GTK_WIDGET (bottom_panel));
+ visible = g_settings_get_boolean (settings, key) &&
+ gedit_panel_get_n_items (GEDIT_PANEL (window->priv->bottom_panel)) > 0;
- g_settings_set_boolean (window->priv->ui_settings,
- GEDIT_SETTINGS_BOTTOM_PANEL_VISIBLE,
- visible);
+ gtk_widget_set_visible (window->priv->bottom_panel, visible);
- action = gtk_action_group_get_action (window->priv->panels_action_group,
- "ViewBottomPanel");
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
-
- /* focus the document */
- if (!visible)
+ /* focus the right widget */
+ if (visible)
+ {
+ gtk_widget_grab_focus (window->priv->bottom_panel);
+ }
+ else
{
gtk_widget_grab_focus (GTK_WIDGET (window->priv->multi_notebook));
}
@@ -3456,13 +3319,7 @@ bottom_panel_item_removed (GeditPanel *panel,
{
if (gedit_panel_get_n_items (panel) == 0)
{
- GtkAction *action;
-
gtk_widget_hide (GTK_WIDGET (panel));
-
- action = gtk_action_group_get_action (window->priv->panels_action_group,
- "ViewBottomPanel");
- gtk_action_set_sensitive (action, FALSE);
}
}
@@ -3475,16 +3332,14 @@ bottom_panel_item_added (GeditPanel *panel,
* sensitive and if needed show the panel */
if (gedit_panel_get_n_items (panel) == 1)
{
- GtkAction *action;
gboolean show;
- action = gtk_action_group_get_action (window->priv->panels_action_group,
- "ViewBottomPanel");
- gtk_action_set_sensitive (action, TRUE);
-
- show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+ show = g_settings_get_boolean (window->priv->ui_settings,
+ "bottom-panel-visible");
if (show)
+ {
gtk_widget_show (GTK_WIDGET (panel));
+ }
}
}
@@ -3493,8 +3348,8 @@ setup_bottom_panel (GeditWindow *window)
{
gedit_debug (DEBUG_WINDOW);
- g_signal_connect_after (window->priv->bottom_panel,
- "notify::visible",
+ g_signal_connect_after (window->priv->ui_settings,
+ "changed::bottom-panel-visible",
G_CALLBACK (bottom_panel_visibility_changed),
window);
}
@@ -3537,13 +3392,6 @@ init_panels_visibility (GeditWindow *window)
gtk_widget_show (window->priv->bottom_panel);
}
}
- else
- {
- GtkAction *action;
- action = gtk_action_group_get_action (window->priv->panels_action_group,
- "ViewBottomPanel");
- gtk_action_set_sensitive (action, FALSE);
- }
/* start track sensitivity after the initial state is set */
window->priv->bottom_panel_item_removed_handler_id =
@@ -4424,14 +4272,8 @@ _gedit_window_fullscreen (GeditWindow *window)
gtk_widget_hide (window->priv->menubar);
- g_signal_handlers_block_by_func (window->priv->toolbar,
- toolbar_visibility_changed,
- window);
gtk_widget_hide (window->priv->toolbar);
- g_signal_handlers_block_by_func (window->priv->statusbar,
- statusbar_visibility_changed,
- window);
gtk_widget_hide (window->priv->statusbar);
fullscreen_controls_build (window);
@@ -4473,18 +4315,12 @@ _gedit_window_unfullscreen (GeditWindow *window)
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
if (visible)
gtk_widget_show (window->priv->toolbar);
- g_signal_handlers_unblock_by_func (window->priv->toolbar,
- toolbar_visibility_changed,
- window);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"ViewStatusbar");
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
if (visible)
gtk_widget_show (window->priv->statusbar);
- g_signal_handlers_unblock_by_func (window->priv->statusbar,
- statusbar_visibility_changed,
- window);
gtk_widget_hide (window->priv->fullscreen_controls);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]