Commit 72e8bd3d authored by Kåre Särs's avatar Kåre Särs

S&R: Disable search buttons while replacing + add replace status

CCBUG: 380861
parent af2d6ae6
......@@ -370,6 +370,8 @@ m_mainWindow (mainWin)
connect(&m_replacer, SIGNAL(matchReplaced(KTextEditor::Document*,int,int,int)),
this, SLOT(addMatchMark(KTextEditor::Document*,int,int,int)));
connect(&m_replacer, &ReplaceMatches::replaceStatus, this, &KatePluginSearchView::replaceStatus);
// Hook into line edit context menus
m_ui.searchCombo->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui.searchCombo, SIGNAL(customContextMenuRequested(QPoint)), this,
......@@ -1431,18 +1433,75 @@ void KatePluginSearchView::replaceChecked()
m_ui.stopAndNext->setCurrentIndex(1);
m_ui.displayOptions->setChecked(false);
m_ui.displayOptions->setDisabled(true);
m_ui.newTabButton->setDisabled(true);
m_ui.searchCombo->setDisabled(true);
m_ui.searchButton->setDisabled(true);
m_ui.replaceCheckedBtn->setDisabled(true);
m_ui.replaceButton->setDisabled(true);
m_ui.replaceCombo->setDisabled(true);
m_ui.searchPlaceCombo->setDisabled(true);
m_ui.useRegExp->setDisabled(true);
m_ui.matchCase->setDisabled(true);
m_ui.expandResults->setDisabled(true);
m_ui.currentFolderButton->setDisabled(true);
m_curResults->replaceStr = m_ui.replaceCombo->currentText();
QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
if (root) {
m_curResults->treeRootText = root->data(0, Qt::DisplayRole).toString();
}
m_replacer.replaceChecked(m_curResults->tree,
m_curResults->regExp,
m_curResults->replaceStr);
}
void KatePluginSearchView::replaceStatus(const QUrl &url)
{
if (!m_curResults) {
qDebug() << "m_curResults == nullptr";
return;
}
QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
if (root) {
QString file = url.toString(QUrl::PreferLocalFile);
if (file.size() > 70) {
root->setData(0, Qt::DisplayRole, i18n("<b>Replacing in: ...%1</b>", file.right(70)));
}
else {
root->setData(0, Qt::DisplayRole, i18n("<b>Replacing in: %1</b>", file));
}
}
}
void KatePluginSearchView::replaceDone()
{
m_ui.stopAndNext->setCurrentIndex(0);
m_ui.replaceCombo->setDisabled(false);
m_ui.newTabButton->setDisabled(false);
m_ui.searchCombo->setDisabled(false);
m_ui.searchButton->setDisabled(false);
m_ui.replaceCheckedBtn->setDisabled(false);
m_ui.replaceButton->setDisabled(false);
m_ui.displayOptions->setDisabled(false);
m_ui.searchPlaceCombo->setDisabled(false);
m_ui.useRegExp->setDisabled(false);
m_ui.matchCase->setDisabled(false);
m_ui.expandResults->setDisabled(false);
m_ui.currentFolderButton->setDisabled(false);
if (!m_curResults) {
qDebug() << "m_curResults == nullptr";
return;
}
QTreeWidgetItem *root = m_curResults->tree->topLevelItem(0);
if (root) {
root->setData(0, Qt::DisplayRole, m_curResults->treeRootText);
}
}
void KatePluginSearchView::docViewChanged()
......
......@@ -58,6 +58,7 @@ public:
bool matchCase;
QString replaceStr;
int searchPlaceIndex;
QString treeRootText;
};
// This class keeps the focus inside the S&R plugin when pressing tab/shift+tab by overriding focusNextPrevChild()
......@@ -155,6 +156,7 @@ private Q_SLOTS:
void replaceSingleMatch();
void replaceChecked();
void replaceStatus(const QUrl &url);
void replaceDone();
void docViewChanged();
......
......@@ -21,6 +21,7 @@
#include "replace_matches.h"
#include <QTreeWidgetItem>
#include <QTimer>
#include <ktexteditor/movinginterface.h>
#include <ktexteditor/movingrange.h>
#include <klocalizedstring.h>
......@@ -43,6 +44,7 @@ void ReplaceMatches::replaceChecked(QTreeWidget *tree, const QRegularExpression
m_regExp = regexp;
m_replaceText = replace;
m_cancelReplace = false;
m_progressTime.restart();
emit replaceNextMatch();
}
......@@ -102,7 +104,6 @@ void ReplaceMatches::doReplaceNextMatch()
KTextEditor::Document *doc;
QString docUrl = rootItem->data(0, FileUrlRole).toString();
QString docName = rootItem->data(0, FileNameRole).toString();
if (docUrl.isEmpty()) {
doc = findNamed(rootItem->data(0, FileNameRole).toString());
}
......@@ -119,6 +120,11 @@ void ReplaceMatches::doReplaceNextMatch()
return;
}
if (m_progressTime.elapsed() > 100) {
m_progressTime.restart();
emit replaceStatus(doc->url());
}
QVector<KTextEditor::MovingRange*> rVector;
QStringList rTexts;
KTextEditor::MovingInterface* miface = qobject_cast<KTextEditor::MovingInterface*>(doc);
......
......@@ -24,6 +24,7 @@
#include <QObject>
#include <QRegularExpression>
#include <QTreeWidget>
#include <QElapsedTimer>
#include <ktexteditor/document.h>
#include <ktexteditor/application.h>
......@@ -59,6 +60,7 @@ private Q_SLOTS:
Q_SIGNALS:
void replaceNextMatch();
void matchReplaced(KTextEditor::Document* doc, int line, int column, int matchLen);
void replaceStatus(const QUrl &url);
void replaceDone();
private:
......@@ -68,6 +70,7 @@ private:
QRegularExpression m_regExp;
QString m_replaceText;
bool m_cancelReplace;
QElapsedTimer m_progressTime;
};
......
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