Warning, /maui/nota/src/views/widgets/DocsBrowser.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 import QtQuick.Layouts 1.3
0004 
0005 import org.mauikit.controls 1.3 as Maui
0006 import org.mauikit.filebrowsing 1.3 as FB
0007 
0008 Maui.AltBrowser
0009 {
0010     id: control
0011 
0012     enableLassoSelection: true
0013 
0014     gridView.itemSize: Math.min(200, Math.max(100, Math.floor(width* 0.3)))
0015     gridView.itemHeight: gridView.itemSize + Maui.Style.rowHeight
0016 
0017     viewType: root.isWide ? Maui.AltBrowser.ViewType.Grid : Maui.AltBrowser.ViewType.List
0018 
0019     property alias menu : _menu
0020 
0021     ItemMenu
0022     {
0023         id: _menu
0024         index: control.currentIndex
0025         model: control.model
0026     }
0027 
0028     Connections
0029     {
0030         target: control.currentView
0031         function onItemsSelected(indexes)
0032         {
0033             for(var i in indexes)
0034             {
0035                 const item =  control.model.get(indexes[i])
0036                 addToSelection(item)
0037             }
0038         }
0039 
0040         function onKeyPress(event)
0041         {
0042             const index = control.currentIndex
0043             const item = control.model.get(index)
0044 
0045             if((event.key == Qt.Key_Left || event.key == Qt.Key_Right || event.key == Qt.Key_Down || event.key == Qt.Key_Up) && (event.modifiers & Qt.ControlModifier) && (event.modifiers & Qt.ShiftModifier))
0046             {
0047                 control.currentView.itemsSelected([index])
0048             }
0049 
0050             if(event.key === Qt.Key_Return)
0051             {
0052                 editorView.openTab(item.path)
0053             }
0054 
0055             if(event.key === Qt.Key_Escape)
0056             {
0057                 control.StackView.view.pop()
0058             }
0059         }
0060     }
0061 
0062     headBar.middleContent: Maui.SearchField
0063     {
0064         Layout.fillWidth: true
0065         Layout.maximumWidth: 500
0066         Layout.alignment: Qt.AlignCenter
0067         placeholderText: i18n("Filter...")
0068         onAccepted: control.model.filter = text
0069         onCleared:  control.model.filter = text
0070     }
0071 
0072     gridDelegate: Item
0073     {
0074         height: GridView.view.cellHeight
0075         width: GridView.view.cellWidth
0076 
0077         Maui.GridBrowserDelegate
0078         {
0079             id: _gridItemDelegate
0080 
0081             template.imageWidth: control.gridView.itemSize
0082             template.imageHeight: control.gridView.itemSize
0083 
0084             anchors.margins: Maui.Handy.isMobile ? Maui.Style.space.small : Maui.Style.space.medium
0085             anchors.fill: parent
0086 
0087             draggable: true
0088             Drag.keys: ["text/uri-list"]
0089 
0090             Drag.mimeData: Drag.active ?
0091                                {
0092                                    "text/uri-list": control.filterSelectedItems(model.path)
0093                                } : {}
0094 
0095 
0096             isCurrentItem: parent.GridView.isCurrentItem || checked
0097             label1.text: model.label
0098             imageSource: model.thumbnail
0099             iconSource: model.icon
0100             template.fillMode: Image.PreserveAspectFit
0101             iconSizeHint: height * 0.6
0102             checkable: control.selectionMode
0103             checked: _selectionbar.contains(model.path)
0104             onToggled: addToSelection(model)
0105 
0106             Connections
0107             {
0108                 target: _selectionbar
0109                 function onUriRemoved(uri)
0110                 {
0111                     if(uri === model.path)
0112                         _gridItemDelegate.checked = false
0113                 }
0114 
0115                 function onUriAdded(uri)
0116                 {
0117                     if(uri === model.path)
0118                         _gridItemDelegate.checked = true
0119                 }
0120 
0121                 function onCleared()
0122                 {
0123                     _gridItemDelegate.checked = false
0124                 }
0125             }
0126 
0127             onClicked:
0128             {
0129                 control.currentIndex = index
0130                 if(root.selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)))
0131                 {
0132                     addToSelection(model)
0133 
0134                 }else if(Maui.Handy.singleClick)
0135                 {
0136                     editorView.openTab(model.path)
0137                 }
0138             }
0139 
0140             onDoubleClicked:
0141             {
0142                 control.currentIndex = index
0143                 if(!Maui.Handy.singleClick && !root.selectionMode)
0144                 {
0145                     editorView.openTab(model.path)
0146                 }
0147             }
0148 
0149             onRightClicked:
0150             {
0151                 control.currentIndex = index
0152                 _menu.show()
0153             }
0154 
0155             onPressAndHold:
0156             {
0157                 control.currentIndex = index
0158                 _menu.show()
0159             }
0160         }
0161     }
0162 
0163     listDelegate: Maui.ListBrowserDelegate
0164     {
0165         id: _listDelegate
0166 
0167         isCurrentItem: ListView.isCurrentItem || checked
0168 
0169         height: Maui.Style.rowHeight *1.5
0170         width: ListView.view.width
0171         draggable: true
0172         Drag.keys: ["text/uri-list"]
0173         Drag.mimeData: Drag.active ?
0174                            {
0175                                "text/uri-list": control.filterSelectedItems(model.path)
0176                            } : {}
0177 
0178     label1.text: model.label
0179     label2.text: model.path
0180     label3.text: Maui.Handy.formatDate(model.modified, "MM/dd/yyyy")
0181     label4.text: model.mime
0182     iconSource: model.icon
0183     iconSizeHint: Maui.Style.iconSizes.medium
0184     checkable: control.selectionMode
0185     checked: _selectionbar.contains(model.path)
0186     onToggled: addToSelection(model)
0187 
0188     Connections
0189     {
0190         target: _selectionbar
0191         function onUriRemoved(uri)
0192         {
0193             if(uri === model.path)
0194                 _listDelegate.checked = false
0195         }
0196 
0197         function onUriAdded(uri)
0198         {
0199             if(uri === model.path)
0200                 _listDelegate.checked = true
0201         }
0202 
0203         function onCleared()
0204         {
0205             _listDelegate.checked = false
0206         }
0207     }
0208 
0209     onClicked:
0210     {
0211         control.currentIndex = index
0212         if(root.selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)))
0213         {
0214             addToSelection(model)
0215 
0216         }else if(Maui.Handy.singleClick)
0217         {
0218             editorView.openTab(model.path)
0219         }
0220     }
0221 
0222     onDoubleClicked:
0223     {
0224         control.currentIndex = index
0225         if(!Maui.Handy.singleClick && !root.selectionMode)
0226         {
0227             editorView.openTab(model.path)
0228         }
0229     }
0230 
0231     onRightClicked:
0232     {
0233         control.currentIndex = index
0234         _menu.show()
0235     }
0236 
0237     onPressAndHold:
0238     {
0239         control.currentIndex = index
0240         _menu.show()
0241     }
0242 }
0243 
0244 function filterSelectedItems(path)
0245 {
0246     if(_selectionbar && _selectionbar.count > 0 && _selectionbar.contains(path))
0247     {
0248         const uris = _selectionbar.uris
0249         return uris.join("\n")
0250     }
0251 
0252     return path
0253 }
0254 }