Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Menusorter #3844

Merged
merged 5 commits into from
Apr 7, 2018
Merged

Fix Menusorter #3844

merged 5 commits into from
Apr 7, 2018

Conversation

onde2rock
Copy link
Contributor

@onde2rock onde2rock commented Apr 7, 2018

See : #3773 (comment)

@Frenzie How do you feel about this ?

Now the layout look like this :


{ { {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.cabinet.files.png",
    id = "filemanager_settings"
  }, { {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.settings.png",
    id = "setting"
  }, { {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.tools.png",
    id = "tools"
  }, { {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.magnify.browse.png",
    id = "search"
  }, { {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/menu-icon.png",
    id = "main"
  },
  id = "KOMenu:menu_buttons"
}

Instead of this :

{ { {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.cabinet.files.png",
    id = "filemanager_settings"
  }, { {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.settings.png",
    id = "setting"
  }, { {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.tools.png",
    id = "tools"
  }, { {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.magnify.browse.png",
    id = "search"
  }, <1>{ {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/menu-icon.png",
    id = "main"
  }, {
    id = "main",
    sub_item_table = <table 1>
  },
  id = "KOMenu:menu_buttons"
}

Copy link
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good at first glance.

@Frenzie Frenzie added the bug label Apr 7, 2018
menu_table["KOMenu:menu_buttons"][i-menu_buttons_offset] = menu_table["KOMenu:menu_buttons"][i].sub_item_table
local tmp = menu_table["KOMenu:menu_buttons"][i].sub_item_table
menu_table["KOMenu:menu_buttons"][i] = nil
menu_table["KOMenu:menu_buttons"][i-menu_buttons_offset] = tmp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like vague names like tmp as opposed to tmp_descriptor. But anyway, I'd write it something like this:

    for i,top_menu in ipairs(menu_table["KOMenu:menu_buttons"]) do
        local menu_button = menu_table["KOMenu:menu_buttons"][i]

        if menu_button.sub_item_table then
            menu_table["KOMenu:menu_buttons"][i-menu_buttons_offset] = menu_button.sub_item_table
        else
            menu_buttons_offset = menu_buttons_offset + 1
        end

        menu_button = nil
    end

if menu_table["KOMenu:menu_buttons"][i].sub_item_table then
menu_table["KOMenu:menu_buttons"][i-menu_buttons_offset] = menu_table["KOMenu:menu_buttons"][i].sub_item_table
local menu_button = menu_table["KOMenu:menu_buttons"][i].sub_item_table
menu_table["KOMenu:menu_buttons"][i] = nil
Copy link
Member

@Frenzie Frenzie Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's arbitrary in principle, but within the context of this file this should go at the bottom. It's how all the other cleanup nilling is structured and deviations make it harder to read. :-)

No further comments besides the double space in

local menu_button  =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go at the bottom

Yes I understand, but in this case the order is important. It doesn't work if placed after the if end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, you'd have to check if menu_buttons_offset > 0. Very well, let's keep it like this.

@Frenzie Frenzie merged commit d7a7a78 into koreader:master Apr 7, 2018
@Frenzie
Copy link
Member

Frenzie commented Apr 7, 2018

Thanks!

@poire-z
Copy link
Contributor

poire-z commented Apr 19, 2018

Mhhh, thought I didn't get that anymore, but I still did and do, with latest (1674) too:

crash1638.log:04/07/18-23:43:51 WARN  menu id not found: plus_menu
crash1638.log:04/08/18-21:11:05 WARN  menu id not found: plus_menu
crash1638.log:04/08/18-21:15:48 WARN  menu id not found: plus_menu
crash1638.log:04/09/18-07:41:46 WARN  menu id not found: plus_menu
crash1638.log:04/09/18-19:28:11 WARN  menu id not found: plus_menu
crash1638.log:04/09/18-21:31:11 WARN  menu id not found: plus_menu
crash1638.log:04/10/18-00:06:09 WARN  menu id not found: plus_menu
crash1646.log:04/11/18-12:05:37 WARN  menu id not found: plus_menu
crash1646.log:04/12/18-09:39:57 WARN  menu id not found: plus_menu

@onde2rock
Copy link
Contributor Author

Ok, if it's bothering you, I can change it do debug.

@poire-z
Copy link
Contributor

poire-z commented Apr 20, 2018

Dunno. @Frenzie ?
Is the minor bug (#3773 (comment)) fixed? and this message should then no more be a WARN.
Or does it needs a better fix?

@Frenzie
Copy link
Member

Frenzie commented Apr 20, 2018

No, it's supposed to be an actual warning for users customizing their menu without the expectation that they have to enable debug mode to be warned of a mistake. The plus_menu breaks an assumption, though it's conceivable that the assumption breaks down in submenus too. In any case it's the assumption that's broken in some way. [Edit: the top menu was intended to be customizable, but I never considered that someone would want to make it dynamic.]

If you're bothered by the legitimate warning then the proper form of that initial self.menu_items.plus_menu = {} would be something like order.plus_menu = nil. That'd be working with MenuSorter rather than against it.

NB I'm not convinced that's quite the right way to go about it. But it's the proper form of that particular workaround.

Edit 2:
Concretely, that'd look something like this:

--- a/frontend/apps/filemanager/filemanagermenu.lua
+++ b/frontend/apps/filemanager/filemanagermenu.lua
@@ -81,6 +81,8 @@ function FileManagerMenu:initGesListener()
 end
 
 function FileManagerMenu:setUpdateItemTable()
+    local order = require("ui/elements/filemanager_menu_order")
+
     for _, widget in pairs(self.registered_widgets) do
         local ok, err = pcall(widget.addToMainMenu, widget, self.menu_items)
         if not ok then
@@ -254,7 +256,9 @@ function FileManagerMenu:setUpdateItemTable()
             self:exitOrRestart(function() UIManager:restartKOReader() end)
         end,
     }
-    if not Device:isTouchDevice() then
+    if Device:isTouchDevice() then
+        order.plus_menu = nil
+    else
         --add a shortcut on non touch-device
         --because this menu is not accessible otherwise
         self.menu_items.plus_menu = {
@@ -267,8 +271,6 @@ function FileManagerMenu:setUpdateItemTable()
         }
     end
 
-    local order = require("ui/elements/filemanager_menu_order")
-
     local MenuSorter = require("ui/menusorter")
     self.tab_item_table = MenuSorter:mergeAndSort("filemanager", self.menu_items, order)
 end

@onde2rock
Copy link
Contributor Author

What about this ?

diff --git a/frontend/ui/menusorter.lua b/frontend/ui/menusorter.lua
index 8fc0110c..11b7422d 100644
--- a/frontend/ui/menusorter.lua
+++ b/frontend/ui/menusorter.lua
@@ -98,7 +98,7 @@ function MenuSorter:sort(item_table, order)
                 i = i + 1
             end
         else
-            if order_id ~= "KOMenu:disabled" then
+            if order_id ~= "KOMenu:disabled" and order_id ~= "plus_menu" then
                 logger.warn("menu id not found:", order_id)
             end
         end
   

@Frenzie
Copy link
Member

Frenzie commented Apr 21, 2018

I like the warning but if you really want to get rid of it for now with a quick hack I can live with that. :-)

onde2rock added a commit to onde2rock/koreader that referenced this pull request Apr 21, 2018
The plus_menu break the assumption of the menusorter about a tab beeing
always present.
See : koreader#3844 (comment)
@poire-z
Copy link
Contributor

poire-z commented Apr 21, 2018

Thanks :)

Frenzie pushed a commit that referenced this pull request Apr 21, 2018
The plus_menu break the assumption of the menusorter about a tab beeing
always present.
See : #3844 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants