mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #1124 from chrox/remember_menutab
remember menu tab index when showing reader menu
This commit is contained in:
@@ -38,9 +38,10 @@ function ReaderMenu:init()
|
||||
},
|
||||
filemanager = {
|
||||
icon = "resources/icons/appbar.cabinet.files.png",
|
||||
remember = false,
|
||||
callback = function()
|
||||
self.ui:onClose()
|
||||
self:onTapCloseMenu()
|
||||
self.ui:onClose()
|
||||
-- screen orientation is independent for docview and filemanager
|
||||
-- so we need to restore the screen mode for the filemanager
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
@@ -52,7 +53,9 @@ function ReaderMenu:init()
|
||||
},
|
||||
home = {
|
||||
icon = "resources/icons/appbar.home.png",
|
||||
remember = false,
|
||||
callback = function()
|
||||
self:onTapCloseMenu()
|
||||
self.ui:onClose()
|
||||
UIManager:quit()
|
||||
end,
|
||||
@@ -187,6 +190,7 @@ function ReaderMenu:onShowReaderMenu()
|
||||
local TouchMenu = require("ui/widget/touchmenu")
|
||||
main_menu = TouchMenu:new{
|
||||
width = Screen:getWidth(),
|
||||
last_index = self.last_tab_index,
|
||||
tab_item_table = {
|
||||
self.tab_item_table.navi,
|
||||
self.tab_item_table.typeset,
|
||||
@@ -225,6 +229,9 @@ function ReaderMenu:onShowReaderMenu()
|
||||
end
|
||||
|
||||
function ReaderMenu:onCloseReaderMenu()
|
||||
self.last_tab_index = self.menu_container[1].last_index
|
||||
DEBUG("remember menu tab index", self.last_tab_index)
|
||||
self:onSaveSettings()
|
||||
UIManager:close(self.menu_container)
|
||||
return true
|
||||
end
|
||||
@@ -247,7 +254,12 @@ function ReaderMenu:onSetDimensions(dimen)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderMenu:onReadSettings(config)
|
||||
self.last_tab_index = config:readSetting("menu_tab_index") or 1
|
||||
end
|
||||
|
||||
function ReaderMenu:onSaveSettings()
|
||||
self.ui.doc_settings:saveSetting("menu_tab_index", self.last_tab_index)
|
||||
end
|
||||
|
||||
function ReaderMenu:registerToMainMenu(widget)
|
||||
|
||||
@@ -157,6 +157,8 @@ function TouchMenuBar:init()
|
||||
self.icon_widgets = {}
|
||||
-- hold icon seperators
|
||||
self.icon_seps = {}
|
||||
-- hold all icon buttons
|
||||
self.icon_buttons = {}
|
||||
-- the start_seg for first icon_widget should be 0
|
||||
-- we asign negative here to offset it in the loop
|
||||
local start_seg = -icon_sep_width
|
||||
@@ -172,6 +174,8 @@ function TouchMenuBar:init()
|
||||
spacing, ib, spacing,
|
||||
})
|
||||
|
||||
table.insert(self.icon_buttons, ib)
|
||||
|
||||
-- we have to use local variable here for closure callback
|
||||
local _start_seg = end_seg + icon_sep_width
|
||||
local _end_seg = _start_seg + self.icon_widgets[k]:getSize().w
|
||||
@@ -234,6 +238,9 @@ function TouchMenuBar:init()
|
||||
self.dimen = Geom:new{ w = self.width, h = self.height }
|
||||
end
|
||||
|
||||
function TouchMenuBar:switchToTab(index)
|
||||
self.icon_buttons[index].callback()
|
||||
end
|
||||
|
||||
--[[
|
||||
TouchMenu widget for hierarchical menus
|
||||
@@ -377,7 +384,7 @@ function TouchMenu:init()
|
||||
self.item_group,
|
||||
}
|
||||
|
||||
self:switchMenuTab(1)
|
||||
self.bar:switchToTab(self.last_index or 1)
|
||||
self:updateItems()
|
||||
end
|
||||
|
||||
@@ -471,6 +478,9 @@ function TouchMenu:netToggle()
|
||||
end
|
||||
|
||||
function TouchMenu:switchMenuTab(tab_num)
|
||||
if self.tab_item_table[tab_num].remember ~= false then
|
||||
self.last_index = tab_num
|
||||
end
|
||||
if self.touch_menu_callback then
|
||||
self.touch_menu_callback()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user