Advertisement
Guest User

Early ver of Mouse File Browser

a guest
Feb 12th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. --[[
  2.         Light weight mouse FB mini
  3.         by BigSHinyToys
  4. ]]--
  5. local bRun = true
  6. local sSlash = [[\]]
  7. local path = {}
  8. local tItemList = {}
  9. local width,hight = term.getSize()
  10. local listPos = -1
  11. local lastListPos
  12. local pading = string.rep(" ",width)
  13.  
  14. local function stringPath()
  15.     return sSlash..table.concat(path,sSlash)
  16. end
  17.  
  18. local function newList()
  19.     lastListPos = nil
  20.     listPos = -1
  21.     tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list
  22.     sPath = stringPath()
  23.     local folders = {}
  24.     local files = {}
  25.     local disks = {}
  26.  
  27.     local test,list = pcall(fs.list,sPath) -- stopes fs.list crash
  28.     if list == nil then
  29.         list = {}
  30.     end
  31.     if #path == 0 then
  32.         for i,v in pairs(rs.getSides()) do
  33.             if disk.isPresent(v) then
  34.                 if disk.hasData(v) then
  35.                     table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v})
  36.                     disks[disk.getMountPath(v)] = true
  37.                 elseif disk.hasAudio(v) then
  38.                     table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v})
  39.                 end
  40.             end
  41.         end
  42.     end
  43.     for i,v in pairs(list) do
  44.         if fs.isDir(sPath..sSlash..v) then
  45.             table.insert(folders,v)
  46.         else
  47.             table.insert(files,v)
  48.         end
  49.     end
  50.     table.sort(folders)
  51.     table.sort(files)
  52.     for i,v in pairs(folders) do
  53.         if disks[v] == nil then
  54.             table.insert(tItemList,{n = v, id = "folder"})
  55.         end
  56.     end
  57.     for i,v in pairs(files) do
  58.         table.insert(tItemList,{n = v, id = "file"})
  59.     end
  60. end
  61.  
  62. term.clear()
  63. newList()
  64.  
  65. local tIcons = {
  66.     back = {tCol = "lightGray",bCol = "blue",txt = " < "},
  67.     disk = {tCol = "lightGray",bCol = "blue",txt = "[*]"},
  68.     audio = {tCol = "yellow",bCol = "red",txt = "(o)"},
  69.     folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"},
  70.     file = {tCol = "lime",bCol = "green",txt = "   "}}
  71.  
  72. while bRun do
  73.     if lastListPos ~= listPos then
  74.         for i = 2,hight do
  75.             term.setCursorPos(1,i)
  76.             --local sel = i+listOff
  77.             local sel = i+listPos
  78.             if tItemList[sel] then
  79.                 term.setBackgroundColor(colors[tIcons[tItemList[sel].id].bCol])
  80.                 term.setTextColor(colors[tIcons[tItemList[sel].id].tCol])
  81.                 term.write(string.sub(tIcons[tItemList[sel].id].txt..tItemList[sel].n..pading,1,width))
  82.             else
  83.                 term.write(pading)
  84.             end
  85.         end
  86.         term.setBackgroundColor(colors.lightBlue)
  87.         term.setTextColor(colors.blue)
  88.         term.setCursorPos(1,1)
  89.         term.write(string.sub(stringPath().."  "..tostring(listPos).." "..#tItemList.." "..hight..pading,1,width))
  90.         lastListPos = listPos
  91.     end
  92.     local event = {os.pullEvent()}
  93.     if event[1] == "mouse_scroll" then
  94.         listPos = math.max(math.min(listPos + event[2],(#tItemList+1) - hight),-1)
  95.     elseif event[1] == "mouse_click" then
  96.         if event[2] == 1 then -- left click
  97.             local itemNumber = event[4] + listPos -- to keep it neat
  98.             if tItemList[itemNumber] then
  99.                 if tItemList[itemNumber].id == "folder" or tItemList[itemNumber].id == "disk" then
  100.                     table.insert(path,tItemList[itemNumber].n)
  101.                 elseif tItemList[itemNumber].id == "file" then
  102.                     os.run(getfenv(),stringPath()..sSlash..tItemList[itemNumber].n)
  103.                 elseif tItemList[itemNumber].id == "back" then
  104.                     table.remove(path,#path)
  105.                 end
  106.                 newList()
  107.             end
  108.         else -- right click
  109.             if tItemList[itemNumber] then -- Open , Open with {Debug , edit , paint , custom program} , Cut , Copy , Paste , Create Shortcut , Rename , Properties
  110.  
  111.             end
  112.         end
  113.     elseif event[1] == "window_resize" then
  114.         width,hight = term.getSize()
  115.         lastListPos = nil
  116.     end
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement