forked from qt-creator/qt-creator
ProjectExplorer: Revive project importer
Fixes a regression introduced in recent changes. Import project from build is now available again on the target setup page (shown when no kit is active) and in the context menu of the left pane. Task-number: QTCREATORBUG-17046 Change-Id: I5a1285624084f0cb6e0947560516ae88d4b3e376 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -25,11 +25,14 @@
|
||||
|
||||
#include "projectwindow.h"
|
||||
|
||||
#include "buildinfo.h"
|
||||
#include "kit.h"
|
||||
#include "kitmanager.h"
|
||||
#include "kitoptionspage.h"
|
||||
#include "panelswidget.h"
|
||||
#include "project.h"
|
||||
#include "projectexplorer.h"
|
||||
#include "projectimporter.h"
|
||||
#include "projectpanelfactory.h"
|
||||
#include "session.h"
|
||||
#include "target.h"
|
||||
@@ -39,6 +42,8 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/basetreeview.h>
|
||||
#include <utils/navigationtreeview.h>
|
||||
@@ -49,6 +54,7 @@
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDockWidget>
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
@@ -362,8 +368,11 @@ public:
|
||||
m_selectorTree = new SelectorTree;
|
||||
m_selectorTree->setModel(&m_projectsModel);
|
||||
m_selectorTree->setItemDelegate(new SelectorDelegate);
|
||||
m_selectorTree->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(m_selectorTree, &QAbstractItemView::activated,
|
||||
this, &SelectorModel::itemActivated);
|
||||
connect(m_selectorTree, &QWidget::customContextMenuRequested,
|
||||
this, &SelectorModel::openContextMenu);
|
||||
|
||||
m_projectSelection = new QComboBox;
|
||||
m_projectSelection->setModel(&m_comboBoxModel);
|
||||
@@ -377,8 +386,6 @@ public:
|
||||
this, &SelectorModel::deregisterProject);
|
||||
connect(sessionManager, &SessionManager::startupProjectChanged,
|
||||
this, &SelectorModel::startupProjectChanged);
|
||||
connect(m_selectorTree, &QWidget::customContextMenuRequested,
|
||||
this, &SelectorModel::openContextMenu);
|
||||
}
|
||||
|
||||
void updatePanel()
|
||||
@@ -445,17 +452,54 @@ public:
|
||||
|
||||
void openContextMenu(const QPoint &pos)
|
||||
{
|
||||
auto menu = new QMenu;
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QMenu menu;
|
||||
|
||||
ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0);
|
||||
Project *project = projectItem ? projectItem->project() : 0;
|
||||
ProjectImporter *projectImporter = project ? project->projectImporter() : 0;
|
||||
|
||||
QModelIndex index = m_selectorTree->indexAt(pos);
|
||||
if (TreeItem *item = m_projectsModel.itemForIndex(index))
|
||||
item->setData(0, QVariant::fromValue(menu), ContextMenuItemAdderRole);
|
||||
TreeItem *item = m_projectsModel.itemForIndex(index);
|
||||
if (item)
|
||||
item->setData(0, QVariant::fromValue(&menu), ContextMenuItemAdderRole);
|
||||
|
||||
if (menu->actions().isEmpty())
|
||||
delete menu;
|
||||
else
|
||||
menu->popup(m_selectorTree->mapToGlobal(pos));
|
||||
if (!menu.actions().isEmpty())
|
||||
menu.addSeparator();
|
||||
|
||||
QAction *importBuild = menu.addAction(tr("Import Existing Build..."));
|
||||
importBuild->setEnabled(projectImporter != 0);
|
||||
QAction *manageKits = menu.addAction(tr("Manage Kits..."));
|
||||
|
||||
QAction *act = menu.exec(m_selectorTree->mapToGlobal(pos));
|
||||
|
||||
if (act == importBuild) {
|
||||
QString dir = project->projectDirectory().toString();
|
||||
QString importDir = QFileDialog::getExistingDirectory(ICore::mainWindow(),
|
||||
ProjectWindow::tr("Import directory"),
|
||||
dir);
|
||||
FileName path = FileName::fromString(importDir);
|
||||
|
||||
const QList<BuildInfo *> toImport = projectImporter->import(path, false);
|
||||
for (BuildInfo *info : toImport) {
|
||||
Target *target = project->target(info->kitId);
|
||||
if (!target) {
|
||||
target = project->createTarget(KitManager::find(info->kitId));
|
||||
if (target)
|
||||
project->addTarget(target);
|
||||
}
|
||||
if (target) {
|
||||
projectImporter->makePersistent(target->kit());
|
||||
BuildConfiguration *bc = info->factory()->create(target, info);
|
||||
QTC_ASSERT(bc, continue);
|
||||
target->addBuildConfiguration(bc);
|
||||
}
|
||||
}
|
||||
qDeleteAll(toImport);
|
||||
} else if (act == manageKits) {
|
||||
if (KitOptionsPage *page = ExtensionSystem::PluginManager::getObject<KitOptionsPage>())
|
||||
page->showKit(KitManager::find(Id::fromSetting(item->data(0, KitIdRole))));
|
||||
ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, ICore::mainWindow());
|
||||
};
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -473,16 +517,20 @@ public:
|
||||
ProjectWindow::ProjectWindow()
|
||||
{
|
||||
setBackgroundRole(QPalette::Base);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
auto selectorModel = new SelectorModel(this, [this](QWidget *panel) { setPanel(panel); });
|
||||
|
||||
auto styledBar = new StyledBar; // The black blob on top of the side bar
|
||||
styledBar->setObjectName("ProjectModeStyledBar");
|
||||
|
||||
auto selectorView = new QWidget; // Black blob + Project tree + Combobox below.
|
||||
auto selectorView = new QWidget; // Black blob + Combobox + Project tree below.
|
||||
selectorView->setObjectName("ProjectSelector"); // Needed for dock widget state saving
|
||||
selectorView->setWindowTitle(tr("Project Selector"));
|
||||
selectorView->setAutoFillBackground(true);
|
||||
selectorView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(selectorView, &QWidget::customContextMenuRequested,
|
||||
selectorModel, &SelectorModel::openContextMenu);
|
||||
|
||||
auto activeLabel = new QLabel(tr("Active Project"));
|
||||
QFont font = activeLabel->font();
|
||||
@@ -504,6 +552,9 @@ ProjectWindow::ProjectWindow()
|
||||
|
||||
auto selectorDock = addDockForWidget(selectorView, true);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, selectorDock);
|
||||
|
||||
connect(this, &QWidget::customContextMenuRequested,
|
||||
selectorModel, &SelectorModel::openContextMenu);
|
||||
}
|
||||
|
||||
void ProjectWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||
|
@@ -44,6 +44,7 @@ enum {
|
||||
ItemDeactivatedFromBelowRole, // A subitem got deactivated and gives us the opportunity to adjust
|
||||
ItemUpdatedFromBelowRole, // A subitem got updated, re-expansion is necessary.
|
||||
ActiveItemRole, // The index of the currently selected item in the tree view
|
||||
KitIdRole, // The kit id in case the item is associated with a kit.
|
||||
PanelWidgetRole // This item's widget to be shown as central widget.
|
||||
};
|
||||
|
||||
|
@@ -26,18 +26,14 @@
|
||||
#include "targetsettingspanel.h"
|
||||
|
||||
#include "buildconfiguration.h"
|
||||
#include "buildinfo.h"
|
||||
#include "buildmanager.h"
|
||||
#include "buildsettingspropertiespage.h"
|
||||
#include "ipotentialkit.h"
|
||||
#include "kit.h"
|
||||
#include "kitmanager.h"
|
||||
#include "kitoptionspage.h"
|
||||
#include "panelswidget.h"
|
||||
#include "project.h"
|
||||
#include "projectexplorer.h"
|
||||
#include "projectimporter.h"
|
||||
#include "projecttree.h"
|
||||
#include "projectwindow.h"
|
||||
#include "runsettingspropertiespage.h"
|
||||
#include "session.h"
|
||||
@@ -48,8 +44,6 @@
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/treemodel.h>
|
||||
@@ -58,7 +52,6 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QApplication>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
@@ -136,6 +129,7 @@ TargetSetupPageWrapper::TargetSetupPageWrapper(Project *project)
|
||||
m_targetSetupPage->setProjectPath(project->projectFilePath().toString());
|
||||
m_targetSetupPage->setRequiredKitMatcher(project->requiredKitMatcher());
|
||||
m_targetSetupPage->setPreferredKitMatcher(project->preferredKitMatcher());
|
||||
m_targetSetupPage->setProjectImporter(project->projectImporter());
|
||||
m_targetSetupPage->initializePage();
|
||||
m_targetSetupPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
updateNoteText();
|
||||
@@ -218,7 +212,6 @@ public:
|
||||
void handleTargetRemoved(Target *target);
|
||||
void handleTargetChanged(Target *target);
|
||||
|
||||
void importTarget(const Utils::FileName &path);
|
||||
void ensureWidget();
|
||||
void rebuildContents();
|
||||
|
||||
@@ -278,34 +271,6 @@ void TargetGroupItemPrivate::ensureWidget()
|
||||
}
|
||||
}
|
||||
|
||||
void TargetGroupItemPrivate::importTarget(const Utils::FileName &path)
|
||||
{
|
||||
ProjectImporter *importer = m_project->projectImporter();
|
||||
if (!importer)
|
||||
return;
|
||||
|
||||
Target *target = nullptr;
|
||||
BuildConfiguration *bc = nullptr;
|
||||
QList<BuildInfo *> toImport = importer->import(path, false);
|
||||
foreach (BuildInfo *info, toImport) {
|
||||
target = m_project->target(info->kitId);
|
||||
if (!target) {
|
||||
target = m_project->createTarget(KitManager::find(info->kitId));
|
||||
m_project->addTarget(target);
|
||||
}
|
||||
bc = info->factory()->create(target, info);
|
||||
QTC_ASSERT(bc, continue);
|
||||
target->addBuildConfiguration(bc);
|
||||
}
|
||||
|
||||
SessionManager::setActiveTarget(m_project, target, SetActive::Cascade);
|
||||
|
||||
if (target && bc)
|
||||
SessionManager::setActiveBuildConfiguration(target, bc, SetActive::Cascade);
|
||||
|
||||
qDeleteAll(toImport);
|
||||
}
|
||||
|
||||
//
|
||||
// Third level: The per-kit entries (inactive or with a 'Build' and a 'Run' subitem)
|
||||
//
|
||||
@@ -498,16 +463,6 @@ public:
|
||||
} else {
|
||||
copyMenu->setEnabled(false);
|
||||
}
|
||||
|
||||
menu->addSeparator();
|
||||
|
||||
QAction *manageKits = menu->addAction(tr("Manage Kits"));
|
||||
QObject::connect(manageKits, &QAction::triggered, menu, [this] {
|
||||
KitOptionsPage *page = ExtensionSystem::PluginManager::getObject<KitOptionsPage>();
|
||||
if (page)
|
||||
page->showKit(KitManager::find(m_kitId));
|
||||
ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, ICore::mainWindow());
|
||||
});
|
||||
}
|
||||
|
||||
bool isEnabled() const { return target() != 0; }
|
||||
@@ -605,6 +560,9 @@ public:
|
||||
case ActiveItemRole:
|
||||
return QVariant::fromValue<TreeItem *>(const_cast<BuildOrRunItem *>(this));
|
||||
|
||||
case KitIdRole:
|
||||
return m_kitId.toSetting();
|
||||
|
||||
case Qt::DecorationRole:
|
||||
return Utils::Icons::EMPTY14.icon();
|
||||
|
||||
@@ -742,15 +700,6 @@ TargetGroupItem::~TargetGroupItem()
|
||||
TargetGroupItemPrivate::TargetGroupItemPrivate(TargetGroupItem *q, Project *project)
|
||||
: q(q), m_project(project)
|
||||
{
|
||||
if (project->projectImporter()) {
|
||||
auto importAction = new QAction(tr("Import existing build..."), 0);
|
||||
QObject::connect(importAction, &QAction::triggered, [this] {
|
||||
QString dir = m_project->projectDirectory().toString();
|
||||
QString toImport = QFileDialog::getExistingDirectory(ICore::mainWindow(), tr("Import directory"), dir);
|
||||
importTarget(FileName::fromString(toImport));
|
||||
});
|
||||
}
|
||||
|
||||
// force a signal since the index has changed
|
||||
connect(KitManager::instance(), &KitManager::kitAdded,
|
||||
this, &TargetGroupItemPrivate::handleAddedKit);
|
||||
|
@@ -305,10 +305,8 @@ void TargetSetupPage::setProjectImporter(ProjectImporter *importer)
|
||||
{
|
||||
if (importer == m_importer)
|
||||
return;
|
||||
if (m_importer)
|
||||
delete m_importer;
|
||||
m_importer = importer;
|
||||
|
||||
m_importer = importer;
|
||||
m_importWidget->setVisible(m_importer);
|
||||
|
||||
reset();
|
||||
|
Reference in New Issue
Block a user