src/ui/gui/widget-io.c \
src/ui/gui/widget-io.h \
src/ui/gui/widgets.c \
- src/ui/gui/widgets.h
+ src/ui/gui/widgets.h \
+ src/ui/gui/windows-menu.c \
+ src/ui/gui/windows-menu.h
OBSOLETE = \
<property name="stock-id">utilities-data-file-comments</property>
</object>
</child>
- <child>
- <object class="GtkAction" id="windows">
- <property name="name">windows</property>
- <property name="label" translatable="yes">_Windows</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="windows_minimise_all">
- <property name="name">windows_minimise_all</property>
- <property name="label" translatable="yes">_Minimize All Windows</property>
- <property name="stock-id">windows-minimize-all</property>
- </object>
- </child>
- <child>
- <object class="GtkToggleAction" id="windows_split">
- <property name="name">windows_split</property>
- <property name="label" translatable="yes">_Split</property>
- <property name="stock-id">windows-split</property>
- </object>
- </child>
</object>
</child>
<ui>
<menuitem action="utilities_variables"/>
<menuitem action="utilities_comments"/>
</menu>
- <menu action="windows">
- <menuitem action="windows_minimise_all"/>
- <menuitem action="windows_split"/>
- </menu>
</menubar>
<toolbar action="toolbar">
<toolitem name="toolbar_open" action="file_open"/>
<property name="label" translatable="yes">_Copy</property>
</object>
</child>
- <child>
- <object class="GtkAction" id="windows_menuitem">
- <property name="name">windows_menuitem</property>
- <property name="label" translatable="yes">_Windows</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="windows_minimise-all">
- <property name="stock-id">windows-minimize-all</property>
- <property name="name">windows_minimise-all</property>
- <property name="label" translatable="yes">_Minimize All Windows</property>
- </object>
- </child>
</object>
</child>
<ui>
<menuitem action="edit_copy"/>
<menuitem action="edit_select-all"/>
</menu>
- <menu action="windows_menuitem">
- <menuitem action="windows_minimise-all"/>
- </menu>
</menubar>
</ui>
</object>
#include "ui/gui/psppire-encoding-selector.h"
#include "ui/gui/psppire-syntax-window.h"
#include "ui/gui/psppire-window.h"
+#include "ui/gui/windows-menu.h"
#include "ui/gui/psppire.h"
#include "ui/syntax-gen.h"
g_object_set (de->data_editor, "value-labels", gtk_toggle_action_get_active (ta), NULL);
}
-static void
-toggle_split_window (PsppireDataWindow *de, GtkToggleAction *ta)
-{
- psppire_data_editor_split_window (de->data_editor,
- gtk_toggle_action_get_active (ta));
-}
-
static void
file_quit (PsppireDataWindow *de)
static void
psppire_data_window_init (PsppireDataWindow *de)
{
- GtkWidget *w ;
de->builder = builder_new ("data-editor.ui");
de->ui_manager = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));
- w = gtk_ui_manager_get_widget (de->ui_manager, "/ui/menubar/windows/windows_minimise_all");
-
- PSPPIRE_WINDOW (de)->menu = GTK_MENU_SHELL (gtk_widget_get_parent (w));
-
de->uim = NULL;
de->merge_id = 0;
}
connect_action (de, "transform_run-pending", G_CALLBACK (execute));
- connect_action (de, "windows_minimise_all", G_CALLBACK (psppire_window_minimise_all));
-
- g_signal_connect_swapped (get_action_assert (de->builder, "windows_split"), "toggled", G_CALLBACK (toggle_split_window), de);
-
+ gtk_menu_shell_append (GTK_MENU_SHELL (menubar), create_windows_menu (GTK_WINDOW (de)));
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), create_help_menu (GTK_WINDOW (de)));
g_signal_connect (de->data_editor, "notify::ui-manager",
#include "ui/gui/help-menu.h"
#include "ui/gui/builder-wrapper.h"
#include "ui/gui/psppire-output-view.h"
+#include "ui/gui/windows-menu.h"
#include "gl/xalloc.h"
G_CALLBACK (cancel_urgency),
NULL);
- g_signal_connect (get_action_assert (xml,"windows_minimise-all"),
- "activate",
- G_CALLBACK (psppire_window_minimise_all),
- NULL);
-
- {
- GtkWidget *w;
- GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER));
+ GtkWidget *menubar = get_widget_assert (xml, "menubar");
- GtkWidget *menubar = get_widget_assert (xml, "menubar");
+ gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
+ create_windows_menu (GTK_WINDOW (window)));
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
+ create_help_menu (GTK_WINDOW (window)));
- gtk_menu_shell_append (GTK_MENU_SHELL (menubar), create_help_menu (GTK_WINDOW (window)));
-
- w = gtk_ui_manager_get_widget (uim,"/ui/menubar/windows_menuitem/windows_minimise-all");
-
- PSPPIRE_WINDOW (window)->menu =
- GTK_MENU_SHELL (gtk_widget_get_parent (w));
- }
g_signal_connect_swapped (get_action_assert (xml, "file_export"), "activate",
G_CALLBACK (psppire_output_window_export), window);
#include "ui/gui/psppire-encoding-selector.h"
#include "ui/gui/psppire-lex-reader.h"
#include "ui/gui/psppire-syntax-window.h"
-#include "ui/gui/psppire-window-register.h"
#include "ui/gui/psppire.h"
+#include "ui/gui/windows-menu.h"
#include "gl/localcharset.h"
#include "gl/xalloc.h"
G_CALLBACK (on_run_to_end),
window);
- g_signal_connect (get_action_assert (xml,"windows_minimise_all"),
- "activate",
- G_CALLBACK (psppire_window_minimise_all), NULL);
-
-
- {
- GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER));
- GtkWidget *w = gtk_ui_manager_get_widget (uim,"/ui/menubar/windows/windows_minimise_all");
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menubar), create_help_menu (GTK_WINDOW (window)));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
+ create_windows_menu (GTK_WINDOW (window)));
- PSPPIRE_WINDOW (window)->menu = GTK_MENU_SHELL (gtk_widget_get_parent (w));
- }
+ gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
+ create_help_menu (GTK_WINDOW (window)));
g_object_unref (xml);
}
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008 Free Software Foundation
+ Copyright (C) 2008 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
g_signal_emit (wr, signals[INSERTED], 0, name);
}
-
void
psppire_window_register_remove (PsppireWindowRegister *wr, const gchar *name)
{
- g_signal_emit (wr, signals[REMOVED], 0, name);
-
g_hash_table_remove (wr->name_table, (gpointer) name);
+ g_signal_emit (wr, signals[REMOVED], 0, name);
}
PsppireWindow *
gint psppire_window_register_n_items (PsppireWindowRegister *wr);
+GtkWidget *create_windows_menu (GtkWindow *toplevel);
+
G_END_DECLS
-static void
-menu_toggled (GtkCheckMenuItem *mi, gpointer data)
-{
-#if GTK3_TRANSITION
- /* Prohibit changes to the state */
- mi->active = !mi->active;
-#endif
-}
-
-
-/* Look up the window associated with this menuitem and present it to the user */
-static void
-menu_activate (GtkMenuItem *mi, gpointer data)
-{
- const gchar *key = data;
-
- PsppireWindowRegister *reg = psppire_window_register_new ();
-
- PsppireWindow *window = psppire_window_register_lookup (reg, key);
-
- gtk_window_present (GTK_WINDOW (window));
-}
-
static void
insert_menuitem_into_menu (PsppireWindow *window, gpointer key)
{
gchar *filename;
GtkWidget *item;
-
- /* Add a separator before adding the first real item. If we add a separator
- at any other time, sometimes GtkUIManager removes it. */
- if (!window->added_separator)
- {
- GtkWidget *separator = gtk_separator_menu_item_new ();
- gtk_widget_show (separator);
- gtk_menu_shell_append (window->menu, separator);
- window->added_separator = TRUE;
- }
-
filename = g_filename_display_name (key);
item = gtk_check_menu_item_new_with_label (filename);
g_free (filename);
-
- g_signal_connect (item, "toggled", G_CALLBACK (menu_toggled), NULL);
- g_signal_connect (item, "activate", G_CALLBACK (menu_activate), key);
-
- gtk_widget_show (item);
-
- gtk_menu_shell_append (window->menu, item);
-
-#if GTK3_TRANSITION
- /* Set the state without emitting a signal */
- GTK_CHECK_MENU_ITEM (item)->active =
- (psppire_window_register_lookup (psppire_window_register_new (), key) == window);
-#endif
-
+
g_hash_table_insert (window->menuitem_table, key, item);
}
remove_menuitem (PsppireWindowRegister *reg, const gchar *key, gpointer data)
{
PsppireWindow *window = PSPPIRE_WINDOW (data);
- GtkWidget *item ;
-
- item = g_hash_table_lookup (window->menuitem_table, key);
-
g_hash_table_remove (window->menuitem_table, key);
-
- if (GTK_IS_CONTAINER (window->menu))
- gtk_container_remove (GTK_CONTAINER (window->menu), item);
}
static void
static void
psppire_window_init (PsppireWindow *window)
{
- window->menu = NULL;
window->filename = NULL;
window->basename = NULL;
window->id = NULL;
window_model_type =
g_type_register_static (G_TYPE_INTERFACE, "PsppireWindowModel",
&window_model_info, 0);
-
+
g_type_interface_add_prerequisite (window_model_type, G_TYPE_OBJECT);
}
gchar *list_name; /* Name for "Windows" menu list. */
GHashTable *menuitem_table;
- GtkMenuShell *menu;
guint insert_handler;
guint remove_handler;
<property name="label" translatable="yes">To End</property>
</object>
</child>
- <child>
- <object class="GtkAction" id="windows">
- <property name="name">windows</property>
- <property name="label" translatable="yes">_Windows</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="windows_minimise_all">
- <property name="stock-id">windows-minimize-all</property>
- <property name="name">windows_minimise_all</property>
- <property name="label" translatable="yes">_Minimize All Windows</property>
- </object>
- </child>
</object>
</child>
<ui>
<menuitem action="run_current_line"/>
<menuitem action="run_to_end"/>
</menu>
- <menu action="windows">
- <menuitem action="windows_minimise_all"/>
- </menu>
</menubar>
</ui>
</object>
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2016 Free Software Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "windows-menu.h"
+#include "psppire-window-register.h"
+#include "psppire-data-window.h"
+
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+static void
+minimise (gpointer key, gpointer value, gpointer user_data)
+{
+ PsppireWindow *pw = PSPPIRE_WINDOW (value);
+ gtk_window_iconify (GTK_WINDOW (pw));
+}
+
+static void
+min_all (GtkWidget *widget, gpointer ud)
+{
+ PsppireWindowRegister *reg = psppire_window_register_new ();
+
+ psppire_window_register_foreach (reg, minimise, NULL);
+}
+
+static void
+reset_check_state (GtkWidget *widget, gpointer ud)
+{
+ /* Prevent the state from actually changing */
+ g_signal_handlers_block_by_func (widget, reset_check_state, ud);
+ gboolean state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), !state);
+ g_signal_handlers_unblock_by_func (widget, reset_check_state, ud);
+}
+
+static gboolean
+raise_window (GtkWidget *widget, GdkEvent *ev, gpointer ud)
+{
+ GtkWindow *win = GTK_WINDOW (ud);
+ gtk_window_present_with_time (win, ((GdkEventButton *)ev)->time);
+
+ return FALSE;
+}
+
+
+static void
+add_menuitem (gpointer key, gpointer value, gpointer user_data)
+{
+ GtkMenu *menu = GTK_MENU (user_data);
+ PsppireWindow *pw = PSPPIRE_WINDOW (value);
+
+ GtkWidget *mi = gtk_check_menu_item_new_with_label (key);
+
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
+ pw == g_object_get_data (G_OBJECT (menu), "toplevel"));
+
+ g_signal_connect (mi, "toggled", G_CALLBACK (reset_check_state), pw);
+
+ g_signal_connect (mi, "button-press-event", G_CALLBACK (raise_window), pw);
+
+
+ gtk_container_add (GTK_CONTAINER(menu), mi);
+}
+
+static void
+toggle_split_window (PsppireDataWindow *de, GtkCheckMenuItem *ta)
+{
+ psppire_data_editor_split_window (de->data_editor,
+ gtk_check_menu_item_get_active (ta));
+}
+
+
+
+static void
+repopulate_windows_menu (GObject *inst, gchar *name, gpointer data)
+{
+ PsppireWindowRegister *reg = psppire_window_register_new ();
+ GtkMenuItem *mi = GTK_MENU_ITEM (data);
+
+ GtkWidget *menu = gtk_menu_new ();
+
+ GtkWindow *toplevel = g_object_get_data (G_OBJECT (mi), "toplevel");
+
+ GtkWidget *minimize = gtk_menu_item_new_with_mnemonic (_("_Minimize all Windows"));
+ GtkWidget *split = gtk_check_menu_item_new_with_mnemonic (_("_Split"));
+
+
+ GtkWidget *sep = gtk_separator_menu_item_new ();
+
+ gtk_menu_attach (GTK_MENU (menu), minimize, 0, 1, 0, 1);
+
+ if (PSPPIRE_DATA_WINDOW_TYPE == G_OBJECT_TYPE (toplevel) )
+ {
+ gtk_menu_attach (GTK_MENU (menu), split, 0, 1, 1, 2);
+ g_signal_connect_swapped (split, "toggled",
+ G_CALLBACK (toggle_split_window), toplevel);
+ }
+
+ gtk_container_add (GTK_CONTAINER (menu), sep);
+
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu);
+
+ g_object_set_data (G_OBJECT (menu), "toplevel", toplevel);
+
+ g_hash_table_foreach (reg->name_table, add_menuitem, menu);
+
+ g_signal_connect (minimize, "activate", G_CALLBACK (min_all), NULL);
+
+ gtk_widget_show_all (GTK_WIDGET (mi));
+}
+
+static void
+on_destroy (GtkWindow *w, gpointer data)
+{
+ PsppireWindowRegister *reg = psppire_window_register_new ();
+
+ g_signal_handlers_disconnect_by_func (reg, repopulate_windows_menu, w);
+}
+
+GtkWidget *
+create_windows_menu (GtkWindow *toplevel)
+{
+ PsppireWindowRegister *reg = psppire_window_register_new ();
+
+ GtkWidget *menuitem = gtk_menu_item_new_with_mnemonic (_("_Windows"));
+
+ g_object_set_data (G_OBJECT (menuitem), "toplevel", toplevel);
+
+ g_signal_connect (reg, "removed", G_CALLBACK (repopulate_windows_menu), menuitem);
+ g_signal_connect (reg, "inserted", G_CALLBACK (repopulate_windows_menu), menuitem);
+
+ g_signal_connect (menuitem, "destroy", G_CALLBACK (on_destroy), NULL);
+
+ return menuitem;
+}
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2016 Free Software Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef WINDOWS_MENU_H
+#define WINDOWS_MENU_H
+
+#include <gtk/gtk.h>
+
+GtkWidget * create_windows_menu (GtkWindow *toplevel);
+
+#endif