2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 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
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/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
|
|
|
|
|
** 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
|
|
|
**
|
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"
|
|
|
|
|
#include "findplugin.h"
|
2011-09-07 20:28:04 +02:00
|
|
|
#include "ifindfilter.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#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>
|
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>
|
2011-06-23 14:35:45 +02:00
|
|
|
#include <utils/flowlayout.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
|
|
|
|
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)
|
|
|
|
|
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),
|
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());
|
|
|
|
|
delete m_ui.replaceButtonsWidget->layout();
|
|
|
|
|
Utils::FlowLayout *flowlayout = new Utils::FlowLayout(m_ui.replaceButtonsWidget, 0, 3, 3);
|
|
|
|
|
flowlayout->addWidget(m_ui.replaceButton);
|
|
|
|
|
flowlayout->addWidget(m_ui.replaceNextButton);
|
|
|
|
|
flowlayout->addWidget(m_ui.replaceAllButton);
|
|
|
|
|
m_ui.replaceButtonsWidget->setLayout(flowlayout);
|
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()));
|
|
|
|
|
|
2012-02-17 14:00:45 +01:00
|
|
|
m_ui.close->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLOSE_DOCUMENT)));
|
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
|
|
|
|
|
|
|
|
QMenu *lineEditMenu = new QMenu(m_ui.findEdit);
|
2010-07-01 09:32:47 +02:00
|
|
|
m_ui.findEdit->setButtonMenu(Utils::FancyLineEdit::Left, lineEditMenu);
|
|
|
|
|
m_ui.findEdit->setButtonVisible(Utils::FancyLineEdit::Left, true);
|
|
|
|
|
m_ui.findEdit->setPlaceholderText(QString());
|
|
|
|
|
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()));
|
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
|
|
|
|
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()));
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_findNextAction, SIGNAL(triggered()), this, SLOT(invokeFindNext()));
|
|
|
|
|
m_ui.findNextButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
|
|
|
|
m_ui.findPreviousButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_replaceAction, SIGNAL(triggered()), this, SLOT(invokeReplace()));
|
|
|
|
|
m_ui.replaceButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_replaceNextAction, SIGNAL(triggered()), this, SLOT(invokeReplaceNext()));
|
|
|
|
|
m_ui.replaceNextButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_replaceAllAction, SIGNAL(triggered()), this, SLOT(invokeReplaceAll()));
|
|
|
|
|
m_ui.replaceAllButton->setDefaultAction(cmd->action());
|
|
|
|
|
|
|
|
|
|
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);
|
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);
|
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);
|
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);
|
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);
|
|
|
|
|
connect(m_regularExpressionAction, SIGNAL(triggered(bool)), this, SLOT(setRegularExpressions(bool)));
|
|
|
|
|
lineEditMenu->addAction(m_regularExpressionAction);
|
|
|
|
|
|
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);
|
|
|
|
|
connect(m_preserveCaseAction, SIGNAL(triggered(bool)), this, SLOT(setPreserveCase(bool)));
|
|
|
|
|
lineEditMenu->addAction(m_preserveCaseAction);
|
|
|
|
|
|
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();
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-20 13:48:58 +01:00
|
|
|
bool FindToolBar::shouldSetFocusOnKeyEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
return event->key() == Qt::Key_Escape && !event->modifiers()
|
|
|
|
|
&& !m_findCompleter->popup()->isVisible()
|
|
|
|
|
&& !m_replaceCompleter->popup()->isVisible()
|
|
|
|
|
&& m_currentDocumentFind->isEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2013-03-20 13:48:58 +01:00
|
|
|
if (shouldSetFocusOnKeyEvent(ke)) {
|
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
2012-09-07 13:31:29 +02:00
|
|
|
} else 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
|
|
|
}
|
|
|
|
|
|
2013-03-20 13:48:58 +01:00
|
|
|
void FindToolBar::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (shouldSetFocusOnKeyEvent(event)) {
|
|
|
|
|
if (setFocusToCurrentFindSupport())
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return Utils::StyledBar::keyPressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
void FindToolBar::adaptToCandidate()
|
|
|
|
|
{
|
|
|
|
|
updateFindAction();
|
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 (findToolBarPlaceHolder() == Core::FindToolBarPlaceHolder::getCurrent())
|
2009-07-21 11:10:02 +02:00
|
|
|
m_currentDocumentFind->acceptCandidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::updateFindAction()
|
|
|
|
|
{
|
2010-06-24 17:51:39 +02:00
|
|
|
bool enabled = m_currentDocumentFind->candidateIsEnabled();
|
|
|
|
|
m_findInDocumentAction->setEnabled(enabled);
|
|
|
|
|
m_findNextSelectedAction->setEnabled(enabled);
|
|
|
|
|
m_findPreviousSelectedAction->setEnabled(enabled);
|
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();
|
|
|
|
|
m_findNextAction->setEnabled(enabled);
|
|
|
|
|
m_findPreviousAction->setEnabled(enabled);
|
2009-07-14 18:01:25 +02:00
|
|
|
|
2010-07-14 14:45:02 +02:00
|
|
|
m_replaceAction->setEnabled(replaceEnabled);
|
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);
|
2013-09-03 15:42:38 +02:00
|
|
|
m_preserveCaseAction->setEnabled(replaceEnabled && !hasFindFlag(FindRegularExpression));
|
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);
|
2011-06-23 14:35:45 +02:00
|
|
|
m_ui.replaceButtonsWidget->setVisible(replaceEnabled);
|
2010-07-14 15:18:56 +02:00
|
|
|
m_ui.advancedButton->setVisible(replaceEnabled);
|
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())
|
2008-12-02 12:01:29 +01:00
|
|
|
m_currentDocumentFind->clearResults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindNext()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(FindBackward, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
invokeFindStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeFindPrevious()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(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)
|
|
|
|
|
{
|
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())
|
|
|
|
|
m_currentDocumentFind->clearResults();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::invokeReplacePrevious()
|
|
|
|
|
{
|
2013-09-03 15:42:38 +02:00
|
|
|
setFindFlag(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());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
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();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2011-09-07 20:28:04 +02:00
|
|
|
QPixmap pixmap(17, 17);
|
|
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
|
QPainter painter(&pixmap);
|
2012-01-20 15:33:18 +01:00
|
|
|
const QPixmap mag = QPixmap(QLatin1String(Core::Constants::ICON_MAGNIFIER));
|
2009-06-02 16:49:29 +02:00
|
|
|
painter.drawPixmap(0, (pixmap.height() - mag.height()) / 2, mag);
|
2011-09-07 20:28:04 +02:00
|
|
|
m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left, pixmap);
|
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-24 17:51:39 +02:00
|
|
|
void FindToolBar::openFind(bool focus)
|
2010-01-21 17:23:31 +01:00
|
|
|
{
|
|
|
|
|
setBackward(false);
|
2010-06-24 17:51:39 +02:00
|
|
|
openFindToolBar(focus);
|
2010-01-21 17:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-24 17:51:39 +02:00
|
|
|
void FindToolBar::openFindToolBar(bool focus)
|
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
|
|
|
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)
|
2009-07-21 17:48:24 +02:00
|
|
|
previousHolder->setWidget(0);
|
2009-07-21 11:10:02 +02:00
|
|
|
Core::FindToolBarPlaceHolder::setCurrent(holder);
|
|
|
|
|
m_currentDocumentFind->acceptCandidate();
|
2009-07-21 17:48:24 +02:00
|
|
|
holder->setWidget(this);
|
2009-07-21 11:10:02 +02:00
|
|
|
holder->setVisible(true);
|
|
|
|
|
setVisible(true);
|
2010-06-24 17:51:39 +02:00
|
|
|
if (focus)
|
|
|
|
|
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());
|
2010-06-24 17:51:39 +02:00
|
|
|
if (focus)
|
|
|
|
|
selectFindText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::findNextSelected()
|
|
|
|
|
{
|
|
|
|
|
openFind(false);
|
|
|
|
|
invokeFindNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolBar::findPreviousSelected()
|
|
|
|
|
{
|
|
|
|
|
openFind(false);
|
|
|
|
|
invokeFindPrevious();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
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-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
|
|
|
|
|
|
|
|
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
|
|
|
}
|