Code: Select all
IniFileName := ""
IniSectionName := ""
IniList := ""
IniSaveFunc := ""
IniDeleteFunc := ""
eIniKey := ""
eIniValue := ""
IniKey := ""
IniValue := ""
loadHotStringIni()
loadHotkeys()
loadHotStringIni() ; load hotstrings from hotstrings.ini file
{
IniRead,value,%A_ScriptDir%\hotstrings.ini,hotstring
Loop, Parse,value,`n
{
keyval := StrSplit(A_LoopField,"=")
hotString := keyval[1]
replacement := keyval[2]
HotString("::" . hotString,replacement)
}
ttip("Hotstrings updated")
}
loadHotkeys() ; load hotkeys from hotkeys.ini file
{
IniRead,hotkeys,%A_ScriptDir%\hotkeys.ini,hotkey
Loop, Parse, hotkeys,`n
{
if(A_LoopField = "")
continue
line_array := StrSplit(A_LoopField,"=")
hkey := line_array[1]
program := line_array[2]
fn := Func("runProgram").Bind(program)
hotkey, %hkey%, % fn
}
ttip("Hotkeys Updated")
}
GuiIniGuiClose:
GuiIniGuiEscape:
{
gui, GuiIni:Destroy
return
}
guiIni(fileName,section,title,saveFunc,deleteFunc)
{
global IniFileName, IniSectionName, IniSaveFunc, IniDeleteFunc
IniFileName := fileName
IniSectionName := section
IniSaveFunc := saveFunc
IniDeleteFunc := deleteFunc
lists := readIniSectionList(fileName,section)
Gui,GuiIni:Destroy
gui,GuiIni:font, s8 bold, Verdana
Gui, GuiIni:Add, ListBox, sort w400 h400 gIniListSubmit vIniList, %lists% ; specifying sort options makes this list searchable
Gui, GuiIni:Add, Edit, veIniKey
Gui, GuiIni:Add, Edit, r2 w400 veIniValue
Gui, GuiIni:Add, Button, gIniSaveButton section , &Save
Gui, GuiIni:Add, Button, ys gIniDeleteButton, &Delete
Gui, GuiIni:Add, Button, ys default gIniExitButton, &Exit
Gui, GuiIni:+AlwaysOnTop
gui, GuiIni:+Lastfound
Gui, GuiIni:Show, AutoSize xCenter yCenter, % title
WinWaitClose
return
}
IniListSubmit:
{
gui, GuiIni:submit, NoHide
arr := StrSplit(IniList,"=")
IniKey := arr[1]
IniValue := arr[2]
GuiControl,,eIniKey,%IniKey%
GuiControl,,eIniValue,%IniValue%
return
}
IniSaveButton:
{
GuiControlGet,IniKey,,eIniKey
GuiControlGet,IniValue,,eIniValue
IniWrite,%IniValue%,%IniFileName%,%IniSectionName%,%IniKey%
lists := readIniSectionList(IniFileName,IniSectionName)
GuiControl, , IniList, % "|" lists
IniSaveFunc.Call()
return
}
IniDeleteButton:
{
GuiControlGet,IniKey,,eIniKey
GuiControlGet,IniValue,,eIniValue
IniDelete,%IniFileName%,%IniSectionName%,%IniKey%
lists := readIniSectionList(IniFileName,IniSectionName)
GuiControl, , IniList, % "|" lists
IniDeleteFunc.Call()
return
}
IniExitButton:
{
Gui, GuiIni:Destroy
return
}
readIniSectionList(fileName,section)
{
IniRead,lists,%fileName%,%section%
lists := StrReplace(lists,"`n","|")
return lists
}
saveIniHotstring() ; function to run after ini key and value are written to ini file
{
global IniKey, IniValue
HotString("::" . IniKey,IniValue,"On")
ttip("Hotstring updated successfully !")
}
deleteIniHotstring() ; function to run after ini key and value are deleted from ini file
{
global IniKey, IniValue
HotString("::" . IniKey,,"Off")
ttip("Hotstring deleted successfully !")
}
saveIniHotkey()
{
global IniKey, IniValue
fn := Func("runProgram").Bind(IniValue)
Hotkey,%IniKey%,% fn,On
ttip("Hotkey updated successfully !")
}
deleteIniHotkey()
{
global IniKey, IniValue
Hotkey,%IniKey%,,Off
ttip("Hotkey deleted successfully !")
}
CapsLock & h:: ; hotstrings CRUD Gui
{
saveFn := Func("saveIniHotstring")
deleteFn := Func("deleteIniHotstring")
guiIni(A_ScriptDir . "\hotstrings.ini","hotstring","HotStrings",saveFn,deleteFn)
return
}
CapsLock & k:: ; hotkeys CRUD Gui
{
saveFn := Func("saveIniHotkey").Bind()
deleteFn := Func("deleteIniHotkey").Bind()
guiIni(A_ScriptDir . "\hotkeys.ini","hotkey","Hotkeys",saveFn,deleteFn)
return
}
ttip(text)
{
ToolTip, %text%
Sleep, 1000
ToolTip
}
runProgram(program)
{
Run, %program%,,max
WinActivate, %win_title%
WinMaximize
}