Commit 113f5c04 authored by Dominik Haumann's avatar Dominik Haumann

Cleanup unneeded code

parent c74d105c
......@@ -17,9 +17,6 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// TODO
// Icons
// Direct shortcut setting
#include "kateexternaltoolsconfigwidget.h"
#include "externaltoolsplugin.h"
#include "kateexternaltool.h"
......@@ -84,13 +81,6 @@ KateExternalToolServiceEditor::KateExternalToolServiceEditor(KateExternalTool* t
ui->setupUi(this);
ui->btnIcon->setIconSize(KIconLoader::SizeSmall);
auto contextAction = new ContextAction(QIcon::fromTheme(QStringLiteral("code-context"), QIcon::fromTheme(QStringLiteral("tools-wizard"))),
QStringLiteral("Insert variable"), this);
contextAction->attachTo(ui->edtExecutable);
contextAction->attachTo(ui->edtArgs);
// contextAction->attachTo(ui->edtInput); // not a QLineEdit
contextAction->attachTo(ui->edtWorkingDir);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &KateExternalToolServiceEditor::slotOKClicked);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(ui->btnMimeType, &QToolButton::clicked, this, &KateExternalToolServiceEditor::showMTDlg);
......@@ -455,37 +445,4 @@ void KateExternalToolsConfigWidget::slotEdit()
}
// END KateExternalToolsConfigWidget
ContextAction::ContextAction(const QIcon & icon, const QString & text, QObject * parent)
: QObject(parent)
, m_action(new QAction(icon, text, this))
{
connect(m_action, &QAction::triggered, [this]() {
if (m_currentLineEdit) {
Q_EMIT triggered(m_currentLineEdit);
}
});
}
void ContextAction::attachTo(QLineEdit * lineEdit)
{
lineEdit->installEventFilter(this);
}
bool ContextAction::eventFilter(QObject *watched, QEvent *event)
{
auto lineEdit = qobject_cast<QLineEdit*>(watched);
if (lineEdit) {
if (event->type() == QEvent::FocusOut) {
lineEdit->removeAction(m_action);
m_currentLineEdit = nullptr;
}
else if (event->type() == QEvent::FocusIn) {
m_currentLineEdit = lineEdit;
lineEdit->addAction(m_action, QLineEdit::TrailingPosition);
}
}
return false;
}
// kate: space-indent on; indent-width 4; replace-tabs on;
......@@ -124,45 +124,6 @@ private:
KateExternalTool* m_tool;
};
/**
* Action that is only visible if QLineEdit has focus.
*/
class ContextAction : public QObject
{
Q_OBJECT
public:
/**
* Constructor that will add @p action to all attached QLineEdits.
*/
ContextAction(const QIcon & icon, const QString & text, QObject * parent = nullptr);
/**
* Attaches the action provided in the constructor to @p lineEdit
* whenever the @p lineEdit has focus.
*/
void attachTo(QLineEdit * lineEdit);
Q_SIGNALS:
/**
* This signal is emitted whenever the action was triggered for
* the given @p lineEdit. The @p lineEdit is always a valid pointer.
*/
void triggered(QLineEdit * lineEdit);
protected:
/**
* Reimplemented to show/hide action for the currently focused
* line edit.
*/
bool eventFilter(QObject *watched, QEvent *event) override;
private:
QLineEdit * m_currentLineEdit = nullptr;
QAction * m_action;
};
#endif // KTEXTEDITOR_EXTERNALTOOLS_CONFIGWIDGET_H
// kate: space-indent on; indent-width 4; replace-tabs on;
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