2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2014-01-13 16:17:34 +01:00
|
|
|
|
|
|
|
|
#include "findplugin.h"
|
|
|
|
|
|
|
|
|
|
#include "currentdocumentfind.h"
|
|
|
|
|
#include "findtoolbar.h"
|
|
|
|
|
#include "findtoolwindow.h"
|
|
|
|
|
#include "ifindfilter.h"
|
2023-01-16 17:20:07 +01:00
|
|
|
#include "searchresultwindow.h"
|
|
|
|
|
#include "../actionmanager/actioncontainer.h"
|
|
|
|
|
#include "../actionmanager/actionmanager.h"
|
|
|
|
|
#include "../actionmanager/command.h"
|
|
|
|
|
#include "../coreconstants.h"
|
|
|
|
|
#include "../coreplugintr.h"
|
|
|
|
|
#include "../icontext.h"
|
|
|
|
|
#include "../icore.h"
|
2014-01-13 16:17:34 +01:00
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2016-02-03 10:24:28 +02:00
|
|
|
#include <utils/algorithm.h>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2022-09-29 12:12:29 +02:00
|
|
|
#include <QApplication>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QStringListModel>
|
2017-12-20 16:40:45 +01:00
|
|
|
#include <QVector>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-13 16:14:56 +01:00
|
|
|
\namespace Core::Internal::ItemDataRoles
|
2014-01-13 16:17:34 +01:00
|
|
|
\internal
|
|
|
|
|
*/
|
2020-02-13 16:14:56 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
/*!
|
2020-02-13 16:14:56 +01:00
|
|
|
\class Core::Find
|
|
|
|
|
\inmodule QtCreator
|
2014-01-13 16:17:34 +01:00
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::IFindFilter*)
|
|
|
|
|
|
2019-11-12 13:28:42 +01:00
|
|
|
using namespace Qt;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2019-11-12 13:28:42 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
namespace {
|
|
|
|
|
const int MAX_COMPLETIONS = 50;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
2017-12-20 16:40:45 +01:00
|
|
|
struct CompletionEntry
|
|
|
|
|
{
|
2021-12-06 05:11:04 +01:00
|
|
|
friend QDebug operator<<(QDebug d, const CompletionEntry &e)
|
|
|
|
|
{
|
|
|
|
|
QDebugStateSaver saver(d);
|
|
|
|
|
d.noquote();
|
|
|
|
|
d.nospace();
|
|
|
|
|
d << "CompletionEntry(\"" << e.text << "\", flags="
|
|
|
|
|
<< "0x" << QString::number(e.findFlags, 16) << ')';
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 16:40:45 +01:00
|
|
|
QString text;
|
|
|
|
|
FindFlags findFlags;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CompletionModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit CompletionModel(QObject *p = nullptr) : QAbstractListModel(p) {}
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex & = QModelIndex()) const override { return m_entries.size(); }
|
|
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
|
|
void writeSettings(QSettings *settings) const;
|
|
|
|
|
void readSettings(QSettings *settings);
|
|
|
|
|
|
|
|
|
|
void updateCompletion(const QString &text, FindFlags f);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QVector<CompletionEntry> m_entries;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVariant CompletionModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
|
const CompletionEntry &entry = m_entries.at(index.row());
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
|
|
|
|
return QVariant(entry.text);
|
|
|
|
|
case Find::CompletionModelFindFlagsRole:
|
|
|
|
|
return QVariant(int(entry.findFlags));
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString completionSettingsArrayPrefix() { return QStringLiteral("FindCompletions"); }
|
|
|
|
|
static inline QString completionSettingsTextKey() { return QStringLiteral("Text"); }
|
|
|
|
|
static inline QString completionSettingsFlagsKey() { return QStringLiteral("Flags"); }
|
|
|
|
|
|
|
|
|
|
void CompletionModel::writeSettings(QSettings *settings) const
|
|
|
|
|
{
|
2020-12-10 11:24:27 +01:00
|
|
|
if (m_entries.isEmpty()) {
|
|
|
|
|
settings->remove(completionSettingsArrayPrefix());
|
|
|
|
|
} else {
|
|
|
|
|
const int size = m_entries.size();
|
|
|
|
|
settings->beginWriteArray(completionSettingsArrayPrefix(), size);
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
settings->setValue(completionSettingsTextKey(), m_entries.at(i).text);
|
|
|
|
|
settings->setValue(completionSettingsFlagsKey(), int(m_entries.at(i).findFlags));
|
|
|
|
|
}
|
|
|
|
|
settings->endArray();
|
2017-12-20 16:40:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompletionModel::readSettings(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
beginResetModel();
|
|
|
|
|
const int size = settings->beginReadArray(completionSettingsArrayPrefix());
|
|
|
|
|
m_entries.clear();
|
|
|
|
|
m_entries.reserve(size);
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
CompletionEntry entry;
|
|
|
|
|
entry.text = settings->value(completionSettingsTextKey()).toString();
|
|
|
|
|
entry.findFlags = FindFlags(settings->value(completionSettingsFlagsKey(), 0).toInt());
|
|
|
|
|
if (!entry.text.isEmpty())
|
|
|
|
|
m_entries.append(entry);
|
|
|
|
|
}
|
|
|
|
|
settings->endArray();
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompletionModel::updateCompletion(const QString &text, FindFlags f)
|
|
|
|
|
{
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
beginResetModel();
|
|
|
|
|
Utils::erase(m_entries, Utils::equal(&CompletionEntry::text, text));
|
|
|
|
|
m_entries.prepend({text, f});
|
|
|
|
|
while (m_entries.size() > MAX_COMPLETIONS)
|
|
|
|
|
m_entries.removeLast();
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
class FindPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-11-18 10:43:05 +01:00
|
|
|
bool isAnyFilterEnabled() const;
|
2016-03-11 19:12:07 +01:00
|
|
|
void writeSettings();
|
2023-05-22 13:56:37 +02:00
|
|
|
void setFindFlag(FindFlag flag, bool enabled);
|
2020-12-10 00:59:50 +01:00
|
|
|
static void updateCompletion(const QString &text, QStringList &completions,
|
|
|
|
|
QStringListModel *model);
|
2016-03-11 19:12:07 +01:00
|
|
|
void setupMenu();
|
|
|
|
|
void setupFilterMenuItems();
|
|
|
|
|
void readSettings();
|
2014-01-13 16:17:34 +01:00
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
Internal::CurrentDocumentFind *m_currentDocumentFind = nullptr;
|
|
|
|
|
Internal::FindToolBar *m_findToolBar = nullptr;
|
|
|
|
|
Internal::FindToolWindow *m_findDialog = nullptr;
|
|
|
|
|
SearchResultWindow *m_searchResultWindow = nullptr;
|
2014-01-13 16:17:34 +01:00
|
|
|
FindFlags m_findFlags;
|
2017-12-20 16:40:45 +01:00
|
|
|
CompletionModel m_findCompletionModel;
|
2016-03-11 19:12:07 +01:00
|
|
|
QStringListModel m_replaceCompletionModel;
|
2014-01-13 16:17:34 +01:00
|
|
|
QStringList m_replaceCompletions;
|
2018-07-21 21:11:46 +02:00
|
|
|
QAction *m_openFindDialog = nullptr;
|
2014-01-13 16:17:34 +01:00
|
|
|
};
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
Find *m_instance = nullptr;
|
|
|
|
|
FindPrivate *d = nullptr;
|
2014-01-13 16:17:34 +01:00
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::destroy()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
delete m_instance;
|
2018-07-21 21:11:46 +02:00
|
|
|
m_instance = nullptr;
|
2016-12-02 09:50:14 +01:00
|
|
|
if (d) {
|
|
|
|
|
delete d->m_currentDocumentFind;
|
|
|
|
|
delete d->m_findToolBar;
|
|
|
|
|
delete d->m_findDialog;
|
|
|
|
|
ExtensionSystem::PluginManager::removeObject(d->m_searchResultWindow);
|
|
|
|
|
delete d->m_searchResultWindow;
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
Find *Find::instance()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
return m_instance;
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::initialize()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
QTC_ASSERT(!m_instance, return);
|
|
|
|
|
m_instance = new Find;
|
|
|
|
|
|
|
|
|
|
d = new FindPrivate;
|
|
|
|
|
d->setupMenu();
|
2014-01-13 16:17:34 +01:00
|
|
|
|
|
|
|
|
d->m_currentDocumentFind = new Internal::CurrentDocumentFind;
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
d->m_findToolBar = new Internal::FindToolBar(d->m_currentDocumentFind);
|
|
|
|
|
auto *findToolBarContext = new IContext(m_instance);
|
2014-03-03 11:55:50 +01:00
|
|
|
findToolBarContext->setWidget(d->m_findToolBar);
|
|
|
|
|
findToolBarContext->setContext(Context(Constants::C_FINDTOOLBAR));
|
|
|
|
|
ICore::addContextObject(findToolBarContext);
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
d->m_findDialog = new Internal::FindToolWindow;
|
2014-01-13 16:17:34 +01:00
|
|
|
d->m_searchResultWindow = new SearchResultWindow(d->m_findDialog);
|
|
|
|
|
ExtensionSystem::PluginManager::addObject(d->m_searchResultWindow);
|
2016-03-11 19:12:07 +01:00
|
|
|
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, d, &FindPrivate::writeSettings);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::extensionsInitialized()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
d->setupFilterMenuItems();
|
|
|
|
|
d->readSettings();
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::aboutToShutdown()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
|
|
|
|
d->m_findToolBar->setVisible(false);
|
2018-07-21 21:11:46 +02:00
|
|
|
d->m_findToolBar->setParent(nullptr);
|
2014-01-13 16:17:34 +01:00
|
|
|
d->m_currentDocumentFind->removeConnections();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 10:43:05 +01:00
|
|
|
bool FindPrivate::isAnyFilterEnabled() const
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-11-18 10:43:05 +01:00
|
|
|
return Utils::anyOf(m_findDialog->findFilters(), &IFindFilter::isEnabled);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-02 15:31:21 +02:00
|
|
|
void Find::openFindDialog(IFindFilter *filter, const QString &findString)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2014-11-04 14:58:48 +01:00
|
|
|
d->m_currentDocumentFind->acceptCandidate();
|
2022-09-02 15:31:21 +02:00
|
|
|
const QString currentFindString = [findString] {
|
|
|
|
|
if (!findString.isEmpty())
|
|
|
|
|
return findString;
|
|
|
|
|
if (d->m_findToolBar->isVisible()
|
|
|
|
|
&& QApplication::focusWidget() == d->m_findToolBar->focusWidget()
|
|
|
|
|
&& !d->m_findToolBar->getFindText().isEmpty()) {
|
|
|
|
|
return d->m_findToolBar->getFindText();
|
|
|
|
|
}
|
|
|
|
|
if (d->m_currentDocumentFind->isEnabled())
|
|
|
|
|
return d->m_currentDocumentFind->currentFindString();
|
|
|
|
|
return QString();
|
|
|
|
|
}();
|
2014-01-13 16:17:34 +01:00
|
|
|
if (!currentFindString.isEmpty())
|
|
|
|
|
d->m_findDialog->setFindText(currentFindString);
|
|
|
|
|
d->m_findDialog->setCurrentFilter(filter);
|
|
|
|
|
SearchResultWindow::instance()->openNewSearchPanel();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void FindPrivate::setupMenu()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
ActionContainer *medit = ActionManager::actionContainer(Constants::M_EDIT);
|
|
|
|
|
ActionContainer *mfind = ActionManager::createMenu(Constants::M_FIND);
|
|
|
|
|
medit->addMenu(mfind, Constants::G_EDIT_FIND);
|
2023-01-16 17:20:07 +01:00
|
|
|
mfind->menu()->setTitle(Tr::tr("&Find/Replace"));
|
2014-01-13 16:17:34 +01:00
|
|
|
mfind->appendGroup(Constants::G_FIND_CURRENTDOCUMENT);
|
|
|
|
|
mfind->appendGroup(Constants::G_FIND_FILTERS);
|
|
|
|
|
mfind->appendGroup(Constants::G_FIND_FLAGS);
|
|
|
|
|
mfind->appendGroup(Constants::G_FIND_ACTIONS);
|
2014-11-16 10:52:41 +02:00
|
|
|
Command *cmd;
|
2015-02-26 13:58:00 +01:00
|
|
|
mfind->addSeparator(Constants::G_FIND_FLAGS);
|
|
|
|
|
mfind->addSeparator(Constants::G_FIND_ACTIONS);
|
2014-01-13 16:17:34 +01:00
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
ActionContainer *mfindadvanced = ActionManager::createMenu(Constants::M_FIND_ADVANCED);
|
2023-01-16 17:20:07 +01:00
|
|
|
mfindadvanced->menu()->setTitle(Tr::tr("Advanced Find"));
|
2014-01-13 16:17:34 +01:00
|
|
|
mfind->addMenu(mfindadvanced, Constants::G_FIND_FILTERS);
|
2023-01-16 17:20:07 +01:00
|
|
|
m_openFindDialog = new QAction(Tr::tr("Open Advanced Find..."), this);
|
|
|
|
|
m_openFindDialog->setIconText(Tr::tr("Advanced..."));
|
2016-03-11 19:12:07 +01:00
|
|
|
cmd = ActionManager::registerAction(m_openFindDialog, Constants::ADVANCED_FIND);
|
2023-01-16 17:20:07 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Shift+F")));
|
2014-01-13 16:17:34 +01:00
|
|
|
mfindadvanced->addAction(cmd);
|
2016-03-11 19:12:07 +01:00
|
|
|
connect(m_openFindDialog, &QAction::triggered,
|
2017-09-07 17:05:47 +02:00
|
|
|
this, [] { Find::openFindDialog(nullptr); });
|
2016-11-18 10:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString filterActionName(const IFindFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(" ") + filter->displayName();
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void FindPrivate::setupFilterMenuItems()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
Command *cmd;
|
2014-01-13 16:17:34 +01:00
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
ActionContainer *mfindadvanced = ActionManager::actionContainer(Constants::M_FIND_ADVANCED);
|
2014-01-13 16:17:34 +01:00
|
|
|
bool haveEnabledFilters = false;
|
2014-11-16 10:52:41 +02:00
|
|
|
const Id base("FindFilter.");
|
2022-10-21 14:05:12 +02:00
|
|
|
const QList<IFindFilter *> sortedFilters = Utils::sorted(IFindFilter::allFindFilters(),
|
|
|
|
|
&IFindFilter::displayName);
|
|
|
|
|
for (IFindFilter *filter : sortedFilters) {
|
2016-11-18 10:43:05 +01:00
|
|
|
QAction *action = new QAction(filterActionName(filter), this);
|
2014-01-13 16:17:34 +01:00
|
|
|
bool isEnabled = filter->isEnabled();
|
|
|
|
|
if (isEnabled)
|
|
|
|
|
haveEnabledFilters = true;
|
|
|
|
|
action->setEnabled(isEnabled);
|
2015-02-19 11:35:47 +01:00
|
|
|
cmd = ActionManager::registerAction(action, base.withSuffix(filter->id()));
|
2014-01-13 16:17:34 +01:00
|
|
|
cmd->setDefaultKeySequence(filter->defaultShortcut());
|
2015-08-21 12:30:35 +02:00
|
|
|
cmd->setAttribute(Command::CA_UpdateText);
|
2014-01-13 16:17:34 +01:00
|
|
|
mfindadvanced->addAction(cmd);
|
2017-09-07 17:05:47 +02:00
|
|
|
connect(action, &QAction::triggered, this, [filter] { Find::openFindDialog(filter); });
|
2016-11-18 10:43:05 +01:00
|
|
|
connect(filter, &IFindFilter::enabledChanged, this, [filter, action] {
|
|
|
|
|
action->setEnabled(filter->isEnabled());
|
|
|
|
|
d->m_openFindDialog->setEnabled(d->isAnyFilterEnabled());
|
|
|
|
|
});
|
|
|
|
|
connect(filter, &IFindFilter::displayNameChanged,
|
|
|
|
|
this, [filter, action] { action->setText(filterActionName(filter)); });
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
2016-02-03 10:24:28 +02:00
|
|
|
d->m_findDialog->setFindFilters(sortedFilters);
|
2014-01-13 16:17:34 +01:00
|
|
|
d->m_openFindDialog->setEnabled(haveEnabledFilters);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
FindFlags Find::findFlags()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
|
|
|
|
return d->m_findFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::setCaseSensitive(bool sensitive)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
d->setFindFlag(FindCaseSensitively, sensitive);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::setWholeWord(bool wholeOnly)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
d->setFindFlag(FindWholeWords, wholeOnly);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::setBackward(bool backward)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
d->setFindFlag(FindBackward, backward);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::setRegularExpression(bool regExp)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
d->setFindFlag(FindRegularExpression, regExp);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::setPreserveCase(bool preserveCase)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
d->setFindFlag(FindPreserveCase, preserveCase);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void FindPrivate::setFindFlag(FindFlag flag, bool enabled)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
bool hasFlag = m_findFlags & flag;
|
2014-01-13 16:17:34 +01:00
|
|
|
if ((hasFlag && enabled) || (!hasFlag && !enabled))
|
|
|
|
|
return;
|
|
|
|
|
if (enabled)
|
2016-03-11 19:12:07 +01:00
|
|
|
m_findFlags |= flag;
|
2014-01-13 16:17:34 +01:00
|
|
|
else
|
2016-03-11 19:12:07 +01:00
|
|
|
m_findFlags &= ~flag;
|
2014-01-13 16:17:34 +01:00
|
|
|
if (flag != FindBackward)
|
2016-03-11 19:12:07 +01:00
|
|
|
emit m_instance->findFlagsChanged();
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
bool Find::hasFindFlag(FindFlag flag)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
|
|
|
|
return d->m_findFlags & flag;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void FindPrivate::writeSettings()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2020-12-10 11:24:27 +01:00
|
|
|
QtcSettings *settings = ICore::settings();
|
2014-01-13 16:17:34 +01:00
|
|
|
settings->beginGroup(QLatin1String("Find"));
|
2020-12-10 11:24:27 +01:00
|
|
|
settings->setValueWithDefault("Backward", bool(m_findFlags & FindBackward), false);
|
|
|
|
|
settings->setValueWithDefault("CaseSensitively", bool(m_findFlags & FindCaseSensitively), false);
|
|
|
|
|
settings->setValueWithDefault("WholeWords", bool(m_findFlags & FindWholeWords), false);
|
|
|
|
|
settings->setValueWithDefault("RegularExpression",
|
|
|
|
|
bool(m_findFlags & FindRegularExpression),
|
|
|
|
|
false);
|
|
|
|
|
settings->setValueWithDefault("PreserveCase", bool(m_findFlags & FindPreserveCase), false);
|
2017-12-20 16:40:45 +01:00
|
|
|
m_findCompletionModel.writeSettings(settings);
|
2020-12-10 11:24:27 +01:00
|
|
|
settings->setValueWithDefault("ReplaceStrings", m_replaceCompletions);
|
2014-01-13 16:17:34 +01:00
|
|
|
settings->endGroup();
|
2016-03-11 19:12:07 +01:00
|
|
|
m_findToolBar->writeSettings();
|
|
|
|
|
m_findDialog->writeSettings();
|
|
|
|
|
m_searchResultWindow->writeSettings();
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void FindPrivate::readSettings()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2014-01-13 16:17:34 +01:00
|
|
|
settings->beginGroup(QLatin1String("Find"));
|
2017-09-30 07:12:57 +02:00
|
|
|
{
|
|
|
|
|
QSignalBlocker blocker(m_instance);
|
|
|
|
|
Find::setBackward(settings->value(QLatin1String("Backward"), false).toBool());
|
|
|
|
|
Find::setCaseSensitive(settings->value(QLatin1String("CaseSensitively"), false).toBool());
|
|
|
|
|
Find::setWholeWord(settings->value(QLatin1String("WholeWords"), false).toBool());
|
|
|
|
|
Find::setRegularExpression(settings->value(QLatin1String("RegularExpression"), false).toBool());
|
|
|
|
|
Find::setPreserveCase(settings->value(QLatin1String("PreserveCase"), false).toBool());
|
|
|
|
|
}
|
2017-12-20 16:40:45 +01:00
|
|
|
m_findCompletionModel.readSettings(settings);
|
2016-03-11 19:12:07 +01:00
|
|
|
m_replaceCompletions = settings->value(QLatin1String("ReplaceStrings")).toStringList();
|
|
|
|
|
m_replaceCompletionModel.setStringList(m_replaceCompletions);
|
2014-01-13 16:17:34 +01:00
|
|
|
settings->endGroup();
|
2016-03-11 19:12:07 +01:00
|
|
|
m_findToolBar->readSettings();
|
|
|
|
|
m_findDialog->readSettings();
|
|
|
|
|
emit m_instance->findFlagsChanged(); // would have been done in the setXXX methods above
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 16:40:45 +01:00
|
|
|
void Find::updateFindCompletion(const QString &text, FindFlags flags)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2017-12-20 16:40:45 +01:00
|
|
|
d->m_findCompletionModel.updateCompletion(text, flags);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::updateReplaceCompletion(const QString &text)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2020-12-10 00:59:50 +01:00
|
|
|
FindPrivate::updateCompletion(text, d->m_replaceCompletions, &d->m_replaceCompletionModel);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void FindPrivate::updateCompletion(const QString &text, QStringList &completions, QStringListModel *model)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
completions.removeAll(text);
|
|
|
|
|
completions.prepend(text);
|
|
|
|
|
while (completions.size() > MAX_COMPLETIONS)
|
|
|
|
|
completions.removeLast();
|
|
|
|
|
model->setStringList(completions);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::setUseFakeVim(bool on)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
|
|
|
|
if (d->m_findToolBar)
|
|
|
|
|
d->m_findToolBar->setUseFakeVim(on);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
void Find::openFindToolBar(FindDirection direction)
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
|
|
|
|
if (d->m_findToolBar) {
|
|
|
|
|
d->m_findToolBar->setBackward(direction == FindBackwardDirection);
|
|
|
|
|
d->m_findToolBar->openFindToolBar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 16:40:45 +01:00
|
|
|
QAbstractListModel *Find::findCompletionModel()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
return &(d->m_findCompletionModel);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 19:12:07 +01:00
|
|
|
QStringListModel *Find::replaceCompletionModel()
|
2014-01-13 16:17:34 +01:00
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
return &(d->m_replaceCompletionModel);
|
2014-01-13 16:17:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|