void ModeManager::currentTabAboutToChange(int index) { if (index >= 0) { IMode *mode = d->m_modes.at(index); if (mode) emit currentModeAboutToChange(mode->id()); } }
void ModeManager::setFocusToCurrentMode() { IMode *mode = findMode(currentMode()); QTC_ASSERT(mode, return); QWidget *widget = mode->widget(); if (widget) { QWidget *focusWidget = widget->focusWidget(); if (!focusWidget) focusWidget = widget; focusWidget->setFocus(); } }
void ModeManager::setFocusToCurrentMode() { IMode *mode = currentMode(); QTC_ASSERT(mode, return); QWidget *widget = mode->widget(); if (widget) { QWidget *focusWidget = widget->focusWidget(); if (!focusWidget) focusWidget = widget; focusWidget->setFocus(); ICore::raiseWindow(focusWidget); } }
void ModeManager::objectAdded(QObject *obj) { IMode *mode = Aggregation::query<IMode>(obj); if (!mode) return; 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->name()); // Register mode shortcut ActionManager *am = m_mainWindow->actionManager(); const QString shortcutId = QLatin1String("GCS.Mode.") + mode->uniqueModeName(); QShortcut *shortcut = new QShortcut(m_mainWindow); shortcut->setWhatsThis(tr("Switch to %1 mode").arg(mode->name())); Command *cmd = am->registerShortcut(shortcut, shortcutId, QList<int>() << Constants::C_GLOBAL_ID); m_modeShortcuts.insert(index, cmd); connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updateModeToolTip())); setDefaultKeyshortcuts(); m_signalMapper->setMapping(shortcut, mode->uniqueModeName()); connect(shortcut, SIGNAL(activated()), m_signalMapper, SLOT(map())); }
void Qtilities::Testing::DebugWidget::refreshModes() { ui->tableModes->clear(); QStringList mode_headers; mode_headers << "Mode Name" << "Mode ID" << "Mode Shortcut" << "Context String" << "Help ID"; ui->tableModes->setHorizontalHeaderLabels(mode_headers); ui->tableModes->setSortingEnabled(false); QtilitiesMainWindow* mainWindow = qobject_cast<QtilitiesMainWindow*> (QtilitiesApplication::mainWindow()); if (mainWindow) { if (mainWindow->modeManager()) { ui->tableModes->setRowCount(mainWindow->modeManager()->modes().count()); for (int i = 0; i < mainWindow->modeManager()->modes().count(); ++i) { IMode* mode = mainWindow->modeManager()->modes().at(i); if (!mode) continue; // Mode Name QTableWidgetItem *newItem = new QTableWidgetItem(mode->modeName()); ui->tableModes->setItem(i, 0, newItem); // Mode ID newItem = new QTableWidgetItem(QString::number(mode->modeID())); ui->tableModes->setItem(i, 1, newItem); // Mode Shortcut newItem = new QTableWidgetItem(mainWindow->modeManager()->modeShortcut(mode->modeID())); ui->tableModes->setItem(i, 2, newItem); // Mode Context String newItem = new QTableWidgetItem(mode->contextString()); ui->tableModes->setItem(i, 3, newItem); // Mode Help ID newItem = new QTableWidgetItem(mode->contextHelpId()); ui->tableModes->setItem(i, 4, newItem); ui->tableModes->setRowHeight(i,17); } } } ui->tableModes->resizeColumnsToContents(); ui->tableModes->horizontalHeader()->setStretchLastSection(true); ui->tableModes->setSortingEnabled(true); ui->tableModes->sortByColumn(0,Qt::AscendingOrder); ui->tableModes->setShowGrid(false); ui->tableModes->setEditTriggers(QAbstractItemView::NoEditTriggers); }
void ModeManager::currentTabChanged(int index) { // Tab index changes to -1 when there is no tab left. if (index >= 0) { IMode *mode = d->m_modes.at(index); // FIXME: This hardcoded context update is required for the Debug and Edit modes, since // they use the editor widget, which is already a context widget so the main window won't // go further up the parent tree to find the mode context. ICore::updateAdditionalContexts(d->m_addedContexts, mode->context()); d->m_addedContexts = mode->context(); IMode *oldMode = 0; if (d->m_oldCurrent >= 0) oldMode = d->m_modes.at(d->m_oldCurrent); d->m_oldCurrent = index; emit currentModeChanged(mode, oldMode); } }
void ModeManager::objectAdded(QObject *obj) { IMode *mode = Aggregation::query<IMode>(obj); if (!mode) return; d->m_mainWindow->addContextObject(mode); // Count the number of modes with a higher priority int index = 0; foreach (const IMode *m, d->m_modes) if (m->priority() > mode->priority()) ++index; d->m_modes.insert(index, mode); d->m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName()); d->m_modeStack->setTabEnabled(index, mode->isEnabled()); // Register mode shortcut ActionManager *am = d->m_mainWindow->actionManager(); const QString shortcutId = QLatin1String("QtCreator.Mode.") + mode->id(); QShortcut *shortcut = new QShortcut(d->m_mainWindow); shortcut->setWhatsThis(tr("Switch to <b>%1</b> mode").arg(mode->displayName())); Command *cmd = am->registerShortcut(shortcut, shortcutId, Context(Constants::C_GLOBAL)); d->m_modeShortcuts.insert(index, cmd); connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updateModeToolTip())); for (int i = 0; i < d->m_modeShortcuts.size(); ++i) { Command *currentCmd = d->m_modeShortcuts.at(i); // we need this hack with currentlyHasDefaultSequence // because we call setDefaultShortcut multiple times on the same cmd // and still expect the current shortcut to change with it bool currentlyHasDefaultSequence = (currentCmd->keySequence() == currentCmd->defaultKeySequence()); #ifdef Q_WS_MAC currentCmd->setDefaultKeySequence(QKeySequence(QString("Meta+%1").arg(i+1))); #else currentCmd->setDefaultKeySequence(QKeySequence(QString("Ctrl+%1").arg(i+1))); #endif if (currentlyHasDefaultSequence) currentCmd->setKeySequence(currentCmd->defaultKeySequence()); } d->m_signalMapper->setMapping(shortcut, mode->id()); connect(shortcut, SIGNAL(activated()), d->m_signalMapper, SLOT(map())); connect(mode, SIGNAL(enabledStateChanged(bool)), this, SLOT(enabledStateChanged())); }
void ModeManager::objectAdded(QObject *obj) { IMode *mode = qobject_cast<IMode *>(obj); if (!mode) return; d->m_mainWindow->addContextObject(mode); // Count the number of modes with a higher priority int index = 0; foreach (const IMode *m, d->m_modes) if (m->priority() > mode->priority()) ++index; d->m_modes.insert(index, mode); d->m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName()); d->m_modeStack->setTabEnabled(index, mode->isEnabled()); // Register mode shortcut const Id actionId = mode->id().withPrefix("QtCreator.Mode."); QAction *action = new QAction(tr("Switch to <b>%1</b> mode").arg(mode->displayName()), this); Command *cmd = ActionManager::registerAction(action, actionId); d->m_modeCommands.insert(index, cmd); connect(cmd, &Command::keySequenceChanged, m_instance, &ModeManager::updateModeToolTip); for (int i = 0; i < d->m_modeCommands.size(); ++i) { Command *currentCmd = d->m_modeCommands.at(i); // we need this hack with currentlyHasDefaultSequence // because we call setDefaultShortcut multiple times on the same cmd // and still expect the current shortcut to change with it bool currentlyHasDefaultSequence = (currentCmd->keySequence() == currentCmd->defaultKeySequence()); currentCmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? QString::fromLatin1("Meta+%1").arg(i+1) : QString::fromLatin1("Ctrl+%1").arg(i+1))); if (currentlyHasDefaultSequence) currentCmd->setKeySequence(currentCmd->defaultKeySequence()); } Id id = mode->id(); connect(action, &QAction::triggered, [id] { m_instance->activateMode(id); ICore::raiseWindow(d->m_modeStack); }); connect(mode, &IMode::enabledStateChanged, m_instance, &ModeManager::enabledStateChanged); }
void ModeManager::currentTabChanged(int index) { // qDebug() << "Current tab changed " << index; // Tab index changes to -1 when there is no tab left. if (index >= 0) { IMode *mode = m_modes.at(index); // FIXME: This hardcoded context update is required for the Debug and Edit modes, since // they use the editor widget, which is already a context widget so the main window won't // go further up the parent tree to find the mode context. ICore *core = ICore::instance(); foreach (const int context, m_addedContexts) core->removeAdditionalContext(context); m_addedContexts = mode->context(); foreach (const int context, m_addedContexts) core->addAdditionalContext(context); emit currentModeChanged(mode); core->updateContext(); }
void ModeManager::enabledStateChanged() { IMode *mode = qobject_cast<IMode *>(sender()); QTC_ASSERT(mode, return); int index = d->m_modes.indexOf(mode); QTC_ASSERT(index >= 0, return); d->m_modeStack->setTabEnabled(index, mode->isEnabled()); // Make sure we leave any disabled mode to prevent possible crashes: if (mode->id() == currentMode() && !mode->isEnabled()) { // This assumes that there is always at least one enabled mode. for (int i = 0; i < d->m_modes.count(); ++i) { if (d->m_modes.at(i) != mode && d->m_modes.at(i)->isEnabled()) { activateMode(d->m_modes.at(i)->id()); break; } } } }