Warning, /office/klevernotes/src/contents/ui/sideBar/Sidebar.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 /*
0005 * BASED ON :
0006 * https://invent.kde.org/graphics/koko/-/blob/master/src/qml/Sidebar.qml
0007 * 2017 Atul Sharma <atulsharma406@gmail.com>
0008 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0009 */
0010
0011 import QtQuick 2.15
0012 import QtQuick.Layouts 1.3
0013 import QtQuick.Controls 2.15 as Controls
0014
0015 import org.kde.kirigamiaddons.delegates 1.0 as Delegates
0016 import org.kde.kirigami 2.5 as Kirigami
0017
0018 import org.kde.Klever 1.0
0019
0020 Kirigami.OverlayDrawer {
0021 id: drawer
0022
0023 readonly property NoteMapper noteMapper: applicationWindow().noteMapper
0024 readonly property NoteTreeModel treeModel: treeview.model
0025 readonly property string storagePath: Config.storagePath
0026
0027 width: Kirigami.Units.gridUnit * 15
0028
0029 leftPadding: 0
0030 rightPadding: 0
0031 topPadding: 0
0032 bottomPadding: 0
0033
0034 edge: Qt.application.layoutDirection == Qt.RightToLeft ? Qt.RightEdge : Qt.LeftEdge
0035 handleClosedIcon.source: null
0036 handleOpenIcon.source: null
0037 handleVisible: applicationWindow().isMainPage() && modal
0038
0039 modal: Kirigami.Settings.isMobile
0040 // Prevent it to being close while in wideScreen
0041 closePolicy: modal ? Controls.Popup.CloseOnReleaseOutside : Controls.Popup.NoAutoClose
0042
0043 contentItem: ColumnLayout {
0044 id: column
0045
0046 ActionBar {
0047 id: actionBar
0048
0049 treeView: treeview
0050
0051 Layout.fillWidth: true
0052 Layout.preferredHeight: pageStack.globalToolBar.preferredHeight
0053 }
0054
0055 TreeView {
0056 id: treeview
0057
0058 model: NoteTreeModel {
0059 id: noteTreeModel
0060
0061 noteMapEnabled: Config.noteMapEnabled
0062
0063 onNewGlobalPathFound: function (path) {
0064 drawer.noteMapper.addGlobalPath(path)
0065 }
0066 onGlobalPathUpdated: function (oldPath, newPath) {
0067 drawer.noteMapper.updateGlobalPath(oldPath, newPath)
0068 }
0069 onGlobalPathRemoved: function (path) {
0070 drawer.noteMapper.removeGlobalPath(path)
0071 }
0072 onInitialGlobalPathsSent: function (initialGlobalPaths) {
0073 drawer.noteMapper.addInitialGlobalPaths(initialGlobalPaths)
0074 }
0075 onErrorOccurred: function (errorMessage) {
0076 applicationWindow().showPassiveNotification(errorMessage)
0077 }
0078 }
0079
0080 Layout.fillWidth: true
0081 Layout.fillHeight: true
0082
0083 onItemRightClicked: function (clickedItem) {
0084 const tempModelIndex = treeview.getModelIndex(clickedItem.index)
0085 actionBar.setClickedItemInfo(clickedItem, tempModelIndex)
0086 }
0087 onCurrentItemChanged: {
0088 const currentModelIndex = treeview.getModelIndex(treeview.currentIndex)
0089 actionBar.setClickedItemInfo(treeview.currentItem, currentModelIndex)
0090 }
0091 }
0092
0093 Controls.ToolSeparator {
0094 orientation: Qt.Horizontal
0095
0096 Layout.fillWidth: true
0097 }
0098
0099 Delegates.RoundedItemDelegate {
0100 text: i18n("Cheat sheet")
0101 icon.name: "text-markdown"
0102
0103 Layout.fillWidth: true
0104
0105 onClicked: {
0106 applicationWindow().showCheatSheet()
0107 if (drawer.modal) drawer.close()
0108 }
0109 }
0110
0111 Delegates.RoundedItemDelegate {
0112 text: i18n("Settings")
0113 icon.name: "settings-configure"
0114
0115 Layout.fillWidth: true
0116
0117 onClicked: {
0118 applicationWindow().switchToPage('Settings')
0119 }
0120 }
0121
0122 Delegates.RoundedItemDelegate {
0123 text: i18n("About KleverNotes")
0124 icon.name: "help-about"
0125
0126 Layout.fillWidth: true
0127
0128 onClicked: {
0129 applicationWindow().switchToPage('About')
0130 }
0131 }
0132 }
0133
0134 onStoragePathChanged: if (storagePath !== "None") {
0135 noteTreeModel.initModel()
0136 }
0137 Component.onCompleted: {
0138 if (storagePath === "None"){
0139 let component = Qt.createComponent("qrc:/contents/ui/dialogs/StorageDialog.qml")
0140
0141 if (component.status == Component.Ready) {
0142 var dialog = component.createObject(applicationWindow());
0143 dialog.open()
0144 }
0145 }
0146 }
0147
0148 ContextMenu {
0149 id: contextMenu
0150
0151 treeView: treeview
0152 actionBar: actionBar
0153 }
0154
0155 Timer {
0156 id: focusTimer
0157
0158 property var focusModelIndex
0159
0160 repeat: false
0161 interval: Kirigami.Units.shortDuration
0162
0163 onTriggered: if (focusModelIndex) {
0164 focusModelIndex.model.askForFocus(focusModelIndex)
0165 focusModelIndex = undefined
0166 }
0167 }
0168
0169 Timer {
0170 id: timer
0171
0172 property var modelIndex
0173
0174 repeat: false
0175 interval: Kirigami.Units.shortDuration
0176
0177 onTriggered: if (modelIndex) {
0178 modelIndex.model.askForExpand(modelIndex)
0179 modelIndex = undefined
0180 interval = Kirigami.Units.shortDuration
0181 focusTimer.start()
0182 }
0183 }
0184
0185 function askForFocus(modelIndex) {
0186 let parentRowsList = []
0187 let currentModelIndex = modelIndex
0188 while (currentModelIndex.parent.row !== -1) {
0189 const nextModelIndex = currentModelIndex.parent
0190 parentRowsList.push(nextModelIndex)
0191 currentModelIndex = nextModelIndex
0192 }
0193
0194 const firstModelIndex = parentRowsList[parentRowsList.length - 1]
0195
0196 firstModelIndex.model.askForExpand(firstModelIndex)
0197 // This might be the exact same as "firstModelIndex" but is still needed for Category notes
0198 timer.modelIndex = parentRowsList[0]
0199 timer.start()
0200
0201 focusTimer.focusModelIndex = modelIndex
0202 }
0203 }