Advertisement
pepeknamornik

FileX P7

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