Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. Class BinderGUI extends GUI {
  2. static DDLAssignments := "Built-in|Multimedia|Imgur|Mouse Function|Launch Application"
  3. static EditAssignments := "Send Text|Launch Website|Launch File/Program"
  4. static WIDTH := 180, HEIGHT := 215, CONTROL_HEIGHT := 26
  5.  
  6. AddButton() {
  7. Key := this.GuiControlGet(, Binder.MainHotkeyHWND)
  8. EditText := this.GetText("Edit1")
  9. Rebind := this.GuiControlGet(, Binder.BindHotkeyHWND)
  10.  
  11. if !StrLen(Key) && this.ShowHotkey {
  12. TrayTip, % AppName, Please input a Hotkey.
  13. return
  14. }
  15.  
  16. ; create nugget
  17. if (this.Assignment ~= this.DDLAssignments) { ; assignment used a dll control, get the data from it
  18.  
  19. for Index, Action in Actions.List[this.Assignment]
  20. if (Action.Desc = this.Function)
  21. Bind := Action
  22.  
  23. } else if (this.Assignment ~= this.EditAssignments) { ; assignment used an edit control
  24.  
  25. if !StrLen(EditText) {
  26. SoundPlay, *-64
  27. return
  28. }
  29.  
  30. if (this.Assignment = "Launch Website")
  31. Bind := {Desc:"Website: " EditText, Func:"Run", Param:[EditText]}
  32. else if (this.Assignment = "Send Text")
  33. Bind := {Desc:"Send Text: " EditText, Func:"SendRaw", Param:[EditText]}
  34. else if (this.Assignment = "Launch File/Program") {
  35. SplitPath, EditText, OutFileName
  36. Bind := {Desc:"Launch: " OutFileName, Func:"Run", Param:[EditText]}
  37. }
  38.  
  39. } else if (this.Assignment = "Rebind Key") {
  40. if !StrLen(Rebind) {
  41. SoundPlay, *-64
  42. return
  43. } Bind := {Desc:"Rebound to: " HotkeyToString(Rebind), Func:"Send", Param:[Rebind]}
  44. } else if (this.Assignment = "Launch Application") {
  45. ; todo
  46. }
  47.  
  48. if !IsObject(Bind) || !StrLen(Bind.Desc) { ; throw an error if we don't have a bind object
  49. Error("Unable to create Bind nugget", A_ThisFunc, "Key: " key "`nAssignment: " this.Assignment "`nFunction: " this.Function "`nEdit: " EditText "`nRebind: " Rebind)
  50. TrayTip, Error, Unable to create create nugget.`nAn error log has been saved.
  51. this.Close()
  52. } else
  53. this.Close(Bind, Key)
  54. }
  55.  
  56. HotkeyChange() {
  57. Key := this.GuiControlGet(, Binder.MainHotkeyHWND)
  58.  
  59. if IsObject(Keybinds[Key]) {
  60. this.KeyInUse := true
  61. this.Control(, "Static1", "KEY IN USE!")
  62. this.Font("cRed")
  63. this.Control("Font", "Static1")
  64. } else if this.KeyInUse {
  65. this.KeyInUse := false
  66. this.SetText("Static1", "Key:")
  67. this.Font("cBlack")
  68. this.Control("Font", "Static1")
  69. }
  70. }
  71.  
  72. AssignmentDDL() {
  73. this.Assignment := this.GetText("ComboBox1")
  74. this.SetAssignment(this.Assignment)
  75. }
  76.  
  77. FunctionDDL() {
  78. this.Function := this.GetText("ComboBox2")
  79. }
  80.  
  81. SetAssignment(Assignment) { ; Static3
  82. if (Assignment ~= this.DDLAssignments) { ; function needs a ddl control
  83. for Index, Functions in Actions.List[Assignment], DDLList:=""
  84. DDLList .= Functions.Desc "|"
  85. this.SetText(Binder.AssignmentTextHWND, "Function:")
  86. this.Control("Text", "ComboBox2", "|" DDLList)
  87. this.Control("Choose", "ComboBox2", 1)
  88. this.ControlShow("ComboBox2")
  89. this.Function := Actions.List[Assignment][1].Desc
  90. } else if (Assignment ~= this.EditAssignments) { ; function needs an edit control
  91. this.SetText("Edit1")
  92. this.ControlShow("Edit1")
  93. if (Assignment = "Send Text")
  94. this.SetText(Binder.AssignmentTextHWND, "Text to Send:")
  95. else if (Assignment = "Launch Website")
  96. this.SetText(Binder.AssignmentTextHWND, "Website URL:")
  97. else if (Assignment = "Launch File/Program") {
  98. this.SetText(Binder.AssignmentTextHWND, "Select file:")
  99. this.ControlShow("Button1") ; hide 'em all
  100. this.Control("Show", "Edit1")
  101. this.Control("Enable", "Edit1")
  102. this.Control("Move", "Edit1", "w" this.WIDTH - 16 - this.CONTROL_HEIGHT)
  103. this.Control("+ReadOnly", "Edit1")
  104. }
  105. } else if (Assignment = "Rebind Key") {
  106. this.SetText(Binder.AssignmentTextHWND, "Rebind to:")
  107. this.ControlShow(Binder.BindHotkeyHWND)
  108. }
  109. }
  110.  
  111. ControlShow(SelectControl) {
  112. if (SelectControl = "Edit1") {
  113. this.Control("Move", "Edit1", "w" this.WIDTH - 12)
  114. this.Control("-ReadOnly", "Edit1")
  115. }
  116. for Index, Control in ["ComboBox2", "Edit1", Binder.BindHotkeyHWND, "Button1"] {
  117. this.Control(SelectControl=Control?"Show":"Hide", Control)
  118. this.Control(SelectControl=Control?"Enable":"Disable", Control)
  119. }
  120. }
  121.  
  122. SelectFile() {
  123. this.Disable()
  124. this.Options("+OwnDialogs")
  125. FileSelectFile, out, S, % A_ProgramFiles, Select a file:
  126. if ErrorLevel
  127. return this.Enable()
  128. this.SetText("Edit1", out)
  129. ControlSend, Edit1, {End}, % this.ahkid
  130. this.Enable()
  131. }
  132.  
  133. Close(Bind := "", Key := "") {
  134. DllCall("AnimateWindow", "UInt", this.hwnd, "Int", 60, "UInt", "0x90000")
  135. WinActivate("ahk_id" this.Owner)
  136.  
  137. this.Destroy()
  138.  
  139. this.Callback.Call(Bind, Key)
  140. }
  141.  
  142. Escape() {
  143. this.Close()
  144. }
  145. }
  146.  
  147. CreateNugget(Callback, ShowHotkey := true, Owner := "") {
  148.  
  149. ; list of assignments
  150. AssignmentList := [ "Multimedia"
  151. , "Imgur"
  152. , "Built-in"
  153. , "Mouse Function"
  154. , "Send Text"
  155. , "Rebind Key"
  156. , "Launch File/Program"
  157. , "Launch Website"
  158. , "Launch Application"]
  159.  
  160. ; parse assignments for the ddl control
  161. for Index, Assignment in AssignmentList
  162. AssignmentDDL .= Assignment "|"
  163.  
  164. Binder := new BinderGUI()
  165.  
  166. Binder.Font("s10", Settings.Font)
  167. Binder.Margin(6, 4)
  168.  
  169. Binder.ShowHotkey := ShowHotkey
  170. Binder.Callback := Callback
  171. Binder.Owner := Owner
  172.  
  173. WIDTH := Binder.WIDTH
  174. HEIGHT := Binder.HEIGHT
  175. CONTROL_HEIGHT := Binder.CONTROL_HEIGHT
  176.  
  177. ; main hotkey control
  178. if ShowHotkey {
  179. Binder.Add("Text", "Center x0 w" WIDTH, "Key:")
  180. Binder.MainHotkeyHWND := Binder.Add("Hotkey", "x6 yp+25 w" WIDTH-12 " Center",, Binder.HotkeyChange.Bind(Binder))
  181. }
  182.  
  183. Binder.Add("Text", "x0 w" WIDTH " Center", "Assignment:")
  184. Binder.Add("DropDownList", "x6 w" WIDTH-12 " h" CONTROL_HEIGHT " Choose1 R99", AssignmentDDL, Binder.AssignmentDDL.Bind(Binder))
  185. Binder.Add("Text", "x6 yp+" 8+CONTROL_HEIGHT " w" WIDTH-12 " h1 0x08") ; separator
  186. Binder.AssignmentTextHWND := Binder.Add("Text", "x0 w" WIDTH " Center", "Function:")
  187.  
  188. Binder.Add("DropDownList", "x6 w" WIDTH-12 " h" CONTROL_HEIGHT " Choose1 Hidden R99",, Binder.FunctionDDL.Bind(Binder))
  189. Binder.EditHWND := Binder.Add("Edit", "x6 yp w" WIDTH-12 " h" CONTROL_HEIGHT)
  190. Binder.Font("s9", "Wingdings")
  191. Binder.Add("Button", "x" WIDTH - 6 - CONTROL_HEIGHT " yp-1 w" CONTROL_HEIGHT " h" CONTROL_HEIGHT + 2, "1", Binder.SelectFile.Bind(Binder))
  192. Binder.Font("s10", Settings.Font)
  193. Binder.BindHotkeyHWND := Binder.Add("Hotkey", "x6 yp+1 w" WIDTH - 12 " h" CONTROL_HEIGHT " w" WIDTH-12)
  194.  
  195. Binder.Margin(6, 10)
  196. Binder.Add("Text", "x6 yp+" 8+CONTROL_HEIGHT " w" WIDTH-12 " h1 0x08") ; separator
  197. Binder.Add("Button", "x6 yp+8 h" CONTROL_HEIGHT, "Cancel", Binder.Close.Bind(Binder))
  198. Binder.Add("Button", "xp" WIDTH - (ShowHotkey?95:61) " yp h" CONTROL_HEIGHT, ShowHotkey?"Add Keybind":"Create", Binder.AddButton.Bind(Binder))
  199. Binder.Options("+Owner" Owner " -Caption +Border +AlwaysOnTop") ; remove border and caption and make BigGUI the owner
  200.  
  201. ; set initial values
  202. Binder.SetAssignment("Multimedia"), Binder.Assignment := "Multimedia", Binder.Function := "Play/Pause"
  203.  
  204. FrameShadow(Binder.hwnd)
  205.  
  206. if (OwnerPos := WinGetPos("ahk_id" Owner))
  207. Binder.Show("x" OwnerPos.X + OwnerPos.W/2 - 182/2 " y" OwnerPos.Y + OwnerPos.H/2 - 218/2 + 15 " w" WIDTH " h" HEIGHT)
  208. else
  209. Binder.Show()
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement