superkh

os

Dec 25th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.71 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --VARS------------------------------------------------------------------------
  3. local Path = A.RCpath()
  4. local conf = A.getT(Path)
  5. local User = A.RUser()
  6. local rng = true
  7. local Exit = nil
  8. local cm = 0
  9. local i = conf["BCI"]
  10. local xy = {0,0}
  11. local xy2= {0,0,1}
  12. local w,h = term.getSize()
  13. local tbi = {} -- this table sets up for picking images for icons
  14. local tbl = {} -- this keep the cords for tbi
  15. local tbP = {} -- sets up program change
  16. local tbl2 = {}
  17. local tbd = {}--used for the draging of icons
  18. local t = nill
  19. local wh = {term.getSize()}
  20. local Inumber = nil -- get to backgones
  21. local drag = {false,1,false}--is draged,index, (is currnetly draging)
  22. local src = "os/users/"..User.."/conf"
  23. --Buffers----------------------------------------------------------------
  24. local BPicon = buf.createBuffer()
  25. local BNicon = buf.createBuffer()
  26. local bdm = A.Rmeun()
  27. --Setup--------------------------------------------------------------------
  28. local programs = {
  29.     programs_defaults = {
  30.         __index = {
  31.             image = "os/images/icons/icon1";
  32.             localtion = nil;
  33.         };
  34.     };
  35.     meta = {   
  36.         __newindex = function(t, key, value) --(posX, posY) or possition
  37.             assert(type(value)=="table","Requires a table")
  38.             if value.possition==nil then
  39.                 assert(value.posX,"Requires a X")
  40.                 assert(value.posY,"Requires a y")
  41.             end
  42.             value.name = value.name or nil
  43.             setmetatable(value, t.programs_defaults)
  44.             value.possition = value.possition or t:checkPossitions(value.posX,value.posY)
  45.             if value.possition ==nil then
  46.                 return false
  47.             end
  48.             value.drag = false
  49.             for index,k in pairs(t.programs) do
  50.                 if k.possition==value.possition then
  51.                     return false
  52.                 end
  53.             end
  54.             table.insert(t.programs,value)
  55.         end;
  56.         __call = function(self)
  57.             for v,k in pairs(self.programs) do
  58.                 if not k.drag then
  59.                     buf.drawImage(bdm,self.possitions[k.possition][1],self.possitions[k.possition][2],k.image)
  60.                 else
  61.                     buf.drawImage(bdm,k.posX,k.posY,k.image)
  62.                 end
  63.             end
  64.         end;   
  65.     };
  66.     possitions = {};
  67.     setPossistions = function(self)
  68.         local w,h = term.getSize()
  69.         for x=2, w, 6 do
  70.             if x+4<w then
  71.                 for y = 2, h, 6 do
  72.                     if y+4<h then
  73.                         table.insert(self.possitions,{[1]=x;[2]=y;[3]=x+4;[4]=y+4;})
  74.                     end
  75.                 end
  76.             end
  77.         end
  78.     end;
  79.     checkPossitions = function(self,x,y)
  80.         for v,k in pairs(self.possitions) do
  81.             if x>=k[1] and x<=k[3] then
  82.                 if y>=k[2] and y<=k[4] then
  83.                     return v
  84.                 end
  85.             end
  86.         end
  87.         return false
  88.     end;
  89.     check_click = function(self,x,y) --returns a index
  90.         for index,k in pairs(self.programs) do
  91.             local pos = self:checkPossitions(x,y)
  92.             if pos and pos==k.possition then
  93.                 return index
  94.             end
  95.         end
  96.         return false
  97.     end;
  98.     return_XYindex = function(self,index)
  99.         local pos = self.programs[index].possition
  100.         return self.possitions[pos]
  101.     end;
  102.     run_program = function(self,index)
  103.         assert(type(index)=="number","requires an index")
  104.         if self.programs[index].localtion~=nil then
  105.             if fs.exists(self.programs[index].localtion) then
  106.                 shell.run(self.programs[index].localtion)
  107.                 --sleep(2)
  108.                 return true
  109.             end
  110.         end
  111.         return false
  112.     end;
  113.     remove_program = function(self,index)
  114.         assert(type(index)=="number", "Requires A Index")
  115.         self.programs[index] = nil
  116.         return true
  117.     end;
  118.     save_programs = function(self,localtion)
  119.         local file = fs.open(localtion, "w")
  120.         file.write(textutils.serialize(self.programs))
  121.         file.close()
  122.     end;
  123.     load_programs = function(self,localtion)
  124.         if pcall(function()
  125.             if fs.exists(localtion) then
  126.                 local file = fs.open(localtion,"r")
  127.                 local data = file.readAll()
  128.                 file.close()
  129.                 self.programs = textutils.unserialize(data)
  130.             else
  131.                 self.programs = {}
  132.                 return false
  133.             end
  134.             for v,k in pairs(self.programs) do
  135.                 setmetatable(k,self.programs_defaults)
  136.             end
  137.             for v,k in pairs(self.programs)do
  138.                 if k.drag == true then
  139.                     k.drag = false
  140.                 end
  141.             end
  142.         end) then
  143.             return true
  144.         else
  145.             return false
  146.         end
  147.     end;
  148.     change_Pogram = function(self,index,localtion)
  149.         assert(type(index)=="number", "Requires a Index")
  150.         assert(type(localtion)=="string", "Requires a Localtion")
  151.         if not fs.exists(localtion) then
  152.             error("Requires a Adiquit Localtion")
  153.         end
  154.         self.programs[index].localtion = localtion
  155.     end;
  156.     change_image = function(self,index,localtion)
  157.         assert(type(index)=="number", "Requires a Index")
  158.         assert(type(localtion)=="string", "Requires a Localtion")
  159.         if not fs.exists(localtion) then
  160.             error("Requires a Adiquit Localtion")
  161.         end
  162.         self.programs[index].image = localtion
  163.     end;
  164.     change_possistion = function(self,index,possition)
  165.         assert(type(index)=="number", "Requires a Index")
  166.         assert(type(possition)=="number", "Requires a Possition")
  167.         local taken = false
  168.         for v,k in pairs(self.programs) do
  169.             if k.possition == possition then taken = true end
  170.         end
  171.         if taken then return false end
  172.             self.programs[index].possition = possition
  173.             self.programs[index].drag = false
  174.         return true
  175.     end;
  176.     change_possistionXY = function(self,index,posX, posY)
  177.         assert(type(index)=="number", "Requires a Index")
  178.         assert(type(posX)=="number", "Requires a X")
  179.         assert(type(posY)=="number", "Requires a Y")
  180.         local pos = self:checkPossitions(self,x,y)
  181.         if not pos then return false end
  182.         local taken = false
  183.         for v,k in pairs(self.programs) do
  184.             if k.possition == pos then taken = true end
  185.         end
  186.         if taken then return false end
  187.         self.programs[index].possition = pos
  188.         self.programs[index].drag = false
  189.         return true
  190.     end;
  191.     change_possistionDrag = function(self,index,posX,posY)
  192.         assert(type(index)=="number", "Requires a Index")
  193.         assert(type(posX)=="number", "Requires a X")
  194.         assert(type(posY)=="number", "Requires a Y")
  195.         self.programs[index].drag = true
  196.         if posX < 0 then
  197.             error("196- Change_possistionDrag: Illegal possistion X: Index>"..index.." posX>"..posX,2)
  198.         elseif posX > w-4 then
  199.             posX = w-4
  200.         end
  201.         if posY < 0 then
  202.             error("196- Change_possistionDrag: Illegal possistion Y: Index>"..index.." posX>"..posX,2)
  203.         elseif posY > h-5 then
  204.             posY = h-5
  205.         end
  206.         self.programs[index].posX = posX
  207.         self.programs[index].posY = posY
  208.     end;
  209.     returnDrag = function(self,index)
  210.         assert(type(index)=="number", "Requires a Index")
  211.         if self.programs[index].drag then
  212.             if self.programs[index].possition then
  213.                 self.programs[index].drag=false
  214.                 return true
  215.             end
  216.         end
  217.         return false
  218.     end;
  219.     draw_blank = function(self)
  220.         for i=1,24 do
  221.             local d = true -- this draws it
  222.             for v,k in pairs(self.programs) do
  223.                 if self.programs[v].possition==i then d = false end
  224.             end
  225.             if d then
  226.                 paintutils.drawImage(paintutils.loadImage("os/images/icons/blank"),self.possitions[i][1],self.possitions[i][2])
  227.             end
  228.         end
  229.     end;
  230.     compare_image = function(self,localtion)
  231.         for index,k in pairs(self.programs) do
  232.             if self.programs[index].image==localtion then
  233.                 return index
  234.             end
  235.         end
  236.         return false
  237.     end;
  238.     compare_program = function(self,localtion)
  239.         for index,k in pairs(self.programs) do
  240.             if self.programs[index].localtion==localtion then
  241.                 return index
  242.             end
  243.         end
  244.         return false
  245.     end;
  246.     programs = {};
  247. }
  248. function setup()
  249.     programs:setPossistions()
  250.     setmetatable(programs, programs.meta) --sets the metatable from meta to button
  251.     programs:load_programs(src)
  252. end
  253. function setT(srcs,save)
  254.   if type(srcs)=="string" and fs.exists(srcs) then
  255.       local file = fs.open(srcs,"w")
  256.       file.write(textutils.serialize(save))
  257.       file.close()
  258.   else
  259.     error("tried to load unkown file: "..srcs)
  260.   end
  261. end
  262. function getT(srcs,save) -- save = 1 or 1 == config
  263.   if type(srcs)=="string" and fs.exists(srcs) and type(save)=="number" then
  264.       local file = fs.open(srcs,"r")
  265.       local data = file.readAll()
  266.       file.close()
  267.       if save==0 then
  268.       icons = textutils.unserialize(data)
  269.       elseif save==1 then
  270.       --used for config
  271.       else
  272.       end
  273.     else
  274.     error("tried to load unkown file: "..srcs)
  275.   end
  276. end
  277. local function getUser()
  278.     Path = A.RCpath()
  279.     conf = A.getT(Path)
  280.     User = A.RUser()
  281.     src = "os/users/"..User.."/conf"
  282. end
  283. function Picon()
  284.     buf.copyBuffer(bdm,BPicon)
  285.     tbP = { }
  286.     tbPL = {} --used for finding if the program is public, private, or on the desktop
  287.     for v,k in ipairs(fs.list("os/programs")) do --Public Programs
  288.         if fs.isDir("os/programs/"..k) then
  289.             for s,d in ipairs(fs.list("os/programs/"..k)) do
  290.                 table.insert(tbP,k.."/"..d)
  291.                 table.insert(tbPL,1)
  292.             end
  293.         else
  294.             table.insert(tbP,k)
  295.             table.insert(tbPL,1)
  296.         end
  297.     end
  298.     for v,k in ipairs(fs.list("")) do --Desktop Programs
  299.         if fs.isDir(k) then
  300.             if k~="os" and k~="rom" then
  301.                 for s,d in ipairs(fs.list(k)) do
  302.                     table.insert(tbP,k.."/"..d)
  303.                     table.insert(tbPL,0)
  304.                 end
  305.             end
  306.         else
  307.             if k ~= "startup" then
  308.                 table.insert(tbP,k)
  309.                 table.insert(tbPL,0)
  310.             end
  311.         end
  312.     end
  313.     local filepos = "os/users/"..User.."/programs"
  314.     if fs.exists(filepos) then --Private Programs
  315.         for v,k in ipairs(fs.list(filepos)) do
  316.             filepos = filepos .."/"
  317.             if fs.isDir(filepos..k) then
  318.                 for s,d in ipairs(fs.list(filepos..k)) do
  319.                     table.insert(tbP,k.."/"..d)
  320.                     table.insert(tbPL,2)
  321.                 end
  322.             else
  323.                 table.insert(tbP,k)
  324.                 table.insert(tbPL,2)
  325.             end
  326.         end
  327.     end    
  328.     local x = 7
  329.     local y = 2
  330.     local x2 = w-8
  331.     local y2 = h-1
  332.     buf.drawFilledBox(BPicon,x,y,x2,y2,colors.white)
  333.     buf.drawBox(BPicon,x,y,x2,y2,colors.black)
  334.     buf.drawLine(BPicon,x2-1,y+1,x2-1,y2-1,colors.orange)
  335.     buf.drawPixel(BPicon,x2-1,y+1,colors.red)
  336.     buf.drawPixel(BPicon,x2-1,y2-1,colors.red)
  337.     buf.pos(x2-1,y+1)
  338.     buf.bWrite(BPicon,"^",colors.white,colors.red)
  339.     buf.pos(x2-1,y2-1)
  340.     buf.bWrite(BPicon,"v",colors.white,colors.red)
  341.     local X = x+2
  342.     local Y = y+1
  343.     buf.bc(colors.white)
  344.     buf.tc(colors.black)
  345.     for v,k in ipairs(tbP) do
  346.         buf.pos(X,Y)
  347.         buf.bWriteL(BPicon,k)
  348.         local t = {X-1,Y,X+#k,k,tbPL[v]}
  349.         table.insert(tbl2,t)
  350.         Y=Y+1
  351.     end
  352.     buf.drawBuffer(BPicon)
  353. end
  354. function Nicon()
  355.     buf.copyBuffer(bdm,BNicon)
  356.     tbi = {}
  357.     for v,k in ipairs(fs.list("os/images/icons")) do
  358.         if fs.isDir("os/images/icons/"..k) then
  359.             for s,d in ipairs(fs.list("os/images/icons/"..k)) do
  360.                 table.insert(tbi,k.."/"..d)
  361.             end
  362.         else
  363.             if k=="blank" then
  364.             else
  365.                 table.insert(tbi,k)
  366.             end
  367.         end
  368.     end
  369.     local imgN = math.ceil(#tbi/2)
  370.     local x = math.ceil((w/2) - ((imgN*5+(imgN+3))/2))
  371.     local y = math.ceil((h/2) - ((2*5+4)/2))
  372.     local x2 = x+(imgN*6+2)
  373.     local y2 = y+14
  374.     buf.drawFilledBox(BNicon,x,y,x2,y2,colors.black)
  375.     buf.drawBox(BNicon,x,y,x2,y2,colors.white)
  376.     local cx = x+2
  377.     local cy = y+2
  378.     for v,k in ipairs(tbi) do
  379.         buf.drawImage(BNicon,cx,cy,"os/images/icons/"..k)
  380.         local t = {cx,cy,cx+5,cy+5,k}
  381.         table.insert(tbl,t)
  382.         if cy==y+2+6 then
  383.             cy=cy-6
  384.             cx=cx+6
  385.         else
  386.             cy=cy+6
  387.         end
  388.     end
  389.     buf.drawBuffer(BNicon)
  390. end
  391. function dm()
  392.   conf = A.getT(A.RCpath())
  393.   buf.bc(conf["BCC"])
  394.   A.dmeun(conf["BCI"],1,1)  
  395.   programs()
  396.   buf.drawBuffer(bdm)
  397.   A.Time(wh[1]-4,wh[2],conf["MC"],conf["MTC"])
  398. end
  399. -------------------------------------------------------------------------
  400. function main()
  401.     setup()
  402.     dm()
  403.     t = os.startTimer(.1)
  404.     while rng do
  405.       getUser()
  406.       local arg = { os.pullEvent() }
  407.       programs:save_programs(src)
  408. --cm0------------------------------------------------------------------
  409.       if arg[1]=="timer" and arg[2]==t then
  410.         A.Time(wh[1]-4,wh[2],conf["MC"],conf["MTC"])
  411.         t = os.startTimer(.01)
  412.       elseif cm==0 then
  413.         --Main Meun nothing open
  414.         if arg[1]=="mouse_click" then
  415.             if arg[2]==1 then
  416.                 if arg[3]>=2 and arg[3]<=8 and arg[4]==1 then
  417.                     A.dmeun1()
  418.                     cm=1
  419.                 else
  420.                     local x = arg[3]
  421.                     local y = arg[4]
  422.                     local index = programs:check_click(x,y)
  423.                     if index then
  424.                         tbd = {arg[3],arg[4],index}
  425.                         cm=9 --check double click and drag
  426.                     end
  427.                 end
  428.             elseif arg[2]==2 then
  429.                 local x = arg[3]
  430.                 local y = arg[4]
  431.                 local index = programs:check_click(x,y)
  432.                 if index then
  433.                     local t = programs:return_XYindex(index) --table returned
  434.                     xy2 = {t[1],t[2],t[1]+14,t[2]+4,index}
  435.                     A.dmeun3(xy2)
  436.                     cm=3
  437.                 else
  438.                     xy = A.dmeun2(arg[3],arg[4])
  439.                     cm=2
  440.                 end
  441.             end
  442.         end
  443. --cm1------------------------------------------------------------------
  444.       elseif cm==1 then
  445.         --start meun
  446.         if arg[1]=="mouse_click" then
  447.          if arg[2]==1 then
  448.           if arg[3]<=11 and arg[3]>1 then
  449.             if arg[4]==3 then
  450.               dm()
  451.               rng=false
  452.               Exit = "log"
  453.             elseif arg[4]==4 then
  454.               os.shutdown()
  455.             elseif arg[4]==5 then
  456.               os.reboot()
  457.             elseif arg[4]==6 then
  458.               dm()
  459.               if A.userin(2,3,2) then
  460.                 rng=false
  461.                 Exit = "Manage"
  462.               end
  463.             elseif arg[4]==7 then
  464.               shell.run("os/APIS/fig")
  465.               YN = A.ExitIS(false)
  466.               A.ExitIS(true,false)
  467.               if YN then
  468.                 rng=false
  469.                 Exit="log"
  470.               else
  471.                 dm()
  472.               end
  473.               t = os.startTimer(.3)
  474.             end
  475.           end
  476.          end
  477.          cm=0
  478.          dm()
  479.         end
  480. --cm2-----------------------------------------------------------------------
  481.       elseif cm==2 then
  482.         --right click meun
  483.         local d = false
  484.         if arg[1]=="mouse_click" then
  485.           if arg[2]==1 then
  486.             if arg[3]>=xy[1] and arg[3]<=xy[1]+11 then
  487.               if arg[4]==xy[2]+1 then
  488.                 d="add Icon"
  489.               elseif arg[4]==xy[2]+2 then
  490.                 A.dmeun7(xy)
  491.                 d="programs"
  492.               elseif arg[4]==xy[2]+3 then  
  493.                 dm()
  494.                 local input = A.userin(2,3,1)
  495.                 shell.run("paint",input) ---new icon
  496.               elseif arg[4]==xy[2]+4 then
  497.               end
  498.               t = os.startTimer(.3)
  499.             end
  500.           end
  501.           if d=="add Icon" then
  502.             cm=4
  503.             dm()
  504.           elseif d=="programs" then
  505.             cm=10
  506.           else
  507.             cm=0
  508.             dm()
  509.           end
  510.         end
  511. --cm3-------------------------------------------------------------------
  512.       elseif cm==3 then
  513.         --right click on icons
  514.         if arg[1]=="mouse_click" then
  515.             term.setBackgroundColor(colors.blue)
  516.             if arg[2]==1 then
  517.                 if arg[3]>=xy2[1] and arg[3]<=xy2[3]+10 then
  518.                     if arg[4]==xy2[4]+2 then
  519.                         cm=5
  520.                         dm()
  521.                         Nicon()
  522.                     elseif arg[4]==xy2[4]+3 then
  523.                         dm()
  524.                         Picon()
  525.                         cm=6
  526.                     elseif arg[4]==xy2[4]+4 then
  527.                         programs:remove_program(xy2[5])
  528.                         cm=0
  529.                         dm()
  530.                     else   
  531.                         cm=0
  532.                         dm()
  533.                     end
  534.                 else
  535.                     cm=0
  536.                     dm()
  537.                 end
  538.             else
  539.                 cm=0
  540.                 dm()
  541.             end
  542.         end
  543. --cm4-------------------------------------------------------------------
  544.       elseif cm==4 then
  545.         programs:draw_blank()
  546.         --add icon
  547.         if arg[1] == "mouse_click" then
  548.             if arg[2]==1 then
  549.                 local x = arg[3]
  550.                 local y = arg[4]
  551.                 local cpos = programs:checkPossitions(x,y)
  552.                 if cpos then
  553.                     programs[1] = {possition = cpos;}
  554.                     dm()
  555.                 end
  556.             end
  557.             cm=0
  558.             dm()
  559.         end
  560. --cm5-------------------------------------------------------------------  
  561.      
  562.       elseif cm==5 then
  563.         --icon image meun
  564.         if arg[1] == "mouse_click" then
  565.             local ok = false
  566.             for v,k in ipairs(tbl) do
  567.                 if arg[3]>=k[1] and arg[3]<=k[3] then
  568.                     if arg[4]>=k[2] and arg[4]<=k[4] then
  569.                         if arg[2]==1 then
  570.                             programs:change_image(xy2[5],"os/images/icons/"..k[5])
  571.                             cm=0
  572.                         elseif arg[2]==2 then
  573.                             ok = true
  574.                             Inumber = k
  575.                         end
  576.                     end
  577.                 end
  578.             end
  579.             if ok then
  580.                 A.dmeun4(Inumber[1],Inumber[4])
  581.                 cm=7
  582.             else
  583.                 dm()
  584.                 cm=0
  585.             end
  586.         end
  587. --cm6--------------------------------------------------------------------
  588.       elseif cm==6 then
  589.         --program icon meun
  590.         local ok = false  
  591.         if arg[1] == "mouse_click" then
  592.             for v,k in ipairs(tbl2) do
  593.                 if arg[3]>=k[1] and arg[3]<=k[3] then
  594.                     if arg[4]==k[2] then
  595.                         if arg[2]==1 then
  596.                             if k[5] == 0 then
  597.                                 programs:change_Pogram(xy2[5],k[4])
  598.                             elseif k[5] == 1 then
  599.                                 programs:change_Pogram(xy2[5],"os/programs/"..k[4])
  600.                             elseif k[5] == 2 then
  601.                                 programs:change_Pogram(xy2[5],"os/users/"..tostring(User).."/programs/"..k[4])
  602.                             end
  603.                         elseif arg[2]==2 then
  604.                             ok = true
  605.                             Inumber = k
  606.                         else
  607.                             cm=0
  608.                             dm()
  609.                         end
  610.                     end
  611.                 end
  612.             end
  613.             if ok then
  614.                 A.dmeun4(Inumber[1],Inumber[2]+1)
  615.                 cm=8
  616.             else
  617.                 dm()
  618.                 cm=0
  619.             end
  620.         end
  621.       elseif cm==7 then
  622.         --right clikc image icon meun
  623.         if arg[1] == "mouse_click" then
  624.             if arg[2]==1 then
  625.                 if arg[3]>=Inumber[1] and arg[3]<=Inumber[3] then -- checks the x
  626.                     if arg[4] == Inumber[4]+1 then
  627.                         shell.run("paint","os/images/icons/"..Inumber[5])
  628.                     elseif arg[4] == Inumber[4]+2 then
  629.                         fs.delete("os/images/icons/"..Inumber[5])
  630.                         local index = programs:compare_image(Inumber[5])
  631.                         if type(index)=="number" then
  632.                             programs:change_image(index,"os/images/icons/icon1")
  633.                         end
  634.                     end
  635.                     t = os.startTimer(.3)
  636.                 end
  637.                 cm=5
  638.                 dm()
  639.                 Nicon()
  640.             end
  641.         end
  642.       elseif cm==8 then
  643.         if arg[1] == "mouse_click" then
  644.             if arg[2]==1 then --Inumber = 1-first x 2-Y 3-second x 4-program name
  645.                 if arg[3]>Inumber[1] and arg[3]<Inumber[1]+9 then
  646.                     if arg[4]==Inumber[2]+2 then --Edit Program
  647.                         if Inumber[5] == 0 then --desktop
  648.                             shell.run("edit",Inumber[4])
  649.                         elseif Inumber[5] == 1 then --Public
  650.                             shell.run("edit","os/programs/"..Inumber[4])
  651.                         elseif Inumber[5] == 2 then --Private
  652.                             shell.run("edit","os/users/"..tostring(User).."/programs/"..Inumber[4])
  653.                         end
  654.                     elseif arg[4]==Inumber[2]+3 then --delete Program
  655.                         if Inumber[5] == 0 then --desktop
  656.                             shell.run("delete",Inumber[4])
  657.                         elseif Inumber[5] == 1 then --Public
  658.                             shell.run("delete","os/programs/"..Inumber[4])
  659.                         elseif Inumber[5] == 2 then --Private
  660.                             shell.run("delete","os/users/"..tostring(User).."/programs/"..Inumber[4])
  661.                         end
  662.                         local index = programs:compare_image(Inumber[4])
  663.                         if index then
  664.                             programs:change_image(index,"")
  665.                         end
  666.                     end
  667.                 end
  668.             end
  669.             cm=6
  670.             Picon()
  671.         end
  672.       elseif cm==9 then
  673.         if arg[1]=="mouse_drag" then
  674.             if drag[1] and drag[3] then
  675.                 programs:change_possistionDrag(drag[2],arg[3],arg[4])
  676.             elseif not drag[3] then
  677.                 local index = programs:check_click(arg[3],arg[4])
  678.                 if index then
  679.                     drag[1]=true
  680.                     drag[2]=index
  681.                     drag[3]=true
  682.                     programs:change_possistionDrag(drag[2],arg[3],arg[4])
  683.                 end
  684.             end
  685.             dm()
  686.         elseif arg[1] == "mouse_click" then
  687.             if arg[2]==1 then
  688.                 local x = arg[3]
  689.                 local y = arg[4]
  690.                 local index = programs:check_click(x,y)
  691.                 if index then
  692.                     programs:run_program(tbd[3])
  693.                     cm=0
  694.                     t = os.startTimer(.3)
  695.                     dm()
  696.                 else
  697.                     cm=0
  698.                 end
  699.             end
  700.             dm()
  701.         elseif arg[1] == "mouse_up" then
  702.             if drag[1] then
  703.                 local pos = programs:checkPossitions(arg[3],arg[4])
  704.                 if pos then
  705.                     programs:change_possistion(drag[2],pos)
  706.                 else
  707.                     programs:returnDrag(drag[2])
  708.                 end
  709.                 drag[1]=false
  710.             end
  711.             drag[3] = false
  712.             dm()
  713.         else
  714.             cm=0
  715.             dm()
  716.         end
  717.       elseif cm==10 then --new programs code, for desk,Public, and Private
  718.         if arg[1] == "mouse_click" then
  719.           if arg[2]==1 then
  720.             dm()
  721.             if arg[3]>=xy[1] and arg[3]<=xy[1]+11 then
  722.               if arg[4]==xy[2]+1 then
  723.                 local input = A.userin(2,3,0)
  724.                 shell.run("edit",input) ---new icon
  725.               elseif arg[4]==xy[2]+2 then
  726.                 local input = A.userin(2,3,0)
  727.                 shell.run("edit","os/programs/"..input) ---new icon
  728.               elseif arg[4]==xy[2]+3 then  
  729.                 local input = A.userin(2,3,0)
  730.                 shell.run("edit","os/users/"..User.."/programs/"..input) ---new icon
  731.               elseif arg[4]==xy[2]+4 then
  732.                 shell.run("os/APIS/PastebinGet")
  733.               end
  734.               t = os.startTimer(.3)
  735.             end
  736.           end
  737.           dm()
  738.           cm=0
  739.         end
  740.       end
  741.     end
  742. ----------------------------------------------------------------------
  743.     if Exit == "log" or Exit == "Manage" then
  744.     else
  745.     term.setBackgroundColor(colors.black)
  746.     term.setTextColor(colors.white)
  747.     term.clear()
  748.     term.setCursorPos(1,1)
  749.     end
  750.     return true
  751. end
  752. local ok, err = pcall(main)
  753. if not ok then
  754.     A.Error(err)
  755. end
  756. if Exit == "Manage" then
  757.     shell.run("os/APIS/manage")
  758. elseif Exit == "log" then
  759.     shell.run("os/login")
  760. end
Add Comment
Please, Sign In to add comment