Mercurial > octave
annotate libgui/src/external-editor-interface.cc @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | 6ecc75589cbc |
children | c003947a98a7 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29052
diff
changeset
|
3 // Copyright (C) 2017-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
25 |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
27 # include "config.h" |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
28 #endif |
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 <QMessageBox> |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
31 #include <QProcess> |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
32 |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
33 #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
|
34 #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
|
35 #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
|
36 #include "octave-qobject.h" |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
37 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
38 namespace octave |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
39 { |
27620
45bb5bbaf291
don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents:
27611
diff
changeset
|
40 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
|
41 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
|
42 : 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
|
43 { } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
44 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
45 // Calling the external editor |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
46 bool |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
47 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
|
48 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
49 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
|
50 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
|
51 else |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
52 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
|
53 |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
54 QString editor = external_editor (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
55 if (editor.isEmpty ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
56 return true; |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
57 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
58 // replace macros |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
59 editor.replace ("%f", file); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
60 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
|
61 |
29052
6ecc75589cbc
avoid deprecated QProcess::startDetached function
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
62 QStringList arguments; |
6ecc75589cbc
avoid deprecated QProcess::startDetached function
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
63 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
64 // start the process and check for success |
29052
6ecc75589cbc
avoid deprecated QProcess::startDetached function
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
65 bool started_ok = QProcess::startDetached (editor, arguments); |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
66 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
67 if (started_ok != true) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
68 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
69 QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
70 tr ("Octave Editor"), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
71 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
|
72 arg (editor), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
73 QMessageBox::Ok); |
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 msgBox->setWindowModality (Qt::NonModal); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
76 msgBox->setAttribute (Qt::WA_DeleteOnClose); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
77 msgBox->show (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
78 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
79 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
80 return started_ok; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
81 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
82 |
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
83 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
84 // 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
|
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_new_file (const QString&) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
87 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
88 call_custom_editor (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
89 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
90 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
91 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
|
92 const QString&, int line, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
93 bool, bool, bool, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
94 const QString&) |
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_name, line); |
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 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
|
100 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
101 call_custom_editor (file); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
102 } |
23385
41639665aa34
improve opening files from gui when built without qscintilla (bug #39179)
Torsten <mttl@mailbox.org>
parents:
diff
changeset
|
103 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
104 // 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
|
105 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
|
106 { |
27629
8b6e928e0705
in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents:
27620
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 global_custom_editor.def).toString (); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
111 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
112 // 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
|
113 if (editor.trimmed ().isEmpty ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
114 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
115 QMessageBox *msgBox |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
116 = new QMessageBox (QMessageBox::Warning, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
117 tr ("Octave Editor"), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
118 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
|
119 "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
|
120 QMessageBox::No | QMessageBox::Yes); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
121 msgBox->setDefaultButton (QMessageBox::Yes); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
122 msgBox->setAttribute (Qt::WA_DeleteOnClose); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
123 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
124 int button = msgBox->exec (); |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
125 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
126 if (button == QMessageBox::Yes) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
127 emit request_settings_dialog ("editor"); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
128 } |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
129 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
130 return editor; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24562
diff
changeset
|
131 } |
24011
9107bae20480
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23385
diff
changeset
|
132 } |