$INCLUDE "rapidq.inc"
CONST GWL_HWNDPARENT = -8
CONST HWND_DESKTOP = 0
DECLARE FUNCTION SetWindowLong LIB "user32" ALIAS "SetWindowLongA" (hwnd AS LONG, nIndex AS LONG, dwNewLong AS LONG) AS LONG
DIM active AS INTEGER
active = -1
DIM docs AS INTEGER
docs = 0
DECLARE SUB mnew
DECLARE SUB mopen
DECLARE SUB msave
DECLARE SUB msaveas
DECLARE SUB mexit
DECLARE SUB mcut
DECLARE SUB mcopy
DECLARE SUB mpaste
DECLARE SUB mselect
DECLARE SUB mfind
DECLARE SUB mwrap
DECLARE SUB mfont
DECLARE SUB mrun
DECLARE SUB mabout
DECLARE SUB tchange
DECLARE SUB change
DECLARE FUNCTION getfile(file$) AS STRING
DECLARE FUNCTION getdir(file$) AS STRING
DECLARE SUB keyed
DECLARE FUNCTION appendfilename(file$,typ) AS STRING
CREATE form AS QFORM
CAPTION = "Text Editor"
width = 400
center
CREATE tab AS QTABCONTROL
align = alclient
PARENT = form
onchange = tchange
multiline = 1
END CREATE
CREATE status AS QSTATUSBAR
align = albottom
addpanels "0:0", "", "No Open Documents"
END CREATE
END CREATE
setwindowlong(form.handle, GWL_HWNDPARENT, HWND_DESKTOP)
setwindowlong(application.handle, GWL_HWNDPARENT, form.handle)
status.panel(0).alignment = tacenter
status.panel(0).width = 50
status.PARENT = tab
status.sizegrip = 0
DIM editor(10) AS QRICHEDIT
FOR n = 0 TO 10
editor(n).plaintext = 1
editor(n).visible = 0
editor(n).PARENT = tab
editor(n).align = alclient
editor(n).onchange = change
editor(n).scrollbars = ssboth
editor(n).onkeydown = keyed
editor(n).onkeyup = keyed
editor(n).onmouseup = keyed
NEXT
DIM font AS QFONT
DIM fontdialog AS QFONTDIALOG
DIM filename(10) AS STRING
DIM filepath(10) AS STRING
DIM changed(10) AS INTEGER
DIM opendialog AS QOPENDIALOG
DIM savedialog AS QSAVEDIALOG
savedialog.filter = "Text Documents (*.txt)|*.txt|Basic Source Code (*.bas)|*.bas|Rapidq Source Code (*.rq)|*.rq|Web Pages (*.html)|*.html|All Files|*.*"
opendialog.filter = "Text Documents (*.txt)|*.txt|Basic Source Code (*.bas)|*.bas|Rapidq Source Code (*.rq)|*.rq|Web Pages (*.html)|*.html|All Files|*.*"
DIM main AS QMAINMENU
DIM file AS QMENUITEM
file.CAPTION = "&File"
DIM edit AS QMENUITEM
edit.CAPTION = "&Edit"
DIM search AS QMENUITEM
search.CAPTION = "&Search"
DIM options AS QMENUITEM
options.CAPTION = "&Options"
DIM help AS QMENUITEM
help.CAPTION = "&Help"
main.PARENT = form
main.additems file, edit, search, options, help
DIM mnunew AS QMENUITEM
mnunew.CAPTION = "&New"
mnunew.shortcut = "Ctrl+N"
mnunew.onclick = mnew
DIM mnuopen AS QMENUITEM
mnuopen.CAPTION = "&Open..."
mnuopen.shortcut = "Ctrl+O"
mnuopen.onclick = mopen
DIM mnusave AS QMENUITEM
mnusave.CAPTION = "&Save..."
mnusave.shortcut = "Ctrl+S"
mnusave.onclick = msave
DIM mnusaveas AS QMENUITEM
mnusaveas.CAPTION = "Save &As..."
mnusaveas.onclick = msaveas
DIM mnubreak AS QMENUITEM
mnubreak.CAPTION = "-"
DIM mnuexit AS QMENUITEM
mnuexit.CAPTION = "E&xit"
mnuexit.shortcut = "Alt+F4"
mnuexit.onclick = mexit
file.additems mnunew, mnuopen, mnusave, mnusaveas, mnubreak, mnuexit
DIM mnucut AS QMENUITEM
mnucut.CAPTION = "Cu&t"
mnucut.shortcut = "Ctrl+X"
mnucut.onclick = mcut
DIM mnucopy AS QMENUITEM
mnucopy.CAPTION = "&Copy"
mnucopy.shortcut = "Ctrl+C"
mnucopy.onclick = mcopy
DIM mnupaste AS QMENUITEM
mnupaste.CAPTION = "&Paste"
mnupaste.shortcut = "Ctrl+V"
mnupaste.onclick = mpaste
DIM mnuselect AS QMENUITEM
mnuselect.CAPTION = "Se&lect All"
mnuselect.shortcut = "Ctrl+A"
mnuselect.onclick = mselect
edit.additems mnucut, mnucopy, mnupaste, mnuselect
DIM mnufind AS QMENUITEM
mnufind.CAPTION = "&Find"
mnufind.onclick = mfind
search.additems mnufind
DIM mnuwrap AS QMENUITEM
mnuwrap.CAPTION = "&WordWrap"
mnuwrap.checked = 1
mnuwrap.onclick = mwrap
DIM mnufont AS QMENUITEM
mnufont.CAPTION = "&Font"
mnufont.onclick = mfont
DIM mnurun AS QMENUITEM
mnurun.CAPTION = "&Run"
mnurun.onclick = mrun
mnurun.shortcut = "F5"
options.additems mnuwrap, mnufont, mnurun
DIM mnuabout AS QMENUITEM
mnuabout.CAPTION = "&About"
mnuabout.onclick = mabout
help.additems mnuabout
SUB mopen
IF docs = 10 THEN
SHOWMESSAGE "11 is the maximum amount of documents..."
EXIT SUB
END IF
IF(opendialog.EXECUTE) THEN
docs = docs + 1
active = docs - 1
editor(active).loadfromfile(opendialog.filename)
tab.addtabs getfile(opendialog.filename)
filename(active) = getfile(opendialog.filename)
filepath(active) = getdir(opendialog.filename)
status.panel(2).CAPTION = filepath(active)
tab.tabindex = active
tchange
status.panel(1).CAPTION = ""
keyed
END IF
END SUB
SUB mnew
IF docs = 10 THEN
SHOWMESSAGE "11 is the maximum amount of documents..."
EXIT SUB
END IF
IF(savedialog.EXECUTE) THEN
savedialog.filename = appendfilename(savedialog.filename, savedialog.filterindex)
docs = docs + 1
active = docs - 1
tab.addtabs getfile(savedialog.filename)
filename(active) = getfile(savedialog.filename)
filepath(active) = getdir(savedialog.filename)
status.panel(2).CAPTION = filepath(active)
tab.tabindex = active
tchange
status.panel(1).CAPTION = ""
keyed
END IF
END SUB
SUB msave
IF FILEEXISTS(filepath(active) + "\" + filename(active)) THEN
KILL filepath(active) + "\" + filename(active)
END IF
SHOWMESSAGE(filepath(active) + "\" + filename(active))
editor(active).savetofile(filepath(active) + "\" + filename(active))
changed(active) = 0
status.panel(1).CAPTION = ""
END SUB
SUB msaveas
savedialog.initialdir = filepath(active)
savedialog.filename = filename(active)
IF(savedialog.EXECUTE) THEN
savedialog.filename = appendfilename(savedialog.filename, savedialog.filterindex)
filepath(active) = getdir(savedialog.filename)
filename(active) = getname(savedialog.filename)
KILL filepath(active) + "\" + filename(active)
editor(active).savetofile(filepath(active) +"\" + filename(active))
changed(active) = 0
status.panel(1).CAPTION = ""
END IF
END SUB
SUB mexit
END
END SUB
SUB mcut: editor(active).cuttoclipboard: END SUB
SUB mcopy: editor(active).copytoclipboard: END SUB
SUB mpaste: editor(active).pastefromclipboard: END SUB
SUB mselect: editor(active).selectall: END SUB
SUB mfind
END SUB
SUB mwrap
IF mnuwrap.checked = 1 THEN
mnuwrap.checked = 0
FOR n = 0 TO 10
editor(n).wordwrap = 0
NEXT
ELSE
mnuwrap.checked = 1
FOR n = 0 TO 10
editor(n).wordwrap = 1
NEXT
END IF
END SUB
SUB mfont
IF(fontdialog.EXECUTE) THEN
fontdialog.setfont(font)
FOR n = 0 TO 10
editor(n).font = font
NEXT
END IF
END SUB
SUB mrun
SHELL "C:\rapidq\RC -opt " + filepath(active) + "\" + filename(active)
SHELL filepath(active) + "\" + LEFT$(filename(active), LEN(filename(active)) - 3) + ".exe"
END SUB
SUB mabout
END SUB
SUB tchange
active = tab.tabindex
FOR n=0 TO 10
IF n <> active THEN
editor(n).visible = 0
END IF
NEXT
editor(active).visible = 1
IF changed(active) = 1 THEN status.panel(1).CAPTION = "Modified" ELSE status.panel(1).CAPTION = ""
status.panel(2).CAPTION = filepath(active)
END SUB
SUB change
status.panel(0).CAPTION = STR$(editor(active).wherey+1) + ":" + STR$(editor(active).wherex+1)
status.panel(1).CAPTION = "Modified"
changed(active) = 1
END SUB
FUNCTION getfile(file$) AS STRING
DIM n AS INTEGER
FOR n = 1 TO LEN(file$)
IF LEFT$(RIGHT$(file$,n),1) = "\" OR LEFT$(RIGHT$(file$,n),1) = "/" THEN EXIT FOR
NEXT
getfile = RIGHT$(file$, n-1)
END FUNCTION
FUNCTION getdir(file$) AS STRING
DIM n AS INTEGER
FOR n = 1 TO LEN(file$)
IF LEFT$(RIGHT$(file$,n),1) = "\" OR LEFT$(RIGHT$(file$,n),1) = "/" THEN EXIT FOR
NEXT
getdir = LEFT$(file$, LEN(file$) - n)
END FUNCTION
SUB keyed
status.panel(0).CAPTION = STR$(editor(active).wherey+1) + ":" + STR$(editor(active).wherex+1)
END SUB
FUNCTION appendfilename(file$, typ) AS STRING
IF LEFT$(RIGHT$(file$, 4), 1) = "." OR LEFT$(RIGHT$(file$, 3), 1) = "." OR LEFT$(RIGHT$(file$, 5), 1) = "." THEN
appendfilename = file$
EXIT FUNCTION
END IF
IF typ = 1 THEN file$ = file$ + ".txt"
IF typ = 2 THEN file$ = file$ + ".bas"
IF typ = 3 THEN file$ = file$ + ".rq"
IF typ = 4 THEN file$ = file$ + ".html"
appendfilename = file$
END FUNCTION
SUB afteropen
FOR n = 1 TO COMMANDCOUNT
c$ = COMMAND$(n)
IF(FILEEXISTS(c$)) THEN
IF docs >= 10 THEN
SHOWMESSAGE "11 is the maximum amount of documents..."
ELSE
filepath(n-1) = getdir(c$)
filename(n-1) = getfile(c$)
docs = docs + 1
active = n - 1
editor(n-1).loadfromfile(filepath(n-1)+"\"+filename(n-1))
editor(n-1).visible = 1
tab.addtabs filename(n-1)
SHOWMESSAGE filename(n-1)+
status.panel(2).CAPTION = filepath(n-1)
tab.tabindex = active
tchange
status.panel(1).CAPTION = ""
keyed
END IF
END IF
NEXT
END SUB
form.onshow = afteropen
form.SHOWMODAL
|
|