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

Tapplus shortcut #3773

Merged
merged 4 commits into from
Mar 26, 2018
Merged

Tapplus shortcut #3773

merged 4 commits into from
Mar 26, 2018

Conversation

onde2rock
Copy link
Contributor

@onde2rock onde2rock commented Mar 18, 2018

Add an element in the filemanager touchmenu to open the tapPlus menu on non touch device only.

2018-03-18-105727_540x720_scrot

@Frenzie
Copy link
Member

Frenzie commented Mar 18, 2018

On Sdl, you have to comment isTouchDevice = yes to see it.

Pssht ;-)

if os.getenv("DISABLE_TOUCH") == "1" then
Device.isTouchDevice = no
end

end,
}
else
self.menu_items.plus_menu = {}
Copy link
Member

Choose a reason for hiding this comment

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

Does the top menu not accept it if you just leave it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not.
2018-03-18-213049_540x720_scrot

Took me some time to figure it out. Haven't look in menusorter to try to debug it.

Copy link
Member

Choose a reason for hiding this comment

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

Apparently I didn't consider the scenario that a top-level menu item might not be there. :-)

It should suffice to put a simple if menu_table["KOMenu:menu_buttons"][i].sub_item_table (or something like that)

for i,top_menu in ipairs(menu_table["KOMenu:menu_buttons"]) do
menu_table["KOMenu:menu_buttons"][i] = menu_table["KOMenu:menu_buttons"][i].sub_item_table
end

And of course a unit test, but I'll worry about that — unless you want to. ;-)

Would you mind checking if you can quickly fix the problem as suggested so that we can remove this else branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'm hitting a bit of a road block on this one. I really can't figure out how it all works.

If I add a simple check like you suggested, it works but the next menu are empty.

I'm trying to dig into the code but I'm progressing very slowly. Maybe we can close this one and I will keep working on it on another PR ?

Copy link
Member

Choose a reason for hiding this comment

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

If you want. In its current state it can't be merged yet because it has odd side effects on touch devices. We can also just leave it open and update the content later (whether by adding a commit or by force push).

screenshot_2018-03-20_21-06-47

@codecov-io
Copy link

codecov-io commented Mar 18, 2018

Codecov Report

Merging #3773 into master will decrease coverage by 0.02%.
The diff coverage is 31.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3773      +/-   ##
==========================================
- Coverage   52.07%   52.04%   -0.03%     
==========================================
  Files         207      207              
  Lines       27879    27910      +31     
==========================================
+ Hits        14517    14525       +8     
- Misses      13362    13385      +23
Impacted Files Coverage Δ
frontend/device/sdl/device.lua 43.9% <5.88%> (-9.95%) ⬇️
frontend/ui/widget/menu.lua 76.79% <50%> (-0.32%) ⬇️
frontend/ui/widget/buttontable.lua 95.45% <57.14%> (-2.17%) ⬇️
frontend/ui/widget/focusmanager.lua 41.3% <66.66%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e47a83...140a45d. Read the comment docs.

@@ -93,7 +94,7 @@ function CoverMenu:updateItems(select_number)
-- reset focus manager accordingly
self.selected = { x = 1, y = select_number }
-- set focus to requested menu item
self.item_group[select_number]:onFocus()
self:getFocusItem():handleEvent(Event:new("Focus"))
Copy link
Member

Choose a reason for hiding this comment

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

@poire-z Oh sorry, ignore #3745 (comment) It's fixed here already.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, good :)

@onde2rock onde2rock changed the title Tapplus shortcut [WIP] Tapplus shortcut Mar 20, 2018
@onde2rock
Copy link
Contributor Author

Ok, I'm not touching menusorter ever again :-)

Not quite as simple as #3773 (comment) suggested.

@onde2rock onde2rock changed the title [WIP] Tapplus shortcut Tapplus shortcut Mar 25, 2018
@Frenzie
Copy link
Member

Frenzie commented Mar 26, 2018

@onde2rock I don't think there's a need for an extra loop.

    -- cleanup, top-level items shouldn't have sub_item_table
    -- they should, however have one going in
    local menu_buttons_offset = 0
    for i,top_menu in ipairs(menu_table["KOMenu:menu_buttons"]) do
        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
        else
            menu_table["KOMenu:menu_buttons"][i] = nil
            menu_buttons_offset = menu_buttons_offset + 1
        end
    end

@onde2rock
Copy link
Contributor Author

onde2rock commented Mar 26, 2018

Yes that's better.

The returned table stay dirty this way, but the touchmenu still work.

An example with a lot of top-level that sould be removed :

{ { {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.settings.png",
    id = "setting"
  }, <1>{ {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.tools.png",
    id = "tools"
  }, <2>{ {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/appbar.magnify.browse.png",
    id = "search"
  }, <3>{ {...}, {...}, {...}, {...}, {...}, {...},
    icon = "resources/icons/menu-icon.png",
    id = "main"
  },
  [8] = {
    id = "tools",
    sub_item_table = <table 1>
  },
  [9] = {
    id = "search",
    sub_item_table = <table 2>
  },
  [10] = {
    id = "main",
    sub_item_table = <table 3>
  },
  id = "KOMenu:menu_buttons"
}

@onde2rock
Copy link
Contributor Author

Ok, unless further comment, I consider this PR done.

@Frenzie Frenzie merged commit 43c2c92 into koreader:master Mar 26, 2018
@Frenzie
Copy link
Member

Frenzie commented Mar 26, 2018

Alright, thanks! Someone will need to extend the unit tests for MenuSorter.

@onde2rock onde2rock deleted the tapplus-shortcut branch March 26, 2018 21:40
@poire-z
Copy link
Contributor

poire-z commented Apr 6, 2018

There is a side effect with this: #3792 does not work when tapping on the right.
It seems that after this PR, at least on touch devices that don't get this Plus tab, FileManagerMenu.tab_item_table has an invisible 5th element that looks like its 4th element (History... Exit koreader).
So, #self.tab_item_table = 5, and this safety check gets triggered:

function TouchMenuBar:switchToTab(index)
-- a little safety check
-- don't auto-activate a non-existent index
if index > #self.icon_widgets then
index = 1
end

Ok, I'm not touching menusorter ever again :-)

I take that as an advice, and let the menusorter guru have a look at it :)

@Frenzie
Copy link
Member

Frenzie commented Apr 6, 2018

Aside from the issue in question, if index is a high value wouldn't you expect it to be index = #self.icon_widgets?

@poire-z
Copy link
Contributor

poire-z commented Apr 6, 2018

if index is a high value wouldn't you expect it to be index = #self.icon_widgets?

Indeed, I'll change that in a coming PR.

@onde2rock
Copy link
Contributor Author

Hum that really look like the issue I described earlier : #3773 (comment).

Without adding a loop, there is no way to get a clean layout variable.
At the time, it didn't seem to make a difference for the menu, but you seem to have find one.
I will look into it.

@poire-z
Copy link
Contributor

poire-z commented Apr 7, 2018

An other minor thing: it outputs in touch devices' crash.log: WARN menu id not found: plus_menu

@onde2rock
Copy link
Contributor Author

WARN menu id not found: plus_menu

If I remember right, this is "normal", I probably shoud do something about it.

@onde2rock
Copy link
Contributor Author

onde2rock commented Apr 7, 2018

I can't reproduce this issue on SDL, tapping right in the filemanager on a non-key device correctly open the last menu.

Oh but I remember a bug I saw once while developing, if you migrate to the new version and your last position is the 4th tab, it try to directly open that tab, which now is tab_plus, and crash.
Maybe it's that ?

A crash log would be nice.

@poire-z
Copy link
Contributor

poire-z commented Apr 7, 2018

Oh, yes, the tap on the top right was workaround'ed yesterday by https://github.com/koreader/koreader/pull/3836/files#diff-200e39a7a76e64783d1d2c16a6d7c01e (if we get a higher index, use the latest one instead of 1).

But the following still remains (although it has now no visible side effect - dunno if it can still be considered a bug - or if it's ok for menusorter to put stuff in invisible slots):

FileManagerMenu.tab_item_table has an invisible 5th element that looks like its 4th element (History... Exit koreader).

About:

WARN menu id not found: plus_menu

If I remember right, this is "normal", I probably shoud do something about it.

Yes, it's probably normal, it should just not output it as WARN on a regular (non debug) device.

@Frenzie
Copy link
Member

Frenzie commented Apr 7, 2018

dunno if it can still be considered a bug

It is a bug, just a very minor one. I'd have blocked the plus menu PR otherwise. It negatively affects the clarity of analyzing MenuSorter.

Yes, it's probably normal, it should just not output it as WARN on a regular (non debug) device.

But it should. It's only logger.dbg that's debugging info. It's a warning because it's the menu saying something's messed up as opposed to showing the resulting output of the sorting or something like that.

onde2rock added a commit to onde2rock/koreader that referenced this pull request Apr 7, 2018
@onde2rock onde2rock mentioned this pull request Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants