Modes: Temporarily re-add a removeMode function

Partially reverts 6a142dfd95

Looks like this was used by 3rdparty plugin(s) for a mode that is only
useful for some time and then should not be shown again.

Re-add removeMode from before 5.0, but do not trigger that automatically
from the mode destructor, so it doesn't interfere at shutdown.

This patch is just a binary compatible partial revert. Since removeMode
is broken in several aspects (e.g. corresponding commands are not
removed) and we don't really support adding and removing modes during
runtime, this should be replaced later on by a different way to handle
the usecase, like a "visible" property for modes, which could be useful
in other ways too.

Fixes: QTCREATORBUG-26270
Change-Id: Ief2a36d94bd09b0511a14f528b33fdbcc4c4222b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2021-09-22 11:33:01 +02:00
parent 0e1ce368b9
commit e84bc5f81f
4 changed files with 30 additions and 0 deletions

View File

@@ -551,6 +551,12 @@ void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const
m_tabBar->insertTab(index, icon, label, hasMenu);
}
void FancyTabWidget::removeTab(int index)
{
m_modesStack->removeWidget(m_modesStack->widget(index));
m_tabBar->removeTab(index);
}
void FancyTabWidget::setBackgroundBrush(const QBrush &brush)
{
QPalette pal;

View File

@@ -109,6 +109,12 @@ public:
updateGeometry();
}
void setEnabled(int index, bool enabled);
void removeTab(int index)
{
FancyTab *tab = m_tabs.takeAt(index);
delete tab;
updateGeometry();
}
void setCurrentIndex(int index);
int currentIndex() const { return m_currentIndex; }
@@ -142,6 +148,7 @@ public:
FancyTabWidget(QWidget *parent = nullptr);
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu);
void removeTab(int index);
void setBackgroundBrush(const QBrush &brush);
void addCornerWidget(QWidget *widget);
void insertCornerWidget(int pos, QWidget *widget);

View File

@@ -256,6 +256,21 @@ void ModeManagerPrivate::appendMode(IMode *mode)
QObject::connect(mode, &IMode::enabledStateChanged, [this, mode] { enabledStateChanged(mode); });
}
void ModeManager::removeMode(IMode *mode)
{
const int index = d->m_modes.indexOf(mode);
if (index >= d->m_modes.size() - 1 && d->m_modes.size() > 1)
d->m_modeStack->setCurrentIndex(d->m_modes.size() - 2);
d->m_modes.remove(index);
if (d->m_startingUp)
return;
d->m_modeCommands.remove(index);
d->m_modeStack->removeTab(index);
d->m_mainWindow->removeContextObject(mode);
}
void ModeManagerPrivate::enabledStateChanged(IMode *mode)
{
int index = d->m_modes.indexOf(mode);

View File

@@ -67,6 +67,8 @@ public:
static void setFocusToCurrentMode();
static Style modeStyle();
static void removeMode(IMode *mode);
public slots:
static void setModeStyle(Style layout);
static void cycleModeStyle();