Commit 4ae5e3e4 authored by Dominik Haumann's avatar Dominik Haumann
Browse files

External Tools: Track mimetype changes to enable/disable actions

BUG: 430625
parent 39c0db6a
......@@ -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 *>()) {
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment