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
668753e6
Commit
668753e6
authored
Jan 04, 2022
by
Waqar Ahmed
Browse files
Move scroll bar restoration to raii class
parent
1bc65ced
Pipeline
#118285
passed with stage
in 5 minutes and 29 seconds
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
addons/externaltools/externaltoolsplugin.cpp
View file @
668753e6
...
...
@@ -55,6 +55,46 @@ 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
>
&
)
...
...
@@ -339,29 +379,12 @@ void KateExternalToolsPlugin::handleToolFinished(KateToolRunner *runner, int exi
const
bool
wereUpdatesEnabled
=
view
->
updatesEnabled
();
view
->
setUpdatesEnabled
(
false
);
// Find KateScrollBar
const
auto
scrollBars
=
view
->
findChildren
<
QScrollBar
*>
();
QScrollBar
*
kateScrollBar
=
[
scrollBars
]
{
for
(
auto
scrollBar
:
scrollBars
)
{
if
(
qstrcmp
(
scrollBar
->
metaObject
()
->
className
(),
"KateScrollBar"
)
==
0
)
{
return
scrollBar
;
}
}
return
static_cast
<
QScrollBar
*>
(
nullptr
);
}();
int
value
=
0
;
if
(
kateScrollBar
)
{
value
=
kateScrollBar
->
value
();
}
KateScrollBarRestorer
scrollRestorer
(
view
);
// Reload doc
view
->
document
()
->
documentReload
();
// Restore scroll pos
if
(
kateScrollBar
)
{
kateScrollBar
->
setValue
(
value
);
}
scrollRestorer
.
restore
();
view
->
setUpdatesEnabled
(
wereUpdatesEnabled
);
}
...
...
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