aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Cullmann <[email protected]>2015-07-27 12:59:17 +0200
committerChristoph Cullmann <[email protected]>2015-07-27 12:59:17 +0200
commita4e3d623350fe6f0f1ae38864d00fded4a454012 (patch)
tree218219a541bb5e610626b32dcaf831bc616437ba
parent428d8d05b3750af3191722b06a1c5879771d5eda (diff)
port more of text filter
-rw-r--r--addons/textfilter/plugin_katetextfilter.cpp79
-rw-r--r--addons/textfilter/plugin_katetextfilter.h14
2 files changed, 53 insertions, 40 deletions
diff --git a/addons/textfilter/plugin_katetextfilter.cpp b/addons/textfilter/plugin_katetextfilter.cpp
index 549be9a..cf474cc 100644
--- a/addons/textfilter/plugin_katetextfilter.cpp
+++ b/addons/textfilter/plugin_katetextfilter.cpp
@@ -16,7 +16,6 @@
***************************************************************************/
#include "plugin_katetextfilter.h"
-#include "plugin_katetextfilter.moc"
#include "ui_textfilterwidget.h"
@@ -35,48 +34,31 @@
#include <KPluginFactory>
#include <kauthorized.h>
#include <kactioncollection.h>
+#include <KXMLGUIFactory>
#include <qapplication.h>
#include <qclipboard.h>
-
K_PLUGIN_FACTORY_WITH_JSON(TextFilterPluginFactory, "textfilterplugin.json", registerPlugin<PluginKateTextFilter>();)
-PluginViewKateTextFilter::PluginViewKateTextFilter(PluginKateTextFilter *plugin,
- Kate::MainWindow *mainwindow)
- : Kate::PluginView(mainwindow)
- , Kate::XMLGUIClient(PluginKateTextFilterFactory::componentData())
- , m_plugin(plugin)
-{
- KAction* a = actionCollection()->addAction("edit_filter");
- a->setText(i18n("Filter Te&xt..."));
- actionCollection()->setDefaultShortcut(a, Qt::CTRL + Qt::Key_Backslash);
- connect(a, SIGNAL(triggered(bool)), plugin, SLOT(slotEditFilter()));
-
- mainwindow->guiFactory()->addClient(this);
-}
-
-PluginViewKateTextFilter::~PluginViewKateTextFilter()
-{
- mainWindow()->guiFactory()->removeClient (this);
-}
-
-PluginKateTextFilter::PluginKateTextFilter(QObject* parent, const QVariantList&)
- : Kate::Plugin((Kate::Application *)parent, "kate-text-filter-plugin")
- , KTextEditor::Command(QStringList dummy("textfilter"))
- , m_pFilterProcess(NULL)
+PluginKateTextFilter::PluginKateTextFilter(QObject *parent, const QList<QVariant> &):
+ KTextEditor::Plugin(parent)
+ , m_pFilterProcess(Q_NULLPTR)
, copyResult(false)
- , mergeOutput(true)
+ , mergeOutput(false)
{
}
PluginKateTextFilter::~PluginKateTextFilter()
{
- delete m_pFilterProcess;
+ if (m_pFilterProcess) {
+ m_pFilterProcess->kill();
+ m_pFilterProcess->waitForFinished();
+ delete m_pFilterProcess;
+ }
}
-
-Kate::PluginView *PluginKateTextFilter::createView (Kate::MainWindow *mainWindow)
+QObject *PluginKateTextFilter::createView (KTextEditor::MainWindow *mainWindow)
{
return new PluginViewKateTextFilter(this, mainWindow);
}
@@ -98,7 +80,7 @@ void PluginKateTextFilter::slotFilterReceivedStderr ()
void PluginKateTextFilter::slotFilterProcessExited(int, QProcess::ExitStatus)
{
- KTextEditor::View* kv(application()->activeMainWindow()->activeView());
+ KTextEditor::View* kv(KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView());
if (!kv) return;
// Is there any error output to display?
@@ -162,20 +144,22 @@ static void slipInFilter(KProcess & proc, KTextEditor::View & view, QString comm
void PluginKateTextFilter::slotEditFilter()
{
- if (!KAuthorized::authorizeKAction("shell_access")) {
+ if (!KAuthorized::authorizeKAction(QStringLiteral("shell_access"))) {
KMessageBox::sorry(0,i18n(
"You are not allowed to execute arbitrary external applications. If "
"you want to be able to do this, contact your system administrator."),
i18n("Access Restrictions"));
return;
}
- if (!application()->activeMainWindow())
+ if (!KTextEditor::Editor::instance()->application()->activeMainWindow())
return;
- KTextEditor::View* kv(application()->activeMainWindow()->activeView());
+ KTextEditor::View* kv(KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView());
if (!kv) return;
- KDialog dialog(application()->activeMainWindow()->window());
+#if 0 // FIXME
+
+ QDialog dialog(KTextEditor::Editor::instance()->application()->activeMainWindow()->window());
dialog.setCaption("Text Filter");
dialog.setButtons(KDialog::Cancel | KDialog::Ok);
dialog.setDefaultButton(KDialog::Ok);
@@ -210,6 +194,7 @@ void PluginKateTextFilter::slotEditFilter()
runFilter(kv, filter);
}
}
+#endif
}
void PluginKateTextFilter::runFilter(KTextEditor::View *kv, const QString &filter)
@@ -247,7 +232,7 @@ bool PluginKateTextFilter::help(KTextEditor::View *, const QString&, QString &ms
bool PluginKateTextFilter::exec(KTextEditor::View *v, const QString &cmd, QString &msg)
{
- QString filter = cmd.section(' ', 1).trimmed();
+ QString filter = cmd.section(QLatin1Char(' '), 1).trimmed();
if (filter.isEmpty()) {
msg = i18n("Usage: textfilter COMMAND");
@@ -259,6 +244,30 @@ bool PluginKateTextFilter::exec(KTextEditor::View *v, const QString &cmd, QStrin
}
//END
+
+PluginViewKateTextFilter::PluginViewKateTextFilter(PluginKateTextFilter *plugin,
+ KTextEditor::MainWindow *mainwindow)
+ : QObject(mainwindow)
+ , m_plugin(plugin)
+ , m_mainWindow(mainwindow)
+{
+ // setup right xml gui data
+ KXMLGUIClient::setComponentName(QStringLiteral("textfilter"), i18n("Text Filter"));
+ setXMLFile(QStringLiteral("ui.rc"));
+
+ QAction* a = actionCollection()->addAction(QStringLiteral("edit_filter"));
+ a->setText(i18n("Filter Te&xt..."));
+ actionCollection()->setDefaultShortcut(a, Qt::CTRL + Qt::Key_Backslash);
+ connect(a, SIGNAL(triggered(bool)), plugin, SLOT(slotEditFilter()));
+
+ mainwindow->guiFactory()->addClient(this);
+}
+
+PluginViewKateTextFilter::~PluginViewKateTextFilter()
+{
+ m_mainWindow->guiFactory()->removeClient (this);
+}
+
// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
// required for TextFilterPluginFactory vtable
diff --git a/addons/textfilter/plugin_katetextfilter.h b/addons/textfilter/plugin_katetextfilter.h
index ae45fcb..df89c91 100644
--- a/addons/textfilter/plugin_katetextfilter.h
+++ b/addons/textfilter/plugin_katetextfilter.h
@@ -21,9 +21,8 @@
#include <KTextEditor/Plugin>
#include <KTextEditor/Application>
#include <KTextEditor/MainWindow>
-
-#include <ktexteditor/view.h>
-#include <ktexteditor/document.h>
+#include <KTextEditor/View>
+#include <KTextEditor/Document>
#include <KTextEditor/Command>
#include <QProcess>
@@ -31,12 +30,16 @@
class KProcess;
-class PluginKateTextFilter : public KTextEditor::Plugin, public KTextEditor::Command
+class PluginKateTextFilter : public KTextEditor::Plugin//, public KTextEditor::Command
{
Q_OBJECT
public:
- explicit PluginKateTextFilter(QObject* parent = 0, const QVariantList& = QVariantList() );
+ /**
+ * Plugin constructor.
+ */
+ explicit PluginKateTextFilter(QObject *parent = 0, const QList<QVariant> & = QList<QVariant>());
+
virtual ~PluginKateTextFilter();
QObject *createView(KTextEditor::MainWindow *mainWindow);
@@ -72,6 +75,7 @@ class PluginViewKateTextFilter: public QObject, public KXMLGUIClient
private:
PluginKateTextFilter *m_plugin;
+ KTextEditor::MainWindow *m_mainWindow;
};
#endif // PLUGIN_KATETEXTFILTER_H