# HG changeset patch # User Torsten # Date 1491769306 -7200 # Node ID 2a122c3fd80f4a1bb8b466ec695d9c30b4def75d # Parent 2cee3976d88f44e583bfe7a270e30306da3442bc Backed out changeset 2cee3976d88f diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/m-editor/external-editor-interface.cc --- a/libgui/src/m-editor/external-editor-interface.cc Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/m-editor/external-editor-interface.cc Sun Apr 09 22:21:46 2017 +0200 @@ -103,6 +103,12 @@ // 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 (); diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/m-editor/external-editor-interface.h --- a/libgui/src/m-editor/external-editor-interface.h Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/m-editor/external-editor-interface.h Sun Apr 09 22:21:46 2017 +0200 @@ -43,6 +43,7 @@ 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, diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/m-editor/file-editor-interface.h --- a/libgui/src/m-editor/file-editor-interface.h Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/m-editor/file-editor-interface.h Sun Apr 09 22:21:46 2017 +0200 @@ -68,6 +68,7 @@ public slots: virtual void request_new_file (const QString& command = QString ()) = 0; + virtual void request_open_file () = 0; virtual void request_open_file (const QString& openFileName, const QString& encoding = QString (), int line = -1, diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/m-editor/file-editor.cc Sun Apr 09 22:21:46 2017 +0200 @@ -72,6 +72,8 @@ setVisible (false); setAcceptDrops (true); + + _file_encoding = QString (); // for selecting an encoding in open dialog } file_editor::~file_editor (void) @@ -226,6 +228,69 @@ } } +void +file_editor::request_open_file (void) +{ + // Open file isn't a file_editor_tab function since the file + // editor tab has yet to be created and there is no object to + // pass a signal to. Hence, functionality is here. + + // Create a NonModal message. + QFileDialog *fileDialog = new QFileDialog (this); + fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); + + // Giving trouble under KDE (problem is related to Qt signal handling on unix, + // see https://bugs.kde.org/show_bug.cgi?id=260719 , + // it had/has no effect on Windows, though) + fileDialog->setOption (QFileDialog::DontUseNativeDialog, true); + + // define a new grid layout with the extra elements + QGridLayout *extra = new QGridLayout (fileDialog); + QFrame *separator = new QFrame (fileDialog); + separator->setFrameShape (QFrame::HLine); // horizontal line as separator + separator->setFrameStyle (QFrame::Sunken); + + // combo box for encoding + QLabel *label_enc = new QLabel (tr ("File Encoding:")); + QComboBox *combo_enc = new QComboBox (); + resource_manager::combo_encoding (combo_enc); + _file_encoding = QString (); // default, no special encoding + + // track changes in the combo boxes + connect (combo_enc, SIGNAL (currentIndexChanged (QString)), + this, SLOT (handle_combo_enc_current_index (QString))); + + // build the extra grid layout + extra->addWidget (separator,0,0,1,3); + extra->addWidget (label_enc,1,0); + extra->addWidget (combo_enc,1,1); + extra->addItem (new QSpacerItem (1,20,QSizePolicy::Expanding, + QSizePolicy::Fixed), 1,2); + + // and add the extra grid layout to the dialog's layout + QGridLayout *dialog_layout = dynamic_cast (fileDialog->layout ()); + dialog_layout->addLayout (extra,dialog_layout->rowCount (),0, + 1,dialog_layout->columnCount ()); + + fileDialog->setAcceptMode (QFileDialog::AcceptOpen); + fileDialog->setViewMode (QFileDialog::Detail); + fileDialog->setFileMode (QFileDialog::ExistingFiles); + fileDialog->setDirectory (ced); + + connect (fileDialog, SIGNAL (filesSelected (const QStringList&)), + this, SLOT (request_open_files (const QStringList&))); + + fileDialog->setWindowModality (Qt::NonModal); + fileDialog->setAttribute (Qt::WA_DeleteOnClose); + fileDialog->show (); +} + +void +file_editor::handle_combo_enc_current_index (QString new_encoding) +{ + _file_encoding = new_encoding; +} + // Check whether this file is already open in the editor. QWidget * file_editor::find_tab_widget (const QString& file) const @@ -259,7 +324,7 @@ // use the external editor interface for handling the call external_editor_interface ext_editor (main_win ()); - ext_editor.request_open_file (file_name, QString (), line); + ext_editor.request_open_file (file_name, line); if (line < 0 && ! file_name.isEmpty ()) handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (), @@ -288,6 +353,16 @@ return false; } +// The following slot is called after files have been selected in the +// open file dialog, possibly with a new selected encoding stored in +// _file_encoding +void +file_editor::request_open_files (const QStringList& open_file_names) +{ + for (int i = 0; i < open_file_names.count (); i++) + request_open_file (open_file_names.at (i), _file_encoding); +} + // Open a file, if not already open, and mark the current execution location // and/or a breakpoint with condition cond. void diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/m-editor/file-editor.h Sun Apr 09 22:21:46 2017 +0200 @@ -205,6 +205,7 @@ bool check_closing (void); void request_new_file (const QString& commands); + void request_open_file (void); void request_close_file (bool); void request_close_all_files (bool); void request_close_other_files (bool); @@ -297,6 +298,7 @@ private slots: + void request_open_files (const QStringList&); void request_open_file (const QString& fileName, const QString& encoding = QString (), int line = -1, bool debug_pointer = false, @@ -305,6 +307,8 @@ void request_preferences (bool); void request_styles_preferences (bool); + void handle_combo_enc_current_index (QString new_encoding); + void show_line_numbers (bool); void show_white_space (bool); void show_eol_chars (bool); @@ -463,6 +467,8 @@ bool _closed; + QString _file_encoding; + enum { MaxMRUFiles = 10 }; QMenu *_mru_file_menu; QAction *_mru_file_actions[MaxMRUFiles]; diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/main-window.cc Sun Apr 09 22:21:46 2017 +0200 @@ -136,8 +136,7 @@ _clipboard (QApplication::clipboard ()), _prevent_readline_conflicts (true), _suppress_dbg_location (true), - _start_gui (app_context && app_context->start_gui_p ()), - _file_encoding (QString ()) + _start_gui (app_context && app_context->start_gui_p ()) { if (_start_gui) { @@ -1399,89 +1398,6 @@ // is built without qscintilla // void -main_window::request_open_file (void) -{ - // Open file isn't a file_editor_tab or editor function since the file - // might be opened in an external editor. Hence, functionality is here. - - QSettings *settings = resource_manager::get_settings (); - bool is_internal = editor_window - && ! settings->value ("useCustomFileEditor",false).toBool (); - - // Create a NonModal message. - QWidget *p = this; - if (is_internal) - p = editor_window; - QFileDialog *fileDialog = new QFileDialog (p); - fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); - - // Giving trouble under KDE (problem is related to Qt signal handling on unix, - // see https://bugs.kde.org/show_bug.cgi?id=260719 , - // it had/has no effect on Windows, though) - fileDialog->setOption (QFileDialog::DontUseNativeDialog, true); - - // define a new grid layout with the extra elements - QGridLayout *extra = new QGridLayout (fileDialog); - QFrame *separator = new QFrame (fileDialog); - separator->setFrameShape (QFrame::HLine); // horizontal line as separator - separator->setFrameStyle (QFrame::Sunken); - - if (is_internal) - { - // combo box for encoding, only when using the internal editor - QLabel *label_enc = new QLabel (tr ("File Encoding:")); - QComboBox *combo_enc = new QComboBox (); - resource_manager::combo_encoding (combo_enc); - _file_encoding = QString (); // default - - // track changes in the combo boxes - connect (combo_enc, SIGNAL (currentIndexChanged (QString)), - this, SLOT (set_file_encoding (QString))); - - // build the extra grid layout - extra->addWidget (separator,0,0,1,3); - extra->addWidget (label_enc,1,0); - extra->addWidget (combo_enc,1,1); - extra->addItem (new QSpacerItem (1,20,QSizePolicy::Expanding, - QSizePolicy::Fixed), 1,2); - - // and add the extra grid layout to the dialog's layout - QGridLayout *dialog_layout = dynamic_cast ( - fileDialog->layout ()); - dialog_layout->addLayout (extra,dialog_layout->rowCount (),0, - 1,dialog_layout->columnCount ()); - } - - fileDialog->setAcceptMode (QFileDialog::AcceptOpen); - fileDialog->setViewMode (QFileDialog::Detail); - fileDialog->setFileMode (QFileDialog::ExistingFiles); - fileDialog->setDirectory (_current_directory_combo_box->itemText (0)); - - connect (fileDialog, SIGNAL (filesSelected (const QStringList&)), - this, SLOT (request_open_files (const QStringList&))); - - fileDialog->setWindowModality (Qt::NonModal); - fileDialog->setAttribute (Qt::WA_DeleteOnClose); - fileDialog->show (); -} - -void -main_window::set_file_encoding (const QString& new_encoding) -{ - _file_encoding = new_encoding; -} - -// The following slot is called after files have been selected in the -// open file dialog., possibly with a new selected encoding stored in -// _file_encoding -void -main_window::request_open_files (const QStringList& open_file_names) -{ - for (int i = 0; i < open_file_names.count (); i++) - emit open_file_signal (open_file_names.at (i), _file_encoding, -1); -} - -void main_window::handle_edit_mfile_request (const QString& fname, const QString& ffile, const QString& curr_dir, int line) @@ -2024,7 +1940,7 @@ _exit_action->setShortcutContext (Qt::ApplicationShortcut); connect (_open_action, SIGNAL (triggered ()), - this, SLOT (request_open_file ())); + _active_editor, SLOT (request_open_file ())); connect (_load_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_load_workspace_request ())); diff -r 2cee3976d88f -r 2a122c3fd80f libgui/src/main-window.h --- a/libgui/src/main-window.h Sun Apr 09 20:08:15 2017 +0200 +++ b/libgui/src/main-window.h Sun Apr 09 22:21:46 2017 +0200 @@ -196,7 +196,6 @@ void debug_step_out (void); void debug_quit (void); - void request_open_file (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, @@ -269,8 +268,6 @@ void disable_menu_shortcuts (bool disable); void restore_create_file_setting (); - void set_file_encoding (const QString& new_encoding); - void request_open_files (const QStringList& open_file_names); protected: void closeEvent (QCloseEvent * closeEvent); @@ -452,8 +449,6 @@ bool _prevent_readline_conflicts; bool _suppress_dbg_location; bool _start_gui; - - QString _file_encoding; }; class news_reader : public QObject