summaryrefslogtreecommitdiff
path: root/src/plugins/find
diff options
context:
space:
mode:
authorcon <qtc-committer@nokia.com>2009-11-04 18:10:03 +0100
committercon <qtc-committer@nokia.com>2009-11-04 18:44:19 +0100
commit9c0ed539ccad01158a63d5cda4e9fdb026180449 (patch)
tree08a32f2131397f9928d6739ccbe19602f51c3d0b /src/plugins/find
parent239e0418caeb7f97c217a7867f45970e07366401 (diff)
downloadqt-creator-9c0ed539ccad01158a63d5cda4e9fdb026180449.tar.gz
Prevent global replace before search is done.
Also fix focusing issues of the replace line edit. Reviewed-by: Roberto Raggi
Diffstat (limited to 'src/plugins/find')
-rw-r--r--src/plugins/find/searchresultwindow.cpp43
-rw-r--r--src/plugins/find/searchresultwindow.h9
2 files changed, 29 insertions, 23 deletions
diff --git a/src/plugins/find/searchresultwindow.cpp b/src/plugins/find/searchresultwindow.cpp
index c60e2d6c9e..5bbf06af51 100644
--- a/src/plugins/find/searchresultwindow.cpp
+++ b/src/plugins/find/searchresultwindow.cpp
@@ -53,7 +53,8 @@ static const QString SETTINGSKEYEXPANDRESULTS("ExpandResults");
SearchResultWindow::SearchResultWindow()
: m_currentSearch(0),
- m_isShowingReplaceUI(false)
+ m_isShowingReplaceUI(false),
+ m_focusReplaceEdit(false)
{
m_widget = new QStackedWidget;
m_widget->setWindowTitle(name());
@@ -124,15 +125,13 @@ void SearchResultWindow::setShowReplaceUI(bool show)
m_isShowingReplaceUI = show;
}
-bool SearchResultWindow::isShowingReplaceUI() const
-{
- return m_isShowingReplaceUI;
-}
-
void SearchResultWindow::handleReplaceButton()
{
QTC_ASSERT(m_currentSearch, return);
- m_currentSearch->replaceButtonClicked(m_replaceTextEdit->text(), checkedItems());
+ // check if button is actually enabled, because this is also triggered
+ // by pressing return in replace line edit
+ if (m_replaceButton->isEnabled())
+ m_currentSearch->replaceButtonClicked(m_replaceTextEdit->text(), checkedItems());
}
QList<SearchResultItem> SearchResultWindow::checkedItems() const
@@ -177,9 +176,19 @@ SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndRep
return m_currentSearch;
}
+void SearchResultWindow::finishSearch()
+{
+ if (m_items.count()) {
+ m_replaceButton->setEnabled(true);
+ } else {
+ showNoMatchesFound();
+ }
+}
+
void SearchResultWindow::clearContents()
{
- setReplaceUIEnabled(false);
+ m_replaceTextEdit->setEnabled(false);
+ m_replaceButton->setEnabled(false);
m_replaceTextEdit->clear();
m_searchResultTreeView->clear();
m_items.clear();
@@ -189,7 +198,8 @@ void SearchResultWindow::clearContents()
void SearchResultWindow::showNoMatchesFound()
{
- setReplaceUIEnabled(false);
+ m_replaceTextEdit->setEnabled(false);
+ m_replaceButton->setEnabled(false);
m_widget->setCurrentWidget(m_noMatchesFoundDisplay);
}
@@ -220,7 +230,8 @@ void SearchResultWindow::setFocus()
m_searchResultTreeView->setFocus();
} else {
if (!m_widget->focusWidget()
- || m_widget->focusWidget() == m_replaceTextEdit) {
+ || m_widget->focusWidget() == m_replaceTextEdit
+ || m_focusReplaceEdit) {
m_replaceTextEdit->setFocus();
} else {
m_searchResultTreeView->setFocus();
@@ -257,20 +268,16 @@ void SearchResultWindow::addResult(const QString &fileName, int lineNumber, cons
m_items.append(item);
m_searchResultTreeView->appendResultLine(index, fileName, lineNumber, rowText, searchTermStart, searchTermLength);
if (index == 0) {
- setReplaceUIEnabled(true);
- // We didn't have an item before, set the focus to the m_searchResultTreeView
+ m_replaceTextEdit->setEnabled(true);
+ // We didn't have an item before, set the focus to the search widget
+ m_focusReplaceEdit = true;
setFocus();
+ m_focusReplaceEdit = false;
m_searchResultTreeView->selectionModel()->select(m_searchResultTreeView->model()->index(0, 0, QModelIndex()), QItemSelectionModel::Select);
emit navigateStateChanged();
}
}
-void SearchResultWindow::setReplaceUIEnabled(bool enabled)
-{
- m_replaceTextEdit->setEnabled(enabled);
- m_replaceButton->setEnabled(enabled);
-}
-
void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
{
m_searchResultTreeView->setAutoExpandResults(checked);
diff --git a/src/plugins/find/searchresultwindow.h b/src/plugins/find/searchresultwindow.h
index c41ca3424f..e8996f8c02 100644
--- a/src/plugins/find/searchresultwindow.h
+++ b/src/plugins/find/searchresultwindow.h
@@ -103,9 +103,6 @@ public:
void setTextEditorFont(const QFont &font);
- void setShowReplaceUI(bool show);
- bool isShowingReplaceUI() const;
-
void setTextToReplace(const QString &textToReplace);
QString textToReplace() const;
@@ -114,17 +111,18 @@ public:
public slots:
void clearContents();
- void showNoMatchesFound();
void addResult(const QString &fileName, int lineNumber, const QString &lineText,
int searchTermStart, int searchTermLength, const QVariant &userData = QVariant());
+ void finishSearch();
private slots:
void handleExpandCollapseToolButton(bool checked);
void handleJumpToSearchResult(int index, bool checked);
void handleReplaceButton();
- void setReplaceUIEnabled(bool enabled);
+ void showNoMatchesFound();
private:
+ void setShowReplaceUI(bool show);
void readSettings();
void writeSettings();
QList<SearchResultItem> checkedItems() const;
@@ -140,6 +138,7 @@ private:
SearchResult *m_currentSearch;
QList<SearchResultItem> m_items;
bool m_isShowingReplaceUI;
+ bool m_focusReplaceEdit;
};
} // namespace Find