Mercurial > hg > octave-nkf
diff libgui/src/m-editor/file-editor-tab.cc @ 15425:8ae34ffe5c1b
Retain QsciAPIs lexer_api as part of lexer_octave_gui object (bug #37359)
This way, it may be deleted upon deconstruction and not cause
segmentation fault at startup
* file-editor-tab.cc, file-editor-tab.h
(file_editor_tab::update_tracked_file): Delete.
(file_editor_tab::set_file_name): Rather than clear whole list, just
subtract out the old file name then add the new name.
(file_editor_tab::load_file): Remove update_tracked_file, it's part
of set_file_name. (file_editor_tab::file_has_changed): Remove
update_tracked_file, it's part of set_file_name.
(file_editor_tab::save_file): Move file close before set_file_name
so watcher doesn't notice. Remove inelegant code that solved this by
clearing watcher files.
* lexer-octave-gui.cc, file-editor-tab.cc
(file_editor_tab::update_lexer, lexer_octave_gui::lexer_octave_gui,
lexer_octave_gui : public QsciLexer): Move all the lexer preparatory
code to the constructor so that lexer_api can be retained as part of
object. (lexer_octave_gui::~lexer_octave_gui): Make destructor
non-virtual and delete lexer_gui when done.
* octave-gui.cc, main-window-h, main-window.cc, file-editor.cc
(octave_start_gui, file_editor::construct): Move read_settings from
constructor to after construction in octave_start_gui so that no
signal occur referencing a partially constructed object.
* file-editor.cc (file_editor::construct): Tidy code.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Thu, 20 Sep 2012 04:08:53 -0500 |
parents | 7f423c6111c6 |
children | 87c3704b5c7a |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -145,9 +145,15 @@ void file_editor_tab::set_file_name (const QString& fileName) { + // update tracked file + QStringList trackedFiles = _file_system_watcher.files (); + if (!trackedFiles.isEmpty ()) + _file_system_watcher.removePath (_file_name); + _file_system_watcher.addPath (fileName); _file_name = fileName; + + // update lexer after _file_name change update_lexer (); - update_tracked_file (); } void @@ -188,31 +194,6 @@ if (_file_name.endsWith (".m") || _file_name.endsWith (".M")) { lexer = new lexer_octave_gui (); - - // The API info that is used for auto completion - // TODO: Where to store a file with API info (raw or prepared?)? - // TODO: Also provide infos on octave-forge functions? - // TODO: Also provide infos on function parameters? - // By now, use the keywords-list from syntax highlighting - - QsciAPIs *lexer_api = new QsciAPIs (lexer); - - QString keyword; - QStringList keywordList; - - // get whole string with all keywords - keyword = lexer->keywords (1); - // split into single strings - keywordList = keyword.split (QRegExp ("\\s+")); - - int i; - for (i = 0; i < keywordList.size (); i++) - { - // add single strings to the API - lexer_api->add (keywordList.at (i)); - } - // prepare API info ... this make take some time - lexer_api->prepare (); } else if (_file_name.endsWith (".c") || _file_name.endsWith (".cc") @@ -365,24 +346,13 @@ emit editor_state_changed (); } -void -file_editor_tab::update_tracked_file () -{ - QStringList trackedFiles = _file_system_watcher.files (); - if (!trackedFiles.isEmpty ()) - _file_system_watcher.removePaths (trackedFiles); - - if (_file_name != UNNAMED_FILE) - _file_system_watcher.addPath (_file_name); -} - int file_editor_tab::check_file_modified (const QString& msg, int cancelButton) { int decision = QMessageBox::Yes; if (_edit_area->isModified ()) { - // file is modified but not saved, aks user what to do + // file is modified but not saved, ask user what to do decision = QMessageBox::warning (this, msg, tr ("The file %1\n" @@ -590,9 +560,6 @@ QApplication::restoreOverrideCursor (); set_file_name (fileName); - update_tracked_file (); - - update_window_title (false); // window title (no modification) _edit_area->setModified (false); // loaded file is not modified yet @@ -627,10 +594,6 @@ return save_file_as(); } - QStringList watched_files = _file_system_watcher.files(); - if (!watched_files.isEmpty ()) - _file_system_watcher.removePaths(watched_files); - // open the file for writing QFile file (saveFileName); if (!file.open (QFile::WriteOnly)) @@ -638,7 +601,6 @@ QMessageBox::warning (this, tr ("Octave Editor"), tr ("Could not open file %1 for write:\n%2."). arg (saveFileName).arg (file.errorString ())); - _file_system_watcher.addPaths (watched_files); return false; } @@ -647,17 +609,15 @@ QApplication::setOverrideCursor (Qt::WaitCursor); out << _edit_area->text (); QApplication::restoreOverrideCursor (); + file.close(); - // save file name for later use - _file_name = saveFileName; + // save file name after closing file otherwise tracker will notice file change + set_file_name (saveFileName); // set the window title to actual file name (not modified) update_window_title (false); // files is save -> not modified _edit_area->setModified (false); - file.close(); - if (!watched_files.isEmpty ()) - _file_system_watcher.addPaths (watched_files); return true; } @@ -760,7 +720,6 @@ set_file_name (UNNAMED_FILE); update_window_title (true); // window title (no modification) set_modified (true); - update_tracked_file (); } } else