Mercurial > octave-dspies
comparison libgui/src/m-editor/file-editor-tab.cc @ 19004:e87e65bc71ae gui-release
improved finding a function file for editing in gui (bug #41509)
* octave-qscintilla.h: new signal context_menu_edit_signal
* octave-qscintilla.cc (contextmenu_edit): only emit a new signal, handling
of this menu action has been moved to file_editor_tab
* file-editor-tab.h: new slot handle_context_menu_edit
* file-editor-tab.cc (constructor): connect new signal from octave-qscintilla
to the related new slot for handling the edit function event;
(handle_context_menu_edit): new slot searching for a matching subfunction,
a private function or one within the same directory when __which__ returns an
empty type; old contents from contextmenu_edit has moved here as well
author | Torsten <ttl@justmail.de> |
---|---|
date | Mon, 11 Aug 2014 17:24:37 +0200 |
parents | 0be65bd7f369 |
children | bf7c5d96d1ff |
comparison
equal
deleted
inserted
replaced
19002:00b1d60500bd | 19004:e87e65bc71ae |
---|---|
58 #include "debug.h" | 58 #include "debug.h" |
59 #include "octave-qt-link.h" | 59 #include "octave-qt-link.h" |
60 #include "version.h" | 60 #include "version.h" |
61 #include "utils.h" | 61 #include "utils.h" |
62 #include "defaults.h" | 62 #include "defaults.h" |
63 #include <oct-map.h> | |
63 | 64 |
64 // Make parent null for the file editor tab so that warning | 65 // Make parent null for the file editor tab so that warning |
65 // WindowModal messages don't affect grandparents. | 66 // WindowModal messages don't affect grandparents. |
66 file_editor_tab::file_editor_tab (const QString& directory_arg) | 67 file_editor_tab::file_editor_tab (const QString& directory_arg) |
67 { | 68 { |
93 this, | 94 this, |
94 SLOT (handle_cursor_moved (int,int))); | 95 SLOT (handle_cursor_moved (int,int))); |
95 | 96 |
96 connect (_edit_area, SIGNAL (create_context_menu_signal (QMenu*)), | 97 connect (_edit_area, SIGNAL (create_context_menu_signal (QMenu*)), |
97 this, SLOT (create_context_menu (QMenu*))); | 98 this, SLOT (create_context_menu (QMenu*))); |
99 connect (_edit_area, SIGNAL (context_menu_edit_signal (const QString&)), | |
100 this, SLOT (handle_context_menu_edit (const QString&))); | |
98 | 101 |
99 // create statusbar for row/col indicator | 102 // create statusbar for row/col indicator |
100 _status_bar = new QStatusBar (this); | 103 _status_bar = new QStatusBar (this); |
101 | 104 |
102 _row_indicator = new QLabel ("", this); | 105 _row_indicator = new QLabel ("", this); |
200 | 203 |
201 void | 204 void |
202 file_editor_tab::execute_command_in_terminal (const QString& command) | 205 file_editor_tab::execute_command_in_terminal (const QString& command) |
203 { | 206 { |
204 emit execute_command_in_terminal_signal (command); // connected to main window | 207 emit execute_command_in_terminal_signal (command); // connected to main window |
208 } | |
209 | |
210 void | |
211 file_editor_tab::handle_context_menu_edit (const QString& word_at_cursor) | |
212 { | |
213 // search for a subfunction in actual file (this is done at first because | |
214 // octave finds this function before other with same name in the search path | |
215 QRegExp rxfun1 ("^[\t ]*function[^=]+=[\t ]*" | |
216 + word_at_cursor + "[\t ]*\\([^\\)]*\\)[\t ]*$"); | |
217 QRegExp rxfun2 ("^[\t ]*function[\t ]+" | |
218 + word_at_cursor + "[\t ]*\\([^\\)]*\\)[\t ]*$"); | |
219 QRegExp rxfun3 ("^[\t ]*function[\t ]+" | |
220 + word_at_cursor + "[\t ]*$"); | |
221 QRegExp rxfun4 ("^[\t ]*function[^=]+=[\t ]*" | |
222 + word_at_cursor + "[\t ]*$"); | |
223 | |
224 int pos_fct = -1; | |
225 QStringList lines = _edit_area->text ().split ("\n"); | |
226 | |
227 int line; | |
228 for (line = 0; line < lines.count (); line++) | |
229 { | |
230 if ((pos_fct = rxfun1.indexIn (lines.at (line))) != -1) | |
231 break; | |
232 if ((pos_fct = rxfun2.indexIn (lines.at (line))) != -1) | |
233 break; | |
234 if ((pos_fct = rxfun3.indexIn (lines.at (line))) != -1) | |
235 break; | |
236 if ((pos_fct = rxfun4.indexIn (lines.at (line))) != -1) | |
237 break; | |
238 } | |
239 | |
240 if (pos_fct > -1) | |
241 { // reg expr. found: it is an internal function | |
242 _edit_area->setCursorPosition (line, pos_fct); | |
243 _edit_area->SendScintilla (2613, line); // SCI_SETFIRSTVISIBLELINE | |
244 return; | |
245 } | |
246 | |
247 // Is it a regular function within the search path? (Call __which__) | |
248 octave_value_list fct = F__which__ (ovl (word_at_cursor.toStdString ()),0); | |
249 octave_map map = fct(0).map_value (); | |
250 | |
251 QString type = QString::fromStdString ( | |
252 map.contents ("type").data ()[0].string_value ()); | |
253 QString name = QString::fromStdString ( | |
254 map.contents ("name").data ()[0].string_value ()); | |
255 | |
256 QString message = QString (); | |
257 QString filename = QString (); | |
258 | |
259 if (type == QString("built-in function")) | |
260 { // built in function: can't edit | |
261 message = tr ("%1 is a built-in function"); | |
262 } | |
263 else if (type.isEmpty ()) | |
264 { | |
265 // function not known to octave -> try directory of edited file | |
266 QFileInfo file = QFileInfo (_file_name); | |
267 file = QFileInfo (QDir (file.canonicalPath ()), word_at_cursor + ".m"); | |
268 | |
269 if (file.exists ()) | |
270 { | |
271 filename = file.canonicalFilePath (); // local file exists | |
272 } | |
273 else | |
274 { // local file does not exist -> try private directory | |
275 file = QFileInfo (_file_name); | |
276 file = QFileInfo (QDir (file.canonicalPath () + "/private"), | |
277 word_at_cursor + ".m"); | |
278 | |
279 if (file.exists ()) | |
280 { | |
281 filename = file.canonicalFilePath (); // private function exists | |
282 } | |
283 else | |
284 { | |
285 message = tr ("Can not find function %1"); // no file found | |
286 } | |
287 } | |
288 } | |
289 | |
290 if (! message.isEmpty ()) | |
291 { | |
292 QMessageBox *msgBox | |
293 = new QMessageBox (QMessageBox::Critical, | |
294 tr ("Octave Editor"), | |
295 message.arg (name), | |
296 QMessageBox::Ok, this); | |
297 | |
298 msgBox->setWindowModality (Qt::NonModal); | |
299 msgBox->setAttribute (Qt::WA_DeleteOnClose); | |
300 msgBox->show (); | |
301 return; | |
302 } | |
303 | |
304 if ( filename.isEmpty ()) | |
305 filename = QString::fromStdString ( | |
306 map.contents ("file").data ()[0].string_value ()); | |
307 | |
308 emit execute_command_in_terminal_signal (QString("edit ") | |
309 + "\""+filename+"\""); | |
205 } | 310 } |
206 | 311 |
207 void | 312 void |
208 file_editor_tab::set_file_name (const QString& fileName) | 313 file_editor_tab::set_file_name (const QString& fileName) |
209 { | 314 { |