Changeset View
Changeset View
Standalone View
Standalone View
src/dolphinmainwindow.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | |||||
88 | #include <QWhatsThisClickedEvent> | 88 | #include <QWhatsThisClickedEvent> | ||
89 | 89 | | |||
90 | namespace { | 90 | namespace { | ||
91 | // Used for GeneralSettings::version() to determine whether | 91 | // Used for GeneralSettings::version() to determine whether | ||
92 | // an updated version of Dolphin is running. | 92 | // an updated version of Dolphin is running. | ||
93 | const int CurrentDolphinVersion = 200; | 93 | const int CurrentDolphinVersion = 200; | ||
94 | // The maximum number of entries in the back/forward popup menu | 94 | // The maximum number of entries in the back/forward popup menu | ||
95 | const int MaxNumberOfNavigationentries = 12; | 95 | const int MaxNumberOfNavigationentries = 12; | ||
96 | // The maximum number of "Activate Tab" shortcuts | ||||
97 | const int MaxActivateTabShortcuts = 9; | ||||
96 | } | 98 | } | ||
97 | 99 | | |||
98 | DolphinMainWindow::DolphinMainWindow() : | 100 | DolphinMainWindow::DolphinMainWindow() : | ||
99 | KXmlGuiWindow(nullptr), | 101 | KXmlGuiWindow(nullptr), | ||
100 | m_newFileMenu(nullptr), | 102 | m_newFileMenu(nullptr), | ||
101 | m_helpMenu(nullptr), | 103 | m_helpMenu(nullptr), | ||
102 | m_tabWidget(nullptr), | 104 | m_tabWidget(nullptr), | ||
103 | m_activeViewContainer(nullptr), | 105 | m_activeViewContainer(nullptr), | ||
▲ Show 20 Lines • Show All 1069 Lines • ▼ Show 20 Line(s) | 1144 | { | |||
1173 | 1175 | | |||
1174 | const QUrl url = viewContainer->url(); | 1176 | const QUrl url = viewContainer->url(); | ||
1175 | emit urlChanged(url); | 1177 | emit urlChanged(url); | ||
1176 | } | 1178 | } | ||
1177 | 1179 | | |||
1178 | void DolphinMainWindow::tabCountChanged(int count) | 1180 | void DolphinMainWindow::tabCountChanged(int count) | ||
1179 | { | 1181 | { | ||
1180 | const bool enableTabActions = (count > 1); | 1182 | const bool enableTabActions = (count > 1); | ||
1183 | for (int i = 0; i < MaxActivateTabShortcuts; ++i) { | ||||
1184 | actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions); | ||||
1185 | } | ||||
1186 | actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions); | ||||
1181 | actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); | 1187 | actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); | ||
1182 | actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); | 1188 | actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); | ||
1183 | } | 1189 | } | ||
1184 | 1190 | | |||
1185 | void DolphinMainWindow::updateWindowTitle() | 1191 | void DolphinMainWindow::updateWindowTitle() | ||
1186 | { | 1192 | { | ||
1187 | const QString newTitle = m_activeViewContainer->caption(); | 1193 | const QString newTitle = m_activeViewContainer->caption(); | ||
1188 | if (windowTitle() != newTitle) { | 1194 | if (windowTitle() != newTitle) { | ||
▲ Show 20 Lines • Show All 309 Lines • ▼ Show 20 Line(s) | 1478 | #endif | |||
1498 | 1504 | | |||
1499 | // not in menu actions | 1505 | // not in menu actions | ||
1500 | QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext(); | 1506 | QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext(); | ||
1501 | nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab)); | 1507 | nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab)); | ||
1502 | 1508 | | |||
1503 | QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev(); | 1509 | QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev(); | ||
1504 | prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab)); | 1510 | prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab)); | ||
1505 | 1511 | | |||
1512 | for (int i = 0; i < MaxActivateTabShortcuts; ++i) { | ||||
1513 | QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i)); | ||||
1514 | activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1)); | ||||
1515 | activateTab->setEnabled(false); | ||||
1516 | connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); }); | ||||
1517 | | ||||
1518 | // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts | ||||
meven: Simplier written with one check instead of two (i is < MaxActivateTabShortcuts) :
```
int… | |||||
The issue with doing that is that if MaxActivateTabShortcuts ever gets changed to anything higher than 10, then there would be extra calls to try to set shortcuts like Alt + 11. Even when changing that else to an else if, you would still have to add another check somehow to make sure you're not calling setDefaultShortcut when i > 10. alexmi: The issue with doing that is that if MaxActivateTabShortcuts ever gets changed to anything… | |||||
meven: Fair enough I didn't get MaxActivateTabShortcuts could be changed. | |||||
1519 | if (i < 9) { | ||||
1520 | actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1)); | ||||
1521 | } | ||||
1522 | } | ||||
1523 | | ||||
1524 | QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab")); | ||||
1525 | activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab")); | ||||
1526 | activateLastTab->setEnabled(false); | ||||
1527 | connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab); | ||||
1528 | actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT + Qt::Key_0); | ||||
1529 | | ||||
1506 | QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); | 1530 | QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); | ||
1507 | activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); | 1531 | activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); | ||
1508 | activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); | 1532 | activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); | ||
1509 | activateNextTab->setEnabled(false); | 1533 | activateNextTab->setEnabled(false); | ||
1510 | connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab); | 1534 | connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab); | ||
1511 | actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys); | 1535 | actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys); | ||
1512 | 1536 | | |||
1513 | QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab")); | 1537 | QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab")); | ||
▲ Show 20 Lines • Show All 711 Lines • Show Last 20 Lines |
Simplier written with one check instead of two (i is < MaxActivateTabShortcuts) :