[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[datasets 13/18] gui: Fix File|Open in syntax editor.
From: |
Ben Pfaff |
Subject: |
[datasets 13/18] gui: Fix File|Open in syntax editor. |
Date: |
Sat, 30 Apr 2011 22:36:41 -0700 |
It didn't do anything.
---
src/ui/gui/psppire-data-window.c | 107 +-----------------------------
src/ui/gui/psppire-syntax-window.c | 7 ++-
src/ui/gui/psppire-window.c | 129 +++++++++++++++++++++++++++++++++++-
src/ui/gui/psppire-window.h | 2 +
src/ui/gui/syntax-editor.ui | 21 +-----
5 files changed, 139 insertions(+), 127 deletions(-)
diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c
index 7e248f8..51b853c 100644
--- a/src/ui/gui/psppire-data-window.c
+++ b/src/ui/gui/psppire-data-window.c
@@ -19,7 +19,6 @@
#include <gtk/gtk.h>
#include <stdlib.h>
-#include "data/any-reader.h"
#include "data/dataset.h"
#include "language/lexer/lexer.h"
#include "libpspp/message.h"
@@ -359,108 +358,6 @@ load_file (PsppireWindow *de, const gchar *file_name)
return ok;
}
-static GtkWidget *
-sysfile_chooser_dialog (PsppireWindow *toplevel)
-{
- GtkWidget *dialog =
- gtk_file_chooser_dialog_new (_("Open"),
- GTK_WINDOW (toplevel),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
-
- GtkFileFilter *filter;
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Data and Syntax Files"));
- gtk_file_filter_add_pattern (filter, "*.sav");
- gtk_file_filter_add_pattern (filter, "*.SAV");
- gtk_file_filter_add_pattern (filter, "*.por");
- gtk_file_filter_add_pattern (filter, "*.POR");
- gtk_file_filter_add_pattern (filter, "*.sps");
- gtk_file_filter_add_pattern (filter, "*.SPS");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
- gtk_file_filter_add_pattern (filter, "*.sav");
- gtk_file_filter_add_pattern (filter, "*.SAV");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
- gtk_file_filter_add_pattern (filter, "*.por");
- gtk_file_filter_add_pattern (filter, "*.POR");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
- gtk_file_filter_add_pattern (filter, "*.sps");
- gtk_file_filter_add_pattern (filter, "*.SPS");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("All Files"));
- gtk_file_filter_add_pattern (filter, "*");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- {
- gchar *dir_name;
- gchar *filename = NULL;
- g_object_get (toplevel, "filename", &filename, NULL);
-
- if ( ! g_path_is_absolute (filename))
- {
- gchar *path =
- g_build_filename (g_get_current_dir (), filename, NULL);
- dir_name = g_path_get_dirname (path);
- g_free (path);
- }
- else
- {
- dir_name = g_path_get_dirname (filename);
- }
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
- dir_name);
- free (dir_name);
- }
-
- return dialog;
-}
-
-/* Callback for the data_open action.
- Prompts for a filename and opens it */
-static void
-open_window (PsppireWindow *de)
-{
- GtkWidget *dialog = sysfile_chooser_dialog (de);
-
- switch (gtk_dialog_run (GTK_DIALOG (dialog)))
- {
- case GTK_RESPONSE_ACCEPT:
- {
- gchar *name =
- gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-
- gchar *sysname = convert_glib_filename_to_system_filename (name, NULL);
-
- if (any_reader_may_open (sysname))
- psppire_window_load (de, name);
- else
- open_syntax_window (name);
-
- g_free (sysname);
- g_free (name);
- }
- break;
- default:
- break;
- }
-
- gtk_widget_destroy (dialog);
-}
-
/* Returns true if NAME has a suffix which might denote a PSPP file */
static gboolean
name_has_suffix (const gchar *name)
@@ -542,7 +439,7 @@ display_dict (PsppireDataWindow *de)
static void
sysfile_info (PsppireDataWindow *de)
{
- GtkWidget *dialog = sysfile_chooser_dialog (PSPPIRE_WINDOW (de));
+ GtkWidget *dialog = psppire_window_file_chooser_dialog (PSPPIRE_WINDOW (de));
if ( GTK_RESPONSE_ACCEPT == gtk_dialog_run (GTK_DIALOG (dialog)))
{
@@ -1028,7 +925,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
connect_action (de, "file_save", G_CALLBACK (data_save));
- connect_action (de, "file_open", G_CALLBACK (open_window));
+ connect_action (de, "file_open", G_CALLBACK (psppire_window_open));
connect_action (de, "file_save_as", G_CALLBACK (data_save_as_dialog));
diff --git a/src/ui/gui/psppire-syntax-window.c
b/src/ui/gui/psppire-syntax-window.c
index 45b6521..2e90ba7 100644
--- a/src/ui/gui/psppire-syntax-window.c
+++ b/src/ui/gui/psppire-syntax-window.c
@@ -1,5 +1,5 @@
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011 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
@@ -659,6 +659,11 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window)
window);
#endif
+ g_signal_connect_swapped (get_action_assert (xml, "file_open"),
+ "activate",
+ G_CALLBACK (psppire_window_open),
+ window);
+
g_signal_connect_swapped (get_action_assert (xml, "file_save"),
"activate",
G_CALLBACK (syntax_save),
diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c
index 369ece5..a3339ec 100644
--- a/src/ui/gui/psppire-window.c
+++ b/src/ui/gui/psppire-window.c
@@ -16,6 +16,7 @@
#include <config.h>
+#include "psppire-window.h"
#include <gtk/gtk.h>
@@ -26,9 +27,15 @@
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
-#include "psppire-window.h"
-#include "psppire-window-register.h"
+#include "data/any-reader.h"
+#include "data/dataset.h"
+
+#include "helper.h"
#include "psppire-conf.h"
+#include "psppire-data-window.h"
+#include "psppire-syntax-window.h"
+#include "psppire-window-register.h"
+#include "psppire.h"
static void psppire_window_base_finalize (PsppireWindowClass *, gpointer);
static void psppire_window_base_init (PsppireWindowClass *class);
@@ -434,7 +441,6 @@ psppire_window_init (PsppireWindow *window)
g_signal_connect (window, "realize",
G_CALLBACK (on_realize), window);
-
}
/*
@@ -636,6 +642,123 @@ psppire_window_load (PsppireWindow *w, const gchar *file)
return ok;
}
+GtkWidget *
+psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
+{
+ GtkWidget *dialog =
+ gtk_file_chooser_dialog_new (_("Open"),
+ GTK_WINDOW (toplevel),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ GtkFileFilter *filter;
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Data and Syntax Files"));
+ gtk_file_filter_add_pattern (filter, "*.sav");
+ gtk_file_filter_add_pattern (filter, "*.SAV");
+ gtk_file_filter_add_pattern (filter, "*.por");
+ gtk_file_filter_add_pattern (filter, "*.POR");
+ gtk_file_filter_add_pattern (filter, "*.sps");
+ gtk_file_filter_add_pattern (filter, "*.SPS");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
+ gtk_file_filter_add_pattern (filter, "*.sav");
+ gtk_file_filter_add_pattern (filter, "*.SAV");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
+ gtk_file_filter_add_pattern (filter, "*.por");
+ gtk_file_filter_add_pattern (filter, "*.POR");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
+ gtk_file_filter_add_pattern (filter, "*.sps");
+ gtk_file_filter_add_pattern (filter, "*.SPS");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All Files"));
+ gtk_file_filter_add_pattern (filter, "*");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ {
+ gchar *dir_name;
+ gchar *filename = NULL;
+ g_object_get (toplevel, "filename", &filename, NULL);
+
+ if ( ! g_path_is_absolute (filename))
+ {
+ gchar *path =
+ g_build_filename (g_get_current_dir (), filename, NULL);
+ dir_name = g_path_get_dirname (path);
+ g_free (path);
+ }
+ else
+ {
+ dir_name = g_path_get_dirname (filename);
+ }
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+ dir_name);
+ free (dir_name);
+ }
+
+ return dialog;
+}
+
+/* Callback for the file_open action.
+ Prompts for a filename and opens it */
+void
+psppire_window_open (PsppireWindow *de)
+{
+ GtkWidget *dialog = psppire_window_file_chooser_dialog (de);
+
+ switch (gtk_dialog_run (GTK_DIALOG (dialog)))
+ {
+ case GTK_RESPONSE_ACCEPT:
+ {
+ gchar *name =
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ gchar *sysname = convert_glib_filename_to_system_filename (name, NULL);
+
+ if (any_reader_may_open (sysname))
+ {
+ PsppireWindow *window;
+
+#if 0
+ if (PSPPIRE_IS_DATA_WINDOW (de)
+ && psppire_data_window_is_empty (PSPPIRE_DATA_WINDOW (de)))
+ window = de;
+ else
+ window = PSPPIRE_WINDOW (psppire_data_window_new (NULL));
+#else
+ window = PSPPIRE_WINDOW (psppire_default_data_window ());
+#endif
+
+ psppire_window_load (window, name);
+ gtk_widget_show (GTK_WIDGET (window));
+ }
+ else
+ open_syntax_window (name);
+
+ g_free (sysname);
+ g_free (name);
+ }
+ break;
+ default:
+ break;
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
/* Puts FILE_NAME into the recent list.
If it's already in the list, it moves it to the top
diff --git a/src/ui/gui/psppire-window.h b/src/ui/gui/psppire-window.h
index 19ed97e..f65e9e3 100644
--- a/src/ui/gui/psppire-window.h
+++ b/src/ui/gui/psppire-window.h
@@ -107,6 +107,8 @@ gint psppire_window_query_save (PsppireWindow *);
void psppire_window_save (PsppireWindow *w);
gboolean psppire_window_load (PsppireWindow *w, const gchar *file);
+void psppire_window_open (PsppireWindow *de);
+GtkWidget *psppire_window_file_chooser_dialog (PsppireWindow *toplevel);
G_END_DECLS
diff --git a/src/ui/gui/syntax-editor.ui b/src/ui/gui/syntax-editor.ui
index c943662..e65eef6 100644
--- a/src/ui/gui/syntax-editor.ui
+++ b/src/ui/gui/syntax-editor.ui
@@ -29,21 +29,9 @@
</object>
</child>
<child>
- <object class="GtkAction" id="open2">
+ <object class="GtkAction" id="file_open">
<property name="stock-id">gtk-open</property>
- <property name="name">open2</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="file_open_syntax">
- <property name="name">file_open_syntax</property>
- <property name="label" translatable="yes">_Syntax</property>
- </object>
- </child>
- <child>
- <object class="GtkAction" id="file_open_data">
- <property name="name">file_open_data</property>
- <property name="label" translatable="yes">_Data</property>
+ <property name="name">file_open</property>
</object>
</child>
<child>
@@ -150,10 +138,7 @@
<menuitem action="file_new_syntax"/>
<menuitem action="file_new_data"/>
</menu>
- <menu action="open2">
- <menuitem action="file_open_syntax"/>
- <menuitem action="file_open_data"/>
- </menu>
+ <menuitem action="file_open"/>
<menuitem action="file_save"/>
<menuitem action="file_save_as"/>
<separator/>
--
1.7.2.5
- [datasets 00/18] Implement multiple datasets support, Ben Pfaff, 2011/05/01
- [datasets 07/18] psppire-window: Use g_string_append_unichar() instead of global var., Ben Pfaff, 2011/05/01
- [datasets 08/18] gui: Include only <gtk/gtk.h> to use GTK+., Ben Pfaff, 2011/05/01
- [datasets 01/18] gui: Always convert file names to UTF-8 for use in syntax., Ben Pfaff, 2011/05/01
- [datasets 14/18] gui: Fix g_object_get() memory leaks for PsppireWindow's filename., Ben Pfaff, 2011/05/01