Mercurial > octave
diff libgui/src/m-editor/file-editor.cc @ 20814:2da4058d65c7
store the encoding of recent editor files in the mru list
* file-editor-tab.cc (set_file_name): signal mru_add_file now with encoding
* file-editor-tab.h: signal mru_add_file now with encoding
* file-editor.cc (call_custom_editor, request_open_file):
handle_mru_add_file with encoding;
(request_mru_open_file): call request_open_file with encoding;
(handle_mru_add_file) takes encoding as additional parameter and adds it
to a second list;
(mru_menu_update): store encoding together with file name in action data,
ensure correct length of both lists;
(construct): get mru lists and check for length of lists with encodings;
(add_file_editor_tab) update connection of mru_add_file signal;
* file-editor.h: slot handle_mru_add_file with encoding, class variable for
list of mru encodingds
author | Torsten <ttl@justmail.de> |
---|---|
date | Sun, 06 Dec 2015 09:35:28 +0100 |
parents | ed770c16a3e8 |
children | 77f5591878bf |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Sun Dec 06 09:14:55 2015 +0100 +++ b/libgui/src/m-editor/file-editor.cc Sun Dec 06 09:35:28 2015 +0100 @@ -344,7 +344,8 @@ } if (line < 0 && ! file_name.isEmpty ()) - handle_mru_add_file (QFileInfo (file_name).canonicalFilePath ()); + handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (), + QString ()); return true; } @@ -439,7 +440,8 @@ fileEditorTab->update_window_title (false); // file already loaded, add file to mru list here QFileInfo file_info = QFileInfo (openFileName); - handle_mru_add_file (file_info.canonicalFilePath ()); + handle_mru_add_file (file_info.canonicalFilePath (), + encoding); if (line > 0) { @@ -542,7 +544,8 @@ { if (action) { - request_open_file (action->data ().toString ()); + request_open_file (action->data ().toStringList ().at (0), + action->data ().toStringList ().at (1)); } } @@ -938,13 +941,18 @@ } void -file_editor::handle_mru_add_file (const QString& file_name) +file_editor::handle_mru_add_file (const QString& file_name, + const QString& encoding) { - if (_mru_files.count () && _mru_files.at (0) == file_name) - return; // the first entry is already the actual filename + int index; + while ((index = _mru_files.indexOf (file_name)) >= 0) + { + _mru_files.removeAt (index); + _mru_files_encodings.removeAt (index); + } - _mru_files.removeAll (file_name); _mru_files.prepend (file_name); + _mru_files_encodings.prepend (encoding); mru_menu_update (); } @@ -960,7 +968,11 @@ QString text = tr ("&%1 %2"). arg ((i+1) % int (MaxMRUFiles)).arg (_mru_files.at (i)); _mru_file_actions[i]->setText (text); - _mru_file_actions[i]->setData (_mru_files.at (i)); + + QStringList action_data; + action_data << _mru_files.at (i) << _mru_files_encodings.at (i); + _mru_file_actions[i]->setData (action_data); + _mru_file_actions[i]->setVisible (true); } @@ -970,13 +982,16 @@ // delete entries in string-list beyond MaxMRUFiles while (_mru_files.size () > MaxMRUFiles) - _mru_files.removeLast (); + { + _mru_files.removeLast (); + _mru_files_encodings.removeLast (); + } // save actual mru-list in settings QSettings *settings = resource_manager::get_settings (); - // FIXME: what should happen if settings is 0? settings->setValue ("editor/mru_file_list", _mru_files); + settings->setValue ("editor/mru_file_encodings", _mru_files_encodings); settings->sync (); } @@ -1330,6 +1345,16 @@ // the mru-list and an empty array of actions QSettings *settings = resource_manager::get_settings (); _mru_files = settings->value ("editor/mru_file_list").toStringList (); + _mru_files_encodings = settings->value ("editor/mru_file_encodings") + .toStringList (); + + if (_mru_files_encodings.count () != _mru_files.count ()) + { // encodings don't have the same count -> do not use them! + _mru_files_encodings = QStringList (); + for (int i = 0; i < _mru_files.count (); i++) + _mru_files_encodings << QString (); + } + for (int i = 0; i < MaxMRUFiles; ++i) { _mru_file_actions[i] = new QAction (this); @@ -1744,8 +1769,8 @@ connect (f, SIGNAL (editor_check_conflict_save (const QString&, bool)), this, SLOT (check_conflict_save (const QString&, bool))); - connect (f, SIGNAL (mru_add_file (const QString&)), - this, SLOT (handle_mru_add_file (const QString&))); + connect (f, SIGNAL (mru_add_file (const QString&, const QString&)), + this, SLOT (handle_mru_add_file (const QString&, const QString&))); connect (f, SIGNAL (run_file_signal (const QFileInfo&)), main_win (), SLOT (run_file_in_terminal (const QFileInfo&)));