PageRenderTime 46ms CodeModel.GetById 43ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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