What I did with Rev last night - few lines of code for graphical file/folder/volume navigator

viktoras didziulis viktoras at ekoinf.net
Fri Jul 6 16:09:59 EDT 2007


Didn't expect programming an embedded volumes/folders/files navigator 
can be so easy. If you need something like this in your application, use 
the source below - just copy/paste the 3 handlers from this message into 
a scrolling field. In object inspector check the lock text and the list 
behavior of the field to true or execute:
set the lockText of fld "yourField" to true
set the listBehavior of fld "yourField" to true
in the message box. Then click the field with mouse and start using it.

on mouseDown
  if me is not empty then
    pass mouseDown
  else
    put the folders & return & return & the files into me   
  end if
  drawList
end mouseDown

on selectionChanged
  local myLine   
  if ".." is in the selectedtext then
    set the defaultfolder to (the defaultfolder & "/" & char 3 to -1 of 
the selectedtext)
  else if char 2 to 3 of the selectedtext = "  " then
    #insert your handler for the selected files here
         answer "file:" && the defaultfolder & "/" & char 4 to -1 of the 
selectedtext
  else if ":" is in the selectedtext then
    set the defaultfolder to (char 3 to -1 of the selectedtext & "/")
  else   
    set the defaultfolder to (the defaultfolder & "/" & char 3 to -1 of 
the selectedtext)
  end if    
  drawList
end selectionChanged

on drawList
  local myLine
  local flag
  put 0 into flag 
  lock screen
  put the defaultfolder & return & the volumes & return & the folders & 
return & return & the files into me
  repeat with i = 1 to the number of lines in me
    put line i of me into myLine
    if myLine is empty then
      put 1 into flag
      next repeat      
    else
      if flag = 1 then #files       
        put "   " before line i of me       
        set the imageSource of char 1 of line i of me to 201066      
      else #folders or volumes      
        put "  " before line i of me      
        set the imageSource of char 1 of line i of me to 210087
      end if
    end if     
  end repeat 
  set the imageSource of char 1 of line 1 of me to 210088
  set the textStyle of line 1 of me to "bold" 
  unlock screen
end drawList




More information about the use-livecode mailing list