GNU Octave  4.4.1
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-2018 Torsten
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <QSettings>
28 #include <QMessageBox>
29 #include <QProcess>
30 
32 #include "resource-manager.h"
33 
34 namespace octave
35 {
37  : QWidget (p)
38  { }
39 
40  // Calling the external editor
41  bool
43  {
44  if (line > -1) // check for a specific line (debugging)
45  return true; // yes: do not open a file in external editor
46  else
47  line = 0; // no: start external editor at beginning of file
48 
49  QString editor = external_editor ();
50  if (editor.isEmpty ())
51  return true;
52 
53  // replace macros
54  editor.replace ("%f", file);
55  editor.replace ("%l", QString::number (line));
56 
57  // start the process and check for success
58  bool started_ok = QProcess::startDetached (editor);
59 
60  if (started_ok != true)
61  {
62  QMessageBox *msgBox = new QMessageBox (QMessageBox::Critical,
63  tr ("Octave Editor"),
64  tr ("Could not start custom file editor\n%1").
65  arg (editor),
66  QMessageBox::Ok);
67 
68  msgBox->setWindowModality (Qt::NonModal);
69  msgBox->setAttribute (Qt::WA_DeleteOnClose);
70  msgBox->show ();
71  }
72 
73  return started_ok;
74  }
75 
76 
77  // Slots for the several signals for invoking the editor
78 
80  {
82  }
83 
84  void external_editor_interface::request_open_file (const QString& file_name,
85  const QString&, int line,
86  bool, bool, bool,
87  const QString&)
88  {
89  call_custom_editor (file_name, line);
90  }
91 
93  {
95  }
96 
97  // Get and verify the settings of the external editor program
99  {
100  QSettings *settings = resource_manager::get_settings ();
101  QString editor = settings->value ("customFileEditor").toString ();
102 
103  // check the settings (avoid an empty string)
104  if (editor.trimmed ().isEmpty ())
105  {
106  QMessageBox *msgBox
107  = new QMessageBox (QMessageBox::Warning,
108  tr ("Octave Editor"),
109  tr ("There is no custom editor configured yet.\n"
110  "Do you want to open the preferences?"),
111  QMessageBox::No | QMessageBox::Yes);
112  msgBox->setDefaultButton (QMessageBox::Yes);
113  msgBox->setAttribute (Qt::WA_DeleteOnClose);
114 
115  int button = msgBox->exec ();
116 
117  if (button == QMessageBox::Yes)
118  emit request_settings_dialog ("editor");
119  }
120 
121  return editor;
122  }
123 }
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
for fields that display a single number
Definition: time.cc:441
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)
octave_value arg
Definition: pr-output.cc:3244
void handle_edit_file_request(const QString &file)
p
Definition: lu.cc:138
static QSettings * get_settings(void)
void request_settings_dialog(const QString &)
nd example The result of the integration is returned in the value of it is recommended to verify this value for difficult integrands and then a warning is issued and as may be less efficient for a smooth or otherwise well behaved integrand than other methods such as Article No
Definition: quadcc.cc:1567