Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

A scripting pad


  • Please log in to reply
No replies to this topic
iason
  • Members
  • 135 posts
  • Last active: Dec 14 2010 04:42 PM
  • Joined: 01 Nov 2005
One more scripting pad

This is some work based on a simple script that resides in the autohotkey help file, in the GUI page. Seems good for general scripting -- .ahk .txt html etc. I couldn't settle some save shortcuts like CtrS or CtrQ because they mess with other windows hotkeys, but the simple menu simplifies the need.

With Autohotkey those machines are simply skyrocketing. Thanks guys. Enjoy!
Any suggestions will be much appreciated. Tweak to your hearts' desire.

#SingleInstance off
;#NoTrayIcon

gui, font, s10, Tahoma
gui, color, FF9B05

Menu, Bar, Add, •Open, FileOpen
Menu, Bar, Add, •Save, FileSave
Menu, Bar, Add, •Save as..., FileSaveAs
Menu, Bar, Add, •Save and Exit, SaveAndExit
Menu, Bar, Add, •Discard, Exit
Gui, Menu, Bar

Gui, +Resize 
Gui, font, s10
Gui, Add, Edit, vMainEdit WantTab r30 x5 y5, 
Gui, Show, w600 x0 y0, iasonpad - untitled
CurrentFileName = 
return

FileOpen:
FileSelectFile, SelectedFileName, 3,, iasonpad - Open File, 
if SelectedFileName =  
return
Gosub FileRead
return

FileRead:  
FileRead, MainEdit, %SelectedFileName%  
if ErrorLevel <> 0
{
MsgBox Could not open "%SelectedFileName%".
return
}
GuiControl,, MainEdit, %MainEdit%  
CurrentFileName = %SelectedFileName%
Gui, Show,, iasonpad - %CurrentFileName%
return

FileSave:
if CurrentFileName =  
Goto FileSaveAs
Gosub SaveCurrentFile
return

FileSaveAs:
FileSelectFile, SelectedFileName, S16, , iasonpad - save file, 
if SelectedFileName =  
return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
Gui, Show,, iasonpad - %CurrentFileName%
return

SaveCurrentFile:  
IfExist %CurrentFileName%
{
 FileDelete %CurrentFileName%
  if ErrorLevel <> 0
   {	
   MsgBox The attempt to overwrite "%CurrentFileName%" failed.
   return
   }
}
GuiControlGet, MainEdit 
FileAppend, %MainEdit%, %CurrentFileName% 
Gui, Show,, iasonpad - %CurrentFileName%
return

GuiDropFiles:
Loop, parse, A_GuiControlEvent, `n
{
SelectedFileName = %A_LoopField% 
break
}
Gosub FileRead
return

GuiSize:
if ErrorLevel = 1 
return
NewWidth := A_GuiWidth - 10
NewHeight := A_GuiHeight - 10
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return

SaveAndExit:
IfExist %CurrentFileName%
Gosub SaveCurrentFile
IfNotExist %CurrentFileName%
{
gosub FileSaveAs
return
}
ExitApp
return

GuiClose:				; what happens when closed...
IfNotExist %CurrentFileName%		; if not been saved previously
{
	msgbox, 3, iasonpad - exit, Save this new file or not?, 
	IfMsgBox, Yes
		{
		Gosub FileSaveAs
		if SelectedFileName =  
			return
		else
			ExitApp
		}
	IfMsgBox, No
		ExitApp
	IfMsgBox, Cancel
		return
}
IfExist %CurrentFileName%		; if already been saved
{
	msgbox, 3, iasonpad - exit, Save %CurrentFileName% before exit?, 
	IfMsgBox, Yes
		{
		FileDelete %CurrentFileName%
		if ErrorLevel <> 0
  			{
			MsgBox The attempt to overwrite "%CurrentFileName%" failed.
			return
			}
		GuiControlGet, MainEdit 
		FileAppend, %MainEdit%, %CurrentFileName% 
		ExitApp
		}
	IfMsgBox, No
		ExitApp
	IfMsgBox, Cancel
		return
}
return

Exit:
ExitApp

help to be helped