mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
FileManager: Refresh key_events handlers on keyboard hotplug
This commit is contained in:
@@ -65,6 +65,13 @@ function FileManager:onSetRotationMode(rotation)
|
||||
return true
|
||||
end
|
||||
|
||||
function FileManager:onPhysicalKeyboardConnected()
|
||||
-- So that the key navigation shortcuts apply right away.
|
||||
-- This will also naturally call registerKeyEvents
|
||||
self:reinit(self.path, self.focused_file)
|
||||
end
|
||||
FileManager.onPhysicalKeyboardDisconnected = FileManager.onPhysicalKeyboardConnected
|
||||
|
||||
function FileManager:setRotationMode()
|
||||
local locked = G_reader_settings:isTrue("lock_rotation")
|
||||
if not locked then
|
||||
@@ -462,6 +469,11 @@ function FileManager:setupLayout()
|
||||
ui = self
|
||||
}
|
||||
|
||||
self:registerKeyEvents()
|
||||
end
|
||||
|
||||
function FileManager:registerKeyEvents()
|
||||
-- NOTE: There's no init vs. runtime distinction here, because we go through reinit at runtime.
|
||||
if Device:hasKeys() then
|
||||
self.key_events.Home = { { "Home" } }
|
||||
-- Override the menu.lua way of handling the back key
|
||||
@@ -470,6 +482,10 @@ function FileManager:setupLayout()
|
||||
-- Also remove the handler assigned to the "Back" key by menu.lua
|
||||
self.file_chooser.key_events.Close = nil
|
||||
end
|
||||
else
|
||||
self.key_events.Home = nil
|
||||
self.file_chooser.key_events.Back = nil
|
||||
self.file_chooser.key_events.Close = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -48,15 +48,25 @@ function FileManagerMenu:init()
|
||||
|
||||
self.registered_widgets = {}
|
||||
|
||||
if Device:hasKeys() then
|
||||
self.key_events.ShowMenu = { { "Menu" } }
|
||||
end
|
||||
self:registerKeyEvents(true)
|
||||
|
||||
self.activation_menu = G_reader_settings:readSetting("activate_menu")
|
||||
if self.activation_menu == nil then
|
||||
self.activation_menu = "swipe_tap"
|
||||
end
|
||||
end
|
||||
|
||||
function FileManagerMenu:registerKeyEvents(init)
|
||||
if Device:hasKeys() then
|
||||
self.key_events.ShowMenu = { { "Menu" } }
|
||||
elseif not init then
|
||||
self.key_events.ShowMenu = nil
|
||||
end
|
||||
end
|
||||
|
||||
FileManagerMenu.onPhysicalKeyboardConnected = FileManagerMenu.registerKeyEvents
|
||||
FileManagerMenu.onPhysicalKeyboardDisconnected = FileManagerMenu.registerKeyEvents
|
||||
|
||||
function FileManagerMenu:initGesListener()
|
||||
if not Device:isTouchDevice() then return end
|
||||
|
||||
|
||||
@@ -1168,7 +1168,6 @@ function Menu:switchItemTable(new_title, new_item_table, itemnumber, itemmatch)
|
||||
end
|
||||
|
||||
function Menu:onScreenResize(dimen)
|
||||
--- @todo Investigate: could this cause minor memory leaks?
|
||||
self:init()
|
||||
return false
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user