gui: Fix File|Open in syntax editor.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 29 Apr 2011 04:12:27 +0000 (21:12 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 3 May 2011 14:52:49 +0000 (07:52 -0700)
It didn't do anything.

src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-syntax-window.c
src/ui/gui/psppire-window.c
src/ui/gui/psppire-window.h
src/ui/gui/syntax-editor.ui

index 7e248f8ed97beb781b0ad46ef9b4a3fd0c2a3464..51b853c1bc2f55c4585df893da305b587299093b 100644 (file)
@@ -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));
 
index 45b6521255aebd5c5bb32e5ac4227556a83e5f3f..2e90ba76535ac69733731a4207aaf69f38d23cc5 100644 (file)
@@ -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),
index 369ece50257566a6e420d081118f62701fe05288..a3339ec8a92f4ca5420d024a58da74fddc901b10 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <config.h>
 
+#include "psppire-window.h"
 
 #include <gtk/gtk.h>
 
 #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
index 19ed97ecb3dcf382e2f291150f89a4a6753a2d48..f65e9e3cf31a2fd6900e5827cc5d7ecf85bc7f39 100644 (file)
@@ -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
index c9436629e58779d6922bf4e795afbd35d675ca30..e65eef66ccd85067d336b121d6d034ca12db7992 100644 (file)
           </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>
             <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/>