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

Use checkbox for stash settings

parent e485b0a0
......@@ -201,10 +201,10 @@ void KateConfigDialog::addSessionPage()
connect(sessionConfigUi.modCloseAfterLast, &QCheckBox::toggled, this, &KateConfigDialog::slotChanged);
// stash unsave changes
sessionConfigUi.stashChangesCombo->setCurrentIndex(KateApp::self()->stashManager()->stashUnsaveChanges());
connect(sessionConfigUi.stashChangesCombo, QOverload<const int>::of(&QComboBox::currentIndexChanged), this, [this](int /*index*/) {
this->slotChanged();
});
sessionConfigUi.stashNewUnsavedFiles->setChecked(KateApp::self()->stashManager()->stashNewUnsavedFiles());
sessionConfigUi.stashUnsavedFilesChanges->setChecked(KateApp::self()->stashManager()->stashUnsavedChanges());
connect(sessionConfigUi.stashNewUnsavedFiles, &QRadioButton::toggled, this, &KateConfigDialog::slotChanged);
connect(sessionConfigUi.stashUnsavedFilesChanges, &QRadioButton::toggled, this, &KateConfigDialog::slotChanged);
}
void KateConfigDialog::addPluginsPage()
......@@ -349,8 +349,10 @@ void KateConfigDialog::slotApply()
cg.readEntry("Show output view for message type", m_messageTypes->currentIndex());
cg.writeEntry("Stash unsaved changes", sessionConfigUi.stashChangesCombo->currentIndex());
KateApp::self()->stashManager()->setStashUnsaveChanges(sessionConfigUi.stashChangesCombo->currentIndex());
cg.writeEntry("Stash unsaved file changes", sessionConfigUi.stashUnsavedFilesChanges->isChecked());
KateApp::self()->stashManager()->setStashUnsavedChanges(sessionConfigUi.stashUnsavedFilesChanges->isChecked());
cg.writeEntry("Stash new unsaved files", sessionConfigUi.stashNewUnsavedFiles->isChecked());
KateApp::self()->stashManager()->setStashNewUnsavedFiles(sessionConfigUi.stashNewUnsavedFiles->isChecked());
cg.writeEntry("Tabbar Tab Limit", m_tabLimit->value());
......
......@@ -653,7 +653,9 @@ void KateMainWindow::readOptions()
m_modCloseAfterLast = generalGroup.readEntry("Close After Last", false);
KateApp::self()->documentManager()->setSaveMetaInfos(generalGroup.readEntry("Save Meta Infos", true));
KateApp::self()->documentManager()->setDaysMetaInfos(generalGroup.readEntry("Days Meta Infos", 30));
KateApp::self()->stashManager()->setStashUnsaveChanges(generalGroup.readEntry("Stash unsaved changes", 1));
KateApp::self()->stashManager()->setStashUnsavedChanges(generalGroup.readEntry("Stash unsaved file changes", false));
KateApp::self()->stashManager()->setStashNewUnsavedFiles(generalGroup.readEntry("Stash new unsaved files", true));
m_paShowPath->setChecked(generalGroup.readEntry("Show Full Path in Title", false));
m_paShowStatusBar->setChecked(generalGroup.readEntry("Show Status Bar", true));
......
......@@ -74,9 +74,6 @@ void KateStashManager::stashDocuments(KConfig *config, const QList<KTextEditor::
bool KateStashManager::willStashDoc(KTextEditor::Document *doc)
{
if (m_stashUnsaveChanges == 0) {
return false;
}
if (!KateApp::self()->sessionManager()->activeSession()) {
return false;
}
......@@ -84,15 +81,16 @@ bool KateStashManager::willStashDoc(KTextEditor::Document *doc)
return false;
}
if (doc->url().isEmpty()) {
return true;
return m_stashNewUnsavedFiles;
}
if (doc->url().isLocalFile()) {
const QString path = doc->url().toLocalFile();
if (path.startsWith(QDir::tempPath())) {
return false; // inside tmp resource, do not stash
}
return m_stashUnsavedChanges;
}
return m_stashUnsaveChanges == 2;
return false;
}
void KateStashManager::stashDocument(KTextEditor::Document *doc, const QString &stashfileName, KConfigGroup &kconfig, const QString &path)
......@@ -142,7 +140,7 @@ bool KateStashManager::popDocument(KTextEditor::Document *doc, const KConfigGrou
file.open(QIODevice::ReadOnly);
QTextStream out(&file);
const auto codec = QTextCodec::codecForName(kconfig.readEntry("Encoding").toLocal8Bit());
if (codec != 0) {
if (codec != nullptr) {
out.setCodec(codec);
}
......
......@@ -23,14 +23,24 @@ class KateStashManager : QObject
public:
KateStashManager(QObject *parent = nullptr);
int stashUnsaveChanges()
bool stashUnsavedChanges()
{
return m_stashUnsaveChanges;
return m_stashUnsavedChanges;
}
void setStashUnsaveChanges(int stashUnsaveChanges)
void setStashUnsavedChanges(bool stashUnsavedChanges)
{
m_stashUnsaveChanges = stashUnsaveChanges;
m_stashUnsavedChanges = stashUnsavedChanges;
}
bool stashNewUnsavedFiles()
{
return m_stashNewUnsavedFiles;
}
void setStashNewUnsavedFiles(bool stashNewUnsavedFiles)
{
m_stashNewUnsavedFiles = stashNewUnsavedFiles;
}
void stashDocuments(KConfig *cfg, const QList<KTextEditor::Document *> &documents);
......@@ -43,16 +53,8 @@ public:
void clearStashForSession(const KateSession::Ptr session);
private:
/**
* Stash unsave changes setting
*
* stash unsaved file by default
*
* 0 => Never
* 1 => for unsaved files
* 2 => for all files
*/
int m_stashUnsaveChanges = 1;
bool m_stashUnsavedChanges = false;
bool m_stashNewUnsavedFiles = true;
};
#endif // KATESTASHMANAGER_H
......@@ -52,28 +52,33 @@
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Save and Restore unsaved changes</string>
<string>Automatically save and restore:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="stashChangesCombo">
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<property name="text">
<string>For unsaved Files</string>
</property>
<widget class="QCheckBox" name="stashNewUnsavedFiles">
<property name="text">
<string>Newly-created unsaved files</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<property name="text">
<string>For all files</string>
</property>
<widget class="QCheckBox" name="stashUnsavedFilesChanges">
<property name="text">
<string>Files with unsaved changes</string>
</property>
</widget>
</item>
</widget>
</layout>
</item>
</layout>
</item>
......
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