annotate libgui/src/external-editor-interface.cc @ 23385:41639665aa34

improve opening files from gui when built without qscintilla (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 and removed request_open_file into the main window * file-editor.cc: include external-editor-interface.h; (file_editor): file encoding tracked in main window; (request_new_function): moved into main window; (request_open_file (void)): moved to main window; (request_open_files): moved to main window; (handle_combo_enc_current_index): moved to 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, handle_edit_mfile_request, request_open_file (void), request_open_files, handle_combo_enc_current_index, and class variable _file_encodinginto the main window; * main-window.cc (main_window): initialize _file_encoding to empty string, set external editor interface and store active editor for connecting signals; (~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; (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; (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, slot for opening files now in main window (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, moved request_open_file, set_file_encoding, request_open_files, and class variable _file_encoding to here * module.mk: added new files external-editor-interface.cc/h
author Torsten <mttl@mailbox.org>
date Tue, 11 Apr 2017 08:00:23 +0200
parents
children 9107bae20480
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23385
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
1 /*
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
2
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
3 Copyright (C) 2017 Torsten
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
4
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
5 This file is part of Octave.
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
6
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
10 (at your option) any later version.
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
11
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
15 GNU General Public License for more details.
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
16
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
20
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
21 */
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
22
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
23 #if defined (HAVE_CONFIG_H)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
24 # include "config.h"
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
25 #endif
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
26
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
27 #include <QSettings>
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
28 #include <QMessageBox>
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
29 #include <QProcess>
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
30
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
31 #include "external-editor-interface.h"
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
32 #include "resource-manager.h"
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
33
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
34 external_editor_interface::external_editor_interface (QWidget *p)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
35 : QWidget (p)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
36 { };
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
37
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
38 // Get and verify the settings of the external editor program
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
39 QString
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
40 external_editor_interface::external_editor ()
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
41 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
42 QSettings *settings = resource_manager::get_settings ();
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
43 QString editor = settings->value ("customFileEditor").toString ();
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
44
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
45 // check the settings (avoid an empty string)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
46 if (editor.trimmed ().isEmpty ())
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
47 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
48 QMessageBox *msgBox = new QMessageBox (QMessageBox::Warning,
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
49 tr ("Octave Editor"),
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
50 tr ("There is no custom editor configured yet.\n"
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
51 "Do you want to open the preferences?"),
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
52 QMessageBox::No | QMessageBox::Yes);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
53 msgBox->setDefaultButton (QMessageBox::Yes);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
54 msgBox->setAttribute (Qt::WA_DeleteOnClose);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
55 int button = msgBox->exec ();
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
56
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
57 if (button == QMessageBox::Yes)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
58 emit request_settings_dialog ("editor");
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
59 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
60
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
61 return editor;
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
62 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
63
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
64 // Calling the external editor
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
65 bool
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
66 external_editor_interface::call_custom_editor (const QString& file, int line)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
67 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
68 if (line > -1) // check for a specific line (debugging)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
69 return true; // yes: do not open a file in external editor
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
70
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
71 QString editor = external_editor ();
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
72 if (editor.isEmpty ())
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
73 return true;
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
74
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
75 // replace macros
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
76 editor.replace ("%f", file);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
77 editor.replace ("%l", QString::number (line));
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
78
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
79 // start the process and check for success
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
80 bool started_ok = QProcess::startDetached (editor);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
81
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
82 if (started_ok != true)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
83 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
84 QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical,
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
85 tr ("Octave Editor"),
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
86 tr ("Could not start custom file editor\n%1").
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
87 arg (editor),
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
88 QMessageBox::Ok);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
89
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
90 msgBox->setWindowModality (Qt::NonModal);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
91 msgBox->setAttribute (Qt::WA_DeleteOnClose);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
92 msgBox->show ();
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
93 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
94
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
95 return started_ok;
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
96 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
97
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
98
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
99 // Slots for the several signals for invoking the editor
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
100
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
101 void
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
102 external_editor_interface::request_new_file (const QString&)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
103 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
104 call_custom_editor ();
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
105 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
106
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
107 void
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
108 external_editor_interface::request_open_file (const QString& file_name,
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
109 const QString&, int line, bool, bool, bool, const QString&)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
110 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
111 call_custom_editor (file_name, line);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
112 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
113
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
114 void
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
115 external_editor_interface::handle_edit_file_request (const QString& file)
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
116 {
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
117 call_custom_editor (file);
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
118 }
41639665aa34 improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff changeset
119