2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectwindow.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-10-13 08:16:32 +02:00
|
|
|
#include "buildinfo.h"
|
2016-07-22 15:53:01 +02:00
|
|
|
#include "kit.h"
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "kitmanager.h"
|
2016-10-13 08:16:32 +02:00
|
|
|
#include "kitoptionspage.h"
|
2016-07-22 15:53:01 +02:00
|
|
|
#include "panelswidget.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
#include "project.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorer.h"
|
2022-04-14 15:51:18 +02:00
|
|
|
#include "projectexplorerconstants.h"
|
2016-10-13 08:16:32 +02:00
|
|
|
#include "projectimporter.h"
|
2014-07-28 14:35:53 +02:00
|
|
|
#include "projectpanelfactory.h"
|
2022-04-14 15:51:18 +02:00
|
|
|
#include "projectsettingswidget.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "session.h"
|
2010-12-10 19:02:19 +01:00
|
|
|
#include "target.h"
|
2016-07-22 15:53:01 +02:00
|
|
|
#include "targetsettingspanel.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2019-11-13 12:53:26 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2021-06-18 16:27:13 +02:00
|
|
|
#include <coreplugin/actionmanager/commandbutton.h>
|
2019-11-13 12:53:26 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <coreplugin/coreicons.h>
|
2021-06-21 11:02:06 +02:00
|
|
|
#include <coreplugin/find/optionspopup.h>
|
2021-09-14 16:42:05 +02:00
|
|
|
#include <coreplugin/findplaceholder.h>
|
2021-06-01 16:21:03 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2021-06-01 16:21:03 +02:00
|
|
|
#include <coreplugin/outputwindow.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/basetreeview.h>
|
2020-06-26 11:59:14 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <utils/navigationtreeview.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
#include <utils/treemodel.h>
|
2021-06-18 16:27:13 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2016-07-22 15:53:01 +02:00
|
|
|
|
2021-06-21 11:30:51 +02:00
|
|
|
#include <texteditor/fontsettings.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDockWidget>
|
2016-10-13 08:16:32 +02:00
|
|
|
#include <QFileDialog>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <QHeaderView>
|
2016-10-13 12:09:54 +02:00
|
|
|
#include <QLabel>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <QMenu>
|
2016-12-05 16:39:38 +01:00
|
|
|
#include <QPushButton>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <QStyledItemDelegate>
|
2016-09-14 12:55:04 +02:00
|
|
|
#include <QTimer>
|
2016-07-22 15:53:01 +02:00
|
|
|
#include <QTreeView>
|
2014-07-11 16:54:04 +02:00
|
|
|
#include <QVBoxLayout>
|
2009-09-29 18:06:13 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
class MiscSettingsGroupItem;
|
|
|
|
|
|
2021-06-18 16:27:13 +02:00
|
|
|
const char kBuildSystemOutputContext[] = "ProjectsMode.BuildSystemOutput";
|
2021-06-21 11:02:06 +02:00
|
|
|
const char kRegExpActionId[] = "OutputFilter.RegularExpressions.BuildSystemOutput";
|
|
|
|
|
const char kCaseSensitiveActionId[] = "OutputFilter.CaseSensitive.BuildSystemOutput";
|
|
|
|
|
const char kInvertActionId[] = "OutputFilter.Invert.BuildSystemOutput";
|
2021-06-18 16:27:13 +02:00
|
|
|
|
|
|
|
|
class BuildSystemOutputWindow : public OutputWindow
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BuildSystemOutputWindow();
|
|
|
|
|
|
|
|
|
|
QWidget *toolBar();
|
|
|
|
|
|
|
|
|
|
private:
|
2021-06-21 11:02:06 +02:00
|
|
|
void updateFilter();
|
|
|
|
|
|
2021-06-18 16:27:13 +02:00
|
|
|
QPointer<QWidget> m_toolBar;
|
2021-06-21 11:02:06 +02:00
|
|
|
QPointer<FancyLineEdit> m_filterOutputLineEdit;
|
2022-06-27 13:35:32 +02:00
|
|
|
QAction m_clear;
|
|
|
|
|
QAction m_filterActionRegexp;
|
|
|
|
|
QAction m_filterActionCaseSensitive;
|
|
|
|
|
QAction m_invertFilterAction;
|
|
|
|
|
QAction m_zoomIn;
|
|
|
|
|
QAction m_zoomOut;
|
2021-06-18 16:27:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BuildSystemOutputWindow::BuildSystemOutputWindow()
|
|
|
|
|
: OutputWindow(Context(kBuildSystemOutputContext), "ProjectsMode.BuildSystemOutput.Zoom")
|
|
|
|
|
{
|
2021-09-14 16:42:05 +02:00
|
|
|
setReadOnly(true);
|
|
|
|
|
|
2021-06-18 16:27:13 +02:00
|
|
|
Command *clearCommand = ActionManager::command(Core::Constants::OUTPUTPANE_CLEAR);
|
2022-06-27 13:35:32 +02:00
|
|
|
m_clear.setIcon(Utils::Icons::CLEAN_TOOLBAR.icon());
|
|
|
|
|
m_clear.setText(clearCommand->action()->text());
|
|
|
|
|
ActionManager::registerAction(&m_clear,
|
2021-06-18 16:27:13 +02:00
|
|
|
Core::Constants::OUTPUTPANE_CLEAR,
|
|
|
|
|
Context(kBuildSystemOutputContext));
|
2022-06-27 13:35:32 +02:00
|
|
|
connect(&m_clear, &QAction::triggered, this, &OutputWindow::clear);
|
2021-06-21 11:02:06 +02:00
|
|
|
|
2022-06-27 13:35:32 +02:00
|
|
|
m_filterActionRegexp.setCheckable(true);
|
|
|
|
|
m_filterActionRegexp.setText(ProjectWindow::tr("Use Regular Expressions"));
|
|
|
|
|
connect(&m_filterActionRegexp, &QAction::toggled, this, &BuildSystemOutputWindow::updateFilter);
|
|
|
|
|
Core::ActionManager::registerAction(&m_filterActionRegexp,
|
2021-06-21 11:02:06 +02:00
|
|
|
kRegExpActionId,
|
|
|
|
|
Context(Constants::C_PROJECTEXPLORER));
|
|
|
|
|
|
2022-06-27 13:35:32 +02:00
|
|
|
m_filterActionCaseSensitive.setCheckable(true);
|
|
|
|
|
m_filterActionCaseSensitive.setText(ProjectWindow::tr("Case Sensitive"));
|
|
|
|
|
connect(&m_filterActionCaseSensitive,
|
2021-06-21 11:02:06 +02:00
|
|
|
&QAction::toggled,
|
|
|
|
|
this,
|
|
|
|
|
&BuildSystemOutputWindow::updateFilter);
|
2022-06-27 13:35:32 +02:00
|
|
|
Core::ActionManager::registerAction(&m_filterActionCaseSensitive,
|
2021-06-21 11:02:06 +02:00
|
|
|
kCaseSensitiveActionId,
|
|
|
|
|
Context(Constants::C_PROJECTEXPLORER));
|
|
|
|
|
|
2022-06-27 13:35:32 +02:00
|
|
|
m_invertFilterAction.setCheckable(true);
|
|
|
|
|
m_invertFilterAction.setText(ProjectWindow::tr("Show Non-matching Lines"));
|
|
|
|
|
connect(&m_invertFilterAction, &QAction::toggled, this, &BuildSystemOutputWindow::updateFilter);
|
|
|
|
|
Core::ActionManager::registerAction(&m_invertFilterAction,
|
2021-06-21 11:02:06 +02:00
|
|
|
kInvertActionId,
|
|
|
|
|
Context(Constants::C_PROJECTEXPLORER));
|
2021-06-21 11:30:51 +02:00
|
|
|
|
|
|
|
|
connect(TextEditor::TextEditorSettings::instance(),
|
|
|
|
|
&TextEditor::TextEditorSettings::fontSettingsChanged,
|
|
|
|
|
this,
|
|
|
|
|
[this] { setBaseFont(TextEditor::TextEditorSettings::fontSettings().font()); });
|
|
|
|
|
setBaseFont(TextEditor::TextEditorSettings::fontSettings().font());
|
|
|
|
|
|
2022-06-27 13:35:32 +02:00
|
|
|
m_zoomIn.setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
|
|
|
|
|
connect(&m_zoomIn, &QAction::triggered, this, [this] { zoomIn(); });
|
|
|
|
|
ActionManager::registerAction(&m_zoomIn,
|
2021-06-21 11:30:51 +02:00
|
|
|
Core::Constants::ZOOM_IN,
|
|
|
|
|
Context(kBuildSystemOutputContext));
|
|
|
|
|
|
2022-08-11 16:30:37 +02:00
|
|
|
m_zoomOut.setIcon(Utils::Icons::MINUS_TOOLBAR.icon());
|
2022-06-27 13:35:32 +02:00
|
|
|
connect(&m_zoomOut, &QAction::triggered, this, [this] { zoomOut(); });
|
|
|
|
|
ActionManager::registerAction(&m_zoomOut,
|
2021-06-21 11:30:51 +02:00
|
|
|
Core::Constants::ZOOM_OUT,
|
|
|
|
|
Context(kBuildSystemOutputContext));
|
2021-06-18 16:27:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *BuildSystemOutputWindow::toolBar()
|
|
|
|
|
{
|
|
|
|
|
if (!m_toolBar) {
|
|
|
|
|
m_toolBar = new StyledBar(this);
|
|
|
|
|
auto clearButton = new CommandButton(Core::Constants::OUTPUTPANE_CLEAR);
|
2022-06-27 13:35:32 +02:00
|
|
|
clearButton->setDefaultAction(&m_clear);
|
|
|
|
|
clearButton->setToolTipBase(m_clear.text());
|
2021-06-21 11:02:06 +02:00
|
|
|
|
|
|
|
|
m_filterOutputLineEdit = new FancyLineEdit;
|
|
|
|
|
m_filterOutputLineEdit->setButtonVisible(FancyLineEdit::Left, true);
|
|
|
|
|
m_filterOutputLineEdit->setButtonIcon(FancyLineEdit::Left, Utils::Icons::MAGNIFIER.icon());
|
|
|
|
|
m_filterOutputLineEdit->setFiltering(true);
|
|
|
|
|
m_filterOutputLineEdit->setHistoryCompleter("ProjectsMode.BuildSystemOutput.Filter");
|
|
|
|
|
connect(m_filterOutputLineEdit,
|
|
|
|
|
&FancyLineEdit::textChanged,
|
|
|
|
|
this,
|
|
|
|
|
&BuildSystemOutputWindow::updateFilter);
|
|
|
|
|
connect(m_filterOutputLineEdit,
|
|
|
|
|
&FancyLineEdit::returnPressed,
|
|
|
|
|
this,
|
|
|
|
|
&BuildSystemOutputWindow::updateFilter);
|
|
|
|
|
connect(m_filterOutputLineEdit, &FancyLineEdit::leftButtonClicked, this, [this] {
|
|
|
|
|
auto popup = new Core::OptionsPopup(m_filterOutputLineEdit,
|
|
|
|
|
{kRegExpActionId,
|
|
|
|
|
kCaseSensitiveActionId,
|
|
|
|
|
kInvertActionId});
|
|
|
|
|
popup->show();
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-21 11:30:51 +02:00
|
|
|
auto zoomInButton = new CommandButton(Core::Constants::ZOOM_IN);
|
2022-06-27 13:35:32 +02:00
|
|
|
zoomInButton->setDefaultAction(&m_zoomIn);
|
2021-06-21 11:30:51 +02:00
|
|
|
auto zoomOutButton = new CommandButton(Core::Constants::ZOOM_OUT);
|
2022-06-27 13:35:32 +02:00
|
|
|
zoomOutButton->setDefaultAction(&m_zoomOut);
|
2021-06-21 11:30:51 +02:00
|
|
|
|
2021-06-18 16:27:13 +02:00
|
|
|
auto layout = new QHBoxLayout;
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
m_toolBar->setLayout(layout);
|
|
|
|
|
layout->addWidget(clearButton);
|
2021-06-21 11:02:06 +02:00
|
|
|
layout->addWidget(m_filterOutputLineEdit);
|
2021-06-21 11:30:51 +02:00
|
|
|
layout->addWidget(zoomInButton);
|
|
|
|
|
layout->addWidget(zoomOutButton);
|
2021-06-18 16:27:13 +02:00
|
|
|
layout->addStretch();
|
|
|
|
|
}
|
|
|
|
|
return m_toolBar;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 11:02:06 +02:00
|
|
|
void BuildSystemOutputWindow::updateFilter()
|
|
|
|
|
{
|
|
|
|
|
if (!m_filterOutputLineEdit)
|
|
|
|
|
return;
|
|
|
|
|
updateFilterProperties(m_filterOutputLineEdit->text(),
|
2022-06-27 13:35:32 +02:00
|
|
|
m_filterActionCaseSensitive.isChecked() ? Qt::CaseSensitive
|
2021-06-21 11:02:06 +02:00
|
|
|
: Qt::CaseInsensitive,
|
2022-06-27 13:35:32 +02:00
|
|
|
m_filterActionRegexp.isChecked(),
|
|
|
|
|
m_invertFilterAction.isChecked());
|
2021-06-21 11:02:06 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
// Standard third level for the generic case: i.e. all except for the Build/Run page
|
|
|
|
|
class MiscSettingsPanelItem : public TreeItem // TypedTreeItem<TreeItem, MiscSettingsGroupItem>
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
2016-09-14 12:55:04 +02:00
|
|
|
MiscSettingsPanelItem(ProjectPanelFactory *factory, Project *project)
|
|
|
|
|
: m_factory(factory), m_project(project)
|
|
|
|
|
{}
|
|
|
|
|
|
2018-07-12 22:17:17 +02:00
|
|
|
~MiscSettingsPanelItem() override { delete m_widget; }
|
2016-09-14 12:55:04 +02:00
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const override;
|
|
|
|
|
Qt::ItemFlags flags(int column) const override;
|
|
|
|
|
bool setData(int column, const QVariant &, int role) override;
|
|
|
|
|
|
2019-11-25 10:09:21 +01:00
|
|
|
ProjectPanelFactory *factory() const { return m_factory; }
|
|
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
protected:
|
|
|
|
|
ProjectPanelFactory *m_factory = nullptr;
|
|
|
|
|
QPointer<Project> m_project;
|
|
|
|
|
|
|
|
|
|
mutable QPointer<QWidget> m_widget = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVariant MiscSettingsPanelItem::data(int column, int role) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
if (m_factory)
|
|
|
|
|
return m_factory->displayName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == PanelWidgetRole) {
|
|
|
|
|
if (!m_widget) {
|
2022-04-14 15:51:18 +02:00
|
|
|
ProjectSettingsWidget *widget = m_factory->createWidget(m_project);
|
2021-12-01 18:54:56 +01:00
|
|
|
m_widget = new PanelsWidget(m_factory->displayName(), widget);
|
2016-12-15 09:10:58 +01:00
|
|
|
m_widget->setFocusProxy(widget);
|
2016-09-14 12:55:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant::fromValue<QWidget *>(m_widget.data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == ActiveItemRole) // We are the active one.
|
|
|
|
|
return QVariant::fromValue<TreeItem *>(const_cast<MiscSettingsPanelItem *>(this));
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags MiscSettingsPanelItem::flags(int column) const
|
|
|
|
|
{
|
|
|
|
|
if (m_factory && m_project) {
|
|
|
|
|
if (!m_factory->supports(m_project))
|
|
|
|
|
return Qt::ItemIsSelectable;
|
|
|
|
|
}
|
|
|
|
|
return TreeItem::flags(column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MiscSettingsPanelItem::setData(int column, const QVariant &, int role)
|
|
|
|
|
{
|
|
|
|
|
if (role == ItemActivatedDirectlyRole) {
|
|
|
|
|
// Bubble up
|
|
|
|
|
return parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)),
|
|
|
|
|
ItemActivatedFromBelowRole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The lower part of the second tree level, i.e. the project settings list.
|
|
|
|
|
// The upper part is the TargetSettingsPanelItem .
|
|
|
|
|
class MiscSettingsGroupItem : public TreeItem // TypedTreeItem<MiscSettingsPanelItem, ProjectItem>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit MiscSettingsGroupItem(Project *project)
|
|
|
|
|
: m_project(project)
|
2016-07-22 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_project, return);
|
2022-05-03 16:48:36 +02:00
|
|
|
const QList<ProjectPanelFactory *> factories = ProjectPanelFactory::factories();
|
|
|
|
|
for (ProjectPanelFactory *factory : factories)
|
2016-09-14 12:55:04 +02:00
|
|
|
appendChild(new MiscSettingsPanelItem(factory, project));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(int) const override
|
|
|
|
|
{
|
2016-10-07 16:21:17 +02:00
|
|
|
return Qt::NoItemFlags;
|
2016-09-14 12:55:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const override
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
return ProjectWindow::tr("Project Settings");
|
|
|
|
|
|
|
|
|
|
case PanelWidgetRole:
|
|
|
|
|
case ActiveItemRole:
|
|
|
|
|
if (0 <= m_currentPanelIndex && m_currentPanelIndex < childCount())
|
|
|
|
|
return childAt(m_currentPanelIndex)->data(column, role);
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool setData(int column, const QVariant &data, int role) override
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
|
|
|
|
|
|
|
|
|
if (role == ItemActivatedFromBelowRole) {
|
2018-07-12 22:17:17 +02:00
|
|
|
auto *item = data.value<TreeItem *>();
|
2016-09-14 12:55:04 +02:00
|
|
|
QTC_ASSERT(item, return false);
|
2017-02-07 08:53:00 +01:00
|
|
|
m_currentPanelIndex = indexOf(item);
|
2016-09-14 12:55:04 +02:00
|
|
|
QTC_ASSERT(m_currentPanelIndex != -1, return false);
|
|
|
|
|
parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(this)),
|
|
|
|
|
ItemActivatedFromBelowRole);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Project *project() const { return m_project; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_currentPanelIndex = -1;
|
|
|
|
|
|
|
|
|
|
Project * const m_project;
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
// The first tree level, i.e. projects.
|
|
|
|
|
class ProjectItem : public TreeItem
|
2016-09-14 12:55:04 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-07-12 22:17:17 +02:00
|
|
|
ProjectItem() = default;
|
2016-09-28 17:31:33 +02:00
|
|
|
|
|
|
|
|
ProjectItem(Project *project, const std::function<void()> &changeListener)
|
|
|
|
|
: m_project(project), m_changeListener(changeListener)
|
2016-09-14 12:55:04 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_project, return);
|
|
|
|
|
QString display = ProjectWindow::tr("Build & Run");
|
|
|
|
|
appendChild(m_targetsItem = new TargetGroupItem(display, project));
|
|
|
|
|
appendChild(m_miscItem = new MiscSettingsGroupItem(project));
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
QVariant data(int column, int role) const override
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case ProjectDisplayNameRole:
|
|
|
|
|
return m_project->displayName();
|
|
|
|
|
|
|
|
|
|
case Qt::FontRole: {
|
|
|
|
|
QFont font;
|
|
|
|
|
font.setBold(m_project == SessionManager::startupProject());
|
|
|
|
|
return font;
|
|
|
|
|
}
|
2009-11-25 16:01:46 +01:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
case PanelWidgetRole:
|
|
|
|
|
case ActiveItemRole:
|
|
|
|
|
if (m_currentChildIndex == 0)
|
|
|
|
|
return m_targetsItem->data(column, role);
|
|
|
|
|
if (m_currentChildIndex == 1)
|
|
|
|
|
return m_miscItem->data(column, role);
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
bool setData(int column, const QVariant &dat, int role) override
|
2016-07-22 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
2009-11-25 15:18:51 +01:00
|
|
|
|
2016-10-13 11:25:31 +02:00
|
|
|
if (role == ItemUpdatedFromBelowRole) {
|
|
|
|
|
announceChange();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
if (role == ItemDeactivatedFromBelowRole) {
|
2016-09-28 17:31:33 +02:00
|
|
|
announceChange();
|
2016-09-14 12:55:04 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == ItemActivatedFromBelowRole) {
|
2017-02-07 08:53:00 +01:00
|
|
|
const TreeItem *item = dat.value<TreeItem *>();
|
2016-09-14 12:55:04 +02:00
|
|
|
QTC_ASSERT(item, return false);
|
2017-02-07 08:53:00 +01:00
|
|
|
int res = indexOf(item);
|
2016-09-14 12:55:04 +02:00
|
|
|
QTC_ASSERT(res >= 0, return false);
|
|
|
|
|
m_currentChildIndex = res;
|
2016-09-28 17:31:33 +02:00
|
|
|
announceChange();
|
2016-09-14 12:55:04 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-03-24 18:36:06 +01:00
|
|
|
|
2016-09-14 12:55:04 +02:00
|
|
|
if (role == ItemActivatedDirectlyRole) {
|
|
|
|
|
// Someone selected the project using the combobox or similar.
|
2016-07-22 15:53:01 +02:00
|
|
|
SessionManager::setStartupProject(m_project);
|
2016-09-14 12:55:04 +02:00
|
|
|
m_currentChildIndex = 0; // Use some Target page by defaults
|
2016-09-28 17:31:33 +02:00
|
|
|
m_targetsItem->setData(column, dat, ItemActivatedFromAboveRole); // And propagate downwards.
|
|
|
|
|
announceChange();
|
2016-07-22 15:53:01 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-07 15:46:07 +02:00
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
void announceChange()
|
2016-07-22 15:53:01 +02:00
|
|
|
{
|
2016-09-28 17:31:33 +02:00
|
|
|
m_changeListener();
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
2014-07-14 17:39:46 +02:00
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
Project *project() const { return m_project; }
|
2016-09-14 12:55:04 +02:00
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
QModelIndex activeIndex() const
|
2016-09-14 12:55:04 +02:00
|
|
|
{
|
2018-07-12 22:17:17 +02:00
|
|
|
auto *activeItem = data(0, ActiveItemRole).value<TreeItem *>();
|
2016-09-28 17:31:33 +02:00
|
|
|
return activeItem ? activeItem->index() : QModelIndex();
|
2016-09-14 12:55:04 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
TreeItem *itemForProjectPanel(Utils::Id panelId)
|
2019-11-25 10:09:21 +01:00
|
|
|
{
|
|
|
|
|
return m_miscItem->findChildAtLevel(1, [panelId](const TreeItem *item){
|
|
|
|
|
return static_cast<const MiscSettingsPanelItem *>(item)->factory()->id() == panelId;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
private:
|
|
|
|
|
int m_currentChildIndex = 0; // Start with Build & Run.
|
|
|
|
|
Project *m_project = nullptr;
|
|
|
|
|
TargetGroupItem *m_targetsItem = nullptr;
|
|
|
|
|
MiscSettingsGroupItem *m_miscItem = nullptr;
|
|
|
|
|
const std::function<void ()> m_changeListener;
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2009-10-07 15:46:07 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
class SelectorDelegate : public QStyledItemDelegate
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
2018-07-12 22:17:17 +02:00
|
|
|
SelectorDelegate() = default;
|
2016-07-22 15:53:01 +02:00
|
|
|
|
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option,
|
2016-09-28 17:31:33 +02:00
|
|
|
const QModelIndex &index) const final;
|
2010-02-22 15:47:47 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
void paint(QPainter *painter,
|
2016-09-28 17:31:33 +02:00
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &index) const final;
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
2010-03-25 16:16:38 +01:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
//
|
|
|
|
|
// SelectorTree
|
|
|
|
|
//
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2016-09-16 13:27:22 +02:00
|
|
|
class SelectorTree : public BaseTreeView
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
public:
|
|
|
|
|
SelectorTree()
|
|
|
|
|
{
|
|
|
|
|
setWindowTitle("Project Kit Selector");
|
|
|
|
|
|
|
|
|
|
header()->hide();
|
|
|
|
|
setExpandsOnDoubleClick(false);
|
|
|
|
|
setHeaderHidden(true);
|
|
|
|
|
setItemsExpandable(false); // No user interaction.
|
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
|
setUniformRowHeights(false); // sic!
|
|
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
setActivationMode(SingleClickActivation);
|
|
|
|
|
setObjectName("ProjectNavigation");
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
2016-09-20 15:59:48 +02:00
|
|
|
|
2020-06-26 11:59:14 +02:00
|
|
|
private:
|
2016-09-20 15:59:48 +02:00
|
|
|
// remove branch indicators
|
2016-09-28 17:31:33 +02:00
|
|
|
void drawBranches(QPainter *, const QRect &, const QModelIndex &) const final
|
2016-09-20 15:59:48 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-26 11:59:14 +02:00
|
|
|
|
|
|
|
|
bool userWantsContextMenu(const QMouseEvent *e) const
|
|
|
|
|
{
|
|
|
|
|
// On Windows, we get additional mouse events for the item view when right-clicking,
|
|
|
|
|
// causing unwanted kit activation (QTCREATORBUG-24156). Let's suppress these.
|
|
|
|
|
return HostOsInfo::isWindowsHost() && e->button() == Qt::RightButton;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 15:26:38 +01:00
|
|
|
void mousePressEvent(QMouseEvent *e) final
|
2020-06-26 11:59:14 +02:00
|
|
|
{
|
|
|
|
|
if (!userWantsContextMenu(e))
|
|
|
|
|
BaseTreeView::mousePressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 15:26:38 +01:00
|
|
|
void mouseReleaseEvent(QMouseEvent *e) final
|
2020-06-26 11:59:14 +02:00
|
|
|
{
|
|
|
|
|
if (!userWantsContextMenu(e))
|
|
|
|
|
BaseTreeView::mouseReleaseEvent(e);
|
|
|
|
|
}
|
2016-07-22 15:53:01 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
class ComboBoxItem : public TreeItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ComboBoxItem(ProjectItem *item) : m_projectItem(item) {}
|
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const final
|
|
|
|
|
{
|
2016-11-03 15:27:30 +01:00
|
|
|
return m_projectItem ? m_projectItem->data(column, role) : QVariant();
|
2016-09-28 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectItem *m_projectItem;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using ProjectsModel = TreeModel<TypedTreeItem<ProjectItem>, ProjectItem>;
|
|
|
|
|
using ComboBoxModel = TreeModel<TypedTreeItem<ComboBoxItem>, ComboBoxItem>;
|
|
|
|
|
|
2016-12-05 18:11:48 +01:00
|
|
|
//
|
|
|
|
|
// ProjectWindowPrivate
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
class ProjectWindowPrivate : public QObject
|
2016-09-28 17:31:33 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2016-12-05 18:11:48 +01:00
|
|
|
ProjectWindowPrivate(ProjectWindow *parent)
|
|
|
|
|
: q(parent)
|
2016-09-28 17:31:33 +02:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
m_projectsModel.setHeader({ProjectWindow::tr("Projects")});
|
2016-09-28 17:31:33 +02:00
|
|
|
|
|
|
|
|
m_selectorTree = new SelectorTree;
|
|
|
|
|
m_selectorTree->setModel(&m_projectsModel);
|
2018-02-16 14:52:05 +01:00
|
|
|
m_selectorTree->setItemDelegate(&m_selectorDelegate);
|
2016-10-13 08:16:32 +02:00
|
|
|
m_selectorTree->setContextMenuPolicy(Qt::CustomContextMenu);
|
2016-09-28 17:31:33 +02:00
|
|
|
connect(m_selectorTree, &QAbstractItemView::activated,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::itemActivated);
|
2016-10-13 08:16:32 +02:00
|
|
|
connect(m_selectorTree, &QWidget::customContextMenuRequested,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::openContextMenu);
|
2016-09-28 17:31:33 +02:00
|
|
|
|
|
|
|
|
m_projectSelection = new QComboBox;
|
|
|
|
|
m_projectSelection->setModel(&m_comboBoxModel);
|
2022-07-19 22:42:48 +02:00
|
|
|
connect(m_projectSelection, &QComboBox::activated,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::projectSelected, Qt::QueuedConnection);
|
2016-09-28 17:31:33 +02:00
|
|
|
|
2019-11-13 12:53:26 +01:00
|
|
|
const auto switchProjectAction = new QAction(this);
|
|
|
|
|
ActionManager::registerAction(switchProjectAction, Core::Constants::GOTOPREVINHISTORY,
|
|
|
|
|
Context(Constants::C_PROJECTEXPLORER));
|
|
|
|
|
connect(switchProjectAction, &QAction::triggered, this, [this] {
|
|
|
|
|
if (m_projectSelection->count() > 1)
|
|
|
|
|
m_projectSelection->showPopup();
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
SessionManager *sessionManager = SessionManager::instance();
|
|
|
|
|
connect(sessionManager, &SessionManager::projectAdded,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::registerProject);
|
2016-09-28 17:31:33 +02:00
|
|
|
connect(sessionManager, &SessionManager::aboutToRemoveProject,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::deregisterProject);
|
2016-09-28 17:31:33 +02:00
|
|
|
connect(sessionManager, &SessionManager::startupProjectChanged,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::startupProjectChanged);
|
2016-12-05 16:39:38 +01:00
|
|
|
|
|
|
|
|
m_importBuild = new QPushButton(ProjectWindow::tr("Import Existing Build..."));
|
|
|
|
|
connect(m_importBuild, &QPushButton::clicked,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::handleImportBuild);
|
2016-12-08 14:38:44 +01:00
|
|
|
connect(sessionManager, &SessionManager::startupProjectChanged, this, [this](Project *project) {
|
|
|
|
|
m_importBuild->setEnabled(project && project->projectImporter());
|
|
|
|
|
});
|
2016-12-05 16:39:38 +01:00
|
|
|
|
|
|
|
|
m_manageKits = new QPushButton(ProjectWindow::tr("Manage Kits..."));
|
|
|
|
|
connect(m_manageKits, &QPushButton::clicked,
|
2016-12-05 18:11:48 +01:00
|
|
|
this, &ProjectWindowPrivate::handleManageKits);
|
|
|
|
|
|
|
|
|
|
auto styledBar = new StyledBar; // The black blob on top of the side bar
|
|
|
|
|
styledBar->setObjectName("ProjectModeStyledBar");
|
|
|
|
|
|
|
|
|
|
auto selectorView = new QWidget; // Black blob + Combobox + Project tree below.
|
|
|
|
|
selectorView->setObjectName("ProjectSelector"); // Needed for dock widget state saving
|
|
|
|
|
selectorView->setWindowTitle(ProjectWindow::tr("Project Selector"));
|
|
|
|
|
selectorView->setAutoFillBackground(true);
|
|
|
|
|
selectorView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
connect(selectorView, &QWidget::customContextMenuRequested,
|
|
|
|
|
this, &ProjectWindowPrivate::openContextMenu);
|
|
|
|
|
|
|
|
|
|
auto activeLabel = new QLabel(ProjectWindow::tr("Active Project"));
|
|
|
|
|
QFont font = activeLabel->font();
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
font.setPointSizeF(font.pointSizeF() * 1.2);
|
|
|
|
|
activeLabel->setFont(font);
|
|
|
|
|
|
|
|
|
|
auto innerLayout = new QVBoxLayout;
|
|
|
|
|
innerLayout->setSpacing(10);
|
2021-12-01 18:54:56 +01:00
|
|
|
innerLayout->setContentsMargins(PanelsWidget::PanelVMargin, innerLayout->spacing(),
|
|
|
|
|
PanelsWidget::PanelVMargin, 0);
|
2016-12-05 18:11:48 +01:00
|
|
|
innerLayout->addWidget(m_manageKits);
|
|
|
|
|
innerLayout->addSpacerItem(new QSpacerItem(10, 30, QSizePolicy::Maximum, QSizePolicy::Maximum));
|
|
|
|
|
innerLayout->addWidget(activeLabel);
|
|
|
|
|
innerLayout->addWidget(m_projectSelection);
|
2018-03-14 14:45:29 +09:00
|
|
|
innerLayout->addWidget(m_importBuild);
|
2016-12-05 18:11:48 +01:00
|
|
|
innerLayout->addWidget(m_selectorTree);
|
|
|
|
|
|
|
|
|
|
auto selectorLayout = new QVBoxLayout(selectorView);
|
|
|
|
|
selectorLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
selectorLayout->addWidget(styledBar);
|
|
|
|
|
selectorLayout->addLayout(innerLayout);
|
|
|
|
|
|
|
|
|
|
auto selectorDock = q->addDockForWidget(selectorView, true);
|
|
|
|
|
q->addDockWidget(Qt::LeftDockWidgetArea, selectorDock);
|
2021-06-01 16:21:03 +02:00
|
|
|
|
2021-06-18 16:27:13 +02:00
|
|
|
m_buildSystemOutput = new BuildSystemOutputWindow;
|
2021-06-01 16:21:03 +02:00
|
|
|
auto output = new QWidget;
|
2021-09-14 16:42:05 +02:00
|
|
|
// ProjectWindow sets background role to Base which is wrong for the output window,
|
|
|
|
|
// especially the find tool bar (resulting in wrong label color)
|
|
|
|
|
output->setBackgroundRole(QPalette::Window);
|
2021-06-01 16:21:03 +02:00
|
|
|
output->setObjectName("BuildSystemOutput");
|
|
|
|
|
output->setWindowTitle(ProjectWindow::tr("Build System Output"));
|
|
|
|
|
auto outputLayout = new QVBoxLayout;
|
|
|
|
|
output->setLayout(outputLayout);
|
|
|
|
|
outputLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
outputLayout->setSpacing(0);
|
2021-06-18 16:27:13 +02:00
|
|
|
outputLayout->addWidget(m_buildSystemOutput->toolBar());
|
2021-06-01 16:21:03 +02:00
|
|
|
outputLayout->addWidget(m_buildSystemOutput);
|
2021-09-14 16:42:05 +02:00
|
|
|
outputLayout->addWidget(new FindToolBarPlaceHolder(m_buildSystemOutput));
|
2022-07-04 14:20:52 +02:00
|
|
|
m_outputDock = q->addDockForWidget(output, true);
|
|
|
|
|
q->addDockWidget(Qt::RightDockWidgetArea, m_outputDock);
|
|
|
|
|
|
|
|
|
|
m_toggleRightSidebarAction.setCheckable(true);
|
|
|
|
|
m_toggleRightSidebarAction.setChecked(true);
|
|
|
|
|
const auto toolTipText = [](bool checked) {
|
2023-01-13 11:03:09 +01:00
|
|
|
return checked ? QCoreApplication::translate("::Core",
|
|
|
|
|
Core::Constants::TR_HIDE_RIGHT_SIDEBAR)
|
|
|
|
|
: QCoreApplication::translate("::Core",
|
|
|
|
|
Core::Constants::TR_SHOW_RIGHT_SIDEBAR);
|
2022-07-04 14:20:52 +02:00
|
|
|
};
|
|
|
|
|
m_toggleRightSidebarAction.setText(toolTipText(false)); // always "Show Right Sidebar"
|
|
|
|
|
m_toggleRightSidebarAction.setToolTip(toolTipText(m_toggleRightSidebarAction.isChecked()));
|
|
|
|
|
ActionManager::registerAction(&m_toggleRightSidebarAction,
|
|
|
|
|
Core::Constants::TOGGLE_RIGHT_SIDEBAR,
|
|
|
|
|
Context(Constants::C_PROJECTEXPLORER));
|
|
|
|
|
connect(&m_toggleRightSidebarAction,
|
|
|
|
|
&QAction::toggled,
|
|
|
|
|
this,
|
|
|
|
|
[this, toolTipText](bool checked) {
|
|
|
|
|
m_toggleRightSidebarAction.setToolTip(toolTipText(checked));
|
|
|
|
|
m_outputDock->setVisible(checked);
|
|
|
|
|
});
|
2016-09-28 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updatePanel()
|
|
|
|
|
{
|
2016-10-13 11:25:31 +02:00
|
|
|
ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0);
|
2017-05-24 08:48:52 +02:00
|
|
|
if (!projectItem)
|
|
|
|
|
return;
|
2016-12-05 18:11:48 +01:00
|
|
|
setPanel(projectItem->data(0, PanelWidgetRole).value<QWidget *>());
|
2016-09-28 17:31:33 +02:00
|
|
|
|
2016-10-13 11:25:31 +02:00
|
|
|
QModelIndex activeIndex = projectItem->activeIndex();
|
|
|
|
|
m_selectorTree->expandAll();
|
2016-09-28 17:31:33 +02:00
|
|
|
m_selectorTree->selectionModel()->clear();
|
|
|
|
|
m_selectorTree->selectionModel()->select(activeIndex, QItemSelectionModel::Select);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void registerProject(Project *project)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(itemForProject(project) == nullptr, return);
|
|
|
|
|
auto projectItem = new ProjectItem(project, [this] { updatePanel(); });
|
|
|
|
|
m_comboBoxModel.rootItem()->appendChild(new ComboBoxItem(projectItem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deregisterProject(Project *project)
|
|
|
|
|
{
|
|
|
|
|
ComboBoxItem *item = itemForProject(project);
|
|
|
|
|
QTC_ASSERT(item, return);
|
|
|
|
|
if (item->m_projectItem->parent())
|
|
|
|
|
m_projectsModel.takeItem(item->m_projectItem);
|
|
|
|
|
delete item->m_projectItem;
|
2016-11-03 15:27:30 +01:00
|
|
|
item->m_projectItem = nullptr;
|
2016-09-28 17:31:33 +02:00
|
|
|
m_comboBoxModel.destroyItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void projectSelected(int index)
|
|
|
|
|
{
|
|
|
|
|
Project *project = m_comboBoxModel.rootItem()->childAt(index)->m_projectItem->project();
|
|
|
|
|
SessionManager::setStartupProject(project);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComboBoxItem *itemForProject(Project *project) const
|
|
|
|
|
{
|
|
|
|
|
return m_comboBoxModel.findItemAtLevel<1>([project](ComboBoxItem *item) {
|
|
|
|
|
return item->m_projectItem->project() == project;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startupProjectChanged(Project *project)
|
|
|
|
|
{
|
|
|
|
|
if (ProjectItem *current = m_projectsModel.rootItem()->childAt(0))
|
|
|
|
|
m_projectsModel.takeItem(current); // Keep item as such alive.
|
|
|
|
|
if (!project) // Shutting down.
|
|
|
|
|
return;
|
|
|
|
|
ComboBoxItem *comboboxItem = itemForProject(project);
|
|
|
|
|
QTC_ASSERT(comboboxItem, return);
|
|
|
|
|
m_projectsModel.rootItem()->appendChild(comboboxItem->m_projectItem);
|
|
|
|
|
m_projectSelection->setCurrentIndex(comboboxItem->indexInParent());
|
|
|
|
|
m_selectorTree->expandAll();
|
|
|
|
|
m_selectorTree->setRootIndex(m_projectsModel.index(0, 0, QModelIndex()));
|
|
|
|
|
updatePanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void itemActivated(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (TreeItem *item = m_projectsModel.itemForIndex(index))
|
|
|
|
|
item->setData(0, QVariant(), ItemActivatedDirectlyRole);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
void activateProjectPanel(Utils::Id panelId)
|
2019-11-25 10:09:21 +01:00
|
|
|
{
|
|
|
|
|
if (ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0)) {
|
|
|
|
|
if (TreeItem *item = projectItem->itemForProjectPanel(panelId))
|
|
|
|
|
itemActivated(item->index());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
void openContextMenu(const QPoint &pos)
|
|
|
|
|
{
|
2016-10-13 08:16:32 +02:00
|
|
|
QMenu menu;
|
2016-09-28 17:31:33 +02:00
|
|
|
|
2016-10-13 08:16:32 +02:00
|
|
|
ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0);
|
2016-11-29 14:23:19 +01:00
|
|
|
Project *project = projectItem ? projectItem->project() : nullptr;
|
2016-09-28 17:31:33 +02:00
|
|
|
|
2016-10-13 08:16:32 +02:00
|
|
|
QModelIndex index = m_selectorTree->indexAt(pos);
|
|
|
|
|
TreeItem *item = m_projectsModel.itemForIndex(index);
|
|
|
|
|
if (item)
|
|
|
|
|
item->setData(0, QVariant::fromValue(&menu), ContextMenuItemAdderRole);
|
|
|
|
|
|
|
|
|
|
if (!menu.actions().isEmpty())
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2016-11-10 17:57:53 +03:00
|
|
|
QAction *importBuild = menu.addAction(ProjectWindow::tr("Import Existing Build..."));
|
2016-12-05 16:39:38 +01:00
|
|
|
importBuild->setEnabled(project && project->projectImporter());
|
2016-11-10 17:57:53 +03:00
|
|
|
QAction *manageKits = menu.addAction(ProjectWindow::tr("Manage Kits..."));
|
2016-10-13 08:16:32 +02:00
|
|
|
|
|
|
|
|
QAction *act = menu.exec(m_selectorTree->mapToGlobal(pos));
|
|
|
|
|
|
2016-12-05 16:39:38 +01:00
|
|
|
if (act == importBuild)
|
|
|
|
|
handleImportBuild();
|
|
|
|
|
else if (act == manageKits)
|
|
|
|
|
handleManageKits();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleManageKits()
|
|
|
|
|
{
|
|
|
|
|
if (ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0)) {
|
2018-04-24 15:07:02 +02:00
|
|
|
if (auto kitPage = KitOptionsPage::instance())
|
|
|
|
|
kitPage->showKit(KitManager::kit(Id::fromSetting(projectItem->data(0, KitIdRole))));
|
2016-12-05 16:39:38 +01:00
|
|
|
}
|
2020-06-02 09:10:40 +02:00
|
|
|
ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID);
|
2016-09-28 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-05 16:39:38 +01:00
|
|
|
void handleImportBuild()
|
|
|
|
|
{
|
|
|
|
|
ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0);
|
2018-07-12 22:17:17 +02:00
|
|
|
Project *project = projectItem ? projectItem->project() : nullptr;
|
|
|
|
|
ProjectImporter *projectImporter = project ? project->projectImporter() : nullptr;
|
2016-12-05 16:39:38 +01:00
|
|
|
QTC_ASSERT(projectImporter, return);
|
|
|
|
|
|
2021-07-26 17:41:28 +02:00
|
|
|
FilePath importDir =
|
2021-08-11 09:01:53 +02:00
|
|
|
FileUtils::getExistingDirectory(nullptr, ProjectWindow::tr("Import Directory"),
|
|
|
|
|
project->projectDirectory());
|
2016-12-05 16:39:38 +01:00
|
|
|
|
2017-04-25 15:51:35 +02:00
|
|
|
Target *lastTarget = nullptr;
|
|
|
|
|
BuildConfiguration *lastBc = nullptr;
|
2021-07-26 17:41:28 +02:00
|
|
|
for (const BuildInfo &info : projectImporter->import(importDir, false)) {
|
2019-01-29 16:51:17 +01:00
|
|
|
Target *target = project->target(info.kitId);
|
2019-08-01 14:58:00 +02:00
|
|
|
if (!target)
|
|
|
|
|
target = project->addTargetForKit(KitManager::kit(info.kitId));
|
2016-12-05 16:39:38 +01:00
|
|
|
if (target) {
|
|
|
|
|
projectImporter->makePersistent(target->kit());
|
2020-01-09 18:42:28 +01:00
|
|
|
BuildConfiguration *bc = info.factory->create(target, info);
|
2016-12-05 16:39:38 +01:00
|
|
|
QTC_ASSERT(bc, continue);
|
|
|
|
|
target->addBuildConfiguration(bc);
|
2017-04-25 15:51:35 +02:00
|
|
|
|
|
|
|
|
lastTarget = target;
|
|
|
|
|
lastBc = bc;
|
2016-11-29 14:23:19 +01:00
|
|
|
}
|
2016-12-05 16:39:38 +01:00
|
|
|
}
|
2017-04-25 15:51:35 +02:00
|
|
|
if (lastTarget && lastBc) {
|
|
|
|
|
SessionManager::setActiveBuildConfiguration(lastTarget, lastBc, SetActive::Cascade);
|
|
|
|
|
SessionManager::setActiveTarget(project, lastTarget, SetActive::Cascade);
|
|
|
|
|
}
|
2016-09-28 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-05 18:11:48 +01:00
|
|
|
void setPanel(QWidget *panel)
|
|
|
|
|
{
|
2021-05-04 14:36:47 +02:00
|
|
|
q->savePersistentSettings();
|
2016-12-05 18:11:48 +01:00
|
|
|
if (QWidget *widget = q->centralWidget()) {
|
|
|
|
|
q->takeCentralWidget();
|
|
|
|
|
widget->hide(); // Don't delete.
|
|
|
|
|
}
|
|
|
|
|
if (panel) {
|
|
|
|
|
q->setCentralWidget(panel);
|
|
|
|
|
panel->show();
|
|
|
|
|
if (q->hasFocus()) // we get assigned focus from setFocusToCurrentMode, pass that on
|
|
|
|
|
panel->setFocus();
|
|
|
|
|
}
|
2021-05-04 14:36:47 +02:00
|
|
|
q->loadPersistentSettings();
|
2016-12-05 18:11:48 +01:00
|
|
|
}
|
2016-12-05 16:39:38 +01:00
|
|
|
|
2016-12-05 18:11:48 +01:00
|
|
|
ProjectWindow *q;
|
2016-09-28 17:31:33 +02:00
|
|
|
ProjectsModel m_projectsModel;
|
|
|
|
|
ComboBoxModel m_comboBoxModel;
|
2018-02-16 14:52:05 +01:00
|
|
|
SelectorDelegate m_selectorDelegate;
|
2016-09-28 17:31:33 +02:00
|
|
|
QComboBox *m_projectSelection;
|
|
|
|
|
SelectorTree *m_selectorTree;
|
2016-12-05 16:39:38 +01:00
|
|
|
QPushButton *m_importBuild;
|
|
|
|
|
QPushButton *m_manageKits;
|
2022-07-04 14:20:52 +02:00
|
|
|
QAction m_toggleRightSidebarAction;
|
|
|
|
|
QDockWidget *m_outputDock;
|
2021-06-18 16:27:13 +02:00
|
|
|
BuildSystemOutputWindow *m_buildSystemOutput;
|
2016-09-28 17:31:33 +02:00
|
|
|
};
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
//
|
|
|
|
|
// ProjectWindow
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
ProjectWindow::ProjectWindow()
|
2018-07-16 13:59:39 +02:00
|
|
|
: d(std::make_unique<ProjectWindowPrivate>(this))
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-07-22 15:53:01 +02:00
|
|
|
setBackgroundRole(QPalette::Base);
|
2016-11-11 15:46:27 +01:00
|
|
|
|
|
|
|
|
// Request custom context menu but do not provide any to avoid
|
|
|
|
|
// the creation of the dock window selection menu.
|
2016-10-13 08:16:32 +02:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
void ProjectWindow::activateProjectPanel(Utils::Id panelId)
|
2019-11-25 10:09:21 +01:00
|
|
|
{
|
|
|
|
|
d->activateProjectPanel(panelId);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:21:03 +02:00
|
|
|
OutputWindow *ProjectWindow::buildSystemOutput() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_buildSystemOutput;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 14:05:45 +02:00
|
|
|
void ProjectWindow::hideEvent(QHideEvent *event)
|
|
|
|
|
{
|
|
|
|
|
savePersistentSettings();
|
|
|
|
|
FancyMainWindow::hideEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectWindow::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
|
|
|
|
FancyMainWindow::showEvent(event);
|
2021-05-04 14:36:47 +02:00
|
|
|
loadPersistentSettings();
|
2020-10-06 14:05:45 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-16 13:59:39 +02:00
|
|
|
ProjectWindow::~ProjectWindow() = default;
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2020-10-06 14:05:45 +02:00
|
|
|
const char PROJECT_WINDOW_KEY[] = "ProjectExplorer.ProjectWindow";
|
|
|
|
|
|
|
|
|
|
void ProjectWindow::savePersistentSettings() const
|
|
|
|
|
{
|
2021-05-04 14:36:47 +02:00
|
|
|
if (!centralWidget())
|
|
|
|
|
return;
|
2020-10-06 14:05:45 +02:00
|
|
|
QSettings * const settings = ICore::settings();
|
|
|
|
|
settings->beginGroup(PROJECT_WINDOW_KEY);
|
|
|
|
|
saveSettings(settings);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectWindow::loadPersistentSettings()
|
|
|
|
|
{
|
2021-05-04 14:36:47 +02:00
|
|
|
if (!centralWidget())
|
|
|
|
|
return;
|
2020-10-06 14:05:45 +02:00
|
|
|
QSettings * const settings = ICore::settings();
|
|
|
|
|
settings->beginGroup(PROJECT_WINDOW_KEY);
|
|
|
|
|
restoreSettings(settings);
|
|
|
|
|
settings->endGroup();
|
2022-07-04 14:20:52 +02:00
|
|
|
d->m_toggleRightSidebarAction.setChecked(d->m_outputDock->isVisible());
|
2020-10-06 14:05:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
QSize SelectorDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
2014-07-25 15:59:33 +02:00
|
|
|
{
|
2016-09-28 17:31:33 +02:00
|
|
|
QSize s = QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
|
auto model = static_cast<const ProjectsModel *>(index.model());
|
|
|
|
|
if (TreeItem *item = model->itemForIndex(index)) {
|
|
|
|
|
switch (item->level()) {
|
2017-01-24 13:17:35 +01:00
|
|
|
case 2:
|
|
|
|
|
s = QSize(s.width(), 3 * s.height());
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
case 4:
|
|
|
|
|
s = QSize(s.width(), s.height() * 1.2);
|
|
|
|
|
break;
|
2016-09-28 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return s;
|
2016-07-22 15:53:01 +02:00
|
|
|
}
|
2014-07-25 15:59:33 +02:00
|
|
|
|
2016-09-28 17:31:33 +02:00
|
|
|
void SelectorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
2016-07-22 15:53:01 +02:00
|
|
|
{
|
2016-09-28 17:31:33 +02:00
|
|
|
auto model = static_cast<const ProjectsModel *>(index.model());
|
|
|
|
|
QStyleOptionViewItem opt = option;
|
|
|
|
|
if (TreeItem *item = model->itemForIndex(index)) {
|
|
|
|
|
switch (item->level()) {
|
2016-10-07 16:21:17 +02:00
|
|
|
case 2: {
|
|
|
|
|
QColor col = creatorTheme()->color(Theme::TextColorNormal);
|
|
|
|
|
opt.palette.setColor(QPalette::Text, col);
|
2016-09-28 17:31:33 +02:00
|
|
|
opt.font.setBold(true);
|
|
|
|
|
opt.font.setPointSizeF(opt.font.pointSizeF() * 1.2);
|
|
|
|
|
break;
|
2016-10-07 16:21:17 +02:00
|
|
|
}
|
2016-09-28 17:31:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QStyledItemDelegate::paint(painter, opt, index);
|
2014-07-25 15:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 15:53:01 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|