fix: show error dialog and reset name when rename fails
commitRename now checks the return value from renameSession/renameAgent. On failure, resets displayName to the old value and shows an error dialog explaining the rename failed (e.g., name already in use).
This commit is contained in:
parent
0c47e1163a
commit
22a2208526
35
gui/main.qml
35
gui/main.qml
|
|
@ -168,16 +168,27 @@ ApplicationWindow {
|
|||
if (renamingIndex < 0) return
|
||||
var item = sessionTreeModel.get(renamingIndex)
|
||||
var newName = renamingText.trim()
|
||||
if (newName !== "" && newName !== item.displayName) {
|
||||
var oldName = item.displayName
|
||||
if (newName !== "" && newName !== oldName) {
|
||||
var success = false
|
||||
if (item.type === "session") {
|
||||
if (ollie.renameSession(item.id, newName)) {
|
||||
success = ollie.renameSession(item.id, newName)
|
||||
if (success) {
|
||||
sessionTreeModel.set(renamingIndex, { id: newName, displayName: newName })
|
||||
}
|
||||
} else if (item.type === "agent") {
|
||||
if (ollie.renameAgent(item.parentId, item.agentId, newName)) {
|
||||
success = ollie.renameAgent(item.parentId, item.agentId, newName)
|
||||
if (success) {
|
||||
sessionTreeModel.set(renamingIndex, { agentId: newName, displayName: newName })
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
// Reset to old name and show error
|
||||
sessionTreeModel.set(renamingIndex, { displayName: oldName })
|
||||
renameErrorDialog.itemType = item.type
|
||||
renameErrorDialog.attemptedName = newName
|
||||
renameErrorDialog.open()
|
||||
}
|
||||
}
|
||||
renamingIndex = -1
|
||||
renamingText = ""
|
||||
|
|
@ -242,6 +253,24 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
// --- Rename Error Dialog ---
|
||||
Dialog {
|
||||
id: renameErrorDialog
|
||||
title: "Rename Failed"
|
||||
anchors.centerIn: parent
|
||||
width: 320
|
||||
modal: true
|
||||
standardButtons: Dialog.Ok
|
||||
|
||||
property string itemType: "session"
|
||||
property string attemptedName: ""
|
||||
|
||||
contentItem: Label {
|
||||
text: "Could not rename " + renameErrorDialog.itemType + " to \"" + renameErrorDialog.attemptedName + "\".\n\nThe name may already be in use."
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
}
|
||||
|
||||
// --- Settings Dialog ---
|
||||
Dialog {
|
||||
id: settingsDialog
|
||||
|
|
|
|||
Reference in New Issue