GNU Octave  8.1.0
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-2023 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 (octave_file_editor_tab_h)
27 #define octave_file_editor_tab_h 1
28 
29 #include <QAbstractButton>
30 #include <QCloseEvent>
31 #include <QDateTime>
32 #include <QFileInfo>
33 #include <QFileSystemWatcher>
34 #include <QLabel>
35 #include <QStatusBar>
36 #include <QWidget>
37 #include <Qsci/qsciapis.h>
38 
39 #include "gui-settings.h"
40 #include "marker.h"
41 #include "octave-qscintilla.h"
42 #include "qt-interpreter-events.h"
43 
44 class octave_value_list;
45 
47 
48 class base_qobject;
49 class file_editor;
50 
51 class file_editor_tab : public QWidget
52 {
53  Q_OBJECT
54 
55 public:
56 
57  file_editor_tab (base_qobject& oct_qobj, const QString& directory = "");
58 
59  ~file_editor_tab (void);
60 
62 
63  // Will initiate close if associated with the identifier tag.
64  bool conditional_close (void);
65 
66  void update_breakpoints ();
67  void set_file_name (const QString& fileName);
68  void enable_file_watcher (bool do_enable);
69 
70  QString file_name (void) const { return m_file_name; }
71  QString encoding (void) const { return m_encoding; }
72 
73 signals:
74 
75  void tab_ready_to_close (void);
76  void file_name_changed (const QString& fileName,
77  const QString& toolTip,
78  bool modified);
79  void editor_state_changed (bool copy_available, bool is_octave_file,
80  bool is_modified);
83  void tab_remove_request (void);
84  void mru_add_file (const QString& file_name, const QString& encoding);
85  void editor_check_conflict_save (const QString& saveFileName,
86  bool remove_on_success);
87  void run_file_signal (const QFileInfo& info);
88  void request_open_file (const QString&, const QString& = QString ());
89  void edit_mfile_request (const QString&, const QString&,
90  const QString&, int);
91 
92  void autoc_closed (void);
93 
95 
96  void remove_breakpoint_via_debugger_linenr (int debugger_linenr);
99  void find_translated_line_number (int original_linenr,
100  int& translated_linenr, marker*&);
101  void find_linenr_just_before (int linenr, int& original_linenr,
102  int& editor_linenr);
103  void report_marker_linenr (QIntList& lines, QStringList& conditions);
104  void remove_position_via_debugger_linenr (int debugger_linenr);
105  void remove_all_positions (void);
106 
107  void debug_quit_signal (void);
108 
109  void interpreter_event (const fcn_callback& fcn);
110  void interpreter_event (const meth_callback& meth);
111 
112  void maybe_remove_next (int remove_line);
113 
114  void dbstop_if (const QString& prompt, int line, const QString& cond);
115  void request_add_breakpoint (int line, const QString& cond);
116  void request_add_octave_apis (const QStringList&);
117  void api_entries_added (void);
118 
119  void do_save_file_signal (const QString& file_to_save,
120  bool remove_on_success, bool restore_breakpoints);
121 
122  void confirm_dbquit_and_save_signal (const QString& file_to_save,
123  const QString& base_name,
124  bool remove_on_success,
125  bool restore_breakpoints);
126 
127  // FIXME: The following is similar to "process_octave_code" signal.
128  // However, currently that signal is connected to something that simply
129  // focuses a window and does not actually communicate with Octave.
130  //
131  // void evaluate_octave_command (const QString& command);
132 
133 public slots:
134 
135  void update_window_title (bool modified);
136  void handle_copy_available (bool enableCopy);
137  void handle_margin_clicked (int line, int margin,
138  Qt::KeyboardModifiers state);
139 
140  // Tells the editor tab to react on changed settings.
141  void notice_settings (const gui_settings *settings, bool init = false);
142 
143  // Change to a different editor tab by identifier tag.
144  void change_editor_state (const QWidget *ID);
145 
146  void set_focus (const QWidget *ID);
147  void set_current_directory (const QString& dir);
148  void context_help (const QWidget *ID, bool);
149  void context_edit (const QWidget *ID);
150  void save_file (const QWidget *ID);
151  void save_file (const QWidget *ID, const QString& fileName,
152  bool remove_on_success);
153  void save_file_as (const QWidget *ID);
154  void print_file (const QWidget *ID);
155  void run_file (const QWidget *ID, bool step_into = false);
156  void context_run (const QWidget *ID);
157  void toggle_bookmark (const QWidget *ID);
158  void next_bookmark (const QWidget *ID);
159  void previous_bookmark (const QWidget *ID);
160  void remove_bookmark (const QWidget *ID);
161 
162  void toggle_breakpoint (const QWidget *ID);
163  void next_breakpoint (const QWidget *ID);
164  void previous_breakpoint (const QWidget *ID);
165  void remove_all_breakpoints (const QWidget *ID);
166 
167  void scintilla_command (const QWidget *, unsigned int);
168 
169  void comment_selected_text (const QWidget *ID, bool input_str);
170  void uncomment_selected_text (const QWidget *ID);
171 
172  void indent_selected_text (const QWidget *ID);
173  void unindent_selected_text (const QWidget *ID);
175  void convert_eol (const QWidget *ID, QsciScintilla::EolMode);
176 
177  void zoom_in (const QWidget *ID);
178  void zoom_out (const QWidget *ID);
179  void zoom_normal (const QWidget *ID);
180 
181  void goto_line (const QWidget *ID, int line = -1);
182  void move_match_brace (const QWidget *ID, bool select);
183  void show_auto_completion (const QWidget *ID);
184 
185  void insert_debugger_pointer (const QWidget *ID, int line = -1);
186  void delete_debugger_pointer (const QWidget *ID, int line = -1);
187 
188  void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1,
189  const QString& cond = "");
190 
191  void recover_from_exit (void);
192  void set_modified (bool modified = true);
193 
194  void set_encoding (const QString& new_encoding);
195 
196  QString load_file (const QString& fileName);
197 
198  void new_file (const QString& commands = QString ());
199 
200  void file_has_changed (const QString& path, bool do_close = false);
201 
202  void handle_context_menu_edit (const QString&);
203  void handle_context_menu_break_condition (int linenr);
204 
205  void handle_request_add_breakpoint (int line, const QString& cond);
206  void handle_request_remove_breakpoint (int line);
207 
208  void update_breakpoints_handler (const octave_value_list& argout);
209  void update_rowcol_indicator (int line, int col);
210  void update_lexer_settings (bool update_apis_only = false);
211 
212 private slots:
213 
214  // When user closes message box for decoding problems
215  void handle_decode_warning_answer (QAbstractButton *btn);
216 
217  // When user closes message box for reload question.
218  void handle_file_reload_answer (int decision);
219 
220  // When user closes message box for resave question.
221  void handle_file_resave_answer (int decision);
222 
223  // When user closes QFileDialog box.
224  void handle_save_file_as_answer (const QString& fileName);
225  void handle_save_file_as_answer_close (const QString& fileName);
227  void handle_save_as_filter_selected (const QString& filter);
228 
229  // When user changes encoding after decoding errors were found
230  void handle_current_enc_changed (const QString& enc);
231 
232  // When apis preparation has finished and is ready to save
233  void save_apis_info (void);
234 
235  // When the numer of lines changes -> adapt width of margin
236  void auto_margin_width (void);
237 
238  void handle_cursor_moved (int line, int col);
239  void handle_char_added (int character);
240  void handle_double_click (int p, int l, int modifier);
241  void handle_lines_changed (void);
242 
243  void handle_remove_next (int remove_line);
244  void handle_dbstop_if (const QString& prompt, int line,
245  const QString& cond);
246  void handle_add_octave_apis (const QStringList& api_entries);
247  void handle_api_entries_added (void);
248 
249  void do_save_file (const QString& file_to_save, bool remove_on_success,
250  bool restore_breakpoints);
251 
252  void confirm_dbquit_and_save (const QString& file_to_save,
253  const QString& base_name,
254  bool remove_on_success,
255  bool restore_breakpoints);
256 
257 protected:
258 
259  void closeEvent (QCloseEvent *event);
260 
261 private:
262 
264 
265  void add_breakpoint_event (int line, const QString& cond);
266 
267  bool valid_file_name (const QString& file = QString ());
268  void save_file (const QString& saveFileName, bool remove_on_success = false,
269  bool restore_breakpoints = true);
270  void save_file_as (bool remove_on_success = false);
271  bool check_valid_identifier (QString file_name);
272  QTextCodec * check_valid_codec (void);
273 
274  bool unchanged_or_saved (void);
275 
276  void update_lexer (void);
277 
278  void show_dialog (QDialog *dlg, bool modal);
279 
280 public:
281 
282  int check_file_modified (bool remove = false);
283  QString get_all_bookmarks (void);
284 
285 private:
286  void do_comment_selected_text (bool comment, bool input_str = false);
287  void do_indent_selected_text (bool indent);
289 
290  void check_restore_breakpoints (void);
291  void center_current_line (bool always=true);
292 
293  QString get_function_name (void);
294 
295  QsciScintilla::EolMode detect_eol_mode (void);
296  void update_eol_indicator (void);
297 
299 
300  QStatusBar *m_status_bar;
305 
306  QsciScintilla::EolMode m_save_as_desired_eol;
307 
308  QString m_file_name;
310  QString m_ced;
311  QString m_encoding;
312  QString m_new_encoding;
313  QDateTime m_last_modified;
314 
322 
323  QFileSystemWatcher m_file_system_watcher;
324 
326  QStringList m_bp_conditions;
327 
328  QsciAPIs *m_lexer_apis;
331 
334  int m_line;
335  int m_col;
339 
341  {
345  };
346 
348 };
349 
351 
352 #endif
OCTAVE_END_NAMESPACE(octave)
Base class for Octave interfaces that use Qt.
void notice_settings(const gui_settings *settings, bool init=false)
void next_breakpoint(const QWidget *ID)
void handle_decode_warning_answer(QAbstractButton *btn)
void handle_add_octave_apis(const QStringList &api_entries)
void smart_indent_line_or_selected_text(const QWidget *ID)
void remove_all_breakpoints_signal(void)
void handle_lines_changed(void)
void handle_dbstop_if(const QString &prompt, int line, const QString &cond)
void report_marker_linenr(QIntList &lines, QStringList &conditions)
bool check_valid_identifier(QString file_name)
void do_comment_selected_text(bool comment, bool input_str=false)
base_qobject & m_octave_qobj
void run_file_signal(const QFileInfo &info)
void move_match_brace(const QWidget *ID, bool select)
void previous_breakpoint(const QWidget *ID)
void save_file_as(const QWidget *ID)
void do_indent_selected_text(bool indent)
void set_modified(bool modified=true)
void set_focus(const QWidget *ID)
void interpreter_event(const meth_callback &meth)
bool valid_file_name(const QString &file=QString())
void set_focus_editor_signal(QWidget *)
QString m_file_name_short
void run_file(const QWidget *ID, bool step_into=false)
void add_breakpoint_event(int line, const QString &cond)
void unindent_selected_text(const QWidget *ID)
void remove_position_via_debugger_linenr(int debugger_linenr)
void save_apis_info(void)
void comment_selected_text(const QWidget *ID, bool input_str)
void handle_save_file_as_answer(const QString &fileName)
void confirm_dbquit_and_save(const QString &file_to_save, const QString &base_name, bool remove_on_success, bool restore_breakpoints)
void do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1, const QString &cond="")
int check_file_modified(bool remove=false)
void request_remove_breakpoint_via_editor_linenr(int editor_linenr)
QString load_file(const QString &fileName)
QStringList m_bp_conditions
void update_rowcol_indicator(int line, int col)
void handle_current_enc_changed(const QString &enc)
QFileSystemWatcher m_file_system_watcher
void handle_request_remove_breakpoint(int line)
void confirm_dbquit_and_save_signal(const QString &file_to_save, const QString &base_name, bool remove_on_success, bool restore_breakpoints)
void indent_selected_text(const QWidget *ID)
void handle_save_file_as_answer_close(const QString &fileName)
void context_run(const QWidget *ID)
void next_bookmark(const QWidget *ID)
void debug_quit_signal(void)
void check_restore_breakpoints(void)
void remove_all_positions(void)
QString m_prep_apis_file
void convert_eol(const QWidget *ID, QsciScintilla::EolMode)
void center_current_line(bool always=true)
void set_file_name(const QString &fileName)
void interpreter_event(const fcn_callback &fcn)
void handle_remove_next(int remove_line)
QString get_all_bookmarks(void)
void recover_from_exit(void)
void new_file(const QString &commands=QString())
void tab_remove_request(void)
void file_has_changed(const QString &path, bool do_close=false)
void handle_file_reload_answer(int decision)
void previous_bookmark(const QWidget *ID)
void remove_bookmark(const QWidget *ID)
void enable_file_watcher(bool do_enable)
void editor_check_conflict_save(const QString &saveFileName, bool remove_on_success)
void update_eol_indicator(void)
void do_save_file(const QString &file_to_save, bool remove_on_success, bool restore_breakpoints)
void request_add_breakpoint(int line, const QString &cond)
bool conditional_close(void)
QLabel * m_eol_indicator
void handle_margin_clicked(int line, int margin, Qt::KeyboardModifiers state)
void mru_add_file(const QString &file_name, const QString &encoding)
void remove_all_breakpoints(const QWidget *ID)
void save_file(const QWidget *ID)
QString get_function_name(void)
file_editor_tab(base_qobject &oct_qobj, const QString &directory="")
A file_editor_tab object consists of a text area and three left margins.
void handle_char_added(int character)
void context_help(const QWidget *ID, bool)
void find_translated_line_number(int original_linenr, int &translated_linenr, marker *&)
void update_breakpoints_handler(const octave_value_list &argout)
void delete_debugger_pointer(const QWidget *ID, int line=-1)
void update_lexer_settings(bool update_apis_only=false)
QStatusBar * m_status_bar
octave_qscintilla * m_edit_area
QTextCodec * check_valid_codec(void)
void handle_cursor_moved(int line, int col)
void auto_margin_width(void)
void editor_state_changed(bool copy_available, bool is_octave_file, bool is_modified)
bool m_always_reload_changed_files
void handle_context_menu_break_condition(int linenr)
void set_current_directory(const QString &dir)
QString encoding(void) const
void handle_api_entries_added(void)
void handle_request_add_breakpoint(int line, const QString &cond)
void set_encoding(const QString &new_encoding)
void zoom_in(const QWidget *ID)
void scintilla_command(const QWidget *, unsigned int)
void toggle_bookmark(const QWidget *ID)
void find_linenr_just_before(int linenr, int &original_linenr, int &editor_linenr)
void change_editor_state(const QWidget *ID)
void edit_mfile_request(const QString &, const QString &, const QString &, int)
void update_lexer(void)
QString file_name(void) const
void show_auto_completion(const QWidget *ID)
octave_qscintilla * qsci_edit_area(void)
QString m_prep_apis_path
void insert_debugger_pointer(const QWidget *ID, int line=-1)
void autoc_closed(void)
void request_open_file(const QString &, const QString &=QString())
void show_dialog(QDialog *dlg, bool modal)
QsciAPIs * m_lexer_apis
void zoom_normal(const QWidget *ID)
void tab_ready_to_close(void)
QDateTime m_last_modified
void handle_save_as_filter_selected(const QString &filter)
void do_save_file_signal(const QString &file_to_save, bool remove_on_success, bool restore_breakpoints)
void uncomment_selected_text(const QWidget *ID)
QsciScintilla::EolMode m_save_as_desired_eol
void handle_context_menu_edit(const QString &)
void print_file(const QWidget *ID)
void dbstop_if(const QString &prompt, int line, const QString &cond)
void maybe_remove_next(int remove_line)
void file_name_changed(const QString &fileName, const QString &toolTip, bool modified)
bool m_highlight_all_occurrences
void update_breakpoints_signal(const octave_value_list &args)
bool unchanged_or_saved(void)
QLabel * m_col_indicator
void context_edit(const QWidget *ID)
void goto_line(const QWidget *ID, int line=-1)
void handle_file_resave_answer(int decision)
breakpoint_info m_breakpoint_info
void handle_copy_available(bool enableCopy)
void handle_double_click(int p, int l, int modifier)
void toggle_breakpoint(const QWidget *ID)
QLabel * m_enc_indicator
void update_window_title(bool modified)
QLabel * m_row_indicator
QsciScintilla::EolMode detect_eol_mode(void)
void remove_breakpoint_via_debugger_linenr(int debugger_linenr)
void edit_area_changed(octave_qscintilla *edit_area)
void request_add_octave_apis(const QStringList &)
void closeEvent(QCloseEvent *event)
void zoom_out(const QWidget *ID)
void api_entries_added(void)
void handle_save_file_as_answer_cancel(void)
void do_smart_indent_line_or_selected_text(void)
Definition: marker.h:45
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
QList< int > QIntList
Definition: dialog.h:40
std::function< void(void)> fcn_callback
Definition: event-manager.h:43
std::function< void(interpreter &)> meth_callback
Definition: event-manager.h:48
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
Definition: filter.cc:48
static uint32_t state[624]
Definition: randmtzig.cc:193