diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 295a5bf2d..c0fcdf188 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -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 }) diff --git a/frontend/apps/filemanager/filemanagercollection.lua b/frontend/apps/filemanager/filemanagercollection.lua index d77487310..6301fa433 100644 --- a/frontend/apps/filemanager/filemanagercollection.lua +++ b/frontend/apps/filemanager/filemanagercollection.lua @@ -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 diff --git a/frontend/apps/filemanager/filemanagerhistory.lua b/frontend/apps/filemanager/filemanagerhistory.lua index b4faf784b..fb1a34a2b 100644 --- a/frontend/apps/filemanager/filemanagerhistory.lua +++ b/frontend/apps/filemanager/filemanagerhistory.lua @@ -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 diff --git a/frontend/apps/filemanager/filemanagershortcuts.lua b/frontend/apps/filemanager/filemanagershortcuts.lua index 1e5c6970d..1fc9c47d2 100644 --- a/frontend/apps/filemanager/filemanagershortcuts.lua +++ b/frontend/apps/filemanager/filemanagershortcuts.lua @@ -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