Warning, /office/klevernotes/src/contents/ui/sideBar/ActionBar.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Louis Schul <schul9louis@gmail.com>
0003
0004 import QtQuick 2.15
0005 import QtQuick.Controls 2.15
0006 import QtQuick.Layouts 1.15
0007 import QtQuick.Dialogs
0008
0009 import org.kde.kitemmodels 1.0
0010 import org.kde.kirigami 2.19 as Kirigami
0011
0012 import org.kde.Klever 1.0
0013
0014 import "qrc:/contents/ui/dialogs"
0015
0016 ToolBar {
0017 id: mainToolBar
0018
0019 required property TreeView treeView
0020 readonly property QtObject renameAction: renameAction
0021 readonly property QtObject createNoteAction: createNoteAction
0022 readonly property QtObject createGroupAction: createGroupAction
0023 readonly property QtObject createCategoryAction: createCategoryAction
0024
0025 property var currentModelIndex
0026 property var currentClickedItem
0027
0028 NamingDialog {
0029 id: namingDialog
0030
0031 onRejected: {
0032 useCurrentItem()
0033 }
0034 }
0035
0036 RowLayout {
0037 id: barLayout
0038
0039 property bool searching: false
0040
0041 anchors.fill: parent
0042 spacing: 0
0043
0044 ToolButton {
0045 action: createCategoryAction
0046 visible: !barLayout.searching
0047 ToolTip.delay: Kirigami.Units.toolTipDelay
0048 ToolTip.visible: hovered
0049 ToolTip.text: i18nc("as in 'A note category'", "Create a new category") + " (" + createCategoryAction.shortcut + ")"
0050 }
0051
0052 ToolButton {
0053 action: createGroupAction
0054 visible: !barLayout.searching
0055 ToolTip.delay: Kirigami.Units.toolTipDelay
0056 ToolTip.visible: hovered
0057 ToolTip.text: i18nc("as in 'A note group'", "Create a new group") + " (" + createGroupAction.shortcut + ")"
0058 }
0059
0060 ToolButton {
0061 action: createNoteAction
0062 visible: !barLayout.searching
0063 ToolTip.delay: Kirigami.Units.toolTipDelay
0064 ToolTip.visible: hovered
0065 ToolTip.text: i18nc("as in 'A note'", "Create a new note") + " (" + createNoteAction.shortcut + ")"
0066 }
0067
0068 ToolButton {
0069 action: renameAction
0070 visible: !barLayout.searching
0071 ToolTip.delay: Kirigami.Units.toolTipDelay
0072 ToolTip.visible: hovered
0073 ToolTip.text: i18n("Rename") + " (" + renameAction.shortcut + ")"
0074 }
0075
0076 Item {Layout.fillWidth: true; visible: !barLayout.searching}
0077
0078 ToolButton {
0079 visible: !barLayout.searching
0080 icon.name: "search-symbolic"
0081 onClicked: {
0082 barLayout.searching = true
0083 searchBar.contentItem.forceActiveFocus()
0084 }
0085 }
0086
0087 SearchBar {
0088 id: searchBar
0089
0090 visible: barLayout.searching
0091 listModel: treeview.model
0092
0093 Layout.fillWidth: true
0094
0095 popup.onClosed: {
0096 barLayout.searching = false
0097 text = ""
0098 }
0099 onClickedIndexChanged: if (clickedIndex) {
0100 applicationWindow().globalDrawer.askForFocus(clickedIndex)
0101 searchBar.popup.close()
0102 return;
0103 }
0104 }
0105 }
0106
0107 Kirigami.Action {
0108 id: createCategoryAction
0109
0110 property string name
0111 property bool isActive : false
0112
0113 shortcut: "Ctrl+Alt+C"
0114 icon.name: "journal-new"
0115
0116 onNameChanged: if (isActive) {
0117 treeView.model.addRow(name, Config.storagePath, 1)
0118 isActive = false
0119 name = ""
0120 useCurrentItem()
0121 }
0122 onTriggered: {
0123 isActive = true
0124 const objectName = Config.defaultCategoryName
0125 mainToolBar.getName("Category", objectName, Config.storagePath, createCategoryAction, true)
0126 }
0127 }
0128
0129 Kirigami.Action {
0130 id: createGroupAction
0131
0132 property string name
0133 property string categoryPath
0134 property var parentModelIndex
0135 property bool isActive : false
0136
0137 shortcut: "Ctrl+Alt+G"
0138 icon.name: "folder-new"
0139
0140 onNameChanged: if (isActive) {
0141 treeView.model.addRow(name, categoryPath, 2, parentModelIndex)
0142 isActive = false
0143 name = ""
0144 useCurrentItem()
0145 }
0146 onTriggered: {
0147 isActive = true
0148
0149 switch(mainToolBar.currentClickedItem.useCase) {
0150 case "Category":
0151 categoryPath = mainToolBar.currentClickedItem.path
0152 parentModelIndex = currentModelIndex
0153 break;
0154 case "Group":
0155 categoryPath = KleverUtility.getParentPath(mainToolBar.currentClickedItem.path)
0156
0157 parentModelIndex = treeView.model.parent(currentModelIndex)
0158 break;
0159 case "Note":
0160 const groupPath = KleverUtility.getParentPath(mainToolBar.currentClickedItem.path)
0161 categoryPath = KleverUtility.getParentPath(groupPath)
0162
0163 if (groupPath.endsWith(".BaseGroup")) {
0164 parentModelIndex = treeView.model.parent(currentModelIndex)
0165 } else {
0166 const groupModelIndex = treeView.model.parent(currentModelIndex)
0167 parentModelIndex = treeView.model.parent(groupModelIndex)
0168 }
0169 break;
0170 }
0171 const objectName = Config.defaultGroupName
0172 mainToolBar.getName("Group", objectName, categoryPath, createGroupAction, true)
0173 }
0174 }
0175
0176 Kirigami.Action {
0177 id: createNoteAction
0178
0179 property string name
0180 property string groupPath
0181 property var parentModelIndex
0182 property bool isActive : false
0183
0184 shortcut: "Ctrl+Alt+N"
0185 icon.name: "document-new"
0186
0187 onNameChanged: if (isActive) {
0188 treeView.model.addRow(name, groupPath, 3, parentModelIndex)
0189 isActive = false
0190 name = ""
0191 useCurrentItem()
0192 }
0193 onTriggered: {
0194 isActive = true
0195
0196 switch(mainToolBar.currentClickedItem.useCase) {
0197 case "Category":
0198 groupPath = mainToolBar.currentClickedItem.path+"/.BaseGroup"
0199 parentModelIndex = currentModelIndex
0200 break;
0201 case "Group":
0202 groupPath = mainToolBar.currentClickedItem.path
0203 parentModelIndex = currentModelIndex
0204 break;
0205 case "Note":
0206 groupPath = KleverUtility.getParentPath(mainToolBar.currentClickedItem.path)
0207 parentModelIndex = treeView.model.parent(currentModelIndex)
0208 break;
0209 }
0210 const shownName = Config.defaultNoteName
0211
0212 mainToolBar.getName("Note", shownName, groupPath, createNoteAction, true)
0213 }
0214 }
0215
0216 Kirigami.Action{
0217 id: renameAction
0218
0219 property bool isActive: false
0220 property string name: mainToolBar.currentClickedItem ? mainToolBar.currentClickedItem.text : ""
0221
0222 shortcut: "Ctrl+R"
0223 icon.name: "edit-rename"
0224
0225 onNameChanged: if (isActive) {
0226 treeView.model.rename(currentModelIndex, name)
0227 isActive = false
0228 useCurrentItem()
0229 }
0230 onTriggered: {
0231 isActive = true
0232
0233 const useCase = mainToolBar.currentClickedItem.useCase
0234 const parentPath = KleverUtility.getParentPath(mainToolBar.currentClickedItem.path)
0235 mainToolBar.getName(useCase, name, parentPath, renameAction, false)
0236 }
0237 }
0238
0239 function getName(useCase, shownName, parentPath, callingAction, newItem){
0240 namingDialog.useCase = useCase
0241 namingDialog.shownName = shownName
0242 namingDialog.textFieldText = shownName
0243 namingDialog.parentPath = parentPath
0244 namingDialog.callingAction = callingAction
0245 namingDialog.newItem = newItem
0246 namingDialog.open()
0247 }
0248
0249 function setClickedItemInfo(clickedItem, clickedModelIndex) {
0250 currentClickedItem = clickedItem
0251 currentModelIndex = clickedModelIndex
0252 }
0253
0254 function useCurrentItem() {
0255 const currentModelIndex = treeView.getModelIndex(treeView.currentIndex)
0256 setClickedItemInfo(treeView.currentItem, currentModelIndex)
0257 }
0258 }