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