forked from qt-creator/qt-creator
Vcs: Use PagedSettings for common settings
Also restrict the Reset VCS Cache button to the second column, as it was earlier. Change-Id: I291fdceb11df4ecdfdc0887fd521288d0b4544f3 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -6,18 +6,13 @@
|
|||||||
#include "vcsbaseconstants.h"
|
#include "vcsbaseconstants.h"
|
||||||
#include "vcsbasetr.h"
|
#include "vcsbasetr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/iversioncontrol.h>
|
|
||||||
#include <coreplugin/vcsmanager.h>
|
#include <coreplugin/vcsmanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
#include <QDebug>
|
using namespace Core;
|
||||||
#include <QPushButton>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace VcsBase::Internal {
|
namespace VcsBase::Internal {
|
||||||
@@ -33,10 +28,24 @@ static QString sshPasswordPromptDefault()
|
|||||||
return QLatin1String("ssh-askpass");
|
return QLatin1String("ssh-askpass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CommonVcsSettings *s_instance;
|
||||||
|
|
||||||
|
CommonVcsSettings &commonSettings()
|
||||||
|
{
|
||||||
|
return *s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
CommonVcsSettings::CommonVcsSettings()
|
CommonVcsSettings::CommonVcsSettings()
|
||||||
{
|
{
|
||||||
|
s_instance = this;
|
||||||
|
|
||||||
setSettingsGroup("VCS");
|
setSettingsGroup("VCS");
|
||||||
setAutoApply(false);
|
setId(Constants::VCS_COMMON_SETTINGS_ID);
|
||||||
|
setDisplayName(Tr::tr("General"));
|
||||||
|
setCategory(Constants::VCS_SETTINGS_CATEGORY);
|
||||||
|
// The following act as blueprint for other pages in the same category:
|
||||||
|
setDisplayCategory(Tr::tr("Version Control"));
|
||||||
|
setCategoryIconPath(":/vcsbase/images/settingscategory_vcs.png");
|
||||||
|
|
||||||
nickNameMailMap.setSettingsKey("NickNameMailMap");
|
nickNameMailMap.setSettingsKey("NickNameMailMap");
|
||||||
nickNameMailMap.setExpectedKind(PathChooser::File);
|
nickNameMailMap.setExpectedKind(PathChooser::File);
|
||||||
@@ -76,69 +85,37 @@ CommonVcsSettings::CommonVcsSettings()
|
|||||||
lineWrapWidth.setSettingsKey("LineWrapWidth");
|
lineWrapWidth.setSettingsKey("LineWrapWidth");
|
||||||
lineWrapWidth.setSuffix(Tr::tr(" characters"));
|
lineWrapWidth.setSuffix(Tr::tr(" characters"));
|
||||||
lineWrapWidth.setDefaultValue(72);
|
lineWrapWidth.setDefaultValue(72);
|
||||||
}
|
|
||||||
|
|
||||||
// CommonSettingsWidget
|
setLayouter([this] {
|
||||||
|
using namespace Layouting;
|
||||||
|
return Column {
|
||||||
|
Row { lineWrap, lineWrapWidth, st },
|
||||||
|
Form {
|
||||||
|
submitMessageCheckScript, br,
|
||||||
|
nickNameMailMap, br,
|
||||||
|
nickNameFieldListFile, br,
|
||||||
|
sshPasswordPrompt, br,
|
||||||
|
empty,
|
||||||
|
PushButton {
|
||||||
|
text(Tr::tr("Reset VCS Cache")),
|
||||||
|
tooltip(Tr::tr("Reset information about which "
|
||||||
|
"version control system handles which directory.")),
|
||||||
|
onClicked(&VcsManager::clearVersionControlCache)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
class CommonSettingsWidget final : public Core::IOptionsPageWidget
|
auto updatePath = [this] {
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommonSettingsWidget(CommonOptionsPage *page)
|
|
||||||
{
|
|
||||||
CommonVcsSettings &s = page->settings();
|
|
||||||
|
|
||||||
auto cacheResetButton = new QPushButton(Tr::tr("Reset VCS Cache"));
|
|
||||||
cacheResetButton->setToolTip(Tr::tr("Reset information about which "
|
|
||||||
"version control system handles which directory."));
|
|
||||||
|
|
||||||
auto updatePath = [&s] {
|
|
||||||
Environment env;
|
Environment env;
|
||||||
env.appendToPath(Core::VcsManager::additionalToolsPath());
|
env.appendToPath(VcsManager::additionalToolsPath());
|
||||||
s.sshPasswordPrompt.setEnvironment(env);
|
sshPasswordPrompt.setEnvironment(env);
|
||||||
};
|
};
|
||||||
|
|
||||||
using namespace Layouting;
|
|
||||||
Column {
|
|
||||||
Row { s.lineWrap, s.lineWrapWidth, st },
|
|
||||||
Form {
|
|
||||||
s.submitMessageCheckScript, br,
|
|
||||||
s.nickNameMailMap, br,
|
|
||||||
s.nickNameFieldListFile, br,
|
|
||||||
s.sshPasswordPrompt, br,
|
|
||||||
{}, cacheResetButton
|
|
||||||
}
|
|
||||||
}.attachTo(this);
|
|
||||||
|
|
||||||
updatePath();
|
updatePath();
|
||||||
|
connect(VcsManager::instance(), &VcsManager::configurationChanged, this, updatePath);
|
||||||
|
|
||||||
connect(Core::VcsManager::instance(), &Core::VcsManager::configurationChanged,
|
readSettings();
|
||||||
this, updatePath);
|
|
||||||
connect(cacheResetButton, &QPushButton::clicked,
|
|
||||||
Core::VcsManager::instance(), &Core::VcsManager::clearVersionControlCache);
|
|
||||||
|
|
||||||
setOnApply([&s] {
|
|
||||||
if (s.isDirty()) {
|
|
||||||
s.apply();
|
|
||||||
s.writeSettings(Core::ICore::settings());
|
|
||||||
emit s.settingsChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// CommonOptionsPage
|
|
||||||
|
|
||||||
CommonOptionsPage::CommonOptionsPage()
|
|
||||||
{
|
|
||||||
m_settings.readSettings(Core::ICore::settings());
|
|
||||||
|
|
||||||
setId(Constants::VCS_COMMON_SETTINGS_ID);
|
|
||||||
setDisplayName(Tr::tr("General"));
|
|
||||||
setCategory(Constants::VCS_SETTINGS_CATEGORY);
|
|
||||||
// The following act as blueprint for other pages in the same category:
|
|
||||||
setDisplayCategory(Tr::tr("Version Control"));
|
|
||||||
setCategoryIconPath(":/vcsbase/images/settingscategory_vcs.png");
|
|
||||||
setWidgetCreator([this] { return new CommonSettingsWidget(this); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // VcsBase::Internal
|
} // VcsBase::Internal
|
||||||
|
|||||||
@@ -4,15 +4,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
#include <coreplugin/iversioncontrol.h>
|
||||||
#include <utils/aspects.h>
|
|
||||||
|
|
||||||
namespace VcsBase::Internal {
|
namespace VcsBase::Internal {
|
||||||
|
|
||||||
class CommonVcsSettings : public Utils::AspectContainer
|
class CommonVcsSettings : public Core::PagedSettings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommonVcsSettings();
|
CommonVcsSettings();
|
||||||
|
|
||||||
@@ -26,20 +23,8 @@ public:
|
|||||||
|
|
||||||
Utils::BoolAspect lineWrap{this};
|
Utils::BoolAspect lineWrap{this};
|
||||||
Utils::IntegerAspect lineWrapWidth{this};
|
Utils::IntegerAspect lineWrapWidth{this};
|
||||||
|
|
||||||
signals:
|
|
||||||
void settingsChanged();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CommonOptionsPage final : public Core::IOptionsPage
|
CommonVcsSettings &commonSettings();
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommonOptionsPage();
|
|
||||||
|
|
||||||
CommonVcsSettings &settings() { return m_settings; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CommonVcsSettings m_settings;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // VcsBase::Internal
|
} // VcsBase::Internal
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ FilePath source(IDocument *document)
|
|||||||
|
|
||||||
void setProcessEnvironment(Environment *e)
|
void setProcessEnvironment(Environment *e)
|
||||||
{
|
{
|
||||||
const QString prompt = Internal::VcsPlugin::instance()->settings().sshPasswordPrompt.value();
|
const QString prompt = Internal::commonSettings().sshPasswordPrompt().path();
|
||||||
if (!prompt.isEmpty())
|
if (!prompt.isEmpty())
|
||||||
e->set("SSH_ASKPASS", prompt);
|
e->set("SSH_ASKPASS", prompt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,11 +103,6 @@ namespace VcsBase {
|
|||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
static inline QString submitMessageCheckScript()
|
|
||||||
{
|
|
||||||
return VcsPlugin::instance()->settings().submitMessageCheckScript.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
class VcsBaseSubmitEditorPrivate
|
class VcsBaseSubmitEditorPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -176,15 +171,15 @@ void VcsBaseSubmitEditor::setParameters(const VcsBaseSubmitEditorParameters &par
|
|||||||
connect(descriptionEdit, &QTextEdit::textChanged,
|
connect(descriptionEdit, &QTextEdit::textChanged,
|
||||||
this, &VcsBaseSubmitEditor::fileContentsChanged);
|
this, &VcsBaseSubmitEditor::fileContentsChanged);
|
||||||
|
|
||||||
const CommonVcsSettings &settings = VcsPlugin::instance()->settings();
|
const CommonVcsSettings &settings = commonSettings();
|
||||||
// Add additional context menu settings
|
// Add additional context menu settings
|
||||||
if (!settings.submitMessageCheckScript.value().isEmpty()
|
if (!settings.submitMessageCheckScript().isEmpty()
|
||||||
|| !settings.nickNameMailMap.value().isEmpty()) {
|
|| !settings.nickNameMailMap.value().isEmpty()) {
|
||||||
auto sep = new QAction(this);
|
auto sep = new QAction(this);
|
||||||
sep->setSeparator(true);
|
sep->setSeparator(true);
|
||||||
d->m_widget->addDescriptionEditContextMenuAction(sep);
|
d->m_widget->addDescriptionEditContextMenuAction(sep);
|
||||||
// Run check action
|
// Run check action
|
||||||
if (!settings.submitMessageCheckScript.value().isEmpty()) {
|
if (!settings.submitMessageCheckScript().isEmpty()) {
|
||||||
auto checkAction = new QAction(Tr::tr("Check Message"), this);
|
auto checkAction = new QAction(Tr::tr("Check Message"), this);
|
||||||
connect(checkAction, &QAction::triggered,
|
connect(checkAction, &QAction::triggered,
|
||||||
this, &VcsBaseSubmitEditor::slotCheckSubmitMessage);
|
this, &VcsBaseSubmitEditor::slotCheckSubmitMessage);
|
||||||
@@ -203,7 +198,7 @@ void VcsBaseSubmitEditor::setParameters(const VcsBaseSubmitEditorParameters &par
|
|||||||
|
|
||||||
// wrapping. etc
|
// wrapping. etc
|
||||||
slotUpdateEditorSettings();
|
slotUpdateEditorSettings();
|
||||||
connect(VcsPlugin::instance(), &VcsPlugin::settingsChanged,
|
connect(&settings, &CommonVcsSettings::changed,
|
||||||
this, &VcsBaseSubmitEditor::slotUpdateEditorSettings);
|
this, &VcsBaseSubmitEditor::slotUpdateEditorSettings);
|
||||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||||
this, [this] {
|
this, [this] {
|
||||||
@@ -229,9 +224,8 @@ VcsBaseSubmitEditor::~VcsBaseSubmitEditor()
|
|||||||
|
|
||||||
void VcsBaseSubmitEditor::slotUpdateEditorSettings()
|
void VcsBaseSubmitEditor::slotUpdateEditorSettings()
|
||||||
{
|
{
|
||||||
const CommonVcsSettings &s = VcsPlugin::instance()->settings();
|
setLineWrapWidth(commonSettings().lineWrapWidth());
|
||||||
setLineWrapWidth(s.lineWrapWidth());
|
setLineWrap(commonSettings().lineWrap());
|
||||||
setLineWrap(s.lineWrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a trimmed list of non-empty field texts
|
// Return a trimmed list of non-empty field texts
|
||||||
@@ -527,7 +521,7 @@ void VcsBaseSubmitEditor::slotCheckSubmitMessage()
|
|||||||
|
|
||||||
bool VcsBaseSubmitEditor::checkSubmitMessage(QString *errorMessage) const
|
bool VcsBaseSubmitEditor::checkSubmitMessage(QString *errorMessage) const
|
||||||
{
|
{
|
||||||
const QString checkScript = submitMessageCheckScript();
|
const QString checkScript = commonSettings().submitMessageCheckScript.value();
|
||||||
if (checkScript.isEmpty())
|
if (checkScript.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public:
|
|||||||
explicit VcsPluginPrivate(VcsPlugin *plugin)
|
explicit VcsPluginPrivate(VcsPlugin *plugin)
|
||||||
: q(plugin)
|
: q(plugin)
|
||||||
{
|
{
|
||||||
QObject::connect(&m_settingsPage.settings(), &CommonVcsSettings::settingsChanged,
|
QObject::connect(&m_settings, &AspectContainer::changed,
|
||||||
[this] { slotSettingsChanged(); });
|
[this] { slotSettingsChanged(); });
|
||||||
slotSettingsChanged();
|
slotSettingsChanged();
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
void populateNickNameModel()
|
void populateNickNameModel()
|
||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
if (!NickNameDialog::populateModelFromMailCapFile(m_settingsPage.settings().nickNameMailMap.filePath(),
|
if (!NickNameDialog::populateModelFromMailCapFile(m_settings.nickNameMailMap(),
|
||||||
m_nickNameModel,
|
m_nickNameModel,
|
||||||
&errorMessage)) {
|
&errorMessage)) {
|
||||||
qWarning("%s", qPrintable(errorMessage));
|
qWarning("%s", qPrintable(errorMessage));
|
||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
VcsPlugin *q;
|
VcsPlugin *q;
|
||||||
CommonOptionsPage m_settingsPage;
|
CommonVcsSettings m_settings;
|
||||||
QStandardItemModel *m_nickNameModel = nullptr;
|
QStandardItemModel *m_nickNameModel = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,9 +101,6 @@ void VcsPlugin::initialize()
|
|||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&d->m_settingsPage.settings(), &CommonVcsSettings::settingsChanged,
|
|
||||||
this, &VcsPlugin::settingsChanged);
|
|
||||||
|
|
||||||
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
|
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
|
||||||
JsonWizardFactory::registerPageFactory(new Internal::VcsCommandPageFactory);
|
JsonWizardFactory::registerPageFactory(new Internal::VcsCommandPageFactory);
|
||||||
|
|
||||||
@@ -146,11 +143,6 @@ VcsPlugin *VcsPlugin::instance()
|
|||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonVcsSettings &VcsPlugin::settings() const
|
|
||||||
{
|
|
||||||
return d->m_settingsPage.settings();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Delayed creation/update of the nick name model. */
|
/* Delayed creation/update of the nick name model. */
|
||||||
QStandardItemModel *VcsPlugin::nickNameModel()
|
QStandardItemModel *VcsPlugin::nickNameModel()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ class VcsBaseSubmitEditor;
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CommonVcsSettings;
|
|
||||||
|
|
||||||
class VcsPlugin : public ExtensionSystem::IPlugin
|
class VcsPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -30,15 +28,12 @@ public:
|
|||||||
|
|
||||||
static VcsPlugin *instance();
|
static VcsPlugin *instance();
|
||||||
|
|
||||||
CommonVcsSettings &settings() const;
|
|
||||||
|
|
||||||
// Model of user nick names used for the submit
|
// Model of user nick names used for the submit
|
||||||
// editor. Stored centrally here to achieve delayed
|
// editor. Stored centrally here to achieve delayed
|
||||||
// initialization and updating on settings change.
|
// initialization and updating on settings change.
|
||||||
QStandardItemModel *nickNameModel();
|
QStandardItemModel *nickNameModel();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged();
|
|
||||||
void submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *e, bool *result);
|
void submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *e, bool *result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user