Commit faba06b5 authored by dt's avatar dt

Search Dialog: Make canceling possible

Task-Nr: QTCREATORBUG-2243
parent f9504cd3
......@@ -131,6 +131,16 @@ bool SymbolsFindFilter::isEnabled() const
return !m_isRunning && m_enabled;
}
bool SymbolsFindFilter::canCancel() const
{
return m_isRunning;
}
void SymbolsFindFilter::cancel()
{
m_watcher.cancel();
}
Find::FindFlags SymbolsFindFilter::supportedFindFlags() const
{
return Find::FindCaseSensitively | Find::FindRegularExpression | Find::FindWholeWords;
......
......@@ -60,6 +60,8 @@ public:
QString id() const;
QString displayName() const;
bool isEnabled() const;
bool canCancel() const;
void cancel();
Find::FindFlags supportedFindFlags() const;
void findAll(const QString &txt, Find::FindFlags findFlags);
......
......@@ -73,7 +73,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Search &amp;for:</string>
......@@ -86,17 +86,10 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="searchTerm"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="closeButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QWidget" name="configWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
......@@ -106,14 +99,7 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="replaceButton">
<property name="text">
<string>Search &amp;&amp; Replace</string>
</property>
</widget>
</item>
<item row="2" column="1" rowspan="3">
<item row="4" column="1" rowspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
......@@ -143,6 +129,27 @@
</layout>
</widget>
</item>
<item row="5" column="2">
<widget class="QPushButton" name="replaceButton">
<property name="text">
<string>Search &amp;&amp; Replace</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="closeButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......@@ -164,8 +171,6 @@
<tabstop>filterList</tabstop>
<tabstop>searchTerm</tabstop>
<tabstop>searchButton</tabstop>
<tabstop>closeButton</tabstop>
<tabstop>replaceButton</tabstop>
</tabstops>
<resources/>
<connections/>
......
......@@ -52,11 +52,13 @@ FindToolWindow::FindToolWindow(FindPlugin *plugin)
connect(m_ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(search()));
connect(m_ui.replaceButton, SIGNAL(clicked()), this, SLOT(replace()));
connect(m_ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelSearch()));
connect(m_ui.matchCase, SIGNAL(toggled(bool)), m_plugin, SLOT(setCaseSensitive(bool)));
connect(m_ui.wholeWords, SIGNAL(toggled(bool)), m_plugin, SLOT(setWholeWord(bool)));
connect(m_ui.regExp, SIGNAL(toggled(bool)), m_plugin, SLOT(setRegularExpression(bool)));
connect(m_ui.filterList, SIGNAL(activated(int)), this, SLOT(setCurrentFilter(int)));
connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates()));
m_findCompleter->setModel(m_plugin->findCompletionModel());
m_ui.searchTerm->setCompleter(m_findCompleter);
m_ui.searchTerm->installEventFilter(this);
......@@ -100,6 +102,7 @@ void FindToolWindow::updateButtonStates()
m_ui.regExp->setEnabled(filterEnabled
&& (m_currentFilter->supportedFindFlags() & Find::FindRegularExpression));
m_ui.searchTerm->setEnabled(filterEnabled);
m_ui.cancelButton->setEnabled(m_currentFilter && m_currentFilter->canCancel());
}
void FindToolWindow::setFindFilters(const QList<IFindFilter *> &filters)
......@@ -195,6 +198,12 @@ void FindToolWindow::replace()
filter->replaceAll(term, m_plugin->findFlags());
}
void FindToolWindow::cancelSearch()
{
if (m_currentFilter)
m_currentFilter->cancel();
}
void FindToolWindow::writeSettings()
{
QSettings *settings = Core::ICore::instance()->settings();
......
......@@ -63,6 +63,7 @@ protected:
private slots:
void search();
void replace();
void cancelSearch();
void setCurrentFilter(int index);
void updateButtonStates();
......
......@@ -52,7 +52,10 @@ public:
virtual QString id() const = 0;
virtual QString displayName() const = 0;
///
virtual bool isEnabled() const = 0;
virtual bool canCancel() const = 0;
virtual void cancel() = 0;
virtual QKeySequence defaultShortcut() const { return QKeySequence(); }
virtual bool isReplaceSupported() const { return false; }
virtual FindFlags supportedFindFlags() const;
......
......@@ -70,6 +70,16 @@ bool BaseFileFind::isEnabled() const
return !m_isSearching;
}
bool BaseFileFind::canCancel() const
{
return m_isSearching;
}
void BaseFileFind::cancel()
{
m_watcher.cancel();
}
QStringList BaseFileFind::fileNameFilters() const
{
QStringList filters;
......
......@@ -62,6 +62,8 @@ public:
explicit BaseFileFind(Find::SearchResultWindow *resultWindow);
bool isEnabled() const;
bool canCancel() const;
void cancel();
bool isReplaceSupported() const { return true; }
void findAll(const QString &txt, Find::FindFlags findFlags);
void replaceAll(const QString &txt, Find::FindFlags findFlags);
......
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