Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
04d5e019
Commit
04d5e019
authored
Feb 13, 2021
by
Méven Car
Committed by
Christoph Cullmann
Mar 05, 2021
Browse files
Add a setting for when to stash changes
parent
017ead02
Changes
5
Hide whitespace changes
Inline
Side-by-side
kate/kateconfigdialog.cpp
View file @
04d5e019
...
...
@@ -199,6 +199,12 @@ void KateConfigDialog::addSessionPage()
// Closing last file closes Kate
sessionConfigUi
.
modCloseAfterLast
->
setChecked
(
m_mainWindow
->
modCloseAfterLast
());
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
();
});
}
void
KateConfigDialog
::
addPluginsPage
()
...
...
@@ -343,6 +349,9 @@ 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
(
"Tabbar Tab Limit"
,
m_tabLimit
->
value
());
cg
.
writeEntry
(
"Show Tabs Close Button"
,
m_showTabCloseButton
->
isChecked
());
...
...
kate/katemainwindow.cpp
View file @
04d5e019
...
...
@@ -540,17 +540,19 @@ bool KateMainWindow::queryClose_internal(KTextEditor::Document *doc)
QList
<
KTextEditor
::
Document
*>
modifiedDocuments
=
KateApp
::
self
()
->
documentManager
()
->
modifiedDocumentList
();
modifiedDocuments
.
removeAll
(
doc
);
bool
shutdown
=
(
modifiedDocuments
.
count
()
==
0
)
||
KateApp
::
self
()
->
sessionManager
()
->
activeSession
();
/*
if (!KateApp::self()->sessionManager()->activeSession()) {
shutdown = KateApp::self()->stashManager()->stash(modifiedDocuments);
} else {
KConfigGroup cfg(KSharedConfig::openConfig(), "MainWindow");
KateApp::self()->documentManager()->saveDocumentList(cfg);
shutdown = true;
// filter out what the stashManager will itself stash
auto
m
=
modifiedDocuments
.
begin
();
while
(
m
!=
modifiedDocuments
.
end
())
{
if
(
KateApp
::
self
()
->
stashManager
()
->
willStashDoc
(
*
m
))
{
m
=
modifiedDocuments
.
erase
(
m
);
}
else
{
++
m
;
}
}
*/
bool
shutdown
=
modifiedDocuments
.
count
()
==
0
;
if
(
!
shutdown
)
{
shutdown
=
KateSaveModifiedDialog
::
queryClose
(
this
,
modifiedDocuments
);
}
...
...
@@ -649,6 +651,7 @@ 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
));
m_paShowPath
->
setChecked
(
generalGroup
.
readEntry
(
"Show Full Path in Title"
,
false
));
m_paShowStatusBar
->
setChecked
(
generalGroup
.
readEntry
(
"Show Status Bar"
,
true
));
...
...
kate/katestashmanager.cpp
View file @
04d5e019
...
...
@@ -68,13 +68,34 @@ void KateStashManager::popStash(KateViewManager *viewManager)
stashGroup
.
sync
();
}
bool
KateStashManager
::
s
tashDoc
ument
(
KTextEditor
::
Document
*
doc
,
const
QString
&
stashfileName
,
KConfigGroup
&
kconfig
,
const
QString
&
path
)
bool
KateStashManager
::
willS
tashDoc
(
KTextEditor
::
Document
*
doc
)
{
if
(
doc
->
text
().
isEmpty
()
||
!
kconfig
.
hasKey
(
"URL"
))
{
// No need to stash empty documents or /tmp files
if
(
m_stashUnsaveChanges
==
0
)
{
return
false
;
}
if
(
!
KateApp
::
self
()
->
sessionManager
()
->
activeSession
())
{
return
false
;
}
if
(
doc
->
text
().
isEmpty
())
{
return
false
;
}
if
(
doc
->
url
().
isEmpty
())
{
return
true
;
}
qCDebug
(
LOG_KATE
)
<<
"stashing document"
<<
stashfileName
<<
doc
->
url
();
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_stashUnsaveChanges
==
2
;
}
void
KateStashManager
::
stashDocument
(
KTextEditor
::
Document
*
doc
,
const
QString
&
stashfileName
,
KConfigGroup
&
kconfig
,
const
QString
&
path
)
{
if
(
!
willStashDoc
(
doc
))
{
return
;
}
// Stash changes
QString
stashedFile
=
path
+
QStringLiteral
(
"/"
)
+
stashfileName
;
...
...
@@ -84,7 +105,7 @@ bool KateStashManager::stashDocument(KTextEditor::Document *doc, const QString &
saveFile
.
write
(
doc
->
text
().
toUtf8
());
if
(
!
saveFile
.
commit
())
{
qCWarning
(
LOG_KATE
())
<<
"Could not write to stash file"
<<
stashedFile
;
return
false
;
return
;
}
// write stash metadata to config
...
...
@@ -95,8 +116,6 @@ bool KateStashManager::stashDocument(KTextEditor::Document *doc, const QString &
}
kconfig
.
sync
();
return
true
;
}
bool
KateStashManager
::
popDocument
(
KTextEditor
::
Document
*
doc
,
const
KConfigGroup
&
kconfig
)
...
...
kate/katestashmanager.h
View file @
04d5e019
...
...
@@ -21,11 +21,36 @@ class KateStashManager : QObject
Q_OBJECT
public:
KateStashManager
(
QObject
*
parent
=
nullptr
);
int
stashUnsaveChanges
()
{
return
m_stashUnsaveChanges
;
}
void
setStashUnsaveChanges
(
int
stashUnsaveChanges
)
{
m_stashUnsaveChanges
=
stashUnsaveChanges
;
}
bool
willStashDoc
(
KTextEditor
::
Document
*
doc
);
bool
stash
(
const
QList
<
KTextEditor
::
Document
*>
&
modifieddocuments
);
void
popStash
(
KateViewManager
*
viewManager
);
void
popStash
();
bool
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
);
private:
/**
* Stash unsave changes setting
*
* stash unsaved file by default
*
* 0 => Never
* 1 => for unsaved files
* 2 => for all files
*/
int
m_stashUnsaveChanges
=
1
;
};
#endif // KATESTASHMANAGER_H
kate/ui/sessionconfigwidget.ui
View file @
04d5e019
...
...
@@ -47,6 +47,36 @@
<string>
Application Shutdown Behavior
</string>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_5"
>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_3"
>
<item>
<widget
class=
"QLabel"
name=
"label_4"
>
<property
name=
"text"
>
<string>
Save and Restore unsaved changes
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QComboBox"
name=
"stashChangesCombo"
>
<item>
<property
name=
"text"
>
<string>
Never
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
For unsaved Files
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
For all files
</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"modCloseAfterLast"
>
<property
name=
"whatsThis"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment