Commit b6adb596 authored by Méven Car's avatar Méven Car Committed by Christoph Cullmann
Browse files

Allow to clear stash dir for session when removing a session.

parent 15085b8a
...@@ -26,6 +26,20 @@ KateStashManager::KateStashManager(QObject *parent) ...@@ -26,6 +26,20 @@ KateStashManager::KateStashManager(QObject *parent)
{ {
} }
void KateStashManager::clearStashForSession(const KateSession::Ptr session)
{
const QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(appDataPath);
if (dir.exists(QStringLiteral("stash"))) {
dir.cd(QStringLiteral("stash"));
const QString sessionName = session->name();
if (dir.exists(sessionName)) {
dir.cd(sessionName);
dir.removeRecursively();
}
}
}
void KateStashManager::stashDocuments(KConfig *config, const QList<KTextEditor::Document *> &documents) void KateStashManager::stashDocuments(KConfig *config, const QList<KTextEditor::Document *> &documents)
{ {
// prepare stash directory // prepare stash directory
...@@ -35,12 +49,15 @@ void KateStashManager::stashDocuments(KConfig *config, const QList<KTextEditor:: ...@@ -35,12 +49,15 @@ void KateStashManager::stashDocuments(KConfig *config, const QList<KTextEditor::
dir.cd(QStringLiteral("stash")); dir.cd(QStringLiteral("stash"));
const auto session = KateApp::self()->sessionManager()->activeSession(); const auto session = KateApp::self()->sessionManager()->activeSession();
if (session) { if (!session) {
const QString sessionName = session->name(); qDebug(LOG_KATE) << "Could not stash files without a session";
dir.mkdir(sessionName); return;
dir.cd(sessionName);
} }
const QString sessionName = session->name();
dir.mkdir(sessionName);
dir.cd(sessionName);
int i = 0; int i = 0;
for (KTextEditor::Document *doc : qAsConst(documents)) { for (KTextEditor::Document *doc : qAsConst(documents)) {
const QString entryName = QStringLiteral("Document %1").arg(i); const QString entryName = QStringLiteral("Document %1").arg(i);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#ifndef KATESTASHMANAGER_H #ifndef KATESTASHMANAGER_H
#define KATESTASHMANAGER_H #define KATESTASHMANAGER_H
#include "katesession.h"
#include "kconfiggroup.h" #include "kconfiggroup.h"
namespace KTextEditor namespace KTextEditor
...@@ -39,6 +40,8 @@ public: ...@@ -39,6 +40,8 @@ public:
void stashDocument(KTextEditor::Document *doc, const QString &stashfileName, KConfigGroup &kconfig, const QString &path); void stashDocument(KTextEditor::Document *doc, const QString &stashfileName, KConfigGroup &kconfig, const QString &path);
bool popDocument(KTextEditor::Document *doc, const KConfigGroup &kconfig); bool popDocument(KTextEditor::Document *doc, const KConfigGroup &kconfig);
void clearStashForSession(const KateSession::Ptr session);
private: private:
/** /**
* Stash unsave changes setting * Stash unsave changes setting
......
...@@ -98,6 +98,7 @@ void KateSessionManageDialog::done(int result) ...@@ -98,6 +98,7 @@ void KateSessionManageDialog::done(int result)
{ {
for (const auto &session : qAsConst(m_deleteList)) { for (const auto &session : qAsConst(m_deleteList)) {
KateApp::self()->sessionManager()->deleteSession(session); KateApp::self()->sessionManager()->deleteSession(session);
KateApp::self()->stashManager()->clearStashForSession(session);
} }
m_deleteList.clear(); // May not needed, but anyway m_deleteList.clear(); // May not needed, but anyway
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment