forked from qt-creator/qt-creator
Find: Save settings in session
Usually the directories and search terms relate to the project(s) worked on, so save them in the session. Fixes: QTCREATORBUG-793 Change-Id: Ia00597a91fa3a902d6b8b4f2d8cb93634cdc333c Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3,12 +3,6 @@
|
|||||||
|
|
||||||
#include "findplugin.h"
|
#include "findplugin.h"
|
||||||
|
|
||||||
#include "currentdocumentfind.h"
|
|
||||||
#include "findtoolbar.h"
|
|
||||||
#include "findtoolwindow.h"
|
|
||||||
#include "ifindfilter.h"
|
|
||||||
#include "searchresultwindow.h"
|
|
||||||
#include "textfindconstants.h"
|
|
||||||
#include "../actionmanager/actioncontainer.h"
|
#include "../actionmanager/actioncontainer.h"
|
||||||
#include "../actionmanager/actionmanager.h"
|
#include "../actionmanager/actionmanager.h"
|
||||||
#include "../actionmanager/command.h"
|
#include "../actionmanager/command.h"
|
||||||
@@ -16,6 +10,13 @@
|
|||||||
#include "../coreplugintr.h"
|
#include "../coreplugintr.h"
|
||||||
#include "../icontext.h"
|
#include "../icontext.h"
|
||||||
#include "../icore.h"
|
#include "../icore.h"
|
||||||
|
#include "../session.h"
|
||||||
|
#include "currentdocumentfind.h"
|
||||||
|
#include "findtoolbar.h"
|
||||||
|
#include "findtoolwindow.h"
|
||||||
|
#include "ifindfilter.h"
|
||||||
|
#include "searchresultwindow.h"
|
||||||
|
#include "textfindconstants.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
@@ -75,6 +76,10 @@ public:
|
|||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
void restore(const Store &s);
|
||||||
|
Store save() const;
|
||||||
|
|
||||||
|
// TODO deprecated since QtC 14.0
|
||||||
void writeSettings(QtcSettings *settings) const;
|
void writeSettings(QtcSettings *settings) const;
|
||||||
void readSettings(QtcSettings *settings);
|
void readSettings(QtcSettings *settings);
|
||||||
|
|
||||||
@@ -105,6 +110,41 @@ static Utils::Key completionSettingsArrayPrefix() { return "FindCompletions"; }
|
|||||||
static Utils::Key completionSettingsTextKey() { return "Text"; }
|
static Utils::Key completionSettingsTextKey() { return "Text"; }
|
||||||
static Utils::Key completionSettingsFlagsKey() { return "Flags"; }
|
static Utils::Key completionSettingsFlagsKey() { return "Flags"; }
|
||||||
|
|
||||||
|
void CompletionModel::restore(const Store &s)
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
const QStringList texts = s.value(completionSettingsTextKey()).toStringList();
|
||||||
|
const QList<FindFlags> flags
|
||||||
|
= transform(s.value(completionSettingsFlagsKey()).toList(), [](const QVariant &v) {
|
||||||
|
return FindFlags(v.toInt());
|
||||||
|
});
|
||||||
|
const int size = texts.size();
|
||||||
|
m_entries.clear();
|
||||||
|
m_entries.reserve(size);
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
CompletionEntry entry;
|
||||||
|
entry.text = texts.at(i);
|
||||||
|
entry.findFlags = i < flags.size() ? flags.at(i) : FindFlags();
|
||||||
|
if (!entry.text.isEmpty())
|
||||||
|
m_entries.append(entry);
|
||||||
|
}
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
Store CompletionModel::save() const
|
||||||
|
{
|
||||||
|
if (m_entries.isEmpty())
|
||||||
|
return {};
|
||||||
|
const QStringList texts = transform(m_entries, [](const CompletionEntry &e) { return e.text; });
|
||||||
|
const QVariantList flags = transform(m_entries, [](const CompletionEntry &e) {
|
||||||
|
return QVariant::fromValue(int(e.findFlags));
|
||||||
|
});
|
||||||
|
Store s;
|
||||||
|
s.insert(completionSettingsTextKey(), texts);
|
||||||
|
s.insert(completionSettingsFlagsKey(), flags);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void CompletionModel::writeSettings(QtcSettings *settings) const
|
void CompletionModel::writeSettings(QtcSettings *settings) const
|
||||||
{
|
{
|
||||||
if (m_entries.isEmpty()) {
|
if (m_entries.isEmpty()) {
|
||||||
@@ -215,13 +255,20 @@ void Find::initialize()
|
|||||||
d->m_findDialog = new Internal::FindToolWindow;
|
d->m_findDialog = new Internal::FindToolWindow;
|
||||||
d->m_searchResultWindow = new SearchResultWindow(d->m_findDialog);
|
d->m_searchResultWindow = new SearchResultWindow(d->m_findDialog);
|
||||||
ExtensionSystem::PluginManager::addObject(d->m_searchResultWindow);
|
ExtensionSystem::PluginManager::addObject(d->m_searchResultWindow);
|
||||||
|
|
||||||
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, d, &FindPrivate::writeSettings);
|
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, d, &FindPrivate::writeSettings);
|
||||||
|
QObject::connect(
|
||||||
|
SessionManager::instance(),
|
||||||
|
&SessionManager::aboutToSaveSession,
|
||||||
|
d,
|
||||||
|
&FindPrivate::writeSettings);
|
||||||
|
QObject::connect(
|
||||||
|
SessionManager::instance(), &SessionManager::sessionLoaded, d, &FindPrivate::readSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Find::extensionsInitialized()
|
void Find::extensionsInitialized()
|
||||||
{
|
{
|
||||||
d->setupFilterMenuItems();
|
d->setupFilterMenuItems();
|
||||||
d->readSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Find::aboutToShutdown()
|
void Find::aboutToShutdown()
|
||||||
@@ -369,6 +416,8 @@ bool Find::hasFindFlag(FindFlag flag)
|
|||||||
|
|
||||||
void FindPrivate::writeSettings()
|
void FindPrivate::writeSettings()
|
||||||
{
|
{
|
||||||
|
// TODO for backwards compatibility
|
||||||
|
// deprecated since QtC 14.0
|
||||||
QtcSettings *settings = ICore::settings();
|
QtcSettings *settings = ICore::settings();
|
||||||
settings->beginGroup("Find");
|
settings->beginGroup("Find");
|
||||||
settings->setValueWithDefault("Backward", bool(m_findFlags & FindBackward), false);
|
settings->setValueWithDefault("Backward", bool(m_findFlags & FindBackward), false);
|
||||||
@@ -384,26 +433,70 @@ void FindPrivate::writeSettings()
|
|||||||
m_findToolBar->writeSettings();
|
m_findToolBar->writeSettings();
|
||||||
m_findDialog->writeSettings();
|
m_findDialog->writeSettings();
|
||||||
m_searchResultWindow->writeSettings();
|
m_searchResultWindow->writeSettings();
|
||||||
|
|
||||||
|
// save in session
|
||||||
|
Store s;
|
||||||
|
if (m_findFlags & FindBackward)
|
||||||
|
s.insert("Backward", true);
|
||||||
|
if (m_findFlags & FindCaseSensitively)
|
||||||
|
s.insert("CaseSensitively", true);
|
||||||
|
if (m_findFlags & FindWholeWords)
|
||||||
|
s.insert("WholeWords", true);
|
||||||
|
if (m_findFlags & FindRegularExpression)
|
||||||
|
s.insert("RegularExpression", true);
|
||||||
|
if (m_findFlags & FindPreserveCase)
|
||||||
|
s.insert("PreserveCase", true);
|
||||||
|
const Store completion = m_findCompletionModel.save();
|
||||||
|
if (!completion.isEmpty())
|
||||||
|
s.insert("FindCompletions", variantFromStore(completion));
|
||||||
|
if (!m_replaceCompletions.isEmpty())
|
||||||
|
s.insert("ReplaceStrings", m_replaceCompletions);
|
||||||
|
const Store toolbar = m_findToolBar->save();
|
||||||
|
if (!toolbar.isEmpty())
|
||||||
|
s.insert("ToolBar", variantFromStore(toolbar));
|
||||||
|
const Store advanced = m_findDialog->save();
|
||||||
|
if (!advanced.isEmpty())
|
||||||
|
s.insert("AdvancedSearch", variantFromStore(advanced));
|
||||||
|
SessionManager::setValue("Find", variantFromStore(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindPrivate::readSettings()
|
void FindPrivate::readSettings()
|
||||||
{
|
{
|
||||||
QtcSettings *settings = ICore::settings();
|
const Store s = storeFromVariant(SessionManager::value("Find"));
|
||||||
settings->beginGroup("Find");
|
if (s.isEmpty() && SessionManager::isDefaultVirgin()) {
|
||||||
{
|
// TODO compatibility path when opening Qt Creator
|
||||||
QSignalBlocker blocker(m_instance);
|
// TODO deprecated since QtC 14.0
|
||||||
Find::setBackward(settings->value("Backward", false).toBool());
|
QtcSettings *settings = ICore::settings();
|
||||||
Find::setCaseSensitive(settings->value("CaseSensitively", false).toBool());
|
settings->beginGroup("Find");
|
||||||
Find::setWholeWord(settings->value("WholeWords", false).toBool());
|
{
|
||||||
Find::setRegularExpression(settings->value("RegularExpression", false).toBool());
|
QSignalBlocker blocker(m_instance);
|
||||||
Find::setPreserveCase(settings->value("PreserveCase", false).toBool());
|
Find::setBackward(settings->value("Backward", false).toBool());
|
||||||
|
Find::setCaseSensitive(settings->value("CaseSensitively", false).toBool());
|
||||||
|
Find::setWholeWord(settings->value("WholeWords", false).toBool());
|
||||||
|
Find::setRegularExpression(settings->value("RegularExpression", false).toBool());
|
||||||
|
Find::setPreserveCase(settings->value("PreserveCase", false).toBool());
|
||||||
|
}
|
||||||
|
m_findCompletionModel.readSettings(settings);
|
||||||
|
m_replaceCompletions = settings->value("ReplaceStrings").toStringList();
|
||||||
|
m_replaceCompletionModel.setStringList(m_replaceCompletions);
|
||||||
|
settings->endGroup();
|
||||||
|
m_findToolBar->readSettings();
|
||||||
|
m_findDialog->readSettings();
|
||||||
|
} else if (!s.empty()) {
|
||||||
|
{
|
||||||
|
QSignalBlocker blocker(m_instance);
|
||||||
|
Find::setBackward(s.value("Backward", false).toBool());
|
||||||
|
Find::setCaseSensitive(s.value("CaseSensitively", false).toBool());
|
||||||
|
Find::setWholeWord(s.value("WholeWords", false).toBool());
|
||||||
|
Find::setRegularExpression(s.value("RegularExpression", false).toBool());
|
||||||
|
Find::setPreserveCase(s.value("PreserveCase", false).toBool());
|
||||||
|
}
|
||||||
|
m_findCompletionModel.restore(storeFromVariant(s.value("FindCompletions")));
|
||||||
|
m_replaceCompletions = s.value("ReplaceStrings").toStringList();
|
||||||
|
m_replaceCompletionModel.setStringList(m_replaceCompletions);
|
||||||
|
m_findToolBar->restore(storeFromVariant(s.value("ToolBar")));
|
||||||
|
m_findDialog->restore(storeFromVariant(s.value("AdvancedSearch")));
|
||||||
}
|
}
|
||||||
m_findCompletionModel.readSettings(settings);
|
|
||||||
m_replaceCompletions = settings->value("ReplaceStrings").toStringList();
|
|
||||||
m_replaceCompletionModel.setStringList(m_replaceCompletions);
|
|
||||||
settings->endGroup();
|
|
||||||
m_findToolBar->readSettings();
|
|
||||||
m_findDialog->readSettings();
|
|
||||||
emit m_instance->findFlagsChanged(); // would have been done in the setXXX methods above
|
emit m_instance->findFlagsChanged(); // would have been done in the setXXX methods above
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1047,6 +1047,39 @@ void FindToolBar::resizeEvent(QResizeEvent *event)
|
|||||||
QMetaObject::invokeMethod(this, &FindToolBar::updateToolBar, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, &FindToolBar::updateToolBar, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FindToolBar::restore(const Store &s)
|
||||||
|
{
|
||||||
|
FindFlags flags;
|
||||||
|
if (s.value("Backward", false).toBool())
|
||||||
|
flags |= FindBackward;
|
||||||
|
if (s.value("CaseSensitively", false).toBool())
|
||||||
|
flags |= FindCaseSensitively;
|
||||||
|
if (s.value("WholeWords", false).toBool())
|
||||||
|
flags |= FindWholeWords;
|
||||||
|
if (s.value("RegularExpression", false).toBool())
|
||||||
|
flags |= FindRegularExpression;
|
||||||
|
if (s.value("PreserveCase", false).toBool())
|
||||||
|
flags |= FindPreserveCase;
|
||||||
|
m_findFlags = flags;
|
||||||
|
findFlagsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
Store FindToolBar::save() const
|
||||||
|
{
|
||||||
|
Store s;
|
||||||
|
if (m_findFlags & FindBackward)
|
||||||
|
s.insert("Backward", true);
|
||||||
|
if (m_findFlags & FindCaseSensitively)
|
||||||
|
s.insert("CaseSensitively", true);
|
||||||
|
if (m_findFlags & FindWholeWords)
|
||||||
|
s.insert("WholeWords", true);
|
||||||
|
if (m_findFlags & FindRegularExpression)
|
||||||
|
s.insert("RegularExpression", true);
|
||||||
|
if (m_findFlags & FindPreserveCase)
|
||||||
|
s.insert("PreserveCase", true);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void FindToolBar::writeSettings()
|
void FindToolBar::writeSettings()
|
||||||
{
|
{
|
||||||
Utils::QtcSettings *settings = ICore::settings();
|
Utils::QtcSettings *settings = ICore::settings();
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "currentdocumentfind.h"
|
#include "currentdocumentfind.h"
|
||||||
|
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
|
#include <utils/store.h>
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -18,7 +19,9 @@ class QSpacerItem;
|
|||||||
class QToolButton;
|
class QToolButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils { class FancyLineEdit; }
|
namespace Utils {
|
||||||
|
class FancyLineEdit;
|
||||||
|
} // namespace Utils
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
@@ -43,6 +46,10 @@ public:
|
|||||||
explicit FindToolBar(CurrentDocumentFind *currentDocumentFind);
|
explicit FindToolBar(CurrentDocumentFind *currentDocumentFind);
|
||||||
~FindToolBar() override;
|
~FindToolBar() override;
|
||||||
|
|
||||||
|
void restore(const Utils::Store &s);
|
||||||
|
Utils::Store save() const;
|
||||||
|
|
||||||
|
// TODO deprecated since QtC 14.0
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
|
@@ -346,6 +346,30 @@ void FindToolWindow::replace()
|
|||||||
filter->replaceAll(term, Find::findFlags());
|
filter->replaceAll(term, Find::findFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FindToolWindow::restore(const Utils::Store &s)
|
||||||
|
{
|
||||||
|
const QString currentFilter = s.value("CurrentFilter").toString();
|
||||||
|
for (int i = 0; i < m_filters.size(); ++i) {
|
||||||
|
IFindFilter *filter = m_filters.at(i);
|
||||||
|
filter->restore(storeFromVariant(s.value(filter->id().toUtf8())));
|
||||||
|
if (filter->id() == currentFilter)
|
||||||
|
setCurrentFilterIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Store FindToolWindow::save() const
|
||||||
|
{
|
||||||
|
Store s;
|
||||||
|
if (m_currentFilter && (m_filters.isEmpty() || m_filters.first() != m_currentFilter))
|
||||||
|
s.insert("CurrentFilter", m_currentFilter->id());
|
||||||
|
for (IFindFilter *filter : std::as_const(m_filters)) {
|
||||||
|
const Store store = filter->save();
|
||||||
|
if (!store.isEmpty())
|
||||||
|
s.insert(filter->id().toUtf8(), variantFromStore(store));
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void FindToolWindow::writeSettings()
|
void FindToolWindow::writeSettings()
|
||||||
{
|
{
|
||||||
Utils::QtcSettings *settings = ICore::settings();
|
Utils::QtcSettings *settings = ICore::settings();
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utils/store.h>
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
@@ -33,6 +35,11 @@ public:
|
|||||||
|
|
||||||
void setFindText(const QString &text);
|
void setFindText(const QString &text);
|
||||||
void setCurrentFilter(IFindFilter *filter);
|
void setCurrentFilter(IFindFilter *filter);
|
||||||
|
|
||||||
|
void restore(const Utils::Store &s);
|
||||||
|
Utils::Store save() const;
|
||||||
|
|
||||||
|
// TODO deprecated since QtC 14.0
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user