mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #786 from houqp/new_ui_code
add last documents history and fix wtest.lua
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
@@ -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
|
||||
|
||||
31
reader.lua
31
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",
|
||||
|
||||
29
wtest.lua
29
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())
|
||||
|
||||
Reference in New Issue
Block a user