Debian Codegraph @

src/app/qml/dialogs/CreateItemDialog.qml

raw
1 import QtQuick 2.4
2 import Lomiri.Components 1.3
3 import Lomiri.Components.Popups 1.3
4
5 // TODO: Path validation in inputText: disable buttons if new object name is not valid
6 // TODO: Handle failure of mkpath/touch
7
8 Dialog {
9 id: dialog
10
11 property var folderPage
12 property var folderModel
13 property bool folderOnly: false
14
15 title: i18n.tr("Create Item")
16 text: i18n.tr("Enter name for new item")
17
18 TextField {
19 id: inputText
20 placeholderText: i18n.tr("Item name")
21 focus: true
22 }
23
24 Button {
25 id: createFile
26 text: i18n.tr("Create file")
27 color: theme.palette.normal.positive
28 visible: !dialog.folderOnly
29 onClicked: {
30 inputText.focus = false
31 console.log("Create file accepted", inputText.text)
32
33 if (inputText.text !== '') {
34 var fileName = inputText.text.trim()
35 if (folderModel.touch(fileName)) {
36 folderPage.tooltipMsg = i18n.tr("Created file '%1'").arg(inputText.text)
37 }
38 } else {
39 console.log("Empty file name, ignored")
40 }
41
42 PopupUtils.close(dialog)
43 }
44 }
45
46 Button {
47 id: createFolder
48 text: i18n.tr("Create Folder")
49 color: dialog.folderOnly ? theme.palette.normal.positive : theme.palette.normal.base
50 onClicked: {
51 inputText.focus = false
52 console.log("Create folder accepted", inputText.text)
53 if (inputText.text !== '') {
54 var folderName = inputText.text.trim()
55 if (folderModel.mkdir(folderName)) {
56 folderPage.tooltipMsg = i18n.tr("Created folder '%1'").arg(inputText.text)
57 }
58 } else {
59 console.log("Empty directory name, ignored")
60 }
61 PopupUtils.close(dialog)
62 }
63 }
64
65 Button {
66 id: cancelButton
67 text: i18n.tr("Cancel")
68 onClicked: {
69 PopupUtils.close(dialog)
70 }
71 }
72 }