@@ -157,31 +157,40 @@ bool SessionManager::saveSessionTo(MainWindow *window, const QString &path)
157157 return false ;
158158 }
159159
160- QSettings * settings = new QSettings (sessionDirectory ().absolutePath () + QDir::separator () + SETTINGS_FILE, QSettings::IniFormat);
160+ QSettings settings (sessionDirectory ().absolutePath () + QDir::separator () + SETTINGS_FILE, QSettings::IniFormat);
161161
162- settings-> beginGroup (" Session" );
162+ settings. beginGroup (" Session" );
163163
164164 setSessionFileTypes (tmp | SavedFile);
165165 saveSession (window, settings);
166166 setSessionFileTypes (tmp);
167167
168- settings-> endGroup ();
169- settings-> sync ();
168+ settings. endGroup ();
169+ settings. sync ();
170170
171- delete settings;
172171 return true ;
173172}
174173
174+ void SessionManager::saveCurrentSession (MainWindow *window)
175+ {
176+ if (useCustomSessionFolder) {
177+ saveSessionTo (window, customSessionPath);
178+ }
179+ else {
180+ saveDefaultSession (window);
181+ }
182+ }
183+
175184void SessionManager::saveDefaultSession (MainWindow *window)
176185{
177186 useCustomSessionFolder = false ;
178187 ApplicationSettings appSettings;
179188 appSettings.beginGroup (" CurrentSession" );
180- saveSession (window, & appSettings);
189+ saveSession (window, appSettings);
181190 appSettings.endGroup ();
182191}
183192
184- void SessionManager::saveSession (MainWindow *window, QSettings* settings)
193+ void SessionManager::saveSession (MainWindow *window, QSettings & settings)
185194{
186195 qInfo (Q_FUNC_INFO);
187196
@@ -196,23 +205,23 @@ void SessionManager::saveSession(MainWindow *window, QSettings* settings)
196205 int currentEditorIndex = 0 ;
197206 ApplicationSettings appSettings;
198207
199- settings-> beginWriteArray (" OpenedFiles" );
208+ settings. beginWriteArray (" OpenedFiles" );
200209
201210 int index = 0 ;
202211 for (const auto &editor : window->editors ()) {
203212 SessionFileType editorType = determineType (editor);
204213
205214 if (fileTypes.testFlag (editorType)) {
206- settings-> setArrayIndex (index);
215+ settings. setArrayIndex (index);
207216
208217 if (editorType == SessionManager::SavedFile) {
209- storeFileDetails (editor, * settings);
218+ storeFileDetails (editor, settings);
210219 }
211220 else if (editorType == SessionManager::UnsavedFile) {
212- storeUnsavedFileDetails (editor, * settings);
221+ storeUnsavedFileDetails (editor, settings);
213222 }
214223 else if (editorType == SessionManager::TempFile) {
215- storeTempFile (editor, * settings);
224+ storeTempFile (editor, settings);
216225 }
217226 else {
218227 qWarning (" Unknown SessionFileType %d" , editorType);
@@ -226,17 +235,17 @@ void SessionManager::saveSession(MainWindow *window, QSettings* settings)
226235 }
227236 }
228237
229- settings-> endArray ();
238+ settings. endArray ();
230239
231- settings-> setValue (" CurrentEditorIndex" , currentEditorIndex);
240+ settings. setValue (" CurrentEditorIndex" , currentEditorIndex);
232241}
233242
234243void SessionManager::loadDefaultSession (MainWindow *window)
235244{
236245 ApplicationSettings settings;
237246
238247 settings.beginGroup (" CurrentSession" );
239- ScintillaNext *currentEditor = loadSession (window, & settings);
248+ ScintillaNext *currentEditor = loadSession (window, settings);
240249 settings.endGroup ();
241250
242251 if (currentEditor) {
@@ -258,47 +267,46 @@ bool SessionManager::loadSessionFrom(MainWindow *window, const QString &path)
258267 {
259268 return false ;
260269 }
261- QSettings * settings = new QSettings (sessionDirectory ().absolutePath () + QDir::separator () + SETTINGS_FILE, QSettings::IniFormat);
270+ QSettings settings (sessionDirectory ().absolutePath () + QDir::separator () + SETTINGS_FILE, QSettings::IniFormat);
262271
263- settings-> beginGroup (" Session" );
272+ settings. beginGroup (" Session" );
264273 ScintillaNext *currentEditor = loadSession (window, settings);
265- settings->endGroup ();
266- delete settings;
274+ settings.endGroup ();
267275
268276 if (currentEditor) {
269277 window->switchToEditor (currentEditor);
270278 }
271279 return true ;
272280}
273281
274- ScintillaNext *SessionManager::loadSession (MainWindow *window, QSettings * settings)
282+ ScintillaNext *SessionManager::loadSession (MainWindow *window, QSettings & settings)
275283{
276284 qInfo (Q_FUNC_INFO);
277285
278286 ScintillaNext *currentEditor = Q_NULLPTR;
279- const int currentEditorIndex = settings-> value (" CurrentEditorIndex" ).toInt ();
280- const int size = settings-> beginReadArray (" OpenedFiles" );
287+ const int currentEditorIndex = settings. value (" CurrentEditorIndex" ).toInt ();
288+ const int size = settings. beginReadArray (" OpenedFiles" );
281289
282290 // NOTE: In theory the fileTypes should determine what is loaded, however if the session fileTypes
283291 // change from the last time it was saved then it means the settings were manually altered outside of the app,
284292 // which is non-standard behavior, so just load anything in the file
285293
286294 for (int index = 0 ; index < size; ++index) {
287- settings-> setArrayIndex (index);
295+ settings. setArrayIndex (index);
288296
289297 ScintillaNext *editor = Q_NULLPTR;
290298
291- if (settings-> contains (" Type" )) {
292- const QString type = settings-> value (" Type" ).toString ();
299+ if (settings. contains (" Type" )) {
300+ const QString type = settings. value (" Type" ).toString ();
293301
294302 if (type == QStringLiteral (" File" )) {
295- editor = loadFileDetails (* settings);
303+ editor = loadFileDetails (settings);
296304 }
297305 else if (type == QStringLiteral (" UnsavedFile" )) {
298- editor = loadUnsavedFileDetails (* settings);
306+ editor = loadUnsavedFileDetails (settings);
299307 }
300308 else if (type == QStringLiteral (" Temp" )) {
301- editor = loadTempFile (* settings);
309+ editor = loadTempFile (settings);
302310 }
303311 else {
304312 qDebug (" Unknown session entry type: %s" , qUtf8Printable (type));
@@ -315,8 +323,8 @@ ScintillaNext *SessionManager::loadSession(MainWindow *window, QSettings *settin
315323 }
316324 }
317325
318- settings-> endArray ();
319- return currentEditor;
326+ settings. endArray ();
327+ return currentEditor;
320328}
321329
322330bool SessionManager::willFileGetStoredInSession (ScintillaNext *editor) const
0 commit comments