2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-06-17 00:01:27 +10:00
|
|
|
** contact the sales department at http://www.qtsoftware.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "findtoolbar.h"
|
|
|
|
|
#include "findplugin.h"
|
|
|
|
|
#include "textfindconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-01-21 18:12:38 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2009-01-14 12:39:59 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2009-01-14 13:17:53 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QSettings>
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
#include <QtGui/QCompleter>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtGui/QKeyEvent>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtGui/QToolButton>
|
2009-07-14 18:01:25 +02:00
|
|
|
#include <QtGui/QPainter>
|
|
|
|
|
#include <QtGui/QPixmapCache>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QStringList)
|
|
|
|
|
Q_DECLARE_METATYPE(Find::IFindFilter*)
|
|
|
|
|
|
|
|
|
|
using namespace Find;
|
|
|
|
|
using namespace Find::Internal;
|
|
|
|
|
|
|
|
|
|
FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind)
|
|
|
|
|
: m_plugin(plugin),
|
|
|
|
|
m_currentDocumentFind(currentDocumentFind),
|
|
|
|
|
m_findCompleter(new QCompleter(this)),
|
|
|
|
|
m_replaceCompleter(new QCompleter(this)),
|
|
|
|
|
m_enterFindStringAction(0),
|
|
|
|
|
m_findNextAction(0),
|
|
|
|
|
m_findPreviousAction(0),
|
|
|
|
|
m_replaceNextAction(0),
|
2009-06-02 16:49:29 +02:00
|
|
|
m_casesensitiveIcon(":/find/images/casesensitively.png"),
|
|
|
|
|
m_regexpIcon(":/find/images/regexp.png"),
|
|
|
|
|
m_wholewordsIcon(":/find/images/wholewords.png")
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
//setup ui
|
2009-07-14 18:01:25 +02:00
|
|
|
m_ui.setupUi(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
setFocusProxy(m_ui.findEdit);
|
2009-07-21 15:55:46 +02:00
|
|
|
setProperty("topBorder", true);
|
2009-07-15 16:23:07 +02:00
|
|
|
setSingleRow(false);
|
2009-02-23 15:29:39 +01:00
|
|
|
m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
m_ui.replaceEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_ui.findEdit, SIGNAL(editingFinished()), this, SLOT(invokeResetIncrementalSearch()));
|
|
|
|
|
|
2009-07-14 18:01:25 +02:00
|
|
|
m_ui.close->setIcon(QIcon(":/core/images/closebutton.png"));
|
|
|
|
|
connect(m_ui.close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_findCompleter->setModel(m_plugin->findCompletionModel());
|
|
|
|
|
m_replaceCompleter->setModel(m_plugin->replaceCompletionModel());
|
|
|
|
|
m_ui.findEdit->setCompleter(m_findCompleter);
|
|
|
|
|
m_findCompleter->popup()->installEventFilter(this);
|
|
|
|
|
m_ui.replaceEdit->setCompleter(m_replaceCompleter);
|
|
|
|
|
|
|
|
|
|
m_ui.findEdit->setSide(qApp->layoutDirection() == Qt::LeftToRight ? Core::Utils::FancyLineEdit::Right : Core::Utils::FancyLineEdit::Left);
|
|
|
|
|
QMenu *lineEditMenu = new QMenu(m_ui.findEdit);
|
|
|
|
|
m_ui.findEdit->setMenu(lineEditMenu);
|
|
|
|
|
|
|
|
|
|
m_ui.findEdit->installEventFilter(this);
|
|
|
|
|
m_ui.replaceEdit->installEventFilter(this);
|
2009-07-14 18:01:25 +02:00
|
|
|
this->installEventFilter(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
|
|
|
|
|
connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()));
|
|
|
|
|
connect(m_ui.replaceEdit, SIGNAL(returnPressed()), this, SLOT(invokeReplaceEnter()));
|
|
|
|
|
|
|
|
|
|
QAction *shiftEnterAction = new QAction(m_ui.findEdit);
|
|
|
|
|
shiftEnterAction->setShortcut(QKeySequence("Shift+Enter"));
|
|
|
|
|
shiftEnterAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftEnterAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
|
|
|
|
m_ui.findEdit->addAction(shiftEnterAction);
|
|
|
|
|
QAction *shiftReturnAction = new QAction(m_ui.findEdit);
|
|
|
|
|
shiftReturnAction->setShortcut(QKeySequence("Shift+Return"));
|
|
|
|
|
shiftReturnAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftReturnAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
|
|
|
|
m_ui.findEdit->addAction(shiftReturnAction);
|
|
|
|
|
|
|
|
|
|
QAction *shiftEnterReplaceAction = new QAction(m_ui.replaceEdit);
|
|
|
|
|
shiftEnterReplaceAction->setShortcut(QKeySequence("Shift+Enter"));
|
|
|
|
|
shiftEnterReplaceAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftEnterReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
|
|
|
|
m_ui.replaceEdit->addAction(shiftEnterReplaceAction);
|
|
|
|
|
QAction *shiftReturnReplaceAction = new QAction(m_ui.replaceEdit);
|
|
|
|
|
shiftReturnReplaceAction->setShortcut(QKeySequence("Shift+Return"));
|
|
|
|
|
shiftReturnReplaceAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftReturnReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
|
|
|
|
m_ui.replaceEdit->addAction(shiftReturnReplaceAction);
|
|
|
|
|
|
|
|
|
|
// need to make sure QStringList is registered as metatype
|
|
|
|
|
QMetaTypeId<QStringList>::qt_metatype_id();
|
|
|
|
|
|
|
|
|
|
//register actions
|
|
|
|
|
QList<int> globalcontext;
|
|
|
|
|
globalcontext << Core::Constants::C_GLOBAL_ID;
|
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ActionManager *am = Core::ICore::instance()->actionManager();
|
2009-01-14 12:39:59 +01:00
|
|
|
Core::ActionContainer *mfind = am->actionContainer(Constants::M_FIND);
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_findInDocumentAction = new QAction(tr("Current Document"), this);
|
|
|
|
|
cmd = am->registerAction(m_findInDocumentAction, Constants::FIND_IN_DOCUMENT, globalcontext);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence::Find);
|
2009-03-26 16:13:01 +01:00
|
|
|
mfind->addAction(cmd, Constants::G_FIND_CURRENTDOCUMENT);
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_findInDocumentAction, SIGNAL(triggered()), this, SLOT(openFind()));
|
|
|
|
|
|
|
|
|
|
if (QApplication::clipboard()->supportsFindBuffer()) {
|
|
|
|
|
m_enterFindStringAction = new QAction(tr("Enter Find String"), this);
|
2009-04-24 14:01:11 +02:00
|
|
|
cmd = am->registerAction(m_enterFindStringAction, QLatin1String("Find.EnterFindString"), globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_enterFindStringAction, SIGNAL(triggered()), this, SLOT(putSelectionToFindClipboard()));
|
|
|
|
|
connect(QApplication::clipboard(), SIGNAL(findBufferChanged()), this, SLOT(updateFromFindClipboard()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_findNextAction = new QAction(tr("Find Next"), this);
|
|
|
|
|
cmd = am->registerAction(m_findNextAction, Constants::FIND_NEXT, globalcontext);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence::FindNext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_findNextAction, SIGNAL(triggered()), this, SLOT(invokeFindNext()));
|
|
|
|
|
m_ui.findNextButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
m_findPreviousAction = new QAction(tr("Find Previous"), this);
|
|
|
|
|
cmd = am->registerAction(m_findPreviousAction, Constants::FIND_PREVIOUS, globalcontext);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence::FindPrevious);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
|
|
|
|
m_ui.findPreviousButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
m_replaceNextAction = new QAction(tr("Replace && Find Next"), this);
|
|
|
|
|
cmd = am->registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+=")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_replaceNextAction, SIGNAL(triggered()), this, SLOT(invokeReplaceNext()));
|
|
|
|
|
m_ui.replaceNextButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
m_replacePreviousAction = new QAction(tr("Replace && Find Previous"), this);
|
|
|
|
|
cmd = am->registerAction(m_replacePreviousAction, Constants::REPLACE_PREVIOUS, globalcontext);
|
|
|
|
|
// shortcut removed, clashes with Ctrl++ on many keyboard layouts
|
|
|
|
|
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+=")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
|
|
|
|
m_ui.replacePreviousButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
m_replaceAllAction = new QAction(tr("Replace All"), this);
|
|
|
|
|
cmd = am->registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_replaceAllAction, SIGNAL(triggered()), this, SLOT(invokeReplaceAll()));
|
|
|
|
|
m_ui.replaceAllButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
m_caseSensitiveAction = new QAction(tr("Case Sensitive"), this);
|
|
|
|
|
m_caseSensitiveAction->setIcon(QIcon(":/find/images/casesensitively.png"));
|
|
|
|
|
m_caseSensitiveAction->setCheckable(true);
|
|
|
|
|
m_caseSensitiveAction->setChecked(false);
|
|
|
|
|
cmd = am->registerAction(m_caseSensitiveAction, Constants::CASE_SENSITIVE, globalcontext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
2009-05-29 16:12:19 +02:00
|
|
|
connect(m_caseSensitiveAction, SIGNAL(triggered(bool)), this, SLOT(setCaseSensitive(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
lineEditMenu->addAction(m_caseSensitiveAction);
|
|
|
|
|
|
|
|
|
|
m_wholeWordAction = new QAction(tr("Whole Words Only"), this);
|
|
|
|
|
m_wholeWordAction->setIcon(QIcon(":/find/images/wholewords.png"));
|
|
|
|
|
m_wholeWordAction->setCheckable(true);
|
|
|
|
|
m_wholeWordAction->setChecked(false);
|
|
|
|
|
cmd = am->registerAction(m_wholeWordAction, Constants::WHOLE_WORDS, globalcontext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
2009-05-29 16:12:19 +02:00
|
|
|
connect(m_wholeWordAction, SIGNAL(triggered(bool)), this, SLOT(setWholeWord(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
lineEditMenu->addAction(m_wholeWordAction);
|
|
|
|
|
|
2009-05-29 16:52:12 +02:00
|
|
|
m_regularExpressionAction = new QAction(tr("Use Regular Expressions"), this);
|
2009-06-02 16:49:29 +02:00
|
|
|
m_regularExpressionAction->setIcon(QIcon(":/find/images/regexp.png"));
|
2009-05-29 16:52:12 +02:00
|
|
|
m_regularExpressionAction->setCheckable(true);
|
|
|
|
|
m_regularExpressionAction->setChecked(false);
|
|
|
|
|
cmd = am->registerAction(m_regularExpressionAction, Constants::REGULAR_EXPRESSIONS, globalcontext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
|
|
|
|
connect(m_regularExpressionAction, SIGNAL(triggered(bool)), this, SLOT(setRegularExpressions(bool)));
|
|
|
|
|
lineEditMenu->addAction(m_regularExpressionAction);
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
connect(m_currentDocumentFind, SIGNAL(candidateChanged()), this, SLOT(adaptToCandidate()));
|
|
|
|
|
connect(m_currentDocumentFind, SIGNAL(changed()), this, SLOT(updateToolBar()));
|
|
|
|
|
updateToolBar();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FindToolBar::~FindToolBar()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
|
|
|
|
|
&& event->type() == QEvent::KeyPress) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifdef Q_WS_MAC
|
2008-12-02 12:01:29 +01:00
|
|
|
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::MetaModifier)) {
|
|
|
|
|
#else
|
|
|
|
|
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::ControlModifier)) {
|
|
|
|
|
#endif
|
|
|
|
|
QString completedText = m_currentDocumentFind->completedFindString();
|
|
|
|
|
if (!completedText.isEmpty()) {
|
|
|
|
|
setFindText(completedText);
|
|
|
|
|
ke->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-14 18:01:25 +02:00
|
|
|
} else if (obj == this && event->type() == QEvent::ShortcutOverride) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
|
if (ke->key() == Qt::Key_Escape && !ke->modifiers()
|
|
|
|
|
&& !m_findCompleter->popup()->isVisible()
|
|
|
|
|
&& !m_replaceCompleter->popup()->isVisible()) {
|
|
|
|
|
if (setFocusToCurrentFindSupport()) {
|
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-06-03 20:45:49 +02:00
|
|
|
#ifdef Q_WS_MAC
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::MetaModifier)) {
|
|
|
|
|
#else
|
|
|
|
|
} else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::ControlModifier)) {
|
|
|
|
|
#endif
|
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-07-14 18:01:25 +02:00
|
|
|
} else if (obj == this && event->type() == QEvent::Hide) {
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeClearResults();
|
|
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
m_currentDocumentFind->clearFindScope();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-15 12:38:45 +02:00
|
|
|
return Core::Utils::StyledBar::eventFilter(obj, event);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
|
|
|
|
|
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()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
bool enabled = m_currentDocumentFind->isEnabled();
|
|
|
|
|
bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace();
|
|
|
|
|
m_findNextAction->setEnabled(enabled);
|
|
|
|
|
m_findPreviousAction->setEnabled(enabled);
|
2009-07-14 18:01:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_replaceNextAction->setEnabled(replaceEnabled);
|
|
|
|
|
m_replacePreviousAction->setEnabled(replaceEnabled);
|
|
|
|
|
m_replaceAllAction->setEnabled(replaceEnabled);
|
2009-07-14 18:01:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_caseSensitiveAction->setEnabled(enabled);
|
|
|
|
|
m_wholeWordAction->setEnabled(enabled);
|
2009-05-29 16:52:12 +02:00
|
|
|
m_regularExpressionAction->setEnabled(enabled);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (QApplication::clipboard()->supportsFindBuffer())
|
|
|
|
|
m_enterFindStringAction->setEnabled(enabled);
|
|
|
|
|
bool replaceFocus = m_ui.replaceEdit->hasFocus();
|
|
|
|
|
m_ui.findEdit->setEnabled(enabled);
|
|
|
|
|
m_ui.findLabel->setEnabled(enabled);
|
2009-07-14 18:01:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.replaceEdit->setEnabled(replaceEnabled);
|
|
|
|
|
m_ui.replaceLabel->setEnabled(replaceEnabled);
|
2009-07-14 18:01:25 +02:00
|
|
|
m_ui.replaceEdit->setVisible(replaceEnabled);
|
|
|
|
|
m_ui.replaceLabel->setVisible(replaceEnabled);
|
|
|
|
|
m_ui.replacePreviousButton->setVisible(replaceEnabled);
|
|
|
|
|
m_ui.replaceNextButton->setVisible(replaceEnabled);
|
|
|
|
|
m_ui.replaceAllButton->setVisible(replaceEnabled);
|
|
|
|
|
layout()->invalidate();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!replaceEnabled && enabled && replaceFocus)
|
|
|
|
|
m_ui.findEdit->setFocus();
|
2009-07-13 14:48:45 +02:00
|
|
|
updateIcons();
|
|
|
|
|
updateFlagMenus();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindEnter()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
invokeFindNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplaceEnter()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
|
|
|
|
|
invokeReplaceNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeClearResults()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
m_currentDocumentFind->clearResults();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindNext()
|
|
|
|
|
{
|
2009-05-29 16:12:19 +02:00
|
|
|
setFindFlag(IFindSupport::FindBackward, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeFindStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindPrevious()
|
|
|
|
|
{
|
2009-05-29 16:12:19 +02:00
|
|
|
setFindFlag(IFindSupport::FindBackward, true);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeFindStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindToolBar::getFindText()
|
|
|
|
|
{
|
|
|
|
|
return m_ui.findEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindToolBar::getReplaceText()
|
|
|
|
|
{
|
|
|
|
|
return m_ui.replaceEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setFindText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
disconnect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
|
2009-06-09 16:47:11 +02:00
|
|
|
if (hasFindFlag(IFindSupport::FindRegularExpression))
|
|
|
|
|
m_ui.findEdit->setText(QRegExp::escape(text));
|
|
|
|
|
else
|
|
|
|
|
m_ui.findEdit->setText(text);
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::selectFindText()
|
|
|
|
|
{
|
|
|
|
|
m_ui.findEdit->selectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindStep()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
m_plugin->updateFindCompletion(getFindText());
|
2009-07-13 14:48:45 +02:00
|
|
|
m_currentDocumentFind->findStep(getFindText(), effectiveFindFlags());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindIncremental()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
QString text = getFindText();
|
2009-07-13 14:48:45 +02:00
|
|
|
m_currentDocumentFind->findIncremental(text, effectiveFindFlags());
|
2008-12-02 12:01:29 +01:00
|
|
|
if (text.isEmpty())
|
|
|
|
|
m_currentDocumentFind->clearResults();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplaceNext()
|
|
|
|
|
{
|
2009-05-29 16:12:19 +02:00
|
|
|
setFindFlag(IFindSupport::FindBackward, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeReplaceStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplacePrevious()
|
|
|
|
|
{
|
2009-05-29 16:12:19 +02:00
|
|
|
setFindFlag(IFindSupport::FindBackward, true);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeReplaceStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplaceStep()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
|
|
|
|
|
m_plugin->updateFindCompletion(getFindText());
|
|
|
|
|
m_plugin->updateReplaceCompletion(getReplaceText());
|
2009-07-13 14:48:45 +02:00
|
|
|
m_currentDocumentFind->replaceStep(getFindText(), getReplaceText(), effectiveFindFlags());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplaceAll()
|
|
|
|
|
{
|
|
|
|
|
m_plugin->updateFindCompletion(getFindText());
|
|
|
|
|
m_plugin->updateReplaceCompletion(getReplaceText());
|
|
|
|
|
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
|
2009-07-13 14:48:45 +02:00
|
|
|
m_currentDocumentFind->replaceAll(getFindText(), getReplaceText(), effectiveFindFlags());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeResetIncrementalSearch()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentDocumentFind->isEnabled())
|
|
|
|
|
m_currentDocumentFind->resetIncrementalSearch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FindToolBar::putSelectionToFindClipboard()
|
|
|
|
|
{
|
|
|
|
|
const QString text = m_currentDocumentFind->currentFindString();
|
|
|
|
|
QApplication::clipboard()->setText(text, QClipboard::FindBuffer);
|
|
|
|
|
setFindText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FindToolBar::updateFromFindClipboard()
|
|
|
|
|
{
|
|
|
|
|
if (QApplication::clipboard()->supportsFindBuffer()) {
|
|
|
|
|
const bool blocks = m_ui.findEdit->blockSignals(true);
|
|
|
|
|
setFindText(QApplication::clipboard()->text(QClipboard::FindBuffer));
|
|
|
|
|
m_ui.findEdit->blockSignals(blocks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::findFlagsChanged()
|
|
|
|
|
{
|
|
|
|
|
updateIcons();
|
|
|
|
|
updateFlagMenus();
|
|
|
|
|
invokeClearResults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::updateIcons()
|
|
|
|
|
{
|
2009-07-13 14:48:45 +02:00
|
|
|
IFindSupport::FindFlags effectiveFlags = effectiveFindFlags();
|
|
|
|
|
bool casesensitive = effectiveFlags & IFindSupport::FindCaseSensitively;
|
|
|
|
|
bool wholewords = effectiveFlags & IFindSupport::FindWholeWords;
|
|
|
|
|
bool regexp = effectiveFlags & IFindSupport::FindRegularExpression;
|
2009-06-02 16:49:29 +02:00
|
|
|
QPixmap pixmap(17, 17);
|
|
|
|
|
QPainter painter(&pixmap);
|
|
|
|
|
painter.eraseRect(0, 0, 17, 17);
|
|
|
|
|
int x = 16;
|
|
|
|
|
|
|
|
|
|
if (casesensitive) {
|
|
|
|
|
painter.drawPixmap(x-10, 0, m_casesensitiveIcon);
|
|
|
|
|
x -= 6;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-06-02 16:49:29 +02:00
|
|
|
if (wholewords) {
|
|
|
|
|
painter.drawPixmap(x-10, 0, m_wholewordsIcon);
|
|
|
|
|
x -= 6;
|
|
|
|
|
}
|
|
|
|
|
if (regexp) {
|
|
|
|
|
painter.drawPixmap(x-10, 0, m_regexpIcon);
|
|
|
|
|
}
|
|
|
|
|
if (!casesensitive && !wholewords && !regexp) {
|
|
|
|
|
QPixmap mag(Core::Constants::ICON_MAGNIFIER);
|
|
|
|
|
painter.drawPixmap(0, (pixmap.height() - mag.height()) / 2, mag);
|
|
|
|
|
}
|
|
|
|
|
m_ui.findEdit->setPixmap(pixmap);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-13 14:48:45 +02:00
|
|
|
IFindSupport::FindFlags FindToolBar::effectiveFindFlags()
|
|
|
|
|
{
|
|
|
|
|
IFindSupport::FindFlags supportedFlags;
|
|
|
|
|
if (m_currentDocumentFind->isEnabled())
|
|
|
|
|
supportedFlags = m_currentDocumentFind->supportedFindFlags();
|
|
|
|
|
else
|
|
|
|
|
supportedFlags = (IFindSupport::FindFlags)0xFFFFFF;
|
|
|
|
|
return supportedFlags & m_findFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::updateFlagMenus()
|
|
|
|
|
{
|
2009-05-29 16:17:02 +02:00
|
|
|
bool wholeOnly = ((m_findFlags & IFindSupport::FindWholeWords));
|
|
|
|
|
bool sensitive = ((m_findFlags & IFindSupport::FindCaseSensitively));
|
2009-05-29 16:52:12 +02:00
|
|
|
bool regexp = ((m_findFlags & IFindSupport::FindRegularExpression));
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_wholeWordAction->isChecked() != wholeOnly)
|
|
|
|
|
m_wholeWordAction->setChecked(wholeOnly);
|
|
|
|
|
if (m_caseSensitiveAction->isChecked() != sensitive)
|
|
|
|
|
m_caseSensitiveAction->setChecked(sensitive);
|
2009-05-29 16:52:12 +02:00
|
|
|
if (m_regularExpressionAction->isChecked() != regexp)
|
|
|
|
|
m_regularExpressionAction->setChecked(regexp);
|
2009-07-13 14:48:45 +02:00
|
|
|
IFindSupport::FindFlags supportedFlags;
|
|
|
|
|
if (m_currentDocumentFind->isEnabled())
|
|
|
|
|
supportedFlags = m_currentDocumentFind->supportedFindFlags();
|
|
|
|
|
m_wholeWordAction->setEnabled(supportedFlags & IFindSupport::FindWholeWords);
|
|
|
|
|
m_caseSensitiveAction->setEnabled(supportedFlags & IFindSupport::FindCaseSensitively);
|
|
|
|
|
m_regularExpressionAction->setEnabled(supportedFlags & IFindSupport::FindRegularExpression);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FindToolBar::setFocusToCurrentFindSupport()
|
|
|
|
|
{
|
|
|
|
|
return m_currentDocumentFind->setFocusToCurrentFindSupport();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::hideAndResetFocus()
|
|
|
|
|
{
|
|
|
|
|
m_currentDocumentFind->setFocusToCurrentFindSupport();
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::openFind()
|
|
|
|
|
{
|
2009-07-21 11:10:02 +02:00
|
|
|
if (!m_currentDocumentFind->candidateIsEnabled())
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2009-07-21 11:10:02 +02:00
|
|
|
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();
|
2008-12-02 12:01:29 +01:00
|
|
|
QString text = m_currentDocumentFind->currentFindString();
|
|
|
|
|
if (!text.isEmpty())
|
|
|
|
|
setFindText(text);
|
|
|
|
|
m_currentDocumentFind->defineFindScope();
|
2009-07-13 14:48:45 +02:00
|
|
|
m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags());
|
2008-12-02 12:01:29 +01:00
|
|
|
selectFindText();
|
|
|
|
|
}
|
2008-12-12 11:22:39 +01:00
|
|
|
|
|
|
|
|
bool FindToolBar::focusNextPrevChild(bool next)
|
|
|
|
|
{
|
|
|
|
|
// close tab order change
|
|
|
|
|
if (next && m_ui.replaceAllButton->hasFocus())
|
|
|
|
|
m_ui.findEdit->setFocus(Qt::TabFocusReason);
|
|
|
|
|
else if (!next && m_ui.findEdit->hasFocus())
|
|
|
|
|
m_ui.replaceAllButton->setFocus(Qt::TabFocusReason);
|
|
|
|
|
else
|
2009-07-15 12:38:45 +02:00
|
|
|
return Core::Utils::StyledBar::focusNextPrevChild(next);
|
2008-12-12 11:22:39 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-05-29 16:12:19 +02:00
|
|
|
|
|
|
|
|
void FindToolBar::writeSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->beginGroup("Find");
|
|
|
|
|
settings->beginGroup("FindToolBar");
|
|
|
|
|
settings->setValue("Backward", QVariant((m_findFlags & IFindSupport::FindBackward) != 0));
|
|
|
|
|
settings->setValue("CaseSensitively", QVariant((m_findFlags & IFindSupport::FindCaseSensitively) != 0));
|
|
|
|
|
settings->setValue("WholeWords", QVariant((m_findFlags & IFindSupport::FindWholeWords) != 0));
|
2009-05-29 16:52:12 +02:00
|
|
|
settings->setValue("RegularExpression", QVariant((m_findFlags & IFindSupport::FindRegularExpression) != 0));
|
2009-05-29 16:12:19 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::readSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->beginGroup("Find");
|
|
|
|
|
settings->beginGroup("FindToolBar");
|
|
|
|
|
IFindSupport::FindFlags flags;
|
|
|
|
|
if (settings->value("Backward", false).toBool())
|
|
|
|
|
flags |= IFindSupport::FindBackward;
|
|
|
|
|
if (settings->value("CaseSensitively", false).toBool())
|
|
|
|
|
flags |= IFindSupport::FindCaseSensitively;
|
|
|
|
|
if (settings->value("WholeWords", false).toBool())
|
|
|
|
|
flags |= IFindSupport::FindWholeWords;
|
2009-05-29 16:52:12 +02:00
|
|
|
if (settings->value("RegularExpression", false).toBool())
|
|
|
|
|
flags |= IFindSupport::FindRegularExpression;
|
2009-05-29 16:12:19 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
m_findFlags = flags;
|
|
|
|
|
findFlagsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setFindFlag(IFindSupport::FindFlag flag, bool enabled)
|
|
|
|
|
{
|
|
|
|
|
bool hasFlag = hasFindFlag(flag);
|
|
|
|
|
if ((hasFlag && enabled) || (!hasFlag && !enabled))
|
|
|
|
|
return;
|
|
|
|
|
if (enabled)
|
|
|
|
|
m_findFlags |= flag;
|
|
|
|
|
else
|
|
|
|
|
m_findFlags &= ~flag;
|
|
|
|
|
if (flag != IFindSupport::FindBackward)
|
|
|
|
|
findFlagsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FindToolBar::hasFindFlag(IFindSupport::FindFlag flag)
|
|
|
|
|
{
|
|
|
|
|
return m_findFlags & flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setCaseSensitive(bool sensitive)
|
|
|
|
|
{
|
|
|
|
|
setFindFlag(IFindSupport::FindCaseSensitively, sensitive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setWholeWord(bool wholeOnly)
|
|
|
|
|
{
|
|
|
|
|
setFindFlag(IFindSupport::FindWholeWords, wholeOnly);
|
|
|
|
|
}
|
2009-05-29 16:52:12 +02:00
|
|
|
|
|
|
|
|
void FindToolBar::setRegularExpressions(bool regexp)
|
|
|
|
|
{
|
|
|
|
|
setFindFlag(IFindSupport::FindRegularExpression, regexp);
|
|
|
|
|
}
|