A bug removed from static variables code. This revision supposed the final one.
George Karras
\\ notepad for M2000 programs (gsb files) Show Clear \\ Clear all variables/objects Flush \\ Empty the stack Title$="M2000 Pad" Dir User Title Title$, 0 Declare NotePad Form Declare Pad EditBox Form NotePad Declare File1 Combobox Form NotePad Declare Edit1 Combobox Form NotePad Declare Help1 Combobox Form NotePad Declare Inform1 Button Form NotePad Method Inform1, "Colors", 15, #FFA000 With Inform1, "Locked", true Method Pad, "FontAttr", "Verdana", 12, true ' size=12, bold=true With Pad, "NoWrap", True, "SetM2000", True With File1,"label","File", "listtext" As list$, "list" As list$() ' With Edit1,"label","Edit", "Mark", Color(255,100,0) With Help1,"label","Help", "Mark", Color(255,100,0) With NotePad,"UseIcon", True, "UseReverse", True With NotePad, "Title" As Caption$, "Visible" As Visible, "TitleHeight" As tHeight, "Sizable", True \\ call MakeStandardInfo, after setting Sizable to true to enable contol box's maximize button. Method NotePad,"MakeStandardInfo", 1 With Pad, "Text" As Pad.Text$, "NoColor", False, "ShowAlways", True, "UseTab", True, "tabwidth", 6 Def TitleStr$(a$)=ucase$(left$(a$,1))+mid$(a$,2) Filename$=Dir$+"Untitled.gsb" Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad" Method NotePad,"move", 2000, 4000, 8000, 4000 Layer NotePad {Cls #FFA000} With File1,"MenuStyle", True, "MenuWidth", 4000 With Edit1,"MenuStyle", True, "MenuWidth", 4000 With Help1,"MenuStyle", True, "MenuWidth", 4000 With File1, "MenuEnabled" As mEnable() For This { mi$="MenuItem" \\ is a temporary variable only for For This Block Method File1, mi$,"Open",True Method File1, mi$,"Save",True Method File1, mi$,"" \\ only a line here Method File1, mi$,"Close",True Method File1, mi$,"Quit",True Rem Method File1, "Transparent" With File1, "MenuGroup","This" Method Edit1, mi$,"Cut",True Method Edit1, mi$,"Copy",True Method Edit1, mi$,"Paste",True Rem Method Edit1, "Transparent" With Edit1, "MenuGroup","This" Method Help1, mi$,"About",True Rem Method Help1, "Transparent" With Help1, "MenuGroup","This" } Document BackUp$="\\Write something..."
Pad.Text$=BackUp$ Function Notepad.Resize { Layer NotePad { Cls Color(255, 160, 0) ,0} With NotePad, "Width" As NP.Width, "Height" As NP.Height, "TitleHeight" As tHeight tHeight1=theight*2 Method File1,"move", twipsX*2, tHeight, twipsX*80, tHeight Method Edit1,"move", twipsX*2+twipsX*80, tHeight, twipsX*80, tHeight Method Help1,"move", twipsX*2+twipsX*160, tHeight, twipsX*80, tHeight Method Inform1,"move", twipsX*2+twipsX*240, tHeight, twipsX*160, tHeight If NP.height>2000 Then { Method Pad,"move", twipsX*2, tHeight1, NP.Width-twipsX*5, NP.Height-tHeight1-twipsx*3 With Pad, "NoWrap" As NoWrap If Not NoWrap Then Method Pad,"Resize" } } Function Pad.Inform { Read New L, P With Inform1, "Caption", format$("{0}-{1}", L,P) Method Pad,"Show" } Function Edit1.DblClick { Read New Edit1index Select Case Edit1index Case 0 Method Pad,"mn1sub" : Method Pad,"Resize" Case 1 Method Pad,"mn2sub" Case 2 Method Pad, "mn3sub" : Method Pad,"GetFocus" : Method Pad,"Resize" End Select } Function Pad.PopUp { Read Local X, Y Method Pad,"PopUpMenu", "",X , Y } Function File1.DblClick { Read New File1index Local cont, cont2, f$, NL$={ } File1index++ \\ Because we want some jumps..we use On Goto \\ on Goto need here a block { On File1index Goto Open1, Save1, ExitNow, Save2, Unload Exitnow: Exit Open1: If Pad.Text$<>BackUp$ Then { If ask("Save Changes first?",Title$)=1 Then Goto Save1 } Layer NotePad { Open.file filename$,"c:\","Load M2000 (Gsb) File","gsb" } Method Pad,"GetFocus" Read f$ If f$<>"" Then Filename$=f$ If exist(F$) then { Clear BackUp$ Load.Doc BackUp$, f$ Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad" Pad.Text$=BackUp$ } else Pad.text$="": Clear BackUp$ Method Pad, "Resize" End If Exit Save1: Layer NotePad { Save.As Filename$,"c:\","Save M2000 File","gsb" } if not cont2 then Method Pad,"GetFocus" Read f$ If f$="" Then Exit If lcase$(file.type$(f$))<>"gsb" then f$=f$+".gsb" If Exist(f$) Then If Ask(NL$+"Overwrite"+NL$+f$,Title$)<>1 Then Exit Try ok { Clear BackUp$ BackUp$=Pad.Text$ Save.Doc BackUp$, f$ filename$=f$ Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad" } If ok else beep If not cont then Exit Save2: cont=True If Pad.Text$<>BackUp$ Then { If ask("Save Changes?",Title$)=1 Then Goto Save1 } Clear BackUp$ Pad.Text$="" If Cont2 then Method NotePad, "CloseNow" Else FileName$=Dir$+"Untitled.gsb" Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad" Method Pad, "Resize" End If Exit Unload: Cont2=True : Goto Save2 } } Function Help1.DblClick { Local A, info$ Info$={ This is an example of a notepad for M2000 Programs written in M2000 and run in M2000 Environment } A=Ask(info$,Title$,"","") } Function Notepad.InfoClick { Read New X If X=0 then Call Local Help1.DblClick() } Call Local Notepad.Resize() \\ make this as the default control (get focus) With Pad,"Default",True \\ open As modal Method NotePad,"Show", 1 Declare Pad Nothing Declare NotePad Nothing Print "Done"