Mercurial > octave
changeset 23380:c319e6d737f2
Backed out changeset 7332287221a9
author | Torsten <mttl@mailbox.org> |
---|---|
date | Mon, 10 Apr 2017 07:02:42 +0200 |
parents | 2a122c3fd80f |
children | e15ffa2b2262 |
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, 196 insertions(+), 384 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/external-editor-interface.cc Sun Apr 09 22:21:46 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/* - -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); -} -
--- a/libgui/src/m-editor/external-editor-interface.h Sun Apr 09 22:21:46 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - -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 Sun Apr 09 22:21:46 2017 +0200 +++ b/libgui/src/m-editor/file-editor-interface.h Mon Apr 10 07:02:42 2017 +0200 @@ -68,6 +68,8 @@ 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 Sun Apr 09 22:21:46 2017 +0200 +++ b/libgui/src/m-editor/file-editor.cc Mon Apr 10 07:02:42 2017 +0200 @@ -27,7 +27,6 @@ #if defined (HAVE_QSCINTILLA) #include "file-editor.h" -#include "external-editor-interface.h" #include "resource-manager.h" #include "shortcut-manager.h" @@ -35,6 +34,7 @@ #include <QFile> #include <QFileDialog> #include <QFont> +#include <QInputDialog> #include <QMessageBox> #include <QMimeData> #include <QProcess> @@ -229,6 +229,48 @@ } 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 @@ -321,10 +363,28 @@ if (settings->value ("useCustomFileEditor",false).toBool ()) { - // 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 > -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 (); + } if (line < 0 && ! file_name.isEmpty ()) handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (), @@ -618,6 +678,92 @@ } 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) { @@ -1762,6 +1908,17 @@ 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 *))); @@ -1875,7 +2032,7 @@ connect (f, SIGNAL (edit_mfile_request (const QString&, const QString&, const QString&, int)), - main_win (), SLOT (handle_edit_mfile_request (const QString&, + this, SLOT (handle_edit_mfile_request (const QString&, const QString&, const QString&, int)));
--- a/libgui/src/m-editor/file-editor.h Sun Apr 09 22:21:46 2017 +0200 +++ b/libgui/src/m-editor/file-editor.h Mon Apr 10 07:02:42 2017 +0200 @@ -205,6 +205,8 @@ 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); @@ -277,6 +279,8 @@ 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); @@ -306,6 +310,7 @@ 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 Sun Apr 09 22:21:46 2017 +0200 +++ b/libgui/src/main-window.cc Mon Apr 10 07:02:42 2017 +0200 @@ -27,7 +27,6 @@ #include <QKeySequence> #include <QApplication> -#include <QInputDialog> #include <QLabel> #include <QMenuBar> #include <QMenu> @@ -65,8 +64,18 @@ #include "symtab.h" #include "version.h" #include "utils.h" -#include <oct-map.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 +} octave_interpreter::octave_interpreter (octave::application *app_context) : QObject (), thread_manager (), m_app_context (app_context) @@ -146,15 +155,7 @@ history_window = new history_dock_widget (this); file_browser_window = new files_dock_widget (this); doc_browser_window = new documentation_dock_widget (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 + editor_window = create_default_editor (this); workspace_window = new workspace_view (this); } @@ -200,7 +201,6 @@ // 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) { - handle_edit_mfile_request (name, QString (), QString (), line); + emit edit_mfile_request (name, QString (), QString (), line); } void @@ -1390,154 +1390,7 @@ 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) { @@ -1793,10 +1646,12 @@ 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&)), - _active_editor, + editor_window, SLOT (handle_edit_file_request (const QString&))); +#endif connect (_octave_qt_link, SIGNAL (insert_debugger_pointer_signal (const QString&, int)), @@ -1939,8 +1794,10 @@ _exit_action = file_menu->addAction (tr ("Exit")); _exit_action->setShortcutContext (Qt::ApplicationShortcut); +#if defined (HAVE_QSCINTILLA) connect (_open_action, SIGNAL (triggered ()), - _active_editor, SLOT (request_open_file ())); + editor_window, SLOT (request_open_file ())); +#endif connect (_load_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_load_workspace_request ())); @@ -1969,18 +1826,13 @@ _new_figure_action = new_menu->addAction (tr ("New Figure")); _new_figure_action->setEnabled (true); +#if defined (HAVE_QSCINTILLA) connect (_new_script_action, SIGNAL (triggered ()), - this, SLOT (request_new_script ())); + editor_window, SLOT (request_new_script ())); + connect (_new_function_action, SIGNAL (triggered ()), - 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))); + editor_window, SLOT (request_new_function ())); +#endif connect (_new_figure_action, SIGNAL (triggered ()), this, SLOT (handle_new_figure_request ()));
--- a/libgui/src/main-window.h Sun Apr 09 22:21:46 2017 +0200 +++ b/libgui/src/main-window.h Mon Apr 10 07:02:42 2017 +0200 @@ -40,7 +40,6 @@ // Editor includes #include "file-editor-interface.h" -#include "external-editor-interface.h" // QTerminal includes #include "QTerminal.h" @@ -125,7 +124,7 @@ void init_terminal_size_signal (void); void new_file_signal (const QString&); void open_file_signal (const QString&); - void open_file_signal (const QString& file, const QString& enc, int line); + void edit_mfile_request (const QString&, const QString&, const QString&, int); void show_doc_signal (const QString&); @@ -196,11 +195,6 @@ 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, @@ -267,7 +261,6 @@ private slots: void disable_menu_shortcuts (bool disable); - void restore_create_file_setting (); protected: void closeEvent (QCloseEvent * closeEvent); @@ -352,9 +345,6 @@ 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 Sun Apr 09 22:21:46 2017 +0200 +++ b/libgui/src/module.mk Mon Apr 10 07:02:42 2017 +0200 @@ -98,7 +98,6 @@ 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 \ @@ -147,7 +146,6 @@ 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 \ @@ -178,7 +176,6 @@ 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 \