| 178 | } |
| 179 | |
| 180 | void SessionManager::loadSession(MainWindow *window) |
| 181 | { |
| 182 | qInfo(Q_FUNC_INFO); |
| 183 | |
| 184 | ApplicationSettings settings;; |
| 185 | |
| 186 | settings.beginGroup("CurrentSession"); |
| 187 | |
| 188 | ScintillaNext *currentEditor = Q_NULLPTR; |
| 189 | const int currentEditorIndex = settings.value("CurrentEditorIndex").toInt(); |
| 190 | const int size = settings.beginReadArray("OpenedFiles"); |
| 191 | |
| 192 | // NOTE: In theory the fileTypes should determine what is loaded, however if the session fileTypes |
| 193 | // change from the last time it was saved then it means the settings were manually altered outside of the app, |
| 194 | // which is non-standard behavior, so just load anything in the file |
| 195 | |
| 196 | for (int index = 0; index < size; ++index) { |
| 197 | settings.setArrayIndex(index); |
| 198 | |
| 199 | ScintillaNext *editor = Q_NULLPTR; |
| 200 | |
| 201 | if (settings.contains("Type")) { |
| 202 | const QString type = settings.value("Type").toString(); |
| 203 | |
| 204 | if (type == QStringLiteral("File")) { |
| 205 | editor = loadFileDetails(settings); |
| 206 | } |
| 207 | else if (type == QStringLiteral("UnsavedFile")) { |
| 208 | editor = loadUnsavedFileDetails(settings); |
| 209 | } |
| 210 | else if (type == QStringLiteral("Temp")) { |
| 211 | editor = loadTempFile(settings); |
| 212 | } |
| 213 | else { |
| 214 | qDebug("Unknown session entry type: %s", qUtf8Printable(type)); |
| 215 | } |
| 216 | |
| 217 | if (editor) { |
| 218 | if (currentEditorIndex == index) { |
| 219 | currentEditor = editor; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | else { |
| 224 | qDebug("Unknown session entry type for index %d", index); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | settings.endArray(); |
| 229 | |
| 230 | settings.endGroup(); |
| 231 | |
| 232 | if (currentEditor) { |
| 233 | window->switchToEditor(currentEditor); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | bool SessionManager::willFileGetStoredInSession(ScintillaNext *editor) const |
no test coverage detected