Mercurial > octave
changeset 23378:2cee3976d88f
provide open file dialog even when built without qscintilla (bug #39179)
* external-editor-interface.cc (request_open_file (QString,int)): removed
* external-editor-interface.h: removed request_open_file (QString, int)
* file-editor-interface.h: removed request_open_file ()
* file-editor.cc (file_editor): file encoding tracked in main window;
(request_open_file (void)): moved to main window;
(handle_combo_enc_current_index): moved to main window;
(call_custom_editor): use request_open_file (file_name, QString (), line)
for calling the external editor, making one version of this function
obsolete;
(request_open_files): moved to main window;
* file-editor.h: moved request_open_file (void), request_open_files
handle_combo_enc_current_index and class variable _file_encoding to
main window
* main-window.cc (main_window): initialize _file_encoding to empty string;
(request_open_file): moved from file editor to here;
(set_file_encoding): moved from file editor to here, old name was
handle_combo_enc_current_index;
(request_open_files): moved from file editor to here;
(construct_file_menu): slot for opening files now in main window
* main-window.h: request_open_file (void), set_file_encoding,
request_open_files and class variable _file_encoding moved to here
author | Torsten <mttl@mailbox.org> |
---|---|
date | Sun, 09 Apr 2017 20:08:15 +0200 |
parents | f1bf2590272a |
children | 2a122c3fd80f |
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 |
diffstat | 7 files changed, 92 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/external-editor-interface.cc Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/m-editor/external-editor-interface.cc Sun Apr 09 20:08:15 2017 +0200 @@ -103,12 +103,6 @@ // 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 ();
--- a/libgui/src/m-editor/external-editor-interface.h Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/m-editor/external-editor-interface.h Sun Apr 09 20:08:15 2017 +0200 @@ -43,7 +43,6 @@ 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,
--- a/libgui/src/m-editor/file-editor-interface.h Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/m-editor/file-editor-interface.h Sun Apr 09 20:08:15 2017 +0200 @@ -68,7 +68,6 @@ 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,
--- a/libgui/src/m-editor/file-editor.cc Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/m-editor/file-editor.cc Sun Apr 09 20:08:15 2017 +0200 @@ -72,8 +72,6 @@ setVisible (false); setAcceptDrops (true); - - _file_encoding = QString (); // for selecting an encoding in open dialog } file_editor::~file_editor (void) @@ -228,69 +226,6 @@ } } -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<QGridLayout*> (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 @@ -324,7 +259,7 @@ // use the external editor interface for handling the call external_editor_interface ext_editor (main_win ()); - ext_editor.request_open_file (file_name, line); + ext_editor.request_open_file (file_name, QString (), line); if (line < 0 && ! file_name.isEmpty ()) handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (), @@ -353,16 +288,6 @@ 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
--- a/libgui/src/m-editor/file-editor.h Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/m-editor/file-editor.h Sun Apr 09 20:08:15 2017 +0200 @@ -205,7 +205,6 @@ 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); @@ -298,7 +297,6 @@ 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, @@ -307,8 +305,6 @@ 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); @@ -467,8 +463,6 @@ bool _closed; - QString _file_encoding; - enum { MaxMRUFiles = 10 }; QMenu *_mru_file_menu; QAction *_mru_file_actions[MaxMRUFiles];
--- a/libgui/src/main-window.cc Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/main-window.cc Sun Apr 09 20:08:15 2017 +0200 @@ -136,7 +136,8 @@ _clipboard (QApplication::clipboard ()), _prevent_readline_conflicts (true), _suppress_dbg_location (true), - _start_gui (app_context && app_context->start_gui_p ()) + _start_gui (app_context && app_context->start_gui_p ()), + _file_encoding (QString ()) { if (_start_gui) { @@ -1398,6 +1399,89 @@ // 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<QGridLayout*> ( + 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) @@ -1940,7 +2024,7 @@ _exit_action->setShortcutContext (Qt::ApplicationShortcut); connect (_open_action, SIGNAL (triggered ()), - _active_editor, SLOT (request_open_file ())); + this, SLOT (request_open_file ())); connect (_load_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_load_workspace_request ()));
--- a/libgui/src/main-window.h Sun Apr 09 17:45:57 2017 +0100 +++ b/libgui/src/main-window.h Sun Apr 09 20:08:15 2017 +0200 @@ -196,6 +196,7 @@ 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, @@ -268,6 +269,8 @@ 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); @@ -449,6 +452,8 @@ bool _prevent_readline_conflicts; bool _suppress_dbg_location; bool _start_gui; + + QString _file_encoding; }; class news_reader : public QObject