From 5ae6434d62cb6950127151ed24bde7db24d48491 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 3 Jan 2019 12:54:14 -0500 Subject: [PATCH] fix ui setTab --- sys/apis/git.lua | 24 ------------------------ sys/apis/ui.lua | 12 +++++++----- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/sys/apis/git.lua b/sys/apis/git.lua index 77c398c..c7a5ccc 100644 --- a/sys/apis/git.lua +++ b/sys/apis/git.lua @@ -1,20 +1,10 @@ local json = require('json') local Util = require('util') --- Limit queries to once per minecraft day --- TODO: will not work if time is stopped - local TREE_URL = 'https://api.github.com/repos/%s/%s/git/trees/%s?recursive=1' local FILE_URL = 'https://raw.githubusercontent.com/%s/%s/%s/%s' local git = { } -local fs = _G.fs -local os = _G.os - -if not _G.GIT then - _G.GIT = { } -end - function git.list(repository) local t = Util.split(repository, '(.-)/') @@ -27,17 +17,7 @@ function git.list(repository) path = table.concat(t, '/') .. '/' end - local cacheKey = table.concat({ user, repo, branch }, '-') - local fname = fs.combine('.git', cacheKey) - local function getContents() - if fs.exists(fname) then - local contents = Util.readTable(fname) - if contents and contents.data == os.day() then - return contents.data - end - fs.delete(fname) - end local dataUrl = string.format(TREE_URL, user, repo, branch) local contents = Util.download(dataUrl) if contents then @@ -55,10 +35,6 @@ function git.list(repository) error("Invalid repository") end - if not fs.exists(fname) then - Util.writeTable('.git/' .. cacheKey, { day = os.day(), data = data }) - end - local list = { } for _,v in pairs(data.tree) do if v.type == "blob" then diff --git a/sys/apis/ui.lua b/sys/apis/ui.lua index dcc0ae8..09ef448 100644 --- a/sys/apis/ui.lua +++ b/sys/apis/ui.lua @@ -2196,13 +2196,15 @@ end function UI.TabBar:eventHandler(event) if event.type == 'tab_select' then - local selected, si = Util.find(self:getFocusables(), 'uid', event.button.uid) - local previous, pi = Util.find(self:getFocusables(), 'selected', true) + local selected, si = Util.find(self.children, 'uid', event.button.uid) + local previous, pi = Util.find(self.children, 'selected', true) if si ~= pi then selected.selected = true - previous.selected = false - self:emit({ type = 'tab_change', current = si, last = pi, tab = selected }) + if previous then + previous.selected = false + self:emit({ type = 'tab_change', current = si, last = pi, tab = selected }) + end end UI.MenuBar.draw(self) end @@ -2252,7 +2254,7 @@ function UI.Tabs:add(children) end function UI.Tabs:selectTab(tab) - local menuItem = Util.find(self.tabBar:getFocusables(), 'tabUid', tab.uid) + local menuItem = Util.find(self.tabBar.children, 'tabUid', tab.uid) if menuItem then self.tabBar:emit({ type = 'tab_select', button = { uid = menuItem.uid } }) end