# HG changeset patch # User Torsten # Date 1449389695 -3600 # Node ID 7349de0bf744bcd5c76a878f0134f9139c4d9665 # Parent d9ca869ca124b827604d20cf5e8924ace874805c# Parent ed770c16a3e8ca61c8b6854eedb25bb7b1235b8f maint: merge away accidental head diff -r d9ca869ca124 -r 7349de0bf744 libgui/src/m-editor/file-editor-interface.h --- a/libgui/src/m-editor/file-editor-interface.h Sat Dec 05 15:59:22 2015 -0800 +++ b/libgui/src/m-editor/file-editor-interface.h Sun Dec 06 09:14:55 2015 +0100 @@ -71,7 +71,9 @@ virtual void request_new_script (const QString& command = QString ()) = 0; virtual void request_new_function (bool) = 0; virtual void request_open_file () = 0; - virtual void request_open_file (const QString& openFileName, int line = -1, + virtual void request_open_file (const QString& openFileName, + const QString& encoding = QString (), + int line = -1, bool debug_pointer = false, bool breakpoint_marker = false, bool insert = true) = 0; diff -r d9ca869ca124 -r 7349de0bf744 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sat Dec 05 15:59:22 2015 -0800 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Dec 06 09:14:55 2015 +0100 @@ -2063,7 +2063,7 @@ // Unnamed files shouldn't be transmitted. if (!_file_name.isEmpty ()) - emit add_filename_to_list (_file_name, this); + emit add_filename_to_list (_file_name, _encoding, this); } void diff -r d9ca869ca124 -r 7349de0bf744 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sat Dec 05 15:59:22 2015 -0800 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Dec 06 09:14:55 2015 +0100 @@ -135,7 +135,7 @@ void file_name_changed (const QString& fileName, const QString& toolTip); void editor_state_changed (bool copy_available, bool is_octave_file); void tab_remove_request (); - void add_filename_to_list (const QString&, QWidget *); + void add_filename_to_list (const QString&, const QString&, QWidget *); void mru_add_file (const QString& file_name); void editor_check_conflict_save (const QString& saveFileName, bool remove_on_success); diff -r d9ca869ca124 -r 7349de0bf744 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sat Dec 05 15:59:22 2015 -0800 +++ b/libgui/src/m-editor/file-editor.cc Sun Dec 06 09:14:55 2015 +0100 @@ -79,16 +79,29 @@ emit fetab_file_name_query (0); // save filenames (even if last session will not be restored next time) + // together with encoding and the tab index QStringList fetFileNames; + QStringList fet_encodings; + QStringList fet_index; + + // over all open tabs for (editor_tab_map_const_iterator p = editor_tab_map.begin (); p != editor_tab_map.end (); p++) { - QString file_name = p->first; - if (!file_name.isEmpty ()) - fetFileNames.append (p->first); // do not append unnamed files + QString file_name = p->first; // get file name of tab + if (!file_name.isEmpty ()) // do not append unnamed files + { + fetFileNames.append (file_name); + fet_encodings.append (editor_tab_map[file_name].encoding); + QString index; + fet_index.append (index.setNum + (_tab_widget->indexOf (editor_tab_map[file_name].fet_ID))); + } } settings->setValue ("editor/savedSessionTabs", fetFileNames); + settings->setValue ("editor/saved_session_encodings", fet_encodings); + settings->setValue ("editor/saved_session_tab_index", fet_index); settings->sync (); // Save all tabs with confirmation. @@ -241,6 +254,7 @@ QLabel *label_enc = new QLabel (tr ("File Encoding:")); QComboBox *combo_enc = new QComboBox (); resource_manager::combo_encoding (combo_enc); + _file_encoding = QString (); // default, no special encoding // track changes in the combo boxes connect (combo_enc, SIGNAL (currentIndexChanged (QString)), @@ -290,7 +304,7 @@ if (same_file (file.toStdString (), tab_file.toStdString ())) { - retval = p->second; + retval = p->second.fet_ID; break; } } @@ -356,19 +370,19 @@ } // The following slot is called after files have been selected in the -// open file dialog, possibly with a new selected encoding. After loading -// all files, _file_encoding is reset. +// open file dialog, possibly with a new selected encoding stored in +// _file_encoding void file_editor::request_open_files (const QStringList& open_file_names) { for (int i = 0; i < open_file_names.count (); i++) - request_open_file (open_file_names.at (i)); - _file_encoding = QString (); // reset: no special encoding + request_open_file (open_file_names.at (i), _file_encoding); } void -file_editor::request_open_file (const QString& openFileName, int line, - bool debug_pointer, +file_editor::request_open_file (const QString& openFileName, + const QString& encoding, + int line, bool debug_pointer, bool breakpoint_marker, bool insert) { if (call_custom_editor (openFileName, line)) @@ -415,7 +429,7 @@ file_editor_tab *fileEditorTab = new file_editor_tab (); if (fileEditorTab) { - fileEditorTab->set_encoding (_file_encoding); + fileEditorTab->set_encoding (encoding); QString result = fileEditorTab->load_file (openFileName); if (result == "") { @@ -602,7 +616,7 @@ file_editor::handle_insert_debugger_pointer_request (const QString& file, int line) { - request_open_file (file, line, true); + request_open_file (file, QString (), line, true); // default encoding } void @@ -635,7 +649,7 @@ const QString& file, int line) { - request_open_file (file, line, false, true, insert); + request_open_file (file, QString (), line, false, true, insert); } void @@ -1054,11 +1068,12 @@ } void -file_editor::handle_add_filename_to_list (const QString& fileName, QWidget *ID) +file_editor::handle_add_filename_to_list (const QString& fileName, + const QString& encoding, QWidget *ID) { // Should we allow multiple tabs for a single file? - - editor_tab_map[fileName] = ID; + editor_tab_map[fileName].fet_ID = ID; + editor_tab_map[fileName].encoding = encoding; } // context menu of edit area @@ -1644,22 +1659,52 @@ setWindowIcon (QIcon (":/actions/icons/logo.png")); set_title (tr ("Editor")); + restore_session (settings); + + check_actions (); +} + +void +file_editor::restore_session (QSettings *settings) +{ //restore previous session - if (settings->value ("editor/restoreSession", true).toBool ()) - { - QStringList sessionFileNames - = settings->value ("editor/savedSessionTabs", - QStringList ()).toStringList (); + if (! settings->value ("editor/restoreSession", true).toBool ()) + return; + + // get the data from the settings file + QStringList sessionFileNames = settings->value ("editor/savedSessionTabs", + QStringList ()).toStringList (); + QStringList session_encodings = settings->value ("editor/saved_session_encodings", + QStringList ()).toStringList (); + QStringList session_index = settings->value ("editor/saved_session_tab_index", + QStringList ()).toStringList (); - for (int n = 0; n < sessionFileNames.count (); ++n) - { - QFileInfo file = QFileInfo (sessionFileNames.at (n)); - if (file.exists ()) - request_open_file (sessionFileNames.at (n)); - } + // fill a list of the struct and sort it (depending on index) + QList s_data; + + bool do_encoding = (session_encodings.count () == sessionFileNames.count ()); + bool do_index = (session_index.count () == sessionFileNames.count ()); + + for (int n = 0; n < sessionFileNames.count (); ++n) + { + QFileInfo file = QFileInfo (sessionFileNames.at (n)); + if (! file.exists ()) + continue; + + session_data item = { QString (), sessionFileNames.at (n), QString ()}; + if (do_index) + item.index = session_index.at (n); + if (do_encoding) + item.encoding = session_encodings.at (n); + + s_data << item; } - check_actions (); + qSort (s_data); + + // finally open the file with the desired encoding in the desired order + for (int n = 0; n < s_data.count (); ++n) + request_open_file (s_data.at (n).file_name, s_data.at (n).encoding); } void @@ -1691,8 +1736,10 @@ connect (f, SIGNAL (tab_remove_request ()), this, SLOT (handle_tab_remove_request ())); - connect (f, SIGNAL (add_filename_to_list (const QString&, QWidget*)), - this, SLOT (handle_add_filename_to_list (const QString&, QWidget*))); + connect (f, SIGNAL (add_filename_to_list (const QString&, + const QString&, QWidget*)), + this, SLOT (handle_add_filename_to_list (const QString&, + const QString&, QWidget*))); connect (f, SIGNAL (editor_check_conflict_save (const QString&, bool)), this, SLOT (check_conflict_save (const QString&, bool))); diff -r d9ca869ca124 -r 7349de0bf744 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sat Dec 05 15:59:22 2015 -0800 +++ b/libgui/src/m-editor/file-editor.h Sun Dec 06 09:14:55 2015 +0100 @@ -56,8 +56,26 @@ public: - typedef std::map::iterator editor_tab_map_iterator; - typedef std::map::const_iterator editor_tab_map_const_iterator; + struct tab_info + { + QWidget *fet_ID; + QString encoding; + }; + + typedef std::map::iterator editor_tab_map_iterator; + typedef std::map::const_iterator editor_tab_map_const_iterator; + + // struct that allows to sort with respect to the tab index + struct session_data + { + QString index; + QString file_name; + QString encoding; + bool operator<(const session_data &other) const + { + return index < other.index; + } + }; file_editor (QWidget *p); ~file_editor (void); @@ -198,7 +216,8 @@ const QString& toolTip); void handle_tab_close_request (int index); void handle_tab_remove_request (void); - void handle_add_filename_to_list (const QString& fileName, QWidget *ID); + void handle_add_filename_to_list (const QString& fileName, + 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); @@ -229,8 +248,9 @@ private slots: void request_open_files (const QStringList&); - void request_open_file (const QString& fileName, int line = -1, - bool debug_pointer = false, + void request_open_file (const QString& fileName, + const QString& encoding = QString (), + int line = -1, bool debug_pointer = false, bool breakpoint_marker = false, bool insert = true); void request_preferences (bool); void request_styles_preferences (bool); @@ -273,6 +293,8 @@ void switch_tab (int direction, bool movetab = false); + void restore_session (QSettings *settings); + bool editor_tab_has_focus (); QWidget *find_tab_widget (const QString& openFileName) const; @@ -281,7 +303,7 @@ QMenu* m_add_menu (QMenuBar *p, QString text); - std::map editor_tab_map; + std::map editor_tab_map; QHash _hash_menu_text; QString ced;