Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 20 additions & 9 deletions src/NotepadNext/NotepadNextApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,19 @@ void NotepadNextApplication::saveSettings()
getSettings()->setValue("App/RecentFilesList", recentFilesListManager->fileList());
}

void NotepadNextApplication::saveSession()
{
// Iterate all the opened editors and add them to the recent file list
for (const auto &editor : window->editors()) {
if (editor->isFile()) {
recentFilesListManager->addFile(editor->getFilePath());
}
}
saveSettings();

getSessionManager()->saveSession(window);
}

MainWindow *NotepadNextApplication::createNewWindow()
{
Q_ASSERT(window == Q_NULLPTR);
Expand All @@ -451,16 +464,14 @@ MainWindow *NotepadNextApplication::createNewWindow()
LuaExtension::Instance().setEditor(editor);
});

// 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());
}
}
// TODO: this shouldn't be dependent on a MainWindow closing, but this works for now
// since the assumption is MainWindow::aboutToClose() infers the application is shutting
// down but the editors are still active.
connect(window, &MainWindow::aboutToClose, this, &NotepadNextApplication::saveSession);

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

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