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
6a675e58
Commit
6a675e58
authored
Jan 12, 2022
by
Waqar Ahmed
Committed by
Christoph Cullmann
Jan 15, 2022
Browse files
Move ScrollBarRestorer to ktexteditor_utils
parent
9244557e
Pipeline
#123903
passed with stage
in 4 minutes and 16 seconds
Changes
3
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
addons/externaltools/CMakeLists.txt
View file @
6a675e58
...
...
@@ -36,6 +36,12 @@ target_sources(
plugin.qrc
)
target_include_directories
(
externaltoolsplugin
PUBLIC
${
CMAKE_SOURCE_DIR
}
/shared
)
if
(
BUILD_TESTING
)
add_subdirectory
(
autotests
)
endif
()
addons/externaltools/externaltoolsplugin.cpp
View file @
6a675e58
...
...
@@ -31,6 +31,8 @@
#include
<QGuiApplication>
#include
<QScrollBar>
#include
<ktexteditor_utils.h>
static
QString
toolsConfigDir
()
{
static
const
QString
dir
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericConfigLocation
)
+
QLatin1String
(
"/kate/externaltools/"
);
...
...
@@ -55,46 +57,6 @@ static QVector<KateExternalTool> readDefaultTools()
return
tools
;
}
struct
KateScrollBarRestorer
{
KateScrollBarRestorer
(
KTextEditor
::
View
*
view
)
{
// Find KateScrollBar
const
auto
scrollBars
=
view
->
findChildren
<
QScrollBar
*>
();
kateScrollBar
=
[
scrollBars
]
{
for
(
auto
scrollBar
:
scrollBars
)
{
if
(
qstrcmp
(
scrollBar
->
metaObject
()
->
className
(),
"KateScrollBar"
)
==
0
)
{
return
scrollBar
;
}
}
return
static_cast
<
QScrollBar
*>
(
nullptr
);
}();
if
(
kateScrollBar
)
{
oldScrollValue
=
kateScrollBar
->
value
();
}
}
void
restore
()
{
if
(
kateScrollBar
)
{
kateScrollBar
->
setValue
(
oldScrollValue
);
}
restored
=
true
;
}
~
KateScrollBarRestorer
()
{
if
(
!
restored
)
{
restore
();
}
}
private:
QPointer
<
QScrollBar
>
kateScrollBar
=
nullptr
;
int
oldScrollValue
=
0
;
bool
restored
=
false
;
};
K_PLUGIN_FACTORY_WITH_JSON
(
KateExternalToolsFactory
,
"externaltoolsplugin.json"
,
registerPlugin
<
KateExternalToolsPlugin
>
();)
KateExternalToolsPlugin
::
KateExternalToolsPlugin
(
QObject
*
parent
,
const
QList
<
QVariant
>
&
)
...
...
@@ -379,7 +341,7 @@ void KateExternalToolsPlugin::handleToolFinished(KateToolRunner *runner, int exi
const
bool
wereUpdatesEnabled
=
view
->
updatesEnabled
();
view
->
setUpdatesEnabled
(
false
);
KateScrollBarRestorer
scrollRestorer
(
view
);
Utils
::
KateScrollBarRestorer
scrollRestorer
(
view
);
// Reload doc
view
->
document
()
->
documentReload
();
...
...
shared/ktexteditor_utils.h
View file @
6a675e58
...
...
@@ -9,10 +9,53 @@
#include
<KTextEditor/View>
#include
<QFontDatabase>
#include
<QPointer>
#include
<QScrollBar>
namespace
Utils
{
// A helper class that maintains scroll position
struct
KateScrollBarRestorer
{
KateScrollBarRestorer
(
KTextEditor
::
View
*
view
)
{
// Find KateScrollBar
const
auto
scrollBars
=
view
->
findChildren
<
QScrollBar
*>
();
kateScrollBar
=
[
scrollBars
]
{
for
(
auto
scrollBar
:
scrollBars
)
{
if
(
qstrcmp
(
scrollBar
->
metaObject
()
->
className
(),
"KateScrollBar"
)
==
0
)
{
return
scrollBar
;
}
}
return
static_cast
<
QScrollBar
*>
(
nullptr
);
}();
if
(
kateScrollBar
)
{
oldScrollValue
=
kateScrollBar
->
value
();
}
}
void
restore
()
{
if
(
kateScrollBar
)
{
kateScrollBar
->
setValue
(
oldScrollValue
);
}
restored
=
true
;
}
~
KateScrollBarRestorer
()
{
if
(
!
restored
)
{
restore
();
}
}
private:
QPointer
<
QScrollBar
>
kateScrollBar
=
nullptr
;
int
oldScrollValue
=
0
;
bool
restored
=
false
;
};
/**
* returns the current active global font
*/
...
...
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