-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFolderViewCreateDialog.qml
More file actions
135 lines (116 loc) · 3.85 KB
/
FolderViewCreateDialog.qml
File metadata and controls
135 lines (116 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import QtQuick
import QtQuick.Controls
import Quickshell
import qs.Common
import qs.Widgets
import qs.Services
import "./dms-common"
Popup {
id: createDialog
width: 260
height: 156
padding: 0
modal: false
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
x: parent ? Math.round((parent.width - width) / 2) : 0
y: parent ? Math.round((parent.height - height) / 2) : 0
property string targetFolderUrl: ""
property bool isFolder: true
property var inputField: null
onOpened: {
Qt.callLater(() => {
if (createDialog.inputField) {
createDialog.inputField.forceActiveFocus();
createDialog.inputField.selectAll();
}
});
}
background: Rectangle {
color: "transparent"
}
contentItem: Rectangle {
color: Theme.surfaceContainer
radius: Theme.cornerRadius
border.color: Theme.withAlpha(Theme.outline, 0.15)
border.width: 1
Column {
anchors.fill: parent
anchors.margins: Theme.spacingM
spacing: Theme.spacingS
StyledText {
text: createDialog.isFolder ? I18n.tr("New Folder") : I18n.tr("New Document")
font.bold: true
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
}
Row {
width: parent.width
spacing: Theme.spacingS
DankTextField {
id: createField
width: parent.width
placeholderText: createDialog.isFolder ? I18n.tr("Folder name...") : I18n.tr("File name...")
focus: true
onAccepted: createDialog.performCreate()
Component.onCompleted: {
createDialog.inputField = createField;
}
}
}
Row {
width: parent.width
spacing: Theme.spacingS
layoutDirection: Qt.RightToLeft
DankButton {
text: I18n.tr("Create")
backgroundColor: Theme.primary
textColor: Theme.primaryText
onClicked: createDialog.performCreate()
}
DankButton {
text: I18n.tr("Cancel")
backgroundColor: Theme.surfaceContainerHigh
textColor: Theme.surfaceText
onClicked: createDialog.close()
}
}
}
}
function showFor(folderOnly) {
createDialog.isFolder = !!folderOnly;
if (createDialog.inputField) {
createDialog.inputField.text = createDialog.isFolder ? "New Folder" : "New Document.txt";
}
createDialog.open();
}
function performCreate() {
if (!createDialog.inputField) {
createDialog.close();
return;
}
const name = createDialog.inputField.text.trim();
if (name.length === 0) {
createDialog.close();
return;
}
let pathStr = String(createDialog.targetFolderUrl);
if (pathStr.startsWith("file://")) {
pathStr = pathStr.substring(7);
}
if (pathStr.startsWith("localhost/")) {
pathStr = pathStr.substring(9);
}
const targetPath = pathStr + "/" + name;
try {
if (createDialog.isFolder) {
Quickshell.execDetached(["mkdir", "-p", targetPath]);
} else {
Quickshell.execDetached(["touch", targetPath]);
}
} catch (e) {
ToastService.showToast("Create error: " + e.message, ToastService.levelError);
}
createDialog.close();
}
}