Warning, /maui/mauikit-filebrowsing/src/controls.5/FileDialog.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2018 Camilo Higuita <milo.h@aol.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Library General Public License as 0006 * published by the Free Software Foundation; either version 2, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details 0013 * 0014 * You should have received a copy of the GNU Library General Public 0015 * License along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 import QtQuick 2.14 0021 import QtQml 2.14 0022 0023 import QtQuick.Controls 2.14 0024 import QtQuick.Layouts 1.3 0025 0026 import org.mauikit.controls 1.3 as Maui 0027 import org.mauikit.filebrowsing 1.3 as FB 0028 0029 /** 0030 * FileDialog 0031 * A file dialog to quickly open or save files. 0032 * 0033 * This component makes use of the FileBrowser. 0034 * 0035 * The FileDialog can be in two modes, one for Opening and other for Saving files. 0036 * 0037 * The file dialog allows to have multiple or single selection, 0038 * and filtering content specific to a file type or arbitrary name filters. 0039 * 0040 */ 0041 Maui.PopupPage 0042 { 0043 id: control 0044 0045 maxHeight: Maui.Handy.isMobile ? parent.height * 0.95 : 500 0046 maxWidth: 700 0047 0048 hint: 1 0049 0050 page.padding: 0 0051 closeButtonVisible: false 0052 headBar.visible: false 0053 0054 /** 0055 * currentPath : url 0056 * The current path of the directory URL. 0057 * To list a directory path, or other location, use the right schemas, 0058 * some of them are file://, webdav://, trash:///, tags:// 0059 */ 0060 property alias currentPath : browser.currentPath 0061 0062 /** 0063 * browser : FileBrowser 0064 * The FileBrowser used to listing. 0065 * For more details on how it works check its documentation. 0066 */ 0067 readonly property alias browser : browser 0068 0069 /** 0070 * selectionBar : SelectionBar 0071 */ 0072 readonly property alias selectionBar: _selectionBar 0073 0074 /** 0075 * singleSelection : bool 0076 * If true then only one item can be selected, either for saving or for opening. 0077 */ 0078 property alias singleSelection : _selectionBar.singleSelection 0079 0080 /** 0081 * suggestedFileName : string 0082 * On save mode a text field is visible and this property is used to assign its default text value. 0083 */ 0084 property string suggestedFileName : "" 0085 0086 /** 0087 * settings : BrowserSettings 0088 * A group of properties for controlling the sorting, listing and behaviour of the file browser. 0089 * For more details check the BrowserSettings documentation. 0090 */ 0091 readonly property alias settings : browser.settings 0092 0093 /** 0094 * searchBar : bool 0095 * Show the search bar to enter a search query. 0096 */ 0097 property bool searchBar : false 0098 onSearchBarChanged: if(!searchBar) browser.quitSearch() 0099 0100 /** 0101 * modes : var 0102 * There are two modes: Save : 1, to save files with a given file name or 0103 * Open : 0 to open one or multiple files. 0104 */ 0105 readonly property var modes : ({OPEN: 0, SAVE: 1}) 0106 0107 /** 0108 * mode : int 0109 * The current mode in use. By default the Open : 0 mode is used. 0110 */ 0111 property int mode : modes.OPEN 0112 0113 property var callback 0114 0115 /** 0116 * textField : TextField 0117 * On Save mode a text field is visible, this property gives access to it. 0118 */ 0119 property alias textField: _textField 0120 0121 /** 0122 * urlsSelected : 0123 * Triggered once the urls have been selected. 0124 */ 0125 signal urlsSelected(var urls) 0126 0127 /** 0128 * finished : 0129 * The selection has been done 0130 */ 0131 signal finished(var urls) 0132 0133 actions: [ 0134 Action 0135 { 0136 Layout.fillWidth: true 0137 text: i18nd("mauikitfilebrowsing", "Cancel") 0138 onTriggered: control.close() 0139 }, 0140 0141 Action 0142 { 0143 Layout.fillWidth: true 0144 text: control.mode === modes.SAVE ? i18nd("mauikitfilebrowsing", "Save") : i18nd("mauikitfilebrowsing", "Open") 0145 onTriggered: 0146 { 0147 console.log("CURRENT PATHb", browser.currentPath+"/"+textField.text) 0148 0149 if(control.mode === modes.SAVE && textField.text.length === 0) 0150 return 0151 0152 if(control.mode === modes.SAVE && FB.FM.fileExists(browser.currentPath+"/"+textField.text)) 0153 { 0154 _confirmationDialog.open() 0155 }else 0156 { 0157 done() 0158 } 0159 } 0160 } 0161 ] 0162 0163 page.footerColumn: [ 0164 0165 Maui.ToolBar 0166 { 0167 visible: control.mode === modes.SAVE 0168 width: parent.width 0169 position: ToolBar.Footer 0170 0171 middleContent: TextField 0172 { 0173 id: _textField 0174 Layout.fillWidth: true 0175 placeholderText: i18nd("mauikitfilebrowsing", "File name...") 0176 text: suggestedFileName 0177 } 0178 } 0179 ] 0180 0181 Maui.InfoDialog 0182 { 0183 id: _confirmationDialog 0184 0185 title: i18nd("mauikitfilebrowsing", "Error") 0186 message: i18nd("mauikitfilebrowsing", "A file named '%1' already exists!\n This action will overwrite '%1'. Are you sure you want to do this?", control.textField.text) 0187 template.iconSource: "dialog-warning" 0188 0189 standardButtons: Dialog.Ok | Dialog.Cancel 0190 0191 onAccepted: control.done() 0192 onRejected: close() 0193 } 0194 0195 stack: Maui.SideBarView 0196 { 0197 id: pageRow 0198 0199 Layout.fillHeight: true 0200 Layout.fillWidth: true 0201 0202 sideBar.preferredWidth: 200 0203 sideBar.minimumWidth: 200 0204 sideBarContent: Loader 0205 { 0206 asynchronous: true 0207 anchors.fill: parent 0208 sourceComponent: FB.PlacesListBrowser 0209 { 0210 onPlaceClicked: 0211 { 0212 //pageRow.currentIndex = 1 0213 browser.openFolder(path) 0214 } 0215 0216 currentPath: browser.currentPath 0217 0218 list.groups: [ 0219 FB.FMList.BOOKMARKS_PATH, 0220 FB.FMList.REMOTE_PATH, 0221 FB.FMList.CLOUD_PATH, 0222 FB.FMList.DRIVES_PATH] 0223 } 0224 } 0225 0226 Maui.Page 0227 { 0228 id: _browserLayout 0229 anchors.fill: parent 0230 0231 floatingFooter: true 0232 flickable: browser.flickable 0233 headBar.visible: true 0234 headerColorSet: Maui.Theme.Header 0235 headBar.farLeftContent: ToolButton 0236 { 0237 icon.name: pageRow.sideBar.visible ? "sidebar-collapse" : "sidebar-expand" 0238 onClicked: pageRow.sideBar.toggle() 0239 checked: pageRow.sideBar.visible 0240 ToolTip.delay: 1000 0241 ToolTip.timeout: 5000 0242 ToolTip.visible: hovered 0243 ToolTip.text: i18nd("mauikitfilebrowsing", "Toogle SideBar") 0244 } 0245 0246 headBar.rightContent:[ 0247 0248 ToolButton 0249 { 0250 id: searchButton 0251 icon.name: "edit-find" 0252 onClicked: browser.toggleSearchBar() 0253 checked: browser.headBar.visible 0254 }, 0255 0256 Loader 0257 { 0258 asynchronous: true 0259 sourceComponent: Maui.ToolButtonMenu 0260 { 0261 icon.name: browser.settings.viewType === FB.FMList.LIST_VIEW ? "view-list-details" : "view-list-icons" 0262 0263 Maui.MenuItemActionRow 0264 { 0265 Action 0266 { 0267 icon.name: "view-hidden" 0268 // text: i18nd("mauikitfilebrowsing", "Hidden Files") 0269 checkable: true 0270 checked: settings.showHiddenFiles 0271 onTriggered: settings.showHiddenFiles = !settings.showHiddenFiles 0272 } 0273 0274 Action 0275 { 0276 icon.name: "folder-new" 0277 onTriggered: browser.newItem() 0278 } 0279 } 0280 0281 Maui.LabelDelegate 0282 { 0283 width: parent.width 0284 isSection: true 0285 label: i18nd("mauikitfilebrowsing", "View type") 0286 } 0287 0288 Action 0289 { 0290 text: i18nd("mauikitfilebrowsing", "List") 0291 icon.name: "view-list-details" 0292 checked: browser.settings.viewType === FB.FMList.LIST_VIEW 0293 checkable: true 0294 onTriggered: 0295 { 0296 if(browser) 0297 { 0298 browser.settings.viewType = FB.FMList.LIST_VIEW 0299 } 0300 } 0301 } 0302 0303 Action 0304 { 0305 text: i18nd("mauikitfilebrowsing", "Grid") 0306 icon.name: "view-list-icons" 0307 checked: browser.settings.viewType === FB.FMList.ICON_VIEW 0308 checkable: true 0309 0310 onTriggered: 0311 { 0312 if(browser) 0313 { 0314 browser.settings.viewType = FB.FMList.ICON_VIEW 0315 } 0316 } 0317 } 0318 0319 MenuSeparator {} 0320 0321 Maui.LabelDelegate 0322 { 0323 width: parent.width 0324 isSection: true 0325 label: i18nd("mauikitfilebrowsing", "Sort by") 0326 } 0327 0328 Action 0329 { 0330 text: i18nd("mauikitfilebrowsing", "Type") 0331 checked: browser.settings.sortBy === FB.FMList.MIME 0332 checkable: true 0333 0334 onTriggered: 0335 { 0336 browser.settings.sortBy = FB.FMList.MIME 0337 } 0338 } 0339 0340 Action 0341 { 0342 text: i18nd("mauikitfilebrowsing", "Date") 0343 checked: browser.settings.sortBy === FB.FMList.DATE 0344 checkable: true 0345 0346 onTriggered: 0347 { 0348 browser.settings.sortBy = FB.FMList.DATE 0349 } 0350 } 0351 0352 Action 0353 { 0354 text: i18nd("mauikitfilebrowsing", "Modified") 0355 checked: browser.settings.sortBy === FB.FMList.MODIFIED 0356 checkable: true 0357 0358 onTriggered: 0359 { 0360 browser.settings.sortBy = FB.FMList.MODIFIED 0361 } 0362 } 0363 0364 Action 0365 { 0366 text: i18nd("mauikitfilebrowsing", "Size") 0367 checked: browser.settings.sortBy === FB.FMList.SIZE 0368 checkable: true 0369 0370 onTriggered: 0371 { 0372 browser.settings.sortBy = FB.FMList.SIZE 0373 } 0374 } 0375 0376 Action 0377 { 0378 text: i18nd("mauikitfilebrowsing", "Name") 0379 checked: browser.settings.sortBy === FB.FMList.LABEL 0380 checkable: true 0381 0382 onTriggered: 0383 { 0384 browser.settings.sortBy = FB.FMList.LABEL 0385 } 0386 } 0387 0388 MenuSeparator{} 0389 0390 MenuItem 0391 { 0392 text: i18nd("mauikitfilebrowsing", "Show Folders First") 0393 checked: browser.settings.foldersFirst 0394 checkable: true 0395 0396 onTriggered: 0397 { 0398 browser.settings.foldersFirst = !browser.settings.foldersFirst 0399 } 0400 } 0401 0402 MenuItem 0403 { 0404 id: groupAction 0405 text: i18nd("mauikitfilebrowsing", "Group") 0406 checkable: true 0407 checked: browser.settings.group 0408 onTriggered: 0409 { 0410 browser.settings.group = !browser.settings.group 0411 } 0412 } 0413 } 0414 } 0415 ] 0416 0417 headBar.leftContent: Loader 0418 { 0419 asynchronous: true 0420 sourceComponent: Maui.ToolActions 0421 { 0422 expanded: true 0423 autoExclusive: false 0424 checkable: false 0425 0426 Action 0427 { 0428 icon.name: "go-previous" 0429 onTriggered : browser.goBack() 0430 } 0431 0432 Action 0433 { 0434 icon.name: "go-up" 0435 onTriggered : browser.goUp() 0436 } 0437 0438 Action 0439 { 0440 icon.name: "go-next" 0441 onTriggered: browser.goNext() 0442 } 0443 } 0444 } 0445 0446 0447 footer: Maui.SelectionBar 0448 { 0449 id: _selectionBar 0450 0451 anchors.horizontalCenter: parent.horizontalCenter 0452 width: Math.min(parent.width-(Maui.Style.space.medium*2), implicitWidth) 0453 maxListHeight: control.height - (Maui.Style.contentMargins*2) 0454 0455 listDelegate: Maui.ListBrowserDelegate 0456 { 0457 width: ListView.view.width 0458 iconSource: model.icon 0459 imageSource: model.thumbnail 0460 label1.text: model.label 0461 label2.text: model.url 0462 } 0463 0464 onExitClicked: 0465 { 0466 _selectionBar.clear() 0467 } 0468 } 0469 0470 FB.FileBrowser 0471 { 0472 id: browser 0473 anchors.fill: parent 0474 0475 selectionBar: _selectionBar 0476 settings.viewType: FB.FMList.LIST_VIEW 0477 currentPath: FB.FM.homePath() 0478 selectionMode: control.mode === modes.OPEN 0479 onItemClicked: 0480 { 0481 if(Maui.Handy.singleClick) 0482 { 0483 performAction(index) 0484 } 0485 } 0486 0487 onItemDoubleClicked: 0488 { 0489 if(!Maui.Handy.singleClick) 0490 { 0491 performAction(index) 0492 } 0493 } 0494 0495 function performAction(index) 0496 { 0497 if(currentFMModel.get(index).isdir == "true") 0498 { 0499 openItem(index) 0500 } 0501 0502 switch(control.mode) 0503 { 0504 case modes.OPEN : 0505 addToSelection(currentFMModel.get(index)) 0506 break; 0507 0508 case modes.SAVE: 0509 textField.text = currentFMModel.get(index).label 0510 break; 0511 } 0512 } 0513 } 0514 } 0515 } 0516 0517 0518 /** 0519 * 0520 */ 0521 function closeIt() 0522 { 0523 _selectionBar.clear() 0524 control.close() 0525 } 0526 0527 /** 0528 * 0529 */ 0530 function done() 0531 { 0532 var paths = browser.selectionBar && browser.selectionBar.visible ? browser.selectionBar.uris : [browser.currentPath] 0533 0534 if(control.mode === modes.SAVE) 0535 { 0536 for(var i in paths) 0537 { 0538 paths[i] = paths[i] + "/" + textField.text 0539 } 0540 0541 // _tagsBar.list.urls = paths 0542 // _tagsBar.list.updateToUrls(_tagsBar.getTags()) 0543 } 0544 0545 control.finished(paths) 0546 0547 // if(control.mode === modes.SAVE) //do it after finished in cas ethe files need to be saved aka exists, before tryign to insert tags 0548 // { 0549 // _tagsBar.list.urls = paths 0550 // _tagsBar.list.updateToUrls(_tagsBar.getTags()) 0551 // } 0552 0553 if(control.callback) 0554 { 0555 control.callback(paths) 0556 } 0557 0558 control.urlsSelected(paths) 0559 control.closeIt() 0560 } 0561 }