GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
external-editor-interface.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2017-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <QMessageBox>
31#include <QProcess>
32
34#include "gui-settings.h"
36#include "octave-qobject.h"
37
38namespace octave
39{
41 base_qobject& oct_qobj)
42 : QWidget (p), m_octave_qobj (oct_qobj)
43 { }
44
45 // Calling the external editor
46 bool
47 external_editor_interface::call_custom_editor (const QString& file, int line)
48 {
49 QString editor = external_editor ();
50 if (editor.isEmpty ())
51 return true;
52
53 if (line < 0)
54 line = 0;
55
56 // replace macros
57 editor.replace ("%f", file);
58 editor.replace ("%l", QString::number (line));
59
60 QStringList arguments = editor.split (QRegExp("\\s+"));
61 editor = arguments.takeFirst ();
62
63 // start the process and check for success
64 bool started_ok = QProcess::startDetached (editor, arguments);
65
66 if (started_ok != true)
67 {
68 QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical,
69 tr ("Octave Editor"),
70 tr ("Could not start custom file editor\n%1").
71 arg (editor),
72 QMessageBox::Ok);
73
74 msgBox->setWindowModality (Qt::NonModal);
75 msgBox->setAttribute (Qt::WA_DeleteOnClose);
76 msgBox->show ();
77 }
78
79 return started_ok;
80 }
81
82
83 // Slots for the several signals for invoking the editor
84
86 {
88 }
89
90 void external_editor_interface::request_open_file (const QString& file_name,
91 const QString&, int line,
92 bool, bool, bool,
93 const QString&)
94 {
95 call_custom_editor (file_name, line);
96 }
97
99 {
100 call_custom_editor (file);
101 }
102
103 // Get and verify the settings of the external editor program
105 {
108 QString editor = settings->value (global_custom_editor.key,
109 global_custom_editor.def).toString ();
110
111 // check the settings (avoid an empty string)
112 if (editor.trimmed ().isEmpty ())
113 {
114 QMessageBox *msgBox
115 = new QMessageBox (QMessageBox::Warning,
116 tr ("Octave Editor"),
117 tr ("There is no custom editor configured yet.\n"
118 "Do you want to open the preferences?"),
119 QMessageBox::No | QMessageBox::Yes);
120 msgBox->setDefaultButton (QMessageBox::Yes);
121 msgBox->setAttribute (Qt::WA_DeleteOnClose);
122
123 int button = msgBox->exec ();
124
125 if (button == QMessageBox::Yes)
126 emit request_settings_dialog ("editor");
127 }
128
129 return editor;
130 }
131}
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
void request_open_file(const QString &fileName, const QString &encoding=QString(), int line=-1, bool debug_pointer=false, bool breakpoint_marker=false, bool insert=true, const QString &cond="")
bool call_custom_editor(const QString &file=QString(), int line=-1)
external_editor_interface(QWidget *main_win, base_qobject &oct_qobj)
void handle_edit_file_request(const QString &file)
void request_settings_dialog(const QString &)
gui_settings * get_settings(void) const
const gui_pref global_custom_editor("customFileEditor", QVariant("emacs +%l %f"))
const QString key
const QVariant def