Commit cd4e7ddd authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

make project restoration configurable

this allows to avoid the restoration if that
doesn't fit your working pattern

at work I open XX projects a day and for
sure don't want this :)
parent 804273df
Pipeline #166011 passed with stage
in 15 minutes and 40 seconds
......@@ -42,6 +42,15 @@ KateProjectConfigPage::KateProjectConfigPage(QWidget *parent, KateProjectPlugin
layout->addWidget(group);
vbox = new QVBoxLayout();
group = new QGroupBox(i18nc("Groupbox title", "Session Behavior"), this);
group->setWhatsThis(i18n("Session settings for projects"));
m_cbSessionRestoreOpenProjects = new QCheckBox(i18n("Restore Open Projects"), this);
vbox->addWidget(m_cbSessionRestoreOpenProjects);
vbox->addStretch(1);
group->setLayout(vbox);
layout->addWidget(group);
vbox = new QVBoxLayout();
group = new QGroupBox(i18nc("Groupbox title", "Project Index"), this);
group->setWhatsThis(i18n("Project ctags index settings"));
......@@ -107,6 +116,7 @@ KateProjectConfigPage::KateProjectConfigPage(QWidget *parent, KateProjectPlugin
connect(m_cbAutoSubversion, &QCheckBox::stateChanged, this, &KateProjectConfigPage::slotMyChanged);
connect(m_cbAutoMercurial, &QCheckBox::stateChanged, this, &KateProjectConfigPage::slotMyChanged);
connect(m_cbAutoFossil, &QCheckBox::stateChanged, this, &KateProjectConfigPage::slotMyChanged);
connect(m_cbSessionRestoreOpenProjects, &QCheckBox::stateChanged, this, &KateProjectConfigPage::slotMyChanged);
connect(m_cbIndexEnabled, &QCheckBox::stateChanged, this, &KateProjectConfigPage::slotMyChanged);
connect(m_indexPath, &KUrlRequester::textChanged, this, &KateProjectConfigPage::slotMyChanged);
connect(m_indexPath, &KUrlRequester::urlSelected, this, &KateProjectConfigPage::slotMyChanged);
......@@ -153,6 +163,8 @@ void KateProjectConfigPage::apply()
m_plugin->setGitStatusShowNumStat(m_cbGitStatusDiffNumStat->isChecked());
m_plugin->setSingleClickAction((ClickAction)m_cmbSingleClick->currentIndex());
m_plugin->setDoubleClickAction((ClickAction)m_cmbDoubleClick->currentIndex());
m_plugin->setRestoreProjectsForSession(m_cbSessionRestoreOpenProjects->isChecked());
}
void KateProjectConfigPage::reset()
......@@ -170,6 +182,8 @@ void KateProjectConfigPage::reset()
m_cmbSingleClick->setCurrentIndex((int)m_plugin->singleClickAcion());
m_cmbDoubleClick->setCurrentIndex((int)m_plugin->doubleClickAcion());
m_cbSessionRestoreOpenProjects->setCheckState(m_plugin->restoreProjectsForSession() ? Qt::Checked : Qt::Unchecked);
m_changed = false;
}
......
......@@ -38,6 +38,7 @@ private Q_SLOTS:
private:
void setupGitConfigUI();
QCheckBox *m_cbSessionRestoreOpenProjects;
QCheckBox *m_cbAutoGit;
QCheckBox *m_cbAutoSubversion;
QCheckBox *m_cbAutoMercurial;
......
......@@ -504,6 +504,17 @@ void KateProjectPlugin::setMultiProject(bool completion, bool gotoSymbol)
writeConfig();
}
void KateProjectPlugin::setRestoreProjectsForSession(bool enabled)
{
m_restoreProjectsForSession = enabled;
writeConfig();
}
bool KateProjectPlugin::restoreProjectsForSession() const
{
return m_restoreProjectsForSession;
}
void KateProjectPlugin::readConfig()
{
KConfigGroup config(KSharedConfig::openConfig(), "project");
......@@ -524,6 +535,8 @@ void KateProjectPlugin::readConfig()
m_singleClickAction = (ClickAction)config.readEntry("gitStatusSingleClick", (int)ClickAction::ShowDiff);
m_doubleClickAction = (ClickAction)config.readEntry("gitStatusDoubleClick", (int)ClickAction::StageUnstage);
m_restoreProjectsForSession = config.readEntry("restoreProjectsForSession", true);
Q_EMIT configUpdated();
}
......@@ -560,6 +573,8 @@ void KateProjectPlugin::writeConfig()
config.writeEntry("gitStatusSingleClick", (int)m_singleClickAction);
config.writeEntry("gitStatusDoubleClick", (int)m_doubleClickAction);
config.writeEntry("restoreProjectsForSession", m_restoreProjectsForSession);
Q_EMIT configUpdated();
}
......@@ -615,47 +630,51 @@ void KateProjectPlugin::unregisterVariables()
void KateProjectPlugin::readSessionConfig(const KConfigGroup &config)
{
// de-serialize all open projects as list of json documents
const auto projectList = config.readEntry("projects", QStringList());
for (const auto &project : projectList) {
const QVariantMap sMap = QJsonDocument::fromJson(project.toUtf8()).toVariant().toMap();
// valid file backed project?
if (const auto file = sMap[QStringLiteral("file")].toString(); !file.isEmpty()) {
createProjectForFileName(file);
continue;
}
// valid path + data project?
if (const auto path = sMap[QStringLiteral("path")].toString(); !path.isEmpty()) {
createProjectForDirectory(QDir(path), sMap[QStringLiteral("data")].toMap());
continue;
// de-serialize all open projects as list of JSON documents if allowed
if (restoreProjectsForSession()) {
const auto projectList = config.readEntry("projects", QStringList());
for (const auto &project : projectList) {
const QVariantMap sMap = QJsonDocument::fromJson(project.toUtf8()).toVariant().toMap();
// valid file backed project?
if (const auto file = sMap[QStringLiteral("file")].toString(); !file.isEmpty()) {
createProjectForFileName(file);
continue;
}
// valid path + data project?
if (const auto path = sMap[QStringLiteral("path")].toString(); !path.isEmpty()) {
createProjectForDirectory(QDir(path), sMap[QStringLiteral("data")].toMap());
continue;
}
// we might arrive here if invalid data is store, just ignore that, we just loose session data
}
// we might arrive here if invalid data is store, just ignore that, we just loose session data
}
}
void KateProjectPlugin::writeSessionConfig(KConfigGroup &config)
{
// serialize all open projects as list of json documents
// serialize all open projects as list of JSON documents if allowed, always write the list to not leave over old data forever
QStringList projectList;
for (const auto project : projects()) {
QVariantMap sMap;
// for file backed stuff, we just remember the file
if (project->isFileBacked()) {
sMap[QStringLiteral("file")] = project->fileName();
}
// otherwise we remember the data we generated purely in memory
else {
sMap[QStringLiteral("data")] = project->projectMap();
sMap[QStringLiteral("path")] = project->baseDir();
if (restoreProjectsForSession()) {
for (const auto project : projects()) {
QVariantMap sMap;
// for file backed stuff, we just remember the file
if (project->isFileBacked()) {
sMap[QStringLiteral("file")] = project->fileName();
}
// otherwise we remember the data we generated purely in memory
else {
sMap[QStringLiteral("data")] = project->projectMap();
sMap[QStringLiteral("path")] = project->baseDir();
}
// encode as one-lines JSON string
projectList.push_back(QString::fromUtf8(QJsonDocument::fromVariant(QVariant(sMap)).toJson(QJsonDocument::Compact)));
}
// encode as one-lines json string
projectList.push_back(QString::fromUtf8(QJsonDocument::fromVariant(QVariant(sMap)).toJson(QJsonDocument::Compact)));
}
config.writeEntry("projects", projectList);
}
......@@ -129,6 +129,9 @@ public:
void setDoubleClickAction(ClickAction cb);
ClickAction doubleClickAcion();
void setRestoreProjectsForSession(bool enabled);
bool restoreProjectsForSession() const;
/**
* filesystem watcher to keep track of all project files
* and auto-reload
......@@ -243,6 +246,9 @@ private:
bool m_autoMercurial = true;
bool m_autoFossil = true;
// restore projects on session loading?
bool m_restoreProjectsForSession = true;
// indexing is expensive, default off
bool m_indexEnabled = false;
QUrl m_indexDirectory;
......
Supports Markdown
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