Commit 1e47de14 authored by Eike Ziller's avatar Eike Ziller
Browse files

Move advanced search dialog into search result pane.

And move the cancel button into the specific search result widget.

Change-Id: Ide8173e1ec5de091e1c1332a2b0c47d9a30a4c87
Reviewed-on: http://codereview.qt-project.org/4555

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 5990b039
......@@ -274,7 +274,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont
result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol);
m_watcher.setFuture(result);
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
CppTools::Constants::TASK_SEARCH);
......@@ -310,6 +310,11 @@ void CppFindReferences::searchFinished()
emit changed();
}
void CppFindReferences::cancel()
{
m_watcher.cancel();
}
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{
if (item.path.size() > 0) {
......@@ -439,6 +444,7 @@ void CppFindReferences::findMacroUses(const Macro &macro)
QFuture<Usage> result;
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, this, macro);
m_watcher.setFuture(result);
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
......
......@@ -83,6 +83,7 @@ public:
private Q_SLOTS:
void displayResults(int first, int last);
void searchFinished();
void cancel();
void openEditor(const Find::SearchResultItem &item);
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
......
......@@ -135,11 +135,6 @@ bool SymbolsFindFilter::isEnabled() const
return !m_isRunning && m_enabled;
}
bool SymbolsFindFilter::canCancel() const
{
return m_isRunning;
}
void SymbolsFindFilter::cancel()
{
m_watcher.cancel();
......@@ -174,6 +169,7 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
Find::FindFlags, CPlusPlus::Snapshot,
SearchSymbols *, QSet<QString> >(runSearch, txt, findFlags, m_manager->snapshot(),
&m_search, projectFileNames));
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
Core::ICore::instance()->progressManager()->addTask(m_watcher.future(),
tr("Searching"),
Find::Constants::TASK_SEARCH);
......
......@@ -63,8 +63,6 @@ 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);
......@@ -87,6 +85,7 @@ private slots:
void addResults(int begin, int end);
void finish();
void cancel();
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Find::Internal::FindDialog</class>
<widget class="QDialog" name="Find::Internal::FindDialog">
<widget class="QWidget" name="Find::Internal::FindDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>221</height>
<width>673</width>
<height>210</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="maximumSize">
<size>
<width>680</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Search for...</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Sc&amp;ope:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>filterList</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="filterList">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Search &amp;for:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>searchTerm</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="searchTerm"/>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="matchCase">
<property name="text">
<string>&amp;Case sensitive</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wholeWords">
<property name="text">
<string>&amp;Whole words only</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="regExp">
<property name="text">
<string>Use regular e&amp;xpressions</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QWidget" name="configWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="minimumSize">
<property name="sizeHint" stdset="0">
<size>
<width>80</width>
<height>0</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>Sc&amp;ope:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>filterList</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="filterList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</spacer>
</item>
<item row="0" column="2">
<item>
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>&amp;Search</string>
......@@ -73,86 +171,16 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Search &amp;for:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>searchTerm</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="searchTerm"/>
</item>
<item row="7" column="0" colspan="2">
<widget class="QWidget" name="configWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="1" rowspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="matchCase">
<property name="text">
<string>&amp;Case sensitive</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wholeWords">
<property name="text">
<string>&amp;Whole words only</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="regExp">
<property name="text">
<string>Use regular e&amp;xpressions</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="2">
<item>
<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>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -173,10 +201,6 @@
<tabstop>matchCase</tabstop>
<tabstop>wholeWords</tabstop>
<tabstop>regExp</tabstop>
<tabstop>searchButton</tabstop>
<tabstop>cancelButton</tabstop>
<tabstop>closeButton</tabstop>
<tabstop>replaceButton</tabstop>
</tabstops>
<resources/>
<connections/>
......
......@@ -136,7 +136,7 @@ bool FindPlugin::initialize(const QStringList &, QString *)
d->m_findToolBar = new Internal::FindToolBar(this, d->m_currentDocumentFind);
d->m_findDialog = new Internal::FindToolWindow(this);
SearchResultWindow *searchResultWindow = new SearchResultWindow;
SearchResultWindow *searchResultWindow = new SearchResultWindow(d->m_findDialog);
addAutoReleasedObject(searchResultWindow);
return true;
}
......@@ -178,12 +178,7 @@ void FindPlugin::openFindFilter()
QAction *action = qobject_cast<QAction*>(sender());
QTC_ASSERT(action, return);
IFindFilter *filter = action->data().value<IFindFilter *>();
if (d->m_currentDocumentFind->candidateIsEnabled())
d->m_currentDocumentFind->acceptCandidate();
QString currentFindString = (d->m_currentDocumentFind->isEnabled() ? d->m_currentDocumentFind->currentFindString() : "");
if (!currentFindString.isEmpty())
d->m_findDialog->setFindText(currentFindString);
d->m_findDialog->open(filter);
openFindDialog(filter);
}
void FindPlugin::openFindDialog(IFindFilter *filter)
......@@ -193,7 +188,8 @@ void FindPlugin::openFindDialog(IFindFilter *filter)
QString currentFindString = (d->m_currentDocumentFind->isEnabled() ? d->m_currentDocumentFind->currentFindString() : "");
if (!currentFindString.isEmpty())
d->m_findDialog->setFindText(currentFindString);
d->m_findDialog->open(filter);
d->m_findDialog->setCurrentFilter(filter);
SearchResultWindow::instance()->openNewSearchPanel();
}
void FindPlugin::setupMenu()
......
......@@ -48,7 +48,6 @@ struct FindPluginPrivate;
namespace Internal {
class FindToolBar;
class FindToolWindow;
class CurrentDocumentFind;
} // namespace Internal
......
......@@ -44,23 +44,27 @@
using namespace Find;
using namespace Find::Internal;
FindToolWindow::FindToolWindow(FindPlugin *plugin)
: QDialog(Core::ICore::instance()->mainWindow()),
static FindToolWindow *m_instance = 0;
FindToolWindow::FindToolWindow(FindPlugin *plugin, QWidget *parent)
: QWidget(parent),
m_plugin(plugin),
m_findCompleter(new QCompleter(this)),
m_currentFilter(0),
m_configWidget(0)
{
m_instance = this;
m_ui.setupUi(this);
connect(m_ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
setFocusProxy(m_ui.searchTerm);
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()));
connect(m_ui.searchTerm, SIGNAL(returnPressed()), this, SLOT(search()));
m_findCompleter->setModel(m_plugin->findCompletionModel());
m_ui.searchTerm->setCompleter(m_findCompleter);
......@@ -77,6 +81,11 @@ FindToolWindow::~FindToolWindow()
qDeleteAll(m_configWidgets);
}
FindToolWindow *FindToolWindow::instance()
{
return m_instance;
}
bool FindToolWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_ui.searchTerm && event->type() == QEvent::KeyPress) {
......@@ -85,7 +94,7 @@ bool FindToolWindow::eventFilter(QObject *obj, QEvent *event)
m_findCompleter->complete();
}
}
return QDialog::eventFilter(obj, event);
return QWidget::eventFilter(obj, event);
}
void FindToolWindow::updateButtonStates()
......@@ -105,7 +114,6 @@ 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)
......@@ -129,7 +137,7 @@ void FindToolWindow::setFindText(const QString &text)
m_ui.searchTerm->setText(text);
}
void FindToolWindow::open(IFindFilter *filter)
void FindToolWindow::setCurrentFilter(IFindFilter *filter)
{
if (!filter)
filter = m_currentFilter;
......@@ -143,7 +151,6 @@ void FindToolWindow::open(IFindFilter *filter)
m_ui.searchTerm->setFocus();
m_ui.searchTerm->selectAll();
exec();
}
void FindToolWindow::setCurrentFilter(int index)
......@@ -172,7 +179,6 @@ void FindToolWindow::acceptAndGetParameters(QString *term, IFindFilter **filter)
{
if (filter)
*filter = 0;
accept();
m_plugin->updateFindCompletion(m_ui.searchTerm->text());
int index = m_ui.filterList->currentIndex();
QString searchTerm = m_ui.searchTerm->text();
......@@ -201,12 +207,6 @@ 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();
......
......@@ -45,18 +45,19 @@ class FindPlugin;
namespace Internal {
class FindToolWindow : public QDialog
class FindToolWindow : public QWidget
{
Q_OBJECT
public:
explicit FindToolWindow(FindPlugin *plugin);
explicit FindToolWindow(FindPlugin *plugin, QWidget *parent = 0);
~FindToolWindow();
static FindToolWindow *instance();
void setFindFilters(const QList<IFindFilter *> &filters);
void setFindText(const QString &text);
void open(IFindFilter *filter);
void setCurrentFilter(IFindFilter *filter);
void readSettings();
void writeSettings();
......@@ -66,7 +67,6 @@ protected:
private slots:
void search();
void replace();
void cancelSearch();
void setCurrentFilter(int index);
void updateButtonStates();
......
......@@ -57,8 +57,6 @@ public:
virtual QString displayName() const = 0;
///
virtual bool isEnabled() const = 0;
virtual bool canCancel() const = 0;
virtual void cancel() = 0;
virtual QKeySequence defaultShortcut() const;
virtual bool isReplaceSupported() const { return false; }
virtual FindFlags supportedFindFlags() const;
......
......@@ -250,6 +250,11 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) :
m_searchTerm->setVisible(false);
descriptionLayout->addWidget(m_label);
descriptionLayout->addWidget(m_searchTerm);
m_cancelButton = new QToolButton(topWidget);
m_cancelButton->setText(tr("Cancel"));
m_cancelButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
m_cancelButton->setVisible(false);
m_replaceLabel = new QLabel(tr("Replace with:"), topWidget);
m_replaceTextEdit = new WideEnoughLineEdit(topWidget);
......@@ -257,18 +262,21 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) :
m_replaceButton->setToolTip(tr("Replace all occurrences"));
m_replaceButton->setText(tr("Replace"));
m_replaceButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
m_replaceButton->setAutoRaise(true);
m_replaceTextEdit->setTabOrder(m_replaceTextEdit, m_searchResultTreeView);
m_matchesFoundLabel = new QLabel(topWidget);
updateMatchesFoundLabel();
topLayout->addWidget(m_descriptionContainer);
topLayout->addWidget(m_cancelButton);
topLayout->addWidget(m_replaceLabel);
topLayout->addWidget(m_replaceTextEdit);
topLayout->addWidget(m_replaceButton);
topLayout->addStretch(2);
topLayout->addWidget(m_matchesFoundLabel);
topWidget->setMinimumHeight(m_cancelButton->sizeHint().height()
+ topLayout->contentsMargins().top() + topLayout->contentsMargins().bottom()
+ topWidget->lineWidth());
setShowReplaceUI(false);