The Document that was here has been removed for some super revision, in the mean time the following script can be used as an example for those who want to proform the following actions to a list, or set of lists:
Move the Cursel Up
Move the Cursel Down
Add Files to a list
Add a User Entry to a list
Add Files via Drag and Drop
Import Contents of a file to a list
Remove A Item from a list
Remove a Select Items' Duplicates from a list
Remove All Duplicated Items from a list
Move Selected Item Up in list
Move Selected Item Down in list
Move Selected Item from one to the other
Replace an Item with User defined entry
Copy Selected Item to other list
Sort a lists contents by Case (Add a single N character to this function for Numeric Sorting)
Swap Items from list to list
Switch two items within a list
Each function has been well tested but bugs may still be present. Please report them as they are found. Note: Know issue with Importing files, Entering "n" as a delimiter is seen as "`n" This will soon be fixed
Functions that are planned to be developed:
Mass Copy (Simular to above)
Mass Swap (Simular to above)
Mass Switch
Mass Move selected Items
...and more as they are thought of....
This script is not well comented but should suffice until I write I document to explain it all.
Code:
AllowedExtList = ahk,wav,mp3,txt
ExcludedExtList = tmp,exe
AppWinTitle = List Function Demo
TargetList = 1
TargetListOSD = %TargetList%
BlankVar =
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Menu, FileMenu, Add, Exit, Exit
Menu, LLFunctionsMenu, Add, Move Cursel Down, MoveCurselDown
Menu, LLFunctionsMenu, Add, Move Cursel UP, MoveCurselUp
Menu, LLFunctionsMenu, Add, Add File, AddFile
Menu, LLFunctionsMenu, Add, Remove Item, RemoveItem
Menu, LLFunctionsMenu, Add, Move Item Down, MoveItemDown
Menu, LLFunctionsMenu, Add, Move Item Up, MoveItemUp
Menu, HLFunctionsMenu, Add, Replace Item, ReplaceItem
Menu, HLFunctionsMenu, Add, Remove Select Duplicates, RemoveDuplicates
Menu, HLFunctionsMenu, Add, Switch Items, SwitchItems
Menu, HLFunctionsMenu, Add, Move Item to Other List, MoveItemToOtherList
Menu, LLFunctionsMenu, Add, Add User Entry, AddUserEntry
Menu, HLFunctionsMenu, Add, Import List From File, ImportListFromFile
Menu, LLFunctionsMenu, Add, Sort Items, SortItems
;Menu, LLFunctionsMenu, Add, Remove All Duplicates, RemoveAddDuplicates
;Menu, HLFunctionsMenu, Add, Swap Items, SwapItems
;Menu, HLFunctionsMenu, Add, Copy Item, CopyItem
;Menu, FunctionsMenu, Add, Function5, Function5
;Menu, FunctionsMenu, Add, Function6, Function6
;Menu, FunctionsMenu, Add, Function7, Function7
;Menu, FunctionsMenu, Add, Function8, Function8
;Menu, FunctionsMenu, Add, Function9, Function9
;Menu, FunctionsMenu, Add, Function10, Function10
;Menu, FunctionsMenu, Add, Function11, Function11
;Menu, FunctionsMenu, Add, Function12, Function12
Menu, OptionsMenu, Add, Filter Settings, FilterSettings
Menu, MyMenuBar, Add, File, :FileMenu ; Attach the three sub-menus that were created above.
Menu, MyMenuBar, Add, Low Level Functions, :LLFunctionsMenu
Menu, MyMenuBar, Add, High Level Fucntions, :HLFunctionsMenu
Menu, MyMenuBar, Add, Options, :OptionsMenu ;Add Options to menu
Gui, Menu, MyMenuBar
Gui, Add, Button, gMoveCurselDown x6 y10 w100 h30, Move Cursel Down
Gui, Add, Button, gMoveCurselUp x6 y40 w100 h30, Move Cursel Up
Gui, Add, Button, gAddFile x6 y70 w100 h30, Add File
Gui, Add, Button, gRemoveItem x6 y100 w100 h30, Remove Item
Gui, Add, Button, gMoveItemUp x6 y130 w100 h30, Move Item Up
Gui, Add, Button, gMoveItemDown x6 y160 w100 h30, Move Item Down
Gui, Add, Button, gReplaceItem x6 y190 w100 h30, Replace Item
Gui, Add, Button, gRemoveDuplicates x6 y220 w100 h30, Remove Select Duplicates
Gui, Add, Button, gSwitchItems x6 y250 w100 h30, Switch Items
Gui, Add, Button, gMoveItemToOtherList x6 y280 w100 h30, Move Item To Other List
Gui, Add, Button, gAddUserEntry x6 y310 w100 h30, Add User Entry
Gui, Add, Button, gImportListFromFile x6 y340 w100 h30, Import List From File
Gui, Add, Button, gCopyItem x106 y10 w100 h30, Copy Item
Gui, Add, Button, gSwapItems x106 y40 w100 h30, Swap Items
Gui, Add, Button, gSortItems x106 y70 w100 h30, Sort Items
Gui, Add, Button, gRemoveAllDuplicates x106 y100 w100 h30, Remove All Duplicates
;Gui, Add, Button, x106 y130 w100 h30, New Function5
;Gui, Add, Button, x106 y160 w100 h30, New Function6
;Gui, Add, Button, x106 y190 w100 h30, New Function7
;Gui, Add, Button, x106 y220 w100 h30, New Function8
;Gui, Add, Button, x106 y250 w100 h30, New Function9
;Gui, Add, Button, x106 y280 w100 h30, New Function10
;Gui, Add, Button, x106 y310 w100 h30, New Function11
;Gui, Add, Button, x106 y340 w100 h30, New Function12
Gui, Add, Text, gTargetList1 x236 y10 w350 h20, List 1 (Select this text to activate this list if there is no entries)
Gui, Add, ListBox, gTargetList1 vListBox1 AltSubmit HScroll x236 y30 w350 h160,
Gui, Add, Text, gTargetList2 x236 y190 w350 h20, List 2 (Select this text to activate this list if there is no entries)
Gui, Add, ListBox, gTargetList2 vListBox2 AltSubmit HScroll x236 y210 w350 h160,
Gui, Font, s18
Gui, Add, Text, vTargetListOSD Center x206 y10 w30 h30, %TargetListOSD%
;#################Second GUI######################
Gui, 2:Add, Text, x116 y30 w250 h20, Allow these types of files (use comma delimited list)
Gui, 2:Add, Edit, vAllowedExtList x116 y60 w250 h20, %AllowedExtList%
Gui, 2:Add, Text, x116 y90 w260 h20, Exclude these types of files (use comma delimited list)
Gui, 2:Add, Edit, vExcludedExtList x116 y120 w250 h20, %ExcludedExtList%
;Gui, 2:Add, Radio, x16 y40 w80 h30, Allow these extentions
;Gui, 2:Add, Radio, x16 y90 w90 h50, Exclude these extentions
Gui, 2:Add, GroupBox, x6 y10 w380 h140, Filter Options
Gui, 2:Add, Button, gApplyOptions x396 y20 w70 h30, Apply
;#####################Third GUI#########################
Gui, 3:Add, Text,, What Character would you like your delimiter to be?
Gui, 3:Add, Edit, vUserDelimiter,
Gui, 3:Add, Text,, What Character/s would you like to omit from the retrieved contense between delimited characters?
Gui, 3:Add, Edit, vUserOmit
Gui, 3:Add, Button, gContImport, Import File
Gui, Show, x0 y0 h377 w594, %AppWinTitle%
Return
;############################################################
TargetList1:
TargetList = 1
OtherList = 2
GuiControl,1:,TargetListOSD, 1
Return
;------------------------------------------------------------
TargetList2:
TargetList = 2
OtherList = 1
GuiControl,1:,TargetListOSD, 2
Return
;############################################################
FilterSettings:
Gui, 2:Show, x147 y109 h159 w477, Options
Return
;------------------------------------------------------------
ApplyOptions:
Gui, 2:Submit
Return
;------------------------------------------------------------
SwapItems:
Gui, Submit, NoHide
TargetItemPos1 := ListBox%TargetList%
TargetItemPos2 := ListBox%OtherList%
GoSub, SplitUpString
TargetItemCont1 := ArrayOfAllEntries%TargetItemPos1%
GoSub, TargetList%OtherList%
GoSub, SplitUpString
TargetItemCont2 := ArrayOfAllEntries%TargetItemPos2%
ArrayOfAllEntries%TargetItemPos2% = %TargetItemCont1%
GoSub, FillListFromArray
GoSub, TargetList%OtherList%
GoSub, SplitUpString
ArrayOfAllEntries%TargetItemPos1% = %TargetItemCont2%
GoSub, FillListFromArray
Return
;------------------------------------------------------------
SortItems:
SortedList := ListBoxCont%TargetList%
Sort, SortedList, D| C
ListBoxCont%TargetList% = %SortedList%
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
MoveCurselDown:
Gui,Submit,NoHide
ChoicePos:= ListBox%TargetList%
ChoicePos++
If (ChoicePos> 0)
Control, Choose, %ChoicePos%, ListBox%TargetList%
Return
;------------------------------------------------------------
MoveCurselUp:
Gui,Submit,NoHide
ChoicePos:= ListBox%TargetList%
ChoicePos--
If (ChoicePos> 0)
Control, Choose, %ChoicePos%, ListBox%TargetList%
Return
;------------------------------------------------------------
RemoveAllDuplicates:
SortedList := ListBoxCont%TargetList%
Sort, SortedList, D| U C
ListBoxCont%TargetList% = %SortedList%
GoSub, SplitUpString
GoSub, FillListFromArray
;GuiControl,1:, ListBox%TargetList%, |%SortedList%
Return
;------------------------------------------------------------
AddFile:
FileSelectFile, FilesToAdd, M 3,, Select some files,
If FilesToAdd =
Return
Loop, parse, FilesToAdd, `n
{
If A_Index = 1
RootPath = %A_LoopField%
Else
{
StringSplit, FileListArray, A_loopField, `.
If FileListArray%FileListArray0% Not Contains %AllowedExtList%
Continue
If FileListArray%FileListArray0% In %ExcludedExtList%
Continue
Else
{
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %RootPath%\%A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . RootPath . "\" . A_LoopField
}
}
}
}
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
RemoveItem:
Gui, Submit, NoHide
ItemToRemovePos := ListBox%TargetList%
;Create array of listboxes contents
GoSub, SplitUpString
;Remove Selected Item
GoSub, RemoveSelection
;Recreate array with new list after selected item was removed
GoSub, SplitUpString
;Fill array and update listbox
GoSub, FillListFromArray
Control, Choose, %ItemToRemovePos%, ListBox%TargetList%, %AppWinTitle%
;This method below is a complex version that removes the selected item from the list
;however this does NOT remove that selected item from the array that makes up that list
;GuiControl, -AltSubmit, ListBox%TargetList%
;GuiControlGet, FileList,, ListBox%TargetList%
;ControlGet, ItemToRemove, FindString, %FileList%, ListBox%TargetList%, %AppWinTitle%
;Control, Delete, %ItemToRemove%, ListBox%TargetList%, %AppWinTitle%
;GuiControl, Choose, ListBox%TargetList%, %ItemToRemove%
;GuiControl, +AltSubmit, ListBox%TargetList%
Return
;------------------------------------------------------------
MoveItemDown:
Gui, Submit, NoHide
GoSub, SplitUpString
; If selected entry is not first entry
If (ListBox%TargetList% < ArrayOfAllEntries0)
{
; New position is one up
NewPosition := ListBox%TargetList% + 1
; Flip entries
GoSub, FlipEntriesInArray
; Fill Array into Listbox
GoSub, FillListFromArray
; Keep moved entry selected
GuiControl, Choose, ListBox%TargetList%, %NewPosition%
}
Return
;------------------------------------------------------------
MoveItemUp:
BtnMoveItemUp:
Gui, Submit, NoHide
GoSub, SplitUpString
; If selected entry is not first entry
If (ListBox%TargetList% > 1)
{
; New position is one up
NewPosition := ListBox%TargetList% - 1
; Flip entries
GoSub, FlipEntriesInArray
; Fill Array into Listbox
GoSub, FillListFromArray
; Keep moved entry selected
GuiControl, Choose, ListBox%TargetList%, %NewPosition%
}
Return
;------------------------------------------------------------
ReplaceItem:
Gui, Submit, NoHide
ReplaceItemPos := ListBox%TargetList%
GoSub, SplitUpString
InputBox, UserEntry, Add User Item, Enter some text to add to list %TargetList%, , 300, 200,
ArrayOfAllEntries%ReplaceItemPos% = %UserEntry%
GoSub, FillListFromArray
Return
;------------------------------------------------------------
RemoveDuplicates:
;This uses a complex method, Sort could also be used
Gui, Submit, NoHide
KeptItemPos := ListBox%TargetList%
GoSub, SplitUpString
ItemToRemove := ArrayOfAllEntries%KeptItemPos%
If KeptItemPos = 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, %ItemToRemove%|,, All
}
If KeptItemPos <> 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, |%ItemToRemove%,, All
}
;StringReplace, OutputVar, InputVar, SearchText [, ReplaceText, ReplaceAll?]
;ArrayOfAllEntries%KeptItemPos% = %ItemToRemove%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . ItemToRemove
}
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
SwitchItems:
Gui, Submit, NoHide
TargetItemPos1 := ListBox%TargetList%
GoSub, SplitUpString
TargetItemCont1 := ArrayOfAllEntries%TargetItemPos1%
MsgBox, 0, SwitchItems, Select a second item in the same list that you want to switch with the first. `nPress OK when ready
Gui, Submit, NoHide
TargetItemPos2 := ListBox%TargetList%
GoSub, SplitUpString
TargetItemCont2 := ArrayOfAllEntries%TargetItemPos2%
;Swap the values
ArrayOfAllEntries%TargetItemPos1% = %TargetItemCont2%
ArrayOfAllEntries%TargetItemPos2% = %TargetItemCont1%
;GoSub, SplitUpString
GoSub, FillListFromArray
Return
;------------------------------------------------------------
MoveItemToOtherList:
Gui, Submit, NoHide
ItemToMovePos := ListBox%TargetList%
GoSub, SplitUpString
ItemToMove := ArrayOfAllEntries%ItemToMovePos%
GoSub, TargetList%OtherList%
GoSub, SplitUpString
If ListBoxCont%TargetList% =
ListBoxCont%TargetList% = %ItemToMove%
Else ;If ListBoxCont%TargetList% <>
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . ItemToMove
GoSub, SplitUpString
GoSub, FillListFromArray
GoSub, TargetList%OtherList%
GoSub, RemoveItem
;GoSub, TargetList%OtherList%
GoSub, SplitUpString
GoSub, FillListFromArray
;GoSub, TargetList%OtherList%
Control, Choose, %ItemToMovePos%, ListBox%TargetList%, %AppWinTitle%
Return
;------------------------------------------------------------
CopyItem:
Gui, Submit, NoHide
ItemToMovePos := ListBox%TargetList%
GoSub, SplitUpString
ItemToMove := ArrayOfAllEntries%ItemToMovePos%
GoSub, TargetList%OtherList%
GoSub, SplitUpString
If ListBoxCont%TargetList% =
ListBoxCont%TargetList% = %ItemToMove%
Else ;If ListBoxCont%TargetList% <>
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . ItemToMove
GoSub, SplitUpString
GoSub, FillListFromArray
GoSub, TargetList%OtherList%
;GoSub, RemoveItem
;GoSub, TargetList%OtherList%
GoSub, SplitUpString
GoSub, FillListFromArray
;GoSub, TargetList%OtherList%
Control, Choose, %ItemToMovePos%, ListBox%TargetList%, %AppWinTitle%
Return
;------------------------------------------------------------
AddUserEntry:
InputBox, UserEntry, Add User Item, Enter some text to add to list %TargetList%, , 300, 200,
GuiControl, 1:, ListBox%TargetList%, %UserEntry%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %UserEntry%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . UserEntry
}
Return
;------------------------------------------------------------
ImportListFromFile:
SelectImports:
FileSelectFile, UserImportFile, 3,, Please Select a File to Import to the Key Lists, *.txt
If UserImportFile =
{
MsgBox, 0, Importing Error, There was no file to import `nImport Aborted ; Prompts user to select file for import
Return
}
Gui, 3:Show,,Importing using Delimiters
Return
ContImport:
Gui, 3:Submit
Loop, read, %UserImportFile% ;,%UserImportFile%
{
Loop, parse, A_LoopReadLine, %UserDelimiter%, %UserOmit%
{
GuiControl, 1:, ListBox%TargetList%, %A_LoopField%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . A_LoopField
}
}
}
Return
;------------------------------------------------------------
GuiDropFiles:
Loop, parse, A_GuiControlEvent, `n
{
StringSplit, FileListArray, A_loopField, `.
If FileListArray%FileListArray0% Not In %AllowedExtList%
Continue
Else If FileListArray%FileListArray0% In %ExcludedExtList%
Continue
Else
{
;GuiControl,1:, ListBox%TargetList%, %RootPath%\%A_LoopField%
If ListBoxCont%TargetList% =
{
ListBoxCont%TargetList% = %A_LoopField%
}
Else ;If ListBoxCont%TargetList% <>
{
ListBoxCont%TargetList% := ListBoxCont%TargetList% . "|" . A_LoopField
}
}
}
GoSub, SplitUpString
GoSub, FillListFromArray
Return
;############################################################
;############################################################
SplitUpString:
SplitVar := ListBoxCont%TargetList%
StringSplit, ArrayOfAllEntries, SplitVar, |
Return
;------------------------------------------------------------
FlipEntriesInArray:
PosValue := ListBox%TargetList%
; Get selected entry from Array
CurrentEntry := ArrayOfAllEntries%PosValue% ;%LstToDo%
; Put entry from new position in Array into current position
ArrayOfAllEntries%PosValue% := ArrayOfAllEntries%NewPosition%
; Put selected entry into new position in Array
ArrayOfAllEntries%NewPosition% = %CurrentEntry%
Return
;-------------------------------------------------------------
; Build string from array and assign it to the listbox control
FillListFromArray:
FillString =
Loop, %ArrayOfAllEntries0%
{
Entry := ArrayOfAllEntries%A_Index%
FillString = %FillString%|%Entry%
}
GuiControl,1:, ListBox%TargetList%, %FillString%
StringTrimLeft, FillString, FillString, 1
ListBoxCont%TargetList% = %FillString%
Return
;--------------------------------------------------------------
RemoveSelection:
ItemToRemove := ArrayOfAllEntries%ItemToRemovePos%
If ItemToRemovePos = 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, %ItemToRemove%|
}
If ItemToRemovePos <> 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, |%ItemToRemove%
}
;Used to remove selected item if its the only item remaining in a list
If ArrayOfAllEntries0 <= 1
{
StringReplace, ListBoxCont%TargetList%, ListBoxCont%TargetList%, %ItemToRemove%
}
Return
Exit:
GuiClose:
ExitApp
F9::Reload
F10::ListVars