[patch] Make anjuta2 remember its window state
- From: Gustavo Giráldez <gustavo giraldez gmx net>
- To: JP Rosevear <jpr ximian com>
- Cc: Gnome Devtools list <gnome-devtools gnome org>
- Subject: [patch] Make anjuta2 remember its window state
- Date: 04 Jun 2002 07:46:06 -0300
Hi Jpr,
This patch makes anjuta2 save its window state when quitting and
restoring it when creating the window. All state tracking is done via
configure-event and window-state-event signals just as the gtk+ api
reference suggests.
I also changed the top Makefile for internationalization of schemas, so
the the current anjuta2.schemas should be removed and put the attached
anjuta2.schemas.in instead.
May I commit?
Regards,
Gustavo
<gconfschemafile>
<schemalist>
<!-- document-manager keys -->
<schema>
<key>/schemas/apps/anjuta2/plugins/document_manager/recent_files_limit</key>
<applyto>/apps/anjuta2/plugins/document_manager/recent_files_limit</applyto>
<owner>anjuta2</owner>
<type>int</type>
<default>10</default>
<locale name="C">
<short>File history limit</short>
<long>The maximum number of entries for the file history</long>
</locale>
</schema>
<!-- project-manager keys -->
<schema>
<key>/schemas/apps/anjuta2/plugins/project_manager/recent_projects_limit</key>
<applyto>/apps/anjuta2/plugins/project_manager/recent_projects_limit</applyto>
<owner>anjuta2</owner>
<type>int</type>
<default>5</default>
<locale name="C">
<short>Project history limit</short>
<long>The maximum number of entries for the project history</long>
</locale>
</schema>
<!-- window-state keys -->
<schema>
<key>/schemas/apps/anjuta2/state/width</key>
<applyto>/apps/anjuta2/state/width</applyto>
<owner>anjuta2</owner>
<type>int</type>
<default>800</default>
<locale name="C">
<short>Window width</short>
<long>Window width for newly created windows</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/anjuta2/state/height</key>
<applyto>/apps/anjuta2/state/height</applyto>
<owner>anjuta2</owner>
<type>int</type>
<default>550</default>
<locale name="C">
<short>Window height</short>
<long>Window height for newly created windows</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/anjuta2/state/maximized</key>
<applyto>/apps/anjuta2/state/maximized</applyto>
<owner>anjuta2</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short>Window maximized</short>
<long>Whether a new window is maximized by default</long>
</locale>
</schema>
</schemalist>
</gconfschemafile>
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/window.c,v
retrieving revision 1.59
diff -u -r1.59 window.c
--- src/window.c 30 May 2002 22:15:25 -0000 1.59
+++ src/window.c 4 Jun 2002 10:42:33 -0000
@@ -38,7 +38,23 @@
#include <libxml/parser.h>
#include <string.h>
#include <libanjuta/libanjuta.h>
+#include <gconf/gconf-client.h>
+
+#define ANJUTA_WINDOW_STATE_PREFIX "/apps/anjuta2/state"
+#define ANJUTA_WINDOW_STATE_WIDTH_KEY ANJUTA_WINDOW_STATE_PREFIX "/width"
+#define ANJUTA_WINDOW_STATE_HEIGHT_KEY ANJUTA_WINDOW_STATE_PREFIX "/height"
+#define ANJUTA_WINDOW_STATE_MAXIMIZED_KEY ANJUTA_WINDOW_STATE_PREFIX "/maximized"
+
+typedef struct _AnjutaWindowState AnjutaWindowState;
+
+struct _AnjutaWindowState {
+ gint width;
+ gint height;
+ gboolean maximized;
+};
+
+
/* ---- Private prototypes ----- */
static void layout_manager (GtkWidget *w,
@@ -46,6 +62,100 @@
static void anjuta_window_save_layout_to_file (AnjutaWindow *window);
+/* ------------ Window state functions */
+
+static void
+load_state (GtkWindow *window)
+{
+ GConfClient *gconf_client;
+ AnjutaWindowState *state;
+
+ state = g_object_get_data (G_OBJECT (window), "window_state");
+ if (!state) {
+ state = g_new0 (AnjutaWindowState, 1);
+ g_object_set_data (G_OBJECT (window), "window_state", state);
+ }
+
+ /* restore window state */
+ gconf_client = gconf_client_get_default ();
+ state->width = gconf_client_get_int (gconf_client,
+ ANJUTA_WINDOW_STATE_WIDTH_KEY,
+ NULL);
+ state->height = gconf_client_get_int (gconf_client,
+ ANJUTA_WINDOW_STATE_HEIGHT_KEY,
+ NULL);
+ state->maximized = gconf_client_get_bool (gconf_client,
+ ANJUTA_WINDOW_STATE_MAXIMIZED_KEY,
+ NULL);
+ gtk_window_set_default_size (GTK_WINDOW (window), state->width, state->height);
+ if (state->maximized)
+ gtk_window_maximize (GTK_WINDOW (window));
+
+ g_object_unref (gconf_client);
+}
+
+static void
+save_state (GtkWindow *window)
+{
+ GConfClient *gconf_client;
+ AnjutaWindowState *state;
+
+ state = g_object_get_data (G_OBJECT (window), "window_state");
+ if (!state)
+ return;
+
+ /* save the window state */
+ gconf_client = gconf_client_get_default ();
+ gconf_client_set_int (gconf_client,
+ ANJUTA_WINDOW_STATE_HEIGHT_KEY,
+ state->height,
+ NULL);
+ gconf_client_set_int (gconf_client,
+ ANJUTA_WINDOW_STATE_WIDTH_KEY,
+ state->width,
+ NULL);
+ gconf_client_set_bool (gconf_client,
+ ANJUTA_WINDOW_STATE_MAXIMIZED_KEY,
+ state->maximized,
+ NULL);
+ g_object_unref (gconf_client);
+}
+
+static gboolean
+anjuta_window_state_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ AnjutaWindowState *state;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+
+ state = g_object_get_data (G_OBJECT (widget), "window_state");
+ if (!state) {
+ state = g_new0 (AnjutaWindowState, 1);
+ g_object_set_data (G_OBJECT (widget), "window_state", state);
+ }
+
+ switch (event->type) {
+ case GDK_WINDOW_STATE:
+ state->maximized = event->window_state.new_window_state &
+ GDK_WINDOW_STATE_MAXIMIZED;
+ break;
+ case GDK_CONFIGURE:
+ if (!state->maximized) {
+ state->width = event->configure.width;
+ state->height = event->configure.height;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+/* ---------- Callbacks */
+
static void
tmp_exit (GtkWidget *w, AnjutaWindow *window)
{
@@ -186,7 +296,8 @@
static void
anjuta_window_class_init (AnjutaWindowClass *class)
{
- GtkObjectClass *object_class;
+
+ GtkObjectClass *object_class;
object_class = (GtkObjectClass*) class;
}
@@ -213,7 +324,7 @@
BonoboUIContainer *ui_container;
GtkTargetEntry dragtypes[] = {{"text/uri-list", 0, 0}};
gchar *filename;
-
+
ui_container = bonobo_window_get_ui_container (BONOBO_WINDOW (window));
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
@@ -253,7 +364,13 @@
g_signal_connect (window->layout_manager, "notify::dirty",
(GCallback) layout_dirty_notify, window);
- gtk_window_set_default_size (GTK_WINDOW (window), 800, 550);
+ /* window state tracking */
+ g_signal_connect (window, "window-state-event",
+ G_CALLBACK (anjuta_window_state_cb), NULL);
+ g_signal_connect (window, "configure-event",
+ G_CALLBACK (anjuta_window_state_cb), NULL);
+ load_state (GTK_WINDOW (window));
+
gtk_widget_realize (GTK_WIDGET(window));
/* drag'n'drop */
@@ -471,7 +588,8 @@
{
AnjutaWindow *window;
GtkAllocation *alloc;
-
+ AnjutaWindowState *state;
+
g_assert (ANJUTA_IS_WINDOW (widget));
window = ANJUTA_WINDOW (widget);
@@ -483,6 +601,15 @@
g_object_unref (window->layout_manager);
window->layout_manager = NULL;
};
+
+ state = g_object_get_data (G_OBJECT (widget), "window_state");
+ if (state) {
+ save_state (GTK_WINDOW (widget));
+
+ /* free window state */
+ g_object_set_data (G_OBJECT (widget), "window_state", NULL);
+ g_free (state);
+ }
}
static void
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/anjuta2/Makefile.am,v
retrieving revision 1.21
diff -u -r1.21 Makefile.am
--- Makefile.am 10 Apr 2002 18:18:17 -0000 1.21
+++ Makefile.am 4 Jun 2002 10:42:33 -0000
@@ -2,8 +2,6 @@
SUBDIRS = po idl libanjuta src plugins
-ANJUTA2_SCHEMA = anjuta2.schemas
-
man_MANS = anjuta.1
appicon_DATA = anjuta2.png
@@ -16,15 +14,17 @@
bin_SCRIPTS=anjuta-clean.sh
-schemadir = $(sysconfdir)/gconf/schemas
-schema_DATA = anjuta2.schemas
+schemasdir = $(sysconfdir)/gconf/schemas
+schemas_in_files = anjuta2.schemas.in
+schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
+ INTLTOOL_SCHEMAS_RULE@
install-data-local:
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 --shutdown
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 --makefile-install-rule $(ANJUTA2_SCHEMA)
+ GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 --makefile-install-rule $(schemas_DATA)
EXTRA_DIST = BUGS ChangeLog README INSTALL TODO anjuta2.png \
docs/tool-tutorial.txt \
$(man_MANS) $(bin_SCRIPTS) anjuta.spec Anjuta2.desktop \
- $(ANJUTA2_SCHEMA)
+ $(schemas_DATA)
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/anjuta2/ChangeLog,v
retrieving revision 1.209
diff -u -r1.209 ChangeLog
--- ChangeLog 30 May 2002 22:15:23 -0000 1.209
+++ ChangeLog 4 Jun 2002 10:42:50 -0000
@@ -1,3 +1,13 @@
+2002-06-04 Gustavo Giráldez <gustavo giraldez gmx net>
+
+ * src/window.c (load_state, save_state, anjuta_window_state_cb):
+ New functions to track and save/restore window state.
+ (anjuta_window_init, anjuta_window_destroy): Changed to remember
+ window state.
+ * Makefile.am: intltoolize anjuta2.schemas file.
+ * anjuta2.schemas.in: Replaces old anjuta2.schemas file. Add
+ window state keys.
+
2002-05-30 Ross Burton <ross burtonini com>
* src/window.c: Tell the about dialog who its parent is so that it
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]