GNU Octave  4.0.0
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-2015 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 class file_editor;
41 
42 class file_editor_tab : public QWidget
43 {
44  Q_OBJECT
45 
46 public:
47 
48  file_editor_tab (const QString& directory = "");
49 
50  ~file_editor_tab (void);
51 
53 
54  // Will initiate close if associated with the identifier tag.
55  bool conditional_close (void);
56 
57  static void reset_cancel (void) {_cancelled = false;}
58  static bool was_cancelled (void) {return _cancelled;}
59 
60 public slots:
61 
62  void update_window_title (bool modified);
63  void handle_copy_available (bool enableCopy);
64  void handle_margin_clicked (int line, int margin,
65  Qt::KeyboardModifiers state);
66 
67  // Tells the editor tab to react on changed settings.
68  void notice_settings (const QSettings *settings, bool init = false);
69 
70  // Change to a different editor tab by identifier tag.
71  void change_editor_state (const QWidget *ID);
72 
73  // Simply transmit file name.
74  void file_name_query (const QWidget *ID);
75 
76  void set_focus (const QWidget *ID);
77  void set_current_directory (const QString& dir);
78  void context_help (const QWidget *ID, bool);
79  void context_edit (const QWidget *ID);
80  void check_modified_file (void);
81  void save_file (const QWidget *ID);
82  void save_file (const QWidget *ID, const QString& fileName,
83  bool remove_on_success);
84  void save_file_as (const QWidget *ID);
85  void print_file (const QWidget *ID);
86  void run_file (const QWidget *ID);
87  void context_run (const QWidget *ID);
88  void toggle_bookmark (const QWidget *ID);
89  void next_bookmark (const QWidget *ID);
90  void previous_bookmark (const QWidget *ID);
91  void remove_bookmark (const QWidget *ID);
92 
93  void toggle_breakpoint (const QWidget *ID);
94  void next_breakpoint (const QWidget *ID);
95  void previous_breakpoint (const QWidget *ID);
96  void remove_all_breakpoints (const QWidget *ID);
97 
98  void scintilla_command (const QWidget *, unsigned int);
99 
100  void comment_selected_text (const QWidget *ID);
101  void uncomment_selected_text (const QWidget *ID);
102 
103  void indent_selected_text (const QWidget *ID);
104  void unindent_selected_text (const QWidget *ID);
105  void convert_eol (const QWidget *ID, QsciScintilla::EolMode);
106 
107  void zoom_in (const QWidget *ID);
108  void zoom_out (const QWidget *ID);
109  void zoom_normal (const QWidget *ID);
110 
111  void find (const QWidget *ID);
112  void goto_line (const QWidget *ID, int line = -1);
113  void move_match_brace (const QWidget *ID, bool select);
114  void show_auto_completion (const QWidget *ID);
115 
116  void insert_debugger_pointer (const QWidget *ID, int line = -1);
117  void delete_debugger_pointer (const QWidget *ID, int line = -1);
118 
119  void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1);
120 
121  void set_modified (bool modified = true);
122 
123  QString load_file (const QString& fileName);
124  void new_file (const QString& commands = QString ());
125 
126  void file_has_changed (const QString& fileName);
127 
128  void handle_context_menu_edit (const QString&);
129 
130 signals:
131 
132  void file_name_changed (const QString& fileName, const QString& toolTip);
133  void editor_state_changed (bool copy_available, bool is_octave_file);
134  void tab_remove_request ();
135  void add_filename_to_list (const QString&, QWidget *);
136  void mru_add_file (const QString& file_name);
137  void editor_check_conflict_save (const QString& saveFileName,
138  bool remove_on_success);
139  void run_file_signal (const QFileInfo& info);
141  void request_open_file (const QString&);
142 
143 protected:
144 
145  void closeEvent (QCloseEvent *event);
146  void set_file_name (const QString& fileName);
147 
148 private slots:
149 
150  // When user closes message box for reload question.
151  void handle_file_reload_answer (int decision);
152 
153  // When user closes message box for resave question.
154  void handle_file_resave_answer (int decision);
155 
156  // When user closes message box for modified question.
157  void handle_file_modified_answer (int decision);
158 
159  // When user closes find_dialog box.
160  void handle_find_dialog_finished (int decision);
161 
162  // When user closes QFileDialog box.
163  void handle_save_file_as_answer (const QString& fileName);
164  void handle_save_file_as_answer_close (const QString& fileName);
166  void handle_save_as_filter_selected (const QString& filter);
167  void handle_combo_eol_current_index (int index);
168 
169  // When apis preparation has finished and is ready to save
170  void save_apis_info ();
171 
172  // When the numer of lines changes -> adapt width of margin
173  void auto_margin_width ();
174 
175  void handle_cursor_moved (int line, int col);
176 
177 private:
178 
180  {
184  };
185 
186  struct bp_info
187  {
188  bp_info (const QString& fname, int l = 0);
189 
190  int line;
191  std::string file;
192  std::string dir;
193  std::string function_name;
194  };
195 
196  bool valid_file_name (const QString& file=QString ());
197  void save_file (const QString& saveFileName, bool remove_on_success = false);
198  void save_file_as (bool remove_on_success = false);
199  bool check_valid_identifier (QString file_name);
200 
201  void update_lexer ();
202  void request_add_breakpoint (int line);
203  void request_remove_breakpoint (int line);
204 
205  void show_dialog (QDialog *dlg, bool modal);
206  int check_file_modified ();
207  void do_comment_selected_text (bool comment);
208  QString comment_string (const QString&);
209  void do_indent_selected_text (bool indent);
210 
211  void add_breakpoint_callback (const bp_info& info);
212  void remove_breakpoint_callback (const bp_info& info);
213  void remove_all_breakpoints_callback (const bp_info& info);
214  void center_current_line ();
215 
216  void add_octave_apis (octave_value_list key_ovl);
217  QString get_function_name ();
218 
219  QsciScintilla::EolMode detect_eol_mode ();
220  void update_eol_indicator ();
221 
223 
224  QStatusBar *_status_bar;
225  QLabel *_row_indicator;
226  QLabel *_col_indicator;
227  QLabel *_eol_indicator;
228 
229  QsciScintilla::EolMode _save_as_desired_eol;
230 
231  QString _file_name;
233  QString _ced;
234 
239 
240  QFileSystemWatcher _file_system_watcher;
241 
245 
246  QsciAPIs *_lexer_apis;
248 
249  static bool _cancelled;
250 };
251 
252 #endif
void handle_file_resave_answer(int decision)
QStatusBar * _status_bar
void file_has_changed(const QString &fileName)
void closeEvent(QCloseEvent *event)
void update_window_title(bool modified)
void auto_margin_width()
void remove_breakpoint_callback(const bp_info &info)
void convert_eol(const QWidget *ID, QsciScintilla::EolMode)
void previous_bookmark(const QWidget *ID)
void indent_selected_text(const QWidget *ID)
void context_help(const QWidget *ID, bool)
void add_filename_to_list(const QString &, QWidget *)
void set_file_name(const QString &fileName)
bp_info(const QString &fname, int l=0)
void set_global_edit_shortcuts_signal(bool)
void find(const QWidget *ID)
static uint32_t state[624]
Definition: randmtzig.c:188
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_eol_current_index(int index)
void zoom_out(const QWidget *ID)
void file_name_query(const QWidget *ID)
void toggle_breakpoint(const QWidget *ID)
void add_breakpoint_callback(const bp_info &info)
void handle_copy_available(bool enableCopy)
void request_add_breakpoint(int line)
void do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1)
void remove_all_breakpoints(const QWidget *ID)
void handle_cursor_moved(int line, int col)
void update_eol_indicator()
void handle_find_dialog_finished(int decision)
void check_modified_file(void)
void save_apis_info()
void save_file_as(const QWidget *ID)
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)
void print_file(const QWidget *ID)
MArray< double > filter(MArray< double > &, MArray< double > &, MArray< double > &, int dim)
void change_editor_state(const QWidget *ID)
void center_current_line()
void goto_line(const QWidget *ID, int line=-1)
void do_comment_selected_text(bool comment)
void request_remove_breakpoint(int line)
void handle_margin_clicked(int line, int margin, Qt::KeyboardModifiers state)
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 handle_file_modified_answer(int decision)
void handle_context_menu_edit(const QString &)
void handle_file_reload_answer(int decision)
void delete_debugger_pointer(const QWidget *ID, int line=-1)
QString get_function_name()
octave_qscintilla * _edit_area
void show_dialog(QDialog *dlg, bool modal)
QLabel * _row_indicator
void toggle_bookmark(const QWidget *ID)
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)
void mru_add_file(const QString &file_name)
QsciAPIs * _lexer_apis
void previous_breakpoint(const QWidget *ID)
QsciScintilla::EolMode detect_eol_mode()
~file_editor_tab(void)
int check_file_modified()
void uncomment_selected_text(const QWidget *ID)
void add_octave_apis(octave_value_list key_ovl)
void handle_save_file_as_answer_cancel()
bool conditional_close(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
void show_auto_completion(const QWidget *ID)
static void reset_cancel(void)
void scintilla_command(const QWidget *, unsigned int)
void zoom_in(const QWidget *ID)
void run_file(const QWidget *ID)
void comment_selected_text(const QWidget *ID)
void set_modified(bool modified=true)
static bool _cancelled
void new_file(const QString &commands=QString())
void run_file_signal(const QFileInfo &info)
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())
file_editor_tab(const QString &directory="")