mirror of
https://github.com/KDE/konsole.git
synced 2026-06-11 23:45:09 -04:00
Add Q_ASSERT/returns for _actionCollection
KXMLGUIClient->actionCollection() only returns a non NULL value so I don't think these checks are needed but for now add Q_ASSERTs and returns. Previously, the if() didn't cover all the assignments.
This commit is contained in:
@@ -122,6 +122,11 @@ QWidget* ViewManager::widget() const
|
||||
|
||||
void ViewManager::setupActions()
|
||||
{
|
||||
Q_ASSERT(_actionCollection);
|
||||
if (!_actionCollection) {
|
||||
return;
|
||||
}
|
||||
|
||||
KActionCollection* collection = _actionCollection;
|
||||
|
||||
QAction* nextViewAction = new QAction(i18nc("@action Shortcut entry", "Next Tab") , this);
|
||||
@@ -137,84 +142,82 @@ void ViewManager::setupActions()
|
||||
QList<QAction*> multiViewOnlyActions;
|
||||
multiViewOnlyActions << nextContainerAction;
|
||||
|
||||
if (collection) {
|
||||
QAction* splitLeftRightAction = new QAction(QIcon::fromTheme(QStringLiteral("view-split-left-right")),
|
||||
i18nc("@action:inmenu", "Split View Left/Right"),
|
||||
this);
|
||||
collection->setDefaultShortcut(splitLeftRightAction, Konsole::ACCEL + Qt::Key_ParenLeft);
|
||||
collection->addAction("split-view-left-right", splitLeftRightAction);
|
||||
connect(splitLeftRightAction , &QAction::triggered , this , &Konsole::ViewManager::splitLeftRight);
|
||||
QAction* splitLeftRightAction = new QAction(QIcon::fromTheme(QStringLiteral("view-split-left-right")),
|
||||
i18nc("@action:inmenu", "Split View Left/Right"),
|
||||
this);
|
||||
collection->setDefaultShortcut(splitLeftRightAction, Konsole::ACCEL + Qt::Key_ParenLeft);
|
||||
collection->addAction("split-view-left-right", splitLeftRightAction);
|
||||
connect(splitLeftRightAction , &QAction::triggered , this , &Konsole::ViewManager::splitLeftRight);
|
||||
|
||||
QAction* splitTopBottomAction = new QAction(QIcon::fromTheme(QStringLiteral("view-split-top-bottom")) ,
|
||||
i18nc("@action:inmenu", "Split View Top/Bottom"), this);
|
||||
collection->setDefaultShortcut(splitTopBottomAction, Konsole::ACCEL + Qt::Key_ParenRight);
|
||||
collection->addAction("split-view-top-bottom", splitTopBottomAction);
|
||||
connect(splitTopBottomAction , &QAction::triggered , this , &Konsole::ViewManager::splitTopBottom);
|
||||
QAction* splitTopBottomAction = new QAction(QIcon::fromTheme(QStringLiteral("view-split-top-bottom")) ,
|
||||
i18nc("@action:inmenu", "Split View Top/Bottom"), this);
|
||||
collection->setDefaultShortcut(splitTopBottomAction, Konsole::ACCEL + Qt::Key_ParenRight);
|
||||
collection->addAction("split-view-top-bottom", splitTopBottomAction);
|
||||
connect(splitTopBottomAction , &QAction::triggered , this , &Konsole::ViewManager::splitTopBottom);
|
||||
|
||||
QAction* closeActiveAction = new QAction(i18nc("@action:inmenu Close Active View", "Close Active") , this);
|
||||
closeActiveAction->setIcon(QIcon::fromTheme(QStringLiteral("view-close")));
|
||||
collection->setDefaultShortcut(closeActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_X);
|
||||
closeActiveAction->setEnabled(false);
|
||||
collection->addAction("close-active-view", closeActiveAction);
|
||||
connect(closeActiveAction , &QAction::triggered , this , &Konsole::ViewManager::closeActiveContainer);
|
||||
QAction* closeActiveAction = new QAction(i18nc("@action:inmenu Close Active View", "Close Active") , this);
|
||||
closeActiveAction->setIcon(QIcon::fromTheme(QStringLiteral("view-close")));
|
||||
collection->setDefaultShortcut(closeActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_X);
|
||||
closeActiveAction->setEnabled(false);
|
||||
collection->addAction("close-active-view", closeActiveAction);
|
||||
connect(closeActiveAction , &QAction::triggered , this , &Konsole::ViewManager::closeActiveContainer);
|
||||
|
||||
multiViewOnlyActions << closeActiveAction;
|
||||
multiViewOnlyActions << closeActiveAction;
|
||||
|
||||
QAction* closeOtherAction = new QAction(i18nc("@action:inmenu Close Other Views", "Close Others") , this);
|
||||
collection->setDefaultShortcut(closeOtherAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_O);
|
||||
closeOtherAction->setEnabled(false);
|
||||
collection->addAction("close-other-views", closeOtherAction);
|
||||
connect(closeOtherAction , &QAction::triggered , this , &Konsole::ViewManager::closeOtherContainers);
|
||||
QAction* closeOtherAction = new QAction(i18nc("@action:inmenu Close Other Views", "Close Others") , this);
|
||||
collection->setDefaultShortcut(closeOtherAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_O);
|
||||
closeOtherAction->setEnabled(false);
|
||||
collection->addAction("close-other-views", closeOtherAction);
|
||||
connect(closeOtherAction , &QAction::triggered , this , &Konsole::ViewManager::closeOtherContainers);
|
||||
|
||||
multiViewOnlyActions << closeOtherAction;
|
||||
multiViewOnlyActions << closeOtherAction;
|
||||
|
||||
// Expand & Shrink Active View
|
||||
QAction* expandActiveAction = new QAction(i18nc("@action:inmenu", "Expand View") , this);
|
||||
collection->setDefaultShortcut(expandActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketRight);
|
||||
expandActiveAction->setEnabled(false);
|
||||
collection->addAction("expand-active-view", expandActiveAction);
|
||||
connect(expandActiveAction , &QAction::triggered , this , &Konsole::ViewManager::expandActiveContainer);
|
||||
// Expand & Shrink Active View
|
||||
QAction* expandActiveAction = new QAction(i18nc("@action:inmenu", "Expand View") , this);
|
||||
collection->setDefaultShortcut(expandActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketRight);
|
||||
expandActiveAction->setEnabled(false);
|
||||
collection->addAction("expand-active-view", expandActiveAction);
|
||||
connect(expandActiveAction , &QAction::triggered , this , &Konsole::ViewManager::expandActiveContainer);
|
||||
|
||||
multiViewOnlyActions << expandActiveAction;
|
||||
multiViewOnlyActions << expandActiveAction;
|
||||
|
||||
QAction* shrinkActiveAction = new QAction(i18nc("@action:inmenu", "Shrink View") , this);
|
||||
collection->setDefaultShortcut(shrinkActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketLeft);
|
||||
shrinkActiveAction->setEnabled(false);
|
||||
collection->addAction("shrink-active-view", shrinkActiveAction);
|
||||
connect(shrinkActiveAction , &QAction::triggered , this , &Konsole::ViewManager::shrinkActiveContainer);
|
||||
QAction* shrinkActiveAction = new QAction(i18nc("@action:inmenu", "Shrink View") , this);
|
||||
collection->setDefaultShortcut(shrinkActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketLeft);
|
||||
shrinkActiveAction->setEnabled(false);
|
||||
collection->addAction("shrink-active-view", shrinkActiveAction);
|
||||
connect(shrinkActiveAction , &QAction::triggered , this , &Konsole::ViewManager::shrinkActiveContainer);
|
||||
|
||||
multiViewOnlyActions << shrinkActiveAction;
|
||||
multiViewOnlyActions << shrinkActiveAction;
|
||||
|
||||
#if defined(ENABLE_DETACHING)
|
||||
QAction* detachViewAction = collection->addAction("detach-view");
|
||||
detachViewAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-detach")));
|
||||
detachViewAction->setText(i18nc("@action:inmenu", "D&etach Current Tab"));
|
||||
// Ctrl+Shift+D is not used as a shortcut by default because it is too close
|
||||
// to Ctrl+D - which will terminate the session in many cases
|
||||
collection->setDefaultShortcut(detachViewAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_H);
|
||||
QAction* detachViewAction = collection->addAction("detach-view");
|
||||
detachViewAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-detach")));
|
||||
detachViewAction->setText(i18nc("@action:inmenu", "D&etach Current Tab"));
|
||||
// Ctrl+Shift+D is not used as a shortcut by default because it is too close
|
||||
// to Ctrl+D - which will terminate the session in many cases
|
||||
collection->setDefaultShortcut(detachViewAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_H);
|
||||
|
||||
connect(this , &Konsole::ViewManager::splitViewToggle , this , &Konsole::ViewManager::updateDetachViewState);
|
||||
connect(detachViewAction , &QAction::triggered , this , &Konsole::ViewManager::detachActiveView);
|
||||
connect(this , &Konsole::ViewManager::splitViewToggle , this , &Konsole::ViewManager::updateDetachViewState);
|
||||
connect(detachViewAction , &QAction::triggered , this , &Konsole::ViewManager::detachActiveView);
|
||||
#endif
|
||||
|
||||
// Next / Previous View , Next Container
|
||||
collection->addAction("next-view", nextViewAction);
|
||||
collection->addAction("previous-view", previousViewAction);
|
||||
collection->addAction("last-tab", lastViewAction);
|
||||
collection->addAction("next-container", nextContainerAction);
|
||||
collection->addAction("move-view-left", moveViewLeftAction);
|
||||
collection->addAction("move-view-right", moveViewRightAction);
|
||||
// Next / Previous View , Next Container
|
||||
collection->addAction("next-view", nextViewAction);
|
||||
collection->addAction("previous-view", previousViewAction);
|
||||
collection->addAction("last-tab", lastViewAction);
|
||||
collection->addAction("next-container", nextContainerAction);
|
||||
collection->addAction("move-view-left", moveViewLeftAction);
|
||||
collection->addAction("move-view-right", moveViewRightAction);
|
||||
|
||||
// Switch to tab N shortcuts
|
||||
const int SWITCH_TO_TAB_COUNT = 19;
|
||||
auto switchToTabMapper = new QSignalMapper(this);
|
||||
connect(switchToTabMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), this, &Konsole::ViewManager::switchToView);
|
||||
for (int i = 0; i < SWITCH_TO_TAB_COUNT; i++) {
|
||||
QAction* switchToTabAction = new QAction(i18nc("@action Shortcut entry", "Switch to Tab %1", i + 1), this);
|
||||
switchToTabMapper->setMapping(switchToTabAction, i);
|
||||
connect(switchToTabAction, &QAction::triggered, switchToTabMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
|
||||
collection->addAction(QString("switch-to-tab-%1").arg(i), switchToTabAction);
|
||||
}
|
||||
// Switch to tab N shortcuts
|
||||
const int SWITCH_TO_TAB_COUNT = 19;
|
||||
auto switchToTabMapper = new QSignalMapper(this);
|
||||
connect(switchToTabMapper, static_cast<void(QSignalMapper::*)(int)>(&QSignalMapper::mapped), this, &Konsole::ViewManager::switchToView);
|
||||
for (int i = 0; i < SWITCH_TO_TAB_COUNT; i++) {
|
||||
QAction* switchToTabAction = new QAction(i18nc("@action Shortcut entry", "Switch to Tab %1", i + 1), this);
|
||||
switchToTabMapper->setMapping(switchToTabAction, i);
|
||||
connect(switchToTabAction, &QAction::triggered, switchToTabMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
|
||||
collection->addAction(QString("switch-to-tab-%1").arg(i), switchToTabAction);
|
||||
}
|
||||
|
||||
foreach(QAction* action, multiViewOnlyActions) {
|
||||
@@ -265,6 +268,7 @@ void ViewManager::switchToView(int index)
|
||||
}
|
||||
void ViewManager::updateDetachViewState()
|
||||
{
|
||||
Q_ASSERT(_actionCollection);
|
||||
if (!_actionCollection)
|
||||
return;
|
||||
|
||||
@@ -667,47 +671,49 @@ void ViewManager::containerMoveViewRequest(int index, int id, bool& moved, Tabbe
|
||||
|
||||
void ViewManager::setNavigationMethod(NavigationMethod method)
|
||||
{
|
||||
Q_ASSERT(_actionCollection);
|
||||
if (!_actionCollection) {
|
||||
return;
|
||||
}
|
||||
_navigationMethod = method;
|
||||
|
||||
KActionCollection* collection = _actionCollection;
|
||||
|
||||
if (collection) {
|
||||
// FIXME: The following disables certain actions for the KPart that it
|
||||
// doesn't actually have a use for, to avoid polluting the action/shortcut
|
||||
// namespace of an application using the KPart (otherwise, a shortcut may
|
||||
// be in use twice, and the user gets to see an "ambiguous shortcut over-
|
||||
// load" error dialog). However, this approach sucks - it's the inverse of
|
||||
// what it should be. Rather than disabling actions not used by the KPart,
|
||||
// a method should be devised to only enable those that are used, perhaps
|
||||
// by using a separate action collection.
|
||||
// FIXME: The following disables certain actions for the KPart that it
|
||||
// doesn't actually have a use for, to avoid polluting the action/shortcut
|
||||
// namespace of an application using the KPart (otherwise, a shortcut may
|
||||
// be in use twice, and the user gets to see an "ambiguous shortcut over-
|
||||
// load" error dialog). However, this approach sucks - it's the inverse of
|
||||
// what it should be. Rather than disabling actions not used by the KPart,
|
||||
// a method should be devised to only enable those that are used, perhaps
|
||||
// by using a separate action collection.
|
||||
|
||||
const bool enable = (_navigationMethod != NoNavigation);
|
||||
QAction* action;
|
||||
const bool enable = (_navigationMethod != NoNavigation);
|
||||
QAction* action;
|
||||
|
||||
action = collection->action("next-view");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("next-view");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("previous-view");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("previous-view");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("last-tab");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("last-tab");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("split-view-left-right");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("split-view-left-right");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("split-view-top-bottom");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("split-view-top-bottom");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("rename-session");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("rename-session");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("move-view-left");
|
||||
if (action) action->setEnabled(enable);
|
||||
action = collection->action("move-view-left");
|
||||
if (action) action->setEnabled(enable);
|
||||
|
||||
action = collection->action("move-view-right");
|
||||
if (action) action->setEnabled(enable);
|
||||
}
|
||||
action = collection->action("move-view-right");
|
||||
if (action) action->setEnabled(enable);
|
||||
}
|
||||
|
||||
ViewManager::NavigationMethod ViewManager::navigationMethod() const
|
||||
|
||||
Reference in New Issue
Block a user