Mercurial > hg > octave-nkf
comparison libgui/src/m-editor/file-editor.cc @ 16377:8430ea8c1594
open editor tab and insert marker for debugging with gui
* file-editor-interface.h (file_editor_interface::request_open_file):
New public slot.
(file_editor_interface::handle_dbstop_request): New virtual function.
* file-editor-tab.h, file-editor-tab.cc (file_editor_tab::goto_line):
New arg, line, with default value. Don't prompt if line is greater
than zero.
(file_editor_tab::set_debugger_position): New arg, widget id.
(file_editor_tab::add_filename_to_list): New arg, widget id.
* file-editor.h, file-editor.cc (file_eidtor::editor_tab_map):
New data member.
(file_editor::fetFileNames) Delete.
(file_editor::~file_editor, file_editor::check_conflict_save,
file_editor::handle_add_filename_to_list): Use editor_tab_map instead
of fetFileNames.
(file_editor::request_open_file): New args, line and set_marker.
Optionally position cursor at line and with debug marker. If file is
already open in tab, switch to it instead of giving error.
(file_editor::construct): Connect fetab_set_debugger_position signal
to set_debugger_position slot.
* main-window.h, main-window.cc (main_window::dbstop_signal):
New signal.
(main_window::handle_dbstop_request): New function.
* octave-event-listener.h (octave_event_listener::dbstop): New
virtual function.
* octave-qt-event-listener.h, octave-qt-event-listener.cc
(octave_qt_event_listener::dbstop): New function.
(octave_qt_event_listener::dbstop_signal): New signal.
* octave-link.h, octave-link.cc (octave_link::dbstop,
octave_link::do_dbstop, octave_link::dbstop_event_hook_fcn,
octave_link::do_dbstop_event_hook_fcn): New functions
* octave-main-thread.h, octave-main-thread.cc (dbstop_event_hook_fcn):
New function.
(octave_main_thread::run): Add it to the list of dbstop event hook
functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 27 Mar 2013 12:59:12 -0400 |
parents | f482302d81c9 |
children | 3cacd597464d |
comparison
equal
deleted
inserted
replaced
16376:a2f65b8f1955 | 16377:8430ea8c1594 |
---|---|
52 } | 52 } |
53 | 53 |
54 file_editor::~file_editor () | 54 file_editor::~file_editor () |
55 { | 55 { |
56 QSettings *settings = resource_manager::get_settings (); | 56 QSettings *settings = resource_manager::get_settings (); |
57 fetFileNames.clear (); | 57 editor_tab_map.clear (); |
58 if (settings->value ("editor/restoreSession",true).toBool ()) | 58 if (settings->value ("editor/restoreSession",true).toBool ()) |
59 { | 59 { |
60 // Have all file editor tabs signal what their file names are. | 60 // Have all file editor tabs signal what their file names are. |
61 emit fetab_file_name_query (0); | 61 emit fetab_file_name_query (0); |
62 } | 62 } |
63 QStringList fetFileNames; | |
64 for (std::map<QString, QWidget *>::const_iterator p = editor_tab_map.begin (); | |
65 p != editor_tab_map.end (); p++) | |
66 fetFileNames.append (p->first); | |
67 | |
63 settings->setValue ("editor/savedSessionTabs", fetFileNames); | 68 settings->setValue ("editor/savedSessionTabs", fetFileNames); |
64 settings->sync (); | 69 settings->sync (); |
65 | 70 |
66 if (_mru_file_menu) | 71 if (_mru_file_menu) |
67 delete _mru_file_menu; | 72 delete _mru_file_menu; |
140 fileDialog->setAttribute (Qt::WA_DeleteOnClose); | 145 fileDialog->setAttribute (Qt::WA_DeleteOnClose); |
141 fileDialog->show (); | 146 fileDialog->show (); |
142 } | 147 } |
143 | 148 |
144 void | 149 void |
145 file_editor::request_open_file (const QString& openFileName) | 150 file_editor::request_open_file (const QString& openFileName, int line, |
151 bool set_marker) | |
146 { | 152 { |
147 if (openFileName.isEmpty ()) | 153 if (openFileName.isEmpty ()) |
148 { | 154 { |
149 // ?? Not sure this will happen. This routine isn't even called | 155 // ?? Not sure this will happen. This routine isn't even called |
150 // if the user hasn't selected a file. | 156 // if the user hasn't selected a file. |
151 } | 157 } |
152 else | 158 else |
153 { | 159 { |
154 // Have all file editor tabs signal what their file names are. | 160 // Have all file editor tabs signal what their file names are. |
155 fetFileNames.clear (); | 161 editor_tab_map.clear (); |
156 emit fetab_file_name_query (0); | 162 emit fetab_file_name_query (0); |
157 | 163 |
158 // Check whether this file is already open in the editor. | 164 // Check whether this file is already open in the editor. |
159 if (fetFileNames.contains (openFileName, Qt::CaseSensitive)) | 165 std::map<QString, QWidget *>::const_iterator p = editor_tab_map.find (openFileName); |
166 if (p != editor_tab_map.end ()) | |
160 { | 167 { |
161 // Create a NonModal message so nothing is blocked and | 168 _tab_widget->setCurrentWidget (p->second); |
162 // bring the existing file forward. | 169 |
163 QMessageBox* msgBox = new QMessageBox ( | 170 if (line > 0) |
164 QMessageBox::Critical, tr ("Octave Editor"), | 171 { |
165 tr ("File %1 is already open in the editor."). | 172 emit fetab_goto_line (p->second, line); |
166 arg (openFileName), QMessageBox::Ok, 0); | 173 |
167 msgBox->setWindowModality (Qt::NonModal); | 174 if (set_marker) |
168 msgBox->setAttribute (Qt::WA_DeleteOnClose); | 175 emit fetab_set_debugger_position (p->second, line-1); |
169 msgBox->show (); | 176 } |
170 QFileInfo file(openFileName); | 177 |
171 QString short_openFileName = file.fileName(); // get file name only | 178 emit fetab_set_focus (p->second); |
172 for(int i = 0; i < _tab_widget->count (); i++) | 179 } |
173 { // check whether tab title is file name (long or short) | 180 else |
174 if (_tab_widget->tabText (i) == openFileName || | 181 { |
175 _tab_widget->tabText (i) == short_openFileName) | 182 file_editor_tab *fileEditorTab = new file_editor_tab (); |
183 if (fileEditorTab) | |
184 { | |
185 QString result = fileEditorTab->load_file(openFileName); | |
186 if (result == "") | |
176 { | 187 { |
177 _tab_widget->setCurrentIndex (i); | 188 // Supply empty title then have the file_editor_tab update |
178 break; | 189 // with full or short name. |
190 add_file_editor_tab (fileEditorTab, ""); | |
191 fileEditorTab->update_window_title (false); | |
192 // file already loaded, add file to mru list here | |
193 handle_mru_add_file(QDir::cleanPath (openFileName)); | |
194 | |
195 if (line > 0) | |
196 { | |
197 emit fetab_goto_line (fileEditorTab, line); | |
198 | |
199 if (set_marker) | |
200 emit fetab_set_debugger_position (fileEditorTab, line-1); | |
201 } | |
202 } | |
203 else | |
204 { | |
205 delete fileEditorTab; | |
206 // Create a NonModal message about error. | |
207 QMessageBox* msgBox = new QMessageBox ( | |
208 QMessageBox::Critical, tr ("Octave Editor"), | |
209 tr ("Could not open file %1 for read:\n%2."). | |
210 arg (openFileName).arg (result), | |
211 QMessageBox::Ok, 0); | |
212 msgBox->setWindowModality (Qt::NonModal); | |
213 msgBox->setAttribute (Qt::WA_DeleteOnClose); | |
214 msgBox->show (); | |
179 } | 215 } |
180 } | 216 } |
181 return; | 217 |
218 // really show editor and the current editor tab | |
219 set_focus (); | |
182 } | 220 } |
183 | |
184 file_editor_tab *fileEditorTab = new file_editor_tab (); | |
185 if (fileEditorTab) | |
186 { | |
187 QString result = fileEditorTab->load_file(openFileName); | |
188 if (result == "") | |
189 { | |
190 // Supply empty title then have the file_editor_tab update | |
191 // with full or short name. | |
192 add_file_editor_tab (fileEditorTab, ""); | |
193 fileEditorTab->update_window_title (false); | |
194 // file already loaded, add file to mru list here | |
195 handle_mru_add_file(QDir::cleanPath (openFileName)); | |
196 } | |
197 else | |
198 { | |
199 delete fileEditorTab; | |
200 // Create a NonModal message about error. | |
201 QMessageBox* msgBox = new QMessageBox ( | |
202 QMessageBox::Critical, tr ("Octave Editor"), | |
203 tr ("Could not open file %1 for read:\n%2."). | |
204 arg (openFileName).arg (result), | |
205 QMessageBox::Ok, 0); | |
206 msgBox->setWindowModality (Qt::NonModal); | |
207 msgBox->setAttribute (Qt::WA_DeleteOnClose); | |
208 msgBox->show (); | |
209 } | |
210 } | |
211 set_focus (); // really show editor and the current editor tab | |
212 } | 221 } |
213 } | 222 } |
214 | 223 |
215 // open a file from the mru list | 224 // open a file from the mru list |
216 void | 225 void |
226 | 235 |
227 void | 236 void |
228 file_editor::check_conflict_save (const QString& saveFileName, bool remove_on_success) | 237 file_editor::check_conflict_save (const QString& saveFileName, bool remove_on_success) |
229 { | 238 { |
230 // Have all file editor tabs signal what their file names are. | 239 // Have all file editor tabs signal what their file names are. |
231 fetFileNames.clear (); | 240 editor_tab_map.clear (); |
232 emit fetab_file_name_query (0); | 241 emit fetab_file_name_query (0); |
233 | 242 |
234 // If one of those names matches the desired name, that's a conflict. | 243 std::map<QString, QWidget *>::const_iterator p = editor_tab_map.find (saveFileName); |
235 if (fetFileNames.contains (saveFileName, Qt::CaseSensitive)) | 244 if (p != editor_tab_map.end ()) |
236 { | 245 { |
237 // Note: to overwrite the contents of some other file editor tab | 246 // Note: to overwrite the contents of some other file editor tab |
238 // with the same name requires identifying which file editor tab | 247 // with the same name requires identifying which file editor tab |
239 // that is (not too difficult) then close that tab. Of course, | 248 // that is (not too difficult) then close that tab. Of course, |
240 // that could trigger another dialog box if the file editor tab | 249 // that could trigger another dialog box if the file editor tab |
278 return; | 287 return; |
279 } | 288 } |
280 | 289 |
281 // Can save without conflict, have the file editor tab do so. | 290 // Can save without conflict, have the file editor tab do so. |
282 emit fetab_save_file (saveFileWidget, saveFileName, remove_on_success); | 291 emit fetab_save_file (saveFileWidget, saveFileName, remove_on_success); |
292 } | |
293 | |
294 void | |
295 file_editor::handle_dbstop_request (const QString& file, int line) | |
296 { | |
297 request_open_file (file, line, true); | |
283 } | 298 } |
284 | 299 |
285 void | 300 void |
286 file_editor::request_undo () | 301 file_editor::request_undo () |
287 { | 302 { |
482 } | 497 } |
483 } | 498 } |
484 } | 499 } |
485 | 500 |
486 void | 501 void |
487 file_editor::handle_add_filename_to_list (const QString& fileName) | 502 file_editor::handle_add_filename_to_list (const QString& fileName, QWidget *ID) |
488 { | 503 { |
489 fetFileNames.append (fileName); | 504 // Should we allow multiple tabs for a single file? |
505 | |
506 editor_tab_map[fileName] = ID; | |
490 } | 507 } |
491 | 508 |
492 void | 509 void |
493 file_editor::active_tab_changed (int index) | 510 file_editor::active_tab_changed (int index) |
494 { | 511 { |
786 this, SLOT (handle_file_name_changed (const QString&, const QString&))); | 803 this, SLOT (handle_file_name_changed (const QString&, const QString&))); |
787 connect (f, SIGNAL (editor_state_changed (bool, const QString&)), | 804 connect (f, SIGNAL (editor_state_changed (bool, const QString&)), |
788 this, SLOT (handle_editor_state_changed (bool, const QString&))); | 805 this, SLOT (handle_editor_state_changed (bool, const QString&))); |
789 connect (f, SIGNAL (tab_remove_request ()), | 806 connect (f, SIGNAL (tab_remove_request ()), |
790 this, SLOT (handle_tab_remove_request ())); | 807 this, SLOT (handle_tab_remove_request ())); |
791 connect (f, SIGNAL (add_filename_to_list (const QString&)), | 808 connect (f, SIGNAL (add_filename_to_list (const QString&, QWidget *)), |
792 this, SLOT (handle_add_filename_to_list (const QString&))); | 809 this, SLOT (handle_add_filename_to_list (const QString&, QWidget *))); |
793 connect (f, SIGNAL (editor_check_conflict_save (const QString&, bool)), | 810 connect (f, SIGNAL (editor_check_conflict_save (const QString&, bool)), |
794 this, SLOT (check_conflict_save (const QString&, bool))); | 811 this, SLOT (check_conflict_save (const QString&, bool))); |
795 connect (f, SIGNAL (mru_add_file (const QString&)), | 812 connect (f, SIGNAL (mru_add_file (const QString&)), |
796 this, SLOT (handle_mru_add_file (const QString&))); | 813 this, SLOT (handle_mru_add_file (const QString&))); |
797 connect (f, SIGNAL (process_octave_code (const QString&)), | 814 connect (f, SIGNAL (process_octave_code (const QString&)), |
845 f, SLOT (comment_selected_text (const QWidget*))); | 862 f, SLOT (comment_selected_text (const QWidget*))); |
846 connect (this, SIGNAL (fetab_uncomment_selected_text (const QWidget*)), | 863 connect (this, SIGNAL (fetab_uncomment_selected_text (const QWidget*)), |
847 f, SLOT (uncomment_selected_text (const QWidget*))); | 864 f, SLOT (uncomment_selected_text (const QWidget*))); |
848 connect (this, SIGNAL (fetab_find (const QWidget*)), | 865 connect (this, SIGNAL (fetab_find (const QWidget*)), |
849 f, SLOT (find (const QWidget*))); | 866 f, SLOT (find (const QWidget*))); |
850 connect (this, SIGNAL (fetab_goto_line (const QWidget*)), | 867 connect (this, SIGNAL (fetab_goto_line (const QWidget *, int)), |
851 f, SLOT (goto_line (const QWidget*))); | 868 f, SLOT (goto_line (const QWidget *, int))); |
852 connect (this, SIGNAL (fetab_set_focus (const QWidget*)), | 869 connect (this, SIGNAL (fetab_set_focus (const QWidget*)), |
853 f, SLOT (set_focus (const QWidget*))); | 870 f, SLOT (set_focus (const QWidget*))); |
871 connect (this, SIGNAL (fetab_set_debugger_position (const QWidget *, int)), | |
872 f, SLOT (set_debugger_position (const QWidget *, int))); | |
854 | 873 |
855 _tab_widget->setCurrentWidget (f); | 874 _tab_widget->setCurrentWidget (f); |
856 } | 875 } |
857 | 876 |
858 #endif | 877 #endif |