Studio API

Editor for AutoHotkey written completely in AutoHotkey.

Moderator: maestrith

User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Studio API

Post by derz00 » 03 Oct 2017, 13:45

Hi. Cap'n Odin gave me this code.

Code: Select all

x:=Studio()
File:=x.Current(2).file
SplitPath,File,Filename,Dir,exte
I am intrigued with working with Studio through this interface. I was wondering how you might do further things with this. Such as Saving the current file.

I found some things in your great wiki, but this it does not seem inclusive. Also, a link to further examples is broke. http://files.maestrith.com/AHK-Studio/Plugins
try it and see
...
User avatar
maestrith
Posts: 731
Joined: 16 Oct 2013, 13:52

Re: Studio API

Post by maestrith » 06 Oct 2017, 20:33

Sorry but I lost my host there and have not updated been able to update anything. Saving of files can be done using x.Save() using your example but it will save all of the files. Studio, by default, saves everything when saving so that it doesn't lose anything.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Studio API

Post by derz00 » 06 Oct 2017, 20:42

Do you suppose there will ever be issues with saving all the files? How does your built in "Run" function do it? Can I do something similar?
EDIT: I'm trying to study the Plugin Class in the code.
Last edited by derz00 on 06 Oct 2017, 20:43, edited 1 time in total.
try it and see
...
User avatar
RUNIE
Posts: 279
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: Studio API

Post by RUNIE » 06 Oct 2017, 20:42

A complete list of callable methods is here: (NOTE: since maestrith updates the whole file at once the location of this class might change, it's the PluginClass)
https://github.com/maestrith/AHK-Studio ... .ahk#L1958
User avatar
maestrith
Posts: 731
Joined: 16 Oct 2013, 13:52

Re: Studio API

Post by maestrith » 06 Oct 2017, 20:44

So

Code: Select all

Text:=x.Publish(1)
would store the contents of the Project into the variable Text

Code: Select all

Class PluginClass{
	__Call(x*){
		m(x)
	}__New(){
		return this
	}Activate(){
		WinActivate(hwnd([1]))
	}AllCtrl(code,lp,wp){
		for a,b in s.ctrl
			b[code](lp,wp)
	}AutoClose(script){
		if(!this.Close[script])
			this.Close[script]:=1
	}Call(info*){
		;this can cause major errors
		if(IsFunc(info.1)&&info.1~="i)(Fix_Indent|newindent)"=0){
			func:=info.1,info.Remove(1)
			return %func%(info*)
		}	SetTimer,% info.1,-100
	}CallTip(text){
		sc:=csc(),sc.2200(sc.2128(sc.2166(sc.2008)),text)
	}Color(con){
		v.con:=con
		SetTimer,Color,-1
		Sleep,10
		v.con:=""
	}csc(obj,hwnd){
		csc({plugin:obj,hwnd:hwnd})
	}Current(x:=""){
		return Current(x)
	}DynaRun(script){
		return DynaRun(script)
	}EnableSC(x:=0){
		sc:=csc()
		if(x){
			GuiControl,1:+Redraw,% sc.sc
			GuiControl,1:+gnotify,% sc.sc
		}	else{
			GuiControl,1:-Redraw,% sc.sc
			GuiControl,1:+g,% sc.sc
	}}File(){
		return A_ScriptFullPath
	}Files(){
		return Update("get").1
	}Focus(){
		ControlFocus,Scintilla1,% hwnd([1])
		GuiControl,+Redraw,Scintilla1
		Gui,1:Default
		Gui,1:TreeView,SysTreeView321
		SetPos(TV_GetSelection()),csc(1)
	}Get(name){
		return _:=%name%
	}GuiControl(info*){
		GuiControl,% info.1,% info.2,% info.3
	}Hotkey(win:=1,key:="",label:="",on:=1){
		if(!(win,key,label))
			return m("Unable to set hotkey")
		Hotkey,IfWinActive,% hwnd([win])
		Hotkey,%key%,%label%,% _:=on?"On":"Off"
	}HotStrings(Text,String,end:=""){
		sc:=csc(),cpos:=sc.2008,TextLength:=StrPut(Text,"UTF-8")-1,StringLength:=StrPut(String,"UTF-8")-1,sc.2686(cpos-TextLength,cpos),sc.2194(StringLength,[String]),sc.2025((!end?cpos+StringLength-TextLength:cpos+end))
	}hwnd(win:=1){
		return hwnd(win)
	}InsertText(text){
		Encode(text,return),sc:=csc(),sc.2003(sc.2008,&return)
		if(end=0)
			sc.2025(sc.2008+StrPut(text,"UTF-8")-1)
		else if(end)
			sc.2025(sc.2008+end)
	}m(info*){
		m(info*)
	}MoveStudio(){
		;auto_version
		SplitPath,A_ScriptFullPath,,,,name
		FileMove,%A_ScriptFullPath%,%name%-%version%.ahk,1
	}Open(info){
		tv:=Open(info),tv(tv),WinActivate(hwnd([1]))
	}Path(){
		return A_ScriptDir
	}Plugin(action,hwnd){
		SetTimer,%action%,-10
	}Publish(info:=0){
		return,Publish(info)
	}ReplaceSelected(text){
		Encode(text,return),csc().2170(0,&return)
	}Save(){
		Save()
	}sc(){
		return csc()
	}SetText(contents){
		length:=VarSetCapacity(text,strput(contents,"utf-8")),StrPut(contents,&text,length,"utf-8"),csc().2181(0,&text)
	}SetTimer(timer,period:=-10){
		if(!IsFunc(timer)&&!IsLabel(timer))
			return
		period:=period>0?-period:period
		SetTimer,%timer%,%period%
	}Show(){
		sc:=csc()
		WinActivate(hwnd([1]))
		GuiControl,+Redraw,% sc.sc
		SetPos(sc.2357),sc.2400
	}SSN(node,path){
		return node.SelectSingleNode(path)
	}StudioPath(){
		return A_ScriptFullPath
	}Style(){
		return ea:=Settings.EA(Settings.SSN("//theme/default")),ea.color:=RGB(ea.color),ea.Background:=RGB(ea.Background)
	}TrayTip(info){
		TrayTip,AHK Studio,%info%,2
	}tv(tv){
		return tv(tv)
	}Update(filename,text){
		Update({file:filename,text:text})
	}Version(){
		;auto_version
		return version
	}
}
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
maestrith
Posts: 731
Joined: 16 Oct 2013, 13:52

Re: Studio API

Post by maestrith » 06 Oct 2017, 21:47

derz00 wrote:Do you suppose there will ever be issues with saving all the files? How does your built in "Run" function do it? Can I do something similar?
EDIT: I'm trying to study the Plugin Class in the code.
Run uses the Save() function to save anything that is unsaved so using the plugins x.Save() just calls the Save() function.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Studio API

Post by derz00 » 10 Oct 2017, 17:45

hi maestrith

I wrote a plugin for Studio, to look at the extension and run with the appropriate AHK version (v1.1 vs v2). This works, except for when a v1.1 script contains #include [file-name-in-A_ScriptDir]. There is then an AHK error message: Include file cannot be opened. When I run the script with the built in Run command, it works. Or if I convert the script and its extension to v2, it works. Would you have any idea what is causing the problem? Why the difference?

Code: Select all

;menu Run with v2
#SingleInstance,Force
x:=Studio()
x.Save()
File:=x.Current(2).file
SplitPath,File,Filename,Dir,exte
if (exte = "ahk2")
{
	Run "C:\Program Files (x86)\AutoHotkey-v2\AutoHotkeyU64.exe" "%file%"
	x.m("Run with v2")
}
else if (exte = "ahk")
{
    Run "C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe" "%file%"
    x.m("Run with v1")
}
else
{
   x.m("something happened",file,filename,dir,exte)
}
ExitApp
cheers :wave:
try it and see
...
User avatar
Delta Pythagorean
Posts: 420
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Equestria

Re: Studio API

Post by Delta Pythagorean » 10 Oct 2017, 20:02

derz00 wrote:hi maestrith

I wrote a plugin for Studio, to look at the extension and run with the appropriate AHK version (v1.1 vs v2). This works, except for when a v1.1 script contains #include [file-name-in-A_ScriptDir]. There is then an AHK error message: Include file cannot be opened. When I run the script with the built in Run command, it works. Or if I convert the script and its extension to v2, it works. Would you have any idea what is causing the problem? Why the difference?

Code: Select all

;menu Run with v2
#SingleInstance,Force
x:=Studio()
x.Save()
File:=x.Current(2).file
SplitPath,File,Filename,Dir,exte
if (exte = "ahk2")
{
	Run "C:\Program Files (x86)\AutoHotkey-v2\AutoHotkeyU64.exe" "%file%"
	x.m("Run with v2")
}
else if (exte = "ahk")
{
    Run "C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe" "%file%"
    x.m("Run with v1")
}
else
{
   x.m("something happened",file,filename,dir,exte)
}
ExitApp
cheers :wave:
I'd Suggest to change the absolute path to A_AHKPath to allow most users who have a portable installation of AHK, to allow usage for this plugin. So...

Code: Select all

;menu Run with v2
; With a little edit by Delta :P

#SingleInstance,Force

x := Studio()
x.Save()
File := x.Current(2).file
SplitPath, File, Filename, Dir, exte
If (exte = "ahk2") {
	Run A_AHKPath "%file%" ; Don't know if this is a thing in AHK v2
	x.m("Run with v2")
} Else If (exte = "ahk") {
	Run A_AHKPath "%file%"
	x.m("Run with v1")
} Else
	x.m("something happened", file, filename, dir, exte)
ExitApp
User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Studio API

Post by derz00 » 11 Oct 2017, 05:34

Hi Delta, That won't work. xD Should come up with a way to do that though... Kinda separate from my current issue
try it and see
...
User avatar
maestrith
Posts: 731
Joined: 16 Oct 2013, 13:52

Re: Studio API

Post by maestrith » 11 Oct 2017, 06:17

Just food for thought, my install of AHK is in D:\Program Files
You might want to use something like

Code: Select all

SplitPath,A_AhkPath,,Dir
Dir:=SubStr(Dir,1,InStr(Dir,"\",0,0))
if (exte = "ahk2")
{
	Run Dir "AutoHotkey-v2\AutoHotkeyU64.exe" "%file%"
	x.m("Run with v2")
}
else if (exte = "ahk")
{
    Run Dir "AutoHotkey\AutoHotkey.exe" "%file%"
    x.m("Run with v1")
}
else
{
   x.m("something happened",file,filename,dir,exte)
}
Also is AutoHotkey-v2 the default install directory for V2?
and is .ahk2 the file extension for V2 files?
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: Studio API

Post by derz00 » 11 Oct 2017, 07:13

No. AHK v2 does not have an installer, so there is no default. Both the directory and the extension are made up by myself. There has been discussion about having an official extension for AHK v2, but there is no such thing yet.

Any idea what about my plugin is different from the built in `Run` that throws the error with the #include?
try it and see
...
User avatar
maestrith
Posts: 731
Joined: 16 Oct 2013, 13:52

Re: Studio API

Post by maestrith » 11 Oct 2017, 08:42

SplitPath,File,Filename,Dir,exte
Run,"C:\Program Files (x86)\AutoHotkey-v2\AutoHotkeyU64.exe" "%file%",%Dir% ;<-----The ,%Dir% sets the working directory
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
Post Reply

Return to “AHK Studio”