Skip to content
GitLab
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
d1004534
Commit
d1004534
authored
Aug 13, 2022
by
Pablo Rauzy
Committed by
Christoph Cullmann
Aug 14, 2022
Browse files
using QSaveFile rather than QLockFile
parent
b68990a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/keyboardmacros/keyboardmacrosplugin.cpp
View file @
d1004534
...
...
@@ -21,12 +21,12 @@
#include
<QKeySequence>
#include
<QLineEdit>
#include
<QList>
#include
<QLockFile>
#include
<QLoggingCategory>
#include
<QMessageBox>
#include
<QObject>
#include
<QPointer>
#include
<QRegularExpression>
#include
<QSaveFile>
#include
<QStandardPaths>
#include
<QString>
#include
<QStringList>
...
...
@@ -60,13 +60,11 @@ KeyboardMacrosPlugin::KeyboardMacrosPlugin(QObject *parent, const QList<QVariant
{
m_commands
=
new
KeyboardMacrosPluginCommands
(
this
);
m_storage
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericDataLocation
)
+
QStringLiteral
(
"/kate/keyboardmacros.json"
);
m_storageLock
=
new
QLockFile
(
m_storage
+
QStringLiteral
(
".lock"
));
}
KeyboardMacrosPlugin
::~
KeyboardMacrosPlugin
()
{
saveNamedMacros
();
delete
m_storageLock
;
delete
m_commands
;
}
...
...
@@ -93,12 +91,8 @@ void KeyboardMacrosPlugin::clearPluginViews()
}
}
void
KeyboardMacrosPlugin
::
loadNamedMacros
(
bool
locked
)
void
KeyboardMacrosPlugin
::
loadNamedMacros
()
{
if
(
!
locked
&&
!
m_storageLock
->
tryLock
())
{
sendMessage
(
i18n
(
"Could not acquire macros storage lock; abort loading macros."
),
true
);
return
;
}
QFile
storage
(
m_storage
);
if
(
!
storage
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
sendMessage
(
i18n
(
"Could not open file '%1'."
,
m_storage
),
false
);
...
...
@@ -123,26 +117,19 @@ void KeyboardMacrosPlugin::loadNamedMacros(bool locked)
}
}
storage
.
close
();
if
(
!
locked
)
{
m_storageLock
->
unlock
();
}
}
void
KeyboardMacrosPlugin
::
saveNamedMacros
()
{
if
(
!
m_storageLock
->
tryLock
())
{
sendMessage
(
i18n
(
"Could not acquire macros storage lock; abort saving macros."
),
true
);
return
;
}
// first keep a copy of the named macros of our instance
QMap
<
QString
,
Macro
>
ourNamedMacros
;
ourNamedMacros
.
swap
(
m_namedMacros
);
// then reload from storage in case another instance saved macros since we first loaded ours from storage
loadNamedMacros
(
true
);
loadNamedMacros
();
// then insert all of our macros, prioritizing ours in case of name conflict since we are the most recent save
m_namedMacros
.
insert
(
ourNamedMacros
);
// and now save named macros
QFile
storage
(
m_storage
);
Q
Save
File
storage
(
m_storage
);
if
(
!
storage
.
open
(
QIODevice
::
WriteOnly
|
QIODevice
::
Text
))
{
sendMessage
(
i18n
(
"Could not open file '%1'."
,
m_storage
),
false
);
return
;
...
...
@@ -152,8 +139,7 @@ void KeyboardMacrosPlugin::saveNamedMacros()
json
.
insert
(
name
,
macro
.
toJson
());
}
storage
.
write
(
QJsonDocument
(
json
).
toJson
(
QJsonDocument
::
Compact
));
storage
.
close
();
m_storageLock
->
unlock
();
storage
.
commit
();
}
// END
...
...
addons/keyboardmacros/keyboardmacrosplugin.h
View file @
d1004534
...
...
@@ -9,7 +9,6 @@
#include
<QEvent>
#include
<QKeySequence>
#include
<QList>
#include
<QLockFile>
#include
<QMap>
#include
<QObject>
#include
<QPointer>
...
...
@@ -50,7 +49,6 @@ class KeyboardMacrosPlugin : public KTextEditor::Plugin
Macro
m_tape
;
Macro
m_macro
;
QString
m_storage
;
QLockFile
*
m_storageLock
;
QMap
<
QString
,
Macro
>
m_namedMacros
;
QSet
<
QString
>
m_wipedMacros
;
...
...
@@ -62,7 +60,7 @@ public:
void
clearPluginViews
();
private:
void
loadNamedMacros
(
bool
locked
=
false
);
void
loadNamedMacros
();
void
saveNamedMacros
();
// GUI feedback helpers
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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