Mercurial > octave
annotate libgui/src/external-editor-interface.cc @ 27805:dccc551aa83b
replace literal strings by symbolic constants for global preferences
* default-qt-settings.in: removed default values from the global section
* dialog.cc: include gui-preferences-global.h;
(FileDialog::FileDialog): replaced literals by symbolic constants
* external-editor-interface.cc: include gui-preferences-global.h;
(external_editor): replaced literals by symbolic constants
* find-files-dialog.cc: include gui-preferences-global.h;
(browse_folders): replaced literals by symbolic constants
* gui-preferences-global.h: added symbolic constants for key names and
default values for preferences in the global section of the settings file
* file-editor-tab.cc (save_file_as): replaced literals by symbolic constants
* file-editor.cc (empty_script, call_custom_editor):
replaced literals by symbolic constants
* main-window.cc (confirm_shutdown, handle_save_workspace_request,
handle_load_workspace_request, notice_settings, browse_for_directory,
request_open_file, request_new_function, handle_octave_ready):
replaced literals by symbolic constants
* resource-manager.cc (config_translators, update_network_settings):
replaced literals by symbolic constants
* settings-dialog.cc (settings_dialog, write_changed_settings):
replaced literals by symbolic constants
* shortcut-manager.cc: include gui-preferences-global.h;
(import_export): replaced literals by symbolic constants
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Thu, 12 Dec 2019 06:45:57 +0100 |
parents | 8b6e928e0705 |
children | b442ec6dda5c |
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 |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
3 Copyright (C) 2017-2019 Torsten |
23385
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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24011
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
23385
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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24011
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
23385
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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24011
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
23385
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 <QMessageBox> |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
28 #include <QProcess> |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
29 |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
30 #include "external-editor-interface.h" |
27611
0495b64288f7
use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents:
27412
diff
changeset
|
31 #include "gui-settings.h" |
27805
dccc551aa83b
replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27629
diff
changeset
|
32 #include "gui-preferences-global.h" |
27629
8b6e928e0705
in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents:
27620
diff
changeset
|
33 #include "octave-qobject.h" |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
34 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
35 namespace octave |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
36 { |
27620
45bb5bbaf291
don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents:
27611
diff
changeset
|
37 external_editor_interface::external_editor_interface (QWidget *p, |
27629
8b6e928e0705
in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents:
27620
diff
changeset
|
38 base_qobject& oct_qobj) |
8b6e928e0705
in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents:
27620
diff
changeset
|
39 : QWidget (p), m_octave_qobj (oct_qobj) |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
40 { } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
41 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
42 // Calling the external editor |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
43 bool |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
44 external_editor_interface::call_custom_editor (const QString& file, int line) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
45 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
46 if (line > -1) // check for a specific line (debugging) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
47 return true; // yes: do not open a file in external editor |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
48 else |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
49 line = 0; // no: start external editor at beginning of file |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
50 |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
51 QString editor = external_editor (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
52 if (editor.isEmpty ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
53 return true; |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
54 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
55 // replace macros |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
56 editor.replace ("%f", file); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
57 editor.replace ("%l", QString::number (line)); |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
58 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
59 // start the process and check for success |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
60 bool started_ok = QProcess::startDetached (editor); |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
61 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
62 if (started_ok != true) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
63 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
64 QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
65 tr ("Octave Editor"), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
66 tr ("Could not start custom file editor\n%1"). |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
67 arg (editor), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
68 QMessageBox::Ok); |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
69 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
70 msgBox->setWindowModality (Qt::NonModal); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
71 msgBox->setAttribute (Qt::WA_DeleteOnClose); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
72 msgBox->show (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
73 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
74 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
75 return started_ok; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
76 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
77 |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
78 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
79 // Slots for the several signals for invoking the editor |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
80 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
81 void external_editor_interface::request_new_file (const QString&) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
82 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
83 call_custom_editor (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
84 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
85 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
86 void external_editor_interface::request_open_file (const QString& file_name, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
87 const QString&, int line, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
88 bool, bool, bool, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
89 const QString&) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
90 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
91 call_custom_editor (file_name, line); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
92 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
93 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
94 void external_editor_interface::handle_edit_file_request (const QString& file) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
95 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
96 call_custom_editor (file); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
97 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
98 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
99 // Get and verify the settings of the external editor program |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
100 QString external_editor_interface::external_editor (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
101 { |
27629
8b6e928e0705
in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents:
27620
diff
changeset
|
102 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); |
8b6e928e0705
in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents:
27620
diff
changeset
|
103 gui_settings *settings = rmgr.get_settings (); |
27805
dccc551aa83b
replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27629
diff
changeset
|
104 QString editor = settings->value (global_custom_editor.key, |
dccc551aa83b
replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27629
diff
changeset
|
105 global_custom_editor.def).toString (); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
106 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
107 // check the settings (avoid an empty string) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
108 if (editor.trimmed ().isEmpty ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
109 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
110 QMessageBox *msgBox |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
111 = new QMessageBox (QMessageBox::Warning, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
112 tr ("Octave Editor"), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
113 tr ("There is no custom editor configured yet.\n" |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
114 "Do you want to open the preferences?"), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
115 QMessageBox::No | QMessageBox::Yes); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
116 msgBox->setDefaultButton (QMessageBox::Yes); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
117 msgBox->setAttribute (Qt::WA_DeleteOnClose); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
118 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
119 int button = msgBox->exec (); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
120 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
121 if (button == QMessageBox::Yes) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
122 emit request_settings_dialog ("editor"); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
123 } |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
124 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
125 return editor; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
126 } |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
127 } |