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, Qt::WindowContextHelpButtonHint), | 101 | KXmlGuiWindow(nullptr, Qt::WindowContextHelpButtonHint), | ||
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 1066 Lines • ▼ Show 20 Line(s) | 1141 | { | |||
1170 | 1172 | | |||
1171 | const QUrl url = viewContainer->url(); | 1173 | const QUrl url = viewContainer->url(); | ||
1172 | emit urlChanged(url); | 1174 | emit urlChanged(url); | ||
1173 | } | 1175 | } | ||
1174 | 1176 | | |||
1175 | void DolphinMainWindow::tabCountChanged(int count) | 1177 | void DolphinMainWindow::tabCountChanged(int count) | ||
1176 | { | 1178 | { | ||
1177 | const bool enableTabActions = (count > 1); | 1179 | const bool enableTabActions = (count > 1); | ||
1180 | for (int i = 0; i < MaxActivateTabShortcuts; ++i) { | ||||
1181 | actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions); | ||||
1182 | } | ||||
1183 | actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions); | ||||
1178 | actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); | 1184 | actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); | ||
1179 | actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); | 1185 | actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); | ||
1180 | } | 1186 | } | ||
1181 | 1187 | | |||
1182 | void DolphinMainWindow::updateWindowTitle() | 1188 | void DolphinMainWindow::updateWindowTitle() | ||
1183 | { | 1189 | { | ||
1184 | const QString newTitle = m_activeViewContainer->caption(); | 1190 | const QString newTitle = m_activeViewContainer->caption(); | ||
1185 | if (windowTitle() != newTitle) { | 1191 | if (windowTitle() != newTitle) { | ||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Line(s) | 1473 | #endif | |||
1493 | 1499 | | |||
1494 | // not in menu actions | 1500 | // not in menu actions | ||
1495 | QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext(); | 1501 | QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext(); | ||
1496 | nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab)); | 1502 | nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab)); | ||
1497 | 1503 | | |||
1498 | QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev(); | 1504 | QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev(); | ||
1499 | prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab)); | 1505 | prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab)); | ||
1500 | 1506 | | |||
1507 | for (int i = 0; i < MaxActivateTabShortcuts; ++i) { | ||||
1508 | QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i)); | ||||
1509 | activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1)); | ||||
1510 | activateTab->setEnabled(false); | ||||
1511 | connect(activateTab, &QAction::triggered, this, [this, i] () { m_tabWidget->activateTab(i); } ); | ||||
1512 | | ||||
1513 | // 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. | |||||
1514 | if (i < 9) { | ||||
1515 | actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1)); | ||||
1516 | } | ||||
1517 | } | ||||
1518 | | ||||
1519 | QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab")); | ||||
1520 | activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab")); | ||||
1521 | activateLastTab->setEnabled(false); | ||||
1522 | connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab); | ||||
1523 | actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT + Qt::Key_0); | ||||
1524 | | ||||
1501 | QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); | 1525 | QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); | ||
1502 | activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); | 1526 | activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); | ||
1503 | activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); | 1527 | activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); | ||
1504 | activateNextTab->setEnabled(false); | 1528 | activateNextTab->setEnabled(false); | ||
1505 | connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab); | 1529 | connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab); | ||
1506 | actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys); | 1530 | actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys); | ||
1507 | 1531 | | |||
1508 | QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab")); | 1532 | 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) :