forked from qt-creator/qt-creator
Android: Simplify pre-/post-run adb command input
AdbCommandWidget is cumbersome to use and has issues regarding updating the enabled state of the buttons and the dragging and dropping of items. Cut the maintenance and replace AdbCommandWidget with a StringAspect, where one line means one entry, just like several other places in Qt Creator do. Some residue remains though: in order to keep project settings compatibility, we need to convert from QStringList (settings) to QString (StringAspect) and back. Change-Id: I3ebfff882358ba2e8c0ac6d5b309e89a84f0554c Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -2,7 +2,6 @@ add_qtc_plugin(Android
|
|||||||
DEPENDS QtcSsh QmlDebug Qt5::Xml LanguageServerProtocol
|
DEPENDS QtcSsh QmlDebug Qt5::Xml LanguageServerProtocol
|
||||||
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport LanguageClient
|
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport LanguageClient
|
||||||
SOURCES
|
SOURCES
|
||||||
adbcommandswidget.cpp adbcommandswidget.h adbcommandswidget.ui
|
|
||||||
addnewavddialog.ui
|
addnewavddialog.ui
|
||||||
android.qrc
|
android.qrc
|
||||||
android_global.h
|
android_global.h
|
||||||
|
|||||||
@@ -1,189 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2017 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 "adbcommandswidget.h"
|
|
||||||
#include "ui_adbcommandswidget.h"
|
|
||||||
|
|
||||||
#include <utils/utilsicons.h>
|
|
||||||
|
|
||||||
#include <QGroupBox>
|
|
||||||
#include <QItemSelectionModel>
|
|
||||||
#include <QShortcut>
|
|
||||||
#include <QStringListModel>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace Android {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
using namespace std::placeholders;
|
|
||||||
|
|
||||||
const char defaultCommand[] = "echo \"shell command\"";
|
|
||||||
|
|
||||||
static void swapData(QStringListModel *model, const QModelIndex &srcIndex,
|
|
||||||
const QModelIndex &destIndex)
|
|
||||||
{
|
|
||||||
if (model) {
|
|
||||||
QVariant data = model->data(destIndex, Qt::EditRole); // QTBUG-55078
|
|
||||||
model->setData(destIndex, model->data(srcIndex, Qt::EditRole));
|
|
||||||
model->setData(srcIndex, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AdbCommandsWidgetPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AdbCommandsWidgetPrivate(AdbCommandsWidget *parent);
|
|
||||||
~AdbCommandsWidgetPrivate();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addString(const QString &str);
|
|
||||||
void onAddButton();
|
|
||||||
void onMoveUpButton();
|
|
||||||
void onMoveDownButton();
|
|
||||||
void onRemove();
|
|
||||||
void onCurrentIndexChanged(const QModelIndex &newIndex, const QModelIndex &prevIndex);
|
|
||||||
|
|
||||||
AdbCommandsWidget *q;
|
|
||||||
Ui::AdbCommandsWidget *m_ui = nullptr;
|
|
||||||
QStringListModel *m_stringModel = nullptr;
|
|
||||||
friend class AdbCommandsWidget;
|
|
||||||
};
|
|
||||||
|
|
||||||
AdbCommandsWidget::AdbCommandsWidget()
|
|
||||||
: d(new AdbCommandsWidgetPrivate(this))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AdbCommandsWidget::~AdbCommandsWidget() = default;
|
|
||||||
|
|
||||||
QStringList AdbCommandsWidget::commandsList() const
|
|
||||||
{
|
|
||||||
return d->m_stringModel->stringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidget::setTitleText(const QString &title)
|
|
||||||
{
|
|
||||||
setTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidget::setCommandList(const QStringList &commands)
|
|
||||||
{
|
|
||||||
d->m_stringModel->setStringList(commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
AdbCommandsWidgetPrivate::AdbCommandsWidgetPrivate(AdbCommandsWidget *q):
|
|
||||||
q(q),
|
|
||||||
m_ui(new Ui::AdbCommandsWidget),
|
|
||||||
m_stringModel(new QStringListModel)
|
|
||||||
{
|
|
||||||
m_ui->setupUi(q);
|
|
||||||
m_ui->addButton->setIcon(Utils::Icons::PLUS.icon());
|
|
||||||
m_ui->removeButton->setIcon(Utils::Icons::MINUS.icon());
|
|
||||||
m_ui->moveUpButton->setIcon(Utils::Icons::ARROW_UP.icon());
|
|
||||||
m_ui->moveDownButton->setIcon(Utils::Icons::ARROW_DOWN.icon());
|
|
||||||
|
|
||||||
auto deleteShortcut = new QShortcut(QKeySequence(QKeySequence::Delete), m_ui->commandsView);
|
|
||||||
deleteShortcut->setContext(Qt::WidgetShortcut);
|
|
||||||
QObject::connect(deleteShortcut, &QShortcut::activated,
|
|
||||||
std::bind(&AdbCommandsWidgetPrivate::onRemove, this));
|
|
||||||
|
|
||||||
QObject::connect(m_ui->addButton, &QToolButton::clicked,
|
|
||||||
std::bind(&AdbCommandsWidgetPrivate::onAddButton, this));
|
|
||||||
QObject::connect(m_ui->removeButton, &QToolButton::clicked,
|
|
||||||
std::bind(&AdbCommandsWidgetPrivate::onRemove, this));
|
|
||||||
QObject::connect(m_ui->moveUpButton, &QToolButton::clicked,
|
|
||||||
std::bind(&AdbCommandsWidgetPrivate::onMoveUpButton, this));
|
|
||||||
QObject::connect(m_ui->moveDownButton, &QToolButton::clicked,
|
|
||||||
std::bind(&AdbCommandsWidgetPrivate::onMoveDownButton, this));
|
|
||||||
|
|
||||||
m_ui->commandsView->setModel(m_stringModel);
|
|
||||||
QObject::connect(m_stringModel, &QStringListModel::dataChanged,
|
|
||||||
q, &AdbCommandsWidget::commandsChanged);
|
|
||||||
QObject::connect(m_stringModel, &QStringListModel::rowsRemoved,
|
|
||||||
q, &AdbCommandsWidget::commandsChanged);
|
|
||||||
QObject::connect(m_ui->commandsView->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
||||||
std::bind(&AdbCommandsWidgetPrivate::onCurrentIndexChanged, this, _1, _2));
|
|
||||||
}
|
|
||||||
|
|
||||||
AdbCommandsWidgetPrivate::~AdbCommandsWidgetPrivate()
|
|
||||||
{
|
|
||||||
delete m_ui;
|
|
||||||
delete m_stringModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidgetPrivate::addString(const QString &str)
|
|
||||||
{
|
|
||||||
if (!str.isEmpty()) {
|
|
||||||
m_stringModel->insertRows(m_stringModel->rowCount(), 1);
|
|
||||||
const QModelIndex lastItemIndex = m_stringModel->index(m_stringModel->rowCount() - 1);
|
|
||||||
m_stringModel->setData(lastItemIndex, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidgetPrivate::onAddButton()
|
|
||||||
{
|
|
||||||
addString(defaultCommand);
|
|
||||||
const QModelIndex index = m_stringModel->index(m_stringModel->rowCount() - 1);
|
|
||||||
m_ui->commandsView->setCurrentIndex(index);
|
|
||||||
m_ui->commandsView->edit(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidgetPrivate::onMoveUpButton()
|
|
||||||
{
|
|
||||||
QModelIndex index = m_ui->commandsView->currentIndex();
|
|
||||||
if (index.row() > 0) {
|
|
||||||
const QModelIndex newIndex = m_stringModel->index(index.row() - 1, 0);
|
|
||||||
swapData(m_stringModel, index, newIndex);
|
|
||||||
m_ui->commandsView->setCurrentIndex(newIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidgetPrivate::onMoveDownButton()
|
|
||||||
{
|
|
||||||
QModelIndex index = m_ui->commandsView->currentIndex();
|
|
||||||
if (index.row() < m_stringModel->rowCount() - 1) {
|
|
||||||
const QModelIndex newIndex = m_stringModel->index(index.row() + 1, 0);
|
|
||||||
swapData(m_stringModel, index, newIndex);
|
|
||||||
m_ui->commandsView->setCurrentIndex(newIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidgetPrivate::onRemove()
|
|
||||||
{
|
|
||||||
const QModelIndex &index = m_ui->commandsView->currentIndex();
|
|
||||||
if (index.isValid())
|
|
||||||
m_stringModel->removeRow(index.row());
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdbCommandsWidgetPrivate::onCurrentIndexChanged(const QModelIndex &newIndex, const QModelIndex &prevIndex)
|
|
||||||
{
|
|
||||||
Q_UNUSED(prevIndex)
|
|
||||||
m_ui->moveUpButton->setEnabled(newIndex.row() != 0);
|
|
||||||
m_ui->moveDownButton->setEnabled(newIndex.row() < m_stringModel->rowCount() - 1);
|
|
||||||
m_ui->removeButton->setEnabled(newIndex.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Internal
|
|
||||||
} // Android
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2017 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 <QGroupBox>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Android {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class AdbCommandsWidgetPrivate;
|
|
||||||
|
|
||||||
class AdbCommandsWidget : public QGroupBox
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
AdbCommandsWidget();
|
|
||||||
~AdbCommandsWidget() override;
|
|
||||||
|
|
||||||
QStringList commandsList() const;
|
|
||||||
void setCommandList(const QStringList &commands);
|
|
||||||
|
|
||||||
void setTitleText(const QString &title);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void commandsChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<AdbCommandsWidgetPrivate> d;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Internal
|
|
||||||
} // Android
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>AdbCommandsWidget</class>
|
|
||||||
<widget class="QGroupBox" name="AdbCommandsWidget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>682</width>
|
|
||||||
<height>391</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Widget</string>
|
|
||||||
</property>
|
|
||||||
<property name="title">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="2" column="1">
|
|
||||||
<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>
|
|
||||||
<item row="0" column="0" rowspan="6">
|
|
||||||
<widget class="QListView" name="commandsView">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="defaultDropAction">
|
|
||||||
<enum>Qt::MoveAction</enum>
|
|
||||||
</property>
|
|
||||||
<property name="movement">
|
|
||||||
<enum>QListView::Snap</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QToolButton" name="moveUpButton">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="arrowType">
|
|
||||||
<enum>Qt::NoArrow</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1">
|
|
||||||
<spacer name="verticalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QToolButton" name="addButton">
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QToolButton" name="moveDownButton">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="arrowType">
|
|
||||||
<enum>Qt::NoArrow</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QToolButton" name="removeButton">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
|
||||||
<tabstops>
|
|
||||||
<tabstop>commandsView</tabstop>
|
|
||||||
<tabstop>addButton</tabstop>
|
|
||||||
<tabstop>removeButton</tabstop>
|
|
||||||
<tabstop>moveUpButton</tabstop>
|
|
||||||
<tabstop>moveDownButton</tabstop>
|
|
||||||
</tabstops>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
||||||
@@ -44,7 +44,6 @@ HEADERS += \
|
|||||||
androidbuildapkstep.h \
|
androidbuildapkstep.h \
|
||||||
androidsdkmanager.h \
|
androidsdkmanager.h \
|
||||||
androidavdmanager.h \
|
androidavdmanager.h \
|
||||||
adbcommandswidget.h \
|
|
||||||
androidsdkpackage.h \
|
androidsdkpackage.h \
|
||||||
androidsdkmodel.h \
|
androidsdkmodel.h \
|
||||||
androidsdkmanagerwidget.h \
|
androidsdkmanagerwidget.h \
|
||||||
@@ -91,7 +90,6 @@ SOURCES += \
|
|||||||
androidbuildapkstep.cpp \
|
androidbuildapkstep.cpp \
|
||||||
androidsdkmanager.cpp \
|
androidsdkmanager.cpp \
|
||||||
androidavdmanager.cpp \
|
androidavdmanager.cpp \
|
||||||
adbcommandswidget.cpp \
|
|
||||||
androidsdkpackage.cpp \
|
androidsdkpackage.cpp \
|
||||||
androidsdkmodel.cpp \
|
androidsdkmodel.cpp \
|
||||||
androidsdkmanagerwidget.cpp \
|
androidsdkmanagerwidget.cpp \
|
||||||
@@ -108,7 +106,6 @@ FORMS += \
|
|||||||
addnewavddialog.ui \
|
addnewavddialog.ui \
|
||||||
androidcreatekeystorecertificate.ui \
|
androidcreatekeystorecertificate.ui \
|
||||||
androiddevicedialog.ui \
|
androiddevicedialog.ui \
|
||||||
adbcommandswidget.ui \
|
|
||||||
androidsdkmanagerwidget.ui
|
androidsdkmanagerwidget.ui
|
||||||
|
|
||||||
RESOURCES = android.qrc
|
RESOURCES = android.qrc
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ Project {
|
|||||||
files: [
|
files: [
|
||||||
"android_global.h",
|
"android_global.h",
|
||||||
"android.qrc",
|
"android.qrc",
|
||||||
"adbcommandswidget.cpp",
|
|
||||||
"adbcommandswidget.h",
|
|
||||||
"adbcommandswidget.ui",
|
|
||||||
"addnewavddialog.ui",
|
"addnewavddialog.ui",
|
||||||
"androidavdmanager.cpp",
|
"androidavdmanager.cpp",
|
||||||
"androidavdmanager.h",
|
"androidavdmanager.h",
|
||||||
|
|||||||
@@ -29,66 +29,45 @@
|
|||||||
#include "androidglobal.h"
|
#include "androidglobal.h"
|
||||||
#include "androidtoolchain.h"
|
#include "androidtoolchain.h"
|
||||||
#include "androidmanager.h"
|
#include "androidmanager.h"
|
||||||
#include "adbcommandswidget.h"
|
|
||||||
|
|
||||||
#include <app/app_version.h>
|
#include <app/app_version.h>
|
||||||
|
|
||||||
#include <projectexplorer/buildsystem.h>
|
#include <projectexplorer/buildsystem.h>
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/runconfigurationaspects.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
|
|
||||||
#include <utils/detailswidget.h>
|
#include <utils/detailswidget.h>
|
||||||
#include <utils/layoutbuilder.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QSpacerItem>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
using namespace Android::Internal;
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
|
|
||||||
BaseStringListAspect::BaseStringListAspect(const QString &settingsKey, Utils::Id id)
|
class BaseStringListAspect final : public Utils::StringAspect
|
||||||
{
|
{
|
||||||
setSettingsKey(settingsKey);
|
public:
|
||||||
setId(id);
|
explicit BaseStringListAspect() = default;
|
||||||
|
~BaseStringListAspect() final = default;
|
||||||
|
|
||||||
|
void fromMap(const QVariantMap &map) final
|
||||||
|
{
|
||||||
|
// Pre Qt Creator 5.0 hack: Reads QStringList as QString
|
||||||
|
setValue(map.value(settingsKey()).toStringList().join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseStringListAspect::~BaseStringListAspect() = default;
|
void toMap(QVariantMap &map) const final
|
||||||
|
|
||||||
void BaseStringListAspect::addToLayout(LayoutBuilder &builder)
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(!m_widget);
|
// Pre Qt Creator 5.0 hack: Writes QString as QStringList
|
||||||
m_widget = new AdbCommandsWidget;
|
map.insert(settingsKey(), value().split('\n'));
|
||||||
m_widget->setCommandList(value());
|
|
||||||
m_widget->setTitleText(labelText());
|
|
||||||
builder.addItem(m_widget.data());
|
|
||||||
connect(m_widget.data(), &AdbCommandsWidget::commandsChanged, this, [this] {
|
|
||||||
BaseAspect::setValue(m_widget->commandsList());
|
|
||||||
emit changed();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList BaseStringListAspect::value() const
|
|
||||||
{
|
|
||||||
return BaseAspect::value().toStringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseStringListAspect::setValue(const QStringList &value)
|
|
||||||
{
|
|
||||||
BaseAspect::setValue(value);
|
|
||||||
if (m_widget)
|
|
||||||
m_widget->setCommandList(value);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Utils::Id id)
|
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Utils::Id id)
|
||||||
: RunConfiguration(target, id)
|
: RunConfiguration(target, id)
|
||||||
@@ -123,16 +102,16 @@ AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Utils::Id id)
|
|||||||
.arg(Core::Constants::IDE_DISPLAY_NAME));
|
.arg(Core::Constants::IDE_DISPLAY_NAME));
|
||||||
|
|
||||||
auto preStartShellCmdAspect = addAspect<BaseStringListAspect>();
|
auto preStartShellCmdAspect = addAspect<BaseStringListAspect>();
|
||||||
|
preStartShellCmdAspect->setDisplayStyle(StringAspect::TextEditDisplay);
|
||||||
preStartShellCmdAspect->setId(Constants::ANDROID_PRESTARTSHELLCMDLIST);
|
preStartShellCmdAspect->setId(Constants::ANDROID_PRESTARTSHELLCMDLIST);
|
||||||
preStartShellCmdAspect->setSettingsKey("Android.PreStartShellCmdListKey");
|
preStartShellCmdAspect->setSettingsKey("Android.PreStartShellCmdListKey");
|
||||||
preStartShellCmdAspect->setLabelText(
|
preStartShellCmdAspect->setLabelText(tr("Pre-launch on-device shell commands:"));
|
||||||
tr("Shell commands to run on Android device before application launch."));
|
|
||||||
|
|
||||||
auto postStartShellCmdAspect = addAspect<BaseStringListAspect>();
|
auto postStartShellCmdAspect = addAspect<BaseStringListAspect>();
|
||||||
|
postStartShellCmdAspect->setDisplayStyle(StringAspect::TextEditDisplay);
|
||||||
postStartShellCmdAspect->setId(Constants::ANDROID_POSTFINISHSHELLCMDLIST);
|
postStartShellCmdAspect->setId(Constants::ANDROID_POSTFINISHSHELLCMDLIST);
|
||||||
postStartShellCmdAspect->setSettingsKey("Android.PostStartShellCmdListKey");
|
postStartShellCmdAspect->setSettingsKey("Android.PostStartShellCmdListKey");
|
||||||
postStartShellCmdAspect->setLabelText(
|
postStartShellCmdAspect->setLabelText(tr("Post-quit on-device shell commands:"));
|
||||||
tr("Shell commands to run on Android device after application quits."));
|
|
||||||
|
|
||||||
setUpdater([this, target] {
|
setUpdater([this, target] {
|
||||||
const BuildTargetInfo bti = buildTargetInfo();
|
const BuildTargetInfo bti = buildTargetInfo();
|
||||||
|
|||||||
@@ -27,31 +27,10 @@
|
|||||||
|
|
||||||
#include "android_global.h"
|
#include "android_global.h"
|
||||||
|
|
||||||
#include "adbcommandswidget.h"
|
|
||||||
|
|
||||||
#include <projectexplorer/runconfiguration.h>
|
#include <projectexplorer/runconfiguration.h>
|
||||||
#include <projectexplorer/runconfigurationaspects.h>
|
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
|
|
||||||
class BaseStringListAspect : public Utils::BaseAspect
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit BaseStringListAspect(const QString &settingsKey = QString(),
|
|
||||||
Utils::Id id = Utils::Id());
|
|
||||||
~BaseStringListAspect() override;
|
|
||||||
|
|
||||||
void addToLayout(Utils::LayoutBuilder &builder) override;
|
|
||||||
|
|
||||||
QStringList value() const;
|
|
||||||
void setValue(const QStringList &val);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QPointer<Android::Internal::AdbCommandsWidget> m_widget; // Owned by RunConfigWidget
|
|
||||||
};
|
|
||||||
|
|
||||||
class ANDROID_EXPORT AndroidRunConfiguration : public ProjectExplorer::RunConfiguration
|
class ANDROID_EXPORT AndroidRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -297,14 +297,18 @@ AndroidRunnerWorker::AndroidRunnerWorker(RunWorker *runner, const QString &packa
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (auto aspect = runControl->aspect(Constants::ANDROID_PRESTARTSHELLCMDLIST)) {
|
if (auto aspect = runControl->aspect(Constants::ANDROID_PRESTARTSHELLCMDLIST)) {
|
||||||
for (const QString &shellCmd : static_cast<BaseStringListAspect *>(aspect)->value())
|
const QStringList commands =
|
||||||
|
static_cast<StringAspect *>(aspect)->value().split('\n', Qt::SkipEmptyParts);
|
||||||
|
for (const QString &shellCmd : commands)
|
||||||
m_beforeStartAdbCommands.append(QString("shell %1").arg(shellCmd));
|
m_beforeStartAdbCommands.append(QString("shell %1").arg(shellCmd));
|
||||||
}
|
}
|
||||||
for (const QString &shellCmd : runner->recordedData(Constants::ANDROID_PRESTARTSHELLCMDLIST).toStringList())
|
for (const QString &shellCmd : runner->recordedData(Constants::ANDROID_PRESTARTSHELLCMDLIST).toStringList())
|
||||||
m_beforeStartAdbCommands.append(QString("shell %1").arg(shellCmd));
|
m_beforeStartAdbCommands.append(QString("shell %1").arg(shellCmd));
|
||||||
|
|
||||||
if (auto aspect = runControl->aspect(Constants::ANDROID_POSTFINISHSHELLCMDLIST)) {
|
if (auto aspect = runControl->aspect(Constants::ANDROID_POSTFINISHSHELLCMDLIST)) {
|
||||||
for (const QString &shellCmd : static_cast<BaseStringListAspect *>(aspect)->value())
|
const QStringList commands =
|
||||||
|
static_cast<StringAspect *>(aspect)->value().split('\n', Qt::SkipEmptyParts);
|
||||||
|
for (const QString &shellCmd : commands)
|
||||||
m_afterFinishAdbCommands.append(QString("shell %1").arg(shellCmd));
|
m_afterFinishAdbCommands.append(QString("shell %1").arg(shellCmd));
|
||||||
}
|
}
|
||||||
for (const QString &shellCmd : runner->recordedData(Constants::ANDROID_POSTFINISHSHELLCMDLIST).toStringList())
|
for (const QString &shellCmd : runner->recordedData(Constants::ANDROID_POSTFINISHSHELLCMDLIST).toStringList())
|
||||||
|
|||||||
Reference in New Issue
Block a user