diff --git a/frontend/settings.lua b/frontend/settings.lua index 638484488..7a691dd9c 100644 --- a/frontend/settings.lua +++ b/frontend/settings.lua @@ -15,6 +15,21 @@ function DocSettings:getHistoryPath(fullpath) return "./history/["..basename:gsub("/","#").."] "..filename..".lua" end +function DocSettings:getPathFromHistory(hist_name) + -- 1. select everything included in brackets + local s = string.match(hist_name,"%b[]") + -- 2. crop the bracket-sign from both sides + -- 3. and finally replace decorative signs '#' to dir-char '/' + return string.gsub(string.sub(s,2,-3),"#","/") +end + +function DocSettings:getNameFromHistory(hist_name) + -- at first, search for path length + local s = string.len(string.match(hist_name,"%b[]")) + -- and return the rest of string without 4 last characters (".lua") + return string.sub(hist_name, s+2, -5) +end + function DocSettings:open(docfile) local conf_path = nil if docfile == ".reader" then diff --git a/frontend/ui/button.lua b/frontend/ui/button.lua index 034dff3a5..4f2cc4db6 100644 --- a/frontend/ui/button.lua +++ b/frontend/ui/button.lua @@ -23,6 +23,9 @@ function Button:init() face = Font:getFace(self.text_font_face, self.text_font_size) } local text_size = text_widget:getSize() + if self.width == nil then + self.width = text_size.w + end -- set FrameContainer content self[1] = FrameContainer:new{ margin = self.margin, diff --git a/frontend/ui/confirmbox.lua b/frontend/ui/confirmbox.lua index 5bc40e29c..704160843 100644 --- a/frontend/ui/confirmbox.lua +++ b/frontend/ui/confirmbox.lua @@ -25,10 +25,18 @@ function ConfirmBox:init() local ok_button = Button:new{ text = self.ok_text, + callback = function() + self.ok_callback() + UIManager:close(self) + end, } local cancel_button = Button:new{ text = self.cancel_text, - preselect = true + preselect = true, + callback = function() + self.cancel_callback() + UIManager:close(self) + end, } self.layout = { { ok_button, cancel_button } } diff --git a/frontend/ui/widget.lua b/frontend/ui/widget.lua index dbeae3f3a..6b4b4d452 100644 --- a/frontend/ui/widget.lua +++ b/frontend/ui/widget.lua @@ -206,7 +206,7 @@ FrameContainer = WidgetContainer:new{ } function FrameContainer:getSize() - local content_size =self[1]:getSize() + local content_size = self[1]:getSize() return Geom:new{ w = content_size.w + ( self.margin + self.bordersize + self.padding ) * 2, h = content_size.h + ( self.margin + self.bordersize + self.padding ) * 2 diff --git a/reader.lua b/reader.lua index e93839a4a..a0e8c9dc6 100755 --- a/reader.lua +++ b/reader.lua @@ -27,6 +27,32 @@ HomeMenu = InputContainer:new{ } function HomeMenu:setUpdateItemTable() + function readHistDir(order_arg, re) + local pipe_out = io.popen("ls "..order_arg.." -1 ./history") + for f in pipe_out:lines() do + table.insert(re, { + dir = DocSettings:getPathFromHistory(f), + name = DocSettings:getNameFromHistory(f), + }) + end + end + + local hist_sub_item_table = {} + local last_files = {} + readHistDir("-c", last_files) + for _,v in pairs(last_files) do + table.insert(hist_sub_item_table, { + text = v.name, + callback = function() + showReader(v.dir .. "/" .. v.name) + end + }) + end + table.insert(self.item_table, { + text = "Last documents", + sub_item_table = hist_sub_item_table, + }) + table.insert(self.item_table, { text = "Exit", callback = function() @@ -36,9 +62,8 @@ function HomeMenu:setUpdateItemTable() end function HomeMenu:onTapShowMenu() - if #self.item_table == 0 then - self:setUpdateItemTable() - end + self.item_table = {} + self:setUpdateItemTable() local home_menu = Menu:new{ title = "Home menu", diff --git a/wtest.lua b/wtest.lua index caeefaf2a..e1b6a9a87 100644 --- a/wtest.lua +++ b/wtest.lua @@ -8,6 +8,10 @@ require "ui/infomessage" require "ui/confirmbox" require "document/document" + +----------------------------------------------------- +-- widget that paints the grid on the background +----------------------------------------------------- TestGrid = Widget:new{} function TestGrid:paintTo(bb) @@ -25,7 +29,9 @@ function TestGrid:paintTo(bb) end end +----------------------------------------------------- -- we create a widget that paints a background: +----------------------------------------------------- Background = InputContainer:new{ is_always_active = true, -- receive events when other dialogs are active key_events = { @@ -37,7 +43,13 @@ Background = InputContainer:new{ FrameContainer:new{ background = 3, bordersize = 0, - dimen = Screen:getSize() + dimen = Screen:getSize(), + Widget:new{ + dimen = { + w = Screen:getWidth(), + h = Screen:getHeight(), + } + }, } } @@ -64,7 +76,9 @@ end +----------------------------------------------------- -- example widget: a clock +----------------------------------------------------- Clock = FrameContainer:new{ background = 0, bordersize = 1, @@ -96,6 +110,9 @@ function Clock:getTextWidget() } end +----------------------------------------------------- +-- a confirmbox box widget +----------------------------------------------------- Quiz = ConfirmBox:new{ text = "Tell me the truth, isn't it COOL?!", width = 300, @@ -108,6 +125,9 @@ Quiz = ConfirmBox:new{ end, } +----------------------------------------------------- +-- a menu widget +----------------------------------------------------- menu_items = { {text = "item1"}, {text = "item2"}, @@ -136,6 +156,9 @@ M = Menu:new{ } +----------------------------------------------------- +-- a reader view widget +----------------------------------------------------- readerwindow = CenterContainer:new{ dimen = Screen:getSize(), FrameContainer:new{ @@ -151,6 +174,10 @@ reader = ReaderUI:new{ } readerwindow[1][1] = reader + +----------------------------------------------------------------------- +-- you may want to uncomment following show calls to see the changes +----------------------------------------------------------------------- UIManager:show(Background:new()) UIManager:show(TestGrid) UIManager:show(Clock:new())