From 5023955f3e48b1b0a703a38d654467360c0794a6 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 28 Dec 2006 00:44:45 +0000 Subject: [PATCH] Added a "Windows" menu, and a "minimise all windows" item. --- src/ui/gui/data-editor.c | 9 +++-- src/ui/gui/data-editor.glade | 27 ++++++++++++-- src/ui/gui/syntax-editor-source.c | 2 +- src/ui/gui/syntax-editor.c | 11 ++++-- src/ui/gui/syntax-editor.glade | 22 ++++++++++++ src/ui/gui/window-manager.c | 58 ++++++++++++++++++++++--------- src/ui/gui/window-manager.h | 8 ++--- 7 files changed, 110 insertions(+), 27 deletions(-) diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 5c2eaf4f..76612b5e 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -24,7 +24,7 @@ #include #include - +#include "window-manager.h" #include #include "helper.h" @@ -116,7 +116,7 @@ new_data_editor (void) connect_help (de->xml); - e->window = get_widget_assert (de->xml, "data_editor"); + e->window = GTK_WINDOW (get_widget_assert (de->xml, "data_editor")); g_signal_connect (get_widget_assert (de->xml,"file_new_data"), "activate", @@ -230,6 +230,11 @@ new_data_editor (void) G_CALLBACK (file_quit), de); + g_signal_connect (get_widget_assert (de->xml, "windows_minimise_all"), + "activate", + G_CALLBACK (minimise_all_windows), NULL); + + select_sheet (de, PAGE_DATA_SHEET); return de; diff --git a/src/ui/gui/data-editor.glade b/src/ui/gui/data-editor.glade index 08555556..419a9c60 100644 --- a/src/ui/gui/data-editor.glade +++ b/src/ui/gui/data-editor.glade @@ -207,7 +207,7 @@ True - + True gtk-find 1 @@ -344,7 +344,7 @@ - + True gtk-jump-to 1 @@ -445,6 +445,29 @@ + + + True + _Windows + True + + + + + + + + True + _Minimise All Windows + True + + + + + + + + True diff --git a/src/ui/gui/syntax-editor-source.c b/src/ui/gui/syntax-editor-source.c index dcb644a3..9e0a5564 100644 --- a/src/ui/gui/syntax-editor-source.c +++ b/src/ui/gui/syntax-editor-source.c @@ -52,7 +52,7 @@ name (const struct getl_interface *i) const struct syntax_editor_source *ses = (const struct syntax_editor_source *) i; - return window_name ((struct window_editor *) ses->se); + return window_name ((const struct editor_window *) ses->se); } diff --git a/src/ui/gui/syntax-editor.c b/src/ui/gui/syntax-editor.c index 95148d2c..643013a3 100644 --- a/src/ui/gui/syntax-editor.c +++ b/src/ui/gui/syntax-editor.c @@ -110,7 +110,7 @@ save_if_modified (struct syntax_editor *se) return ; } - gtk_widget_destroy (e->window); + gtk_widget_destroy (GTK_WIDGET (e->window)); } /* Callback for the File->SaveAs menuitem */ @@ -331,7 +331,7 @@ new_syntax_editor (void) e = (struct editor_window *)se; - e->window = get_widget_assert (xml, "syntax_editor"); + e->window = GTK_WINDOW (get_widget_assert (xml, "syntax_editor")); text_view = get_widget_assert (xml, "syntax_text_view"); se->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); se->lexer = lex_create (the_source_stream); @@ -408,6 +408,13 @@ new_syntax_editor (void) se); + g_signal_connect (get_widget_assert (xml,"windows_minimise_all"), + "activate", + G_CALLBACK (minimise_all_windows), + NULL); + + + g_object_unref (xml); g_signal_connect (e->window, "delete-event", diff --git a/src/ui/gui/syntax-editor.glade b/src/ui/gui/syntax-editor.glade index f5473006..80e6bff3 100644 --- a/src/ui/gui/syntax-editor.glade +++ b/src/ui/gui/syntax-editor.glade @@ -226,6 +226,28 @@ + + + True + _Windows + True + + + + + + + + True + _Minimise All Windows + True + + + + + + + True diff --git a/src/ui/gui/window-manager.c b/src/ui/gui/window-manager.c index 8ecce98c..d7c543a4 100644 --- a/src/ui/gui/window-manager.c +++ b/src/ui/gui/window-manager.c @@ -1,3 +1,4 @@ +#include #include "syntax-editor.h" #include "data-editor.h" @@ -9,17 +10,48 @@ #include "window-manager.h" -static int window_count = 0; + +/* A list of struct editor_windows */ +static GSList *window_list = NULL; + static void -deregister (GtkObject *o, gpointer data) +deregister_window (GtkWindow *w, gpointer data) { - window_count --; + struct editor_window *e = data; - if ( 0 == window_count ) + window_list = g_slist_remove (window_list, e); + + if ( g_slist_length (window_list) == 0 ) gtk_main_quit (); }; + +static void +register_window (struct editor_window *e) +{ + window_list = g_slist_prepend (window_list, e); +} + + +static gint +next_window_id (void) +{ + return g_slist_length (window_list); +} + +void +minimise_all_windows (void) +{ + const GSList *i = NULL; + + for (i = window_list; i != NULL ; i = i->next) + { + struct editor_window *e = i->data; + gtk_window_iconify (e->window); + } +} + static void set_window_name (struct editor_window *e, const gchar *name ); @@ -48,11 +80,12 @@ window_create (enum window_type type, const gchar *name) gtk_window_set_icon_from_file (GTK_WINDOW (e->window), PKGDATADIR "/psppicon.png", 0); - g_signal_connect (e->window, "destroy", G_CALLBACK (deregister), NULL); + g_signal_connect (e->window, "destroy", + G_CALLBACK (deregister_window), e); - gtk_widget_show (e->window); + register_window (e); - window_count ++; + gtk_widget_show (e->window); return e; } @@ -75,11 +108,11 @@ set_window_name (struct editor_window *e, switch (e->type ) { case WINDOW_SYNTAX: - e->name = g_strdup_printf (_("Syntax%d"), window_count); + e->name = g_strdup_printf (_("Syntax%d"), next_window_id () ); title = g_strdup_printf (_("%s --- PSPP Syntax Editor"), e->name); break; case WINDOW_DATA: - e->name = g_strdup_printf (_("Untitled%d"), window_count); + e->name = g_strdup_printf (_("Untitled%d"), next_window_id () ); title = g_strdup_printf (_("%s --- PSPP Data Editor"), e->name); break; default: @@ -119,13 +152,6 @@ window_set_name_from_filename (struct editor_window *e, g_free (title); } - -GtkWindow * -window_toplevel (const struct editor_window *e) -{ - return GTK_WINDOW (e->window); -} - const gchar * window_name (const struct editor_window *e) { diff --git a/src/ui/gui/window-manager.h b/src/ui/gui/window-manager.h index ee137dbc..3c5655ed 100644 --- a/src/ui/gui/window-manager.h +++ b/src/ui/gui/window-manager.h @@ -12,7 +12,7 @@ enum window_type struct editor_window { - GtkWidget *window; /* The top level window of the editor */ + GtkWindow *window; /* The top level window of the editor */ gchar *name; /* The name of this editor */ enum window_type type; } ; @@ -20,12 +20,12 @@ struct editor_window struct editor_window * window_create (enum window_type type, const gchar *name); - -GtkWindow * window_toplevel (const struct editor_window *); - const gchar * window_name (const struct editor_window *); void window_set_name_from_filename (struct editor_window *e, const gchar *filename); +void minimise_all_windows (void); + + #endif -- 2.30.2