View previous topic :: View next topic |
Author |
Message |
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sat Feb 23, 2002 11:55 pm Post subject: VDS Text Editor |
|
|
I'm sure most of you remember this text editor,
I'm including the original description for new users.
Fixed another bug (using spaces in command line
filenames/directories). This has been my default
editor in Windows for a while, so I'll post bugs/fixes
if I find any more.
** VDS3 & VDS4 compatible **
Here's a text editor that uses several of
Julian Moss's routines, but I added the
ability to set the font size, either bold or
normal text (you could add italics and
bold italics if you want), and word wrap.
You can set these without exiting the
program.
The options automatically apply to any
text you are viewing. However, word wrap
and other modifications will not affect the
file itself, it's always saved as plain text.
The font size is also used in the print
procedure.
"Word Wrap" and "Bold Text" menu items
will have ">>" in front of them when the
option is active.
_______________________________________________________________________________________________________________________________________________________________________________________
Code: |
rem -- VDS3 & VDS4 compatible --
rem -- Some of these routines were designed by Julian Moss --
rem -- Added ability to change font size, normal or bold text,
rem -- and set word wrap without exiting the program --
rem -- Creates DAT file ([program name].DAT) to save settings --
rem -- Filename (check for command line filename with spaces) --
if %1
%f = @trim(%1 %2 %3 %4 %5 %6 %7 %8 %9)
end
if @file(%f)
if @greater(@file(%f, Z), 32000)
if @ask("File is too large for this program."@tab()@cr()@cr()"Use Wordpad instead?")
RUN Wordpad.exe %f
EXIT
else
%f = "Untitled"
end
end
else
%f = "Untitled"
end
rem -- Check for DAT file with settings (DO NOT close/clear list 2) --
rem -- Items: 0 = fontsize, 1 = fontstyle, 2 = WRAP/NOWRAP, 3 = tabstop
rem -- Items: 4 - 11 = last 8 files opened (if applicable).
LIST CREATE, 2
if @file(@path(%0)@name(%0).DAT)
LIST LOADFILE, 2, @path(%0)@name(%0).DAT
else
rem -- Create DAT file if not found --
LIST ADD, 2, "10"
LIST ADD, 2, "N"
LIST ADD, 2, "NOWRAP"
LIST ADD, 2, "8"
LIST SAVEFILE, 2, @path(%0)@name(%0).DAT
end
if @greater(@count(2), 3)
%%fontsize = @item(2, 0)
%%fontstyle = @item(2, 1)
if @equal(%%fontstyle, "B")
%%bold = ">>"
end
if @equal(@item(2, 2), "WRAP")
%%wordwrap = @item(2, 2)
%%wrap = ">>"
else
%%wordwrap = ""
end
if @numeric(@item(2, 3))
%%stops = @item(2, 3)
else
%%stops = 8
end
else
rem -- DAT file must be corrupt, replace it and use defaults --
LIST CLEAR, 2
LIST ADD, 2, "10"
LIST ADD, 2, "N"
LIST ADD, 2, "NOWRAP"
LIST ADD, 2, "8"
LIST SAVEFILE, 2, @path(%0)@name(%0).DAT
%%fontsize = 10
%%fontstyle = N
%%wordwrap = ""
%%stops = 8
end
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Mac's Editor - %f,20,0,632,388,RESIZABLE
rem -- Normal fonts --
DIALOG ADD,STYLE,Style08N,Courier New,8,,WHITE
DIALOG ADD,STYLE,Style09N,Courier New,9,,WHITE
DIALOG ADD,STYLE,Style10N,Courier New,10,,WHITE
DIALOG ADD,STYLE,Style11N,Courier New,11,,WHITE
DIALOG ADD,STYLE,Style12N,Courier New,12,,WHITE
rem -- Bold fonts --
DIALOG ADD,STYLE,Style08B,Courier New,8,B,WHITE
DIALOG ADD,STYLE,Style09B,Courier New,9,B,WHITE
DIALOG ADD,STYLE,Style10B,Courier New,10,B,WHITE
DIALOG ADD,STYLE,Style11B,Courier New,11,B,WHITE
DIALOG ADD,STYLE,Style12B,Courier New,12,B,WHITE
DIALOG ADD,EDIT,E1,0,0,632,368,,,MULTI,SCROLL,TABS,%%wordwrap,Style%%fontsize%%fontstyle
DIALOG ADD,MENU,&File,&New|Ctrl+N,&Open|Ctrl+O,&Save|Ctrl+S,Save &As,-,&Recent Files|Ctrl+R,-,&Print|Ctrl+P,-,E&xit|Alt+X
DIALOG ADD,MENU,&Edit,Cu&t|Ctrl+X,&Copy|Ctrl+C,&Paste|Ctrl+V,-,Select &All|Ctrl+A,-,&Find|Ctrl+F,Find &Next|F3,-,&Options|Alt+O
DIALOG ADD,STATUS,Stat,"Line 1 Col 1"
DIALOG SHOW
rem -- Get ID of edit element for use in @sendmsg() --
%q = @winexists(~E1)
rem -- Set tabstops --
%z = @sendmsg(%q,$0CB,1,@chr(@prod(%%stops, 4)))
GOSUB GetFontSize
rem -- Load file from command line --
if @file(%f)
GOSUB LoadFile
end
:EVLOOP
WAIT EVENT, "0.1"
%e = @event()
if @equal(@substr(%e,2), ".")
goto Recent
end
goto %e
:TIMER
rem -- Get line number (use %c to get a start point) --
%c = @sendmsg(%q,$0BB,-1,0)
%l = @succ(@sendmsg(%q,$0C9,%c,0))
rem -- Get total number of lines in document --
%n = @sendmsg(%q,$0BA,0,0)
rem -- Get character position in edit line (complicated) --
%c = @mod(@sendmsg(%q,$0B0,0,0),65536)
%c = @mod(@sendmsg(%q,214,%c,0),65536)
if @greater(0,%c)
%c = @sum(%c,65536)
end
if @greater(%c,32768)
%c = @diff(%c,65536)
end
%z = @mod(@sendmsg(%q,214,0,0),65536)
if @greater(0,%z)
%z = @sum(%z,65536)
end
if @greater(%z,32768)
%z = @diff(%z,65536)
end
%c = @succ(@div(@diff(%c,%z),%%charwidth))
rem -- Check if document has been modified --
if @zero(@sendmsg(%q,$0B8,0,0))
%m = ""
else
%m = Modified
end
DIALOG SET, Stat, "Line " %l" of "%n" lines Col "%c" "%m" "@len(@dlgtext(E1))" bytes"
goto EVLOOP
:RESIZE
PARSE "%h;%w", @dlgpos(,HW)
DIALOG SETPOS,E1,0,0,%w,@diff(%h,20)
goto EVLOOP
:NewMENU
if %m
%z = @msgbox(Text has been been modified. Save changes?,Save File,$003)
if @equal(%z, 2)
goto EVLOOP
end
if @equal(%z, 6)
if @equal(%f, "Untitled")
%f = @filedlg(,,,SAVE)
end
if %f
GOSUB SaveFile
else
%f = "Untitled"
goto EVLOOP
end
end
end
DIALOG CLEAR, E1
%f = "Untitled"
rem -- Clear "text modified" flag --
%z = @sendmsg(%q,$0B9,0,0)
DIALOG TITLE, "Mac's Editor - "%f
goto EVLOOP
:OpenMENU
if %m
%z = @msgbox(Text has been been modified. Save changes?,Save File,$003)
if @equal(%z, 2)
goto EVLOOP
end
if @equal(%z, 6)
if @equal(%f, "Untitled")
%f = @filedlg(,,,SAVE)
end
if %f
GOSUB SaveFile
else
%f = "Untitled"
goto EVLOOP
end
end
end
%f = @filedlg()
:Open2
if %f
if @greater(@file(%f, Z), 32000)
if @ask("File is too large for this program."@tab()@cr()@cr()"Use Wordpad instead?")
RUN Wordpad.exe %f
EXIT
end
else
gosub LoadFile
end
end
goto EVLOOP
:SaveMENU
if @equal(%f, "Untitled")
goto Save asMENU
else
if %f
GOSUB SaveFile
end
end
goto EVLOOP
:Save asMENU
if %f
%g = %f
else
%g = "Untitled"
end
%f = @filedlg(,,,SAVE)
if %f
if @file(%f)
if @ask("File already exists. Overwrite it?"@tab())
GOSUB SaveFile
end
else
GOSUB SaveFile
end
else
%f = %g
end
goto EVLOOP
:Recent FilesMENU
DIALOG POPUP,1.@item(2,4)|2.@item(2,5)|3.@item(2,6)|4.@item(2,7)|5.@item(2,8)|6.@item(2,9)|7.@item(2,10)|8.@item(2,11),-5,0
goto EVLOOP
:Recent
if @greater(@len(%e), 6)
if %m
%z = @msgbox(Text has been been modified. Save changes?,Save File,$003)
if @equal(%z, 2)
goto EVLOOP
end
if @equal(%z, 6)
if @equal(%f, "Untitled")
%f = @filedlg(,,,SAVE)
end
if %f
GOSUB SaveFile
else
%f = "Untitled"
goto EVLOOP
end
end
end
%f = @substr(%e, 3, @diff(@len(%e), 4))
goto Open2
end
goto EVLOOP
:PrintMENU
if @dlgtext(E1)
if @not(@ask(Is printer ready?))
goto EVLOOP
end
LIST CREATE, 1
LIST ASSIGN, 1, @dlgtext(E1)
%z = @input("Enter left margin spaces for printing:", 0)
%s = ""
if @numeric(%z)
if @greater(%z, 0)
%x = 0
REPEAT
%s = %s" "
%x = @succ(%x)
UNTIL @equal(%x, %z)
%x = 0
REPEAT
%z = @item(1, %x)
LIST PUT, 1, %s%z
%x = @succ(%x)
UNTIL @equal(%x, @count(1))
end
end
LIST PRINT, 1, Courier New, %%fontsize
LIST CLOSE, 1
end
goto EVLOOP
:ExitMENU
:CLOSE
if %m
%z = @msgbox(Text has been been modified. Save changes?,Save File,$003)
if @equal(%z, 2)
goto EVLOOP
end
if @equal(%z, 6)
if @equal(%f, "Untitled")
%f = @filedlg(,,,SAVE)
end
if %f
GOSUB SaveFile
else
%f = "Untitled"
goto EVLOOP
end
end
WAIT
end
LIST SAVEFILE, 2, @path(%0)@name(%0).DAT
WAIT "0.1"
EXIT
STOP
:FindMENU
%t = @input(Enter text to search for:)
if %t
%s = @pred(@pos(%t,@dlgtext(E1)))
if @greater(%s,-1)
gosub SelectText
else
INFO Text not found @tab()
end
end
goto EVLOOP
:Find NextMENU
if %t
%p = @pos(%t,@strdel(@dlgtext(E1),1,@succ(%s)))
if @greater(%p,0)
%s = @sum(%s,%p)
gosub SelectText
else
INFO Text not found @tab()
end
end
goto EVLOOP
:OptionsMENU
DIALOG POPUP, %%wrap Word Wrap...|%%bold Bold Text...| Font Size...| Set Tab Stops...,-5,24
goto EVLOOP
: Word Wrap...MENU
:>> Word Wrap...MENU
LIST SEEK, 2, 2
if %%wrap
%%wrap = ""
%%wordwrap = ""
LIST PUT, 2, NOWRAP
else
%%wrap = ">>"
%%wordwrap = WRAP
LIST PUT, 2, WRAP
end
GOSUB SetOptions
goto EVLOOP
: Bold Text...MENU
:>> Bold Text...MENU
LIST SEEK, 2, 1
if %%bold
%%bold = ""
%%fontstyle = N
LIST PUT, 2, N
else
%%bold = ">>"
%%fontstyle = B
LIST PUT, 2, B
end
GOSUB SetOptions
goto EVLOOP
: Font Size...MENU
DIALOG POPUP,08|09|10|11|12,-5,24
goto EVLOOP
:08MENU
:09MENU
:10MENU
:11MENU
:12MENU
%%fontsize = @substr(%e,1,2)
LIST SEEK, 2, 0
LIST PUT, 2, %%fontsize
GOSUB SetOptions
goto EVLOOP
: Set Tab Stops...MENU
%t = @input("Enter tab stop interval (0 - 8):", %%stops)
if @numeric(%t)
if @both(@greater(%t,0),@greater(9,%t))
%z = @sendmsg(%q,$0CB,1,@chr(@prod(%t,4)))
%%stops = %t
LIST SEEK, 2, 3
LIST PUT, 2, %%stops
end
end
goto EVLOOP
:Select AllMENU
rem -- Select all text --
DIALOG FOCUS, E1
%z = @sendmsg(%q,$0B1,0,-1)
goto EVLOOP
:CopyMENU
%z = @sendmsg(%q,$0301,0,0)
goto EVLOOP
:CutMENU
rem -- Copy selected text --
%z = @sendmsg(%q,$0301,0,0)
rem -- Remove selected text --
%z = @sendmsg(%q,$0C2,0,)
goto EVLOOP
:PasteMENU
%z = @sendmsg(%q,$0302,0,0)
goto EVLOOP
rem ---------------- GOSUB PROCEDURES ------------------
:SetOptions
LIST CREATE, 1
LIST ASSIGN, 1, @dlgtext(E1)
DIALOG REMOVE, E1
WAIT "0.1"
DIALOG ADD,EDIT,E1,0,0,632,368,,,MULTI,SCROLL,TABS,%%wordwrap,Style%%fontsize%%fontstyle
rem -- In case ID changes when E1 is recreated --
%q = @winexists(~E1)
DIALOG SET, E1, @text(1)
LIST CLOSE, 1
rem -- set tabstops --
%z = @sendmsg(%q,$0CB,1,@chr(@prod(%%stops, 4)))
rem -- Send click to current mousepos so cursor shows again --
PARSE "%%mx;%%my", @mousepos(XY)
WINDOW CLICK, %q, %%my, %%mx
:GetFontSize
rem -- Get character width of current font size character --
DIALOG ADD,TEXT,DummyTxt,0,0,,,"A",Style%%fontsize%%fontstyle
%%charwidth = @dlgpos(DummyTxt,W)
DIALOG REMOVE, DummyTxt
rem -- Set "text modified" flag --
if %m
%z = @sendmsg(%q,$0B9,1,0)
end
exit
:LoadFile
LIST CREATE, 1
LIST LOADFILE, 1, %f
DIALOG SET, E1, @text(1)
LIST CLOSE, 1
rem -- Clear "text modified" flag --
%z = @sendmsg(%q,$0B9,0,0)
DIALOG TITLE, "Mac's Editor - "%f
GOSUB AddToRecent
rem -- Send UP arrow key a few times so cursor shows again --
WINDOW SEND, %q, @key(UP)@key(UP)@key(UP)
exit
:SaveFile
LIST CREATE, 1
LIST ASSIGN, 1, @dlgtext(E1)
LIST SAVEFILE, 1, %f
LIST CLOSE, 1
rem -- Clear "text modified" flag --
%z = @sendmsg(%q,$0B9,0,0)
DIALOG TITLE, "Mac's Editor - "%f
GOSUB AddToRecent
exit
:SelectText
rem -- Select text found --
%z = @sendmsg(%q,$0B1,%s,@sum(%s,@len(%t)))
rem -- Scroll selected text (caret) into view --
%z = @sendmsg(%q,$0B7,0,0)
exit
:AddToRecent
rem -- Add to recent files and trim list --
if @not(@equal(@item(2, 4), %f))
LIST INSERT, 2, %f
if @greater(@count(2), 12)
LIST SEEK, 2, 12
LIST DELETE, 2
end
end
exit
|
EDIT 1
Fixed prompt to save modified text whether options
are changed or not. _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Last edited by Mac on Sun Feb 24, 2002 7:59 am; edited 2 times in total |
|
Back to top |
|
|
Zoltar VDS Pirate
Joined: 26 Dec 2001 Posts: 91
|
Posted: Sun Feb 24, 2002 7:09 am Post subject: |
|
|
Hi Mac
another bug for you
if uou write some txt without saving, and you choose somme
of the options.
When you will quit, the modified text is not detected.
It quit without asking to save
Bye _________________ Zoltar
http://membres.lycos.fr/ |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Feb 24, 2002 7:49 am Post subject: |
|
|
Thanks Zoltar.
That one is now fixed... _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Mon Feb 25, 2002 2:06 pm Post subject: |
|
|
Hi again, Mac!
This is a very nice piece of code! A have a little bug for you, though:
When you start typing, the Col indicator in the status bar will indicate
position 1 all the time. Only when the cursor is placed to the left of the
last char in the file, the actual position will be shown.
Greetz
Dread
_________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing
Last edited by Dr. Dread on Tue Feb 26, 2002 12:08 pm; edited 1 time in total |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Mon Feb 25, 2002 10:05 pm Post subject: |
|
|
Hiya Dread,
Yeah, if I was Bill Gates I could call that "feature"... lol
The column count code is from Julian Moss's original
example, and I haven't been able to come up with a
way to make it show the count unless the cursor is
in front of a char (I guess that's because when there's
no char, it has nothing to go on...). Actually, I was pretty
happy to get a column count at all since NOTEPAD doesn't
have one. And this is basically a NOTEPAD replacement.
I have experimented with it some, and by inserting this
code: %c = @pred(%c) at line 123 (after this line:
%c = @mod(@sendmsg(%q,$0B0,0,0),65536)),
it gives the column count BEFORE the cursor continously.
However, on a new line it also increments the previous
line's last column until a char is entered on the new line.
I'd be happy if anyone can come up with a solution...
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Feb 26, 2002 12:07 pm Post subject: |
|
|
I see what you mean, Mac!
This is one tough moth........ I've been trying to figure it out,
but I'm in over my head here, I'm afraid.
By the way, if someone's looking for a really powerful Notepad replacement
(besides yours, Mac, of course ) with some really useful tools and only
41K in size, then have a look at Metapad:
http://liquidninja.com/metapad/
I can only recommend this one - and it's freeware.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Apr 18, 2002 8:07 pm Post subject: |
|
|
Minor bug fix:
Added current directory to file path on command line
if not already included (files without a full path in the
"recent files" menu were not accessible from a different
directory).
Cheers, Mac
BTW, this program is approx 16k compiled in VDS 3
(not counting the VDSRUN DLL of course...). _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Apr 28, 2002 7:33 pm Post subject: |
|
|
Minor bug fix in command line parameters:
Fixed bug in command line path (had forgot to check
and allow for "\" in root drive dir) when loading files
from the command line.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
nemisis010 Newbie
Joined: 29 May 2002 Posts: 17 Location: Australia
|
Posted: Fri May 31, 2002 3:21 am Post subject: LOOOOONG! |
|
|
DAM, thats one long peice of code!! 8O 8O _________________ ------------------------------------
Boo |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|