[easytag/wip/application-window: 1/2] WIP Save application window paned state
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/application-window: 1/2] WIP Save application window paned state
- Date: Fri, 18 Jul 2014 08:18:31 +0000 (UTC)
commit 9b2b1160391e14e7e491a3dfb95550816972d89e
Author: David King <amigadave amigadave com>
Date: Thu Jul 17 08:31:19 2014 +0100
WIP Save application window paned state
TODO Does not seem to restore state correctly, is the paned position set
too early?
Browser paned should be managed by EtBrowser.
src/application_window.c | 49 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index dde830e..0aee9ec 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -93,6 +93,8 @@ struct _EtApplicationWindowPrivate
gboolean is_maximized;
gint height;
gint width;
+ gint paned_position;
+ gulong position_handler;
};
/* Used to force to hide the msgbox when deleting file */
@@ -147,6 +149,8 @@ save_state (EtApplicationWindow *self)
priv->height);
g_key_file_set_boolean (keyfile, "EtApplicationWindow", "is_maximized",
priv->is_maximized);
+ g_key_file_set_integer (keyfile, "EtApplicationWindow", "paned_position",
+ priv->paned_position);
/* TODO; Use g_key_file_save_to_file() in GLib 2.40. */
buffer = g_key_file_to_data (keyfile, &length, NULL);
@@ -198,6 +202,9 @@ restore_state (EtApplicationWindow *self)
priv->is_maximized = g_key_file_get_boolean (keyfile,
"EtApplicationWindow",
"is_maximized", NULL);
+ priv->paned_position = g_key_file_get_integer (keyfile,
+ "EtApplicationWindow",
+ "paned_position", NULL);
gtk_window_set_default_size (window, priv->width, priv->height);
@@ -205,6 +212,12 @@ restore_state (EtApplicationWindow *self)
{
gtk_window_maximize (window);
}
+
+ if (priv->paned_position > 0)
+ {
+ gtk_paned_set_position (GTK_PANED (priv->hpaned),
+ priv->paned_position);
+ }
}
static gboolean
@@ -245,12 +258,33 @@ on_window_state_event (GtkWidget *window,
if (state_event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
{
priv->is_maximized = (state_event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+
+ /* Set the paned position when maximizing, as setting it in
+ * restore_state() does not work when the window is maximized (as the
+ * gtk_window_maximize() has not yet taken effect). */
+ if (priv->is_maximized)
+ {
+ gtk_paned_set_position (GTK_PANED (priv->hpaned),
+ priv->paned_position);
+ }
}
return GDK_EVENT_PROPAGATE;
}
static void
+on_hpaned_notify_position (EtApplicationWindow *self,
+ GParamSpec *pspec,
+ GtkWidget *hpaned)
+{
+ EtApplicationWindowPrivate *priv;
+
+ priv = et_application_window_get_instance_private (self);
+
+ priv->paned_position = gtk_paned_get_position (GTK_PANED (hpaned));
+}
+
+static void
Convert_P20_And_Underscore_Into_Spaces (GtkWidget *entry)
{
gchar *string = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
@@ -3059,11 +3093,15 @@ static void
et_application_window_destroy (GtkWidget *widget)
{
EtApplicationWindow *self;
+ EtApplicationWindowPrivate *priv;
self = ET_APPLICATION_WINDOW (widget);
+ priv = et_application_window_get_instance_private (self);
save_state (self);
+ g_signal_handler_disconnect (priv->hpaned, priv->position_handler);
+
GTK_WIDGET_CLASS (et_application_window_parent_class)->destroy (widget);
}
@@ -3131,8 +3169,6 @@ et_application_window_init (EtApplicationWindow *self)
g_signal_connect (self, "window-state-event",
G_CALLBACK (on_window_state_event), NULL);
- restore_state (self);
-
/* Mainvbox for Menu bar + Tool bar + "Browser Area & FileArea & TagArea" + Log Area + "Status bar &
Progress bar" */
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (self), main_vbox);
@@ -3171,6 +3207,10 @@ et_application_window_init (EtApplicationWindow *self)
/* The two panes: BrowserArea on the left, FileArea+TagArea on the right */
priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
+ priv->position_handler = g_signal_connect_swapped (priv->hpaned,
+ "notify::position",
+ G_CALLBACK (on_hpaned_notify_position),
+ self);
/* Browser (Tree + File list + Entry) */
widget = create_browser_area (self);
@@ -3180,9 +3220,6 @@ et_application_window_init (EtApplicationWindow *self)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_paned_pack2 (GTK_PANED (priv->hpaned), vbox, FALSE, FALSE);
- /* TODO: Set a sensible default size for both widgets in the paned. */
- gtk_paned_set_position (GTK_PANED (priv->hpaned), 600);
-
/* File */
priv->file_area = create_file_area ();
gtk_box_pack_start (GTK_BOX (vbox), priv->file_area, FALSE, FALSE, 0);
@@ -3215,6 +3252,8 @@ et_application_window_init (EtApplicationWindow *self)
widget = Create_Progress_Bar ();
gtk_box_pack_end (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+ restore_state (self);
+
gtk_widget_show_all (GTK_WIDGET (main_vbox));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]