diff --git a/gui/main.qml b/gui/main.qml index e71477a..131fe75 100644 --- a/gui/main.qml +++ b/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