Warning, /maui/bonsai/src/main.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.15
0003 import QtQuick.Layouts 1.12
0004 
0005 import org.mauikit.controls 1.3 as Maui
0006 import org.mauikit.filebrowsing 1.3 as FB
0007 import org.maui.bonsai 1.0 as Bonsai
0008 
0009 import "views"
0010 
0011 Maui.ApplicationWindow
0012 {
0013     id: root
0014 
0015     property alias dialog : _dialogLoader.item
0016     property alias fmDialog : _fmDialogLoader.item
0017 
0018     Bonsai.ProjectManager
0019     {
0020         id: _projectManager
0021     }
0022 
0023     Component
0024     {
0025         id: _cloneDialogComponent
0026 
0027         CloneDialog {}
0028     }
0029 
0030     Loader
0031     {
0032         id: _dialogLoader
0033     }
0034 
0035     Loader
0036     {
0037         id: _fmDialogLoader
0038     }
0039 
0040     Component
0041     {
0042         id: _settingsDialogComponent
0043 
0044         SettingsDialog  {}
0045     }
0046 
0047     Component
0048     {
0049         id: _openFileDialogComponent
0050 
0051         FB.FileDialog  {}
0052     }
0053 
0054     Component
0055     {
0056         id: _browserViewComponent
0057         BrowserView
0058         {
0059             id: _browserView
0060             headBar.leftContent: ToolButton
0061             {
0062                 icon.name: "go-previous"
0063                 onClicked: _mainStackView.pop()
0064             }
0065 
0066             Keys.enabled: true
0067             Keys.onEscapePressed: _mainStackView.pop()
0068         }
0069     }
0070 
0071     Component
0072     {
0073         id: _projectPageComponent
0074 
0075         ProjectView {}
0076     }
0077 
0078     Action
0079     {
0080         id: _recentAction
0081         icon.name: "shallow-history"
0082         text: i18n("Recent")
0083 
0084         onTriggered:
0085         {
0086             _mainStackView.push(_browserViewComponent)
0087         }
0088     }
0089 
0090     Action
0091     {
0092         id: _cloneAction
0093         icon.name: "vcs-merge"
0094         text: i18n("Clone")
0095         onTriggered:
0096         {
0097             _dialogLoader.sourceComponent = _cloneDialogComponent
0098             dialog.open()
0099         }
0100     }
0101 
0102     Action
0103     {
0104 
0105         id: _newAction
0106         icon.name: "folder-new"
0107         text: i18n("Create")
0108 
0109     }
0110 
0111     Action
0112     {
0113 
0114         id: _openAction
0115         icon.name: "document-open"
0116         text: i18n("Open")
0117 
0118         onTriggered: openLocalRepo()
0119     }
0120 
0121     StackView
0122     {
0123         id: _mainStackView
0124         anchors.fill: parent
0125 
0126         initialItem: Maui.TabView
0127         {
0128             id: _tabView
0129             holder.title : i18n("Let's Start")
0130             holder.body: i18n("Open or clone an existing repository, or create a new one.")
0131             holder.emoji: "qrc:/assets/assets/folder-add.svg"
0132 
0133             holder.actions:[  _recentAction, _cloneAction, _openAction, _newAction ]
0134 
0135             tabBar.visible: true
0136             tabBar.showNewTabButton: false
0137 
0138             tabBar.rightContent: [
0139                 Maui.ToolButtonMenu
0140                 {
0141                     icon.name: "list-add"
0142 
0143 
0144                     MenuItem
0145                     {
0146                         action: _recentAction
0147                     }
0148 
0149                     MenuItem
0150                     {
0151                         action: _cloneAction
0152 
0153                     }
0154 
0155                     MenuItem
0156                     {
0157                         action: _newAction
0158                     }
0159 
0160                     MenuItem
0161                     {
0162                         action: _openAction
0163                     }
0164 
0165                     MenuSeparator {}
0166 
0167                     MenuItem
0168                     {
0169                         text: i18n("Settings")
0170                         icon.name: "settings-configure"
0171                         onTriggered: openConfigDialog()
0172                     }
0173 
0174                     MenuItem
0175                     {
0176                         text: i18n("About")
0177                         icon.name: "documentinfo"
0178                         onTriggered: root.about()
0179                     }
0180                 },
0181 
0182                 Maui.WindowControls {}
0183             ]
0184         }
0185     }
0186 
0187     function openLocalRepo()
0188     {
0189         _fmDialogLoader.sourceComponent = _openFileDialogComponent
0190         fmDialog.singleSelection = true
0191         fmDialog.callback = function(paths)
0192         {
0193 
0194             for(var path of paths)
0195                 openProject(path)
0196         }
0197 
0198         fmDialog.open()
0199     }
0200 
0201     function openProject(url, remote)
0202     {
0203         const index = tabIndex(url)
0204         if(index > -1)
0205         {
0206             _tabView.setCurrentIndex(index)
0207             return
0208         }
0209 
0210         //        _projectManager.addProject(url)
0211         console.log("OPEN PROJECT", url, remote)
0212 
0213         var obj = _tabView.addTab(_projectPageComponent, {'url' : url})
0214 
0215         if(remote)
0216             obj.project.clone(remote)
0217 
0218         if(_mainStackView.depth === 2)
0219         {
0220             _mainStackView.pop()
0221         }
0222     }
0223 
0224     function tabIndex(path) //find the tab index for a path
0225     {
0226         if(path.length === 0)
0227         {
0228             return -1
0229         }
0230 
0231         for(var i = 0; i < _tabView.count; i++)
0232         {
0233             const tab =  _tabView.contentModel.get(i)
0234             console.log("FIN TAB INDEX", i, tab.url, path)
0235             if(tab.url === path)
0236             {
0237                 return i
0238             }
0239         }
0240         return -1
0241     }
0242 
0243     function openConfigDialog()
0244     {
0245         _dialogLoader.sourceComponent = _settingsDialogComponent
0246         dialog.open()
0247     }
0248 }