2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "navigationwidget.h"
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "actionmanager/actionmanager.h"
|
|
|
|
|
#include "actionmanager/command.h"
|
|
|
|
|
#include "coreplugintr.h"
|
2010-06-25 12:56:16 +02:00
|
|
|
#include "icontext.h"
|
2013-05-07 11:39:45 +02:00
|
|
|
#include "icore.h"
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "imode.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
#include "inavigationwidgetfactory.h"
|
|
|
|
|
#include "modemanager.h"
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "navigationsubwidget.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
#include <utils/qtcassert.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
2015-04-23 23:57:48 +03:00
|
|
|
#include <QCoreApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QResizeEvent>
|
|
|
|
|
#include <QStandardItemModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
namespace Core {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::s_currentLeft = nullptr;
|
|
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::s_currentRight = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::current(Side side)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
return side == Side::Left ? s_currentLeft : s_currentRight;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
void NavigationWidgetPlaceHolder::setCurrent(Side side, NavigationWidgetPlaceHolder *navWidget)
|
|
|
|
|
{
|
|
|
|
|
if (side == Side::Left)
|
|
|
|
|
s_currentLeft = navWidget;
|
|
|
|
|
else
|
|
|
|
|
s_currentRight = navWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder::NavigationWidgetPlaceHolder(Id mode, Side side, QWidget *parent)
|
|
|
|
|
:QWidget(parent), m_mode(mode), m_side(side)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setLayout(new QVBoxLayout);
|
2019-08-29 10:36:01 +02:00
|
|
|
layout()->setContentsMargins(0, 0, 0, 0);
|
2014-11-16 10:52:41 +02:00
|
|
|
connect(ModeManager::instance(), &ModeManager::currentModeAboutToChange,
|
|
|
|
|
this, &NavigationWidgetPlaceHolder::currentModeAboutToChange);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder::~NavigationWidgetPlaceHolder()
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
if (NavigationWidgetPlaceHolder::current(m_side) == this) {
|
|
|
|
|
if (NavigationWidget *nw = NavigationWidget::instance(m_side)) {
|
|
|
|
|
nw->setParent(nullptr);
|
2011-03-15 14:52:35 +01:00
|
|
|
nw->hide();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
void NavigationWidgetPlaceHolder::applyStoredSize()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-07-21 21:11:46 +02:00
|
|
|
auto splitter = qobject_cast<QSplitter *>(parentWidget());
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
if (splitter) {
|
|
|
|
|
// A splitter we need to resize the splitter sizes
|
|
|
|
|
QList<int> sizes = splitter->sizes();
|
|
|
|
|
int diff = 0;
|
|
|
|
|
int count = sizes.count();
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
|
|
|
|
if (auto ph = qobject_cast<NavigationWidgetPlaceHolder *>(splitter->widget(i))) {
|
|
|
|
|
--count;
|
|
|
|
|
int width = ph->storedWidth();
|
|
|
|
|
diff += width - sizes.at(i);
|
|
|
|
|
sizes[i] = width;
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
int adjust = count > 1 ? (diff / (count - 1)) : 0;
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
|
|
|
|
if (!qobject_cast<NavigationWidgetPlaceHolder *>(splitter->widget(i)))
|
|
|
|
|
sizes[i] += adjust;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
splitter->setSizes(sizes);
|
|
|
|
|
} else {
|
|
|
|
|
QSize s = size();
|
|
|
|
|
s.setWidth(storedWidth());
|
|
|
|
|
resize(s);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function does work even though the order in which
|
|
|
|
|
// the placeHolder get the signal is undefined.
|
|
|
|
|
// It does ensure that after all PlaceHolders got the signal
|
|
|
|
|
// m_current points to the current PlaceHolder, or zero if there
|
|
|
|
|
// is no PlaceHolder in this mode
|
|
|
|
|
// And that the parent of the NavigationWidget gets the correct parent
|
2016-03-25 20:00:19 +01:00
|
|
|
void NavigationWidgetPlaceHolder::currentModeAboutToChange(Id mode)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidget *navigationWidget = NavigationWidget::instance(m_side);
|
|
|
|
|
NavigationWidgetPlaceHolder *current = NavigationWidgetPlaceHolder::current(m_side);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
if (current == this) {
|
|
|
|
|
setCurrent(m_side, nullptr);
|
|
|
|
|
navigationWidget->setParent(nullptr);
|
2008-12-02 12:01:29 +01:00
|
|
|
navigationWidget->hide();
|
2016-09-17 18:31:56 +03:00
|
|
|
navigationWidget->placeHolderChanged(nullptr);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-09-17 18:31:56 +03:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_mode == mode) {
|
2016-09-17 18:31:56 +03:00
|
|
|
setCurrent(m_side, this);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
layout()->addWidget(navigationWidget);
|
|
|
|
|
navigationWidget->show();
|
|
|
|
|
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
applyStoredSize();
|
2008-12-02 12:01:29 +01:00
|
|
|
setVisible(navigationWidget->isShown());
|
2016-09-17 18:31:56 +03:00
|
|
|
navigationWidget->placeHolderChanged(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
int NavigationWidgetPlaceHolder::storedWidth() const
|
|
|
|
|
{
|
|
|
|
|
return NavigationWidget::instance(m_side)->storedWidth();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
struct ActivationInfo {
|
|
|
|
|
Side side;
|
|
|
|
|
int position;
|
|
|
|
|
};
|
|
|
|
|
using ActivationsMap = QHash<Id, ActivationInfo>;
|
|
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
struct NavigationWidgetPrivate
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
explicit NavigationWidgetPrivate(QAction *toggleSideBarAction, Side side);
|
2013-11-13 13:34:23 +01:00
|
|
|
~NavigationWidgetPrivate() { delete m_factoryModel; }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
QList<Internal::NavigationSubWidget *> m_subWidgets;
|
2014-11-16 10:52:41 +02:00
|
|
|
QHash<QAction *, Id> m_actionMap;
|
|
|
|
|
QHash<Id, Command *> m_commandMap;
|
2010-09-16 12:26:28 +02:00
|
|
|
QStandardItemModel *m_factoryModel;
|
|
|
|
|
|
|
|
|
|
bool m_shown;
|
|
|
|
|
int m_width;
|
2013-11-13 13:34:23 +01:00
|
|
|
QAction *m_toggleSideBarAction; // does not take ownership
|
2016-09-17 18:31:56 +03:00
|
|
|
Side m_side;
|
|
|
|
|
|
|
|
|
|
static NavigationWidget *s_instanceLeft;
|
|
|
|
|
static NavigationWidget *s_instanceRight;
|
|
|
|
|
|
|
|
|
|
static ActivationsMap s_activationsMap;
|
|
|
|
|
|
|
|
|
|
static void updateActivationsMap(Id activatedId, const ActivationInfo &activationInfo);
|
|
|
|
|
static void removeFromActivationsMap(const ActivationInfo &activationInfo);
|
2010-09-16 12:26:28 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPrivate::NavigationWidgetPrivate(QAction *toggleSideBarAction, Side side) :
|
2010-07-15 12:24:03 +02:00
|
|
|
m_factoryModel(new QStandardItemModel),
|
|
|
|
|
m_shown(true),
|
|
|
|
|
m_width(0),
|
2016-09-17 18:31:56 +03:00
|
|
|
m_toggleSideBarAction(toggleSideBarAction),
|
|
|
|
|
m_side(side)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidgetPrivate::updateActivationsMap(Id activatedId, const ActivationInfo &activationInfo)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
s_activationsMap.insert(activatedId, activationInfo);
|
2010-09-16 12:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidget *NavigationWidgetPrivate::s_instanceLeft = nullptr;
|
|
|
|
|
NavigationWidget *NavigationWidgetPrivate::s_instanceRight = nullptr;
|
|
|
|
|
ActivationsMap NavigationWidgetPrivate::s_activationsMap;
|
2010-09-16 12:26:28 +02:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction, Side side) :
|
|
|
|
|
d(new NavigationWidgetPrivate(toggleSideBarAction, side))
|
2010-09-16 12:26:28 +02:00
|
|
|
{
|
|
|
|
|
d->m_factoryModel->setSortRole(FactoryPriorityRole);
|
2008-12-02 12:01:29 +01:00
|
|
|
setOrientation(Qt::Vertical);
|
2016-09-17 18:31:56 +03:00
|
|
|
|
|
|
|
|
if (side == Side::Left)
|
2020-11-18 22:42:51 +01:00
|
|
|
NavigationWidgetPrivate::s_instanceLeft = this;
|
2016-09-17 18:31:56 +03:00
|
|
|
else
|
2020-11-18 22:42:51 +01:00
|
|
|
NavigationWidgetPrivate::s_instanceRight = this;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget::~NavigationWidget()
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
if (d->m_side == Side::Left)
|
|
|
|
|
NavigationWidgetPrivate::s_instanceLeft = nullptr;
|
|
|
|
|
else
|
|
|
|
|
NavigationWidgetPrivate::s_instanceRight = nullptr;
|
|
|
|
|
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidget *NavigationWidget::instance(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left ? NavigationWidgetPrivate::s_instanceLeft
|
|
|
|
|
: NavigationWidgetPrivate::s_instanceRight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *NavigationWidget::activateSubWidget(Id factoryId, Side fallbackSide)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidget *navigationWidget = NavigationWidget::instance(fallbackSide);
|
|
|
|
|
int preferredPosition = -1;
|
|
|
|
|
|
|
|
|
|
if (NavigationWidgetPrivate::s_activationsMap.contains(factoryId)) {
|
|
|
|
|
const ActivationInfo info = NavigationWidgetPrivate::s_activationsMap.value(factoryId);
|
|
|
|
|
navigationWidget = NavigationWidget::instance(info.side);
|
|
|
|
|
preferredPosition = info.position;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-17 17:33:47 +02:00
|
|
|
return navigationWidget->activateSubWidget(factoryId, preferredPosition);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-13 13:34:47 +01:00
|
|
|
void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &factories)
|
2010-07-15 12:24:03 +02:00
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
Context navicontext(Constants::C_NAVIGATION_PANE);
|
2022-10-07 14:46:06 +02:00
|
|
|
for (INavigationWidgetFactory *factory : std::as_const(factories)) {
|
2011-11-09 12:07:41 +01:00
|
|
|
const Id id = factory->id();
|
2016-09-17 18:31:56 +03:00
|
|
|
const Id actionId = id.withPrefix("QtCreator.Sidebar.");
|
|
|
|
|
|
|
|
|
|
if (!ActionManager::command(actionId)) {
|
|
|
|
|
QAction *action = new QAction(tr("Activate %1 View").arg(factory->displayName()), this);
|
|
|
|
|
d->m_actionMap.insert(action, id);
|
|
|
|
|
connect(action, &QAction::triggered, this, [this, action]() {
|
|
|
|
|
NavigationWidget::activateSubWidget(d->m_actionMap[action], Side::Left);
|
|
|
|
|
});
|
|
|
|
|
Command *cmd = ActionManager::registerAction(action, actionId, navicontext);
|
|
|
|
|
cmd->setDefaultKeySequence(factory->activationSequence());
|
|
|
|
|
d->m_commandMap.insert(id, cmd);
|
|
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
|
|
|
|
|
QStandardItem *newRow = new QStandardItem(factory->displayName());
|
2019-05-27 13:32:20 +02:00
|
|
|
newRow->setData(QVariant::fromValue(factory), FactoryObjectRole);
|
2011-11-09 12:07:41 +01:00
|
|
|
newRow->setData(QVariant::fromValue(factory->id()), FactoryIdRole);
|
2021-09-21 16:21:33 +02:00
|
|
|
newRow->setData(QVariant::fromValue(actionId), FactoryActionIdRole);
|
2010-09-09 14:35:26 +02:00
|
|
|
newRow->setData(factory->priority(), FactoryPriorityRole);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_factoryModel->appendRow(newRow);
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_factoryModel->sort(0);
|
2011-01-31 15:18:16 +01:00
|
|
|
updateToggleText();
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
QString NavigationWidget::settingsGroup() const
|
|
|
|
|
{
|
|
|
|
|
const QString side(d->m_side == Side::Left ? QStringLiteral("Left")
|
|
|
|
|
: QStringLiteral("Right"));
|
|
|
|
|
return QStringLiteral("Navigation%1").arg(side);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int NavigationWidget::storedWidth()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_width;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
QAbstractItemModel *NavigationWidget::factoryModel() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_factoryModel;
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-12-08 18:29:44 +01:00
|
|
|
void NavigationWidget::updateToggleText()
|
|
|
|
|
{
|
2010-10-21 17:49:19 +02:00
|
|
|
bool haveData = d->m_factoryModel->rowCount();
|
|
|
|
|
d->m_toggleSideBarAction->setVisible(haveData);
|
2016-09-17 18:31:56 +03:00
|
|
|
d->m_toggleSideBarAction->setEnabled(haveData && NavigationWidgetPlaceHolder::current(d->m_side));
|
2010-10-21 17:49:19 +02:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
const char *trToolTip = d->m_side == Side::Left
|
|
|
|
|
? (isShown() ? Constants::TR_HIDE_LEFT_SIDEBAR : Constants::TR_SHOW_LEFT_SIDEBAR)
|
|
|
|
|
: (isShown() ? Constants::TR_HIDE_RIGHT_SIDEBAR : Constants::TR_SHOW_RIGHT_SIDEBAR);
|
|
|
|
|
|
2022-07-05 13:56:04 +02:00
|
|
|
d->m_toggleSideBarAction->setToolTip(Tr::tr(trToolTip));
|
2009-12-08 18:29:44 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::placeHolderChanged(NavigationWidgetPlaceHolder *holder)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toggleSideBarAction->setChecked(holder && isShown());
|
2009-12-08 18:29:44 +01:00
|
|
|
updateToggleText();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::resizeEvent(QResizeEvent *re)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_width && re->size().width())
|
|
|
|
|
d->m_width = re->size().width();
|
2008-12-02 12:01:29 +01:00
|
|
|
MiniSplitter::resizeEvent(re);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-25 15:05:56 +02:00
|
|
|
static QIcon closeIconForSide(Side side, int itemCount)
|
|
|
|
|
{
|
|
|
|
|
if (itemCount > 1)
|
|
|
|
|
return Utils::Icons::CLOSE_SPLIT_TOP.icon();
|
|
|
|
|
return side == Side::Left
|
|
|
|
|
? Utils::Icons::CLOSE_SPLIT_LEFT.icon()
|
|
|
|
|
: Utils::Icons::CLOSE_SPLIT_RIGHT.icon();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position, int factoryIndex)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int pos = position + 1; pos < d->m_subWidgets.size(); ++pos) {
|
2016-09-17 18:31:56 +03:00
|
|
|
Internal::NavigationSubWidget *nsw = d->m_subWidgets.at(pos);
|
|
|
|
|
nsw->setPosition(pos + 1);
|
|
|
|
|
NavigationWidgetPrivate::updateActivationsMap(nsw->factory()->id(), {d->m_side, pos + 1});
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-19 17:07:49 +01:00
|
|
|
if (!d->m_subWidgets.isEmpty()) // Make all icons the bottom icon
|
2016-08-03 17:55:54 +02:00
|
|
|
d->m_subWidgets.at(0)->setCloseIcon(Utils::Icons::CLOSE_SPLIT_BOTTOM.icon());
|
2015-01-19 17:07:49 +01:00
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
auto nsw = new Internal::NavigationSubWidget(this, position, factoryIndex);
|
2022-07-20 12:05:49 +02:00
|
|
|
connect(nsw, &Internal::NavigationSubWidget::splitMe, this, [this, nsw](int factoryIndex) {
|
|
|
|
|
insertSubItem(indexOf(nsw) + 1, factoryIndex);
|
|
|
|
|
});
|
|
|
|
|
connect(nsw, &Internal::NavigationSubWidget::closeMe, this, [this, nsw] {
|
|
|
|
|
closeSubWidget(nsw);
|
|
|
|
|
});
|
|
|
|
|
connect(nsw, &Internal::NavigationSubWidget::factoryIndexChanged, this, [this, nsw] {
|
|
|
|
|
const Id factoryId = nsw->factory()->id();
|
|
|
|
|
NavigationWidgetPrivate::updateActivationsMap(factoryId, {d->m_side, nsw->position()});
|
|
|
|
|
});
|
2008-12-02 12:01:29 +01:00
|
|
|
insertWidget(position, nsw);
|
2016-09-17 18:31:56 +03:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.insert(position, nsw);
|
2017-07-25 15:05:56 +02:00
|
|
|
d->m_subWidgets.at(0)->setCloseIcon(closeIconForSide(d->m_side, d->m_subWidgets.size()));
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPrivate::updateActivationsMap(nsw->factory()->id(), {d->m_side, position});
|
2008-12-02 12:01:29 +01:00
|
|
|
return nsw;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
QWidget *NavigationWidget::activateSubWidget(Id factoryId, int preferredPosition)
|
2010-08-13 10:10:43 +02:00
|
|
|
{
|
|
|
|
|
setShown(true);
|
2022-10-07 14:46:06 +02:00
|
|
|
for (Internal::NavigationSubWidget *subWidget : std::as_const(d->m_subWidgets)) {
|
2010-08-13 10:10:43 +02:00
|
|
|
if (subWidget->factory()->id() == factoryId) {
|
2008-12-02 12:01:29 +01:00
|
|
|
subWidget->setFocusWidget();
|
2013-05-07 11:39:45 +02:00
|
|
|
ICore::raiseWindow(this);
|
2015-08-20 14:47:02 +02:00
|
|
|
return subWidget->widget();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-13 10:10:43 +02:00
|
|
|
int index = factoryIndex(factoryId);
|
2010-07-15 12:24:03 +02:00
|
|
|
if (index >= 0) {
|
2016-09-17 18:31:56 +03:00
|
|
|
bool preferredIndexValid = 0 <= preferredPosition && preferredPosition < d->m_subWidgets.count();
|
|
|
|
|
const int activationIndex = preferredIndexValid ? preferredPosition : 0;
|
|
|
|
|
Internal::NavigationSubWidget *subWidget = d->m_subWidgets.at(activationIndex);
|
|
|
|
|
subWidget->setFactoryIndex(index);
|
|
|
|
|
subWidget->setFocusWidget();
|
2013-05-07 11:39:45 +02:00
|
|
|
ICore::raiseWindow(this);
|
2016-09-17 18:31:56 +03:00
|
|
|
return subWidget->widget();
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2015-08-25 11:43:29 +02:00
|
|
|
return nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-20 12:05:49 +02:00
|
|
|
void NavigationWidget::closeSubWidget(Internal::NavigationSubWidget *subWidget)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_subWidgets.count() != 1) {
|
2010-07-15 12:24:03 +02:00
|
|
|
subWidget->saveSettings();
|
2016-09-17 18:31:56 +03:00
|
|
|
|
|
|
|
|
int position = d->m_subWidgets.indexOf(subWidget);
|
|
|
|
|
for (int pos = position + 1; pos < d->m_subWidgets.size(); ++pos) {
|
|
|
|
|
Internal::NavigationSubWidget *nsw = d->m_subWidgets.at(pos);
|
|
|
|
|
nsw->setPosition(pos - 1);
|
|
|
|
|
NavigationWidgetPrivate::updateActivationsMap(nsw->factory()->id(), {d->m_side, pos - 1});
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.removeOne(subWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
subWidget->hide();
|
|
|
|
|
subWidget->deleteLater();
|
2015-01-19 17:07:49 +01:00
|
|
|
// update close button of top item
|
2017-07-25 15:05:56 +02:00
|
|
|
if (!d->m_subWidgets.isEmpty())
|
|
|
|
|
d->m_subWidgets.at(0)->setCloseIcon(closeIconForSide(d->m_side, d->m_subWidgets.size()));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
|
|
|
|
setShown(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 11:24:27 +01:00
|
|
|
static QString defaultFirstView(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left ? QString("Projects") : QString("Outline");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool defaultVisible(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::saveSettings(QtcSettings *settings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
QStringList viewIds;
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int i=0; i<d->m_subWidgets.count(); ++i) {
|
|
|
|
|
d->m_subWidgets.at(i)->saveSettings();
|
2011-11-09 12:07:41 +01:00
|
|
|
viewIds.append(d->m_subWidgets.at(i)->factory()->id().toString());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2020-12-10 11:24:27 +01:00
|
|
|
settings->setValueWithDefault(settingsKey("Views"), viewIds, {defaultFirstView(d->m_side)});
|
|
|
|
|
settings->setValueWithDefault(settingsKey("Visible"), isShown(), defaultVisible(d->m_side));
|
2016-09-17 18:31:56 +03:00
|
|
|
settings->setValue(settingsKey("VerticalPosition"), saveState());
|
|
|
|
|
settings->setValue(settingsKey("Width"), d->m_width);
|
|
|
|
|
|
|
|
|
|
const QString activationKey = QStringLiteral("ActivationPosition.");
|
|
|
|
|
const auto keys = NavigationWidgetPrivate::s_activationsMap.keys();
|
|
|
|
|
for (const auto &factoryId : keys) {
|
|
|
|
|
const auto &info = NavigationWidgetPrivate::s_activationsMap[factoryId];
|
|
|
|
|
if (info.side == d->m_side)
|
|
|
|
|
settings->setValue(settingsKey(activationKey + factoryId.toString()), info.position);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
void NavigationWidget::restoreSettings(QSettings *settings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-10-21 17:49:19 +02:00
|
|
|
if (!d->m_factoryModel->rowCount()) {
|
|
|
|
|
// We have no widgets to show!
|
|
|
|
|
setShown(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
const bool isLeftSide = d->m_side == Side::Left;
|
2020-12-10 11:24:27 +01:00
|
|
|
QStringList viewIds = settings
|
|
|
|
|
->value(settingsKey("Views"), QStringList(defaultFirstView(d->m_side)))
|
|
|
|
|
.toStringList();
|
2009-03-26 15:54:05 +01:00
|
|
|
|
|
|
|
|
bool restoreSplitterState = true;
|
2016-09-17 18:31:56 +03:00
|
|
|
int version = settings->value(settingsKey("Version"), 1).toInt();
|
2009-03-26 15:54:05 +01:00
|
|
|
if (version == 1) {
|
2016-09-17 18:31:56 +03:00
|
|
|
QLatin1String defaultSecondView = isLeftSide ? QLatin1String("Open Documents") : QLatin1String("Bookmarks");
|
|
|
|
|
if (!viewIds.contains(defaultSecondView)) {
|
|
|
|
|
viewIds += defaultSecondView;
|
2009-03-26 15:54:05 +01:00
|
|
|
restoreSplitterState = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-09-17 18:31:56 +03:00
|
|
|
settings->setValue(settingsKey("Version"), 2);
|
2009-03-26 15:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:54:11 +02:00
|
|
|
int position = 0;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const QString &id : std::as_const(viewIds)) {
|
2013-01-16 14:18:35 +01:00
|
|
|
int index = factoryIndex(Id::fromString(id));
|
2010-10-21 11:54:11 +02:00
|
|
|
if (index >= 0) {
|
|
|
|
|
// Only add if the id was actually found!
|
|
|
|
|
insertSubItem(position, index);
|
|
|
|
|
++position;
|
2010-07-15 12:24:03 +02:00
|
|
|
} else {
|
2010-10-21 11:54:11 +02:00
|
|
|
restoreSplitterState = false;
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:54:11 +02:00
|
|
|
if (d->m_subWidgets.isEmpty())
|
2016-09-17 18:31:56 +03:00
|
|
|
// Make sure we have at least the projects widget or outline widget
|
2020-12-10 11:24:27 +01:00
|
|
|
insertSubItem(0, qMax(0, factoryIndex(Id::fromString(defaultFirstView(d->m_side)))));
|
2010-10-21 11:54:11 +02:00
|
|
|
|
2020-12-10 11:24:27 +01:00
|
|
|
setShown(settings->value(settingsKey("Visible"), defaultVisible(d->m_side)).toBool());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
if (restoreSplitterState && settings->contains(settingsKey("VerticalPosition"))) {
|
|
|
|
|
restoreState(settings->value(settingsKey("VerticalPosition")).toByteArray());
|
2009-03-26 15:54:05 +01:00
|
|
|
} else {
|
|
|
|
|
QList<int> sizes;
|
|
|
|
|
sizes += 256;
|
2010-07-15 12:24:03 +02:00
|
|
|
for (int i = viewIds.size()-1; i > 0; --i)
|
2009-03-26 15:54:05 +01:00
|
|
|
sizes.prepend(512);
|
|
|
|
|
setSizes(sizes);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
d->m_width = settings->value(settingsKey("Width"), 240).toInt();
|
2010-10-25 12:06:14 +02:00
|
|
|
if (d->m_width < 40)
|
|
|
|
|
d->m_width = 40;
|
2010-10-21 11:56:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Apply
|
2016-09-17 18:31:56 +03:00
|
|
|
if (NavigationWidgetPlaceHolder::current(d->m_side))
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
NavigationWidgetPlaceHolder::current(d->m_side)->applyStoredSize();
|
2016-09-17 18:31:56 +03:00
|
|
|
|
|
|
|
|
// Restore last activation positions
|
|
|
|
|
settings->beginGroup(settingsGroup());
|
|
|
|
|
const QString activationKey = QStringLiteral("ActivationPosition.");
|
|
|
|
|
const auto keys = settings->allKeys();
|
|
|
|
|
for (const QString &key : keys) {
|
|
|
|
|
if (!key.startsWith(activationKey))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int position = settings->value(key).toInt();
|
|
|
|
|
Id factoryId = Id::fromString(key.mid(activationKey.length()));
|
|
|
|
|
NavigationWidgetPrivate::updateActivationsMap(factoryId, {d->m_side, position});
|
|
|
|
|
}
|
|
|
|
|
settings->endGroup();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:59:04 +02:00
|
|
|
void NavigationWidget::closeSubWidgets()
|
|
|
|
|
{
|
2022-10-07 14:46:06 +02:00
|
|
|
for (Internal::NavigationSubWidget *subWidget : std::as_const(d->m_subWidgets)) {
|
2010-08-11 14:59:04 +02:00
|
|
|
subWidget->saveSettings();
|
|
|
|
|
delete subWidget;
|
|
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.clear();
|
2010-08-11 14:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::setShown(bool b)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_shown == b)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2010-10-21 17:49:19 +02:00
|
|
|
bool haveData = d->m_factoryModel->rowCount();
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_shown = b;
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *current = NavigationWidgetPlaceHolder::current(d->m_side);
|
|
|
|
|
if (current) {
|
2017-04-20 11:30:06 +02:00
|
|
|
bool visible = d->m_shown && haveData;
|
2016-09-17 18:31:56 +03:00
|
|
|
current->setVisible(visible);
|
|
|
|
|
d->m_toggleSideBarAction->setChecked(visible);
|
2009-01-06 17:03:08 +01:00
|
|
|
} else {
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toggleSideBarAction->setChecked(false);
|
2009-01-06 17:03:08 +01:00
|
|
|
}
|
2009-12-08 18:29:44 +01:00
|
|
|
updateToggleText();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::isShown() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_shown;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
int NavigationWidget::factoryIndex(Id id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int row = 0; row < d->m_factoryModel->rowCount(); ++row) {
|
2014-11-16 10:52:41 +02:00
|
|
|
if (d->m_factoryModel->data(d->m_factoryModel->index(row, 0), FactoryIdRole).value<Id>() == id)
|
2010-07-15 12:24:03 +02:00
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
QString NavigationWidget::settingsKey(const QString &key) const
|
|
|
|
|
{
|
|
|
|
|
return QStringLiteral("%1/%2").arg(settingsGroup(), key);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
QHash<Id, Command *> NavigationWidget::commandMap() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_commandMap;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
} // namespace Core
|