Skip to content

Commit 9947191

Browse files
committed
GUI: add CommandHelper#delete
1 parent 05fd896 commit 9947191

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

desktop-gui/compose/src/main/kotlin/view/CommandHelper.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ fun commandHelper() {
7171
item { cmdHeader() }
7272

7373
items(itemList.size) { i ->
74-
commandItem(itemList[i])
74+
commandItem(itemList[i]) {
75+
if (it) {
76+
itemList.removeAt(i)
77+
}
78+
}
7579
}
7680
}
7781

@@ -97,6 +101,13 @@ fun storeCommand() {
97101
G_REQUEST.readEvents({},{ _, j ->})
98102
}
99103

104+
fun delCommand(id: String) {
105+
G_REQUEST.runTool(Tools.Helper, mapOf(
106+
"del" to id
107+
))
108+
G_REQUEST.readEvents({},{ _, j ->})
109+
}
110+
100111
fun editCommand(item: CommandItem) {
101112
G_REQUEST.runTool(Tools.Helper, mapOf(
102113
"add" to "${item.id} ${item.cmd} ${item.tags?.joinToString(separator = " ") }"
@@ -115,7 +126,7 @@ fun searchCommand(items: MutableList<CommandItem>, query: String) {
115126

116127
@Composable
117128
@Preview
118-
fun commandItem(cmd: CommandItem) {
129+
fun commandItem(cmd: CommandItem, action: (Boolean) -> Unit) {
119130
var isEditing by remember { mutableStateOf(false) }
120131

121132
var id by remember { mutableStateOf(cmd.id) }
@@ -188,6 +199,15 @@ fun commandItem(cmd: CommandItem) {
188199
) {
189200
Text(if (isEditing) "Save" else "Edit")
190201
}
202+
Button(
203+
onClick = {
204+
delCommand(cmd.id)
205+
action(true)
206+
},
207+
modifier = Modifier.padding(8.dp)
208+
) {
209+
Text("Delete")
210+
}
191211
}
192212
grayDivider()
193213
}

0 commit comments

Comments
 (0)