Commit be861391 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Allow opening results in new doc + use full doc text if no selection

This is a proposal to add the following two features to textfilter:
- Allow opening results in a new document
- If there is no selection, use full document text

This allows you to run grep / rg like tools to filter text in the
document quickly and view the results. One can do a selection to achieve
the same but the major issue with selection is that, it is very slow if
your document is big.
parent 67205f7f
......@@ -57,6 +57,7 @@ PluginKateTextFilter::~PluginKateTextFilter()
QObject *PluginKateTextFilter::createView(KTextEditor::MainWindow *mainWindow)
{
m_mainWindow = mainWindow;
// create a plugin view
return new PluginViewKateTextFilter(this, mainWindow);
}
......@@ -93,6 +94,14 @@ void PluginKateTextFilter::slotFilterProcessExited(int, QProcess::ExitStatus)
kv->document()->postMessage(message);
}
if (newDocument) {
auto v = m_mainWindow->openUrl(QUrl());
if (v && v->document()) {
v->document()->setText(m_strFilterOutput);
}
return;
}
if (copyResult) {
QApplication::clipboard()->setText(m_strFilterOutput);
return;
......@@ -122,6 +131,8 @@ static void slipInFilter(KProcess &proc, KTextEditor::View &view, const QString
if (view.selection()) {
inputText = view.selectionText();
} else {
inputText = view.document()->text();
}
proc.clearProgram();
......@@ -165,18 +176,22 @@ void PluginKateTextFilter::slotEditFilter()
QStringList items = config.readEntry("Completion list", QStringList());
copyResult = config.readEntry("Copy result", false);
mergeOutput = config.readEntry("Merge output", true);
newDocument = config.readEntry("New Document", false);
ui.filterBox->setMaxCount(10);
ui.filterBox->setHistoryItems(items, true);
ui.filterBox->setMinimumContentsLength(80);
ui.copyResult->setChecked(copyResult);
ui.mergeOutput->setChecked(mergeOutput);
ui.newDoc->setChecked(newDocument);
if (dialog.exec() == QDialog::Accepted) {
copyResult = ui.copyResult->isChecked();
mergeOutput = ui.mergeOutput->isChecked();
newDocument = ui.newDoc->isChecked();
const QString filter = ui.filterBox->currentText();
if (!filter.isEmpty()) {
ui.filterBox->addToHistory(filter);
config.writeEntry("New Document", newDocument);
config.writeEntry("Completion list", ui.filterBox->historyItems());
config.writeEntry("Copy result", copyResult);
config.writeEntry("Merge output", mergeOutput);
......
......@@ -49,6 +49,8 @@ private:
QStringList completionList;
bool copyResult = false;
bool mergeOutput = false;
bool newDocument = false;
KTextEditor::MainWindow *m_mainWindow;
public Q_SLOTS:
void slotEditFilter();
void slotFilterReceivedStdout();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>370</width>
<height>159</height>
<height>190</height>
</rect>
</property>
<property name="windowTitle">
......@@ -31,7 +31,13 @@
</widget>
</item>
<item>
<widget class="KHistoryComboBox" name="filterBox">
<widget class="KHistoryComboBox" name="filterBox"/>
</item>
<item>
<widget class="QCheckBox" name="newDoc">
<property name="text">
<string>Open results in a new document</string>
</property>
</widget>
</item>
<item>
......
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