forked from qt-creator/qt-creator
Nim: Use aspects in NimRunConfiguration similarly to other runconfigs
Change-Id: I4b9d9cda4867c36cece3f4d4e208ec4163a7d6b8 Reviewed-by: Filippo Cucchetto <filippocucchetto@gmail.com> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -23,7 +23,6 @@ HEADERS += \
|
||||
project/nimcompilercleanstep.h \
|
||||
project/nimcompilercleanstepconfigwidget.h \
|
||||
project/nimrunconfiguration.h \
|
||||
project/nimrunconfigurationwidget.h \
|
||||
project/nimbuildconfigurationwidget.h \
|
||||
editor/nimeditorfactory.h \
|
||||
settings/nimcodestylesettingspage.h \
|
||||
@@ -46,7 +45,6 @@ SOURCES += \
|
||||
project/nimcompilercleanstep.cpp \
|
||||
project/nimcompilercleanstepconfigwidget.cpp \
|
||||
project/nimrunconfiguration.cpp \
|
||||
project/nimrunconfigurationwidget.cpp \
|
||||
project/nimbuildconfigurationwidget.cpp \
|
||||
editor/nimeditorfactory.cpp \
|
||||
settings/nimcodestylesettingspage.cpp \
|
||||
|
||||
@@ -44,7 +44,6 @@ QtcPlugin {
|
||||
"nimproject.h", "nimproject.cpp",
|
||||
"nimprojectnode.h", "nimprojectnode.cpp",
|
||||
"nimrunconfiguration.h", "nimrunconfiguration.cpp",
|
||||
"nimrunconfigurationwidget.h", "nimrunconfigurationwidget.cpp",
|
||||
"nimtoolchain.h", "nimtoolchain.cpp",
|
||||
"nimtoolchainfactory.h", "nimtoolchainfactory.cpp",
|
||||
]
|
||||
|
||||
@@ -42,15 +42,7 @@ const char C_NIMTOOLCHAIN_COMPILER_COMMAND_KEY[] = "Nim.NimToolChain.CompilerCom
|
||||
|
||||
// NimRunConfiguration
|
||||
const char C_NIMRUNCONFIGURATION_ID[] = "Nim.NimRunConfiguration";
|
||||
const char C_NIMRUNCONFIGURATION_DISPLAY[] = QT_TRANSLATE_NOOP("NimRunConfiguration", "Current Build Target");
|
||||
const char C_NIMRUNCONFIGURATION_DEFAULT_DISPLAY[] = QT_TRANSLATE_NOOP("NimRunConfiguration", "Current Build Target");
|
||||
const QString C_NIMRUNCONFIGURATION_EXECUTABLE_KEY = QStringLiteral("Nim.NimRunConfiguration.Executable");
|
||||
const QString C_NIMRUNCONFIGURATION_WORKINGDIRECTORY_KEY = QStringLiteral("Nim.NimRunConfiguration.WorkingDirectory");
|
||||
const QString C_NIMRUNCONFIGURATION_COMMANDLINEARGS_KEY = QStringLiteral("Nim.NimRunConfiguration.CommandlineArgs");
|
||||
const QString C_NIMRUNCONFIGURATION_RUNMODE_KEY = QStringLiteral("Nim.NimRunConfiguration.RunMode");
|
||||
const QString C_NIMRUNCONFIGURATION_WORKINGDIRECTORYASPECT_ID = QStringLiteral("Nim.NimRunConfiguration.WorkingDirectoryAspect");
|
||||
const QString C_NIMRUNCONFIGURATION_ARGUMENTASPECT_ID = QStringLiteral("Nim.NimRunConfiguration.ArgumentAspect");
|
||||
const QString C_NIMRUNCONFIGURATION_TERMINALASPECT_ID = QStringLiteral("Nim.NimRunConfiguration.TerminalAspect");
|
||||
|
||||
// NimProject
|
||||
const char C_NIMPROJECT_EXCLUDEDFILES[] = "Nim.NimProjectExcludedFiles";
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "nimrunconfiguration.h"
|
||||
#include "nimbuildconfiguration.h"
|
||||
#include "nimrunconfigurationwidget.h"
|
||||
|
||||
#include "../nimconstants.h"
|
||||
|
||||
@@ -37,27 +36,40 @@
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFormLayout>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Nim {
|
||||
|
||||
class NimRunConfigurationWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
explicit NimRunConfigurationWidget(NimRunConfiguration *rc)
|
||||
{
|
||||
auto fl = new QFormLayout(this);
|
||||
rc->extraAspect<ExecutableAspect>()->addToMainConfigurationWidget(this, fl);
|
||||
rc->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, fl);
|
||||
rc->extraAspect<WorkingDirectoryAspect>()->addToMainConfigurationWidget(this, fl);
|
||||
rc->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, fl);
|
||||
}
|
||||
};
|
||||
|
||||
NimRunConfiguration::NimRunConfiguration(Target *target)
|
||||
: RunConfiguration(target, Constants::C_NIMRUNCONFIGURATION_ID)
|
||||
, m_workingDirectoryAspect(new WorkingDirectoryAspect(this, Nim::Constants::C_NIMRUNCONFIGURATION_WORKINGDIRECTORYASPECT_ID))
|
||||
, m_argumentAspect(new ArgumentsAspect(this, Nim::Constants::C_NIMRUNCONFIGURATION_ARGUMENTASPECT_ID))
|
||||
, m_terminalAspect(new TerminalAspect(this, Nim::Constants::C_NIMRUNCONFIGURATION_TERMINALASPECT_ID))
|
||||
, m_localEnvironmentAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()))
|
||||
{
|
||||
m_terminalAspect->setRunMode(ApplicationLauncher::Gui);
|
||||
auto terminalAspect = new TerminalAspect(this, "Nim.NimRunConfiguration.TerminalAspect");
|
||||
terminalAspect->setRunMode(ApplicationLauncher::Gui);
|
||||
addExtraAspect(terminalAspect);
|
||||
|
||||
addExtraAspect(m_argumentAspect);
|
||||
addExtraAspect(m_terminalAspect);
|
||||
addExtraAspect(m_localEnvironmentAspect);
|
||||
addExtraAspect(new ExecutableAspect(this));
|
||||
addExtraAspect(new ArgumentsAspect(this, "Nim.NimRunConfiguration.ArgumentAspect"));
|
||||
addExtraAspect(new WorkingDirectoryAspect(this, "Nim.NimRunConfiguration.WorkingDirectoryAspect"));
|
||||
addExtraAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()));
|
||||
|
||||
setDisplayName(tr(Constants::C_NIMRUNCONFIGURATION_DISPLAY));
|
||||
setDefaultDisplayName(tr(Constants::C_NIMRUNCONFIGURATION_DEFAULT_DISPLAY));
|
||||
setDisplayName(tr("Current Build Target"));
|
||||
setDefaultDisplayName(tr("Current Build Target"));
|
||||
|
||||
// Connect target signals
|
||||
connect(target, &Target::activeBuildConfigurationChanged,
|
||||
@@ -67,45 +79,29 @@ NimRunConfiguration::NimRunConfiguration(Target *target)
|
||||
|
||||
QWidget *NimRunConfiguration::createConfigurationWidget()
|
||||
{
|
||||
return new NimRunConfigurationWidget(this);
|
||||
return wrapWidget(new NimRunConfigurationWidget(this));
|
||||
}
|
||||
|
||||
Runnable NimRunConfiguration::runnable() const
|
||||
{
|
||||
StandardRunnable result;
|
||||
result.runMode = m_terminalAspect->runMode();
|
||||
result.executable = m_executable;
|
||||
result.commandLineArguments = m_argumentAspect->arguments();
|
||||
result.workingDirectory = m_workingDirectoryAspect->workingDirectory().toString();
|
||||
result.environment = m_localEnvironmentAspect->environment();
|
||||
result.runMode = extraAspect<TerminalAspect>()->runMode();
|
||||
result.executable = extraAspect<ExecutableAspect>()->executable().toString();
|
||||
result.commandLineArguments = extraAspect<ArgumentsAspect>()->arguments();
|
||||
result.workingDirectory = extraAspect<WorkingDirectoryAspect>()->workingDirectory().toString();
|
||||
result.environment = extraAspect<EnvironmentAspect>()->environment();
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantMap NimRunConfiguration::toMap() const
|
||||
{
|
||||
auto result = RunConfiguration::toMap();
|
||||
result[Constants::C_NIMRUNCONFIGURATION_EXECUTABLE_KEY] = m_executable;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool NimRunConfiguration::fromMap(const QVariantMap &map)
|
||||
{
|
||||
bool result = RunConfiguration::fromMap(map);
|
||||
if (!result)
|
||||
return result;
|
||||
m_executable = map[Constants::C_NIMRUNCONFIGURATION_EXECUTABLE_KEY].toString();
|
||||
return true;
|
||||
}
|
||||
|
||||
void NimRunConfiguration::updateConfiguration()
|
||||
{
|
||||
auto buildConfiguration = qobject_cast<NimBuildConfiguration *>(activeBuildConfiguration());
|
||||
QTC_ASSERT(buildConfiguration, return);
|
||||
setActiveBuildConfiguration(buildConfiguration);
|
||||
const QFileInfo outFileInfo = buildConfiguration->outFilePath().toFileInfo();
|
||||
m_executable = outFileInfo.absoluteFilePath();
|
||||
extraAspect<ExecutableAspect>()->setExecutable(FileName::fromString(outFileInfo.absoluteFilePath()));
|
||||
const QString workingDirectory = outFileInfo.absoluteDir().absolutePath();
|
||||
m_workingDirectoryAspect->setDefaultWorkingDirectory(FileName::fromString(workingDirectory));
|
||||
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(FileName::fromString(workingDirectory));
|
||||
}
|
||||
|
||||
void NimRunConfiguration::setActiveBuildConfiguration(NimBuildConfiguration *activeBuildConfiguration)
|
||||
@@ -132,10 +128,10 @@ void NimRunConfiguration::setActiveBuildConfiguration(NimBuildConfiguration *act
|
||||
|
||||
// NimRunConfigurationFactory
|
||||
|
||||
NimRunConfigurationFactory::NimRunConfigurationFactory() : FixedRunConfigurationFactory("-TempRunConf")
|
||||
NimRunConfigurationFactory::NimRunConfigurationFactory() : FixedRunConfigurationFactory(QString())
|
||||
{
|
||||
registerRunConfiguration<NimRunConfiguration>(Constants::C_NIMRUNCONFIGURATION_ID);
|
||||
addSupportedProjectType(Constants::C_NIMPROJECT_ID);
|
||||
}
|
||||
|
||||
}
|
||||
} // Nim
|
||||
|
||||
@@ -27,13 +27,6 @@
|
||||
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class WorkingDirectoryAspect;
|
||||
class ArgumentsAspect;
|
||||
class TerminalAspect;
|
||||
class LocalEnvironmentAspect;
|
||||
}
|
||||
|
||||
namespace Nim {
|
||||
|
||||
class NimBuildConfiguration;
|
||||
@@ -47,19 +40,12 @@ public:
|
||||
|
||||
QWidget *createConfigurationWidget() override;
|
||||
ProjectExplorer::Runnable runnable() const override;
|
||||
QVariantMap toMap() const override;
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
|
||||
private:
|
||||
void updateConfiguration();
|
||||
void setActiveBuildConfiguration(NimBuildConfiguration *activeBuildConfiguration);
|
||||
|
||||
QString m_executable;
|
||||
NimBuildConfiguration *m_buildConfiguration = nullptr;
|
||||
ProjectExplorer::WorkingDirectoryAspect* m_workingDirectoryAspect;
|
||||
ProjectExplorer::ArgumentsAspect* m_argumentAspect;
|
||||
ProjectExplorer::TerminalAspect* m_terminalAspect;
|
||||
ProjectExplorer::LocalEnvironmentAspect* m_localEnvironmentAspect;
|
||||
};
|
||||
|
||||
class NimRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
||||
** Contact: http://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 "nimrunconfigurationwidget.h"
|
||||
#include "nimrunconfiguration.h"
|
||||
|
||||
#include <projectexplorer/runconfigurationaspects.h>
|
||||
|
||||
#include <QFormLayout>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace Nim {
|
||||
|
||||
NimRunConfigurationWidget::NimRunConfigurationWidget(NimRunConfiguration *rc,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_rc(rc)
|
||||
{
|
||||
QTC_ASSERT(rc, return);
|
||||
auto fl = new QFormLayout(this);
|
||||
fl->setMargin(0);
|
||||
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
||||
rc->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, fl);
|
||||
rc->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this,fl);
|
||||
}
|
||||
|
||||
} // namespace Nim
|
||||
@@ -1,45 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
||||
** Contact: http://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 <QWidget>
|
||||
|
||||
namespace Nim {
|
||||
|
||||
class NimRunConfiguration;
|
||||
|
||||
class NimRunConfigurationWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NimRunConfigurationWidget(NimRunConfiguration *rc, QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
NimRunConfiguration* m_rc;
|
||||
};
|
||||
|
||||
} // namespace Nim
|
||||
Reference in New Issue
Block a user