Core: Force and rely on mode creation before extensionsInitialized

cf7f898db3 broke initial mode display due to the then-intentional
delay in registration. Now change the approach: Only record
the modes and the last requested start mode and do all remaining
setup triggered from MainWindow::extensionsInitialized.

This changes behavior insofar as only the last requested mode
on startup (typical Welcome, if Welcome not loaded, Edit) will
be activated.

Change-Id: I62b28342c347938b001c6d3be6a076c5a69b560b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2018-01-26 08:56:40 +01:00
parent 78b7c34bbc
commit 3d2db474a4
3 changed files with 47 additions and 15 deletions

View File

@@ -327,6 +327,8 @@ void MainWindow::extensionsInitialized()
m_leftNavigationWidget->setFactories(INavigationWidgetFactory::allNavigationFactories()); m_leftNavigationWidget->setFactories(INavigationWidgetFactory::allNavigationFactories());
m_rightNavigationWidget->setFactories(INavigationWidgetFactory::allNavigationFactories()); m_rightNavigationWidget->setFactories(INavigationWidgetFactory::allNavigationFactories());
ModeManager::extensionsInitialized();
readSettings(); readSettings();
updateContext(); updateContext();

View File

@@ -37,6 +37,7 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QAction> #include <QAction>
@@ -59,8 +60,10 @@ namespace Core {
struct ModeManagerPrivate struct ModeManagerPrivate
{ {
void showMenu(int index, QMouseEvent *event); void showMenu(int index, QMouseEvent *event);
void addModeHelper(IMode *mode); void addModeHelper(int index);
void enabledStateChanged(IMode *mode); void enabledStateChanged(IMode *mode);
void activateModeHelper(Id id);
void extensionsInitializedHelper();
Internal::MainWindow *m_mainWindow; Internal::MainWindow *m_mainWindow;
Internal::FancyTabWidget *m_modeStack; Internal::FancyTabWidget *m_modeStack;
@@ -71,6 +74,9 @@ struct ModeManagerPrivate
Context m_addedContexts; Context m_addedContexts;
int m_oldCurrent; int m_oldCurrent;
bool m_modeSelectorVisible; bool m_modeSelectorVisible;
bool m_startingUp = true;
Id m_pendingFirstActiveMode; // Valid before extentionsInitialized.
}; };
static ModeManagerPrivate *d; static ModeManagerPrivate *d;
@@ -138,29 +144,51 @@ static IMode *findMode(Id id)
void ModeManager::activateMode(Id id) void ModeManager::activateMode(Id id)
{ {
const int currentIndex = d->m_modeStack->currentIndex(); d->activateModeHelper(id);
}
void ModeManagerPrivate::activateModeHelper(Id id)
{
if (m_startingUp) {
m_pendingFirstActiveMode = id;
} else {
const int currentIndex = m_modeStack->currentIndex();
const int newIndex = indexOf(id); const int newIndex = indexOf(id);
if (newIndex != currentIndex && newIndex >= 0) if (newIndex != currentIndex && newIndex >= 0)
d->m_modeStack->setCurrentIndex(newIndex); m_modeStack->setCurrentIndex(newIndex);
}
}
void ModeManager::extensionsInitialized()
{
d->extensionsInitializedHelper();
}
void ModeManagerPrivate::extensionsInitializedHelper()
{
m_startingUp = false;
Utils::sort(m_modes, &IMode::priority);
std::reverse(m_modes.begin(), m_modes.end());
for (int index = 0; index < m_modes.size(); ++index)
addModeHelper(index);
if (m_pendingFirstActiveMode.isValid())
activateModeHelper(m_pendingFirstActiveMode);
} }
void ModeManager::addMode(IMode *mode) void ModeManager::addMode(IMode *mode)
{ {
// Delay needed to get access to subclass's IMode::widget(). QTC_ASSERT(d->m_startingUp, return);
QTimer::singleShot(0, [mode] { d->addModeHelper(mode); }); d->m_modes.append(mode);
} }
void ModeManagerPrivate::addModeHelper(IMode *mode) void ModeManagerPrivate::addModeHelper(int index)
{ {
IMode *mode = m_modes.at(index);
m_mainWindow->addContextObject(mode); m_mainWindow->addContextObject(mode);
// Count the number of modes with a higher priority
int index = 0;
foreach (const IMode *m, m_modes)
if (m->priority() > mode->priority())
++index;
m_modes.insert(index, mode);
m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName(), m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName(),
mode->menu() != nullptr); mode->menu() != nullptr);
m_modeStack->setTabEnabled(index, mode->isEnabled()); m_modeStack->setTabEnabled(index, mode->isEnabled());

View File

@@ -70,6 +70,8 @@ private:
explicit ModeManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack); explicit ModeManager(Internal::MainWindow *mainWindow, Internal::FancyTabWidget *modeStack);
~ModeManager(); ~ModeManager();
static void extensionsInitialized();
static void addMode(IMode *mode); static void addMode(IMode *mode);
static void removeMode(IMode *mode); static void removeMode(IMode *mode);
void currentTabAboutToChange(int index); void currentTabAboutToChange(int index);