Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/NotepadNext/NotepadNextApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,17 @@ void NotepadNextApplication::saveSettings()
getSettings()->setValue("App/RecentFilesList", recentFilesListManager->fileList());
}

void NotepadNextApplication::saveSession()
{
for (const auto &editor : window->editors()) {
if (editor->isFile()) {
recentFilesListManager->addFile(editor->getFilePath());
}
}

getSessionManager()->saveSession(window);
}

MainWindow *NotepadNextApplication::createNewWindow()
{
Q_ASSERT(window == Q_NULLPTR);
Expand All @@ -452,15 +463,12 @@ MainWindow *NotepadNextApplication::createNewWindow()
});

// Since these editors don't actually get "closed" go ahead and add them to the recent file list
connect(window, &MainWindow::aboutToClose, this, [=]() {
for (const auto &editor : window->editors()) {
if (editor->isFile()) {
recentFilesListManager->addFile(editor->getFilePath());
}
}
connect(window, &MainWindow::aboutToClose, this, &NotepadNextApplication::saveSession);

getSessionManager()->saveSession(window);
});
// Timer to autosave session each minute
connect(&autoSaveTimer, &QTimer::timeout, this, &NotepadNextApplication::saveSession);
autoSaveTimer.setInterval(60 * 1000);
autoSaveTimer.start();

return window;
}
Expand Down
4 changes: 4 additions & 0 deletions src/NotepadNext/NotepadNextApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <QCommandLineParser>
#include <QPointer>
#include <QTimer>


class MainWindow;
Expand Down Expand Up @@ -75,6 +76,7 @@ class NotepadNextApplication : public SingleApplication
private slots:
void saveSettings();
void receiveInfoFromSecondaryInstance(quint32 instanceId, QByteArray message);
void saveSession();

private:
void openFiles(const QStringList &files);
Expand All @@ -95,6 +97,8 @@ private slots:
MainWindow *createNewWindow();

QCommandLineParser parser;

QTimer autoSaveTimer; //save automatically the session
};

#endif // NOTEPADNEXTAPPLICATION_H
4 changes: 2 additions & 2 deletions src/NotepadNext/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ ScintillaNext *SessionManager::loadUnsavedFileDetails(QSettings &settings)
editor->setFileInfo(filePath);
editor->setTemporary(true);

loadEditorViewDetails(editor, settings);

app->getEditorManager()->manageEditor(editor);

loadEditorViewDetails(editor, settings);

return editor;
}
else {
Expand Down
Loading