[kde-doc-english] [kate] addons/kate/textfilter: REVIEW: 113411
Alex Turbov
i.zaufi at gmail.com
Sat Oct 26 06:12:34 UTC 2013
Git commit b1fa3a7a48221762e2acc29e61b7c89bd3a9d3b7 by Alex Turbov.
Committed on 24/10/2013 at 06:26.
Pushed by turbov into branch 'master'.
REVIEW: 113411
GUI:
Add an option to split STROUT and STDERR. If there smth in STDOUT, then
a passive error message will arrive w/ a command line end an error output.
When turned OFF, the textfilter plugin works as it was before:
output everything to a document despite of error.
Both options ("copy to clipboard" and "merge output") now are stored
in the configuration file.
If no output produced by the filter, the document remains unchaged.
M +59 -19 addons/kate/textfilter/plugin_katetextfilter.cpp
M +11 -8 addons/kate/textfilter/plugin_katetextfilter.h
M +15 -9 addons/kate/textfilter/textfilterwidget.ui
http://commits.kde.org/kate/b1fa3a7a48221762e2acc29e61b7c89bd3a9d3b7
diff --git a/addons/kate/textfilter/plugin_katetextfilter.cpp b/addons/kate/textfilter/plugin_katetextfilter.cpp
index 9b8828e..5a00fce 100644
--- a/addons/kate/textfilter/plugin_katetextfilter.cpp
+++ b/addons/kate/textfilter/plugin_katetextfilter.cpp
@@ -21,9 +21,9 @@
#include "ui_textfilterwidget.h"
#include <ktexteditor/editor.h>
+#include <ktexteditor/messageinterface.h>
#include <kdialog.h>
-
#include <kaction.h>
#include <kcomponentdata.h>
#include <kmessagebox.h>
@@ -51,12 +51,12 @@ PluginViewKateTextFilter::PluginViewKateTextFilter(PluginKateTextFilter *plugin,
, Kate::XMLGUIClient(PluginKateTextFilterFactory::componentData())
, m_plugin(plugin)
{
- KAction *a = actionCollection()->addAction("edit_filter");
+ KAction* a = actionCollection()->addAction("edit_filter");
a->setText(i18n("Filter Te&xt..."));
a->setShortcut(Qt::CTRL + Qt::Key_Backslash);
connect(a, SIGNAL(triggered(bool)), plugin, SLOT(slotEditFilter()));
- mainwindow->guiFactory()->addClient (this);
+ mainwindow->guiFactory()->addClient(this);
}
PluginViewKateTextFilter::~PluginViewKateTextFilter()
@@ -68,7 +68,8 @@ PluginKateTextFilter::PluginKateTextFilter(QObject* parent, const QVariantList&)
: Kate::Plugin((Kate::Application *)parent, "kate-text-filter-plugin")
, KTextEditor::Command()
, m_pFilterProcess(NULL)
- , pasteResult(true)
+ , copyResult(false)
+ , mergeOutput(true)
{
KTextEditor::CommandInterface* cmdIface =
qobject_cast<KTextEditor::CommandInterface*>(application()->editor());
@@ -103,19 +104,49 @@ void PluginKateTextFilter::slotFilterReceivedStdout()
void PluginKateTextFilter::slotFilterReceivedStderr ()
{
- m_strFilterOutput += QString::fromLocal8Bit(m_pFilterProcess->readAllStandardError());
+ const QString block = QString::fromLocal8Bit(m_pFilterProcess->readAllStandardError());
+ if (mergeOutput)
+ m_strFilterOutput += block;
+ else
+ m_stderrOutput += block;
}
-void PluginKateTextFilter::slotFilterProcessExited (int, QProcess::ExitStatus)
+void PluginKateTextFilter::slotFilterProcessExited(int, QProcess::ExitStatus)
{
- KTextEditor::View * kv (application()->activeMainWindow()->activeView());
+ KTextEditor::View* kv(application()->activeMainWindow()->activeView());
if (!kv) return;
- if (!pasteResult) {
+ // Is there any error output to display?
+ if (!mergeOutput && !m_stderrOutput.isEmpty())
+ {
+ KTextEditor::MessageInterface* iface =
+ qobject_cast<KTextEditor::MessageInterface*>(kv->document());
+ if (iface)
+ {
+ QPointer<KTextEditor::Message> message = new KTextEditor::Message(
+ i18nc(
+ "@info"
+ , "<title>Result of:</title><nl /><pre><code>$ %1\n<nl />%2</code></pre>"
+ , m_last_command
+ , m_stderrOutput
+ )
+ , KTextEditor::Message::Error
+ );
+ message->setWordWrap(true);
+ message->setAutoHide(1000);
+ iface->postMessage(message);
+ }
+ }
+
+ if (copyResult) {
QApplication::clipboard()->setText(m_strFilterOutput);
return;
}
+ // Do not even try to change the document if no result collected...
+ if (m_strFilterOutput.isEmpty())
+ return;
+
kv->document()->startEditing();
KTextEditor::Cursor start = kv->cursorPosition();
@@ -128,23 +159,22 @@ void PluginKateTextFilter::slotFilterProcessExited (int, QProcess::ExitStatus)
kv->insertText(m_strFilterOutput);
kv->document()->endEditing();
- m_strFilterOutput = "";
}
-static void slipInFilter (KProcess & proc, KTextEditor::View & view, QString command)
+static void slipInFilter(KProcess & proc, KTextEditor::View & view, QString command)
{
QString inputText;
if (view.selection()) {
- inputText = view.selectionText ();
+ inputText = view.selectionText();
}
proc.clearProgram ();
proc.setShellCommand(command);
proc.start();
- QByteArray encoded = inputText.toLocal8Bit ();
+ QByteArray encoded = inputText.toLocal8Bit();
proc.write(encoded);
proc.closeWriteChannel();
// TODO: Put up a modal dialog to defend the text from further
@@ -163,7 +193,7 @@ void PluginKateTextFilter::slotEditFilter()
if (!application()->activeMainWindow())
return;
- KTextEditor::View * kv (application()->activeMainWindow()->activeView());
+ KTextEditor::View* kv(application()->activeMainWindow()->activeView());
if (!kv) return;
KDialog dialog(application()->activeMainWindow()->window());
@@ -179,17 +209,25 @@ void PluginKateTextFilter::slotEditFilter()
KConfigGroup config(KGlobal::config(), "PluginTextFilter");
QStringList items = config.readEntry("Completion list", QStringList());
+ copyResult = config.readEntry("Copy result", false);
+ mergeOutput = config.readEntry("Merge output", true);
ui.filterBox->setMaxCount(10);
ui.filterBox->setHistoryItems(items, true);
+ ui.copyResult->setChecked(copyResult);
+ ui.mergeOutput->setChecked(mergeOutput);
connect(ui.filterBox, SIGNAL(activated(QString)), &dialog, SIGNAL(okClicked()));
if (dialog.exec() == QDialog::Accepted) {
- pasteResult = !ui.checkBox->isChecked();
+ copyResult = ui.copyResult->isChecked();
+ mergeOutput = ui.mergeOutput->isChecked();
const QString filter = ui.filterBox->currentText();
if (!filter.isEmpty()) {
ui.filterBox->addToHistory(filter);
config.writeEntry("Completion list", ui.filterBox->historyItems());
+ config.writeEntry("Copy result", copyResult);
+ config.writeEntry("Merge output", mergeOutput);
+ m_last_command = filter;
runFilter(kv, filter);
}
}
@@ -197,12 +235,12 @@ void PluginKateTextFilter::slotEditFilter()
void PluginKateTextFilter::runFilter(KTextEditor::View *kv, const QString &filter)
{
- m_strFilterOutput = "";
+ m_strFilterOutput.clear();
+ m_stderrOutput.clear();
if (!m_pFilterProcess)
{
m_pFilterProcess = new KProcess;
- m_pFilterProcess->setOutputChannelMode(KProcess::MergedChannels);
connect (m_pFilterProcess, SIGNAL(readyReadStandardOutput()),
this, SLOT(slotFilterReceivedStdout()));
@@ -211,10 +249,13 @@ void PluginKateTextFilter::runFilter(KTextEditor::View *kv, const QString &filte
this, SLOT(slotFilterReceivedStderr()));
connect (m_pFilterProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
- this, SLOT(slotFilterProcessExited(int,QProcess::ExitStatus))) ;
+ this, SLOT(slotFilterProcessExited(int,QProcess::ExitStatus)));
}
+ m_pFilterProcess->setOutputChannelMode(
+ mergeOutput ? KProcess::MergedChannels : KProcess::SeparateChannels
+ );
- slipInFilter (*m_pFilterProcess, *kv, filter);
+ slipInFilter(*m_pFilterProcess, *kv, filter);
}
//BEGIN Kate::Command methods
@@ -240,7 +281,6 @@ bool PluginKateTextFilter::exec(KTextEditor::View *v, const QString &cmd, QStrin
return false;
}
- pasteResult = true;
runFilter(v, filter);
return true;
}
diff --git a/addons/kate/textfilter/plugin_katetextfilter.h b/addons/kate/textfilter/plugin_katetextfilter.h
index 6c4a8c5..9bf1431 100644
--- a/addons/kate/textfilter/plugin_katetextfilter.h
+++ b/addons/kate/textfilter/plugin_katetextfilter.h
@@ -37,28 +37,31 @@ class PluginKateTextFilter : public Kate::Plugin, public KTextEditor::Command
Q_OBJECT
public:
- explicit PluginKateTextFilter( QObject* parent = 0, const QVariantList& = QVariantList() );
+ explicit PluginKateTextFilter(QObject* parent = 0, const QVariantList& = QVariantList() );
virtual ~PluginKateTextFilter();
Kate::PluginView *createView (Kate::MainWindow *mainWindow);
// Kate::Command
const QStringList& cmds ();
- bool exec (KTextEditor::View *view, const QString &cmd, QString &msg);
- bool help (KTextEditor::View *view, const QString &cmd, QString &msg);
+ bool exec(KTextEditor::View *view, const QString &cmd, QString &msg);
+ bool help(KTextEditor::View *view, const QString &cmd, QString &msg);
private:
- void runFilter( KTextEditor::View *kv, const QString & filter );
+ void runFilter(KTextEditor::View *kv, const QString & filter);
private:
QString m_strFilterOutput;
+ QString m_stderrOutput;
+ QString m_last_command;
KProcess * m_pFilterProcess;
QStringList completionList;
- bool pasteResult;
+ bool copyResult;
+ bool mergeOutput;
public slots:
void slotEditFilter ();
- void slotFilterReceivedStdout ();
- void slotFilterReceivedStderr ();
- void slotFilterProcessExited (int exitCode, QProcess::ExitStatus exitStatus);
+ void slotFilterReceivedStdout();
+ void slotFilterReceivedStderr();
+ void slotFilterProcessExited(int exitCode, QProcess::ExitStatus exitStatus);
};
class PluginViewKateTextFilter: public Kate::PluginView, public Kate::XMLGUIClient
diff --git a/addons/kate/textfilter/textfilterwidget.ui b/addons/kate/textfilter/textfilterwidget.ui
index 73e4d3c..ed77177 100644
--- a/addons/kate/textfilter/textfilterwidget.ui
+++ b/addons/kate/textfilter/textfilterwidget.ui
@@ -2,14 +2,6 @@
<ui version="4.0">
<class>TextFilterWidget</class>
<widget class="QWidget" name="TextFilterWidget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>464</width>
- <height>73</height>
- </rect>
- </property>
<property name="windowTitle">
<string>Filter</string>
</property>
@@ -44,12 +36,26 @@
</widget>
</item>
<item>
- <widget class="QCheckBox" name="checkBox">
+ <widget class="QCheckBox" name="copyResult">
+ <property name="toolTip">
+ <string>Copy the result to clipboard leaving a document unchanged.</string>
+ </property>
<property name="text">
<string>Copy the result instead of pasting it</string>
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="mergeOutput">
+ <property name="toolTip">
+ <string>If checked, an output from STDOUT and STDERR will be merged and no errors will be reported.
+Otherwise, STDERR will be displayed as a passive message.</string>
+ </property>
+ <property name="text">
+ <string>Merge STDIN and STDOUT</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<customwidgets>
More information about the kde-doc-english
mailing list