FakeVim: Delay settings creation until actual use

Task-number: QTCREATORBUG-29167
Change-Id: I3a6f1330922f3840cb7e99d8adb60a728d36eb4b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-07-07 12:13:07 +02:00
parent 6a068a6509
commit 2c512625c5
3 changed files with 38 additions and 34 deletions

View File

@@ -45,29 +45,15 @@ void setAutoApply(bool ) {}
#endif
static FakeVimSettings *s_settings;
FakeVimSettings &settings()
{
return *s_settings;
static FakeVimSettings theSettings;
return theSettings;
}
FakeVimSettings::FakeVimSettings()
{
s_settings = this;
#ifndef FAKEVIM_STANDALONE
const char SETTINGS_CATEGORY[] = "D.FakeVim";
const char SETTINGS_ID[] = "A.FakeVim.General";
setId(SETTINGS_ID);
setDisplayName(Tr::tr("General"));
setCategory(SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIconPath(":/fakevim/images/settingscategory_fakevim.png");
setup(&useFakeVim, false, "UseFakeVim", {}, Tr::tr("Use FakeVim"));
#endif
// Specific FakeVim settings
setup(&readVimRc, false, "ReadVimRc", {}, Tr::tr("Read .vimrc from location:"));
@@ -303,4 +289,27 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
m_nameToAspect[shortName] = aspect;
}
#ifndef FAKEVIM_STANDALONE
class FakeVimSettingsPage final : public Core::IOptionsPage
{
public:
FakeVimSettingsPage()
{
const char SETTINGS_CATEGORY[] = "D.FakeVim";
const char SETTINGS_ID[] = "A.FakeVim.General";
setId(SETTINGS_ID);
setDisplayName(Tr::tr("General"));
setCategory(SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIconPath(":/fakevim/images/settingscategory_fakevim.png");
setSettingsProvider([] { return &settings(); });
}
};
const FakeVimSettingsPage settingsPage;
#endif
} // FakeVim::Internal

View File

@@ -28,10 +28,10 @@ public:
FvBaseAspect() = default;
virtual ~FvBaseAspect() = default;
virtual void setVariantValue(const QVariant &value) = 0;
virtual void setDefaultVariantValue(const QVariant &value) = 0;
virtual QVariant variantValue() const = 0;
virtual QVariant defaultVariantValue() const = 0;
virtual void setVariantValue(const QVariant &) {}
virtual void setDefaultVariantValue(const QVariant &) {}
virtual QVariant variantValue() const { return {}; }
virtual QVariant defaultVariantValue() const { return {}; }
void setSettingsKey(const QString &group, const QString &key);
QString settingsKey() const;
@@ -84,7 +84,7 @@ public:
#else
using FvAspectContainer = Core::PagedSettings;
using FvAspectContainer = Utils::AspectContainer;
using FvBaseAspect = Utils::BaseAspect;
using FvBoolAspect = Utils::BoolAspect;
using FvIntegerAspect = Utils::IntegerAspect;

View File

@@ -683,6 +683,8 @@ public:
}
};
const FakeVimExCommandsPage exCommandPage;
///////////////////////////////////////////////////////////////////////
//
// FakeVimUserCommandsPage
@@ -752,11 +754,10 @@ public:
class FakeVimUserCommandsPageWidget : public IOptionsPageWidget
{
public:
FakeVimUserCommandsPageWidget(FakeVimUserCommandsModel *model)
: m_model(model)
FakeVimUserCommandsPageWidget()
{
auto widget = new QTreeView;
widget->setModel(m_model);
widget->setModel(&m_model);
widget->resizeColumnToContents(0);
auto delegate = new FakeVimUserCommandsDelegate(widget);
@@ -771,7 +772,7 @@ private:
void apply() final
{
// now save the mappings if necessary
const UserCommandMap &current = m_model->commandMap();
const UserCommandMap &current = m_model.commandMap();
UserCommandMap &userMap = dd->m_userCommandMap;
if (current != userMap) {
@@ -800,7 +801,7 @@ private:
}
}
FakeVimUserCommandsModel *m_model;
FakeVimUserCommandsModel m_model;
};
class FakeVimUserCommandsPage : public IOptionsPage
@@ -811,13 +812,11 @@ public:
setId(SETTINGS_USER_CMDS_ID);
setDisplayName(Tr::tr("User Command Mapping"));
setCategory(SETTINGS_CATEGORY);
setWidgetCreator([this] { return new FakeVimUserCommandsPageWidget(&m_model); });
setWidgetCreator([this] { return new FakeVimUserCommandsPageWidget; });
}
private:
FakeVimUserCommandsModel m_model;
};
const FakeVimUserCommandsPage userCommandsPage;
///////////////////////////////////////////////////////////////////////
//
@@ -978,10 +977,6 @@ IAssistProcessor *FakeVimCompletionAssistProvider::createProcessor(const AssistI
class FakeVimPluginRunData
{
public:
FakeVimSettings settings;
FakeVimExCommandsPage exCommandsPage;
FakeVimUserCommandsPage userCommandsPage;
FakeVimCompletionAssistProvider wordProvider;
};