1. It first checks for an ini file. If none exists, prompt the user for the location of their 'state' files, then write it to an ini file. This works.
2. After learning the directory for the state files, it browses the directory and reads the file contents of any .xml file, grabbing the plugin name and actual file name. This works.
3. If I double-click on a row, it will open up the state file in my default editor. This works.
4. If I right-click on the state file, it presents an option to delete the file. This is my roadblock.
I keep getting "Invalid callback" no matter what I try to do for the ContextMenu. Originally, I was going to have it just straight delete it, but I decided I wanted to make sure a user is deleting the proper file so it would present with a delete prompt. I'll also add the plugin name so that the user doesn't have to guess, but that's a separate task for now. Right now, I just want to be able to delete on a right-click menu. What am I missing?
Code: Select all
#SingleInstance Force
#Requires AutoHotkey v2.0
IniFile := A_ScriptDir "\state.ini"
defaultFileName := "e0eb198d8d5698e3b2f61483-"
if (!FileExist(IniFile))
{
StateLocation := DirSelect(, , "Select the 'state' folder location")
IniWrite(StateLocation, IniFile, "State", "Location")
} else {
StateLocation := IniRead(IniFile, "State", "Location")
}
FilePattern := StateLocation "\*.xml"
EasyStates := Gui("+Resize +Theme", "Easy States")
ESLV := EasyStates.Add("ListView", "r30 w600 sort grid", ["Plugin Name", "State File"])
Loop Files, FilePattern, "R"
{
FileContents := FileRead(A_LoopFileFullPath)
if (RegExMatch(FileContents, "Plugin: `"(.+?)`"", &Name))
{
ESLV.Add(, Name[1], A_LoopFileName)
}
}
RCMenu := Menu()
ESLV.OnEvent("DoubleClick", ESLV_DoubleClick)
ESLV.OnEvent("ContextMenu", ESLV_RClick)
EasyStates.OnEvent("Size", GuiSize)
ESLV.ModifyCol
EasyStates.Show()
ESLV_DoubleClick(LV, RowNumber)
{
filePath := StateLocation "\" LV.GetText(RowNumber, 2)
Run filePath
}
GuiSize(thisGui, MinMax, width, height)
{
if (MinMax = -1)
return
ESLV.Move(, , width - 20, height - 20)
}
ESLV_RClick(thisLV, info)
{
RCMenu.Add "Delete", ESLV_Delete
RCMenu.Show()
}
ESLV_Delete(thisLV, clickedRow)
{
filePath := StateLocation "\" thisLV.GetText(clickedRow, 2)
FileDelete(filePath)
thisLV.Delete(clickedRow)
}