Making the find tool bar be more connected to the searched text.

This commit is contained in:
con
2009-07-21 11:10:02 +02:00
parent e1362eab38
commit 091f372723
14 changed files with 124 additions and 55 deletions

View File

@@ -32,7 +32,6 @@
#include "textfindconstants.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
@@ -75,7 +74,7 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
//setup ui
m_ui.setupUi(this);
setFocusProxy(m_ui.findEdit);
setProperty("topBorder", true);
// setProperty("topBorder", true);
setSingleRow(false);
m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
m_ui.replaceEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
@@ -213,8 +212,9 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
connect(m_regularExpressionAction, SIGNAL(triggered(bool)), this, SLOT(setRegularExpressions(bool)));
lineEditMenu->addAction(m_regularExpressionAction);
connect(m_currentDocumentFind, SIGNAL(changed()), this, SLOT(updateActions()));
updateActions();
connect(m_currentDocumentFind, SIGNAL(candidateChanged()), this, SLOT(adaptToCandidate()));
connect(m_currentDocumentFind, SIGNAL(changed()), this, SLOT(updateToolBar()));
updateToolBar();
}
FindToolBar::~FindToolBar()
@@ -264,11 +264,31 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
return Core::Utils::StyledBar::eventFilter(obj, event);
}
void FindToolBar::updateActions()
void FindToolBar::removeFromParent()
{
setVisible(false);
setParent(0);
Core::FindToolBarPlaceHolder::setCurrent(0);
}
void FindToolBar::adaptToCandidate()
{
updateFindAction();
if (findToolBarPlaceHolder() == Core::FindToolBarPlaceHolder::getCurrent()) {
m_currentDocumentFind->acceptCandidate();
}
}
void FindToolBar::updateFindAction()
{
m_findInDocumentAction->setEnabled(m_currentDocumentFind->candidateIsEnabled());
}
void FindToolBar::updateToolBar()
{
bool enabled = m_currentDocumentFind->isEnabled();
bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace();
m_findInDocumentAction->setEnabled(enabled);
m_findNextAction->setEnabled(enabled);
m_findPreviousAction->setEnabled(enabled);
@@ -507,19 +527,38 @@ void FindToolBar::hideAndResetFocus()
hide();
}
Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const
{
QList<Core::FindToolBarPlaceHolder*> placeholders = ExtensionSystem::PluginManager::instance()
->getObjects<Core::FindToolBarPlaceHolder>();
QWidget *candidate = QApplication::focusWidget();
while (candidate) {
foreach (Core::FindToolBarPlaceHolder *ph, placeholders) {
if (ph->widget() == candidate)
return ph;
}
candidate = candidate->parentWidget();
}
return 0;
}
void FindToolBar::openFind()
{
if (!m_currentDocumentFind->isEnabled())
if (!m_currentDocumentFind->candidateIsEnabled())
return;
Core::FindToolBarPlaceHolder *holder = Core::FindToolBarPlaceHolder::getCurrent();
QLayout *findContainerLayout = holder ? holder->layout() : 0;
if (findContainerLayout) {
findContainerLayout->addWidget(this);
holder->setVisible(true);
setVisible(true);
setFocus();
}
Core::FindToolBarPlaceHolder *holder = findToolBarPlaceHolder();
if (!holder)
return;
Core::FindToolBarPlaceHolder *previousHolder = Core::FindToolBarPlaceHolder::getCurrent();
if (previousHolder)
disconnect(previousHolder, SIGNAL(destroyed(QObject*)), this, SLOT(removeFromParent()));
Core::FindToolBarPlaceHolder::setCurrent(holder);
connect(holder, SIGNAL(destroyed(QObject*)), this, SLOT(removeFromParent()));
m_currentDocumentFind->acceptCandidate();
holder->layout()->addWidget(this);
holder->setVisible(true);
setVisible(true);
setFocus();
QString text = m_currentDocumentFind->currentFindString();
if (!text.isEmpty())
setFindText(text);
@@ -528,7 +567,6 @@ void FindToolBar::openFind()
selectFindText();
}
bool FindToolBar::focusNextPrevChild(bool next)
{
// close tab order change