[gedit/wip/redesign2: 4/12] Restore per-window handling of panes
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/redesign2: 4/12] Restore per-window handling of panes
- Date: Mon, 6 Jan 2014 12:03:22 +0000 (UTC)
commit a3050df07d8cf205e1822195eb3f4311c58f24d9
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 4 12:20:09 2014 +0100
Restore per-window handling of panes
gedit/gedit-app.c | 11 -----
gedit/gedit-commands-view.c | 48 ++++++++++++++++++++
gedit/gedit-commands.h | 7 +++-
gedit/gedit-menu.ui | 12 -----
gedit/gedit-window.c | 101 +++++++++++++++++++++++++++++++------------
gedit/gedit-window.ui | 10 ++++
6 files changed, 137 insertions(+), 52 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 8951f0d..47a1e37 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -467,23 +467,12 @@ gedit_app_startup (GApplication *application)
if (_gedit_app_has_app_menu (app))
{
GtkBuilder *builder;
- GAction *action;
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries,
G_N_ELEMENTS (app_entries),
app);
- 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,
"/org/gnome/gedit/ui/gedit-menu.ui",
diff --git a/gedit/gedit-commands-view.c b/gedit/gedit-commands-view.c
index 26ff473..5074ab3 100644
--- a/gedit/gedit-commands-view.c
+++ b/gedit/gedit-commands-view.c
@@ -43,6 +43,54 @@
#include "gedit-highlight-mode-dialog.h"
void
+_gedit_cmd_view_toggle_side_panel (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
+ GeditPanel *panel;
+ gboolean visible;
+
+ gedit_debug (DEBUG_COMMANDS);
+
+ panel = gedit_window_get_side_panel (window);
+
+ visible = g_variant_get_boolean (state);
+ gtk_widget_set_visible (GTK_WIDGET (panel), visible);
+
+ if (visible)
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (panel));
+ }
+
+ g_simple_action_set_state (action, state);
+}
+
+void
+_gedit_cmd_view_toggle_bottom_panel (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
+ GeditPanel *panel;
+ gboolean visible;
+
+ gedit_debug (DEBUG_COMMANDS);
+
+ panel = gedit_window_get_bottom_panel (window);
+
+ visible = g_variant_get_boolean (state);
+ gtk_widget_set_visible (GTK_WIDGET (panel), visible);
+
+ if (visible)
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (panel));
+ }
+
+ g_simple_action_set_state (action, state);
+}
+
+void
_gedit_cmd_view_toggle_fullscreen_mode (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 9f3a6b2..f805a1f 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -130,7 +130,12 @@ void _gedit_cmd_edit_select_all (GSimpleAction *action,
void _gedit_cmd_edit_preferences (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
-
+void _gedit_cmd_view_toggle_side_panel (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+void _gedit_cmd_view_toggle_bottom_panel (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
void _gedit_cmd_view_toggle_fullscreen_mode (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
diff --git a/gedit/gedit-menu.ui b/gedit/gedit-menu.ui
index 6520d4a..b2f9c78 100644
--- a/gedit/gedit-menu.ui
+++ b/gedit/gedit-menu.ui
@@ -10,18 +10,6 @@
</section>
<section>
<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-window.c b/gedit/gedit-window.c
index 0d41c59..e8d705f 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -1284,6 +1284,11 @@ 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));
+
return window;
}
@@ -2912,19 +2917,26 @@ vpaned_restore_position (GtkWidget *widget,
}
static void
-side_panel_visibility_changed (GSettings *settings,
- const gchar *key,
+side_panel_visibility_changed (GtkWidget *panel,
+ GParamSpec *pspec,
GeditWindow *window)
{
- GtkStyleContext *context;
gboolean visible;
+ GAction *action;
+ GtkStyleContext *context;
- context = gtk_widget_get_style_context (window->priv->headerbar);
- visible = g_settings_get_boolean (settings, key);
+ visible = gtk_widget_get_visible (panel);
- gtk_widget_set_visible (window->priv->side_panel, visible);
+ g_settings_set_boolean (window->priv->ui_settings,
+ GEDIT_SETTINGS_SIDE_PANEL_VISIBLE,
+ visible);
+
+ /* sync the action state if the panel visibility was changed programmatically */
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "side_panel");
+ g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (visible));
/* focus the right widget and set the right styles */
+ context = gtk_widget_get_style_context (window->priv->headerbar);
if (visible)
{
gtk_style_context_add_class (context, "gedit-titlebar-right");
@@ -2945,10 +2957,10 @@ setup_side_panel (GeditWindow *window)
gedit_debug (DEBUG_WINDOW);
- g_signal_connect (window->priv->ui_settings,
- "changed::side-panel-visible",
- G_CALLBACK (side_panel_visibility_changed),
- window);
+ g_signal_connect_after (window->priv->side_panel,
+ "notify::visible",
+ G_CALLBACK (side_panel_visibility_changed),
+ window);
documents_panel = gedit_documents_panel_new (window);
image = gtk_image_new_from_icon_name ("view-list-symbolic",
@@ -2961,24 +2973,28 @@ setup_side_panel (GeditWindow *window)
image);
}
-
-
static void
-bottom_panel_visibility_changed (GSettings *settings,
- const gchar *key,
- GeditWindow *window)
+bottom_panel_visibility_changed (GtkWidget *panel,
+ GParamSpec *pspec,
+ GeditWindow *window)
{
gboolean visible;
+ GAction *action;
- visible = g_settings_get_boolean (settings, key) &&
- gedit_panel_get_n_items (GEDIT_PANEL (window->priv->bottom_panel)) > 0;
+ visible = gtk_widget_get_visible (panel);
- gtk_widget_set_visible (window->priv->bottom_panel, visible);
+ g_settings_set_boolean (window->priv->ui_settings,
+ GEDIT_SETTINGS_BOTTOM_PANEL_VISIBLE,
+ visible);
+
+ /* sync the action state if the panel visibility was changed programmatically */
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "bottom_panel");
+ g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (visible));
/* focus the right widget */
if (visible)
{
- gtk_widget_grab_focus (window->priv->bottom_panel);
+ gtk_widget_grab_focus (window->priv->side_panel);
}
else
{
@@ -2991,10 +3007,15 @@ bottom_panel_item_removed (GeditPanel *panel,
GtkWidget *item,
GeditWindow *window)
{
- if (gedit_panel_get_n_items (panel) == 0)
- {
- gtk_widget_hide (GTK_WIDGET (panel));
- }
+ gboolean empty;
+ GAction *action;
+
+ empty = gedit_panel_get_n_items (panel) == 0;
+
+ gtk_widget_set_visible (GTK_WIDGET (panel), !empty);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "bottom_panel");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !empty);
}
static void
@@ -3007,6 +3028,7 @@ bottom_panel_item_added (GeditPanel *panel,
if (gedit_panel_get_n_items (panel) == 1)
{
gboolean show;
+ GAction *action;
show = g_settings_get_boolean (window->priv->ui_settings,
"bottom-panel-visible");
@@ -3014,6 +3036,9 @@ bottom_panel_item_added (GeditPanel *panel,
{
gtk_widget_show (GTK_WIDGET (panel));
}
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "bottom_panel");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
}
}
@@ -3022,10 +3047,10 @@ setup_bottom_panel (GeditWindow *window)
{
gedit_debug (DEBUG_WINDOW);
- g_signal_connect_after (window->priv->ui_settings,
- "changed::bottom-panel-visible",
- G_CALLBACK (bottom_panel_visibility_changed),
- window);
+ g_signal_connect_after (window->priv->bottom_panel,
+ "notify::visible",
+ G_CALLBACK (bottom_panel_visibility_changed),
+ window);
}
static void
@@ -3066,6 +3091,13 @@ init_panels_visibility (GeditWindow *window)
gtk_widget_show (window->priv->bottom_panel);
}
}
+ else
+ {
+ GAction *action;
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "bottom_panel");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ }
/* start track sensitivity after the initial state is set */
window->priv->bottom_panel_item_removed_handler_id =
@@ -3154,6 +3186,18 @@ extension_removed (PeasExtensionSet *extensions,
gtk_ui_manager_ensure_update (window->priv->manager);
}
+static void
+activate_toggle (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GVariant *state;
+
+ state = g_action_get_state (G_ACTION (action));
+ g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
+ g_variant_unref (state);
+}
+
static GActionEntry win_entries[] = {
{ "open", _gedit_cmd_file_open },
{ "new_tab", _gedit_cmd_file_new },
@@ -3162,6 +3206,8 @@ static GActionEntry win_entries[] = {
{ "print", _gedit_cmd_file_print },
{ "revert", _gedit_cmd_file_revert },
{ "close", _gedit_cmd_file_close },
+ { "side_panel", activate_toggle, NULL, "false", _gedit_cmd_view_toggle_side_panel },
+ { "bottom_panel", activate_toggle, NULL, "false", _gedit_cmd_view_toggle_bottom_panel },
{ "fullscreen", _gedit_cmd_view_toggle_fullscreen_mode },
{ "leave_fullscreen", _gedit_cmd_view_leave_fullscreen_mode },
{ "find", _gedit_cmd_search_find },
@@ -3381,7 +3427,6 @@ gedit_window_init (GeditWindow *window)
(PeasExtensionSetForeachFunc) extension_added,
window);
-
/* set visibility of panels.
* This needs to be done after plugins activatation */
init_panels_visibility (window);
diff --git a/gedit/gedit-window.ui b/gedit/gedit-window.ui
index 0567339..e228e5c 100644
--- a/gedit/gedit-window.ui
+++ b/gedit/gedit-window.ui
@@ -34,6 +34,16 @@
<section>
<attribute name="id">ext6</attribute>
<item>
+ <attribute name="label" translatable="yes">Side _Panel</attribute>
+ <attribute name="action">win.side_panel</attribute>
+ <attribute name="accel">F9</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Bottom Panel</attribute>
+ <attribute name="action">win.bottom_panel</attribute>
+ <attribute name="accel"><Primary>F9</attribute>
+ </item>
+ <item>
<attribute name="label" translatable="yes">_Fullscreen</attribute>
<attribute name="action">win.fullscreen</attribute>
<attribute name="accel">F11</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]