Enabled remaining items in syntax editor's Run menu.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 23 Dec 2006 23:05:59 +0000 (23:05 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 23 Dec 2006 23:05:59 +0000 (23:05 +0000)
Removed global variable 'the_lexer'.

src/ui/gui/psppire.c
src/ui/gui/syntax-editor.c
src/ui/gui/syntax-editor.glade
src/ui/gui/syntax-editor.h

index 59dde1b082f44fe96191361a16bb01db33cd6c3d..f0041eba4ec07b0f57ff072226a8695f54338600 100644 (file)
@@ -78,7 +78,6 @@ PsppireVarStore *the_var_store = 0;
 void create_icon_factory (void);
 
 struct source_stream *the_source_stream ;
-struct lexer *the_lexer;
 struct dataset * the_dataset = NULL;
 
 
@@ -130,8 +129,6 @@ main(int argc, char *argv[])
                          fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
                          );
 
-  the_lexer = lex_create (the_source_stream);
-
   the_dataset = create_dataset (factory);
 
   message_dialog_init (the_source_stream);
index 05a4c8851b09019fd156db44fbfcd6e95f78bf6c..31307978a970df67e08330532581affc5d30ae4d 100644 (file)
 
 #include "window-manager.h"
 
+#include <language/lexer/lexer.h>
 #include <language/command.h>
 #include <data/procedure.h>
 #include "syntax-editor.h"
 #include "syntax-editor-source.h"
 
 extern struct source_stream *the_source_stream ;
-extern struct lexer *the_lexer;
 extern struct dataset *the_dataset;
 
 static gboolean save_editor_to_file (struct syntax_editor *se,
@@ -196,19 +196,14 @@ on_quit (GtkMenuItem *menuitem, gpointer    user_data)
 }
 
 static void
-on_run_all (GtkMenuItem *menuitem, gpointer user_data)
+execute_syntax (const struct syntax_editor *se, GtkTextIter start,
+               GtkTextIter stop)
 {
-  GtkTextIter begin, end;
-  struct syntax_editor *se = user_data;
-
-  gtk_text_buffer_get_iter_at_line (se->buffer, &begin, 0);
-  gtk_text_buffer_get_iter_at_line (se->buffer, &end, -1);
-
   getl_append_source (the_source_stream,
-                     create_syntax_editor_source (se, begin, end));
+                     create_syntax_editor_source (se, start, stop));
   for (;;)
     {
-      int result = cmd_parse (the_lexer, the_dataset,
+      int result = cmd_parse (se->lexer, the_dataset,
                              proc_has_source (the_dataset)
                              ? CMD_STATE_DATA : CMD_STATE_INITIAL);
 
@@ -217,6 +212,87 @@ on_run_all (GtkMenuItem *menuitem, gpointer user_data)
     }
 }
 
+/* Parse and execute all the text in the buffer */
+static void
+on_run_all (GtkMenuItem *menuitem, gpointer user_data)
+{
+  GtkTextIter begin, end;
+  struct syntax_editor *se = user_data;
+
+  gtk_text_buffer_get_iter_at_line (se->buffer, &begin, 0);
+  gtk_text_buffer_get_iter_at_line (se->buffer, &end, -1);
+
+
+  execute_syntax (se, begin, end);
+}
+
+/* Parse and execute the currently selected text */
+static void
+on_run_selection (GtkMenuItem *menuitem, gpointer user_data)
+{
+  GtkTextIter begin, end;
+  struct syntax_editor *se = user_data;
+
+  if ( gtk_text_buffer_get_selection_bounds (se->buffer, &begin, &end) )
+    execute_syntax (se, begin, end);
+}
+
+
+/* Parse and execute the current line */
+static void
+on_run_current_line (GtkMenuItem *menuitem, gpointer user_data)
+{
+  GtkTextIter begin, end;
+  GtkTextIter here;
+  gint line;
+
+  struct syntax_editor *se = user_data;
+
+  /* Get the current line */
+  gtk_text_buffer_get_iter_at_mark (se->buffer,
+                                   &here,
+                                   gtk_text_buffer_get_insert (se->buffer)
+                                   );
+
+  line = gtk_text_iter_get_line (&here) ;
+
+  /* Now set begin and end to the start of this line, and start of
+     following line respectively */
+  gtk_text_buffer_get_iter_at_line (se->buffer, &begin, line);
+  gtk_text_buffer_get_iter_at_line (se->buffer, &end, line + 1);
+
+  execute_syntax (se, begin, end);
+}
+
+
+
+/* Parse and execute the from the current line, to the end of the
+   buffer */
+static void
+on_run_to_end (GtkMenuItem *menuitem, gpointer user_data)
+{
+  GtkTextIter begin, end;
+  GtkTextIter here;
+  gint line;
+
+  struct syntax_editor *se = user_data;
+
+  /* Get the current line */
+  gtk_text_buffer_get_iter_at_mark (se->buffer,
+                                   &here,
+                                   gtk_text_buffer_get_insert (se->buffer)
+                                   );
+
+  line = gtk_text_iter_get_line (&here) ;
+
+  /* Now set begin and end to the start of this line, and end of buffer
+     respectively */
+  gtk_text_buffer_get_iter_at_line (se->buffer, &begin, line);
+  gtk_text_buffer_get_iter_at_line (se->buffer, &end, -1);
+
+  execute_syntax (se, begin, end);
+}
+
 
 
 
@@ -241,64 +317,84 @@ new_syntax_editor (void)
   e->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);
 
   g_signal_connect (get_widget_assert (xml,"file_new_syntax"),
                    "activate",
-                   G_CALLBACK(new_syntax_window),
+                   G_CALLBACK (new_syntax_window),
                    e->window);
 
   g_signal_connect (get_widget_assert (xml,"file_open_syntax"),
                    "activate",
-                   G_CALLBACK(open_syntax_window),
+                   G_CALLBACK (open_syntax_window),
                    e->window);
 
   g_signal_connect (get_widget_assert (xml,"file_new_data"),
                    "activate",
-                   G_CALLBACK(new_data_window),
+                   G_CALLBACK (new_data_window),
                    e->window);
 
   g_signal_connect (get_widget_assert (xml,"file_open_data"),
                    "activate",
-                   G_CALLBACK(open_data_window),
+                   G_CALLBACK (open_data_window),
                    e->window);
 
 
   g_signal_connect (get_widget_assert (xml,"help_about"),
                    "activate",
-                   G_CALLBACK(about_new),
+                   G_CALLBACK (about_new),
                    e->window);
 
 
 #if 0
 
-  g_signal_connect (get_widget_assert (xml,"file_quit"),
-                   "activate",
-                   G_CALLBACK(on_quit),
-                   se);
-
   g_signal_connect (get_widget_assert (xml,"file_save"),
                    "activate",
-                   G_CALLBACK(on_syntax_save),
+                   G_CALLBACK (on_syntax_save),
                    se);
 
   g_signal_connect (get_widget_assert (xml,"file_save_as"),
                    "activate",
-                   G_CALLBACK(on_syntax_save_as),
+                   G_CALLBACK (on_syntax_save_as),
                    se);
 
 #endif
 
+  g_signal_connect (get_widget_assert (xml,"file_quit"),
+                   "activate",
+                   G_CALLBACK (on_quit),
+                   se);
+
+
   g_signal_connect (get_widget_assert (xml,"run_all"),
                    "activate",
-                   G_CALLBACK(on_run_all),
+                   G_CALLBACK (on_run_all),
+                   se);
+
+
+  g_signal_connect (get_widget_assert (xml,"run_selection"),
+                   "activate",
+                   G_CALLBACK (on_run_selection),
                    se);
 
+  g_signal_connect (get_widget_assert (xml,"run_current_line"),
+                   "activate",
+                   G_CALLBACK (on_run_current_line),
+                   se);
+
+
+  g_signal_connect (get_widget_assert (xml,"run_to_end"),
+                   "activate",
+                   G_CALLBACK (on_run_to_end),
+                   se);
 
 
   g_object_unref (xml);
 
   g_signal_connect (e->window, "delete-event",
-                   G_CALLBACK(on_delete), se);
+                   G_CALLBACK (on_delete), se);
+
+
 
   return se;
 }
@@ -431,8 +527,3 @@ open_syntax_window (GtkMenuItem *menuitem, gpointer parent)
   gtk_widget_destroy (dialog);
 }
 
-
-
-
-
-
index 62e409bd7e8d88eb2d2c4556c31493d805973040..e7d32ebf4f0ff63a8a292cdedf11bf844be18d6e 100644 (file)
                  <child>
                    <widget class="GtkMenuItem" id="run_selection">
                      <property name="visible">True</property>
-                     <property name="sensitive">False</property>
                      <property name="label" translatable="yes">Selection</property>
                      <property name="use_underline">True</property>
                    </widget>
                  <child>
                    <widget class="GtkMenuItem" id="run_current_line">
                      <property name="visible">True</property>
-                     <property name="sensitive">False</property>
                      <property name="label" translatable="yes">Current Line</property>
                      <property name="use_underline">True</property>
                    </widget>
                  <child>
                    <widget class="GtkMenuItem" id="run_to_end">
                      <property name="visible">True</property>
-                     <property name="sensitive">False</property>
                      <property name="label" translatable="yes">To End</property>
                      <property name="use_underline">True</property>
                    </widget>
index cfb49803dea1afbd2ecaadef7854f546eb760b95..0d366831b988fc817fa41689b71d4d8d732e1a25 100644 (file)
 
 #include "window-manager.h"
 
+struct lexer;
+
 struct syntax_editor
 {
   struct editor_window parent;
   GtkTextBuffer *buffer;  /* The buffer which contains the text */
+  struct lexer *lexer;    /* Lexer to parse syntax */
 };