Bazaar: Aspectify settings

Change-Id: I0354698cf3473dd096e57481a945f0f59afc75b3
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2021-03-19 13:34:25 +01:00
parent 78b4449692
commit fb9796ae8a
10 changed files with 169 additions and 372 deletions

View File

@@ -11,7 +11,6 @@ add_qtc_plugin(Bazaar
branchinfo.cpp branchinfo.h
commiteditor.cpp commiteditor.h
constants.h
optionspage.cpp optionspage.h optionspage.ui
pullorpushdialog.cpp pullorpushdialog.h pullorpushdialog.ui
revertdialog.ui
uncommitdialog.ui

View File

@@ -2,7 +2,6 @@ include(../../qtcreatorplugin.pri)
SOURCES += \
bazaarclient.cpp \
bazaarplugin.cpp \
optionspage.cpp \
bazaarsettings.cpp \
commiteditor.cpp \
bazaarcommitwidget.cpp \
@@ -15,7 +14,6 @@ HEADERS += \
bazaarclient.h \
constants.h \
bazaarplugin.h \
optionspage.h \
bazaarsettings.h \
commiteditor.h \
bazaarcommitwidget.h \
@@ -25,7 +23,6 @@ HEADERS += \
branchinfo.h
FORMS += \
optionspage.ui \
revertdialog.ui \
bazaarcommitpanel.ui \
pullorpushdialog.ui \

View File

@@ -29,9 +29,6 @@ QtcPlugin {
"commiteditor.cpp",
"commiteditor.h",
"constants.h",
"optionspage.cpp",
"optionspage.h",
"optionspage.ui",
"pullorpushdialog.cpp",
"pullorpushdialog.h",
"pullorpushdialog.ui",

View File

@@ -49,13 +49,13 @@ class BazaarDiffConfig : public VcsBaseEditorConfig
{
Q_OBJECT
public:
BazaarDiffConfig(VcsBaseClientSettings &settings, QToolBar *toolBar) :
BazaarDiffConfig(BazaarSettings &settings, QToolBar *toolBar) :
VcsBaseEditorConfig(toolBar)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
settings.boolPointer(BazaarSettings::diffIgnoreWhiteSpaceKey));
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
settings.boolPointer(BazaarSettings::diffIgnoreBlankLinesKey));
mapSetting(addToggleButton("-w", tr("Ignore Whitespace")),
&settings.diffIgnoreWhiteSpace);
mapSetting(addToggleButton("-B", tr("Ignore Blank Lines")),
&settings.diffIgnoreBlankLines);
}
QStringList arguments() const override
@@ -64,8 +64,7 @@ public:
// Bazaar wants "--diff-options=-w -B.."
const QStringList formatArguments = VcsBaseEditorConfig::arguments();
if (!formatArguments.isEmpty()) {
const QString a = QLatin1String("--diff-options=")
+ formatArguments.join(QString(QLatin1Char(' ')));
const QString a = "--diff-options=" + formatArguments.join(' ');
args.append(a);
}
return args;
@@ -76,31 +75,31 @@ class BazaarLogConfig : public VcsBaseEditorConfig
{
Q_OBJECT
public:
BazaarLogConfig(VcsBaseClientSettings &settings, QToolBar *toolBar) :
BazaarLogConfig(BazaarSettings &settings, QToolBar *toolBar) :
VcsBaseEditorConfig(toolBar)
{
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
mapSetting(addToggleButton("--verbose", tr("Verbose"),
tr("Show files changed in each revision.")),
settings.boolPointer(BazaarSettings::logVerboseKey));
mapSetting(addToggleButton(QLatin1String("--forward"), tr("Forward"),
&settings.logVerbose);
mapSetting(addToggleButton("--forward", tr("Forward"),
tr("Show from oldest to newest.")),
settings.boolPointer(BazaarSettings::logForwardKey));
mapSetting(addToggleButton(QLatin1String("--include-merges"), tr("Include Merges"),
&settings.logForward);
mapSetting(addToggleButton("--include-merges", tr("Include Merges"),
tr("Show merged revisions.")),
settings.boolPointer(BazaarSettings::logIncludeMergesKey));
&settings.logIncludeMerges);
const QList<ChoiceItem> logChoices = {
ChoiceItem(tr("Detailed"), QLatin1String("long")),
ChoiceItem(tr("Moderately Short"), QLatin1String("short")),
ChoiceItem(tr("One Line"), QLatin1String("line")),
ChoiceItem(tr("GNU Change Log"), QLatin1String("gnu-changelog"))
{tr("Detailed"), "long"},
{tr("Moderately Short"), "short"},
{tr("One Line"), "line"},
{tr("GNU Change Log"), "gnu-changelog"}
};
mapSetting(addChoices(tr("Format"), { "--log-format=%1" }, logChoices),
settings.stringPointer(BazaarSettings::logFormatKey));
&settings.logFormat);
}
};
BazaarClient::BazaarClient(BazaarSettings *settings) : VcsBaseClient(settings)
BazaarClient::BazaarClient(BazaarSettings *settings) : VcsBaseClient(nullptr, settings)
{
setDiffConfigCreator([settings](QToolBar *toolBar) {
return new BazaarDiffConfig(*settings, toolBar);

View File

@@ -31,7 +31,6 @@
#include "bazaarsettings.h"
#include "commiteditor.h"
#include "constants.h"
#include "optionspage.h"
#include "pullorpushdialog.h"
#include "ui_revertdialog.h"
@@ -490,7 +489,7 @@ void BazaarPluginPrivate::logRepository()
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
QStringList extraOptions;
extraOptions += QLatin1String("--limit=") + QString::number(m_settings.intValue(BazaarSettings::logCountKey));
extraOptions += "--limit=" + QString::number(m_settings.logCount.value());
m_client.log(state.topLevel(), QStringList(), extraOptions);
}
@@ -677,8 +676,8 @@ void BazaarPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusItem
const BranchInfo branch = m_client.synchronousBranchQuery(m_submitRepository);
commitEditor->setFields(m_submitRepository, branch,
m_settings.stringValue(BazaarSettings::userNameKey),
m_settings.stringValue(BazaarSettings::userEmailKey), status);
m_settings.userName.value(),
m_settings.userEmail.value(), status);
}
void BazaarPluginPrivate::diffFromEditorSelected(const QStringList &files)
@@ -865,7 +864,7 @@ bool BazaarPluginPrivate::managesFile(const QString &workingDirectory, const QSt
bool BazaarPluginPrivate::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();

View File

@@ -24,36 +24,145 @@
****************************************************************************/
#include "bazaarsettings.h"
#include "bazaarclient.h"
#include "constants.h"
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <vcsbase/vcsbaseconstants.h>
using namespace Utils;
namespace Bazaar {
namespace Internal {
const QLatin1String BazaarSettings::diffIgnoreWhiteSpaceKey("diffIgnoreWhiteSpace");
const QLatin1String BazaarSettings::diffIgnoreBlankLinesKey("diffIgnoreBlankLines");
const QLatin1String BazaarSettings::logVerboseKey("logVerbose");
const QLatin1String BazaarSettings::logForwardKey("logForward");
const QLatin1String BazaarSettings::logIncludeMergesKey("logIncludeMerges");
const QLatin1String BazaarSettings::logFormatKey("logFormat");
BazaarSettings::BazaarSettings()
{
setSettingsGroup(QLatin1String(Constants::BAZAAR));
// Override default binary path
declareKey(binaryPathKey, QLatin1String(Constants::BAZAARDEFAULT));
declareKey(diffIgnoreWhiteSpaceKey, false);
declareKey(diffIgnoreBlankLinesKey, false);
declareKey(logVerboseKey, false);
declareKey(logForwardKey, false);
declareKey(logIncludeMergesKey, false);
declareKey(logFormatKey, QLatin1String("long"));
setSettingsGroup(Constants::BAZAAR);
setAutoApply(false);
registerAspect(&binaryPath);
binaryPath.setDisplayStyle(StringAspect::PathChooserDisplay);
binaryPath.setExpectedKind(PathChooser::ExistingCommand);
binaryPath.setDefaultValue(Constants::BAZAARDEFAULT);
binaryPath.setDisplayName(tr("Bazaar Command"));
binaryPath.setHistoryCompleter("Bazaar.Command.History");
binaryPath.setLabelText(tr("Command:"));
registerAspect(&diffIgnoreWhiteSpace);
diffIgnoreWhiteSpace.setSettingsKey("diffIgnoreWhiteSpace");
registerAspect(&diffIgnoreBlankLines);
diffIgnoreBlankLines.setSettingsKey("diffIgnoreBlankLines");
registerAspect(&logVerbose);
logVerbose.setSettingsKey("logVerbose");
registerAspect(&logFormat);
logForward.setSettingsKey("logForward");
registerAspect(&logIncludeMerges);
logIncludeMerges.setSettingsKey("logIncludeMerges");
registerAspect(&logFormat);
logFormat.setDisplayStyle(StringAspect::LineEditDisplay);
logFormat.setSettingsKey("logFormat");
logFormat.setDefaultValue("long");
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(&logCount);
logCount.setLabelText(tr("Log count:"));
logCount.setToolTip(tr("The number of recent commit logs to show. Choose 0 to see all entries."));
registerAspect(&logCount);
timeout.setLabelText(tr("Timeout:"));
timeout.setSuffix(tr("s"));
}
bool BazaarSettings::sameUserId(const BazaarSettings &other) const
{
return stringValue(userNameKey) == other.stringValue(userNameKey)
&& stringValue(userEmailKey) == other.stringValue(userEmailKey);
return userName.value() == other.userName.value()
&& userEmail.value() == other.userEmail.value();
}
} // namespace Internal
} // namespace Bazaar
// OptionsPage
class OptionsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Bazaar::Internal::OptionsPageWidget)
public:
OptionsPageWidget(const std::function<void()> &onApply, BazaarSettings *settings);
void apply() final;
private:
const std::function<void()> m_onApply;
BazaarSettings *m_settings;
};
void OptionsPageWidget::apply()
{
if (!m_settings->isDirty())
return;
m_settings->apply();
m_onApply();
}
OptionsPageWidget::OptionsPageWidget(const std::function<void(void)> &onApply, BazaarSettings *settings)
: m_onApply(onApply), m_settings(settings)
{
BazaarSettings &s = *m_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);
}
OptionsPage::OptionsPage(const std::function<void(void)> &onApply, BazaarSettings *settings)
{
setId(VcsBase::Constants::VCS_ID_BAZAAR);
setDisplayName(OptionsPageWidget::tr("Bazaar"));
setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); });
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
}
} // Internal
} // Bazaar

View File

@@ -25,24 +25,34 @@
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/aspects.h>
#include <vcsbase/vcsbaseclientsettings.h>
namespace Bazaar {
namespace Internal {
class BazaarSettings : public VcsBase::VcsBaseClientSettings
class BazaarSettings : public VcsBase::VcsBaseSettings
{
public:
static const QLatin1String diffIgnoreWhiteSpaceKey;
static const QLatin1String diffIgnoreBlankLinesKey;
static const QLatin1String logVerboseKey;
static const QLatin1String logForwardKey;
static const QLatin1String logIncludeMergesKey;
static const QLatin1String logFormatKey;
Utils::BoolAspect diffIgnoreWhiteSpace;
Utils::BoolAspect diffIgnoreBlankLines;
Utils::BoolAspect logVerbose;
Utils::BoolAspect logForward;
Utils::BoolAspect logIncludeMerges;
Utils::StringAspect logFormat;
BazaarSettings();
bool sameUserId(const BazaarSettings &other) const;
};
class OptionsPage final : public Core::IOptionsPage
{
public:
OptionsPage(const std::function<void()> &onApply, BazaarSettings *settings);
};
} // namespace Internal
} // namespace Bazaar

View File

@@ -1,95 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Hugues Delorme
** 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 "bazaarclient.h"
#include "bazaarsettings.h"
#include "bazaarplugin.h"
#include "ui_optionspage.h"
#include <coreplugin/icore.h>
#include <vcsbase/vcsbaseconstants.h>
using namespace VcsBase;
namespace Bazaar {
namespace Internal {
class OptionsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Bazaar::Internal::OptionsPageWidget)
public:
OptionsPageWidget(const std::function<void()> &onApply, BazaarSettings *settings);
void apply() final;
private:
Ui::OptionsPage m_ui;
const std::function<void()> m_onApply;
BazaarSettings *m_settings;
};
void OptionsPageWidget::apply()
{
BazaarSettings s = *m_settings;
s.setValue(BazaarSettings::binaryPathKey, m_ui.commandChooser->rawPath());
s.setValue(BazaarSettings::userNameKey, m_ui.defaultUsernameLineEdit->text().trimmed());
s.setValue(BazaarSettings::userEmailKey, m_ui.defaultEmailLineEdit->text().trimmed());
s.setValue(BazaarSettings::logCountKey, m_ui.logEntriesCount->value());
s.setValue(BazaarSettings::timeoutKey, m_ui.timeout->value());
if (*m_settings == s)
return;
*m_settings = s;
m_onApply();
}
OptionsPageWidget::OptionsPageWidget(const std::function<void(void)> &onApply, BazaarSettings *settings)
: m_onApply(onApply), m_settings(settings)
{
m_ui.setupUi(this);
m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_ui.commandChooser->setPromptDialogTitle(tr("Bazaar Command"));
m_ui.commandChooser->setHistoryCompleter(QLatin1String("Bazaar.Command.History"));
m_ui.commandChooser->setPath(m_settings->stringValue(BazaarSettings::binaryPathKey));
m_ui.defaultUsernameLineEdit->setText(m_settings->stringValue(BazaarSettings::userNameKey));
m_ui.defaultEmailLineEdit->setText(m_settings->stringValue(BazaarSettings::userEmailKey));
m_ui.logEntriesCount->setValue(m_settings->intValue(BazaarSettings::logCountKey));
m_ui.timeout->setValue(m_settings->intValue(BazaarSettings::timeoutKey));
}
OptionsPage::OptionsPage(const std::function<void(void)> &onApply, BazaarSettings *settings)
{
setId(VcsBase::Constants::VCS_ID_BAZAAR);
setDisplayName(OptionsPageWidget::tr("Bazaar"));
setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); });
setCategory(Constants::VCS_SETTINGS_CATEGORY);
}
} // Internal
} // Bazaar

View File

@@ -1,42 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Hugues Delorme
** 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 Bazaar {
namespace Internal {
class BazaarSettings;
class OptionsPage final : public Core::IOptionsPage
{
public:
OptionsPage(const std::function<void()> &onApply, BazaarSettings *settings);
};
} // namespace Internal
} // namespace Bazaar

View File

@@ -1,176 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Bazaar::Internal::OptionsPage</class>
<widget class="QWidget" name="Bazaar::Internal::OptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>649</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="commandLabel">
<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="0">
<widget class="QLabel" name="showLogEntriesLabel">
<property name="text">
<string>Log count:</string>
</property>
</widget>
</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>1000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
</item>
<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>213</width>
<height>20</height>
</size>
</property>
</spacer>
</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>
<resources/>
<connections/>
</ui>