Implemented the find dialog.
[pspp-builds.git] / src / ui / gui / data-editor.c
index 722ac2e851a9772a528408d8f5db230f6bec6828..f73aa5e20de4f4a8ff57430936a389dbcfc41769 100644 (file)
@@ -36,6 +36,7 @@
 #include "select-cases-dialog.h"
 #include "compute-dialog.h"
 #include "goto-case-dialog.h"
+#include "find-dialog.h"
 #include "comments-dialog.h"
 #include "variable-info-dialog.h"
 #include "dict-display.h"
@@ -47,6 +48,7 @@
 #include "data-editor.h"
 #include "syntax-editor.h"
 #include <language/syntax-string-source.h>
+#include <language/command.h>
 #include <libpspp/syntax-gen.h>
 #include "window-manager.h"
 
@@ -160,6 +162,27 @@ transformation_change_callback (bool transformations_pending,
 static void open_data_file (const gchar *, struct data_editor *);
 
 
+/* Puts FILE_NAME into the recent list.
+   If it's already in the list, it moves it to the top
+*/
+static void
+add_most_recent (const char *file_name)
+{
+#if RECENT_LISTS_AVAILABLE
+
+  GtkRecentManager *manager = gtk_recent_manager_get_default();
+  gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
+
+  gtk_recent_manager_remove_item (manager, uri, NULL);
+
+  if ( ! gtk_recent_manager_add_item (manager, uri))
+    g_warning ("Could not add item %s to recent list\n",uri);
+
+  g_free (uri);
+#endif
+}
+
+
 
 #if RECENT_LISTS_AVAILABLE
 
@@ -571,6 +594,16 @@ new_data_editor (void)
   g_signal_connect (de->invoke_comments_dialog, "activate",
                    G_CALLBACK (comments_dialog), de);
 
+  de->invoke_find_dialog  =
+    gtk_action_new ("find-dialog",
+                   _("Find"),
+                   _("Find Case"),
+                   "gtk-find");
+
+  g_signal_connect (de->invoke_find_dialog, "activate",
+                   G_CALLBACK (find_dialog), de);
+
+
   de->invoke_variable_info_dialog  =
     gtk_action_new ("variable-info-dialog",
                    _("Variables"),
@@ -656,6 +689,14 @@ new_data_editor (void)
                            G_CALLBACK (gtk_action_activate),
                            de->action_data_save_as);
 
+  gtk_action_connect_proxy (de->invoke_find_dialog,
+                           get_widget_assert (de->xml, "edit_find")
+                           );
+
+  gtk_action_connect_proxy (de->invoke_find_dialog,
+                           get_widget_assert (de->xml, "button-find")
+                           );
+
   gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
                            get_widget_assert (de->xml, "data_weight-cases")
                            );
@@ -1492,14 +1533,17 @@ open_data_file (const gchar *file_name, struct data_editor *de)
 
   sss = create_syntax_string_source ("GET FILE=%s.",
                                     ds_cstr (&filename));
-
-  execute_syntax (sss);
   ds_destroy (&filename);
 
-  window_set_name_from_filename ((struct editor_window *) de, file_name);
+  if (execute_syntax (sss) )
+  {
+    window_set_name_from_filename ((struct editor_window *) de, file_name);
+    add_most_recent (file_name);
+  }
 }
 
 
+
 /* Callback for the data_open action.
    Prompts for a filename and opens it */
 static void
@@ -1550,19 +1594,6 @@ open_data_dialog (GtkAction *action, struct data_editor *de)
          gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 
        open_data_file (de->file_name, de);
-
-#if RECENT_LISTS_AVAILABLE
-       {
-         GtkRecentManager *manager = gtk_recent_manager_get_default();
-         gchar *uri = g_filename_to_uri (de->file_name, NULL, NULL);
-
-         if ( ! gtk_recent_manager_add_item (manager, uri))
-           g_warning ("Could not add item %s to recent list\n",uri);
-
-         g_free (uri);
-       }
-#endif
-
       }
       break;
     default: