changeset 14910:41b86dc61306 gui

Removed run command, instead cding into the script directory and executing script directly. * file-editor-interface: Added methods for entering and quitting debug mode. * file-editor-tab: Removed run-command. * file-editor: Implemented methods for entering and quitting debug mode.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 02 Jul 2012 16:06:50 +0200
parents e97be88fc478
children cff522bf80c5
files gui/src/m-editor/file-editor-interface.h gui/src/m-editor/file-editor-tab.cc gui/src/m-editor/file-editor.cc gui/src/m-editor/file-editor.h gui/src/main-window.cc
diffstat 5 files changed, 41 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/gui/src/m-editor/file-editor-interface.h
+++ b/gui/src/m-editor/file-editor-interface.h
@@ -43,6 +43,9 @@
 
     virtual QMenu *debug_menu () = 0;
 
+    virtual void handle_entered_debug_mode () = 0;
+    virtual void handle_quit_debug_mode () = 0;
+
   public slots:
     virtual void request_new_file () = 0;
     virtual void request_open_file () = 0;
--- a/gui/src/m-editor/file-editor-tab.cc
+++ b/gui/src/m-editor/file-editor-tab.cc
@@ -632,7 +632,16 @@
   if (_edit_area->isModified ())
     save_file(_file_name);
 
-  _file_editor->terminal ()->sendText (QString ("run \'%1\'\n").arg (_file_name));
+  QFileInfo file_info (_file_name);
+  QString path = file_info.absolutePath ();
+  QString current_path = QString::fromStdString
+      (octave_link::instance ()->get_last_working_directory ());
+  QString function_name = file_info.fileName ();
+
+  // We have to cut off the suffix, because octave appends it.
+  function_name.chop (file_info.suffix ().length () + 1);
+  _file_editor->terminal ()->sendText (QString ("cd \'%1\'\n%2\ncd \'%3\'\n\n")
+    .arg(path).arg (function_name).arg (current_path));
   // TODO: Sending a run event crashes for long scripts. Find out why.
   //  octave_link::instance ()
   //      ->post_event (new octave_run_file_event (*this, _file_name.toStdString ()));
--- a/gui/src/m-editor/file-editor.cc
+++ b/gui/src/m-editor/file-editor.cc
@@ -64,6 +64,18 @@
 }
 
 void
+file_editor::handle_entered_debug_mode ()
+{
+  _run_action->setEnabled (false);
+}
+
+void
+file_editor::handle_quit_debug_mode ()
+{
+  _run_action->setEnabled (true);
+}
+
+void
 file_editor::request_new_file ()
 {
   file_editor_tab *fileEditorTab = new file_editor_tab (this);
@@ -360,35 +372,14 @@
   QAction *comment_selection_action   = new QAction (tr ("&Comment Selected Text"),_tool_bar);
   QAction *uncomment_selection_action = new QAction (tr ("&Uncomment Selected Text"),_tool_bar);
 
-  QAction *run_action = new QAction (QIcon(":/actions/icons/artsbuilderexecute.png"),
+  _run_action = new QAction (QIcon(":/actions/icons/artsbuilderexecute.png"),
         tr("&Run File"), _tool_bar);
 
   // some actions are disabled from the beginning
   _copy_action->setEnabled(false);
   _cut_action->setEnabled(false);
-
-  // short cuts
-  // TODO: These shortcuts are ambiguous and lead to bugs.
-//  new_action->setShortcut                       (QKeySequence::New);
-//  new_action->setShortcutContext                (Qt::WindowShortcut);
-//  open_action->setShortcut                      (QKeySequence::Open);
-//  open_action->setShortcutContext               (Qt::WindowShortcut);
-//  save_action->setShortcut                      (QKeySequence::Save);
-//  save_action->setShortcutContext               (Qt::WindowShortcut);
-//  save_as_action->setShortcut                   (QKeySequence::SaveAs);
-//  save_as_action->setShortcutContext            (Qt::WindowShortcut);
-//  undo_action->setShortcut                      (QKeySequence::Undo);
-//  undo_action->setShortcutContext               (Qt::WindowShortcut);
-//  redo_action->setShortcut                      (QKeySequence::Redo);
-//  redo_action->setShortcutContext               (Qt::WindowShortcut);
-//  _copy_action->setShortcut                     (QKeySequence::Copy);
-//  _copy_action->setShortcutContext              (Qt::WindowShortcut);
-//  _cut_action->setShortcut                      (QKeySequence::Cut);
-//  _cut_action->setShortcutContext               (Qt::WindowShortcut);
-//  paste_action->setShortcut                     (QKeySequence::Paste);
-//  paste_action->setShortcutContext              (Qt::WindowShortcut);
-  run_action->setShortcut                       (Qt::ControlModifier+ Qt::Key_R);
-  run_action->setShortcutContext                (Qt::WindowShortcut);
+  _run_action->setShortcut                      (Qt::ControlModifier+ Qt::Key_R);
+  _run_action->setShortcutContext               (Qt::WindowShortcut);
   next_bookmark_action->setShortcut             (Qt::Key_F2);
   next_bookmark_action->setShortcutContext      (Qt::WindowShortcut);
   previous_bookmark_action->setShortcut         (Qt::SHIFT + Qt::Key_F2);
@@ -412,7 +403,7 @@
   _tool_bar->addAction (_cut_action);
   _tool_bar->addAction (paste_action);
   _tool_bar->addSeparator ();
-  _tool_bar->addAction (run_action);
+  _tool_bar->addAction (_run_action);
 
   // menu bar
   QMenu *fileMenu = new QMenu (tr ("&File"), _menu_bar);
@@ -449,9 +440,9 @@
   // The other debug actions will be added by the main window.
   _menu_bar->addMenu (_debug_menu);
 
-  QMenu *runMenu = new QMenu (tr ("&Run"), _menu_bar);
-  runMenu->addAction (run_action);
-  _menu_bar->addMenu (runMenu);
+  QMenu *_run_menu = new QMenu (tr ("&Run"), _menu_bar);
+  _run_menu->addAction (_run_action);
+  _menu_bar->addMenu (_run_menu);
 
   QVBoxLayout *layout = new QVBoxLayout ();
   layout->addWidget (_menu_bar);
@@ -470,7 +461,7 @@
   connect (paste_action,             SIGNAL (triggered ()), this, SLOT (request_paste ()));
   connect (save_action,              SIGNAL (triggered ()), this, SLOT (request_save_file ()));
   connect (save_as_action,            SIGNAL (triggered ()), this, SLOT (request_save_file_as ()));
-  connect (run_action,               SIGNAL (triggered ()), this, SLOT (request_run_file ()));
+  connect (_run_action,               SIGNAL (triggered ()), this, SLOT (request_run_file ()));
   connect (toggle_bookmark_action,    SIGNAL (triggered ()), this, SLOT (request_toggle_bookmark ()));
   connect (next_bookmark_action,      SIGNAL (triggered ()), this, SLOT (request_next_bookmark ()));
   connect (previous_bookmark_action,      SIGNAL (triggered ()), this, SLOT (request_previous_bookmark ()));
--- a/gui/src/m-editor/file-editor.h
+++ b/gui/src/m-editor/file-editor.h
@@ -57,6 +57,9 @@
 
   QMenu *           debug_menu();
 
+  void handle_entered_debug_mode ();
+  void handle_quit_debug_mode ();
+
 public slots:
   void request_new_file ();
   void request_open_file ();
@@ -97,8 +100,9 @@
   QMenuBar *        _menu_bar;
   QToolBar *        _tool_bar;
   QMenu *           _debug_menu;
-  QAction*          _copy_action;
-  QAction*          _cut_action;
+  QAction *         _copy_action;
+  QAction *         _cut_action;
+  QAction *         _run_action;
   QTabWidget *      _tab_widget;
   int               _marker_breakpoint;
   lexer_octave_gui *_lexer;
--- a/gui/src/main-window.cc
+++ b/gui/src/main-window.cc
@@ -300,6 +300,7 @@
   _debug_step_over->setEnabled (true);
   _debug_step_out->setEnabled (true);
   _debug_quit->setEnabled (true);
+  _file_editor->handle_entered_debug_mode ();
 }
 
 void
@@ -311,6 +312,7 @@
   _debug_step_over->setEnabled (false);
   _debug_step_out->setEnabled (false);
   _debug_quit->setEnabled (false);
+  _file_editor->handle_quit_debug_mode ();
 }
 
 void