From 3bcd26b6ae02e01bc00a16ef28c74daa36811113 Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Wed, 28 Sep 2022 12:50:15 +0200 Subject: [PATCH] fix(@desktop/general): Fix sections switching shortcuts Ctrl+n shortcut changes enabled section. Fix #7478 --- src/app/modules/main/module.nim | 1 - src/app/modules/main/view.nim | 4 ++ .../modules/shared_models/section_model.nim | 11 +++++ ui/app/mainui/AppMain.qml | 49 +++++++++++++++++-- ui/imports/utils/Global.qml | 6 +++ 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 7c4102e198..722a4c2b30 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -575,7 +575,6 @@ method setActiveSection*[T](self: Module[T], item: SectionItem) = if(item.isEmpty()): echo "section is empty and cannot be made as active one" return - self.controller.setActiveSection(item.id) proc notifySubModulesAboutChange[T](self: Module[T], sectionId: string) = diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 1800fa9d93..2cad930cb3 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -145,6 +145,10 @@ QtObject: self.activeSection.setActiveSectionData(item) self.activeSectionChanged() + proc setNthEnabledSectionActive*(self: View, nth: int) {.slot.} = + let item = self.model.getNthEnabledItem(nth) + self.delegate.setActiveSection(item) + proc setActiveSectionById*(self: View, sectionId: string) {.slot.} = let item = self.model.getItemById(sectionId) self.delegate.setActiveSection(item) diff --git a/src/app/modules/shared_models/section_model.nim b/src/app/modules/shared_models/section_model.nim index 2c8eddb295..74436f0d40 100644 --- a/src/app/modules/shared_models/section_model.nim +++ b/src/app/modules/shared_models/section_model.nim @@ -280,6 +280,17 @@ QtObject: ModelRole.BannedMembersModel.int ]) + proc getNthEnabledItem*(self: SectionModel, nth: int): SectionItem = + if nth >= 0 and nth < self.items.len: + var counter = 0 + for i in 0 ..< self.items.len: + if self.items[i].enabled: + if counter == nth: + return self.items[i] + else: + counter = counter + 1 + return SectionItem() + proc getItemById*(self: SectionModel, id: string): SectionItem = for it in self.items: if(it.id == id): diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 846767f6b7..c8e46da5a4 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -1027,20 +1027,59 @@ Item { Action { shortcut: "Ctrl+1" - onTriggered: Global.changeAppSectionBySectionType(Constants.appSection.chat) + onTriggered: { + Global.setNthEnabledSectionActive(0) + } } Action { shortcut: "Ctrl+2" - onTriggered: Global.changeAppSectionBySectionType(Constants.appSection.browser) + onTriggered: { + Global.setNthEnabledSectionActive(1) + } } Action { shortcut: "Ctrl+3" - onTriggered: Global.changeAppSectionBySectionType(Constants.appSection.wallet) + onTriggered: { + Global.setNthEnabledSectionActive(2) + } } Action { - shortcut: "Ctrl+4, Ctrl+," - onTriggered: Global.changeAppSectionBySectionType(Constants.appSection.profile) + shortcut: "Ctrl+4" + onTriggered: { + Global.setNthEnabledSectionActive(3) + } } + Action { + shortcut: "Ctrl+5" + onTriggered: { + Global.setNthEnabledSectionActive(4) + } + } + Action { + shortcut: "Ctrl+6" + onTriggered: { + Global.setNthEnabledSectionActive(5) + } + } + Action { + shortcut: "Ctrl+7" + onTriggered: { + Global.setNthEnabledSectionActive(6) + } + } + Action { + shortcut: "Ctrl+8" + onTriggered: { + Global.setNthEnabledSectionActive(7) + } + } + Action { + shortcut: "Ctrl+9" + onTriggered: { + Global.setNthEnabledSectionActive(8) + } + } + Action { shortcut: "Ctrl+K" onTriggered: { diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index 518ab04fb3..3a407ef452 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -69,6 +69,12 @@ QtObject { } } + function setNthEnabledSectionActive(nthSection) { + if(!root.mainModuleInst) + return + mainModuleInst.setNthEnabledSectionActive(nthSection) + } + function getProfileImage(pubkey, isCurrentUser, useLargeImage) { if (isCurrentUser || (isCurrentUser === undefined && pubkey === userProfile.pubKey)) { return userProfile.icon;