Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- local Items = {}
- local DeskItems = {}
- local OpenedTask = "n"
- local Tabs = {}
- local ActiveTab = 0
- local FullScreen = false
- local Desktop = "desktop"
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function GetItems()
- local file = fs.open("os/SystemFiles/TaskbarShortcuts","r")
- local Name
- local Path
- local Image
- repeat
- Name = file.readLine()
- Path = file.readLine()
- Image = file.readLine()
- if Name ~= nil then Items[#Items + 1] = {Name,Path,Image} end
- until Name == nil
- file.close()
- GetDesktop()
- end
- function GetDesktop()
- local file = fs.open("os/SystemFiles/DesktopShortcuts","r")
- local Name
- local Path
- local Image
- repeat
- Name = file.readLine()
- Path = file.readLine()
- Image = file.readLine()
- if Name ~= nil then DeskItems[#DeskItems + 1] = {Name,Path,Image} end
- until Name == nil
- file.close()
- end
- function CreateTab(Program)
- Tabs[#Tabs + 1] = {window.create(term.current(),1,2,w, h - 1),Program}
- ActiveTab = #Tabs
- end
- function DrawTabbar()
- term.redirect(Tabs[ActiveTab][1])
- paintutils.drawBox(1,1,w,1,colors.gray)
- term.setCursorPos(1,1)
- term.write(Tabs[ActiveTab][2])
- paintutils.drawBox(w,1,w,1,colors.red)
- end
- function DrawTaskbar()
- local Prev = term.redirect(term.native())
- paintutils.drawBox(6,h,w-8,h,colors.lightGray)
- paintutils.drawBox(1,h,5,h,colors.gray)
- paintutils.drawBox(w - 7, h, w, h, colors.lightBlue)
- term.setCursorPos(w - 7, h)
- term.write(textutils.formatTime(os.time("local")))
- DrawItems(Prev)
- end
- function DrawItems(Prev)
- local x = 7
- for i = 1, #Items do
- if Items[i][3] == "n" then
- paintutils.drawBox(x, h - 3, x + 3, h - 1, colors.white)
- else
- local Image = paintutils.loadImage(Items[i][3])
- paintutils.drawImage(Image,x,h - 3)
- end
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(x,h)
- term.write(Items[i][1])
- x = x + 4
- end
- term.redirect(Prev)
- end
- function Popup()
- local Prev = term.redirect(term.native())
- paintutils.drawFilledBox(1, h - 10, 7, h - 1, colors.lightGray)
- local n = 0
- while true do
- local a, b, c, d = os.pullEvent("mouse_click")
- if c > 7 or d < h - 10 or d == h then n = 50 end
- if n > 0 then break end
- end
- term.redirect(Prev)
- end
- function TabBar()
- local Prev = term.redirect(term.native())
- DrawTabbar()
- term.redirect(Prev)
- local n = 0
- while true do
- local a, b, c, d = os.pullEvent("mouse_click")
- if d == 1 and c == w then n = 1 end
- if n > 0 then break end
- end
- end
- function Run()
- end
- function RunTask()
- term.redirect(Tabs[ActiveTab][1])
- shell.run(Tabs[ActiveTab][2])
- end
- function DrawDesktop()
- local x = 2
- local y = 1
- local MW = w / 5
- for i = 1, #DeskItems do
- if DeskItems[i][3] == "n" then
- paintutils.drawFilledBox(x,y,x+3,y+2,colors.white)
- else
- local Image = paintutils.loadImage(DeskItems[i][3])
- paintutils.drawImage(Image,x,y)
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(x, y + 3)
- term.write(DeskItems[i][1])
- if x + 5 > w then
- x = 2
- y = y + 4
- else
- x = x + 5
- end
- end
- end
- function Loop()
- term.setBackgroundColor(colors.black)
- Clear()
- if FullScreen == false then
- if ActiveTab > 0 then
- parallel.waitForAny(Int,RunTask,TabBar)
- else
- parallel.waitForAny(Int,DesktopInt)
- end
- else
- parallel.waitForAny(BackInt,RunTask)
- end
- if ActiveTab > 0 then
- term.redirect(term.native())
- Tabs[ActiveTab][1].setVisible(false)
- ActiveTab = 0
- end
- term.setBackgroundColor(colors.black)
- Clear()
- Loop()
- end
- function Int()
- local n = 0
- while true do
- DrawTaskbar()
- local a, b, c, d = os.pullEvent()
- if a == "mouse_click" and d > h - 2 then
- local x = 8
- for i = 1, #Items do
- if c >= x and c <= x + 3 then n = i end
- x = x + 4
- end
- if n == 0 and c < 6 then n = 50 end
- end
- if a == "key" and b == keys.p then n = 50 end
- if n > 0 then break end
- end
- if n == 50 then Popup() end
- if n < 50 then CreateTab(Items[n][2]) end
- end
- function DesktopInt()
- DrawDesktop()
- local n = 0
- while true do
- DrawTaskbar()
- local a, b, c, d = os.pullEvent("mouse_click")
- local x = 2
- local y = 1
- for i = 1, #DeskItems do
- if c >= x and c <= x+3 and d >= y and d <= y + 2 then n = i end
- if x + 3 > w then x = 2 y = y + 4 else x = x + 5 end
- end
- if n > 0 then break end
- end
- CreateTab(DeskItems[n][2])
- end
- function BackInt()
- local n = 0
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.p then n = 50 end
- if n > 0 then break end
- end
- if n == 50 then FullScreen = false end
- end
- GetItems()
- Loop()
Add Comment
Please, Sign In to add comment