forked from qt-creator/qt-creator
Perforce: Aspectify settings
Change-Id: I2074b642166f135bb4617f9e14ac3e7b895720e7 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -11,6 +11,5 @@ add_qtc_plugin(Perforce
|
||||
perforcesubmiteditor.cpp perforcesubmiteditor.h
|
||||
perforcesubmiteditorwidget.cpp perforcesubmiteditorwidget.h
|
||||
promptdialog.ui
|
||||
settingspage.cpp settingspage.h settingspage.ui
|
||||
submitpanel.ui
|
||||
)
|
||||
|
@@ -3,7 +3,6 @@ include(../../qtcreatorplugin.pri)
|
||||
HEADERS += \
|
||||
perforceplugin.h \
|
||||
perforcechecker.h \
|
||||
settingspage.h \
|
||||
perforceeditor.h \
|
||||
changenumberdialog.h \
|
||||
perforcesubmiteditor.h \
|
||||
@@ -14,7 +13,6 @@ HEADERS += \
|
||||
|
||||
SOURCES += perforceplugin.cpp \
|
||||
perforcechecker.cpp \
|
||||
settingspage.cpp \
|
||||
perforceeditor.cpp \
|
||||
changenumberdialog.cpp \
|
||||
perforcesubmiteditor.cpp \
|
||||
@@ -23,7 +21,7 @@ SOURCES += perforceplugin.cpp \
|
||||
annotationhighlighter.cpp \
|
||||
perforcesubmiteditorwidget.cpp
|
||||
|
||||
FORMS += settingspage.ui \
|
||||
FORMS += \
|
||||
changenumberdialog.ui \
|
||||
pendingchangesdialog.ui \
|
||||
submitpanel.ui
|
||||
|
@@ -31,9 +31,6 @@ QtcPlugin {
|
||||
"perforcesubmiteditor.h",
|
||||
"perforcesubmiteditorwidget.cpp",
|
||||
"perforcesubmiteditorwidget.h",
|
||||
"settingspage.cpp",
|
||||
"settingspage.h",
|
||||
"settingspage.ui",
|
||||
"submitpanel.ui",
|
||||
]
|
||||
}
|
||||
|
@@ -31,7 +31,6 @@
|
||||
#include "perforceeditor.h"
|
||||
#include "perforcesettings.h"
|
||||
#include "perforcesubmiteditor.h"
|
||||
#include "settingspage.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
@@ -358,7 +357,7 @@ public:
|
||||
QAction *m_menuAction = nullptr;
|
||||
|
||||
PerforceSettings m_settings;
|
||||
SettingsPage m_settingsPage{&m_settings, [this] { applySettings(); }};
|
||||
PerforceSettingsPage m_settingsPage{&m_settings};
|
||||
|
||||
ManagedDirectoryCache m_managedDirectoryCache;
|
||||
|
||||
@@ -396,7 +395,7 @@ PerforcePluginPrivate::PerforcePluginPrivate()
|
||||
|
||||
dd = this;
|
||||
|
||||
m_settings.fromSettings(ICore::settings());
|
||||
m_settings.settings().readSettings(ICore::settings());
|
||||
|
||||
const QString prefix = QLatin1String("p4");
|
||||
m_commandLocator = new CommandLocator("Perforce", prefix, prefix, this);
|
||||
@@ -572,6 +571,11 @@ PerforcePluginPrivate::PerforcePluginPrivate()
|
||||
command = ActionManager::registerAction(m_filelogAction, CMD_ID_FILELOG, context);
|
||||
connect(m_filelogAction, &QAction::triggered, this, &PerforcePluginPrivate::filelogFile);
|
||||
perforceContainer->addAction(command);
|
||||
|
||||
QObject::connect(&m_settings.settings(), &AspectContainer::applied, [this] {
|
||||
m_settings.clearTopLevel();
|
||||
applySettings();
|
||||
});
|
||||
}
|
||||
|
||||
void PerforcePlugin::extensionsInitialized()
|
||||
@@ -1593,7 +1597,7 @@ bool PerforcePluginPrivate::submitEditorAboutToClose()
|
||||
// Set without triggering the checking mechanism
|
||||
if (wantsPrompt != m_settings.promptToSubmit()) {
|
||||
m_settings.setPromptToSubmit(wantsPrompt);
|
||||
m_settings.toSettings(ICore::settings());
|
||||
m_settings.settings().writeSettings(ICore::settings());
|
||||
}
|
||||
if (!DocumentManager::saveDocument(editorDocument))
|
||||
return false;
|
||||
@@ -1720,7 +1724,7 @@ void PerforcePluginPrivate::setTopLevel(const QString &topLevel)
|
||||
|
||||
void PerforcePluginPrivate::applySettings()
|
||||
{
|
||||
m_settings.toSettings(ICore::settings());
|
||||
m_settings.settings().writeSettings(ICore::settings());
|
||||
m_managedDirectoryCache.clear();
|
||||
getTopLevel();
|
||||
emit configurationChanged();
|
||||
|
@@ -24,63 +24,107 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "perforcesettings.h"
|
||||
|
||||
#include "perforcechecker.h"
|
||||
#include "perforceplugin.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QCoreApplication>
|
||||
#include <vcsbase/vcsbaseconstants.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QPushButton>
|
||||
#include <QStringList>
|
||||
|
||||
static const char groupC[] = "Perforce";
|
||||
static const char commandKeyC[] = "Command";
|
||||
static const char defaultKeyC[] = "Default";
|
||||
static const char portKeyC[] = "Port";
|
||||
static const char clientKeyC[] = "Client";
|
||||
static const char userKeyC[] = "User";
|
||||
static const char promptToSubmitKeyC[] = "PromptForSubmit";
|
||||
static const char autoOpenKeyC[] = "PromptToOpen";
|
||||
static const char timeOutKeyC[] = "TimeOut";
|
||||
static const char logCountKeyC[] = "LogCount";
|
||||
using namespace Utils;
|
||||
|
||||
enum { defaultTimeOutS = 30, defaultLogCount = 1000 };
|
||||
namespace Perforce {
|
||||
namespace Internal {
|
||||
|
||||
static QString defaultCommand()
|
||||
{
|
||||
return QLatin1String("p4" QTC_HOST_EXE_SUFFIX);
|
||||
}
|
||||
|
||||
namespace Perforce {
|
||||
namespace Internal {
|
||||
|
||||
Settings::Settings() : logCount(defaultLogCount), timeOutS(defaultTimeOutS)
|
||||
{ }
|
||||
|
||||
bool Settings::equals(const Settings &rhs) const
|
||||
Settings::Settings()
|
||||
{
|
||||
return defaultEnv == rhs.defaultEnv
|
||||
&& logCount == rhs.logCount
|
||||
&& p4Command == rhs.p4Command && p4Port == rhs.p4Port
|
||||
&& p4Client == rhs.p4Client && p4User == rhs.p4User
|
||||
&& timeOutS == rhs.timeOutS && promptToSubmit == rhs.promptToSubmit
|
||||
&& autoOpen == rhs.autoOpen;
|
||||
setSettingsGroup("Perforce");
|
||||
setAutoApply(false);
|
||||
|
||||
registerAspect(&p4BinaryPath);
|
||||
p4BinaryPath.setDisplayStyle(StringAspect::PathChooserDisplay);
|
||||
p4BinaryPath.setSettingsKey("Command");
|
||||
p4BinaryPath.setDefaultValue(
|
||||
Environment::systemEnvironment().searchInPath(defaultCommand()).toString());
|
||||
p4BinaryPath.setHistoryCompleter("Perforce.Command.History");
|
||||
p4BinaryPath.setExpectedKind(PathChooser::Command);
|
||||
p4BinaryPath.setDisplayName(tr("Perforce Command"));
|
||||
p4BinaryPath.setLabelText(tr("P4 command:"));
|
||||
|
||||
registerAspect(&p4Port);
|
||||
p4Port.setDisplayStyle(StringAspect::LineEditDisplay);
|
||||
p4Port.setSettingsKey("Port");
|
||||
p4Port.setLabelText(tr("P4 port:"));
|
||||
|
||||
registerAspect(&p4Client);
|
||||
p4Client.setDisplayStyle(StringAspect::LineEditDisplay);
|
||||
p4Client.setSettingsKey("Client");
|
||||
p4Client.setLabelText(tr("P4 client:"));
|
||||
|
||||
registerAspect(&p4User);
|
||||
p4User.setDisplayStyle(StringAspect::LineEditDisplay);
|
||||
p4User.setSettingsKey("User");
|
||||
p4User.setLabelText(tr("P4 user:"));
|
||||
|
||||
registerAspect(&logCount);
|
||||
logCount.setSettingsKey("LogCount");
|
||||
logCount.setRange(1000, 10000);
|
||||
logCount.setDefaultValue(1000);
|
||||
logCount.setLabelText(tr("Log count:"));
|
||||
|
||||
registerAspect(&customEnv);
|
||||
// The settings value has been stored with the opposite meaning for a while.
|
||||
// Avoid changing the stored value, but flip it on read/write:
|
||||
customEnv.setSettingsKey("Default");
|
||||
const auto invertBoolVariant = [](const QVariant &v) { return QVariant(!v.toBool()); };
|
||||
customEnv.setFromSettingsTransformation(invertBoolVariant);
|
||||
customEnv.setToSettingsTransformation(invertBoolVariant);
|
||||
|
||||
registerAspect(&timeOutS);
|
||||
timeOutS.setSettingsKey("TimeOut");
|
||||
timeOutS.setRange(1, 360);
|
||||
timeOutS.setDefaultValue(30);
|
||||
timeOutS.setLabelText(tr("Timeout:"));
|
||||
timeOutS.setSuffix(tr("s"));
|
||||
|
||||
registerAspect(&promptToSubmit);
|
||||
promptToSubmit.setSettingsKey("PromptForSubmit");
|
||||
promptToSubmit.setDefaultValue(true);
|
||||
promptToSubmit.setLabelText(tr("Prompt on submit"));
|
||||
|
||||
registerAspect(&autoOpen);
|
||||
autoOpen.setSettingsKey("PromptToOpen");
|
||||
autoOpen.setDefaultValue(true);
|
||||
autoOpen.setLabelText(tr("Automatically open files when editing"));
|
||||
}
|
||||
|
||||
QStringList Settings::commonP4Arguments() const
|
||||
{
|
||||
if (defaultEnv)
|
||||
return QStringList();
|
||||
QStringList lst;
|
||||
if (!p4Client.isEmpty())
|
||||
lst << QLatin1String("-c") << p4Client;
|
||||
if (!p4Port.isEmpty())
|
||||
lst << QLatin1String("-p") << p4Port;
|
||||
if (!p4User.isEmpty())
|
||||
lst << QLatin1String("-u") << p4User;
|
||||
if (customEnv.value()) {
|
||||
if (!p4Client.value().isEmpty())
|
||||
lst << "-c" << p4Client.value();
|
||||
if (!p4Port.value().isEmpty())
|
||||
lst << "-p" << p4Port.value();
|
||||
if (!p4User.value().isEmpty())
|
||||
lst << "-u" << p4User.value();
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
@@ -90,99 +134,54 @@ PerforceSettings::~PerforceSettings()
|
||||
delete m_topLevelDir;
|
||||
}
|
||||
|
||||
void PerforceSettings::fromSettings(QSettings *settings)
|
||||
bool PerforceSettings::isValid() const
|
||||
{
|
||||
settings->beginGroup(QLatin1String(groupC));
|
||||
m_settings.p4Command = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString();
|
||||
m_settings.p4BinaryPath =
|
||||
Utils::Environment::systemEnvironment().searchInPath(m_settings.p4Command).toString();
|
||||
m_settings.defaultEnv = settings->value(QLatin1String(defaultKeyC), true).toBool();
|
||||
m_settings.p4Port = settings->value(QLatin1String(portKeyC), QString()).toString();
|
||||
m_settings.p4Client = settings->value(QLatin1String(clientKeyC), QString()).toString();
|
||||
m_settings.p4User = settings->value(QLatin1String(userKeyC), QString()).toString();
|
||||
m_settings.timeOutS = settings->value(QLatin1String(timeOutKeyC), defaultTimeOutS).toInt();
|
||||
m_settings.promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
|
||||
m_settings.logCount = settings->value(QLatin1String(logCountKeyC), int(defaultLogCount)).toInt();
|
||||
m_settings.autoOpen = settings->value(QLatin1String(autoOpenKeyC), true).toBool();
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void PerforceSettings::toSettings(QSettings *settings) const
|
||||
{
|
||||
settings->beginGroup(QLatin1String(groupC));
|
||||
settings->setValue(QLatin1String(commandKeyC), m_settings.p4Command);
|
||||
settings->setValue(QLatin1String(defaultKeyC), m_settings.defaultEnv);
|
||||
settings->setValue(QLatin1String(portKeyC), m_settings.p4Port);
|
||||
settings->setValue(QLatin1String(clientKeyC), m_settings.p4Client);
|
||||
settings->setValue(QLatin1String(userKeyC), m_settings.p4User);
|
||||
settings->setValue(QLatin1String(timeOutKeyC), m_settings.timeOutS);
|
||||
settings->setValue(QLatin1String(promptToSubmitKeyC), m_settings.promptToSubmit);
|
||||
settings->setValue(QLatin1String(logCountKeyC), m_settings.logCount);
|
||||
settings->setValue(QLatin1String(autoOpenKeyC), m_settings.autoOpen);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void PerforceSettings::setSettings(const Settings &newSettings)
|
||||
{
|
||||
if (newSettings != m_settings) {
|
||||
m_settings = newSettings;
|
||||
clearTopLevel();
|
||||
}
|
||||
}
|
||||
|
||||
Settings PerforceSettings::settings() const
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
QString PerforceSettings::p4Command() const
|
||||
{
|
||||
return m_settings.p4Command;
|
||||
return !m_topLevel.isEmpty() && !m_settings.p4BinaryPath.value().isEmpty();
|
||||
}
|
||||
|
||||
QString PerforceSettings::p4BinaryPath() const
|
||||
{
|
||||
return m_settings.p4BinaryPath;
|
||||
return m_settings.p4BinaryPath.value();
|
||||
}
|
||||
|
||||
QString PerforceSettings::p4Port() const
|
||||
{
|
||||
return m_settings.p4Port;
|
||||
return m_settings.p4Port.value();
|
||||
}
|
||||
|
||||
QString PerforceSettings::p4Client() const
|
||||
{
|
||||
return m_settings.p4Client;
|
||||
return m_settings.p4Client.value();
|
||||
}
|
||||
|
||||
QString PerforceSettings::p4User() const
|
||||
{
|
||||
return m_settings.p4User;
|
||||
return m_settings.p4User.value();
|
||||
}
|
||||
|
||||
bool PerforceSettings::defaultEnv() const
|
||||
{
|
||||
return m_settings.defaultEnv;
|
||||
return !m_settings.customEnv.value(); // Note: negated
|
||||
}
|
||||
|
||||
bool PerforceSettings::promptToSubmit() const
|
||||
{
|
||||
return m_settings.promptToSubmit;
|
||||
return m_settings.promptToSubmit.value();
|
||||
}
|
||||
|
||||
void PerforceSettings::setPromptToSubmit(bool p)
|
||||
{
|
||||
m_settings.promptToSubmit = p;
|
||||
m_settings.promptToSubmit.setValue(p);
|
||||
}
|
||||
|
||||
bool PerforceSettings::autoOpen() const
|
||||
{
|
||||
return m_settings.autoOpen;
|
||||
return m_settings.autoOpen.value();
|
||||
}
|
||||
|
||||
void PerforceSettings::setAutoOpen(bool b)
|
||||
{
|
||||
m_settings.autoOpen = b;
|
||||
m_settings.autoOpen.setValue(b);
|
||||
}
|
||||
|
||||
QString PerforceSettings::topLevel() const
|
||||
@@ -266,5 +265,72 @@ QString PerforceSettings::mapToFileSystem(const QString &perforceFilePath) const
|
||||
return mapPathRoot(perforceFilePath, m_topLevel, m_topLevelSymLinkTarget);
|
||||
}
|
||||
|
||||
// SettingsPage
|
||||
|
||||
PerforceSettingsPage::PerforceSettingsPage(PerforceSettings *settings)
|
||||
{
|
||||
setId(VcsBase::Constants::VCS_ID_PERFORCE);
|
||||
setDisplayName(Settings::tr("Perforce"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
setSettings(&settings->settings());
|
||||
|
||||
setLayouter([settings, this](QWidget *widget) {
|
||||
Settings &s = settings->settings();
|
||||
using namespace Layouting;
|
||||
|
||||
auto errorLabel = new QLabel;
|
||||
auto testButton = new QPushButton(Settings::tr("Test"));
|
||||
connect(testButton, &QPushButton::clicked, this, [this, settings, errorLabel, testButton] {
|
||||
testButton->setEnabled(false);
|
||||
auto checker = new PerforceChecker(errorLabel);
|
||||
checker->setUseOverideCursor(true);
|
||||
connect(checker, &PerforceChecker::failed, errorLabel,
|
||||
[errorLabel, testButton, checker](const QString &t) {
|
||||
errorLabel->setStyleSheet("background-color: red");
|
||||
errorLabel->setText(t);
|
||||
testButton->setEnabled(true);
|
||||
checker->deleteLater();
|
||||
});
|
||||
connect(checker, &PerforceChecker::succeeded, errorLabel,
|
||||
[errorLabel, testButton, checker](const QString &repo) {
|
||||
errorLabel->setStyleSheet({});
|
||||
errorLabel->setText(tr("Test succeeded (%1).").arg(QDir::toNativeSeparators(repo)));
|
||||
testButton->setEnabled(true);
|
||||
checker->deleteLater();
|
||||
});
|
||||
|
||||
errorLabel->setStyleSheet(QString());
|
||||
errorLabel->setText(Settings::tr("Testing..."));
|
||||
const Settings &s = settings->settings();
|
||||
checker->start(s.p4BinaryPath.value(), QString(), s.commonP4Arguments(), 10000);
|
||||
});
|
||||
|
||||
Group config {
|
||||
Title(Settings::tr("Configuration")),
|
||||
Row { s.p4BinaryPath }
|
||||
};
|
||||
|
||||
Group environment {
|
||||
Title(Settings::tr("Environment Variables"), &s.customEnv),
|
||||
Row { s.p4Port, s.p4Client, s.p4User }
|
||||
};
|
||||
|
||||
Group misc {
|
||||
Title(Settings::tr("Miscellaneous")),
|
||||
Row { s.logCount, s.timeOutS, Stretch() },
|
||||
s.promptToSubmit,
|
||||
s.autoOpen
|
||||
};
|
||||
|
||||
Column {
|
||||
config,
|
||||
environment,
|
||||
misc,
|
||||
Row { errorLabel, Stretch(), testButton },
|
||||
Stretch()
|
||||
}.attachTo(widget);
|
||||
});
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Perforce
|
||||
|
@@ -25,19 +25,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <utils/aspects.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
class QDir;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Perforce {
|
||||
namespace Internal {
|
||||
|
||||
struct Settings {
|
||||
class Settings : public Utils::AspectContainer
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Perforce::Internal::SettingsPage)
|
||||
|
||||
public:
|
||||
Settings();
|
||||
bool equals(const Settings &s) const;
|
||||
QStringList commonP4Arguments() const;
|
||||
|
||||
// Checks. On success, errorMessage will contains the client root.
|
||||
@@ -46,22 +50,17 @@ struct Settings {
|
||||
QString *repositoryRoot /* = 0 */,
|
||||
QString *errorMessage);
|
||||
|
||||
QString p4Command;
|
||||
QString p4BinaryPath;
|
||||
QString p4Port;
|
||||
QString p4Client;
|
||||
QString p4User;
|
||||
QString errorString;
|
||||
int logCount;
|
||||
bool defaultEnv = true;
|
||||
int timeOutS;
|
||||
bool promptToSubmit = true;
|
||||
bool autoOpen = true;
|
||||
Utils::StringAspect p4BinaryPath;
|
||||
Utils::StringAspect p4Port;
|
||||
Utils::StringAspect p4Client;
|
||||
Utils::StringAspect p4User;
|
||||
Utils::IntegerAspect logCount;
|
||||
Utils::BoolAspect customEnv;
|
||||
Utils::IntegerAspect timeOutS;
|
||||
Utils::BoolAspect promptToSubmit;
|
||||
Utils::BoolAspect autoOpen;
|
||||
};
|
||||
|
||||
inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
|
||||
inline bool operator!=(const Settings &s1, const Settings &s2) { return !s1.equals(s2); }
|
||||
|
||||
/* PerforceSettings: Aggregates settings struct and toplevel directory
|
||||
* which is determined externally by background checks and provides a convenience
|
||||
* for determining the common arguments.
|
||||
@@ -83,22 +82,15 @@ public:
|
||||
~PerforceSettings();
|
||||
PerforceSettings(const PerforceSettings &other) = delete;
|
||||
|
||||
inline bool isValid() const
|
||||
{
|
||||
return !m_topLevel.isEmpty() && !m_settings.p4BinaryPath.isEmpty();
|
||||
}
|
||||
bool isValid() const;
|
||||
|
||||
void fromSettings(QSettings *settings);
|
||||
void toSettings(QSettings *) const;
|
||||
const Settings &settings() const { return m_settings; }
|
||||
Settings &settings() { return m_settings; }
|
||||
|
||||
void setSettings(const Settings &s);
|
||||
Settings settings() const;
|
||||
|
||||
inline int timeOutS() const { return m_settings.timeOutS; }
|
||||
inline int longTimeOutS() const { return m_settings.timeOutS * 10; }
|
||||
inline int timeOutMS() const { return m_settings.timeOutS * 1000; }
|
||||
|
||||
inline int logCount() const { return m_settings.logCount; }
|
||||
int timeOutS() const { return m_settings.timeOutS.value(); }
|
||||
int longTimeOutS() const { return m_settings.timeOutS.value() * 10; }
|
||||
int timeOutMS() const { return m_settings.timeOutS.value() * 1000; }
|
||||
int logCount() const { return m_settings.logCount.value(); }
|
||||
|
||||
QString topLevel() const;
|
||||
QString topLevelSymLinkTarget() const;
|
||||
@@ -115,7 +107,6 @@ public:
|
||||
// Map p4 path back to file system in case of a symlinked top-level
|
||||
QString mapToFileSystem(const QString &perforceFilePath) const;
|
||||
|
||||
QString p4Command() const;
|
||||
QString p4BinaryPath() const;
|
||||
QString p4Port() const;
|
||||
QString p4Client() const;
|
||||
@@ -129,15 +120,22 @@ public:
|
||||
// Return basic arguments, including -d and server connection parameters.
|
||||
QStringList commonP4Arguments(const QString &workingDir) const;
|
||||
|
||||
private:
|
||||
inline QStringList workingDirectoryArguments(const QString &workingDir) const;
|
||||
void clearTopLevel();
|
||||
|
||||
private:
|
||||
QStringList workingDirectoryArguments(const QString &workingDir) const;
|
||||
|
||||
Settings m_settings;
|
||||
QString m_topLevel;
|
||||
QString m_topLevelSymLinkTarget;
|
||||
QDir *m_topLevelDir = nullptr;
|
||||
};
|
||||
|
||||
class PerforceSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
explicit PerforceSettingsPage(PerforceSettings *settings);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Perforce
|
||||
|
@@ -1,158 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** 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 "settingspage.h"
|
||||
#include "perforcesettings.h"
|
||||
#include "perforceplugin.h"
|
||||
#include "perforcechecker.h"
|
||||
|
||||
#include <vcsbase/vcsbaseconstants.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLineEdit>
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Perforce {
|
||||
namespace Internal {
|
||||
|
||||
class SettingsPageWidget final : public Core::IOptionsPageWidget
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Perforce::Internal::SettingsPage)
|
||||
|
||||
public:
|
||||
SettingsPageWidget(PerforceSettings *settings, const std::function<void()> &onApply);
|
||||
~SettingsPageWidget() final;
|
||||
|
||||
private:
|
||||
void apply() final;
|
||||
|
||||
Settings settings() const;
|
||||
|
||||
void slotTest();
|
||||
void setStatusText(const QString &);
|
||||
void setStatusError(const QString &);
|
||||
void testSucceeded(const QString &repo);
|
||||
|
||||
Ui::SettingsPage m_ui;
|
||||
PerforceChecker *m_checker = nullptr;
|
||||
PerforceSettings *m_settings = nullptr;
|
||||
std::function<void()> m_onApply;
|
||||
};
|
||||
|
||||
SettingsPageWidget::SettingsPageWidget(PerforceSettings *settings, const std::function<void()> &onApply)
|
||||
: m_settings(settings), m_onApply(onApply)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
m_ui.errorLabel->clear();
|
||||
m_ui.pathChooser->setPromptDialogTitle(tr("Perforce Command"));
|
||||
m_ui.pathChooser->setHistoryCompleter(QLatin1String("Perforce.Command.History"));
|
||||
m_ui.pathChooser->setExpectedKind(PathChooser::Command);
|
||||
connect(m_ui.testPushButton, &QPushButton::clicked, this, &SettingsPageWidget::slotTest);
|
||||
|
||||
const PerforceSettings &s = *settings;
|
||||
m_ui.pathChooser->setPath(s.p4Command());
|
||||
m_ui.environmentGroupBox->setChecked(!s.defaultEnv());
|
||||
m_ui.portLineEdit->setText(s.p4Port());
|
||||
m_ui.clientLineEdit->setText(s.p4Client());
|
||||
m_ui.userLineEdit->setText(s.p4User());
|
||||
m_ui.logCountSpinBox->setValue(s.logCount());
|
||||
m_ui.timeOutSpinBox->setValue(s.timeOutS());
|
||||
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit());
|
||||
m_ui.autoOpenCheckBox->setChecked(s.autoOpen());
|
||||
}
|
||||
|
||||
SettingsPageWidget::~SettingsPageWidget()
|
||||
{
|
||||
delete m_checker;
|
||||
}
|
||||
|
||||
void SettingsPageWidget::slotTest()
|
||||
{
|
||||
if (!m_checker) {
|
||||
m_checker = new PerforceChecker(this);
|
||||
m_checker->setUseOverideCursor(true);
|
||||
connect(m_checker, &PerforceChecker::failed, this, &SettingsPageWidget::setStatusError);
|
||||
connect(m_checker, &PerforceChecker::succeeded, this, &SettingsPageWidget::testSucceeded);
|
||||
}
|
||||
|
||||
if (m_checker->isRunning())
|
||||
return;
|
||||
|
||||
setStatusText(tr("Testing..."));
|
||||
const Settings s = m_settings->settings();
|
||||
m_checker->start(s.p4BinaryPath, QString(), s.commonP4Arguments(), 10000);
|
||||
}
|
||||
|
||||
void SettingsPageWidget::testSucceeded(const QString &repo)
|
||||
{
|
||||
setStatusText(tr("Test succeeded (%1).").arg(QDir::toNativeSeparators(repo)));
|
||||
}
|
||||
|
||||
void SettingsPageWidget::apply()
|
||||
{
|
||||
Settings settings;
|
||||
settings.p4Command = m_ui.pathChooser->rawPath();
|
||||
settings.p4BinaryPath = m_ui.pathChooser->path();
|
||||
settings.defaultEnv = !m_ui.environmentGroupBox->isChecked();
|
||||
settings.p4Port = m_ui.portLineEdit->text();
|
||||
settings.p4User = m_ui.userLineEdit->text();
|
||||
settings.p4Client= m_ui.clientLineEdit->text();
|
||||
settings.timeOutS = m_ui.timeOutSpinBox->value();
|
||||
settings.logCount = m_ui.logCountSpinBox->value();
|
||||
settings.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
|
||||
settings.autoOpen = m_ui.autoOpenCheckBox->isChecked();
|
||||
|
||||
if (settings == m_settings->settings())
|
||||
return;
|
||||
|
||||
m_settings->setSettings(settings);
|
||||
m_onApply();
|
||||
}
|
||||
|
||||
void SettingsPageWidget::setStatusText(const QString &t)
|
||||
{
|
||||
m_ui.errorLabel->setStyleSheet(QString());
|
||||
m_ui.errorLabel->setText(t);
|
||||
}
|
||||
|
||||
void SettingsPageWidget::setStatusError(const QString &t)
|
||||
{
|
||||
m_ui.errorLabel->setStyleSheet(QLatin1String("background-color: red"));
|
||||
m_ui.errorLabel->setText(t);
|
||||
}
|
||||
|
||||
SettingsPage::SettingsPage(PerforceSettings *settings, const std::function<void ()> &onApply)
|
||||
{
|
||||
setId(VcsBase::Constants::VCS_ID_PERFORCE);
|
||||
setDisplayName(SettingsPageWidget::tr("Perforce"));
|
||||
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
|
||||
setWidgetCreator([settings, onApply] { return new SettingsPageWidget(settings, onApply); });
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Perforce
|
@@ -1,44 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** 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>
|
||||
|
||||
#include "ui_settingspage.h"
|
||||
|
||||
namespace Perforce {
|
||||
namespace Internal {
|
||||
|
||||
class PerforceSettings;
|
||||
|
||||
class SettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
SettingsPage(PerforceSettings *settings, const std::function<void()> &onApply);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Perforce
|
@@ -1,228 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Perforce::Internal::SettingsPage</class>
|
||||
<widget class="QWidget" name="Perforce::Internal::SettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>595</width>
|
||||
<height>366</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="configGroupBox">
|
||||
<property name="title">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="commandLabel">
|
||||
<property name="text">
|
||||
<string>P4 command:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Utils::PathChooser" name="pathChooser" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="environmentGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Environment Variables</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="portLabel">
|
||||
<property name="text">
|
||||
<string>P4 port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="portLineEdit"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="clientLabel">
|
||||
<property name="text">
|
||||
<string>P4 client:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLineEdit" name="clientLineEdit"/>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QLabel" name="userLabel">
|
||||
<property name="text">
|
||||
<string>P4 user:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<widget class="QLineEdit" name="userLineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="miscGroupBox">
|
||||
<property name="title">
|
||||
<string>Miscellaneous</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="logCountLabel">
|
||||
<property name="text">
|
||||
<string>Log count:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="logCountSpinBox">
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="timeOutLabel">
|
||||
<property name="text">
|
||||
<string>Timeout:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QSpinBox" name="timeOutSpinBox">
|
||||
<property name="suffix">
|
||||
<string>s</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</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_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>396</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="promptToSubmitCheckBox">
|
||||
<property name="text">
|
||||
<string>Prompt on submit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QCheckBox" name="autoOpenCheckBox">
|
||||
<property name="text">
|
||||
<string>Automatically open files when editing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="errorLabel">
|
||||
<property name="text">
|
||||
<string notr="true" extracomment="Placeholder">errorLabel: blah blubb</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="testPushButton">
|
||||
<property name="text">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</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>environmentGroupBox</tabstop>
|
||||
<tabstop>portLineEdit</tabstop>
|
||||
<tabstop>clientLineEdit</tabstop>
|
||||
<tabstop>userLineEdit</tabstop>
|
||||
<tabstop>logCountSpinBox</tabstop>
|
||||
<tabstop>timeOutSpinBox</tabstop>
|
||||
<tabstop>promptToSubmitCheckBox</tabstop>
|
||||
<tabstop>autoOpenCheckBox</tabstop>
|
||||
<tabstop>testPushButton</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in New Issue
Block a user