Page 1 of 1

Studio API

Posted: 03 Oct 2017, 13:45
by derz00
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

Re: Studio API

Posted: 06 Oct 2017, 20:33
by maestrith
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.

Re: Studio API

Posted: 06 Oct 2017, 20:42
by derz00
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.

Re: Studio API

Posted: 06 Oct 2017, 20:42
by runie
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

Re: Studio API

Posted: 06 Oct 2017, 20:44
by maestrith
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
	}
}

Re: Studio API

Posted: 06 Oct 2017, 21:47
by maestrith
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.

Re: Studio API

Posted: 10 Oct 2017, 17:45
by derz00
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:

Re: Studio API

Posted: 10 Oct 2017, 20:02
by Delta Pythagorean
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

Re: Studio API

Posted: 11 Oct 2017, 05:34
by derz00
Hi Delta, That won't work. xD Should come up with a way to do that though... Kinda separate from my current issue

Re: Studio API

Posted: 11 Oct 2017, 06:17
by maestrith
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?

Re: Studio API

Posted: 11 Oct 2017, 07:13
by derz00
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?

Re: Studio API

Posted: 11 Oct 2017, 08:42
by maestrith
SplitPath,File,Filename,Dir,exte
Run,"C:\Program Files (x86)\AutoHotkey-v2\AutoHotkeyU64.exe" "%file%",%Dir% ;<-----The ,%Dir% sets the working directory