I guess most folks has at least a few blank areas where they struggle and mine is definitely Associative Arrays In my defence I have to say what im trying to do here is quite intricate to begin with and Im coming up short. Im building an Undo feature in my GUI, where stuff like for example Undo Renaming of files and Undo copying files can be done. I have it working quite nicely, but there is a big drawback. There is no Undo queue, which implies only one Undo of the last action can be done. In comparison the shell for example queues up the Undo actions and you're abled to Undo as many actions you done since starting up the App. Replicate that is certainly no easy action or requires a big brain which seem to be in the freezer in my case
So my thought was to have an UndoQueue associative array where the keys gets values from different arrays. When Undo is executed only the last added Key with values should be undone. If the UndoQueue contains other Undos (not executed yet) that one should be Undone next upon an Undo execution and so on. Im struggeling with how to sequence the keys to accomplish that. Maybe it's not possible doing it like that?
The second problem is how to retrieve the values from the UnRenameArray inside the UndoQueue AssocArray back to their original variables from an Object point of view, in order to do the actual Undo Rename?
So here is what I've got so far
Code: Select all
#NoEnv
; Create Associative Array UndoQueue
UndoQueue := {}
;-------------------------
; Undo renaming stuff
UndoOldName := "F:\10.jpg"
UndoNewName := "F:\555.jpg"
UndoOldID := "12447688"
UndoFileNameNoPath := "10.jpg"
UnRenameArray := [UndoOldName, UndoNewName, UndoOldID, UndoFileNameNoPath]
;-------------------------
; Undo copy stuff
UnCopyArray := []
UndoList=
(
F:\0.jpg
F:\888.jpg
)
UndoPath := "F:\TV" ; UndoList gets copied/pasted to UndoPath and gets deleted from there in case of an Undo
Loop, Parse, UndoList, `n, `r
{
SplitPath, A_LoopField, UndoFilename
UndoListCopy := UndoPath "\" UndoFilename ; Path swap for copied files
UnCopyArray.Push(UndoListCopy) ; Put the copied files in the UnCopyArray
}
;-------------------------
UndoNameChange := True
UndoCopy := True
;-------------------------
If (UndoNameChange) {
If (UnRenameArray.Length() = 0) ; If no files in UnRenameArray key no action
msgbox % "No Files in UnRenameArray"
Else { ; UnRenameArray has content
For Each, File in UnRenameArray {
UndoQueue[UnRenameArray, "UndoFile"] := File
UndoQueue[File] := {UnRenameArray: UndoFile}
UndoFile := UndoQueue[UnRenameArray, "UndoFile"]
msgbox % "UnRenameArrayFiles= " UndoFile
; How would one go about to get the values back into thier original variables?
; Restore the old filename here
/*
If TVCache[UndoOldID, "IsDir"] { ; folder
DropEffect := 4 ; FO_RENAME SHFileOperation
SHFileOperation_Internal([UndoNewName], UndoOldName, DropEffect)
TV_Modify(UndoOldID, , UndoFileNameNoPath) ; Remove renamed file from TV if opened in other player
}
Else { ; file
DropEffect := 4 ; FO_RENAME SHFileOperation
SHFileOperation_Internal([UndoNewName], UndoOldName, DropEffect)
TV_Modify(UndoOldID, , UndoFileNameNoPath) ; Remove renamed file from TV if opened in other player
}
*/
;UndoQueue.Delete(UnRenameArray) ; If Undo gets executed from context menu, UnRenameArray values gets deleted (same deal upon TV reload,
;but there all keys are emptied). The Undo menu item gets disabled if no other UndoQueue key has content.
;msgbox % UndoFile " files in UnMoveArray has been deleted"
UndoNameChange := False
}
}
}
;-------------------------
If (UndoCopy) {
If (UnCopyArray.Length() = 0) ; If no files in UnCopyArray key no action
msgbox % "No Files in UnCopyArray"
Else { ; UnCopyArray has files
For Each, File in UnCopyArray {
UndoQueue[UnCopyArray, "UndoFile"] := File
UndoQueue[File] := {UnCopyArray: UndoFile}
UndoFile := UndoQueue[UnCopyArray, "UndoFile"]
msgbox % "UnCopyArrayFiles= " UndoFile
;FileDelete, %UndoFile% ; Delete the files here
;--------
;UndoQueue.Delete(UnCopyArray) ; If Undo gets executed or upon TV reload values gets deleted
;from the UndoQueue and Undo menu item disabled if no other UndoQueue key has content
;msgbox % UndoFile " files in UnCopyArray has been deleted"
UndoCopy := False
}
}
}
;-------------------------