Mercurial: Aspectify settings

Change-Id: I689ce9a52124043e07472a1c95a3672f856232c3
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2021-03-19 14:12:25 +01:00
parent fb9796ae8a
commit 4a2a0f1037
10 changed files with 120 additions and 351 deletions

View File

@@ -11,7 +11,6 @@ add_qtc_plugin(Mercurial
mercurialeditor.cpp mercurialeditor.h
mercurialplugin.cpp mercurialplugin.h
mercurialsettings.cpp mercurialsettings.h
optionspage.cpp optionspage.h optionspage.ui
revertdialog.cpp revertdialog.h revertdialog.ui
srcdestdialog.cpp srcdestdialog.h srcdestdialog.ui
)

View File

@@ -1,6 +1,5 @@
include(../../qtcreatorplugin.pri)
SOURCES += mercurialplugin.cpp \
optionspage.cpp \
mercurialclient.cpp \
annotationhighlighter.cpp \
mercurialeditor.cpp \
@@ -12,7 +11,6 @@ SOURCES += mercurialplugin.cpp \
authenticationdialog.cpp
HEADERS += mercurialplugin.h \
constants.h \
optionspage.h \
mercurialclient.h \
annotationhighlighter.h \
mercurialeditor.h \
@@ -22,7 +20,7 @@ HEADERS += mercurialplugin.h \
commiteditor.h \
mercurialsettings.h \
authenticationdialog.h
FORMS += optionspage.ui \
FORMS += \
revertdialog.ui \
srcdestdialog.ui \
mercurialcommitpanel.ui \

View File

@@ -31,9 +31,6 @@ QtcPlugin {
"mercurialplugin.h",
"mercurialsettings.cpp",
"mercurialsettings.h",
"optionspage.cpp",
"optionspage.h",
"optionspage.ui",
"revertdialog.cpp",
"revertdialog.h",
"revertdialog.ui",

View File

@@ -86,7 +86,7 @@ QStringList MercurialDiffEditorController::addConfigurationArguments(const QStri
/////////////////////////////////////////////////////////////
MercurialClient::MercurialClient(MercurialSettings *settings) : VcsBaseClient(settings)
MercurialClient::MercurialClient(MercurialSettings *settings) : VcsBaseClient(nullptr, settings)
{
}
@@ -458,8 +458,8 @@ void MercurialClient::requestReload(const QString &documentId, const QString &so
controller->setReloader([controller, args] {
controller->runCommand({controller->addConfigurationArguments(args)});
});
controller->setVcsBinary(settings().binaryPath());
controller->setVcsTimeoutS(settings().vcsTimeoutS());
controller->setVcsBinary(baseSettings().binaryPath.filePath());
controller->setVcsTimeoutS(baseSettings().timeout.value());
controller->setProcessEnvironment(processEnvironment());
controller->setWorkingDirectory(workingDirectory);

View File

@@ -24,14 +24,14 @@
****************************************************************************/
#include "mercurialplugin.h"
#include "optionspage.h"
#include "commiteditor.h"
#include "constants.h"
#include "mercurialclient.h"
#include "mercurialeditor.h"
#include "mercurialsettings.h"
#include "revertdialog.h"
#include "srcdestdialog.h"
#include "commiteditor.h"
#include "mercurialsettings.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
@@ -662,8 +662,8 @@ void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusI
const QString branch = vcsTopic(m_submitRepository);
commitEditor->setFields(QFileInfo(m_submitRepository), branch,
m_settings.stringValue(MercurialSettings::userNameKey),
m_settings.stringValue(MercurialSettings::userEmailKey), status);
m_settings.userName.value(),
m_settings.userEmail.value(), status);
}
void MercurialPluginPrivate::diffFromEditorSelected(const QStringList &files)
@@ -767,7 +767,7 @@ bool MercurialPluginPrivate::managesFile(const QString &workingDirectory, const
bool MercurialPluginPrivate::isConfigured() const
{
const Utils::FilePath binary = m_settings.binaryPath();
const FilePath binary = m_settings.binaryPath.filePath();
if (binary.isEmpty())
return false;
QFileInfo fi = binary.toFileInfo();
@@ -839,7 +839,7 @@ Core::ShellCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const Q
args << QLatin1String("clone") << extraArgs << url << localName;
auto command = new VcsBase::VcsCommand(baseDirectory.toString(),
m_client.processEnvironment());
command->addJob({m_settings.binaryPath(), args}, -1);
command->addJob({m_settings.binaryPath.filePath(), args}, -1);
return command;
}

View File

@@ -24,23 +24,112 @@
****************************************************************************/
#include "mercurialsettings.h"
#include "constants.h"
#include <QSettings>
#include <utils/layoutbuilder.h>
#include <vcsbase/vcsbaseconstants.h>
using namespace Utils;
namespace Mercurial {
namespace Internal {
const QLatin1String MercurialSettings::diffIgnoreWhiteSpaceKey("diffIgnoreWhiteSpace");
const QLatin1String MercurialSettings::diffIgnoreBlankLinesKey("diffIgnoreBlankLines");
MercurialSettings::MercurialSettings()
{
setSettingsGroup(QLatin1String("Mercurial"));
// Override default binary path
declareKey(binaryPathKey, QLatin1String(Constants::MERCURIALDEFAULT));
declareKey(diffIgnoreWhiteSpaceKey, false);
declareKey(diffIgnoreBlankLinesKey, false);
setSettingsGroup("Mercurial");
setAutoApply(false);
registerAspect(&binaryPath);
binaryPath.setDisplayStyle(StringAspect::PathChooserDisplay);
binaryPath.setExpectedKind(PathChooser::ExistingCommand);
binaryPath.setDefaultValue(Constants::MERCURIALDEFAULT);
binaryPath.setDisplayName(tr("Mercurial Command"));
binaryPath.setHistoryCompleter("Bazaar.Command.History");
binaryPath.setLabelText(tr("Command:"));
registerAspect(&userName);
userName.setDisplayStyle(StringAspect::LineEditDisplay);
userName.setLabelText(tr("Default username:"));
userName.setToolTip(tr("Username to use by default on commit."));
registerAspect(&userEmail);
userEmail.setDisplayStyle(StringAspect::LineEditDisplay);
userEmail.setLabelText(tr("Default email:"));
userEmail.setToolTip(tr("Email to use by default on commit."));
registerAspect(&diffIgnoreWhiteSpace);
diffIgnoreWhiteSpace.setSettingsKey("diffIgnoreWhiteSpace");
registerAspect(&diffIgnoreBlankLines);
diffIgnoreBlankLines.setSettingsKey("diffIgnoreBlankLines");
}
// Optionpage
class OptionsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Mercurial::Internal::OptionsPageWidget)
public:
OptionsPageWidget(const std::function<void()> &onApply, MercurialSettings *settings);
void apply() final;
private:
std::function<void()> m_onApply;
MercurialSettings *m_settings;
};
OptionsPageWidget::OptionsPageWidget(const std::function<void()> &onApply, MercurialSettings *settings)
: m_onApply(onApply), m_settings(settings)
{
MercurialSettings &s = *settings;
using namespace Layouting;
const Break nl;
Column {
Group {
Title(tr("Configuration")),
Row { s.binaryPath }
},
Group {
Title(tr("User")),
Form {
s.userName, nl,
s.userEmail
}
},
Group {
Title(tr("Miscellaneous")),
Row {
s.logCount,
s.timeout,
Stretch()
}
},
Stretch()
}.attachTo(this);
}
void OptionsPageWidget::apply()
{
if (!m_settings->isDirty())
return;
m_settings->apply();
m_onApply();
}
OptionsPage::OptionsPage(const std::function<void()> &onApply, MercurialSettings *settings)
{
setId(VcsBase::Constants::VCS_ID_MERCURIAL);
setDisplayName(OptionsPageWidget::tr("Mercurial"));
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); });
}
} // namespace Internal

View File

@@ -25,19 +25,27 @@
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
#include <vcsbase/vcsbaseclientsettings.h>
namespace Mercurial {
namespace Internal {
class MercurialSettings : public VcsBase::VcsBaseClientSettings
class MercurialSettings : public VcsBase::VcsBaseSettings
{
public:
static const QLatin1String diffIgnoreWhiteSpaceKey;
static const QLatin1String diffIgnoreBlankLinesKey;
Utils::StringAspect diffIgnoreWhiteSpace;
Utils::StringAspect diffIgnoreBlankLines;
MercurialSettings();
};
class OptionsPage final : public Core::IOptionsPage
{
public:
OptionsPage(const std::function<void()> &onApply, MercurialSettings *settings);
};
} // namespace Internal
} // namespace Mercurial

View File

@@ -1,98 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Brian McGillion
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "optionspage.h"
#include "mercurialclient.h"
#include "mercurialsettings.h"
#include "mercurialplugin.h"
#include "ui_optionspage.h"
#include "ui_optionspage.h"
#include <coreplugin/icore.h>
#include <utils/pathchooser.h>
#include <vcsbase/vcsbaseconstants.h>
using namespace VcsBase;
namespace Mercurial {
namespace Internal {
class OptionsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Mercurial::Internal::OptionsPageWidget)
public:
OptionsPageWidget(const std::function<void()> &onApply, MercurialSettings *settings);
void apply() final;
private:
Ui::OptionsPage m_ui;
std::function<void()> m_onApply;
MercurialSettings *m_settings;
};
OptionsPageWidget::OptionsPageWidget(const std::function<void()> &onApply, MercurialSettings *settings)
: m_onApply(onApply), m_settings(settings)
{
m_ui.setupUi(this);
m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_ui.commandChooser->setHistoryCompleter(QLatin1String("Mercurial.Command.History"));
m_ui.commandChooser->setPromptDialogTitle(tr("Mercurial Command"));
const VcsBaseClientSettings &s = *settings;
m_ui.commandChooser->setPath(s.stringValue(MercurialSettings::binaryPathKey));
m_ui.defaultUsernameLineEdit->setText(s.stringValue(MercurialSettings::userNameKey));
m_ui.defaultEmailLineEdit->setText(s.stringValue(MercurialSettings::userEmailKey));
m_ui.logEntriesCount->setValue(s.intValue(MercurialSettings::logCountKey));
m_ui.timeout->setValue(s.intValue(MercurialSettings::timeoutKey));
}
void OptionsPageWidget::apply()
{
MercurialSettings ms;
ms.setValue(MercurialSettings::binaryPathKey, m_ui.commandChooser->rawPath());
ms.setValue(MercurialSettings::userNameKey, m_ui.defaultUsernameLineEdit->text().trimmed());
ms.setValue(MercurialSettings::userEmailKey, m_ui.defaultEmailLineEdit->text().trimmed());
ms.setValue(MercurialSettings::logCountKey, m_ui.logEntriesCount->value());
ms.setValue(MercurialSettings::timeoutKey, m_ui.timeout->value());
if (*m_settings != ms) {
*m_settings = ms;
m_onApply();
}
}
OptionsPage::OptionsPage(const std::function<void()> &onApply, MercurialSettings *settings)
{
setId(VcsBase::Constants::VCS_ID_MERCURIAL);
setDisplayName(OptionsPageWidget::tr("Mercurial"));
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); });
}
} // namespace Internal
} // namespace Mercurial

View File

@@ -1,42 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Brian McGillion
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
namespace Mercurial {
namespace Internal {
class MercurialSettings;
class OptionsPage final : public Core::IOptionsPage
{
public:
OptionsPage(const std::function<void()> &onApply, MercurialSettings *settings);
};
} // namespace Internal
} // namespace Mercurial

View File

@@ -1,182 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Mercurial::Internal::OptionsPage</class>
<widget class="QWidget" name="Mercurial::Internal::OptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>268</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="configGroupBox">
<property name="title">
<string>Configuration</string>
</property>
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="mercurialCommandLabel">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::PathChooser" name="commandChooser" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="userGroupBox">
<property name="title">
<string>User</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="defaultUsernameLabel">
<property name="toolTip">
<string>Username to use by default on commit.</string>
</property>
<property name="text">
<string>Default username:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="defaultUsernameLineEdit">
<property name="toolTip">
<string>Username to use by default on commit.</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="defaultEmailLabel">
<property name="toolTip">
<string>Email to use by default on commit.</string>
</property>
<property name="text">
<string>Default email:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="defaultEmailLineEdit">
<property name="toolTip">
<string>Email to use by default on commit.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="miscGroupBox">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QLabel" name="timeoutSecondsLabel">
<property name="text">
<string>Timeout:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="timeout">
<property name="suffix">
<string>s</string>
</property>
<property name="maximum">
<number>360</number>
</property>
<property name="value">
<number>30</number>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>217</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="logEntriesCount">
<property name="toolTip">
<string>The number of recent commit logs to show, choose 0 to see all entries.</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="showLogEntriesLabel">
<property name="text">
<string>Log count:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
<slots>
<signal>editingFinished()</signal>
<signal>browsingFinished()</signal>
</slots>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>defaultUsernameLineEdit</tabstop>
<tabstop>defaultEmailLineEdit</tabstop>
<tabstop>logEntriesCount</tabstop>
<tabstop>timeout</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>