/res/ahk/profile_settings.ahk

http://github.com/Skiouros/Macro · AutoHotKey · 141 lines · 118 code · 20 blank · 3 comment · 11 complexity · 65392116ae491f4279000ecf65351a9d MD5 · raw file

  1. Class Profile Extends CGUI
  2. {
  3. __New(mainGui, owner = "")
  4. {
  5. this.AddControl("Text", "F", "x46 y11 w75 h13 ", "Name:")
  6. this.edtName := this.AddControl("Edit", "edtName", "x87 y6 w299 h23 ", "")
  7. this.radioBrowse := this.AddControl("Radio", "radioBrowse", "x33 y86 w329 h16 ", "Browse")
  8. this.radioSelect := this.AddControl("Radio", "radioSelect", "x33 y121 w327 h16 ", "Select from list")
  9. this.radioSelect := this.AddControl("Radio", "radioHotkey", "x33 y161 w327 h16 ", "Select with F12")
  10. this.AddControl("GroupBox", "X", "x6 y62 w380 h159 ", "Select Program Executable")
  11. this.edtExe := this.AddControl("Edit", "edtExe", "x55 y187 w278 h23 ", "")
  12. this.btnOK := this.AddControl("Button", "btnOK", "x148 y224 w75 h23 ", "OK")
  13. this.AddControl("Button", "btnCanel", "x229 y224 w75 h23 ", "Cancel")
  14. this.AddControl("Button", "btnHelp", "x310 y224 w75 h23 ", "Help")
  15. this.btnOK.Disable()
  16. this.gui := mainGui
  17. if (owner)
  18. this.Owner := owner, this.OwnerAutoClose := 1, this.MinimizeBox := 0
  19. this.Toolwindow := 1
  20. this.Title := "Profile Manager"pp
  21. }
  22. btnHelp_Click()
  23. {
  24. MsgBox, Name: Name of profile.`nProgram Executable: Exe of program for profile switching.
  25. }
  26. edtName_textChanged()
  27. {
  28. ; Making sure its a valid name.
  29. if (this.edtName.text && !RegExMatch(this.edtName.text, "[\\/\?\*\""""\:\<\>\|]") )
  30. this.btnOK.Enable()
  31. else
  32. this.btnOK.Disable()
  33. }
  34. radioBrowse_CheckedChanged()
  35. {
  36. this.OwnDialogs := 1 ; For file select dialog
  37. file := new CFileDialog(), file.FileMustExist := 1
  38. file.Filter := "Program (*.exe)"
  39. if ( file.show() )
  40. this.edtExe.Text := file.FileName
  41. }
  42. radioSelect_CheckedChanged()
  43. {
  44. this.gui.Windows.Load()
  45. this.Enabled := false
  46. }
  47. radioHotkey_CheckedChanged()
  48. {
  49. Hotkey, F12, SelectExe, On
  50. Hotkey, Escape, SelectExe, On
  51. SplashTextOn, 230, 50, Select Program, Activate the program and press F12`nPress Esc to cancel
  52. }
  53. btnCanel_Click()
  54. {
  55. this.Loaded := 0
  56. this.edtName.Text := "", this.edtExe.Text := ""
  57. this.gui.Enabled := true
  58. this.Hide()
  59. debug ? debug("Canceled profile creation")
  60. }
  61. btnOK_Click()
  62. {
  63. name := Trim(this.edtName.Text)
  64. if (name = "Default")
  65. {
  66. MsgBox, 48, , Profile name can not be "Default".
  67. return
  68. }
  69. else if (FileExist(A_ScriptDir . "\res\Profiles\" . name . ".xml")) ; Profile already exists.
  70. {
  71. MsgBox, 52, , Profile already exists.`nWould you like to overwrite it?
  72. IfMsgBox, No
  73. return
  74. }
  75. if (this.Loaded)
  76. {
  77. FileRead, xmlValue, % this.savedProfile
  78. FileDelete % this.savedProfile
  79. }
  80. currentXml := A_ScriptDir . "\res\Profiles\" . name . ".xml"
  81. if (xmlValue)
  82. FileAppend, % xmlValue, % currentXml
  83. xml := New Xml(currentXml)
  84. exe := this.edtExe.Text
  85. ; Update values in xml file.
  86. xml.Set("exe", exe)
  87. xml.Set("name", name)
  88. xml.Save(A_ScriptDir . "\res\Profiles\" . name . ".xml") ; Save xml file.
  89. ; Clear value from edit boxs.
  90. this.edtName.Text := "", this.edtExe.Text := "", this.Loaded := 0
  91. this.gui.Enabled := true
  92. this.Hide()
  93. debug ? debug("Created profile: " name)
  94. this.gui.LoadProfiles()
  95. Control, ChooseString, % name, % this.gui.drpProfiles.ClassNN, A
  96. }
  97. Load(profilePath)
  98. {
  99. SplitPath, profilePath, name
  100. this.savedProfile := profilePath
  101. this.edtName.Text := SubStr(name, 1, -4)
  102. this.edtExe.Text := xml.Get("exe")
  103. this.Loaded := 1
  104. debug ? debug("Loaded profile: " . name)
  105. this.Show()
  106. }
  107. PreClose() {
  108. this.gui.Enabled := true
  109. }
  110. }
  111. SelectExe:
  112. SplashTextOff
  113. if (A_ThisHotkey = "F12")
  114. {
  115. WinGet, exeName, ProcessPath , A
  116. gui.Profile.edtExe.Text := exeName
  117. }
  118. Hotkey, F12, Off
  119. Hotkey, Escape, Off
  120. WinActivate % "ahk_pid " . DllCall("GetCurrentProcessId")
  121. return