REM    _____________________________________________________
REM   |\___________________________________________________/| 
REM   | |                                                 | |
REM   | | SOURCE TITLE:    Garrett's Editor               | |
REM   | | ------------                                    | |
REM   | | SOURCE AUTHOR:   Based on sources from NoNarb   | |
REM   | | -------------    and by Garrett R. Hylltun      | |
REM   | |                                                 | |
REM   | | DATE:            ?? March, 1999                 | |
REM   | | ----                                            | |
REM   | | REQUIREMENTS:    VDS 3.x                        | |
REM   | | ------------                                    | |
REM   | | SOURCE STATUS:   Public Domain                  | |
REM   | | -------------                                   | |
REM   | | SOURCE DESCRIPTION:                             | |
REM   | | ------------------                              | |
REM   | |   Somewhat long and maybe complicated example   | |
REM   | | of how to make a notepad type program with      | |
REM   | | VDS.  I originally started my own example       | |
REM   | | while beta testing VDS 3.0, but soon after that | |
REM   | | Nobnarb shared his work, and I took the best of | |
REM   | | both sources and made this example.             | |
REM   | |                                                 | |
REM   | |   I think you really need to be familiar with   | |
REM   | | VDS to get through this one, but I could be     | |
REM   | | wrong.                                          | |
REM   | |                                                 | |
REM   | |   There is even a "Recent" used files routine   | |
REM   | | included.                                       | |
REM   | |                                                 | |
REM   | |   There is absolutely no Commenting with this.  | |
REM   | | So use and tinker at your own risk.             | |
REM   | |_________________________________________________| |
REM   |/___________________________________________________\|



:BEGINTHESHOW
  LIST CREATE,1
  LIST LOADFILE,1,@shortname(@path(%0))\edsys.ini
  %%A1 = @item(1)
  If @null(%%A1)
    LIST CLOSE,1
    Goto INITIALIZESETTINGS
  End
  LIST CLOSE,1

  %a = "NEW DOCUMENT"
TITLE Garrett's Editor - [ @upper(%a) ]
option errortrap,evloop 
DIALOG CREATE,Garrett's Editor - [ @upper(%a) ],-1,0,590,380,RESIZABLE
DIALOG ADD,STYLE,STYLE1,Courier New
DIALOG ADD,MENU,&File,&New|Ctrl+N,&Open...|Ctrl+O,&Save|Ctrl+S,Save &As...|Ctrl+A,-,&Print|Ctrl+P,-,Recent Files...|d:\myapps\arrow.bmp,-,E&xit|Alt+X
DIALOG ADD,MENU,&Edit,&Undo|Ctrl+Z,-,Cu&t|Ctrl+X,&Copy|Ctrl+C,&Paste|Ctrl+V,&Delete|Ctrl+D,-,Select &All|Alt+A
DIALOG ADD,MENU,&Search,
DIALOG ADD,MENU,&Tools,
DIALOG ADD,MENU,&Options,
DIALOG ADD,MENU,&Help,&Help,&About
DIALOG ADD,EDIT,EDIT1,0,0,590,360,,Multi,scroll,wrap,style1
DIALOG ADD,STATUS,STATUS1,IDLE
  DIALOG SHOW

TITLE About
DIALOG CREATE,About,-1,0,240,160,NOMIN,NOSYS,SMALLCAP
DIALOG ADD,STYLE,STYLE1,Arial,12,BR,,BLACK
DIALOG ADD,STYLE,STYLE2,Arial,12,BR,,DKBLUE
DIALOG ADD,STYLE,STYLE3,Arial,12,BR,,LTBLUE
DIALOG ADD,STYLE,STYLE4,Arial,12,BR,,CYAN
DIALOG ADD,STYLE,STYLE5,Arial,12,BR,,LTGREEN
DIALOG ADD,STYLE,STYLE6,Arial,12,BR,,DKGREEN
DIALOG ADD,STYLE,STYLE7,Arial,12,BR,,MAGENTA
DIALOG ADD,STYLE,STYLE8,Arial,12,BR,,DKRED
DIALOG ADD,STYLE,STYLE9,Arial,12,BR,,RED
DIALOG ADD,STYLE,STYLE10,Arial,12,BR,,YELLOW
DIALOG ADD,STYLE,STYLE11,Arial,12,BR,,WHITE
DIALOG ADD,STYLE,STYLE12,Arial,12,BR,,SILVER
DIALOG ADD,STYLE,STYLE13,Arial,12,BR,,GRAY
DIALOG ADD,BITMAP,BITMAP1,8,8,32,32,%0,HAND
DIALOG ADD,TEXT,TEXT01,10,52,172,36,"It's just another Text Editor Example"@CHR(13)"<<- Click to visit VDS on the web."
DIALOG ADD,TEXT,TEXT02,48,20,204,36,"This example brought to you by: Garrett"
DIALOG ADD,TEXT,TEXT03,104,20,204,36,"Release date: ?? March, 1999"
DIALOG ADD,BUTTON,BUTTON1,128,166,64,24,Ok
DIALOG ADD,PROGRESS,PROGRESS1,70,13,2,24
DIALOG ADD,PROGRESS,PROGRESS2,70,222,2,24
DIALOG ADD,TEXT,TEXT1,72,16,204,,,STYLE1
DIALOG ADD,TEXT,TEXT2,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE2
DIALOG ADD,TEXT,TEXT3,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE3
DIALOG ADD,TEXT,TEXT4,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE4
DIALOG ADD,TEXT,TEXT5,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE5
DIALOG ADD,TEXT,TEXT6,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE6
DIALOG ADD,TEXT,TEXT7,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE7
DIALOG ADD,TEXT,TEXT8,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE8
DIALOG ADD,TEXT,TEXT9,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE9
DIALOG ADD,TEXT,TEXT10,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE10
DIALOG ADD,TEXT,TEXT11,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE11
DIALOG ADD,TEXT,TEXT12,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE12
DIALOG ADD,TEXT,TEXT13,72,16,204,,"Visual DialogScript 3.0 ! ! ! ",STYLE13
  DIALOG SELECT,1
%X = 1
REPEAT
  %X = @sum(%X,1)
  DIALOG HIDE,TEXT%X
Until @equal(%X,13)
  DIALOG SELECT,0
  %Z = @winexists(~EDIT1)
  %A = @sendmsg(@win(~edit1),213,0,0)
rem warn %A

:evloop
  wait event
  %E = @event()
  If @equal(@substr(%E,2,3),":\")
    goto OPENRECENT
  End
  If @equal(%E,"(empty)MENU")
    goto OPENRECENT
  End
  If @equal(%E,Close)
    goto Close
  End
  If %E
    goto %E
  goto evloop

:TIMER
  
  goto evloop
  
REM ---------- File Menu Functions ----------

:NewMENU
  dialog clear,edit1
  dialog title,Garrett's Editor - [ NEW DOCUMENT ]
  dialog set,status1,IDLE
  goto evloop
	 
:Open...MENU
  DIALOG SET,STATUS1,Working........
  %a = @filedlg(*.txt)
  if @null(%a)
    DIALOG SET,STATUS,IDLE
    goto evloop
  end
:OPENALTERNATE
  LIST CREATE,2
  LIST LOADFILE,2,%a
  DIALOG TITLE,Garrett's Editor - [ @upper(%a) ]
  %B = @text(2)
  DIALOG SET,EDIT1,%B
  LIST CLOSE,2
  DIALOG SET,STATUS1,File loaded
goto SAVERECENT

:SaveMENU
	if @equal(%a,NEW DOCUMENT)
		goto Save asMENU
	end
  LIST CREATE,2
  LIST ASSIGN,2,@dlgtext(EDIT1)
  LIST SAVEFILE,2,%a
  LIST CLOSE,2
  DIALOG SET,STATUS1,File Save completed
goto evloop

:Save As...MENU
  DIALOG SET,STATUS1,Working........
  %a = @filedlg("Text Files (*.txt)|*.txt|All Files (*.*)|*.*",Save File As)
  if @null(%a)
    DIALOG SET,STATUS1,Idle...
    goto evloop
  end
:SaveAsErrorChecks
  if @null(@ext(%a))
    If @query(There is no file extension on this @chr(34)Save As@chr(34) command such @chr(13)as .txt. would you like to add an Extension now?)
      If @ok()
	    %e = @input(Add file extension:,.txt)
	    %a = %a%e
		goto SaveAsErrorChecks
	  End
	End
  End
  LIST CREATE,2
  LIST ASSIGN,2,@dlgtext(EDIT1)
  LIST SAVEFILE,2,%a
  LIST CLOSE,2
  dialog title,Garrett's Editor - [ @upper(%a) ]
  DIALOG SET,STATUS1,File Save As completed
goto evloop

:OPENRECENT
  If @equal(%E,"(empty)MENU")
    Warn This is an empty entry.  Please select an entry that has a file in it.
	goto evloop
  End
  %%Length = @len(%E)
  %a = @substr(%E,1,@fsub(%%Length,4))
goto OPENALTERNATE

:Recent Files...MENU
  INIFILE OPEN,@shortname(@path(%0))\edsys.ini
    %%Recent1 = @iniread(Recent Files,Recent1)
    %%Recent2 = @iniread(Recent Files,Recent2)
    %%Recent3 = @iniread(Recent Files,Recent3)
    %%Recent4 = @iniread(Recent Files,Recent4)
    %%Recent5 = @iniread(Recent Files,Recent5)
    %%Recent6 = @iniread(Recent Files,Recent6)
    %%Recent7 = @iniread(Recent Files,Recent7)
	DIALOG POPUP, %%Recent1|%%Recent2|%%Recent3|%%Recent4|%%Recent5|%%Recent6|%%Recent7
goto evloop
	
:ExitMENU
:CLOSE
exit

REM ---------- Edit Menu Functions ----------

:UndoMENU
	%E = @sendmsg(%Z,$0304,0,0)
	goto evloop

:CutMENU
	%E = @sendmsg(%Z,$0300,0,0)
	goto evloop
goto evloop

:CopyMENU
	%E = @sendmsg(%Z,$0301,0,0)
	goto evloop
goto evloop

:PasteMENU
	%E = @sendmsg(%Z,$0302,0,0)
	goto evloop
goto evloop

:DeleteMENU
goto evloop

:Select AllMENU
	dialog focus,Editor
	%E = @sendmsg(%Z,$0B1,0,-1)
	goto evloop


REM ---------- Help Menu Fundtion ----------

:HelpMENU
  Info "Help?? You don't need no stinking HELP!!  It's a text editor.. Just use it!"
goto evloop

REM ---------- About Box ----------

:AboutMENU
  Play @windir()\media\The Microsoft Sound.wav
  DIALOG SELECT,1
  DIALOG SHOW
  OPTION SLEEPTIME, 100
  %C = 0
  %I = "Visual DialogScript 3.0 ! ! ! "
  %X = 1
:AboutLoop
  If @not(@greater(%C,30))
    %C = @sum(%C,1)
    wait 0
    DIALOG SET,TEXT1,@substr(%I,1,%C)
  Else
    OPTION SLEEPTIME, 150
    repeat
	  DIALOG HIDE,TEXT%X
	  %X = @sum(%X,1)
	  DIALOG SHOW,TEXT%X
	    %E = @event()
	    If @equal(%E,BUTTON1BUTTON)
          goto BUTTON1BUTTON
        End
		If @equal(%E,BITMAP1CLICK)
          goto BITMAP1CLICK
        End
	  wait 0
	Until @equal(%X,13)
	DIALOG HIDE,TEXT13
	DIALOG SHOW,TEXT1
	%X = 1
  End
  %E = @event()
  If @equal(%E,BUTTON1BUTTON)
    goto BUTTON1BUTTON
  End
  If @equal(%E,BITMAP1CLICK)
    goto BITMAP1CLICK
  End
goto AboutLoop

:BITMAP1CLICK
  RUN http://www.dialogscript.com/
goto AboutLoop

:BUTTON1BUTTON
  DIALOG HIDE
  DIALOG SELECT,0
goto evloop

REM ---------- Internal Functions ----------

:RESIZE
  parse "%f;%b;%c;%d",@dlgpos(,LTWH)
  DIALOG SETPOS,EDIT1,0,0,@diff(%c,0),@diff(%d,21)
goto evloop

:SAVERECENT
  LIST CREATE,3
  INIFILE OPEN,@shortname(@path(%0))\edsys.ini
  %%INI_Recent1 = @iniread(Recent Files,Recent1)
  LIST ADD,3,%%INI_Recent1
  %%INI_Recent2 = @iniread(Recent Files,Recent2)
  LIST ADD,3,%%INI_Recent2
  %%INI_Recent3 = @iniread(Recent Files,Recent3)
  LIST ADD,3,%%INI_Recent3
  %%INI_Recent4 = @iniread(Recent Files,Recent4)
  LIST ADD,3,%%INI_Recent4
  %%INI_Recent5 = @iniread(Recent Files,Recent5)
  LIST ADD,3,%%INI_Recent5
  %%INI_Recent6 = @iniread(Recent Files,Recent6)
  LIST ADD,3,%%INI_Recent6
  %%INI_Recent7 = @iniread(Recent Files,Recent7)
  LIST ADD,3,%%INI_Recent7
  LIST SEEK,3,0
  %%FindMatch = @match(3,%a)
  If @equal(%%FindMatch,1)
    LIST DELETE,3
	LIST SEEK,3,0
  End
  LIST SEEK,3,0
  LIST INSERT,3,%a
  LIST SEEK,3,0
  INIFILE OPEN,@shortname(@path(%0))\edsys.ini
  INIFILE WRITE,Recent Files,Recent1,@item(3)
  %%NextItem = @next(3)
  INIFILE WRITE,Recent Files,Recent2,@item(3)
  %%NextItem = @next(3)
  INIFILE WRITE,Recent Files,Recent3,@item(3)
  %%NextItem = @next(3)
  INIFILE WRITE,Recent Files,Recent4,@item(3)
  %%NextItem = @next(3)
  INIFILE WRITE,Recent Files,Recent5,@item(3)
  %%NextItem = @next(3)
  INIFILE WRITE,Recent Files,Recent6,@item(3)
  %%NextItem = @next(3)
  INIFILE WRITE,Recent Files,Recent7,@item(3)
  %%NextItem = @next(3)
  LIST CLOSE,3
    INIFILE OPEN,@shortname(@path(%0))\edsys.ini
    %%Recent1 = @iniread(Recent Files,Recent1)
    %%Recent2 = @iniread(Recent Files,Recent2)
    %%Recent3 = @iniread(Recent Files,Recent3)
    %%Recent4 = @iniread(Recent Files,Recent4)
    %%Recent5 = @iniread(Recent Files,Recent5)
    %%Recent6 = @iniread(Recent Files,Recent6)
    %%Recent7 = @iniread(Recent Files,Recent7)
	goto evloop

:error
goto evloop

:INITIALIZESETTINGS
  LIST CREATE,1
  LIST ADD,1,[Main]
  LIST ADD,1,Status=1
  LIST ADD,1,T=
  LIST ADD,1,L=
  LIST ADD,1,H=
  LIST ADD,1,W=
  LIST ADD,1," "
  LIST ADD,1,[Recent Files]
  LIST ADD,1,"Recent1=(empty)"
  LIST ADD,1,"Recent2=(empty)"
  LIST ADD,1,"Recent3=(empty)"
  LIST ADD,1,"Recent4=(empty)"
  LIST ADD,1,"Recent5=(empty)"
  LIST ADD,1,"Recent6=(empty)"
  LIST ADD,1,"Recent7=(empty)"
  LIST ADD,1,
  LIST ADD,1,
  LIST ADD,1,
  LIST ADD,1,
  LIST SAVEFILE,1,@shortname(@path(%0))\edsys.ini
  LIST CLOSE,1
  GOTO BEGINTHESHOW