GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
file-editor-tab.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 
44 class octave_value_list;
45 
46 class file_editor;
47 
48 class file_editor_tab : public QWidget
49 {
50  Q_OBJECT
51 
52 public:
53 
54  file_editor_tab (const QString& directory = "");
55 
56  ~file_editor_tab (void);
57 
59 
60  // Will initiate close if associated with the identifier tag.
61  bool conditional_close (void);
62 
63  static void reset_cancel (void) {_cancelled = false;}
64  static bool was_cancelled (void) {return _cancelled;}
65 
66 public slots:
67 
68  void update_window_title (bool modified);
69  void handle_copy_available (bool enableCopy);
70  void handle_margin_clicked (int line, int margin,
71  Qt::KeyboardModifiers state);
72 
73  // Tells the editor tab to react on changed settings.
74  void notice_settings (const QSettings *settings, bool init = false);
75 
76  // Change to a different editor tab by identifier tag.
77  void change_editor_state (const QWidget *ID);
78 
79  // Simply transmit filename.
80  void file_name_query (const QWidget *ID);
81 
82  void set_focus (const QWidget *ID);
83  void set_current_directory (const QString& dir);
84  void context_help (const QWidget *ID, bool);
85  void context_edit (const QWidget *ID);
86  void check_modified_file (void);
87  void save_file (const QWidget *ID);
88  void save_file (const QWidget *ID, const QString& fileName,
89  bool remove_on_success);
90  void save_file_as (const QWidget *ID);
91  void print_file (const QWidget *ID);
92  void run_file (const QWidget *ID);
93  void context_run (const QWidget *ID);
94  void toggle_bookmark (const QWidget *ID);
95  void next_bookmark (const QWidget *ID);
96  void previous_bookmark (const QWidget *ID);
97  void remove_bookmark (const QWidget *ID);
98 
99  void toggle_breakpoint (const QWidget *ID);
100  void next_breakpoint (const QWidget *ID);
101  void previous_breakpoint (const QWidget *ID);
102  void remove_all_breakpoints (const QWidget *ID);
103 
104  void scintilla_command (const QWidget *, unsigned int);
105 
106  void comment_selected_text (const QWidget *ID);
107  void uncomment_selected_text (const QWidget *ID);
108 
109  void indent_selected_text (const QWidget *ID);
110  void unindent_selected_text (const QWidget *ID);
111  void convert_eol (const QWidget *ID, QsciScintilla::EolMode);
112 
113  void zoom_in (const QWidget *ID);
114  void zoom_out (const QWidget *ID);
115  void zoom_normal (const QWidget *ID);
116 
117  void find (const QWidget *ID, QList<QAction *>);
118  void find_next (const QWidget *ID);
119  void find_previous (const QWidget *ID);
120  void goto_line (const QWidget *ID, int line = -1);
121  void move_match_brace (const QWidget *ID, bool select);
122  void show_auto_completion (const QWidget *ID);
123 
124  void insert_debugger_pointer (const QWidget *ID, int line = -1);
125  void delete_debugger_pointer (const QWidget *ID, int line = -1);
126 
127  void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1,
128  const QString& cond = "");
129 
130  void recover_from_exit (void);
131  void set_modified (bool modified = true);
132 
133  void set_encoding (const QString& new_encoding);
134 
135  QString load_file (const QString& fileName);
136 
137  void new_file (const QString& commands = QString ());
138 
139  void file_has_changed (const QString& fileName);
140 
141  void handle_context_menu_edit (const QString&);
142  void handle_context_menu_break_condition (int linenr);
143 
144  void handle_request_add_breakpoint (int line, const QString& cond);
146 
147  void handle_octave_result (QObject *requester, QString& command,
149 
150 signals:
151 
152  void file_name_changed (const QString& fileName, const QString& toolTip);
153  void editor_state_changed (bool copy_available, bool is_octave_file);
154  void tab_remove_request ();
155  void add_filename_to_list (const QString&, const QString&, QWidget *);
156  void mru_add_file (const QString& file_name, const QString& encoding);
157  void editor_check_conflict_save (const QString& saveFileName,
158  bool remove_on_success);
159  void run_file_signal (const QFileInfo& info);
160  void request_open_file (const QString&);
161  void edit_mfile_request (const QString&, const QString&,
162  const QString&, int);
163 
164  void request_find_next (void);
165  void request_find_previous (void);
166 
167  void remove_breakpoint_via_debugger_linenr (int debugger_linenr);
168  void request_remove_breakpoint_via_editor_linenr (int editor_linenr);
169  void remove_all_breakpoints (void);
170  void find_translated_line_number (int original_linenr,
171  int& translated_linenr, marker*&);
172  void find_linenr_just_before (int linenr, int& original_linenr,
173  int& editor_linenr);
174  void report_marker_linenr (QIntList& lines, QStringList& conditions);
175  void remove_position_via_debugger_linenr (int debugger_linenr);
176  void remove_all_positions (void);
177  void execute_command_in_terminal_signal (const QString&);
178  // FIXME: The following is similar to "process_octave_code" signal. However,
179  // currently that signal is connected to something that simply focuses a
180  // window and not actually communicate with Octave.
181  // void evaluate_octave_command (const QString& command);
182 
183 protected:
184 
185  void closeEvent (QCloseEvent *event);
186  void set_file_name (const QString& fileName);
187 
188 private slots:
189 
190  // When user closes message box for reload question.
191  void handle_file_reload_answer (int decision);
192 
193  // When user closes message box for resave question.
194  void handle_file_resave_answer (int decision);
195 
196  // When user closes message box for modified question.
197  void handle_file_modified_answer (int decision);
198 
199  // When user closes find_dialog box.
200  void handle_find_dialog_finished (int decision);
201 
202  // When user closes QFileDialog box.
203  void handle_save_file_as_answer (const QString& fileName);
204  void handle_save_file_as_answer_close (const QString& fileName);
206  void handle_save_as_filter_selected (const QString& filter);
207  void handle_combo_eol_current_index (int index);
208  void handle_combo_enc_current_index (QString text);
209 
210  // When apis preparation has finished and is ready to save
211  void save_apis_info ();
212 
213  // When the numer of lines changes -> adapt width of margin
214  void auto_margin_width ();
215 
216  void handle_cursor_moved (int line, int col);
217  void handle_lines_changed (void);
218 
219 private:
220 
221  struct bp_info
222  {
223  bp_info (const QString& fname, int l = 0, const QString& cond = "");
224 
225  int line;
230  };
231 
232  bool valid_file_name (const QString& file=QString ());
233  bool exit_debug_and_clear (const QString& full_name,
234  const QString& base_name);
235  void save_file (const QString& saveFileName, bool remove_on_success = false,
236  bool restore_breakpoints = true);
237  void save_file_as (bool remove_on_success = false);
238  bool check_valid_identifier (QString file_name);
239  bool check_valid_codec (QTextCodec *codec);
240 
241  bool unchanged_or_saved (void);
242 
243  void update_lexer ();
244 
245  void show_dialog (QDialog *dlg, bool modal);
246  int check_file_modified ();
247  void do_comment_selected_text (bool comment);
248  QString comment_string (const QString&);
249  void do_indent_selected_text (bool indent);
250 
251  void add_breakpoint_callback (const bp_info& info);
252  void remove_breakpoint_callback (const bp_info& info);
253  void remove_all_breakpoints_callback (const bp_info& info);
254  void check_restore_breakpoints (void);
255  void center_current_line (bool always=true);
256 
257  void add_octave_apis (octave_value_list key_ovl);
258  QString get_function_name ();
259 
260  void do_smart_indent (void);
261 
262  QsciScintilla::EolMode detect_eol_mode ();
263  void update_eol_indicator ();
264 
266 
267  QStatusBar *_status_bar;
268  QLabel *_row_indicator;
269  QLabel *_col_indicator;
270  QLabel *_eol_indicator;
271  QLabel *_enc_indicator;
272 
273  QsciScintilla::EolMode _save_as_desired_eol;
274 
275  QString _file_name;
277  QString _ced;
278  QString _encoding;
279  QString _new_encoding;
280 
286 
287  QFileSystemWatcher _file_system_watcher;
288 
290  QStringList _bp_conditions;
291 
295 
296  QsciAPIs *_lexer_apis;
298 
299  static bool _cancelled;
300 
301  int _line;
302  int _col;
304 
305 };
306 
307 #endif
void report_marker_linenr(QIntList &lines, QStringList &conditions)
void remove_position_via_debugger_linenr(int debugger_linenr)
void handle_file_resave_answer(int decision)
void find_linenr_just_before(int linenr, int &original_linenr, int &editor_linenr)
QStatusBar * _status_bar
void file_has_changed(const QString &fileName)
void closeEvent(QCloseEvent *event)
void update_window_title(bool modified)
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
void remove_breakpoint_callback(const bp_info &info)
void convert_eol(const QWidget *ID, QsciScintilla::EolMode)
void previous_bookmark(const QWidget *ID)
void handle_request_add_breakpoint(int line, const QString &cond)
fname
Definition: load-save.cc:754
void indent_selected_text(const QWidget *ID)
void context_help(const QWidget *ID, bool)
void set_file_name(const QString &fileName)
void remove_breakpoint_via_debugger_linenr(int debugger_linenr)
find_dialog * _find_dialog
QFileSystemWatcher _file_system_watcher
void handle_save_file_as_answer_close(const QString &fileName)
void zoom_normal(const QWidget *ID)
void handle_combo_enc_current_index(QString text)
void handle_combo_eol_current_index(int index)
void zoom_out(const QWidget *ID)
void handle_lines_changed(void)
void handle_context_menu_break_condition(int linenr)
void file_name_query(const QWidget *ID)
bool unchanged_or_saved(void)
void toggle_breakpoint(const QWidget *ID)
void add_breakpoint_callback(const bp_info &info)
void check_restore_breakpoints(void)
void center_current_line(bool always=true)
void handle_copy_available(bool enableCopy)
void handle_cursor_moved(int line, int col)
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 handle_find_dialog_finished(int decision)
void handle_octave_result(QObject *requester, QString &command, octave_value_list &result)
void request_find_next(void)
void check_modified_file(void)
void save_file_as(const QWidget *ID)
bp_info(const QString &fname, int l=0, const QString &cond="")
QString _file_name_short
void set_focus(const QWidget *ID)
void file_name_changed(const QString &fileName, const QString &toolTip)
QLabel * _eol_indicator
octave_qscintilla * qsci_edit_area()
void insert_debugger_pointer(const QWidget *ID, int line=-1)
void notice_settings(const QSettings *settings, bool init=false)
bool exit_debug_and_clear(const QString &full_name, const QString &base_name)
void print_file(const QWidget *ID)
bool check_valid_codec(QTextCodec *codec)
void find_next(const QWidget *ID)
void change_editor_state(const QWidget *ID)
void recover_from_exit(void)
void goto_line(const QWidget *ID, int line=-1)
void do_comment_selected_text(bool comment)
void handle_margin_clicked(int line, int margin, Qt::KeyboardModifiers state)
void find_previous(const QWidget *ID)
void next_bookmark(const QWidget *ID)
void save_file(const QWidget *ID)
QLabel * _col_indicator
void move_match_brace(const QWidget *ID, bool select)
void context_run(const QWidget *ID)
void remove_bookmark(const QWidget *ID)
void unindent_selected_text(const QWidget *ID)
void set_current_directory(const QString &dir)
void add_filename_to_list(const QString &, const QString &, QWidget *)
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
Definition: filter.cc:43
void handle_file_modified_answer(int decision)
void find(const QWidget *ID, QList< QAction * >)
void execute_command_in_terminal_signal(const QString &)
void mru_add_file(const QString &file_name, const QString &encoding)
void handle_context_menu_edit(const QString &)
void handle_file_reload_answer(int decision)
void delete_debugger_pointer(const QWidget *ID, int line=-1)
With real return the complex result
Definition: data.cc:3375
QString get_function_name()
octave_qscintilla * _edit_area
Definition: marker.h:39
void show_dialog(QDialog *dlg, bool modal)
static uint32_t state[624]
Definition: randmtzig.cc:184
QLabel * _row_indicator
void edit_mfile_request(const QString &, const QString &, const QString &, int)
void toggle_bookmark(const QWidget *ID)
void request_remove_breakpoint_via_editor_linenr(int editor_linenr)
bool check_valid_identifier(QString file_name)
void handle_save_file_as_answer(const QString &fileName)
void context_edit(const QWidget *ID)
void do_indent_selected_text(bool indent)
static bool was_cancelled(void)
void remove_all_breakpoints_callback(const bp_info &info)
void next_breakpoint(const QWidget *ID)
bool _always_reload_changed_files
QString comment_string(const QString &)
void handle_save_as_filter_selected(const QString &filter)
QsciAPIs * _lexer_apis
void do_smart_indent(void)
void previous_breakpoint(const QWidget *ID)
QsciScintilla::EolMode detect_eol_mode()
void do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1, const QString &cond="")
void uncomment_selected_text(const QWidget *ID)
void add_octave_apis(octave_value_list key_ovl)
void handle_save_file_as_answer_cancel()
QStringList _bp_conditions
bool conditional_close(void)
void request_find_previous(void)
void editor_check_conflict_save(const QString &saveFileName, bool remove_on_success)
QString load_file(const QString &fileName)
QsciScintilla::EolMode _save_as_desired_eol
QList< int > QIntList
Definition: dialog.h:38
void show_auto_completion(const QWidget *ID)
static void reset_cancel(void)
void remove_all_breakpoints(void)
void find_translated_line_number(int original_linenr, int &translated_linenr, marker *&)
void scintilla_command(const QWidget *, unsigned int)
void zoom_in(const QWidget *ID)
void handle_request_remove_breakpoint(int line)
void run_file(const QWidget *ID)
void comment_selected_text(const QWidget *ID)
void remove_all_positions(void)
void set_modified(bool modified=true)
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:854
static bool _cancelled
void new_file(const QString &commands=QString())
void run_file_signal(const QFileInfo &info)
QLabel * _enc_indicator
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 editor_state_changed(bool copy_available, bool is_octave_file)
void request_open_file(const QString &)
bool valid_file_name(const QString &file=QString())
void set_encoding(const QString &new_encoding)
OCTAVE_EXPORT octave_value_list directory
Definition: variables.cc:582
file_editor_tab(const QString &directory="")
A file_editor_tab object consists of a text area and three left margins.