changeset 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 7349de0bf744
children 6935b8f038cc
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h
diffstat 4 files changed, 41 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun Dec 06 09:14:55 2015 +0100
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun Dec 06 09:35:28 2015 +0100
@@ -376,7 +376,7 @@
   emit editor_state_changed (_copy_available, _is_octave_file);
 
   // add the new file to the mru list
-  emit mru_add_file (_file_name);
+  emit mru_add_file (_file_name, _encoding);
 }
 
 // valid_file_name (file): checks whether "file" names a file
--- a/libgui/src/m-editor/file-editor-tab.h	Sun Dec 06 09:14:55 2015 +0100
+++ b/libgui/src/m-editor/file-editor-tab.h	Sun Dec 06 09:35:28 2015 +0100
@@ -136,7 +136,7 @@
   void editor_state_changed (bool copy_available, bool is_octave_file);
   void tab_remove_request ();
   void add_filename_to_list (const QString&, const QString&, QWidget *);
-  void mru_add_file (const QString& file_name);
+  void mru_add_file (const QString& file_name, const QString& encoding);
   void editor_check_conflict_save (const QString& saveFileName,
                                    bool remove_on_success);
   void run_file_signal (const QFileInfo& info);
--- 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&)));
--- a/libgui/src/m-editor/file-editor.h	Sun Dec 06 09:14:55 2015 +0100
+++ b/libgui/src/m-editor/file-editor.h	Sun Dec 06 09:35:28 2015 +0100
@@ -220,7 +220,7 @@
                                     const QString& encoding, QWidget *ID);
   void active_tab_changed (int index);
   void handle_editor_state_changed (bool enableCopy, bool is_octave_file);
-  void handle_mru_add_file (const QString& file_name);
+  void handle_mru_add_file (const QString& file_name, const QString& encoding);
   void check_conflict_save (const QString& fileName, bool remove_on_success);
 
   void handle_insert_debugger_pointer_request (const QString& file, int line);
@@ -407,6 +407,7 @@
   QMenu *_mru_file_menu;
   QAction *_mru_file_actions[MaxMRUFiles];
   QStringList _mru_files;
+  QStringList _mru_files_encodings;
 };
 
 #endif // FILEEDITORMDISUBWINDOW_H