GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
file-editor-tab.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 Jacob Dawid
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 (octave_file_editor_tab_h)
24 #define octave_file_editor_tab_h 1
25 
26 #include <QWidget>
27 #include <QCloseEvent>
28 #include <QFileSystemWatcher>
29 #include <QSettings>
30 #include <QFileInfo>
31 #include <Qsci/qsciapis.h>
32 #include <QStatusBar>
33 #include <QLabel>
34 #include <QComboBox>
35 
36 #include "find-dialog.h"
37 #include "octave-qscintilla.h"
38 #include "builtin-defun-decls.h"
39 
40 #include "marker.h" /* Only needed for typedef of "QIntList", which may be
41  typedefed elsewhere. Could use common location. */
42 
43 class octave_value_list;
44 
45 namespace octave
46 {
47  class file_editor;
48 
49  class file_editor_tab : public QWidget
50  {
51  Q_OBJECT
52 
53  public:
54 
55  file_editor_tab (const QString& directory = "");
56 
57  ~file_editor_tab (void);
58 
60 
61  // Will initiate close if associated with the identifier tag.
62  bool conditional_close (void);
63 
64  static void reset_cancel (void) {_cancelled = false;}
65  static bool was_cancelled (void) {return _cancelled;}
66 
67  public slots:
68 
69  void update_window_title (bool modified);
70  void handle_copy_available (bool enableCopy);
71  void handle_margin_clicked (int line, int margin,
72  Qt::KeyboardModifiers state);
73 
74  // Tells the editor tab to react on changed settings.
75  void notice_settings (const QSettings *settings, bool init = false);
76 
77  // Change to a different editor tab by identifier tag.
78  void change_editor_state (const QWidget *ID);
79 
80  // Simply transmit filename.
81  void file_name_query (const QWidget *ID);
82 
83  void set_focus (const QWidget *ID);
84  void set_current_directory (const QString& dir);
85  void context_help (const QWidget *ID, bool);
86  void context_edit (const QWidget *ID);
87  void check_modified_file (void);
88  void save_file (const QWidget *ID);
89  void save_file (const QWidget *ID, const QString& fileName,
90  bool remove_on_success);
91  void save_file_as (const QWidget *ID);
92  void print_file (const QWidget *ID);
93  void run_file (const QWidget *ID);
94  void context_run (const QWidget *ID);
95  void toggle_bookmark (const QWidget *ID);
96  void next_bookmark (const QWidget *ID);
97  void previous_bookmark (const QWidget *ID);
98  void remove_bookmark (const QWidget *ID);
99 
100  void toggle_breakpoint (const QWidget *ID);
101  void next_breakpoint (const QWidget *ID);
102  void previous_breakpoint (const QWidget *ID);
103  void remove_all_breakpoints (const QWidget *ID);
104 
105  void scintilla_command (const QWidget *, unsigned int);
106 
107  void comment_selected_text (const QWidget *ID, bool input_str);
108  void uncomment_selected_text (const QWidget *ID);
109 
110  void indent_selected_text (const QWidget *ID);
111  void unindent_selected_text (const QWidget *ID);
113  void convert_eol (const QWidget *ID, QsciScintilla::EolMode);
114 
115  void zoom_in (const QWidget *ID);
116  void zoom_out (const QWidget *ID);
117  void zoom_normal (const QWidget *ID);
118 
119  void find (const QWidget *ID, QList<QAction *>);
120  void find_next (const QWidget *ID);
121  void find_previous (const QWidget *ID);
122  void goto_line (const QWidget *ID, int line = -1);
123  void move_match_brace (const QWidget *ID, bool select);
124  void show_auto_completion (const QWidget *ID);
125 
126  void insert_debugger_pointer (const QWidget *ID, int line = -1);
127  void delete_debugger_pointer (const QWidget *ID, int line = -1);
128 
129  void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1,
130  const QString& cond = "");
131 
132  void recover_from_exit (void);
133  void set_modified (bool modified = true);
134 
135  void set_encoding (const QString& new_encoding);
136 
137  QString load_file (const QString& fileName);
138 
139  void new_file (const QString& commands = QString ());
140 
141  void file_has_changed (const QString& path, bool do_close = false);
142 
143  void handle_context_menu_edit (const QString&);
144  void handle_context_menu_break_condition (int linenr);
145 
146  void handle_request_add_breakpoint (int line, const QString& cond);
148 
149  void handle_octave_result (QObject *requester, QString& command,
151 
152  signals:
153 
154  void file_name_changed (const QString& fileName, const QString& toolTip);
155  void editor_state_changed (bool copy_available, bool is_octave_file);
157  void tab_remove_request (void);
158  void add_filename_to_list (const QString&, const QString&, QWidget *);
159  void mru_add_file (const QString& file_name, const QString& encoding);
160  void editor_check_conflict_save (const QString& saveFileName,
161  bool remove_on_success);
162  void run_file_signal (const QFileInfo& info);
163  void request_open_file (const QString&);
164  void edit_mfile_request (const QString&, const QString&,
165  const QString&, int);
166 
167  void request_find_next (void);
168  void request_find_previous (void);
169 
170  void remove_breakpoint_via_debugger_linenr (int debugger_linenr);
171  void request_remove_breakpoint_via_editor_linenr (int editor_linenr);
172  void remove_all_breakpoints (void);
173  void find_translated_line_number (int original_linenr,
174  int& translated_linenr, marker*&);
175  void find_linenr_just_before (int linenr, int& original_linenr,
176  int& editor_linenr);
177  void report_marker_linenr (QIntList& lines, QStringList& conditions);
178  void remove_position_via_debugger_linenr (int debugger_linenr);
179  void remove_all_positions (void);
180  void execute_command_in_terminal_signal (const QString&);
181 
182  // FIXME: The following is similar to "process_octave_code"
183  // signal. However, currently that signal is connected to
184  // something that simply focuses a window and not actually
185  // communicate with Octave.
186  //
187  // void evaluate_octave_command (const QString& command);
188 
189  protected:
190 
191  void closeEvent (QCloseEvent *event);
192  void set_file_name (const QString& fileName);
193 
194  private slots:
195 
196  // When user closes message box for reload question.
197  void handle_file_reload_answer (int decision);
198 
199  // When user closes message box for resave question.
200  void handle_file_resave_answer (int decision);
201 
202  // When user closes message box for modified question.
203  void handle_file_modified_answer (int decision);
204 
205  // When user closes find_dialog box.
206  void handle_find_dialog_finished (int decision);
207 
208  // When user closes QFileDialog box.
209  void handle_save_file_as_answer (const QString& fileName);
210  void handle_save_file_as_answer_close (const QString& fileName);
212  void handle_save_as_filter_selected (const QString& filter);
213  void handle_combo_eol_current_index (int index);
214  void handle_combo_enc_current_index (QString text);
215 
216  // When apis preparation has finished and is ready to save
217  void save_apis_info (void);
218 
219  // When the numer of lines changes -> adapt width of margin
220  void auto_margin_width (void);
221 
222  void handle_cursor_moved (int line, int col);
223  void handle_char_added (int character);
224  void handle_double_click (int p, int l, int modifier);
225  void handle_lines_changed (void);
226 
227  private:
228 
229  struct bp_info
230  {
231  bp_info (const QString& fname, int l = 0, const QString& cond = "");
232 
233  int line;
238  };
239 
240  bool valid_file_name (const QString& file = QString ());
241  bool exit_debug_and_clear (const QString& full_name,
242  const QString& base_name);
243  void save_file (const QString& saveFileName, bool remove_on_success = false,
244  bool restore_breakpoints = true);
245  void save_file_as (bool remove_on_success = false);
246  bool check_valid_identifier (QString file_name);
247  bool check_valid_codec (QTextCodec *codec);
248 
249  bool unchanged_or_saved (void);
250 
251  void update_lexer (void);
252  void update_lexer_settings (void);
253 
254  void show_dialog (QDialog *dlg, bool modal);
255  int check_file_modified (void);
256  void do_comment_selected_text (bool comment, bool input_str = false);
257  void do_indent_selected_text (bool indent);
259 
260  void add_breakpoint_callback (const bp_info& info);
261  void remove_breakpoint_callback (const bp_info& info);
262  void remove_all_breakpoints_callback (const bp_info& info);
263  void check_restore_breakpoints (void);
264  void center_current_line (bool always=true);
265 
266  void add_octave_apis (octave_value_list key_ovl);
267  QString get_function_name (void);
268 
269  QsciScintilla::EolMode detect_eol_mode (void);
270  void update_eol_indicator (void);
271 
273 
274  QStatusBar *_status_bar;
275  QLabel *_row_indicator;
276  QLabel *_col_indicator;
277  QLabel *_eol_indicator;
278  QLabel *_enc_indicator;
279 
280  QsciScintilla::EolMode _save_as_desired_eol;
281 
282  QString _file_name;
284  QString _ced;
285  QString _encoding;
286  QString _new_encoding;
287 
294 
295  QFileSystemWatcher _file_system_watcher;
296 
298  QStringList _bp_conditions;
299 
303 
304  QsciAPIs *_lexer_apis;
306 
307  static bool _cancelled;
308 
311  int _line;
312  int _col;
316  };
317 }
318 
319 #endif
void handle_find_dialog_finished(int decision)
void handle_file_resave_answer(int decision)
void comment_selected_text(const QWidget *ID, bool input_str)
QString load_file(const QString &fileName)
void print_file(const QWidget *ID)
void handle_char_added(int character)
void previous_bookmark(const QWidget *ID)
void convert_eol(const QWidget *ID, QsciScintilla::EolMode)
void set_focus(const QWidget *ID)
void handle_copy_available(bool enableCopy)
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
void request_remove_breakpoint_via_editor_linenr(int editor_linenr)
void remove_all_breakpoints(void)
fname
Definition: load-save.cc:767
bool valid_file_name(const QString &file=QString())
void set_modified(bool modified=true)
bool check_valid_identifier(QString file_name)
void run_file(const QWidget *ID)
void edit_mfile_request(const QString &, const QString &, const QString &, int)
QsciScintilla::EolMode _save_as_desired_eol
bp_info(const QString &fname, int l=0, const QString &cond="")
void next_breakpoint(const QWidget *ID)
void set_focus_editor_signal(QWidget *)
void editor_state_changed(bool copy_available, bool is_octave_file)
void next_bookmark(const QWidget *ID)
void handle_request_remove_breakpoint(int line)
QFileSystemWatcher _file_system_watcher
void file_has_changed(const QString &path, bool do_close=false)
void add_octave_apis(octave_value_list key_ovl)
void file_name_query(const QWidget *ID)
void handle_file_modified_answer(int decision)
void find_next(const QWidget *ID)
void scintilla_command(const QWidget *, unsigned int)
static bool was_cancelled(void)
void zoom_normal(const QWidget *ID)
void handle_save_as_filter_selected(const QString &filter)
void remove_position_via_debugger_linenr(int debugger_linenr)
to define functions rather than attempting to enter them directly on the command line The block of commands is executed as soon as you exit the editor To avoid executing any simply delete all the lines from the buffer before leaving the editor When invoked with no edit the previously executed command
Definition: oct-hist.cc:587
void update_window_title(bool modified)
void zoom_out(const QWidget *ID)
void context_edit(const QWidget *ID)
void closeEvent(QCloseEvent *event)
void do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1, const QString &cond="")
void handle_combo_enc_current_index(QString text)
void execute_command_in_terminal_signal(const QString &)
void zoom_in(const QWidget *ID)
void unindent_selected_text(const QWidget *ID)
void toggle_bookmark(const QWidget *ID)
void handle_request_add_breakpoint(int line, const QString &cond)
void do_smart_indent_line_or_selected_text(void)
void insert_debugger_pointer(const QWidget *ID, int line=-1)
file_editor_tab(const QString &directory="")
A file_editor_tab object consists of a text area and three left margins.
void mru_add_file(const QString &file_name, const QString &encoding)
void notice_settings(const QSettings *settings, bool init=false)
void move_match_brace(const QWidget *ID, bool select)
void find_previous(const QWidget *ID)
void file_name_changed(const QString &fileName, const QString &toolTip)
void handle_save_file_as_answer(const QString &fileName)
void previous_breakpoint(const QWidget *ID)
void do_indent_selected_text(bool indent)
void add_filename_to_list(const QString &, const QString &, QWidget *)
void request_find_previous(void)
void handle_double_click(int p, int l, int modifier)
void run_file_signal(const QFileInfo &info)
void smart_indent_line_or_selected_text(const QWidget *ID)
static void reset_cancel(void)
octave_qscintilla * qsci_edit_area(void)
void toggle_breakpoint(const QWidget *ID)
void handle_context_menu_edit(const QString &)
void indent_selected_text(const QWidget *ID)
void set_current_directory(const QString &dir)
void context_help(const QWidget *ID, bool)
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
Definition: filter.cc:43
void set_file_name(const QString &fileName)
void report_marker_linenr(QIntList &lines, QStringList &conditions)
void save_file_as(const QWidget *ID)
void do_comment_selected_text(bool comment, bool input_str=false)
void save_file(const QWidget *ID)
void editor_check_conflict_save(const QString &saveFileName, bool remove_on_success)
void goto_line(const QWidget *ID, int line=-1)
void delete_debugger_pointer(const QWidget *ID, int line=-1)
With real return the complex result
Definition: data.cc:3260
QsciScintilla::EolMode detect_eol_mode(void)
void context_run(const QWidget *ID)
static uint32_t state[624]
Definition: randmtzig.cc:183
void uncomment_selected_text(const QWidget *ID)
octave_qscintilla * _edit_area
void remove_breakpoint_callback(const bp_info &info)
p
Definition: lu.cc:138
void handle_context_menu_break_condition(int linenr)
void center_current_line(bool always=true)
void remove_all_breakpoints_callback(const bp_info &info)
void remove_all_positions(void)
void handle_file_reload_answer(int decision)
void handle_cursor_moved(int line, int col)
void handle_save_file_as_answer_close(const QString &fileName)
void handle_combo_eol_current_index(int index)
void remove_breakpoint_via_debugger_linenr(int debugger_linenr)
void remove_bookmark(const QWidget *ID)
void set_encoding(const QString &new_encoding)
QList< int > QIntList
Definition: dialog.h:38
void request_open_file(const QString &)
bool exit_debug_and_clear(const QString &full_name, const QString &base_name)
void handle_octave_result(QObject *requester, QString &command, octave_value_list &result)
void show_dialog(QDialog *dlg, bool modal)
void show_auto_completion(const QWidget *ID)
void new_file(const QString &commands=QString())
void handle_save_file_as_answer_cancel(void)
void change_editor_state(const QWidget *ID)
bool check_valid_codec(QTextCodec *codec)
void tab_remove_request(void)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
void handle_margin_clicked(int line, int margin, Qt::KeyboardModifiers state)
void request_find_next(void)
void find_linenr_just_before(int linenr, int &original_linenr, int &editor_linenr)
void add_breakpoint_callback(const bp_info &info)
void find_translated_line_number(int original_linenr, int &translated_linenr, marker *&)
to define functions rather than attempting to enter them directly on the command line The block of commands is executed as soon as you exit the editor To avoid executing any commands
Definition: oct-hist.cc:587
void find(const QWidget *ID, QList< QAction *>)
nd example oindent assigns the value of the alert character(control-g, ASCII code 7) to the string variable ode
Definition: utils.cc:888
OCTAVE_EXPORT octave_value_list directory
Definition: variables.cc:593