add shortcuts for tab navigation in ViewSplit

This commit is contained in:
Le Tan 2021-06-02 22:04:30 +08:00
parent 79abddd802
commit 1f3b00ee44
7 changed files with 218 additions and 11 deletions

@ -1 +1 @@
Subproject commit 5e02a011cb7e4979e897c0670fe8ac8f1060feb4
Subproject commit 32678afe91f4ad15acb4f4d24d92e1fa61bb1df7

View File

@ -38,6 +38,18 @@ namespace vnotex
Quit,
FlashPage,
QuickAccess,
ActivateTab1,
ActivateTab2,
ActivateTab3,
ActivateTab4,
ActivateTab5,
ActivateTab6,
ActivateTab7,
ActivateTab8,
ActivateTab9,
AlternateTab,
ActivateNextTab,
ActivatePreviousTab,
MaxShortcut
};
Q_ENUM(Shortcut)
@ -70,6 +82,8 @@ namespace vnotex
void setRecoverLastSessionOnStartEnabled(bool p_enabled);
private:
friend class MainConfig;
void loadShortcuts(const QJsonObject &p_app, const QJsonObject &p_user);
void loadNoteManagement(const QJsonObject &p_app, const QJsonObject &p_user);

View File

@ -117,4 +117,10 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
void MainConfig::doVersionSpecificOverride()
{
// In a new version, we may want to change one value by force.
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::NavigationDock] = "Ctrl+G, A";
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::OutlineDock] = "Ctrl+G, U";
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::SearchDock] = "Ctrl+G, S";
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::LocationListDock] = "Ctrl+G, L";
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::NewWorkspace] = "Ctrl+G, M";
m_coreConfig->writeToSettings();
}

View File

@ -15,10 +15,10 @@
"Settings" : "Ctrl+Alt+P",
"NewNote" : "Ctrl+Alt+N",
"CloseTab" : "Ctrl+G, X",
"NavigationDock" : "Ctrl+G, 1",
"OutlineDock" : "Ctrl+G, 2",
"SearchDock" : "Ctrl+G, 3",
"LocationListDock" : "Ctrl+G, 4",
"NavigationDock" : "Ctrl+G, A",
"OutlineDock" : "Ctrl+G, U",
"SearchDock" : "Ctrl+G, S",
"LocationListDock" : "Ctrl+G, L",
"Search" : "Ctrl+Alt+F",
"NavigationMode" : "Ctrl+G, W",
"LocateNode" : "Ctrl+G, D",
@ -27,11 +27,23 @@
"MaximizeSplit" : "Ctrl+G, Shift+\\",
"DistributeSplits" : "Ctrl+G, =",
"RemoveSplitAndWorkspace" : "Ctrl+G, R",
"NewWorkspace" : "Ctrl+G, N",
"NewWorkspace" : "Ctrl+G, M",
"Export" : "Ctrl+G, T",
"Quit" : "Ctrl+Q",
"FlashPage" : "Ctrl+Alt+L",
"QuickAccess" : "Ctrl+Alt+I"
"QuickAccess" : "Ctrl+Alt+I",
"ActivateTab1" : "Ctrl+G, 1",
"ActivateTab2" : "Ctrl+G, 2",
"ActivateTab3" : "Ctrl+G, 3",
"ActivateTab4" : "Ctrl+G, 4",
"ActivateTab5" : "Ctrl+G, 5",
"ActivateTab6" : "Ctrl+G, 6",
"ActivateTab7" : "Ctrl+G, 7",
"ActivateTab8" : "Ctrl+G, 8",
"ActivateTab9" : "Ctrl+G, 9",
"AlternateTab" : "Ctrl+G, 0",
"ActivateNextTab" : "Ctrl+G, N",
"ActivatePreviousTab" : "Ctrl+G, P"
},
"toolbar_icon_size" : 16,
"note_management" : {

View File

@ -103,6 +103,9 @@ void ViewSplit::focusCurrentViewWindow()
} else {
setFocus();
}
m_lastViewWindow = m_currentViewWindow;
m_currentViewWindow = win;
}
void ViewSplit::setupCornerWidget()
@ -407,7 +410,7 @@ void ViewSplit::updateWindowList(QMenu *p_menu)
int cnt = getViewWindowCount();
if (cnt == 0) {
// Add a dummy entry.
auto act = p_menu->addAction(tr("No window to show here"));
auto act = p_menu->addAction(tr("No Window To Show"));
act->setEnabled(false);
return;
}
@ -742,6 +745,136 @@ void ViewSplit::setupShortcuts()
});
}
}
// ActivateTab1.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab1), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(0);
});
}
}
// ActivateTab2.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab2), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(1);
});
}
}
// ActivateTab3.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab3), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(2);
});
}
}
// ActivateTab4.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab4), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(3);
});
}
}
// ActivateTab5.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab5), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(4);
});
}
}
// ActivateTab6.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab6), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(5);
});
}
}
// ActivateTab7.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab7), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(6);
});
}
}
// ActivateTab8.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab8), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(7);
});
}
}
// ActivateTab9.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateTab9), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
setCurrentViewWindow(8);
});
}
}
// AlternateTab.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::AlternateTab), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, &ViewSplit::alternateTab);
}
}
// ActivateNextTab.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivateNextTab), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
activateNextTab(false);
});
}
}
// ActivatePreviousTab.
{
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::ActivatePreviousTab), this, Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this]() {
activateNextTab(true);
});
}
}
}
void ViewSplit::focus()
@ -759,3 +892,40 @@ void ViewSplit::setCurrentViewWindow(int p_idx)
auto win = getViewWindow(p_idx);
setCurrentViewWindow(win);
}
void ViewSplit::alternateTab()
{
if (!m_lastViewWindow) {
return;
}
// It is fine even when m_lastViewWindow is a wild pointer. The implementation will just
// compare its value without dereferencing it.
if (-1 != indexOf(m_lastViewWindow)) {
setCurrentViewWindow(m_lastViewWindow);
} else {
m_lastViewWindow = nullptr;
}
}
void ViewSplit::activateNextTab(bool p_backward)
{
int idx = currentIndex();
if (idx == -1 || count() == 1) {
return;
}
if (p_backward) {
--idx;
if (idx < 0) {
idx = count() - 1;
}
} else {
++idx;
if (idx >= count()) {
idx = 0;
}
}
setCurrentViewWindow(idx);
}

View File

@ -129,6 +129,10 @@ namespace vnotex
void focusCurrentViewWindow();
void alternateTab();
void activateNextTab(bool p_backward);
ID m_id = 0;
const QVector<QSharedPointer<ViewWorkspace>> &m_allWorkspaces;
@ -143,6 +147,10 @@ namespace vnotex
QActionGroup *m_workspaceActionGroup = nullptr;
// Used for AlternateTab.
ViewWindow *m_currentViewWindow = nullptr;
ViewWindow *m_lastViewWindow = nullptr;
static QIcon s_windowListIcon;
static QIcon s_windowListActiveIcon;

View File

@ -180,14 +180,11 @@ void ViewWindow::detachFromBuffer(bool p_quiet)
QIcon ViewWindow::getIcon() const
{
/*
if (m_buffer) {
return m_buffer->isModified() ? s_modifiedIcon : s_savedIcon;
} else {
return s_savedIcon;
}
*/
return QIcon();
}
QString ViewWindow::getName() const