FileManager modules: Slightly less hackish onSetRotationMode handlers...

And, also, rotate the parent widget (i.e., FM/RV) to avoid leaving the
user with a broken layout when they exit in a different orientation ;).
pull/7527/head
NiLuJe 3 years ago
parent 732ab56104
commit d31dc1e450

@ -495,12 +495,8 @@ function FileManager:init()
self.active_widgets = { screenshoter } -- to get events even when hidden
table.insert(self, self.menu)
table.insert(self, FileManagerHistory:new{
ui = self,
})
table.insert(self, FileManagerCollection:new{
ui = self,
})
table.insert(self, FileManagerHistory:new{ ui = self })
table.insert(self, FileManagerCollection:new{ ui = self })
table.insert(self, FileManagerFileSearcher:new{ ui = self })
table.insert(self, FileManagerShortcuts:new{ ui = self })
table.insert(self, ReaderDictionary:new{ ui = self })

@ -135,6 +135,21 @@ function FileManagerCollection:onMenuHold(item)
return true
end
function FileManagerCollection:MenuSetRotationModeHandler(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(self._manager.coll_menu)
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
self._manager.ui.view:onSetRotationMode(rotation)
elseif self._manager.ui.onSetRotationMode then
self._manager.ui:onSetRotationMode(rotation)
else
Screen:setRotationMode(rotation)
end
self._manager:onShowColl()
end
return true
end
function FileManagerCollection:onShowColl(collection)
self.coll_menu = Menu:new{
ui = self.ui,
@ -144,21 +159,11 @@ function FileManagerCollection:onShowColl(collection)
is_borderless = true,
is_popout = false,
onMenuHold = self.onMenuHold,
onSetRotationMode = self.MenuSetRotationModeHandler,
_manager = self,
collection = collection,
}
-- Handle rotation events
local this = self
function self.coll_menu:onSetRotationMode(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(this.coll_menu)
Screen:setRotationMode(rotation)
this:onShowColl()
end
return true
end
self:updateItemTable()
self.coll_menu.close_callback = function()
-- Close it at next tick so it stays displayed

@ -123,6 +123,23 @@ function FileManagerHistory:onMenuHold(item)
return true
end
-- Can't *actually* name it onSetRotationMode, or it also fires in FM itself ;).
function FileManagerHistory:MenuSetRotationModeHandler(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(self._manager.hist_menu)
-- Also re-layout ReaderView or FileManager itself
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
self._manager.ui.view:onSetRotationMode(rotation)
elseif self._manager.ui.onSetRotationMode then
self._manager.ui:onSetRotationMode(rotation)
else
Screen:setRotationMode(rotation)
end
self._manager:onShowHist()
end
return true
end
function FileManagerHistory:onShowHist()
self.hist_menu = Menu:new{
ui = self.ui,
@ -132,20 +149,10 @@ function FileManagerHistory:onShowHist()
is_borderless = true,
is_popout = false,
onMenuHold = self.onMenuHold,
onSetRotationMode = self.MenuSetRotationModeHandler,
_manager = self,
}
-- Handle rotation events
local this = self
function self.hist_menu:onSetRotationMode(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(this.hist_menu)
Screen:setRotationMode(rotation)
this:onShowHist()
end
return true
end
self:updateItemTable()
self.hist_menu.close_callback = function()
-- Close it at next tick so it stays displayed

@ -214,6 +214,21 @@ function FileManagerShortcuts:onSetDimensions(dimen)
self.dimen = dimen
end
function FileManagerShortcuts:MenuSetRotationModeHandler(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(self._manager.fm_bookmark)
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
self._manager.ui.view:onSetRotationMode(rotation)
elseif self._manager.ui.onSetRotationMode then
self._manager.ui:onSetRotationMode(rotation)
else
Screen:setRotationMode(rotation)
end
self._manager:onShowFolderShortcutsDialog()
end
return true
end
function FileManagerShortcuts:onShowFolderShortcutsDialog()
self.fm_bookmark = Menu:new{
title = _("Folder shortcuts"),
@ -227,20 +242,10 @@ function FileManagerShortcuts:onShowFolderShortcutsDialog()
is_borderless = true,
curr_path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile(),
onMenuHold = self.onMenuHold,
onSetRotationMode = self.MenuSetRotationModeHandler,
_manager = self,
}
-- Handle rotation events
local this = self
function self.fm_bookmark:onSetRotationMode(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
UIManager:close(this.fm_bookmark)
Screen:setRotationMode(rotation)
this:onShowFolderShortcutsDialog()
end
return true
end
self:updateItemTable()
UIManager:show(self.fm_bookmark)
end

Loading…
Cancel
Save