added Item$ = "__SmIC__="+FileName$ to COLUMNBOX ADD, add a filemode: r+ ( read/write )

This commit is contained in:
Jim
2015-05-05 21:04:32 -07:00
parent cd2a1ddb30
commit 83339084fe
13 changed files with 639 additions and 348 deletions

View File

@@ -0,0 +1,62 @@
import fileblock
x=openfile("/boot/home/test.file", 150,3)
if x < 1 error "cannot open file"
ok=Field(x,1,"name",50)
ok=ok+Field(x,2,"address",50)
ok=ok+Field(x,3,"phonenumber",50)
if (!ok = 3 ) error "bad field"
// werite some blocks
for z=1 to 20
lset(x,"name", "Some dude")
lset(x,"address", "Some address")
rset(x,"phonenumber","123-456-7890")
y=write_block(-1, x) // -1 appends the data to the file.
next
// over-write a block with new data
lset(x,"name", "Some other dude")
lset(x,"address", "Some kewl address")
rset(x,"phonenumber","098-765-4321")
write_block(6, x)
// read back the over-written block
read_block(6, x)
// get the data from the read operation
name$=readfield$(x, "name")
address$=readfield$(x, "address")
phone$=readfield$(x, "phonenumber")
// show the data
print name$
print address$
print trim$(phone$)
// over write the block again
lset(x,"name", "")
lset(x,"address", "")
rset(x,"phonenumber","")
write_block(6, x)
//read back the over-written block
recno = read_block(6, x) // returns the read block that will next be read if called with -1 recordnumber
name$=readfield$(x, "name")
address$=readfield$(x, "address")
phone$=readfield$(x, "phonenumber")
print name$
print address$
print phone$
print recno
//read the next block
recno = read_block(-1, x)
name$=readfield$(x, "name")
address$=readfield$(x, "address")
phone$=readfield$(x, "phonenumber")
print name$
print address$
print phone$
print recno

View File

@@ -1,97 +0,0 @@
// Filebox is a library to have an easy access to a list of files.
// This is easier than poking around with columnboxes yourself.
// Open a new filebox from (x1,y1) to (x2,y2)
// with the id ID$, the type of scrollbar ScrollbarType on View$
export sub Filebox(x1,y1,x2,y2, ID$, ScrollbarType, View$)
local myscrollbar
columnbox x1,y1 to x2,y2, ID$, ScrollbarType, "resizable", View$
columnbox column ID$, " ", 1, 20, 20, 20, "align-center"
if(scrollbarType=1 or scrollbarType=3) myscrollbar = peek("scrollbarwidth")
columnbox column ID$, "Name", 2, 1000, 21, x2-x1-24-myscrollbar, "align-left"
columnbox color ID$, "Selection-Active", 220,220,250
columnbox color ID$, "Row-Divider", 255,255,255
return
end sub
// Easy interface to a Filebox, simply name a directory
export sub FileboxDirectorySimple(ID$, dir$)
FileboxDirectory(ID$,dir$,false)
return
end sub
// return the name of the row position
export sub FileboxName$(ID$, position)
return columnbox get$ ID$, 2, position
end sub
// return true, if the row position is a directory
export sub FileboxIsDirectory(ID$, position)
local t$
t$ = columnbox get$ ID$, 1, position
if(t$ = "__Mime__=application/x-vnd.Be-directory") return true
return false
end sub
// Give a directory and the following options:
// showDot: set this to true to show hidden (dot) files
export sub FileboxDirectory(ID$, dir$, showDot)
local t$
local i
local n
local arraysizeDir
local arraysizeFiles
dim directories$(1)
dim files$(1)
arraysizeDir = 0
arraysizeFiles = 0
columnbox clear ID$
if(showDot) then
t$ = system$("ls --format=single-column --color=none -a "+dir$+" |sort -f")
else
t$ = system$("ls --format=single-column --color=none "+dir$+" |sort -f")
endif
dim splitdir$(1)
n = split(t$, splitdir$(), "\n")
for i=1 to n-1
if(system("test -d \""+ dir$+splitdir$(i)+"\"") = 0) then
// comment the if clause out if you want to have the direcotries "." and ".." listed
if(splitdir$(i)<>"." and splitdir$(i)<>"..") then
arraysizeDir = arraysizeDir + 1
dim directories$(arraysizeDir)
directories$(arraysizeDir-1) = splitdir$(i)
endif
// handle files
else
arraysizeFiles = arraysizeFiles + 1
dim files$(arraysizeFiles)
files$(arraysizeFiles-1) = splitdir$(i)
endif
next i
for i=0 to arraysizeDir-1
FileboxAdd(ID$, directories$(i), true)
next i
for i=0 to arraysizeFiles-1
FileboxAdd(ID$, files$(i), false)
next i
return
end sub
sub FileboxAdd(ID$, Name$, IsFolder)
local maxpos
maxpos = (columnbox count ID$) + 1
if(IsFolder) then
columnbox add ID$, 1, maxpos, 18, "__Mime__=application/x-vnd.Be-directory"
else
columnbox add ID$, 1, maxpos, 18, "__Mime__=application/octet-stream"
endif
columnbox add ID$, 2, maxpos, 20, Name$
return
end sub

View File

@@ -1,9 +1,12 @@
#!yab
import Filebox
dir$ = "/boot/home/"
window open 100,100 to 500,500, "Demo","Demo"
window open 100,100 to 500,500, "Demo",dir$
Filebox(10,10,350,390,"Filebox", 1, "Demo")
FileboxDirectory("Filebox", dir$, false)
button 360,10,390,30, "DirUp", "..", "Demo"
@@ -13,6 +16,7 @@ inloop = true
while(inloop)
n = split(message$, msg$(), "|")
for i=1 to n
print msg$(i)
// Quit
if(msg$(i) = "Demo:_QuitRequested") inloop = false
@@ -23,7 +27,9 @@ while(inloop)
t = t - 1
wend
dir$ = left$(dir$,t)
WINDOW SET "Demo", "Title", dir$
FileboxDirectory("Filebox", dir$, false)
endif
// An item is invoked
@@ -31,11 +37,12 @@ while(inloop)
position = val(right$(msg$(i),len(msg$(i))-16))
// if the item is a directory, then update the filebox else print the filename
if(FileboxIsDirectory("Filebox", position)) then
if(FileboxIsDirectory("Filebox", position,dir$)) then
dir$ = dir$ + FileboxName$("Filebox", position) + "/"
WINDOW SET "Demo", "Title", dir$
FileboxDirectory("Filebox", dir$, false)
else
print FileboxName$("Filebox", position)
print dir$+FileboxName$("Filebox", position)
endif
endif
next i