Advertisement
programcreator

FileX

Feb 22nd, 2015
2,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.76 KB | None | 0 0
  1. --------------FileX v1.2-------------
  2. ---------------Program---------------
  3. --------------by Creator-------------
  4.  
  5. --Variables--
  6. term.current(term.native())
  7. local copyPath = ""
  8. local copyHelp = ""
  9. local settDir = "FTPconfig"
  10. local progsDir = "subPrograms"
  11. local textutilsserialize = textutils.serialize
  12. local textutilsunserialize = textutils.unserialize
  13. local w, h = term.getSize()
  14. local folderMenu = {
  15.     term.current(),
  16.     16,
  17.     "Folder Options",
  18.     colors.white,
  19.     colors.blue,
  20.     colors.black,
  21.     colors.lightGray,
  22.     {
  23.         {
  24.             "Open",
  25.             "open",
  26.         },
  27.         {
  28.             "Delete",
  29.             "delete",
  30.         },
  31.         {
  32.             "Rename",
  33.             "rename",
  34.         },
  35.         {
  36.             "Move",
  37.             "move",
  38.         },
  39.         {
  40.             "Copy",
  41.             "copy",
  42.         },
  43.         {
  44.             "Cancel",
  45.             "cancel",
  46.         },
  47.     },
  48. }
  49. local fileMenu = {
  50.     term.current(),
  51.     16,
  52.     "File Options",
  53.     colors.white,
  54.     colors.blue,
  55.     colors.black,
  56.     colors.lightGray,
  57.     {
  58.         {
  59.             "Open",
  60.             "open",
  61.         },
  62.         {
  63.             "Delete",
  64.             "delete",
  65.         },
  66.         {
  67.             "Rename",
  68.             "rename",
  69.         },
  70.         {
  71.             "Move",
  72.             "move",
  73.         },
  74.         {
  75.             "Cancel",
  76.             "cancel",
  77.         },
  78.         {
  79.             "Run",
  80.             "run",
  81.         },
  82.         {
  83.             "Copy",
  84.             "copy",
  85.         },
  86.         {
  87.             "Open with",
  88.             "openWith",
  89.         },
  90.     },
  91. }
  92. local nilMenu = {
  93.     term.current(),
  94.     16,
  95.     "Options",
  96.     colors.white,
  97.     colors.blue,
  98.     colors.black,
  99.     colors.lightGray,
  100.     {
  101.         {
  102.             "Make a folder",
  103.             "makeFolder",
  104.         },
  105.         {
  106.             "Make a file",
  107.             "makeFile",
  108.         },
  109.         {
  110.             "Cancel",
  111.             "cancel",
  112.         },
  113.     },
  114. }
  115. local newFolderWindow = {
  116.     term.current(),
  117.     math.floor((w-32)/2),
  118.     math.floor((h-8)/2),
  119.     32,
  120.     8,
  121.     true,
  122.     "New folder name",
  123.     colors.white,
  124.     colors.blue,
  125.     "Write the name of%the new folder.",
  126.     colors.black,
  127.     colors.lightGray,
  128.     colors.white,
  129.     colors.black,
  130. }
  131. local newFileWindow = {
  132.     term.current(),
  133.     math.floor((w-32)/2),
  134.     math.floor((h-8)/2),
  135.     32,
  136.     8,
  137.     true,
  138.     "New file name",
  139.     colors.white,
  140.     colors.blue,
  141.     "Write the name of%the new file.",
  142.     colors.black,
  143.     colors.lightGray,
  144.     colors.white,
  145.     colors.black,
  146. }
  147. local upFileWindow = {
  148.     term.current(),
  149.     math.floor((w-32)/2),
  150.     math.floor((h-8)/2),
  151.     32,
  152.     8,
  153.     true,
  154.     "File path",
  155.     colors.white,
  156.     colors.blue,
  157.     "Write the path of%the file.",
  158.     colors.black,
  159.     colors.lightGray,
  160.     colors.white,
  161.     colors.black,
  162. }
  163. local moveFolderWindow = {
  164.     term.current(),
  165.     math.floor((w-32)/2),
  166.     math.floor((h-8)/2),
  167.     32,
  168.     8,
  169.     true,
  170.     "New folder path",
  171.     colors.white,
  172.     colors.blue,
  173.     "Write the name of%the new folder path.",
  174.     colors.black,
  175.     colors.lightGray,
  176.     colors.white,
  177.     colors.black,
  178. }
  179. local bgColor = colors.black
  180. local txtColor = colors.white
  181. local domain = {}
  182. local currDir = ""
  183. local files = {}
  184. local Buttons = {
  185.     {
  186.         2,
  187.         2,
  188.         7,
  189.         1,
  190.         "Refresh",
  191.         colors.white,
  192.         colors.green,
  193.         "refresh"
  194.     },
  195.     {
  196.         11,
  197.         2,
  198.         2,
  199.         1,
  200.         "Up",
  201.         colors.white,
  202.         colors.green,
  203.         "up"
  204.     },
  205.     {
  206.         15,
  207.         2,
  208.         5,
  209.         1,
  210.         "Paste",
  211.         colors.white,
  212.         colors.green,
  213.         "paste"
  214.     },
  215. }
  216. local folderIcon = {
  217.     {
  218.     2,
  219.     2,
  220.     2,
  221.     2,
  222.     16,
  223.     16,
  224.     16,
  225.     16,
  226.     },
  227.     {
  228.     2,
  229.     2,
  230.     2,
  231.     2,
  232.     2,
  233.     2,
  234.     2,
  235.     2,
  236.     },
  237.     {
  238.     2,
  239.     2,
  240.     2,
  241.     2,
  242.     2,
  243.     2,
  244.     2,
  245.     2,
  246.     },
  247.     {
  248.     2,
  249.     2,
  250.     2,
  251.     2,
  252.     2,
  253.     2,
  254.     2,
  255.     2,
  256.     },
  257. }
  258. local fileIcon = {
  259.     {
  260.     8192,
  261.     8192,
  262.     8192,
  263.     8192,
  264.     8192,
  265.     8192,
  266.     8192,
  267.     8192,
  268.     },
  269.     {
  270.     8192,
  271.     8192,
  272.     8192,
  273.     8192,
  274.     8192,
  275.     8192,
  276.     8192,
  277.     8192,
  278.     },
  279.     {
  280.     8192,
  281.     8192,
  282.     8192,
  283.     8192,
  284.     8192,
  285.     8192,
  286.     8192,
  287.     8192,
  288.     },
  289.     {
  290.     8192,
  291.     8192,
  292.     8192,
  293.     8192,
  294.     8192,
  295.     8192,
  296.     8192,
  297.     8192,
  298.     },
  299. }
  300. local scroll = 0
  301. local globalButtonList = {}
  302. local notEnded = true
  303. local fileExtensions = {
  304. nfp = "nPaintPro",
  305. nfa = "nPaintPro",
  306. txt = "edit",
  307. exe = "shell",
  308. lua = "shell",
  309. }
  310.  
  311. --Functions--
  312.  
  313. local function detectButtonHit(buttonsToTest)
  314.     local event, button, x, y
  315.     repeat
  316.         event, button, x, y = os.pullEvent()
  317.     until event == "mouse_click" or event == "key"
  318.     if event == "mouse_click" then
  319.         for i,v in pairs(buttonsToTest) do
  320.             if v[1] <= x and x <= v[3] and v[2] <= y and y <= v[4] then
  321.                 return {v[5], button, x, y}
  322.             end
  323.         end
  324.     elseif event == "key" then
  325.         return {"key:"..tostring(button)}
  326.     end
  327.     return {"pong"}
  328. end
  329.  
  330. local function mkStrShort(str,lenght,n)
  331.     local bufferTable = {}
  332.     local toReturnTable = {}
  333.     local lenghtN = tonumber(lenght)
  334.     if lenghtN == nil then return false end
  335.     for i = 0,n-1 do
  336.         bufferTable[i+1] = string.sub(tostring(str),(i*lenghtN)+1,(i*lenghtN)+lenghtN)
  337.     end
  338.     for i,v in pairs(bufferTable) do
  339.         if v ~= nil then
  340.             toReturnTable[#toReturnTable+1] = v
  341.         end
  342.     end
  343.     return toReturnTable
  344. end
  345.  
  346. local function clear(bgColorArg)
  347.     term.setBackgroundColor(bgColorArg or bgColor)
  348.     term.setTextColor(txtColor)
  349.     term.setCursorPos(1,1)
  350.     term.clear()
  351.     globalButtonList = {}
  352. end
  353.  
  354. local function dropDownMenu(tableInput,clearBg,x,y)
  355.     term.setCursorPos(1,1)
  356.     if clearBg ~= false then
  357.         clear(colors.cyan)
  358.     end
  359.     globalButtonList = {}
  360.     local nTable = {}
  361.     local dropDownMenuWindow = window.create(tableInput[1],x,y,tableInput[2],#tableInput[8]+1,true)
  362.     dropDownMenuWindow.setTextColor(tableInput[4])
  363.     dropDownMenuWindow.setBackgroundColor(tableInput[5])
  364.     dropDownMenuWindow.setCursorPos(1,1)
  365.     dropDownMenuWindow.clearLine()
  366.     dropDownMenuWindow.write(tableInput[3])
  367.     dropDownMenuWindow.setTextColor(tableInput[6])
  368.     dropDownMenuWindow.setBackgroundColor(tableInput[7])
  369.     for i = 1 , #tableInput[8] do
  370.         dropDownMenuWindow.setCursorPos(1,i+1)
  371.         dropDownMenuWindow.clearLine()
  372.         dropDownMenuWindow.write(tableInput[8][i][1])
  373.         globalButtonList[#globalButtonList+1] = {x+1,y+i,x+tableInput[2],y+i,tableInput[8][i][2]}
  374.     end
  375.     local result
  376.     repeat
  377.         result =  detectButtonHit(globalButtonList)
  378.     until result[1] ~= "pong"
  379.     return result[1]
  380. end
  381.  
  382. local function dialogBox(tableInput,clearBg)
  383.     if clearBg ~= false then
  384.         clear(colors.cyan)
  385.     end
  386.     local nTable = {}
  387.     dialogBoxWindow = window.create(
  388.     tableInput[1],
  389.     tableInput[2],
  390.     tableInput[3],
  391.     tableInput[4],
  392.     tableInput[5])
  393.     dialogBoxWindow.setBackgroundColor(tableInput[9])
  394.     dialogBoxWindow.setCursorPos(2,1)
  395.     dialogBoxWindow.clearLine()
  396.     dialogBoxWindow.setTextColor(tableInput[8])
  397.     dialogBoxWindow.write(tableInput[7])
  398.     dialogBoxWindow.setCursorPos(1,2)
  399.     dialogBoxWindow.setBackgroundColor(tableInput[12])
  400.     for i = 2 , tableInput[5] do
  401.         dialogBoxWindow.setCursorPos(1,i)
  402.         dialogBoxWindow.clearLine()
  403.     end
  404.     dialogBoxWindow.setCursorPos(1,2)
  405.     dialogBoxWindow.setTextColor(tableInput[11])
  406.     for token in string.gmatch(tableInput[10],"[^%%]+") do
  407.         nTable[#nTable+1] = token
  408.     end
  409.     for i,v in pairs(nTable) do
  410.         dialogBoxWindow.setCursorPos(2,1+i)
  411.         dialogBoxWindow.write(v)
  412.     end
  413.     local totalLenght = 0
  414.     globalButtonList = {}
  415.     for i,v in pairs(tableInput[13]) do
  416.         dialogBoxWindow.setCursorPos(2+totalLenght,tableInput[5]-1)
  417.         dialogBoxWindow.setTextColor(v[2])
  418.         dialogBoxWindow.setBackgroundColor(v[3])
  419.         local toWrite = " "..v[1].." "
  420.         dialogBoxWindow.write(toWrite)
  421.         if globalButtonList == nil then
  422.             globalButtonList = {{tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}}
  423.         else
  424.             globalButtonList[#globalButtonList+1] = {tableInput[2]+1+totalLenght,tableInput[3] + tableInput[5]-2,tableInput[2]+totalLenght + #toWrite,tableInput[3] + tableInput[5]-1,v[4]}
  425.         end
  426.         totalLenght = #toWrite + totalLenght + 2
  427.     end
  428.     local repeatIt = true
  429.     while repeatIt == true do
  430.         local unparsedResult = detectButtonHit(globalButtonList)
  431.         result = unparsedResult[1]
  432.         if result ~= "pong" then
  433.             repeatIt = false
  434.         end
  435.     end
  436.     return result
  437. end
  438.  
  439. local function textBox(tableInput,secret,clearBg)
  440.     if clearBg ~= false then
  441.         clear(colors.cyan)
  442.     end
  443.     local nTable = {}
  444.     textBoxWindow = window.create(tableInput[1],tableInput[2],tableInput[3],tableInput[4],tableInput[5])
  445.     textBoxWindow.setCursorPos(2,1)
  446.     textBoxWindow.setBackgroundColor(tableInput[9])
  447.     textBoxWindow.clearLine()
  448.     textBoxWindow.setTextColor(tableInput[8])
  449.     textBoxWindow.write(tableInput[7])
  450.     textBoxWindow.setCursorPos(1,2)
  451.     textBoxWindow.setBackgroundColor(tableInput[12])
  452.     for i = 2 , tableInput[5] do
  453.         textBoxWindow.setCursorPos(1,i)
  454.         textBoxWindow.clearLine()
  455.     end
  456.     textBoxWindow.setTextColor(tableInput[11])
  457.     for token in string.gmatch(tableInput[10],"[^%%]+") do
  458.         nTable[#nTable+1] = token
  459.     end
  460.     for i,v in pairs(nTable) do
  461.         textBoxWindow.setCursorPos(2,1+i)
  462.         textBoxWindow.write(v)
  463.     end
  464.     textBoxWindow.setTextColor(tableInput[13])
  465.     textBoxWindow.setBackgroundColor(tableInput[14])
  466.     textBoxWindow.setCursorPos(2,tableInput[5]-1)
  467.     textBoxWindow.clearLine()
  468.     textBoxWindow.setCursorPos(2,tableInput[5]-1)
  469.     textBoxWindow.setTextColor(tableInput[13])
  470.     textBoxWindow.setBackgroundColor(tableInput[14])
  471.     if secret then
  472.         return read("*")
  473.     else
  474.         return read()
  475.     end
  476. end
  477.  
  478. local function refresh(dir)
  479.     local bufferFiles = {}
  480.     for i,v in pairs(fs.list(dir)) do
  481.         if fs.isDir(currDir.."/"..v) then
  482.             bufferFiles[#bufferFiles+1] = {v,"folder"}
  483.         else
  484.             bufferFiles[#bufferFiles+1] = {v,"file"}
  485.         end
  486.     end
  487.     return bufferFiles
  488. end
  489.  
  490. local function drawOptions(tableInputDrawOptions)
  491.     for i,v in pairs(tableInputDrawOptions) do
  492.         term.setCursorPos(v[1],v[2])
  493.         paintutils.drawFilledBox(v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,v[7])
  494.         term.setCursorPos(v[1],v[2])
  495.         term.setTextColor(v[6])
  496.         term.write(v[5])
  497.         if globalButtonList == nil then
  498.             globalButtonList = {{v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,"button:"..v[8]}}
  499.         else
  500.             globalButtonList[#globalButtonList+1] = {v[1],v[2],v[3]+v[1]-1,v[4]+v[2]-1,"button:"..v[8]}
  501.         end
  502.     end
  503. end
  504.  
  505. local function drawFiles(filesToDisplay)
  506.     local numItemsX = math.floor((w-1)/10)
  507.     numItemsY = math.ceil(#filesToDisplay/numItemsX)
  508.     local currFile = 1
  509.     for i = 0 , numItemsY-1 do
  510.         for k = 0 , numItemsX - 1 do
  511.             if currFile > #filesToDisplay then
  512.                 break
  513.             else
  514.                 term.setTextColor(colors.black)
  515.                 if filesToDisplay[currFile][2] == "file" then
  516.                     paintutils.drawImage(fileIcon,(k*10)+2,(i*5)+4-scroll)
  517.                     for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do
  518.                         term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)
  519.                         term.write(m)
  520.                     end
  521.                     if ((i*5)+4-scroll) < 4 then
  522.                         if ((i*5)+7-scroll) >= 4 then
  523.                             if globalButtonList == nil then
  524.                                 globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}}
  525.                             else
  526.                                 globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}
  527.                             end
  528.                         end
  529.                     else
  530.                         if globalButtonList == nil then
  531.                             globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}}
  532.                         else
  533.                             globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"file:"..filesToDisplay[currFile][1]}
  534.                         end
  535.                     end
  536.                 elseif filesToDisplay[currFile][2] == "folder" then
  537.                     paintutils.drawImage(folderIcon,(k*10)+2,(i*5)+4-scroll)
  538.                     for l,m in pairs(mkStrShort(filesToDisplay[currFile][1],6,3)) do
  539.                         term.setCursorPos((k*10)+3,(i*5)+4+l-scroll)
  540.                         term.write(m)
  541.                     end
  542.                     if ((i*5)+4-scroll) < 4 then
  543.                         if ((i*5)+7-scroll) >= 4 then
  544.                             if globalButtonList == nil then
  545.                                 globalButtonList = {{((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}}
  546.                             else
  547.                                 globalButtonList[#globalButtonList+1] = {((k*10)+2),4,((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}
  548.                             end
  549.                         end
  550.                     else
  551.                         if globalButtonList == nil then
  552.                             globalButtonList = {{((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}}
  553.                         else
  554.                             globalButtonList[#globalButtonList+1] = {((k*10)+2),((i*5)+4-scroll),((k*10)+9),((i*5)+7-scroll),"folder:"..filesToDisplay[currFile][1]}
  555.                         end
  556.                     end
  557.                 end
  558.                 currFile = currFile + 1
  559.             end
  560.         end
  561.     end
  562. end
  563.  
  564. local function drawSideBar()
  565.     local lenghtSideBar = h-4
  566.     if numItemsY ~= 0 then
  567.          lenghtSideBar = math.ceil(((h-5)*(h-5))/(numItemsY*5))
  568.     end
  569.     paintutils.drawLine(w,3,w,3+lenghtSideBar,colors.green)
  570.     term.setBackgroundColor(colors.blue)
  571.     term.setCursorPos(w,3)
  572.     term.write("^")
  573.     term.setCursorPos(w,h-1)
  574.     term.write("v")
  575.     if globalButtonList == nil then
  576.         globalButtonList = {{w,3,w,3,"button:scrollUp"}}
  577.     else
  578.         globalButtonList[#globalButtonList+1] = {w,3,w,3,"button:scrollUp"}
  579.     end
  580.     if globalButtonList == nil then
  581.         globalButtonList = {{w,h-1,w,h-1,"button:scrollDown"}}
  582.     else
  583.         globalButtonList[#globalButtonList+1] = {w,h-1,w,h-1,"button:scrollDown"}
  584.     end
  585. end
  586.  
  587. local function program(extension)
  588.     if fileExtensions[extension] ~= nil then
  589.         return fileExtensions[extension]
  590.     else
  591.         return "edit"
  592.     end
  593. end
  594.  
  595. local function main(filesToDisplay,buttonsToDisplay)
  596.     clear(colors.white)
  597.     drawFiles(filesToDisplay)
  598.     drawSideBar()
  599.     term.setBackgroundColor(colors.orange)
  600.     for i = 1,2 do
  601.         term.setCursorPos(1,i)
  602.         term.clearLine()
  603.     end
  604.     term.setCursorPos(1,1)
  605.     term.setTextColor(colors.black)
  606.     term.write("Creator\'s FileX v1.0")
  607.     term.setCursorPos(w,1)
  608.     term.setBackgroundColor(colors.magenta)
  609.     term.write("X")
  610.     if globalButtonList == nil then
  611.         globalButtonList = {{w,1,w,1,"button:x"}}
  612.     else
  613.         globalButtonList[#globalButtonList+1] = {w,1,w,1,"button:x"}
  614.     end
  615.     if globalButtonList == nil then
  616.         globalButtonList = {{1,3,w,h,"nil:nil"}}
  617.     else
  618.         globalButtonList[#globalButtonList+1] = {1,4,w,h,"nil:nil"}
  619.     end
  620.     drawOptions(buttonsToDisplay)
  621.     if globalButtonList == nil then
  622.         globalButtonList = {{1,1,w,3,"nil:nilnil"}}
  623.     else
  624.         globalButtonList[#globalButtonList+1] = {1,1,w,3,"nil:nilnil"}
  625.     end
  626.     term.setCursorPos(1,h)
  627.     term.setBackgroundColor(colors.orange)
  628.     term.clearLine()
  629.     term.setTextColor(colors.black)
  630.     term.write(currDir)
  631.     term.setCursorPos(1,1)
  632.     local detectedButtonUnparsedTable = detectButtonHit(globalButtonList)
  633.     local detectedButtonUnparsed = detectedButtonUnparsedTable[1]
  634.     local button = detectedButtonUnparsedTable[2]
  635.     local detectedButtonParsedTable = {}
  636.     for token in string.gmatch(detectedButtonUnparsed,"[^:]+") do
  637.         detectedButtonParsedTable[#detectedButtonParsedTable + 1] = token
  638.     end
  639.     local action = detectedButtonParsedTable[2]
  640.     if detectedButtonParsedTable[1] == "button" then
  641.         if action == "x" then
  642.             term.setBackgroundColor(colors.black)
  643.             clear()
  644.             print("Thank you for using Creator\'s FTPclient. More coming soon...\nSpecial thanks to:\nNitrogenFinger\'s for nPaintPro")
  645.             notEnded = false
  646.         elseif action == "up" then
  647.             scroll = 0
  648.             if currDir == "/" then
  649.             else
  650.                 local currDirBuffer = {}
  651.                 for token in string.gmatch(currDir,"(/[^/]+)") do
  652.                     currDirBuffer[#currDirBuffer + 1] = token
  653.                 end
  654.                 currDir = ""
  655.                 if #currDirBuffer == 1 then
  656.                     currDir = ""
  657.                 else
  658.                     for i = 1, #currDirBuffer-1 do
  659.                         if i == 1 then
  660.                             currDir = currDirBuffer[1]
  661.                         else
  662.                             currDir = currDir..currDirBuffer[i]
  663.                         end
  664.                     end
  665.                 end
  666.                 files = refresh(currDir)
  667.             end
  668.         elseif action == "refresh" then
  669.             files = refresh(currDir)
  670.         elseif action == "scrollUp" then
  671.             scroll = scroll - 1
  672.             if scroll < 0 then
  673.                 scroll = 0
  674.             end
  675.         elseif action == "scrollDown" then
  676.             scroll = scroll + 1
  677.             if scroll > numItemsY*6 - h then
  678.                 scroll = scroll - 1
  679.             end
  680.         elseif action == "paste" then
  681.             term.setCursorPos(1,1)
  682.             print(pathToCopy)
  683.             print(currDir)
  684.             print(copyHelp)
  685.             sleep(3)
  686.             fs.copy(copyPath,currDir.."/"..copyHelp)
  687.             files = refresh(currDir)
  688.            
  689.         end
  690.     elseif detectedButtonParsedTable[1] == "key" then
  691.         if tonumber(action) == keys.up then
  692.             scroll = scroll - 1
  693.             if scroll < 0 then
  694.                 scroll = 0
  695.             end
  696.         elseif tonumber(action) == keys.down then
  697.             scroll = scroll + 1
  698.             if scroll > numItemsY*6 - h then
  699.                 scroll = scroll - 1
  700.             end
  701.         end
  702.     elseif detectedButtonParsedTable[1] == "folder" then
  703.         if button == 1 then
  704.             currDir = currDir.."/"..action
  705.             files = refresh(currDir)
  706.             scroll = 0
  707.         elseif button == 2 then
  708.             local result = dropDownMenu(folderMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])
  709.             if result == "open" then
  710.                 currDir = currDir.."/"..action
  711.                 files = refresh(currDir)
  712.                 scroll = 0
  713.             elseif result == "copy" then
  714.                 pathToCopy = currDir..action
  715.             elseif result == "delete" then
  716.                 fs.delete(currDir.."/"..action)
  717.                 files = refresh(currDir)
  718.             elseif result == "rename" then
  719.                 local answ = textBox(newFolderWindow,false,false)
  720.                 fs.move(currDir.."/"..action,currDir.."/"..answ)
  721.                 files = refresh(currDir)
  722.             elseif result == "move" then
  723.                 local answ = textBox(moveFolderWindow,false,false)
  724.                 if string.sub(answ,1,1) ~= "/" then
  725.                     answ = "/"..answ
  726.                 end
  727.                 fs.move(currDir.."/"..action,answ)
  728.                 files = refresh(currDir)
  729.             elseif result == "copy" then
  730.                 copyPath = currDir.."/"..action
  731.                 copyHelp = action
  732.             end
  733.         end
  734.     elseif detectedButtonParsedTable[1] == "file" then
  735.         if button == 1 then
  736.             local fileExtension
  737.             for token in string.gmatch(action,"[^%.]+") do
  738.                 fileExtension = token
  739.             end
  740.             if fileExtension == action then
  741.                 fileExtension = "txt"
  742.             end
  743.             programT = program(fileExtension)
  744.             shell.run(progsDir.."/"..programT.." "..currDir.."/"..action)
  745.         elseif button == 2 then
  746.             local result = dropDownMenu(fileMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])
  747.             if result == "open" then
  748.                 local fileExtension
  749.                 for token in string.gmatch(action,"[^%.]+") do
  750.                     fileExtension = token
  751.                 end
  752.                 if fileExtension == action then
  753.                     fileExtension = "txt"
  754.                 end
  755.                 programT = program(fileExtension)
  756.                 shell.run(progsDir.."/"..programT.." "..currDir.."/"..action)
  757.             elseif result == "delete" then
  758.                 fs.delete(currDir.."/"..action)
  759.                 files = refresh(currDir)
  760.             elseif result == "rename" then
  761.                 local answ = textBox(newFolderWindow,false,false)
  762.                 fs.move(currDir.."/"..action,currDir.."/"..answ)
  763.                 files = refresh(currDir)
  764.             elseif result == "move" then
  765.                 local answ = textBox(moveFolderWindow,false,false)
  766.                 if string.sub(answ,1,1) ~= "/" then
  767.                     answ = "/"..answ
  768.                 end
  769.                 fs.move(currDir.."/"..action,answ)
  770.                 files = refresh(currDir)
  771.             elseif result == "run" then
  772.                 shell.run(progsDir.."/shell "..currDir.."/"..action)
  773.             elseif result == "openWith" then
  774.                 local possibleExtensions = {}
  775.                 for i,v in pairs(fileExtensions) do
  776.                     local alreadyRegistered = false
  777.                     for m,k in pairs(possibleExtensions) do
  778.                         if v == k then
  779.                             alreadyRegistered = true
  780.                         end
  781.                     end
  782.                     if not alreadyRegistered then
  783.                         possibleExtensions[#possibleExtensions+1] = v
  784.                     end
  785.                 end
  786.                 local openWith = {
  787.                     term.current(),
  788.                     16,
  789.                     "Open with:",
  790.                     colors.white,
  791.                     colors.blue,
  792.                     colors.black,
  793.                     colors.lightGray,
  794.                     {}
  795.                 }
  796.                 for i,v in pairs(possibleExtensions) do
  797.                     openWith[8][#openWith[8]+1] = {v,v}
  798.                 end
  799.                 openWith[8][#openWith[8]+1] = {"Cancel","cancel"}
  800.                 globalButtonList = {}
  801.                 result = dropDownMenu(openWith,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4]+6)
  802.                 shell.run(progsDir.."/"..result.." "..currDir.."/"..action)
  803.             elseif result == "copy" then
  804.                 copyPath = currDir.."/"..action
  805.                 copyHelp = action
  806.             end
  807.         end
  808.     elseif detectedButtonParsedTable[1] == "nil" then
  809.         if button == 2 then
  810.             if action == "nil" then
  811.                 local result = dropDownMenu(nilMenu,false,detectedButtonUnparsedTable[3],detectedButtonUnparsedTable[4])
  812.                 if result == "makeFolder" then
  813.                     local answ = textBox(newFolderWindow,false,false)
  814.                     fs.makeDir(currDir.."/"..answ)
  815.                     files = refresh(currDir)
  816.                     scroll = 0
  817.                 elseif result == "makeFile" then
  818.                     local answ = textBox(newFileWindow,false,false)
  819.                     f = fs.open(currDir.."/"..answ,"w")
  820.                     f.close()
  821.                     files = refresh(currDir)
  822.                     scroll = 0
  823.                 end
  824.             end
  825.         end
  826.     end
  827. end
  828.  
  829. --Code--
  830.  
  831. clear()
  832. files = refresh(currDir)
  833. while notEnded do
  834.     main(files,Buttons)
  835. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement