Mercurial > octave-nkf
comparison libgui/src/m-editor/file-editor-tab.cc @ 18867:6504a1932637 gui-release
auto completion offers builtins and file functions for octave (bug #41371)
* file-editor-tab.cc (update_lexer): read settings whether builtin and file
functions should also be considered in auto completion for octave files;
when functions are also displayed, updating of the files with prepared auto
completion informations depends on last modification date of package lists;
(add_octave_apis): new function for adding strings to the lexer APIs from
the internal octave functions
* file-editor-tab.h (add_octave_apis): new function
* main-window.cc (handle_octave_ready): call function for creating the empty
tab in the editor here because all octave functions must be known for creating
the auto completion information
* settings-dialog.ui: new checkboxes for auto completion of octaves
buitlin and file functions
* settings-dialog.cc (constructor): read states for new checkboxes from the
settings file;
(write_changed_settings): write states of new checkboxes into the settings
file
author | Torsten <ttl@justmail.de> |
---|---|
date | Mon, 16 Jun 2014 12:11:21 +0200 |
parents | 095fdef3d67c |
children | 0e6f7b5f6556 |
comparison
equal
deleted
inserted
replaced
18862:4b98fc5c2eb1 | 18867:6504a1932637 |
---|---|
46 #include <QMessageBox> | 46 #include <QMessageBox> |
47 #include <QTextStream> | 47 #include <QTextStream> |
48 #include <QVBoxLayout> | 48 #include <QVBoxLayout> |
49 #include <QInputDialog> | 49 #include <QInputDialog> |
50 #include <QPrintDialog> | 50 #include <QPrintDialog> |
51 #include <QDateTime> | |
51 | 52 |
52 #include "file-editor-tab.h" | 53 #include "file-editor-tab.h" |
53 #include "file-editor.h" | 54 #include "file-editor.h" |
54 | 55 |
55 #include "file-ops.h" | 56 #include "file-ops.h" |
56 | 57 |
57 #include "debug.h" | 58 #include "debug.h" |
58 #include "octave-qt-link.h" | 59 #include "octave-qt-link.h" |
59 #include "version.h" | 60 #include "version.h" |
60 #include "utils.h" | 61 #include "utils.h" |
62 #include "defaults.h" | |
61 | 63 |
62 // Make parent null for the file editor tab so that warning | 64 // Make parent null for the file editor tab so that warning |
63 // WindowModal messages don't affect grandparents. | 65 // WindowModal messages don't affect grandparents. |
64 file_editor_tab::file_editor_tab (const QString& directory_arg) | 66 file_editor_tab::file_editor_tab (const QString& directory_arg) |
65 { | 67 { |
328 // other or no extension | 330 // other or no extension |
329 lexer = new QsciLexerBash (); | 331 lexer = new QsciLexerBash (); |
330 } | 332 } |
331 } | 333 } |
332 | 334 |
335 QSettings *settings = resource_manager::get_settings (); | |
336 | |
337 // build information for auto completion (APIs) | |
333 _lexer_apis = new QsciAPIs(lexer); | 338 _lexer_apis = new QsciAPIs(lexer); |
339 | |
334 if (_lexer_apis) | 340 if (_lexer_apis) |
335 { | 341 { |
342 bool update_apis_file = false; // flag, whether update of apis files | |
343 | |
336 // get path to prepared api info | 344 // get path to prepared api info |
337 QDesktopServices desktopServices; | 345 QDesktopServices desktopServices; |
338 QString prep_apis_path | 346 QString prep_apis_path |
339 = desktopServices.storageLocation (QDesktopServices::HomeLocation) | 347 = desktopServices.storageLocation (QDesktopServices::HomeLocation) |
340 + "/.config/octave/" + QString(OCTAVE_VERSION) + "/qsci/"; | 348 + "/.config/octave/" + QString(OCTAVE_VERSION) + "/qsci/"; |
341 _prep_apis_file = prep_apis_path + lexer->lexer () + ".pap"; | 349 |
342 | 350 // get settings which infos are used for octave |
343 if (!_lexer_apis->loadPrepared (_prep_apis_file)) | 351 bool octave_builtins = settings->value ( |
352 "editor/codeCompletion_octave_builtins", true).toBool (); | |
353 bool octave_functions = settings->value ( | |
354 "editor/codeCompletion_octave_functions", true).toBool (); | |
355 | |
356 if (_is_octave_file) | |
357 { | |
358 // octave file: keywords are always used | |
359 _prep_apis_file = prep_apis_path + lexer->lexer () + "_k"; | |
360 | |
361 if (octave_builtins) | |
362 _prep_apis_file = _prep_apis_file + "b"; // use builtins, too | |
363 | |
364 if (octave_functions) | |
365 _prep_apis_file = _prep_apis_file + "f"; // use keywords, too | |
366 | |
367 _prep_apis_file = _prep_apis_file + ".pap"; // final name of apis file | |
368 | |
369 // check whether the APIs info needs to be prepared and saved | |
370 QFileInfo apis_file = QFileInfo (_prep_apis_file); | |
371 update_apis_file = ! apis_file.exists (); // flag whether apis file needs update | |
372 | |
373 // function list depends on installed packages: check mod. date | |
374 if (! update_apis_file & octave_functions) | |
375 { | |
376 // check whether package file is newer than apis_file | |
377 QDateTime apis_date = apis_file.lastModified (); | |
378 | |
379 // compare to local package list | |
380 // FIXME: How to get user chosen location? | |
381 QFileInfo local_pkg_list = QFileInfo ( | |
382 desktopServices.storageLocation (QDesktopServices::HomeLocation) | |
383 + "/.octave_packages"); | |
384 if (local_pkg_list.exists () | |
385 & (apis_date < local_pkg_list.lastModified ()) ) | |
386 update_apis_file = true; | |
387 | |
388 // compare to global package list | |
389 // FIXME: How to get user chosen location? | |
390 QFileInfo global_pkg_list = QFileInfo ( | |
391 QString::fromStdString (Voctave_home) | |
392 + "/share/octave/octave_packages"); | |
393 if (global_pkg_list.exists () | |
394 & (apis_date < global_pkg_list.lastModified ()) ) | |
395 update_apis_file = true; | |
396 } | |
397 } | |
398 else // no octave file, just add extension | |
399 { | |
400 _prep_apis_file = prep_apis_path + lexer->lexer () + ".pap"; | |
401 } | |
402 | |
403 if (update_apis_file | !_lexer_apis->loadPrepared (_prep_apis_file)) | |
344 { | 404 { |
345 // no prepared info loaded, prepare and save if possible | 405 // no prepared info loaded, prepare and save if possible |
346 | 406 |
347 // create raw apis info | 407 // create raw apis info |
348 QString keyword; | 408 QString keyword; |
349 QStringList keyword_list; | 409 QStringList keyword_list; |
350 int i,j; | 410 int i,j; |
351 for (i=1; i<=3; i++) // test the first 5 keyword sets | 411 |
412 if (_is_octave_file) | |
352 { | 413 { |
353 keyword = QString(lexer->keywords (i)); // get list | 414 // octave: get keywords from internal informations depending on |
354 keyword_list = keyword.split (QRegExp ("\\s+")); // split | 415 // user preferences |
355 for (j = 0; j < keyword_list.size (); j++) // add to API | 416 |
356 _lexer_apis->add (keyword_list.at (j)); | 417 // keywords are always used |
418 add_octave_apis (F__keywords__ ()); // add new entries | |
419 | |
420 if (octave_builtins) | |
421 add_octave_apis (F__builtins__ ()); // add new entries | |
422 | |
423 if (octave_functions) | |
424 add_octave_apis (F__list_functions__ ()); // add new entries | |
425 | |
426 } | |
427 else | |
428 { | |
429 | |
430 _prep_apis_file = prep_apis_path + lexer->lexer () + ".pap"; | |
431 | |
432 for (i=1; i<=3; i++) // test the first 5 keyword sets | |
433 { | |
434 keyword = QString(lexer->keywords (i)); // get list | |
435 keyword_list = keyword.split (QRegExp ("\\s+")); // split | |
436 for (j = 0; j < keyword_list.size (); j++) // add to API | |
437 _lexer_apis->add (keyword_list.at (j)); | |
438 } | |
357 } | 439 } |
358 | 440 |
359 // dsiconnect slot for saving prepared info if already connected | 441 // dsiconnect slot for saving prepared info if already connected |
360 disconnect (_lexer_apis, SIGNAL (apiPreparationFinished ()), 0, 0); | 442 disconnect (_lexer_apis, SIGNAL (apiPreparationFinished ()), 0, 0); |
361 // check whether path for prepared info exists or can be created | 443 // check whether path for prepared info exists or can be created |
367 } | 449 } |
368 _lexer_apis->prepare (); // prepare apis info | 450 _lexer_apis->prepare (); // prepare apis info |
369 } | 451 } |
370 } | 452 } |
371 | 453 |
372 QSettings *settings = resource_manager::get_settings (); | 454 lexer->readSettings (*settings); |
373 if (settings) | |
374 lexer->readSettings (*settings); | |
375 | 455 |
376 _edit_area->setLexer (lexer); | 456 _edit_area->setLexer (lexer); |
377 | 457 |
378 // fix line number width with respect to the font size of the lexer | 458 // fix line number width with respect to the font size of the lexer |
379 if (settings->value ("editor/showLineNumbers", true).toBool ()) | 459 if (settings->value ("editor/showLineNumbers", true).toBool ()) |
380 auto_margin_width (); | 460 auto_margin_width (); |
381 else | 461 else |
382 _edit_area->setMarginWidth (2,0); | 462 _edit_area->setMarginWidth (2,0); |
383 | 463 |
464 } | |
465 | |
466 // function for adding entries to the octave lexer's APIs | |
467 void | |
468 file_editor_tab::add_octave_apis (octave_value_list key_ovl) | |
469 { | |
470 octave_value keys = key_ovl(0); | |
471 Cell key_list = keys.cell_value (); | |
472 | |
473 for (int idx = 0; idx < key_list.numel (); idx++) | |
474 _lexer_apis->add (QString (key_list.elem (idx).string_value ().data ())); | |
384 } | 475 } |
385 | 476 |
386 void | 477 void |
387 file_editor_tab::save_apis_info () | 478 file_editor_tab::save_apis_info () |
388 { | 479 { |