GNU Octave  3.8.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-2013 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 
35 #include "find-dialog.h"
36 #include "octave-qscintilla.h"
37 
38 class file_editor;
39 
40 class file_editor_tab : public QWidget
41 {
42  Q_OBJECT
43 
44 public:
45 
46  file_editor_tab (const QString& directory = "");
47 
48  ~file_editor_tab (void);
49 
50 public slots:
51 
52  void update_window_title (bool modified);
53  void handle_copy_available (bool enableCopy);
54  void handle_margin_clicked (int line, int margin,
55  Qt::KeyboardModifiers state);
56 
57  // Tells the editor tab to react on changed settings.
58  void notice_settings (const QSettings *settings);
59 
60  // Will initiate close if associated with the identifier tag.
61  void conditional_close (const QWidget *ID, bool app_closing = false);
62 
63  // Change to a different editor tab by identifier tag.
64  void change_editor_state (const QWidget *ID);
65 
66  // Simply transmit file name.
67  void file_name_query (const QWidget *ID);
68 
69  void set_focus (const QWidget *ID);
70  void undo (const QWidget *ID);
71  void redo (const QWidget *ID);
72  void copy (const QWidget *ID);
73  void cut (const QWidget *ID);
74  void paste (const QWidget *ID);
75  void context_help (const QWidget *ID, bool);
76  void context_edit (const QWidget *ID);
77  void save_file (const QWidget *ID);
78  void save_file (const QWidget *ID, const QString& fileName,
79  bool remove_on_success);
80  void save_file_as (const QWidget *ID);
81  void print_file (const QWidget *ID);
82  void run_file (const QWidget *ID);
83  void context_run (const QWidget *ID);
84  void toggle_bookmark (const QWidget *ID);
85  void next_bookmark (const QWidget *ID);
86  void previous_bookmark (const QWidget *ID);
87  void remove_bookmark (const QWidget *ID);
88 
89  void toggle_breakpoint (const QWidget *ID);
90  void next_breakpoint (const QWidget *ID);
91  void previous_breakpoint (const QWidget *ID);
92  void remove_all_breakpoints (const QWidget *ID);
93 
94  void comment_selected_text (const QWidget *ID);
95  void uncomment_selected_text (const QWidget *ID);
96  void find (const QWidget *ID);
97  void goto_line (const QWidget *ID, int line = -1);
98 
99  void insert_debugger_pointer (const QWidget *ID, int line = -1);
100  void delete_debugger_pointer (const QWidget *ID, int line = -1);
101 
102  void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1);
103 
104  void set_modified (bool modified = true);
105 
106  QString load_file (const QString& fileName);
107  void new_file (const QString& commands = QString ());
108 
109  void file_has_changed (const QString& fileName);
110 
111  void execute_command_in_terminal (const QString& command);
112 
113 signals:
114 
115  void file_name_changed (const QString& fileName, const QString& toolTip);
116  void editor_state_changed (bool copy_available, const QString& fileName);
117  void tab_remove_request ();
118  void add_filename_to_list (const QString&, QWidget *);
119  void mru_add_file (const QString& file_name);
120  void editor_check_conflict_save (const QString& saveFileName,
121  bool remove_on_success);
122  void run_file_signal (const QFileInfo& info);
123  void execute_command_in_terminal_signal (const QString&);
124 
125 protected:
126 
127  void closeEvent (QCloseEvent *event);
128  void set_file_name (const QString& fileName);
129 
130 private slots:
131 
132  // When user closes message box for reload question.
133  void handle_file_reload_answer (int decision);
134 
135  // When user closes message box for resave question.
136  void handle_file_resave_answer (int decision);
137 
138  // When user closes message box for modified question.
139  void handle_file_modified_answer (int decision);
140 
141  // When user closes find_dialog box.
142  void handle_find_dialog_finished (int decision);
143 
144  // When user closes QFileDialog box.
145  void handle_save_file_as_answer (const QString& fileName);
146  void handle_save_file_as_answer_close (const QString& fileName);
148 
149  // When apis preparation has finished and is ready to save
150  void save_apis_info ();
151 
152  // When the numer of lines changes -> adapt width of margin
153  void auto_margin_width ();
154 
155  void handle_cursor_moved (int line, int col);
156 
157 private:
158 
160  {
164  };
165 
166  struct bp_info
167  {
168  bp_info (const QString& f, const QString& d, const QString& fn, int l)
169  : file (f.toStdString ()), dir (d.toStdString ()),
170  function_name (fn.toStdString ()), line (l)
171  { }
172 
173  std::string file;
174  std::string dir;
175  std::string function_name;
176  int line;
177  };
178 
179  bool valid_file_name (const QString& file=QString ());
180  void save_file (const QString& saveFileName, bool remove_on_success = false);
181  void save_file_as (bool remove_on_success = false);
182 
183  void update_lexer ();
184  void request_add_breakpoint (int line);
185  void request_remove_breakpoint (int line);
186 
187  void show_dialog (QDialog *dlg);
188  int check_file_modified ();
189  void do_comment_selected_text (bool comment);
190  QString comment_string (const QString&);
191 
192  void add_breakpoint_callback (const bp_info& info);
193  void remove_breakpoint_callback (const bp_info& info);
194  void remove_all_breakpoints_callback (const bp_info& info);
195  void center_current_line ();
196 
198 
199  QStatusBar *_status_bar;
200  QLabel *_row_indicator;
201  QLabel *_col_indicator;
202 
203  QString _file_name;
205 
209 
210  QFileSystemWatcher _file_system_watcher;
211 
215 
216  QsciAPIs *_lexer_apis;
218 };
219 
220 #endif