mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Add option for deleting history entries and refactor dialogs
- Refactor FileDialog and HightlightDialog into ButtonDialog - Create a new ButtonDialog when a file in the History dialog is hold, offering an option to delete the history entry.
This commit is contained in:
@@ -1,71 +1,21 @@
|
||||
local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local FileManagerMenu = require("apps/filemanager/filemanagermenu")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local FileChooser = require("ui/widget/filechooser")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local ButtonTable = require("ui/widget/buttontable")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Input = require("ui/input")
|
||||
local Font = require("ui/font")
|
||||
local Screen = require("ui/screen")
|
||||
local Geom = require("ui/geometry")
|
||||
local Device = require("ui/device")
|
||||
local Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local FileDialog = InputContainer:new{
|
||||
buttons = nil,
|
||||
tap_close_callback = nil,
|
||||
}
|
||||
|
||||
function FileDialog:init()
|
||||
if Device:hasKeyboard() then
|
||||
self.key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any },
|
||||
seqtext = "any key", doc = _("close dialog") }
|
||||
}
|
||||
else
|
||||
self.ges_events.TapClose = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
FrameContainer:new{
|
||||
ButtonTable:new{
|
||||
width = Screen:getWidth()*0.9,
|
||||
buttons = self.buttons,
|
||||
},
|
||||
background = 0,
|
||||
bordersize = 2,
|
||||
radius = 7,
|
||||
padding = 2,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function FileDialog:onTapClose()
|
||||
UIManager:close(self)
|
||||
if self.tap_close_callback then
|
||||
self.tap_close_callback()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local FileManager = InputContainer:extend{
|
||||
title = _("FileManager"),
|
||||
width = Screen:getWidth(),
|
||||
@@ -127,7 +77,7 @@ function FileManager:init()
|
||||
|
||||
function file_chooser:onFileHold(file)
|
||||
--DEBUG("hold file", file)
|
||||
self.file_dialog = FileDialog:new{
|
||||
self.file_dialog = ButtonDialog:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local Screen = require("ui/screen")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local DocSettings = require("docsettings")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local history_dir = "./history/"
|
||||
|
||||
local FileManagerHistory = InputContainer:extend{
|
||||
hist_menu_title = _("History"),
|
||||
}
|
||||
@@ -19,25 +22,43 @@ function FileManagerHistory:onSetDimensions(dimen)
|
||||
self.dimen = dimen
|
||||
end
|
||||
|
||||
function FileManagerHistory:onShowHist()
|
||||
self:updateItemTable()
|
||||
function FileManagerHistory:onMenuHold(item)
|
||||
self.histfile_dialog = ButtonDialog:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Delete"),
|
||||
callback = function()
|
||||
os.remove(history_dir..item.histfile)
|
||||
self._manager:updateItemTable()
|
||||
UIManager:close(self.histfile_dialog)
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
UIManager:show(self.histfile_dialog)
|
||||
return true
|
||||
end
|
||||
|
||||
function FileManagerHistory:onShowHist()
|
||||
local menu_container = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
}
|
||||
|
||||
local hist_menu = Menu:new{
|
||||
title = _("History"),
|
||||
item_table = self.hist,
|
||||
self.hist_menu = Menu:new{
|
||||
ui = self.ui,
|
||||
width = Screen:getWidth()-50,
|
||||
height = Screen:getHeight()-50,
|
||||
show_parent = menu_container,
|
||||
onMenuHold = self.onMenuHold,
|
||||
_manager = self,
|
||||
}
|
||||
self:updateItemTable()
|
||||
|
||||
table.insert(menu_container, hist_menu)
|
||||
table.insert(menu_container, self.hist_menu)
|
||||
|
||||
hist_menu.close_callback = function()
|
||||
self.hist_menu.close_callback = function()
|
||||
UIManager:close(menu_container)
|
||||
end
|
||||
|
||||
@@ -58,7 +79,6 @@ end
|
||||
function FileManagerHistory:updateItemTable()
|
||||
function readHistDir(re)
|
||||
local sorted_files = {}
|
||||
local history_dir = "./history/"
|
||||
for f in lfs.dir(history_dir) do
|
||||
local path = history_dir..f
|
||||
if lfs.attributes(path, "mode") == "file" then
|
||||
@@ -70,6 +90,7 @@ function FileManagerHistory:updateItemTable()
|
||||
table.insert(re, {
|
||||
dir = DocSettings:getPathFromHistory(v.file),
|
||||
name = DocSettings:getNameFromHistory(v.file),
|
||||
histfile = v.file,
|
||||
})
|
||||
end
|
||||
end
|
||||
@@ -80,11 +101,13 @@ function FileManagerHistory:updateItemTable()
|
||||
for _,v in pairs(last_files) do
|
||||
table.insert(self.hist, {
|
||||
text = v.name,
|
||||
histfile = v.histfile,
|
||||
callback = function()
|
||||
showReaderUI(v.dir .. "/" .. v.name)
|
||||
end
|
||||
})
|
||||
end
|
||||
self.hist_menu:swithItemTable(self.hist_menu_title, self.hist)
|
||||
end
|
||||
|
||||
return FileManagerHistory
|
||||
return FileManagerHistory
|
||||
|
||||
@@ -1,63 +1,14 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local Device = require("ui/device")
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local ButtonTable = require("ui/widget/buttontable")
|
||||
local Input = require("ui/input")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local HighlightDialog = InputContainer:new{
|
||||
buttons = nil,
|
||||
tap_close_callback = nil,
|
||||
}
|
||||
|
||||
function HighlightDialog:init()
|
||||
if Device:hasKeyboard() then
|
||||
self.key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any },
|
||||
seqtext = "any key", doc = _("close dialog") }
|
||||
}
|
||||
else
|
||||
self.ges_events.TapClose = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
FrameContainer:new{
|
||||
ButtonTable:new{
|
||||
width = Screen:getWidth()*0.9,
|
||||
buttons = self.buttons,
|
||||
},
|
||||
background = 0,
|
||||
bordersize = 2,
|
||||
radius = 7,
|
||||
padding = 2,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function HighlightDialog:onTapClose()
|
||||
UIManager:close(self)
|
||||
if self.tap_close_callback then
|
||||
self.tap_close_callback()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local ReaderHighlight = InputContainer:new{}
|
||||
|
||||
function ReaderHighlight:init()
|
||||
@@ -228,7 +179,7 @@ function ReaderHighlight:onTapXPointerSavedHighlight(ges)
|
||||
end
|
||||
|
||||
function ReaderHighlight:onShowHighlightDialog(page, index)
|
||||
self.edit_highlight_dialog = HighlightDialog:new{
|
||||
self.edit_highlight_dialog = ButtonDialog:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
@@ -327,7 +278,7 @@ function ReaderHighlight:onHoldRelease(arg, ges)
|
||||
self.selected_word = nil
|
||||
elseif self.selected_text then
|
||||
DEBUG("show highlight dialog")
|
||||
self.highlight_dialog = HighlightDialog:new{
|
||||
self.highlight_dialog = ButtonDialog:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
|
||||
58
frontend/ui/widget/buttondialog.lua
Normal file
58
frontend/ui/widget/buttondialog.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
local ButtonTable = require("ui/widget/buttontable")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local Device = require("ui/device")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Geom = require("ui/geometry")
|
||||
local Input = require("ui/input")
|
||||
local Screen = require("ui/screen")
|
||||
local UIManager = require("ui/uimanager")
|
||||
|
||||
local ButtonDialog = InputContainer:new{
|
||||
buttons = nil,
|
||||
tap_close_callback = nil,
|
||||
}
|
||||
|
||||
function ButtonDialog:init()
|
||||
if Device:hasKeyboard() then
|
||||
self.key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any },
|
||||
seqtext = "any key", doc = _("close dialog") }
|
||||
}
|
||||
else
|
||||
self.ges_events.TapClose = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
FrameContainer:new{
|
||||
ButtonTable:new{
|
||||
width = Screen:getWidth()*0.9,
|
||||
buttons = self.buttons,
|
||||
},
|
||||
background = 0,
|
||||
bordersize = 2,
|
||||
radius = 7,
|
||||
padding = 2,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function ButtonDialog:onTapClose()
|
||||
UIManager:close(self)
|
||||
if self.tap_close_callback then
|
||||
self.tap_close_callback()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return ButtonDialog
|
||||
Reference in New Issue
Block a user