2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "findtoolbar.h"
|
2011-09-07 20:28:04 +02:00
|
|
|
#include "ifindfilter.h"
|
2014-01-13 16:17:34 +01:00
|
|
|
#include "findplugin.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/coreplugin.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>
|
2010-03-24 10:43:01 +01:00
|
|
|
#include <coreplugin/findplaceholder.h>
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2010-03-24 10:43:01 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2014-02-25 18:38:35 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2014-07-15 15:25:32 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2014-02-25 18:38:35 +01:00
|
|
|
#include <QCheckBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QCompleter>
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QStringListModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QStringList)
|
2014-01-13 16:17:34 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::IFindFilter*)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-06-11 16:30:48 +02:00
|
|
|
static const int MINIMUM_WIDTH_FOR_COMPLEX_LAYOUT = 150;
|
|
|
|
|
static const int FINDBUTTON_SPACER_WIDTH = 20;
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
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),
|
2010-07-14 14:45:02 +02:00
|
|
|
m_replaceAction(0),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_replaceNextAction(0),
|
2010-07-14 14:45:02 +02:00
|
|
|
m_replacePreviousAction(0),
|
2010-01-21 17:23:31 +01:00
|
|
|
m_findIncrementalTimer(this), m_findStepTimer(this),
|
2010-03-10 11:44:09 +01:00
|
|
|
m_useFakeVim(false),
|
|
|
|
|
m_eventFiltersInstalled(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
//setup ui
|
2009-07-14 18:01:25 +02:00
|
|
|
m_ui.setupUi(this);
|
2011-06-23 14:35:45 +02:00
|
|
|
// compensate for a vertically expanding spacer below the label
|
|
|
|
|
m_ui.replaceLabel->setMinimumHeight(m_ui.replaceEdit->sizeHint().height());
|
2014-06-11 16:30:48 +02:00
|
|
|
m_ui.mainLayout->setColumnStretch(1, 10);
|
|
|
|
|
|
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()));
|
|
|
|
|
|
2014-08-11 17:31:27 +02:00
|
|
|
setLightColoredIcon(false);
|
2009-07-14 18:01:25 +02:00
|
|
|
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());
|
2012-08-23 14:10:12 +02:00
|
|
|
m_ui.findEdit->setSpecialCompleter(m_findCompleter);
|
|
|
|
|
m_ui.replaceEdit->setSpecialCompleter(m_replaceCompleter);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-07-01 09:32:47 +02:00
|
|
|
m_ui.findEdit->setButtonVisible(Utils::FancyLineEdit::Left, true);
|
2014-02-13 13:54:39 +01:00
|
|
|
m_ui.findEdit->setFiltering(true);
|
2014-02-20 08:56:25 +02:00
|
|
|
m_ui.findEdit->setPlaceholderText(QString());
|
2014-02-25 18:38:35 +01:00
|
|
|
m_ui.findEdit->button(Utils::FancyLineEdit::Left)->setFocusPolicy(Qt::TabFocus);
|
2010-07-01 09:32:47 +02:00
|
|
|
m_ui.replaceEdit->setPlaceholderText(QString());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental()));
|
2014-02-25 18:38:35 +01:00
|
|
|
connect(m_ui.findEdit, SIGNAL(leftButtonClicked()),
|
|
|
|
|
this, SLOT(findEditButtonClicked()));
|
2012-12-11 22:22:49 +02:00
|
|
|
|
|
|
|
|
// invoke{Find,Replace}Helper change the completion model. QueuedConnection is used to perform these
|
|
|
|
|
// changes only after the completer's activated() signal is handled (QTCREATORBUG-8408)
|
|
|
|
|
connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()), Qt::QueuedConnection);
|
|
|
|
|
connect(m_ui.replaceEdit, SIGNAL(returnPressed()), this, SLOT(invokeReplaceEnter()), Qt::QueuedConnection);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QAction *shiftEnterAction = new QAction(m_ui.findEdit);
|
2012-01-20 15:33:18 +01:00
|
|
|
shiftEnterAction->setShortcut(QKeySequence(tr("Shift+Enter")));
|
2008-12-02 12:01:29 +01:00
|
|
|
shiftEnterAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftEnterAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
|
|
|
|
m_ui.findEdit->addAction(shiftEnterAction);
|
|
|
|
|
QAction *shiftReturnAction = new QAction(m_ui.findEdit);
|
2012-01-20 15:33:18 +01:00
|
|
|
shiftReturnAction->setShortcut(QKeySequence(tr("Shift+Return")));
|
2008-12-02 12:01:29 +01:00
|
|
|
shiftReturnAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftReturnAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
|
|
|
|
m_ui.findEdit->addAction(shiftReturnAction);
|
|
|
|
|
|
|
|
|
|
QAction *shiftEnterReplaceAction = new QAction(m_ui.replaceEdit);
|
2012-01-20 15:33:18 +01:00
|
|
|
shiftEnterReplaceAction->setShortcut(QKeySequence(tr("Shift+Enter")));
|
2008-12-02 12:01:29 +01:00
|
|
|
shiftEnterReplaceAction->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(shiftEnterReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
|
|
|
|
m_ui.replaceEdit->addAction(shiftEnterReplaceAction);
|
|
|
|
|
QAction *shiftReturnReplaceAction = new QAction(m_ui.replaceEdit);
|
2012-01-20 15:33:18 +01:00
|
|
|
shiftReturnReplaceAction->setShortcut(QKeySequence(tr("Shift+Return")));
|
2008-12-02 12:01:29 +01:00
|
|
|
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();
|
|
|
|
|
|
2010-06-25 12:56:16 +02:00
|
|
|
// register actions
|
2010-06-28 14:30:03 +02:00
|
|
|
Core::Context globalcontext(Core::Constants::C_GLOBAL);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionContainer *mfind = Core::ActionManager::actionContainer(Constants::M_FIND);
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
m_ui.advancedButton->setDefaultAction(Core::ActionManager::command(Constants::ADVANCED_FIND)->action());
|
2010-07-14 15:18:56 +02:00
|
|
|
|
2014-07-17 15:06:06 +02:00
|
|
|
m_goToCurrentFindAction = new QAction(this);
|
2014-05-19 18:28:32 +03:00
|
|
|
Core::ActionManager::registerAction(m_goToCurrentFindAction, Constants::S_RETURNTOEDITOR,
|
|
|
|
|
Context(Constants::C_FINDTOOLBAR));
|
2014-03-03 11:55:50 +01:00
|
|
|
connect(m_goToCurrentFindAction, SIGNAL(triggered()), this, SLOT(setFocusToCurrentFindSupport()));
|
|
|
|
|
|
2010-03-19 15:25:20 +01:00
|
|
|
QIcon icon = QIcon::fromTheme(QLatin1String("edit-find-replace"));
|
|
|
|
|
m_findInDocumentAction = new QAction(icon, tr("Find/Replace"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_findInDocumentAction, Constants::FIND_IN_DOCUMENT, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
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()));
|
|
|
|
|
|
2014-11-03 17:09:41 +01:00
|
|
|
// Pressing the find shortcut while focus is in the tool bar should not change the search text,
|
|
|
|
|
// so register a different find action for the tool bar
|
|
|
|
|
auto localFindAction = new QAction(this);
|
|
|
|
|
cmd = ActionManager::registerAction(localFindAction, Constants::FIND_IN_DOCUMENT,
|
|
|
|
|
Context(Constants::C_FINDTOOLBAR));
|
|
|
|
|
connect(localFindAction, &QAction::triggered, this, [this]() {
|
|
|
|
|
openFindToolBar(OpenFlags(UpdateAll & ~UpdateFindText));
|
|
|
|
|
});
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (QApplication::clipboard()->supportsFindBuffer()) {
|
|
|
|
|
m_enterFindStringAction = new QAction(tr("Enter Find String"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_enterFindStringAction, "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);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_findNextAction, Constants::FIND_NEXT, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence::FindNext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_findNextAction, SIGNAL(triggered()), this, SLOT(invokeGlobalFindNext()));
|
|
|
|
|
auto localFindNextAction = new QAction(m_findNextAction->text(), this);
|
|
|
|
|
cmd->augmentActionWithShortcutToolTip(localFindNextAction);
|
|
|
|
|
connect(localFindNextAction, &QAction::triggered, this, &FindToolBar::invokeFindNext);
|
|
|
|
|
m_ui.findNextButton->setDefaultAction(localFindNextAction);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_findPreviousAction = new QAction(tr("Find Previous"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_findPreviousAction, Constants::FIND_PREVIOUS, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence::FindPrevious);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeGlobalFindPrevious()));
|
|
|
|
|
auto localFindPreviousAction = new QAction(m_findPreviousAction->text(), this);
|
|
|
|
|
cmd->augmentActionWithShortcutToolTip(localFindPreviousAction);
|
|
|
|
|
connect(localFindPreviousAction, &QAction::triggered, this, &FindToolBar::invokeFindPrevious);
|
|
|
|
|
m_ui.findPreviousButton->setDefaultAction(localFindPreviousAction);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-24 17:51:39 +02:00
|
|
|
m_findNextSelectedAction = new QAction(tr("Find Next (Selected)"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_findNextSelectedAction, Constants::FIND_NEXT_SELECTED, globalcontext);
|
2010-06-24 17:51:39 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F3")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_findNextSelectedAction, SIGNAL(triggered()), this, SLOT(findNextSelected()));
|
|
|
|
|
|
|
|
|
|
m_findPreviousSelectedAction = new QAction(tr("Find Previous (Selected)"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_findPreviousSelectedAction, Constants::FIND_PREV_SELECTED, globalcontext);
|
2010-06-24 17:51:39 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F3")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
|
|
|
|
connect(m_findPreviousSelectedAction, SIGNAL(triggered()), this, SLOT(findPreviousSelected()));
|
|
|
|
|
|
2010-07-14 14:45:02 +02:00
|
|
|
m_replaceAction = new QAction(tr("Replace"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_replaceAction, Constants::REPLACE, globalcontext);
|
2010-07-14 14:45:02 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence());
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_replaceAction, SIGNAL(triggered()), this, SLOT(invokeGlobalReplace()));
|
|
|
|
|
auto localReplaceAction = new QAction(m_replaceAction->text(), this);
|
|
|
|
|
cmd->augmentActionWithShortcutToolTip(localReplaceAction);
|
|
|
|
|
connect(localReplaceAction, &QAction::triggered, this, &FindToolBar::invokeReplace);
|
|
|
|
|
m_ui.replaceButton->setDefaultAction(localReplaceAction);
|
2010-07-14 14:45:02 +02:00
|
|
|
|
|
|
|
|
m_replaceNextAction = new QAction(tr("Replace && Find"), this);
|
|
|
|
|
m_replaceNextAction->setIconText(tr("Replace && Find")); // work around bug in Qt that kills ampersands in tool button
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+=")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_replaceNextAction, SIGNAL(triggered()), this, SLOT(invokeGlobalReplaceNext()));
|
|
|
|
|
auto localReplaceNextAction = new QAction(m_replaceNextAction->text(), this);
|
|
|
|
|
cmd->augmentActionWithShortcutToolTip(localReplaceNextAction);
|
|
|
|
|
connect(localReplaceNextAction, &QAction::triggered, this, &FindToolBar::invokeReplaceNext);
|
|
|
|
|
m_ui.replaceNextButton->setDefaultAction(localReplaceNextAction);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_replacePreviousAction = new QAction(tr("Replace && Find Previous"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_replacePreviousAction, Constants::REPLACE_PREVIOUS, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
// shortcut removed, clashes with Ctrl++ on many keyboard layouts
|
|
|
|
|
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+=")));
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeGlobalReplacePrevious()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_replaceAllAction = new QAction(tr("Replace All"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_replaceAllAction, SIGNAL(triggered()), this, SLOT(invokeGlobalReplaceAll()));
|
|
|
|
|
auto localReplaceAllAction = new QAction(m_replaceAllAction->text(), this);
|
|
|
|
|
cmd->augmentActionWithShortcutToolTip(localReplaceAllAction);
|
|
|
|
|
connect(localReplaceAllAction, &QAction::triggered, this, &FindToolBar::invokeReplaceAll);
|
|
|
|
|
m_ui.replaceAllButton->setDefaultAction(localReplaceAllAction);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_caseSensitiveAction = new QAction(tr("Case Sensitive"), this);
|
2010-07-30 22:16:59 +02:00
|
|
|
m_caseSensitiveAction->setIcon(QIcon(QLatin1String(":/find/images/casesensitively.png")));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_caseSensitiveAction->setCheckable(true);
|
|
|
|
|
m_caseSensitiveAction->setChecked(false);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_caseSensitiveAction, Constants::CASE_SENSITIVE, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
2014-02-25 18:38:35 +01:00
|
|
|
connect(m_caseSensitiveAction, SIGNAL(toggled(bool)), this, SLOT(setCaseSensitive(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_wholeWordAction = new QAction(tr("Whole Words Only"), this);
|
2010-07-30 22:16:59 +02:00
|
|
|
m_wholeWordAction->setIcon(QIcon(QLatin1String(":/find/images/wholewords.png")));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_wholeWordAction->setCheckable(true);
|
|
|
|
|
m_wholeWordAction->setChecked(false);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_wholeWordAction, Constants::WHOLE_WORDS, globalcontext);
|
2008-12-02 12:01:29 +01:00
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
2014-02-25 18:38:35 +01:00
|
|
|
connect(m_wholeWordAction, SIGNAL(toggled(bool)), this, SLOT(setWholeWord(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-29 16:52:12 +02:00
|
|
|
m_regularExpressionAction = new QAction(tr("Use Regular Expressions"), this);
|
2010-07-30 22:16:59 +02:00
|
|
|
m_regularExpressionAction->setIcon(QIcon(QLatin1String(":/find/images/regexp.png")));
|
2009-05-29 16:52:12 +02:00
|
|
|
m_regularExpressionAction->setCheckable(true);
|
|
|
|
|
m_regularExpressionAction->setChecked(false);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_regularExpressionAction, Constants::REGULAR_EXPRESSIONS, globalcontext);
|
2009-05-29 16:52:12 +02:00
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
2014-02-25 18:38:35 +01:00
|
|
|
connect(m_regularExpressionAction, SIGNAL(toggled(bool)), this, SLOT(setRegularExpressions(bool)));
|
2009-05-29 16:52:12 +02:00
|
|
|
|
2012-11-30 16:15:07 +01:00
|
|
|
m_preserveCaseAction = new QAction(tr("Preserve Case when Replacing"), this);
|
|
|
|
|
m_preserveCaseAction->setIcon(QPixmap(QLatin1String(":/find/images/preservecase.png")));
|
|
|
|
|
m_preserveCaseAction->setCheckable(true);
|
|
|
|
|
m_preserveCaseAction->setChecked(false);
|
|
|
|
|
cmd = Core::ActionManager::registerAction(m_preserveCaseAction, Constants::PRESERVE_CASE, globalcontext);
|
|
|
|
|
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
|
2014-02-25 18:38:35 +01:00
|
|
|
connect(m_preserveCaseAction, SIGNAL(toggled(bool)), this, SLOT(setPreserveCase(bool)));
|
2012-11-30 16:15:07 +01:00
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
connect(m_currentDocumentFind, &CurrentDocumentFind::candidateChanged,
|
|
|
|
|
this, &FindToolBar::adaptToCandidate);
|
|
|
|
|
connect(m_currentDocumentFind, &CurrentDocumentFind::changed,
|
|
|
|
|
this, &FindToolBar::updateGlobalActions);
|
|
|
|
|
connect(m_currentDocumentFind, &CurrentDocumentFind::changed,
|
|
|
|
|
this, &FindToolBar::updateToolBar);
|
|
|
|
|
updateGlobalActions();
|
2009-07-21 11:10:02 +02:00
|
|
|
updateToolBar();
|
2009-09-09 17:11:00 +02:00
|
|
|
|
|
|
|
|
m_findIncrementalTimer.setSingleShot(true);
|
|
|
|
|
m_findStepTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_findIncrementalTimer, SIGNAL(timeout()),
|
|
|
|
|
this, SLOT(invokeFindIncremental()));
|
|
|
|
|
connect(&m_findStepTimer, SIGNAL(timeout()), this, SLOT(invokeFindStep()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FindToolBar::~FindToolBar()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 11:44:09 +01:00
|
|
|
void FindToolBar::installEventFilters()
|
|
|
|
|
{
|
|
|
|
|
if (!m_eventFiltersInstalled) {
|
|
|
|
|
m_findCompleter->popup()->installEventFilter(this);
|
|
|
|
|
m_ui.findEdit->installEventFilter(this);
|
|
|
|
|
m_ui.replaceEdit->installEventFilter(this);
|
|
|
|
|
this->installEventFilter(this);
|
|
|
|
|
m_eventFiltersInstalled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
2009-09-18 20:26:20 +02:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
|
if (ke->key() == Qt::Key_Down) {
|
2012-08-26 14:50:00 +03:00
|
|
|
if (obj == m_ui.findEdit) {
|
|
|
|
|
if (m_ui.findEdit->text().isEmpty())
|
|
|
|
|
m_findCompleter->setCompletionPrefix(QString());
|
2009-09-18 20:26:20 +02:00
|
|
|
m_findCompleter->complete();
|
2012-08-26 14:50:00 +03:00
|
|
|
} else if (obj == m_ui.replaceEdit) {
|
|
|
|
|
if (m_ui.replaceEdit->text().isEmpty())
|
|
|
|
|
m_replaceCompleter->setCompletionPrefix(QString());
|
2009-09-18 20:26:20 +02:00
|
|
|
m_replaceCompleter->complete();
|
2012-08-26 14:50:00 +03:00
|
|
|
}
|
2009-09-18 20:26:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
|
|
|
|
|
&& event->type() == QEvent::KeyPress) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
2012-09-07 13:31:29 +02:00
|
|
|
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) {
|
2008-12-02 12:01:29 +01:00
|
|
|
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);
|
2014-03-03 11:55:50 +01:00
|
|
|
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) {
|
2008-12-02 12:01:29 +01:00
|
|
|
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();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_currentDocumentFind->isEnabled())
|
2008-12-02 12:01:29 +01:00
|
|
|
m_currentDocumentFind->clearFindScope();
|
|
|
|
|
}
|
2009-10-05 11:06:05 +02:00
|
|
|
return Utils::StyledBar::eventFilter(obj, event);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
void FindToolBar::adaptToCandidate()
|
|
|
|
|
{
|
2014-11-04 14:58:48 +01:00
|
|
|
updateGlobalActions();
|
2014-07-02 13:59:25 +02:00
|
|
|
if (findToolBarPlaceHolder() == Core::FindToolBarPlaceHolder::getCurrent()) {
|
2009-07-21 11:10:02 +02:00
|
|
|
m_currentDocumentFind->acceptCandidate();
|
2014-07-02 13:59:25 +02:00
|
|
|
if (isVisible())
|
|
|
|
|
m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags());
|
|
|
|
|
}
|
2009-07-21 11:10:02 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::updateGlobalActions()
|
2009-07-21 11:10:02 +02:00
|
|
|
{
|
2014-11-04 14:58:48 +01:00
|
|
|
IFindSupport *candidate = m_currentDocumentFind->candidate();
|
|
|
|
|
bool enabled = (candidate != 0);
|
|
|
|
|
bool replaceEnabled = enabled && candidate->supportsReplace();
|
|
|
|
|
m_findInDocumentAction->setEnabled(enabled || (toolBarHasFocus() && isEnabled()));
|
2010-06-24 17:51:39 +02:00
|
|
|
m_findNextSelectedAction->setEnabled(enabled);
|
|
|
|
|
m_findPreviousSelectedAction->setEnabled(enabled);
|
2014-04-03 18:06:27 +02:00
|
|
|
if (QApplication::clipboard()->supportsFindBuffer())
|
|
|
|
|
m_enterFindStringAction->setEnabled(enabled);
|
2014-11-04 14:58:48 +01:00
|
|
|
m_findNextAction->setEnabled(enabled);
|
|
|
|
|
m_findPreviousAction->setEnabled(enabled);
|
|
|
|
|
m_replaceAction->setEnabled(replaceEnabled);
|
|
|
|
|
m_replaceNextAction->setEnabled(replaceEnabled);
|
|
|
|
|
m_replacePreviousAction->setEnabled(replaceEnabled);
|
|
|
|
|
m_replaceAllAction->setEnabled(replaceEnabled);
|
2009-07-21 11:10:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::updateToolBar()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
bool enabled = m_currentDocumentFind->isEnabled();
|
|
|
|
|
bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace();
|
2014-06-11 16:30:48 +02:00
|
|
|
bool showAllControls = canShowAllControls(replaceEnabled);
|
2014-03-03 11:55:50 +01:00
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
m_ui.findNextButton->setEnabled(enabled);
|
|
|
|
|
m_ui.findPreviousButton->setEnabled(enabled);
|
2009-07-14 18:01:25 +02:00
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
m_ui.replaceButton->setEnabled(replaceEnabled);
|
|
|
|
|
m_ui.replaceNextButton->setEnabled(replaceEnabled);
|
|
|
|
|
m_ui.replaceAllButton->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);
|
2013-09-03 15:42:38 +02:00
|
|
|
m_preserveCaseAction->setEnabled(replaceEnabled && !hasFindFlag(FindRegularExpression));
|
2008-12-02 12:01:29 +01:00
|
|
|
bool replaceFocus = m_ui.replaceEdit->hasFocus();
|
2014-06-11 16:30:48 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.findLabel->setEnabled(enabled);
|
2014-06-11 16:30:48 +02:00
|
|
|
m_ui.findLabel->setVisible(showAllControls);
|
|
|
|
|
m_ui.findEdit->setEnabled(enabled);
|
|
|
|
|
m_ui.findEdit->setPlaceholderText(showAllControls ? QString() : tr("Search for..."));
|
|
|
|
|
m_ui.findPreviousButton->setVisible(showAllControls);
|
|
|
|
|
m_ui.findNextButton->setVisible(showAllControls);
|
|
|
|
|
m_ui.horizontalSpacer->changeSize((showAllControls ? FINDBUTTON_SPACER_WIDTH : 0), 0,
|
|
|
|
|
QSizePolicy::Expanding, QSizePolicy::Ignored);
|
|
|
|
|
m_ui.findButtonLayout->invalidate(); // apply spacer change
|
2009-07-14 18:01:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.replaceLabel->setEnabled(replaceEnabled);
|
2014-06-11 16:30:48 +02:00
|
|
|
m_ui.replaceLabel->setVisible(replaceEnabled && showAllControls);
|
|
|
|
|
m_ui.replaceEdit->setEnabled(replaceEnabled);
|
|
|
|
|
m_ui.replaceEdit->setPlaceholderText(showAllControls ? QString() : tr("Replace with..."));
|
2009-07-14 18:01:25 +02:00
|
|
|
m_ui.replaceEdit->setVisible(replaceEnabled);
|
2014-06-11 16:30:48 +02:00
|
|
|
m_ui.replaceButtonsWidget->setVisible(replaceEnabled && showAllControls);
|
|
|
|
|
m_ui.advancedButton->setVisible(replaceEnabled && showAllControls);
|
|
|
|
|
|
2009-07-14 18:01:25 +02:00
|
|
|
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()) {
|
2010-01-21 17:23:31 +01:00
|
|
|
if (m_useFakeVim)
|
|
|
|
|
setFocusToCurrentFindSupport();
|
|
|
|
|
else
|
|
|
|
|
invokeFindNext();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplaceEnter()
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace())
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeReplaceNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeClearResults()
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_currentDocumentFind->isEnabled())
|
2014-07-02 13:43:31 +02:00
|
|
|
m_currentDocumentFind->clearHighlights();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindNext()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeFindStep();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::invokeGlobalFindNext()
|
|
|
|
|
{
|
|
|
|
|
acceptCandidateAndMoveToolBar();
|
|
|
|
|
invokeFindNext();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::invokeFindPrevious()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, true);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeFindStep();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::invokeGlobalFindPrevious()
|
|
|
|
|
{
|
|
|
|
|
acceptCandidateAndMoveToolBar();
|
|
|
|
|
invokeFindPrevious();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString FindToolBar::getFindText()
|
|
|
|
|
{
|
|
|
|
|
return m_ui.findEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindToolBar::getReplaceText()
|
|
|
|
|
{
|
|
|
|
|
return m_ui.replaceEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setFindText(const QString &text)
|
|
|
|
|
{
|
2012-03-05 22:30:59 +01:00
|
|
|
disconnect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental()));
|
2013-09-03 15:42:38 +02:00
|
|
|
if (hasFindFlag(FindRegularExpression))
|
2009-06-09 16:47:11 +02:00
|
|
|
m_ui.findEdit->setText(QRegExp::escape(text));
|
|
|
|
|
else
|
|
|
|
|
m_ui.findEdit->setText(text);
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::selectFindText()
|
|
|
|
|
{
|
|
|
|
|
m_ui.findEdit->selectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindStep()
|
|
|
|
|
{
|
2009-09-09 17:11:00 +02:00
|
|
|
m_findStepTimer.stop();
|
|
|
|
|
m_findIncrementalTimer.stop();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
m_plugin->updateFindCompletion(getFindText());
|
2009-09-09 17:11:00 +02:00
|
|
|
IFindSupport::Result result =
|
|
|
|
|
m_currentDocumentFind->findStep(getFindText(), effectiveFindFlags());
|
|
|
|
|
if (result == IFindSupport::NotYetFound)
|
|
|
|
|
m_findStepTimer.start(50);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindIncremental()
|
|
|
|
|
{
|
2009-09-09 17:11:00 +02:00
|
|
|
m_findIncrementalTimer.stop();
|
|
|
|
|
m_findStepTimer.stop();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
|
|
|
|
QString text = getFindText();
|
2009-09-09 17:11:00 +02:00
|
|
|
IFindSupport::Result result =
|
|
|
|
|
m_currentDocumentFind->findIncremental(text, effectiveFindFlags());
|
|
|
|
|
if (result == IFindSupport::NotYetFound)
|
|
|
|
|
m_findIncrementalTimer.start(50);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (text.isEmpty())
|
2014-07-02 13:43:31 +02:00
|
|
|
m_currentDocumentFind->clearHighlights();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:45:02 +02:00
|
|
|
void FindToolBar::invokeReplace()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, false);
|
2010-07-14 14:45:02 +02:00
|
|
|
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
|
|
|
|
|
m_plugin->updateFindCompletion(getFindText());
|
|
|
|
|
m_plugin->updateReplaceCompletion(getReplaceText());
|
|
|
|
|
m_currentDocumentFind->replace(getFindText(), getReplaceText(), effectiveFindFlags());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::invokeGlobalReplace()
|
|
|
|
|
{
|
|
|
|
|
acceptCandidateAndMoveToolBar();
|
|
|
|
|
invokeReplace();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::invokeReplaceNext()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeReplaceStep();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::invokeGlobalReplaceNext()
|
|
|
|
|
{
|
|
|
|
|
acceptCandidateAndMoveToolBar();
|
|
|
|
|
invokeReplaceNext();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::invokeReplacePrevious()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, true);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeReplaceStep();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::invokeGlobalReplacePrevious()
|
|
|
|
|
{
|
|
|
|
|
acceptCandidateAndMoveToolBar();
|
|
|
|
|
invokeReplacePrevious();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
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());
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
void FindToolBar::invokeGlobalReplaceAll()
|
|
|
|
|
{
|
|
|
|
|
acceptCandidateAndMoveToolBar();
|
|
|
|
|
invokeReplaceAll();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::invokeResetIncrementalSearch()
|
|
|
|
|
{
|
2009-09-09 17:11:00 +02:00
|
|
|
m_findIncrementalTimer.stop();
|
|
|
|
|
m_findStepTimer.stop();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_currentDocumentFind->isEnabled())
|
|
|
|
|
m_currentDocumentFind->resetIncrementalSearch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FindToolBar::putSelectionToFindClipboard()
|
|
|
|
|
{
|
2014-04-03 18:06:27 +02:00
|
|
|
openFind(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
const QString text = m_currentDocumentFind->currentFindString();
|
|
|
|
|
QApplication::clipboard()->setText(text, QClipboard::FindBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (isVisible())
|
2009-08-25 11:55:33 +02:00
|
|
|
m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-25 18:38:35 +01:00
|
|
|
void FindToolBar::findEditButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
OptionsPopup *popup = new OptionsPopup(m_ui.findEdit);
|
|
|
|
|
popup->show();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::updateIcons()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
FindFlags effectiveFlags = effectiveFindFlags();
|
|
|
|
|
bool casesensitive = effectiveFlags & FindCaseSensitively;
|
|
|
|
|
bool wholewords = effectiveFlags & FindWholeWords;
|
|
|
|
|
bool regexp = effectiveFlags & FindRegularExpression;
|
|
|
|
|
bool preserveCase = effectiveFlags & FindPreserveCase;
|
2012-11-30 16:15:07 +01:00
|
|
|
if (!casesensitive && !wholewords && !regexp && !preserveCase) {
|
2014-07-15 15:25:32 +02:00
|
|
|
m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left,
|
2014-07-24 15:24:58 +02:00
|
|
|
Utils::StyleHelper::dpiSpecificImageFile(QLatin1Literal(Core::Constants::ICON_MAGNIFIER)));
|
2011-09-07 20:28:04 +02:00
|
|
|
} else {
|
|
|
|
|
m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left,
|
|
|
|
|
IFindFilter::pixmapForFindFlags(effectiveFlags));
|
2009-06-02 16:49:29 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-03 15:42:38 +02:00
|
|
|
FindFlags FindToolBar::effectiveFindFlags()
|
2009-07-13 14:48:45 +02:00
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
FindFlags supportedFlags;
|
2012-11-30 16:15:07 +01:00
|
|
|
bool supportsReplace = true;
|
|
|
|
|
if (m_currentDocumentFind->isEnabled()) {
|
2009-07-13 14:48:45 +02:00
|
|
|
supportedFlags = m_currentDocumentFind->supportedFindFlags();
|
2012-11-30 16:15:07 +01:00
|
|
|
supportsReplace = m_currentDocumentFind->supportsReplace();
|
|
|
|
|
} else {
|
2013-09-03 15:42:38 +02:00
|
|
|
supportedFlags = (FindFlags)0xFFFFFF;
|
2012-11-30 16:15:07 +01:00
|
|
|
}
|
2013-09-03 15:42:38 +02:00
|
|
|
if (!supportsReplace || m_findFlags & FindRegularExpression)
|
|
|
|
|
supportedFlags &= ~FindPreserveCase;
|
2009-07-13 14:48:45 +02:00
|
|
|
return supportedFlags & m_findFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FindToolBar::updateFlagMenus()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
bool wholeOnly = ((m_findFlags & FindWholeWords));
|
|
|
|
|
bool sensitive = ((m_findFlags & FindCaseSensitively));
|
|
|
|
|
bool regexp = ((m_findFlags & FindRegularExpression));
|
|
|
|
|
bool preserveCase = ((m_findFlags & FindPreserveCase));
|
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);
|
2012-11-30 16:15:07 +01:00
|
|
|
if (m_preserveCaseAction->isChecked() != preserveCase)
|
|
|
|
|
m_preserveCaseAction->setChecked(preserveCase);
|
2013-09-03 15:42:38 +02:00
|
|
|
FindFlags supportedFlags;
|
2009-07-13 14:48:45 +02:00
|
|
|
if (m_currentDocumentFind->isEnabled())
|
|
|
|
|
supportedFlags = m_currentDocumentFind->supportedFindFlags();
|
2013-09-03 15:42:38 +02:00
|
|
|
m_wholeWordAction->setEnabled(supportedFlags & FindWholeWords);
|
|
|
|
|
m_caseSensitiveAction->setEnabled(supportedFlags & FindCaseSensitively);
|
|
|
|
|
m_regularExpressionAction->setEnabled(supportedFlags & FindRegularExpression);
|
2012-11-30 16:15:07 +01:00
|
|
|
bool replaceEnabled = m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace();
|
2013-09-03 15:42:38 +02:00
|
|
|
m_preserveCaseAction->setEnabled((supportedFlags & FindPreserveCase) && !regexp && replaceEnabled);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 11:23:09 +02:00
|
|
|
void FindToolBar::setFocusToCurrentFindSupport()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-07-23 11:23:09 +02:00
|
|
|
if (!m_currentDocumentFind->setFocusToCurrentFindSupport())
|
|
|
|
|
if (QWidget *w = focusWidget())
|
|
|
|
|
w->clearFocus();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::hideAndResetFocus()
|
|
|
|
|
{
|
|
|
|
|
m_currentDocumentFind->setFocusToCurrentFindSupport();
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const
|
|
|
|
|
{
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<Core::FindToolBarPlaceHolder*> placeholders = ExtensionSystem::PluginManager::getObjects<Core::FindToolBarPlaceHolder>();
|
2009-07-21 11:10:02 +02:00
|
|
|
QWidget *candidate = QApplication::focusWidget();
|
|
|
|
|
while (candidate) {
|
|
|
|
|
foreach (Core::FindToolBarPlaceHolder *ph, placeholders) {
|
2009-07-21 17:48:24 +02:00
|
|
|
if (ph->owner() == candidate)
|
2009-07-21 11:10:02 +02:00
|
|
|
return ph;
|
|
|
|
|
}
|
|
|
|
|
candidate = candidate->parentWidget();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 14:28:06 +02:00
|
|
|
bool FindToolBar::toolBarHasFocus() const
|
|
|
|
|
{
|
|
|
|
|
return qApp->focusWidget() == focusWidget();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 16:30:48 +02:00
|
|
|
bool FindToolBar::canShowAllControls(bool replaceIsVisible) const
|
|
|
|
|
{
|
|
|
|
|
int fullWidth = width();
|
|
|
|
|
int findFixedWidth = m_ui.findLabel->sizeHint().width()
|
|
|
|
|
+ m_ui.findNextButton->sizeHint().width()
|
|
|
|
|
+ m_ui.findPreviousButton->sizeHint().width()
|
|
|
|
|
+ FINDBUTTON_SPACER_WIDTH
|
|
|
|
|
+ m_ui.close->sizeHint().width();
|
|
|
|
|
if (fullWidth - findFixedWidth < MINIMUM_WIDTH_FOR_COMPLEX_LAYOUT)
|
|
|
|
|
return false;
|
|
|
|
|
if (!replaceIsVisible)
|
|
|
|
|
return true;
|
|
|
|
|
int replaceFixedWidth = m_ui.replaceLabel->sizeHint().width()
|
|
|
|
|
+ m_ui.replaceButton->sizeHint().width()
|
|
|
|
|
+ m_ui.replaceNextButton->sizeHint().width()
|
|
|
|
|
+ m_ui.replaceAllButton->sizeHint().width()
|
|
|
|
|
+ m_ui.advancedButton->sizeHint().width();
|
|
|
|
|
return fullWidth - replaceFixedWidth >= MINIMUM_WIDTH_FOR_COMPLEX_LAYOUT;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 14:58:48 +01:00
|
|
|
/*!
|
|
|
|
|
Accepts the candidate find of the current focus widget (if any), and moves the tool bar
|
|
|
|
|
there, if it was visible before.
|
|
|
|
|
*/
|
|
|
|
|
void FindToolBar::acceptCandidateAndMoveToolBar()
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentDocumentFind->candidate())
|
|
|
|
|
return;
|
|
|
|
|
if (isVisible()) {
|
|
|
|
|
openFindToolBar(UpdateHighlight);
|
|
|
|
|
} else {
|
|
|
|
|
// Make sure we are really hidden, and not just because our parent was hidden.
|
|
|
|
|
// Otherwise when the tool bar gets visible again, it will be in a different widget than
|
|
|
|
|
// the current document find it acts on.
|
|
|
|
|
// Test case: Open find in navigation side bar, hide side bar, click into editor,
|
|
|
|
|
// trigger find next, show side bar
|
|
|
|
|
hide();
|
|
|
|
|
m_currentDocumentFind->acceptCandidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-24 17:51:39 +02:00
|
|
|
void FindToolBar::openFind(bool focus)
|
2010-01-21 17:23:31 +01:00
|
|
|
{
|
|
|
|
|
setBackward(false);
|
2014-11-03 17:09:41 +01:00
|
|
|
OpenFlags flags = UpdateAll;
|
|
|
|
|
if (!focus) // remove focus flag
|
|
|
|
|
flags = flags & ~UpdateFocusAndSelect;
|
|
|
|
|
openFindToolBar(flags);
|
2010-01-21 17:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
2014-11-03 17:09:41 +01:00
|
|
|
void FindToolBar::openFindToolBar(OpenFlags flags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-10 11:44:09 +01:00
|
|
|
installEventFilters();
|
2009-07-21 11:10:02 +02:00
|
|
|
Core::FindToolBarPlaceHolder *holder = findToolBarPlaceHolder();
|
|
|
|
|
if (!holder)
|
|
|
|
|
return;
|
|
|
|
|
Core::FindToolBarPlaceHolder *previousHolder = Core::FindToolBarPlaceHolder::getCurrent();
|
2014-05-14 14:28:06 +02:00
|
|
|
if (previousHolder != holder) {
|
|
|
|
|
if (previousHolder)
|
|
|
|
|
previousHolder->setWidget(0);
|
|
|
|
|
holder->setWidget(this);
|
|
|
|
|
Core::FindToolBarPlaceHolder::setCurrent(holder);
|
|
|
|
|
}
|
2009-07-21 11:10:02 +02:00
|
|
|
m_currentDocumentFind->acceptCandidate();
|
|
|
|
|
holder->setVisible(true);
|
|
|
|
|
setVisible(true);
|
2014-11-03 17:09:41 +01:00
|
|
|
// We do not want to change the text when we currently have the focus and user presses the
|
|
|
|
|
// find shortcut
|
|
|
|
|
// if (!focus || !toolBarHasFocus()) {
|
|
|
|
|
if (flags & UpdateFindText) {
|
2014-05-14 14:28:06 +02:00
|
|
|
QString text = m_currentDocumentFind->currentFindString();
|
|
|
|
|
if (!text.isEmpty())
|
|
|
|
|
setFindText(text);
|
|
|
|
|
}
|
2014-11-03 17:09:41 +01:00
|
|
|
if (flags & UpdateFocusAndSelect)
|
2010-06-24 17:51:39 +02:00
|
|
|
setFocus();
|
2014-11-03 17:09:41 +01:00
|
|
|
if (flags & UpdateFindScope)
|
|
|
|
|
m_currentDocumentFind->defineFindScope();
|
|
|
|
|
if (flags & UpdateHighlight)
|
|
|
|
|
m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags());
|
|
|
|
|
if (flags & UpdateFocusAndSelect)
|
2010-06-24 17:51:39 +02:00
|
|
|
selectFindText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::findNextSelected()
|
|
|
|
|
{
|
2014-11-03 17:09:41 +01:00
|
|
|
openFindToolBar(OpenFlags(UpdateAll & ~UpdateFocusAndSelect));
|
2010-06-24 17:51:39 +02:00
|
|
|
invokeFindNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::findPreviousSelected()
|
|
|
|
|
{
|
2014-11-03 17:09:41 +01:00
|
|
|
openFindToolBar(OpenFlags(UpdateAll & ~UpdateFocusAndSelect));
|
2010-06-24 17:51:39 +02:00
|
|
|
invokeFindPrevious();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-12 11:22:39 +01:00
|
|
|
|
|
|
|
|
bool FindToolBar::focusNextPrevChild(bool next)
|
|
|
|
|
{
|
2014-02-25 18:38:35 +01:00
|
|
|
QAbstractButton *optionsButton = m_ui.findEdit->button(Utils::FancyLineEdit::Left);
|
|
|
|
|
// close tab order
|
2014-02-24 17:32:01 +01:00
|
|
|
if (next && m_ui.advancedButton->hasFocus())
|
2014-02-25 18:38:35 +01:00
|
|
|
optionsButton->setFocus(Qt::TabFocusReason);
|
|
|
|
|
else if (next && optionsButton->hasFocus())
|
2008-12-12 11:22:39 +01:00
|
|
|
m_ui.findEdit->setFocus(Qt::TabFocusReason);
|
2014-02-25 18:38:35 +01:00
|
|
|
else if (!next && optionsButton->hasFocus())
|
2014-02-24 17:32:01 +01:00
|
|
|
m_ui.advancedButton->setFocus(Qt::TabFocusReason);
|
2014-02-25 18:38:35 +01:00
|
|
|
else if (!next && m_ui.findEdit->hasFocus())
|
|
|
|
|
optionsButton->setFocus(Qt::TabFocusReason);
|
2008-12-12 11:22:39 +01:00
|
|
|
else
|
2009-10-05 11:06:05 +02:00
|
|
|
return Utils::StyledBar::focusNextPrevChild(next);
|
2008-12-12 11:22:39 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-05-29 16:12:19 +02:00
|
|
|
|
2014-06-11 16:30:48 +02:00
|
|
|
void FindToolBar::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(updateToolBar()));
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-29 16:12:19 +02:00
|
|
|
void FindToolBar::writeSettings()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-01-20 15:33:18 +01:00
|
|
|
settings->beginGroup(QLatin1String("Find"));
|
|
|
|
|
settings->beginGroup(QLatin1String("FindToolBar"));
|
2013-09-03 15:42:38 +02:00
|
|
|
settings->setValue(QLatin1String("Backward"), QVariant((m_findFlags & FindBackward) != 0));
|
|
|
|
|
settings->setValue(QLatin1String("CaseSensitively"), QVariant((m_findFlags & FindCaseSensitively) != 0));
|
|
|
|
|
settings->setValue(QLatin1String("WholeWords"), QVariant((m_findFlags & FindWholeWords) != 0));
|
|
|
|
|
settings->setValue(QLatin1String("RegularExpression"), QVariant((m_findFlags & FindRegularExpression) != 0));
|
|
|
|
|
settings->setValue(QLatin1String("PreserveCase"), QVariant((m_findFlags & FindPreserveCase) != 0));
|
2009-05-29 16:12:19 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::readSettings()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-01-20 15:33:18 +01:00
|
|
|
settings->beginGroup(QLatin1String("Find"));
|
|
|
|
|
settings->beginGroup(QLatin1String("FindToolBar"));
|
2013-09-03 15:42:38 +02:00
|
|
|
FindFlags flags;
|
2012-01-20 15:33:18 +01:00
|
|
|
if (settings->value(QLatin1String("Backward"), false).toBool())
|
2013-09-03 15:42:38 +02:00
|
|
|
flags |= FindBackward;
|
2012-01-20 15:33:18 +01:00
|
|
|
if (settings->value(QLatin1String("CaseSensitively"), false).toBool())
|
2013-09-03 15:42:38 +02:00
|
|
|
flags |= FindCaseSensitively;
|
2012-01-20 15:33:18 +01:00
|
|
|
if (settings->value(QLatin1String("WholeWords"), false).toBool())
|
2013-09-03 15:42:38 +02:00
|
|
|
flags |= FindWholeWords;
|
2012-01-20 15:33:18 +01:00
|
|
|
if (settings->value(QLatin1String("RegularExpression"), false).toBool())
|
2013-09-03 15:42:38 +02:00
|
|
|
flags |= FindRegularExpression;
|
2012-11-30 16:15:07 +01:00
|
|
|
if (settings->value(QLatin1String("PreserveCase"), false).toBool())
|
2013-09-03 15:42:38 +02:00
|
|
|
flags |= FindPreserveCase;
|
2009-05-29 16:12:19 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
m_findFlags = flags;
|
|
|
|
|
findFlagsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-21 17:23:31 +01:00
|
|
|
void FindToolBar::setUseFakeVim(bool on)
|
|
|
|
|
{
|
|
|
|
|
m_useFakeVim = on;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 15:42:38 +02:00
|
|
|
void FindToolBar::setFindFlag(FindFlag flag, bool enabled)
|
2009-05-29 16:12:19 +02:00
|
|
|
{
|
|
|
|
|
bool hasFlag = hasFindFlag(flag);
|
|
|
|
|
if ((hasFlag && enabled) || (!hasFlag && !enabled))
|
|
|
|
|
return;
|
|
|
|
|
if (enabled)
|
|
|
|
|
m_findFlags |= flag;
|
|
|
|
|
else
|
|
|
|
|
m_findFlags &= ~flag;
|
2013-09-03 15:42:38 +02:00
|
|
|
if (flag != FindBackward)
|
2009-05-29 16:12:19 +02:00
|
|
|
findFlagsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 15:42:38 +02:00
|
|
|
bool FindToolBar::hasFindFlag(FindFlag flag)
|
2009-05-29 16:12:19 +02:00
|
|
|
{
|
|
|
|
|
return m_findFlags & flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setCaseSensitive(bool sensitive)
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindCaseSensitively, sensitive);
|
2009-05-29 16:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::setWholeWord(bool wholeOnly)
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindWholeWords, wholeOnly);
|
2009-05-29 16:12:19 +02:00
|
|
|
}
|
2009-05-29 16:52:12 +02:00
|
|
|
|
|
|
|
|
void FindToolBar::setRegularExpressions(bool regexp)
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindRegularExpression, regexp);
|
2009-05-29 16:52:12 +02:00
|
|
|
}
|
2010-01-21 17:23:31 +01:00
|
|
|
|
2012-11-30 16:15:07 +01:00
|
|
|
void FindToolBar::setPreserveCase(bool preserveCase)
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindPreserveCase, preserveCase);
|
2012-11-30 16:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-21 17:23:31 +01:00
|
|
|
void FindToolBar::setBackward(bool backward)
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, backward);
|
2010-01-21 17:23:31 +01:00
|
|
|
}
|
2014-02-25 18:38:35 +01:00
|
|
|
|
2014-08-11 17:31:27 +02:00
|
|
|
void FindToolBar::setLightColoredIcon(bool lightColored)
|
|
|
|
|
{
|
|
|
|
|
m_ui.close->setIcon(lightColored ? QIcon(QLatin1String(Core::Constants::ICON_DARK_CLOSE))
|
|
|
|
|
: QIcon(QLatin1String(Core::Constants::ICON_BUTTON_CLOSE)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 18:38:35 +01:00
|
|
|
OptionsPopup::OptionsPopup(QWidget *parent)
|
|
|
|
|
: QWidget(parent, Qt::Popup)
|
|
|
|
|
{
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
|
layout->setSpacing(2);
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
QCheckBox *firstCheckBox = createCheckboxForCommand(Constants::CASE_SENSITIVE);
|
|
|
|
|
layout->addWidget(firstCheckBox);
|
|
|
|
|
layout->addWidget(createCheckboxForCommand(Constants::WHOLE_WORDS));
|
|
|
|
|
layout->addWidget(createCheckboxForCommand(Constants::REGULAR_EXPRESSIONS));
|
|
|
|
|
layout->addWidget(createCheckboxForCommand(Constants::PRESERVE_CASE));
|
|
|
|
|
firstCheckBox->setFocus();
|
|
|
|
|
move(parent->mapToGlobal(QPoint(0, -sizeHint().height())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OptionsPopup::event(QEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::ShortcutOverride) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(ev);
|
|
|
|
|
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
|
|
|
|
|
ev->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::event(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OptionsPopup::eventFilter(QObject *obj, QEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
QCheckBox *checkbox = qobject_cast<QCheckBox *>(obj);
|
|
|
|
|
if (ev->type() == QEvent::KeyPress && checkbox) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(ev);
|
|
|
|
|
if (!ke->modifiers() && (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)) {
|
|
|
|
|
checkbox->click();
|
|
|
|
|
ev->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::eventFilter(obj, ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OptionsPopup::actionChanged()
|
|
|
|
|
{
|
|
|
|
|
QAction *action = qobject_cast<QAction *>(sender());
|
|
|
|
|
QTC_ASSERT(action, return);
|
|
|
|
|
QCheckBox *checkbox = m_checkboxMap.value(action);
|
|
|
|
|
QTC_ASSERT(checkbox, return);
|
|
|
|
|
checkbox->setEnabled(action->isEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QCheckBox *OptionsPopup::createCheckboxForCommand(Id id)
|
|
|
|
|
{
|
|
|
|
|
QAction *action = ActionManager::command(id)->action();
|
|
|
|
|
QCheckBox *checkbox = new QCheckBox(action->text());
|
|
|
|
|
checkbox->setToolTip(action->toolTip());
|
|
|
|
|
checkbox->setChecked(action->isChecked());
|
|
|
|
|
checkbox->setEnabled(action->isEnabled());
|
|
|
|
|
checkbox->installEventFilter(this); // enter key handling
|
|
|
|
|
QObject::connect(checkbox, SIGNAL(clicked(bool)), action, SLOT(setChecked(bool)));
|
|
|
|
|
QObject::connect(action, SIGNAL(changed()), this, SLOT(actionChanged()));
|
|
|
|
|
m_checkboxMap.insert(action, checkbox);
|
|
|
|
|
return checkbox;
|
|
|
|
|
}
|