Fossil: Consolidate optionpage/apply further

Change-Id: I345c6f38421864630d99a45fd2176ba0836536e9
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2023-05-15 10:24:35 +02:00
parent fe74e6d43b
commit e6d574ee77
3 changed files with 55 additions and 72 deletions

View File

@@ -190,7 +190,7 @@ public:
FossilSettings m_fossilSettings; FossilSettings m_fossilSettings;
FossilClient m_client{&m_fossilSettings}; FossilClient m_client{&m_fossilSettings};
OptionsPage optionPage{[this] { configurationChanged(); }, &m_fossilSettings}; OptionsPage optionPage{&m_fossilSettings};
VcsSubmitEditorFactory submitEditorFactory { VcsSubmitEditorFactory submitEditorFactory {
submitEditorParameters, submitEditorParameters,
@@ -300,6 +300,9 @@ FossilPluginPrivate::FossilPluginPrivate()
return new FossilJsExtension(&m_fossilSettings); return new FossilJsExtension(&m_fossilSettings);
}); });
connect(&m_fossilSettings, &AspectContainer::changed,
this, &IVersionControl::configurationChanged);
createMenu(context); createMenu(context);
} }

View File

@@ -15,8 +15,7 @@
using namespace Utils; using namespace Utils;
namespace Fossil { namespace Fossil::Internal {
namespace Internal {
FossilSettings::FossilSettings() FossilSettings::FossilSettings()
{ {
@@ -95,80 +94,63 @@ FossilSettings::FossilSettings()
logCount.setLabelText(Tr::tr("Log count:")); logCount.setLabelText(Tr::tr("Log count:"));
logCount.setToolTip(Tr::tr("The number of recent commit log entries to show. " logCount.setToolTip(Tr::tr("The number of recent commit log entries to show. "
"Choose 0 to see all entries.")); "Choose 0 to see all entries."));
}; }
// OptionsPage // OptionsPage
class OptionsPageWidget final : public Core::IOptionsPageWidget class OptionsPageWidget final : public Core::IOptionsPageWidget
{ {
public: public:
OptionsPageWidget(const std::function<void()> &onApply, FossilSettings *settings); OptionsPageWidget(FossilSettings *settings)
void apply() final; {
FossilSettings &s = *settings;
private: using namespace Layouting;
const std::function<void()> m_onApply;
FossilSettings *m_settings; Column {
Group {
title(Tr::tr("Configuration")),
Row { s.binaryPath }
},
Group {
title(Tr::tr("Local Repositories")),
Row { s.defaultRepoPath }
},
Group {
title(Tr::tr("User")),
Form {
s.userName, br,
s.sslIdentityFile
}
},
Group {
title(Tr::tr("Miscellaneous")),
Column {
Row {
s.logCount,
s.timelineWidth,
s.timeout,
st
},
s.disableAutosync
},
},
st
}.attachTo(this);
setOnApply([settings] { settings->apply(); });
}
}; };
void OptionsPageWidget::apply() OptionsPage::OptionsPage(FossilSettings *settings)
{
if (!m_settings->isDirty())
return;
m_settings->apply();
m_onApply();
}
OptionsPageWidget::OptionsPageWidget(const std::function<void()> &onApply, FossilSettings *settings) :
m_onApply(onApply),
m_settings(settings)
{
FossilSettings &s = *m_settings;
using namespace Layouting;
Column {
Group {
title(Tr::tr("Configuration")),
Row { s.binaryPath }
},
Group {
title(Tr::tr("Local Repositories")),
Row { s.defaultRepoPath }
},
Group {
title(Tr::tr("User")),
Form {
s.userName, br,
s.sslIdentityFile
}
},
Group {
title(Tr::tr("Miscellaneous")),
Column {
Row {
s.logCount,
s.timelineWidth,
s.timeout,
st
},
s.disableAutosync
},
},
st
}.attachTo(this);
}
OptionsPage::OptionsPage(const std::function<void()> &onApply, FossilSettings *settings)
{ {
setId(Constants::VCS_ID_FOSSIL); setId(Constants::VCS_ID_FOSSIL);
setDisplayName(Tr::tr("Fossil")); setDisplayName(Tr::tr("Fossil"));
setWidgetCreator([onApply, settings]() { return new OptionsPageWidget(onApply, settings); }); setWidgetCreator([settings] { return new OptionsPageWidget(settings); });
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY); setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
} }
} // Internal } // Fossil::Internal
} // Fossil

View File

@@ -6,12 +6,13 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <vcsbase/vcsbaseclientsettings.h> #include <vcsbase/vcsbaseclientsettings.h>
namespace Fossil { namespace Fossil::Internal {
namespace Internal {
class FossilSettings : public VcsBase::VcsBaseSettings class FossilSettings : public VcsBase::VcsBaseSettings
{ {
public: public:
FossilSettings();
Utils::StringAspect defaultRepoPath; Utils::StringAspect defaultRepoPath;
Utils::StringAspect sslIdentityFile; Utils::StringAspect sslIdentityFile;
Utils::BoolAspect diffIgnoreAllWhiteSpace; Utils::BoolAspect diffIgnoreAllWhiteSpace;
@@ -23,8 +24,6 @@ public:
Utils::BoolAspect timelineVerbose; Utils::BoolAspect timelineVerbose;
Utils::StringAspect timelineItemType; Utils::StringAspect timelineItemType;
Utils::BoolAspect disableAutosync; Utils::BoolAspect disableAutosync;
FossilSettings();
}; };
struct RepositorySettings struct RepositorySettings
@@ -46,8 +45,7 @@ inline bool operator==(const RepositorySettings &lh, const RepositorySettings &r
class OptionsPage : public Core::IOptionsPage class OptionsPage : public Core::IOptionsPage
{ {
public: public:
OptionsPage(const std::function<void()> &onApply, FossilSettings *settings); explicit OptionsPage(FossilSettings *settings);
}; };
} // namespace Internal } // Fossil::Internal
} // namespace Fossil