changeset 23376:7332287221a9

improve usage without qscintilla by external editor interface (bug #39179) * external-editor-interface.cc/h: new class with an interface for an external editor, which is used by preference or if qscintilla is not available; (external_editor_interface): ctor, connect a signal for opening the settings; (external_editor): check for an external editor being set in the settings; (call_custom_editor): call the custom editor; (request_open_file, request_open_file, handle_edit_file_request): slots for the various ways for opening a file * file-editor-interface.h: moved request_new_function into the main window * file-editor.cc: include external-editor-interface.h; (request_new_function): moved into main window; (restore_create_file_setting): moved into main window; (request_new_script): moved into main window; (restore_create_file_setting): moved into main window; (call_custom_editor): use external_editor_interface; (handle_edit_mfile_request): moved into main window; (construct): moved some signal connection into the main window; (add_file_editor_tab): update signal connection to moved slots; * file-editor.h: moved request_new_function and handle_edit_mfile_request into the main window; * main-window.cc (create_default_editor): removed staic function; (main_window): set editor window or external editor interface; (~main_window): delete external_editor_interface; (edit_mfile): directly use slot handle_edit_mfile_request moved here; (handle_edit_mfile_request): moved from editor to here; (request_new_function): moved from editor to here; (restore_create_file_setting): moved from editor to here; (construct_octave_qt_link): connect signals to slots in editor or external editor interface; (construct_file_menu): connect signals to slots in editor or external editor interface; (construct_new_menu): connect signals to slots in editor, external editor interface, or to slots moved here; * main-window.h: update signals according to moved slots, namely request_new_function, request_new_script, handle_edit_mfile_request, restore_create_file_setting * module.mk: added new files external-editor-interface.cc/h
author Torsten <mttl@mailbox.org>
date Sun, 09 Apr 2017 07:46:46 +0200
parents 0c59e3b744dd
children f1bf2590272a
files libgui/src/m-editor/external-editor-interface.cc libgui/src/m-editor/external-editor-interface.h libgui/src/m-editor/file-editor-interface.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk
diffstat 8 files changed, 384 insertions(+), 196 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/m-editor/external-editor-interface.cc	Sun Apr 09 07:46:46 2017 +0200
@@ -0,0 +1,129 @@
+/*
+
+Copyright (C) 2017 Torsten
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+Octave is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include <QSettings>
+#include <QMessageBox>
+#include <QProcess>
+
+#include "external-editor-interface.h"
+#include "resource-manager.h"
+
+external_editor_interface::external_editor_interface (QWidget *main_win)
+    : QWidget (main_win)
+{
+  // Connect the signal for displaying a specific preference dialog
+  connect (this, SIGNAL (request_settings_dialog (const QString&)),
+           main_win, SLOT (process_settings_dialog_request (const QString&)));
+};
+
+// Get and verify the settings of the external editor program
+QString
+external_editor_interface::external_editor ()
+{
+  QSettings *settings = resource_manager::get_settings ();
+  QString editor = settings->value ("customFileEditor").toString ();
+
+  // check the settings (avoid an empty string)
+  if (editor.trimmed ().isEmpty ())
+    {
+      QMessageBox *msgBox = new QMessageBox (QMessageBox::Warning,
+                              tr ("Octave Editor"),
+                              tr ("There is no custom editor configured yet.\n"
+                                  "Do you want to open the preferences?"),
+                              QMessageBox::No | QMessageBox::Yes);
+      msgBox->setDefaultButton (QMessageBox::Yes);
+      msgBox->setAttribute (Qt::WA_DeleteOnClose);
+      int button = msgBox->exec ();
+
+      if (button == QMessageBox::Yes)
+        emit request_settings_dialog ("editor");
+    }
+
+  return editor;
+}
+
+// Calling the external editor
+bool
+external_editor_interface::call_custom_editor (const QString& file, int line)
+{
+  if (line > -1)  // check for a specific line (debugging)
+    return true;  // yes: do not open a file in external editor
+
+  QString editor = external_editor ();
+  if (editor.isEmpty ())
+    return true;
+
+  // replace macros
+  editor.replace ("%f", file);
+  editor.replace ("%l", QString::number (line));
+
+  // start the process and check for success
+  bool started_ok = QProcess::startDetached (editor);
+
+  if (started_ok != true)
+    {
+      QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical,
+                               tr ("Octave Editor"),
+                               tr ("Could not start custom file editor\n%1").
+                               arg (editor),
+                               QMessageBox::Ok);
+
+      msgBox->setWindowModality (Qt::NonModal);
+      msgBox->setAttribute (Qt::WA_DeleteOnClose);
+      msgBox->show ();
+    }
+
+  return started_ok;
+}
+
+
+// Slots for the several signals for invoking the editor
+
+void
+external_editor_interface::request_open_file (QString file, int line)
+{
+  call_custom_editor (file, line);
+}
+
+void
+external_editor_interface::request_new_file (const QString&)
+{
+  call_custom_editor ();
+}
+
+void
+external_editor_interface::request_open_file (const QString& file_name,
+                const QString&, int line, bool, bool, bool, const QString&)
+{
+  call_custom_editor (file_name, line);
+}
+
+void
+external_editor_interface::handle_edit_file_request (const QString& file)
+{
+  call_custom_editor (file);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/m-editor/external-editor-interface.h	Sun Apr 09 07:46:46 2017 +0200
@@ -0,0 +1,62 @@
+/*
+
+Copyright (C) 2017 Torsten
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU Genera*_*)
+* l Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+Octave is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_external_editor_interface_h)
+#define octave_external_editor_interface_h 1
+
+#include <QWidget>
+#include <QString>
+
+class external_editor_interface : public QWidget
+{
+
+  Q_OBJECT
+
+public:
+
+  external_editor_interface (QWidget *main_win);
+  ~external_editor_interface () { };
+
+signals:
+
+  void request_settings_dialog (const QString&);
+
+public slots:
+
+  void request_open_file (QString file, int line);
+  void request_open_file (const QString& fileName,
+                          const QString& encoding = QString (),
+                          int line = -1, bool debug_pointer = false,
+                          bool breakpoint_marker = false, bool insert = true,
+                          const QString& cond = "");
+  void request_new_file (const QString&);
+  void handle_edit_file_request (const QString& file);
+
+private:
+
+  bool call_custom_editor (const QString& file = QString (), int line = -1);
+  QString external_editor ();
+
+};
+
+#endif
--- a/libgui/src/m-editor/file-editor-interface.h	Sat Apr 08 17:41:52 2017 -0700
+++ b/libgui/src/m-editor/file-editor-interface.h	Sun Apr 09 07:46:46 2017 +0200
@@ -68,8 +68,6 @@
 
 public slots:
   virtual void request_new_file (const QString& command = QString ()) = 0;
-  virtual void request_new_script (const QString& command = QString ()) = 0;
-  virtual void request_new_function (bool) = 0;
   virtual void request_open_file () = 0;
   virtual void request_open_file (const QString& openFileName,
                                   const QString& encoding = QString (),
--- a/libgui/src/m-editor/file-editor.cc	Sat Apr 08 17:41:52 2017 -0700
+++ b/libgui/src/m-editor/file-editor.cc	Sun Apr 09 07:46:46 2017 +0200
@@ -27,6 +27,7 @@
 #if defined (HAVE_QSCINTILLA)
 
 #include "file-editor.h"
+#include "external-editor-interface.h"
 #include "resource-manager.h"
 #include "shortcut-manager.h"
 
@@ -34,7 +35,6 @@
 #include <QFile>
 #include <QFileDialog>
 #include <QFont>
-#include <QInputDialog>
 #include <QMessageBox>
 #include <QMimeData>
 #include <QProcess>
@@ -229,48 +229,6 @@
 }
 
 void
-file_editor::request_new_script (const QString& commands)
-{
-  request_new_file (commands);
-}
-
-void
-file_editor::request_new_function (bool)
-{
-  bool ok;
-  // get the name of the new function
-  QString new_name = QInputDialog::getText (this, tr ("New Function"),
-                     tr ("New function name:\n"), QLineEdit::Normal, "", &ok);
-  if (ok && new_name.length () > 0)
-    {
-      // append suffix if it not already exists
-      if (new_name.rightRef (2) != ".m")
-        new_name.append (".m");
-      // check whether new files are created without prompt
-      QSettings *settings = resource_manager::get_settings ();
-      if (! settings->value ("editor/create_new_file",false).toBool ())
-        {
-          // no, so enable this settings and wait for end of new file loading
-          settings->setValue ("editor/create_new_file",true);
-          connect (this, SIGNAL (file_loaded_signal ()),
-                   this, SLOT (restore_create_file_setting ()));
-        }
-      // start the edit command
-      emit execute_command_in_terminal_signal ("edit " + new_name);
-    }
-}
-
-void
-file_editor::restore_create_file_setting ()
-{
-  // restore the new files creation setting
-  QSettings *settings = resource_manager::get_settings ();
-  settings->setValue ("editor/create_new_file",false);
-  disconnect (this, SIGNAL (file_loaded_signal ()),
-              this, SLOT (restore_create_file_setting ()));
-}
-
-void
 file_editor::request_open_file (void)
 {
   // Open file isn't a file_editor_tab function since the file
@@ -363,28 +321,10 @@
 
   if (settings->value ("useCustomFileEditor",false).toBool ())
     {
-      if (line > -1)  // check for a specific line (debugging)
-        return true;  // yes: do ont open a file in external editor
-
-      QString editor = settings->value ("customFileEditor").toString ();
-      editor.replace ("%f", file_name);
-      editor.replace ("%l", QString::number (line));
-
-      bool started_ok = QProcess::startDetached (editor);
-
-      if (started_ok != true)
-        {
-          QMessageBox *msgBox
-            = new QMessageBox (QMessageBox::Critical,
-                               tr ("Octave Editor"),
-                               tr ("Could not start custom file editor\n%1").
-                               arg (editor),
-                               QMessageBox::Ok, this);
-
-          msgBox->setWindowModality (Qt::NonModal);
-          msgBox->setAttribute (Qt::WA_DeleteOnClose);
-          msgBox->show ();
-        }
+      // use the external editor interface for handling the call
+      external_editor_interface ext_editor (main_win ());
+
+      ext_editor.request_open_file (file_name, line);
 
       if (line < 0 && ! file_name.isEmpty ())
         handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (),
@@ -678,92 +618,6 @@
 }
 
 void
-file_editor::handle_edit_mfile_request (const QString& fname,
-                                        const QString& ffile,
-                                        const QString& curr_dir, int line)
-{
-  // Is it a regular function within the search path? (Call __which__)
-  octave_value_list fct = F__which__ (ovl (fname.toStdString ()),0);
-  octave_map map = fct(0).map_value ();
-
-  QString type = QString::fromStdString (
-                         map.contents ("type").data ()[0].string_value ());
-  QString name = QString::fromStdString (
-                         map.contents ("name").data ()[0].string_value ());
-
-  QString message = QString ();
-  QString filename = QString ();
-
-  if (type == QString ("built-in function"))
-    {
-      // built in function: can't edit
-      message = tr ("%1 is a built-in function");
-    }
-  else if (type.isEmpty ())
-    {
-      // function not known to octave -> try directory of edited file
-      // get directory
-      QDir dir;
-      if (ffile.isEmpty ())
-        {
-          if (curr_dir.isEmpty ())
-            dir = QDir (ced);
-          else
-            dir = QDir (curr_dir);
-        }
-      else
-        dir = QDir (QFileInfo (ffile).canonicalPath ());
-
-      // function not known to octave -> try directory of edited file
-      QFileInfo file = QFileInfo (dir, fname + ".m");
-
-      if (file.exists ())
-        {
-          filename = file.canonicalFilePath (); // local file exists
-        }
-      else
-        {
-          // local file does not exist -> try private directory
-          file = QFileInfo (ffile);
-          file = QFileInfo (QDir (file.canonicalPath () + "/private"),
-                            fname + ".m");
-
-          if (file.exists ())
-            {
-              filename = file.canonicalFilePath ();  // private function exists
-            }
-          else
-            {
-              message = tr ("Can not find function %1");  // no file found
-            }
-        }
-    }
-
-  if (! message.isEmpty ())
-    {
-      QMessageBox *msgBox
-        = new QMessageBox (QMessageBox::Critical,
-                           tr ("Octave Editor"),
-                           message.arg (name),
-                           QMessageBox::Ok, this);
-
-      msgBox->setWindowModality (Qt::NonModal);
-      msgBox->setAttribute (Qt::WA_DeleteOnClose);
-      msgBox->show ();
-      return;
-    }
-
-  if (filename.isEmpty ())
-    filename = QString::fromStdString (
-                           map.contents ("file").data ()[0].string_value ());
-
-  if (! filename.endsWith (".m"))
-    filename.append (".m");
-
-  request_open_file (filename, QString (), line);  // default encoding
-}
-
-void
 file_editor::handle_insert_debugger_pointer_request (const QString& file,
                                                      int line)
 {
@@ -1908,17 +1762,6 @@
            main_win (),
            SLOT (process_settings_dialog_request (const QString&)));
 
-  connect (main_win (), SIGNAL (new_file_signal (const QString&)),
-           this, SLOT (request_new_file (const QString&)));
-
-  connect (main_win (), SIGNAL (open_file_signal (const QString&)),
-           this, SLOT (request_open_file (const QString&)));
-
-  connect (main_win (), SIGNAL (edit_mfile_request (const QString&,
-                                       const QString&, const QString&, int)),
-           this, SLOT (handle_edit_mfile_request (const QString&,
-                                       const QString&, const QString&, int)));
-
   connect (_mru_file_menu, SIGNAL (triggered (QAction *)),
            this, SLOT (request_mru_open_file (QAction *)));
 
@@ -2032,7 +1875,7 @@
 
   connect (f, SIGNAL (edit_mfile_request (const QString&, const QString&,
                                           const QString&, int)),
-           this, SLOT (handle_edit_mfile_request (const QString&,
+           main_win (), SLOT (handle_edit_mfile_request (const QString&,
                                                   const QString&,
                                                   const QString&, int)));
 
--- a/libgui/src/m-editor/file-editor.h	Sat Apr 08 17:41:52 2017 -0700
+++ b/libgui/src/m-editor/file-editor.h	Sun Apr 09 07:46:46 2017 +0200
@@ -205,8 +205,6 @@
   bool check_closing (void);
 
   void request_new_file (const QString& commands);
-  void request_new_script (const QString& commands);
-  void request_new_function (bool triggered = true);
   void request_open_file (void);
   void request_close_file (bool);
   void request_close_all_files (bool);
@@ -279,8 +277,6 @@
   void handle_update_breakpoint_marker_request (bool insert,
                                                 const QString& file, int line,
                                                 const QString& cond);
-  void handle_edit_mfile_request (const QString& name, const QString& file,
-                                  const QString& curr_dir, int line);
 
   void handle_edit_file_request (const QString& file);
 
@@ -310,7 +306,6 @@
                           const QString& cond = "");
   void request_preferences (bool);
   void request_styles_preferences (bool);
-  void restore_create_file_setting ();
 
   void handle_combo_enc_current_index (QString new_encoding);
 
--- a/libgui/src/main-window.cc	Sat Apr 08 17:41:52 2017 -0700
+++ b/libgui/src/main-window.cc	Sun Apr 09 07:46:46 2017 +0200
@@ -27,6 +27,7 @@
 
 #include <QKeySequence>
 #include <QApplication>
+#include <QInputDialog>
 #include <QLabel>
 #include <QMenuBar>
 #include <QMenu>
@@ -64,18 +65,8 @@
 #include "symtab.h"
 #include "version.h"
 #include "utils.h"
-
-static file_editor_interface *
-create_default_editor (QWidget *p)
-{
-#if defined (HAVE_QSCINTILLA)
-  return new file_editor (p);
-#else
-  octave_unused_parameter (p);
-
-  return 0;
-#endif
-}
+#include <oct-map.h>
+
 
 octave_interpreter::octave_interpreter (octave::application *app_context)
   : QObject (), thread_manager (), m_app_context (app_context)
@@ -155,7 +146,15 @@
       history_window = new history_dock_widget (this);
       file_browser_window = new files_dock_widget (this);
       doc_browser_window = new documentation_dock_widget (this);
-      editor_window = create_default_editor (this);
+#if defined (HAVE_QSCINTILLA)
+      editor_window = new file_editor (this);
+      _external_editor = 0;
+      _active_editor = editor_window;  // for connecting signals
+#else
+      editor_window = 0;
+      _external_editor = new external_editor_interface (p);
+      _active_editor = _external_editor;  // for connecting signals
+#endif
       workspace_window = new workspace_view (this);
     }
 
@@ -201,6 +200,7 @@
   // to its original pipe to capture error messages at exit.
 
   delete editor_window;     // first one for dialogs of modified editor-tabs
+  delete _external_editor;
   delete command_window;
   delete workspace_window;
   delete doc_browser_window;
@@ -312,7 +312,7 @@
 
 main_window::edit_mfile (const QString& name, int line)
 {
-  emit edit_mfile_request (name, QString (), QString (), line);
+  handle_edit_mfile_request (name, QString (), QString (), line);
 }
 
 void
@@ -1390,7 +1390,154 @@
   file_dialog->show ();
 }
 
+
+//
+// Functions related to file editing
+//
+// These are moved from editor to here for also using them when octave
+// is built without qscintilla
+//
+void
+main_window::handle_edit_mfile_request (const QString& fname,
+                                        const QString& ffile,
+                                        const QString& curr_dir, int line)
+{
+  // Is it a regular function within the search path? (Call __which__)
+  octave_value_list fct = F__which__ (ovl (fname.toStdString ()),0);
+  octave_map map = fct(0).map_value ();
+
+  QString type = QString::fromStdString (
+                         map.contents ("type").data ()[0].string_value ());
+  QString name = QString::fromStdString (
+                         map.contents ("name").data ()[0].string_value ());
+
+  QString message = QString ();
+  QString filename = QString ();
+
+  if (type == QString ("built-in function"))
+    {
+      // built in function: can't edit
+      message = tr ("%1 is a built-in function");
+    }
+  else if (type.isEmpty ())
+    {
+      // function not known to octave -> try directory of edited file
+      // get directory
+      QDir dir;
+      if (ffile.isEmpty ())
+        {
+          if (curr_dir.isEmpty ())
+            dir = QDir (_current_directory_combo_box->itemText (0));
+          else
+            dir = QDir (curr_dir);
+        }
+      else
+        dir = QDir (QFileInfo (ffile).canonicalPath ());
+
+      // function not known to octave -> try directory of edited file
+      QFileInfo file = QFileInfo (dir, fname + ".m");
+
+      if (file.exists ())
+        {
+          filename = file.canonicalFilePath (); // local file exists
+        }
+      else
+        {
+          // local file does not exist -> try private directory
+          file = QFileInfo (ffile);
+          file = QFileInfo (QDir (file.canonicalPath () + "/private"),
+                            fname + ".m");
+
+          if (file.exists ())
+            {
+              filename = file.canonicalFilePath ();  // private function exists
+            }
+          else
+            {
+              message = tr ("Can not find function %1");  // no file found
+            }
+        }
+    }
+
+  if (! message.isEmpty ())
+    {
+      QMessageBox *msgBox
+        = new QMessageBox (QMessageBox::Critical,
+                           tr ("Octave Editor"),
+                           message.arg (name),
+                           QMessageBox::Ok, this);
+
+      msgBox->setWindowModality (Qt::NonModal);
+      msgBox->setAttribute (Qt::WA_DeleteOnClose);
+      msgBox->show ();
+      return;
+    }
+
+  if (filename.isEmpty ())
+    filename = QString::fromStdString (
+                           map.contents ("file").data ()[0].string_value ());
+
+  if (! filename.endsWith (".m"))
+    filename.append (".m");
+
+  emit open_file_signal (filename, QString (), line);  // default encoding
+}
+
+// Create a new script
+void
+main_window::request_new_script (const QString& commands)
+{
+  emit new_file_signal (commands);
+}
+
+// Create a new function and open it
+void
+main_window::request_new_function (bool)
+{
+  bool ok;
+  // Get the name of the new function: Parent of the input dialog is the
+  // editor window or the main window. The latter is chosen, if a custom
+  // editor is used or qscintilla is not available
+  QWidget *p = editor_window;
+  QSettings *settings = resource_manager::get_settings ();
+  if (! p || settings->value ("useCustomFileEditor",false).toBool ())
+    p = this;
+  QString new_name = QInputDialog::getText (p, tr ("New Function"),
+                     tr ("New function name:\n"), QLineEdit::Normal, "", &ok);
+
+  if (ok && new_name.length () > 0)
+    {
+      // append suffix if it not already exists
+      if (new_name.rightRef (2) != ".m")
+        new_name.append (".m");
+      // check whether new files are created without prompt
+      QSettings *settings = resource_manager::get_settings ();
+      if (! settings->value ("editor/create_new_file",false).toBool ())
+        {
+          // no, so enable this settings and wait for end of new file loading
+          settings->setValue ("editor/create_new_file",true);
+          connect (this, SIGNAL (file_loaded_signal ()),
+                   this, SLOT (restore_create_file_setting ()));
+        }
+      // start the edit command
+      execute_command_in_terminal ("edit " + new_name);
+    }
+}
+
+void
+main_window::restore_create_file_setting ()
+{
+  // restore the new files creation setting
+  QSettings *settings = resource_manager::get_settings ();
+  settings->setValue ("editor/create_new_file",false);
+  disconnect (this, SIGNAL (file_loaded_signal ()),
+              this, SLOT (restore_create_file_setting ()));
+}
+
+
+//
 // Main subroutine of the constructor
+//
 void
 main_window::construct (void)
 {
@@ -1646,12 +1793,10 @@
                SIGNAL (show_preferences_signal (void)),
                this, SLOT (process_settings_dialog_request ()));
 
-#if defined (HAVE_QSCINTILLA)
       connect (_octave_qt_link,
                SIGNAL (edit_file_signal (const QString&)),
-               editor_window,
+               _active_editor,
                SLOT (handle_edit_file_request (const QString&)));
-#endif
 
       connect (_octave_qt_link,
                SIGNAL (insert_debugger_pointer_signal (const QString&, int)),
@@ -1794,10 +1939,8 @@
   _exit_action = file_menu->addAction (tr ("Exit"));
   _exit_action->setShortcutContext (Qt::ApplicationShortcut);
 
-#if defined (HAVE_QSCINTILLA)
   connect (_open_action, SIGNAL (triggered ()),
-           editor_window, SLOT (request_open_file ()));
-#endif
+           _active_editor, SLOT (request_open_file ()));
 
   connect (_load_workspace_action, SIGNAL (triggered ()),
            this, SLOT (handle_load_workspace_request ()));
@@ -1826,13 +1969,18 @@
   _new_figure_action = new_menu->addAction (tr ("New Figure"));
   _new_figure_action->setEnabled (true);
 
-#if defined (HAVE_QSCINTILLA)
   connect (_new_script_action, SIGNAL (triggered ()),
-           editor_window, SLOT (request_new_script ()));
-
+           this, SLOT (request_new_script ()));
   connect (_new_function_action, SIGNAL (triggered ()),
-           editor_window, SLOT (request_new_function ()));
-#endif
+           this, SLOT (request_new_function ()));
+  connect (this, SIGNAL (new_file_signal (const QString&)),
+           _active_editor, SLOT (request_new_file (const QString&)));
+  connect (this, SIGNAL (open_file_signal (const QString&)),
+           _active_editor, SLOT (request_open_file (const QString&)));
+  connect (this,
+           SIGNAL (open_file_signal (const QString&, const QString&, int)),
+           _active_editor,
+           SLOT (request_open_file (const QString&, const QString&, int)));
 
   connect (_new_figure_action, SIGNAL (triggered ()),
            this, SLOT (handle_new_figure_request ()));
--- a/libgui/src/main-window.h	Sat Apr 08 17:41:52 2017 -0700
+++ b/libgui/src/main-window.h	Sun Apr 09 07:46:46 2017 +0200
@@ -40,6 +40,7 @@
 
 // Editor includes
 #include "file-editor-interface.h"
+#include "external-editor-interface.h"
 
 // QTerminal includes
 #include "QTerminal.h"
@@ -124,7 +125,7 @@
   void init_terminal_size_signal (void);
   void new_file_signal (const QString&);
   void open_file_signal (const QString&);
-  void edit_mfile_request (const QString&, const QString&, const QString&, int);
+  void open_file_signal (const QString& file, const QString& enc, int line);
 
   void show_doc_signal (const QString&);
 
@@ -195,6 +196,11 @@
   void debug_step_out (void);
   void debug_quit (void);
 
+  void request_new_script (const QString& commands = QString ());
+  void request_new_function (bool triggered = true);
+  void handle_edit_mfile_request (const QString& name, const QString& file,
+                                  const QString& curr_dir, int line);
+
   void handle_insert_debugger_pointer_request (const QString& file, int line);
   void handle_delete_debugger_pointer_request (const QString& file, int line);
   void handle_update_breakpoint_marker_request (bool insert,
@@ -261,6 +267,7 @@
 private slots:
 
   void disable_menu_shortcuts (bool disable);
+  void restore_create_file_setting ();
 
 protected:
   void closeEvent (QCloseEvent * closeEvent);
@@ -345,6 +352,9 @@
   file_editor_interface *editor_window;
   workspace_view *workspace_window;
 
+  external_editor_interface *_external_editor;
+  QWidget *_active_editor;
+
   QList<octave_dock_widget *> dock_widget_list ();
 
   octave_dock_widget *_active_dock;
--- a/libgui/src/module.mk	Sat Apr 08 17:41:52 2017 -0700
+++ b/libgui/src/module.mk	Sun Apr 09 07:46:46 2017 +0200
@@ -98,6 +98,7 @@
 endif
 
 OCTAVE_GUI_SRC_MOC = \
+  libgui/src/m-editor/moc-external-editor-interface.cc \
   libgui/src/moc-dialog.cc \
   libgui/src/moc-documentation-dock-widget.cc \
   libgui/src/moc-files-dock-widget.cc \
@@ -146,6 +147,7 @@
   libgui/src/files-dock-widget.h \
   libgui/src/history-dock-widget.h \
   libgui/src/liboctgui-build-info.h \
+  libgui/src/m-editor/external-editor-interface.h \
   libgui/src/m-editor/file-editor-interface.h \
   libgui/src/m-editor/file-editor-tab.h \
   libgui/src/m-editor/file-editor.h \
@@ -176,6 +178,7 @@
   libgui/src/documentation-dock-widget.cc \
   libgui/src/files-dock-widget.cc \
   libgui/src/history-dock-widget.cc \
+  libgui/src/m-editor/external-editor-interface.cc \
   libgui/src/m-editor/file-editor-tab.cc \
   libgui/src/m-editor/file-editor.cc \
   libgui/src/m-editor/find-dialog.cc \