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
4ae5e3e4
Commit
4ae5e3e4
authored
Dec 31, 2020
by
Dominik Haumann
Browse files
External Tools: Track mimetype changes to enable/disable actions
BUG: 430625
parent
39c0db6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/externaltools/kateexternaltoolsview.cpp
View file @
4ae5e3e4
...
...
@@ -108,8 +108,22 @@ void KateExternalToolsMenuAction::slotViewChanged(KTextEditor::View *view)
return
;
}
disconnect
(
m_docUrlChangedConnection
);
m_docUrlChangedConnection
=
connect
(
view
->
document
(),
&
KTextEditor
::
Document
::
documentUrlChanged
,
this
,
[
this
](
KTextEditor
::
Document
*
doc
)
{
updateActionState
(
doc
);
});
updateActionState
(
view
->
document
());
}
void
KateExternalToolsMenuAction
::
updateActionState
(
KTextEditor
::
Document
*
activeDoc
)
{
if
(
!
activeDoc
)
{
return
;
}
// try to enable/disable to match current mime type
const
QString
mimeType
=
view
->
document
()
->
mimeType
();
const
QString
mimeType
=
activeDoc
->
mimeType
();
const
auto
actions
=
m_actionCollection
->
actions
();
for
(
QAction
*
action
:
actions
)
{
if
(
action
&&
action
->
data
().
value
<
KateExternalTool
*>
())
{
...
...
addons/externaltools/kateexternaltoolsview.h
View file @
4ae5e3e4
...
...
@@ -13,6 +13,7 @@ class MainWindow;
}
namespace
KTextEditor
{
class
Document
;
class
View
;
}
...
...
@@ -57,10 +58,15 @@ public:
private
Q_SLOTS
:
/**
* Called whenever the current view changed.
*
Required to enable/disable the tools that depend on specific mimetypes
.
*
Calls updateActionState() for the corresponding document
.
*/
void
slotViewChanged
(
KTextEditor
::
View
*
view
);
/**
* Required to enable/disable the tools that depend on specific mimetypes.
*/
void
updateActionState
(
KTextEditor
::
Document
*
activeDoc
);
/**
* Triggered via Tools > External Tools > Configure...
*/
...
...
@@ -70,6 +76,7 @@ private:
KateExternalToolsPlugin
*
m_plugin
;
KTextEditor
::
MainWindow
*
m_mainwindow
;
// for the actions to access view/doc managers
KActionCollection
*
m_actionCollection
;
QMetaObject
::
Connection
m_docUrlChangedConnection
;
};
class
KateExternalToolsPluginView
:
public
QObject
,
public
KXMLGUIClient
...
...
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