Disable View mode shortcuts outside of View mode
ClosedPublic

Authored by huoni on Mar 24 2018, 6:42 AM.

Details

Summary

The document view zoom actions like Zoom to Fit only apply to
View mode.
In the case of Zoom to Fit, the default keyboard shortcut is
F, which interferes with single-letter keypresses in Browse
mode (to skip to files starting with that letter).

There is an existing function that enables or disables these View
mode actions based on whether ViewMainPage is visible, however this
function isn't called when leaving View mode. This patch ensures
that these actions are updated when ViewMainPage is reset, ensuring
these actions are disabled when View mode is not active.

Test Plan

Ensure default F shortcut for Zoom to Fit is set.
Go to Browse in a folder containing at least one image starting with F.
Press F - selection to jump to that image.
Go to {View, and ensure F triggers Zoom to Fit.
Go back to Browse and ensure F still works as previously.

Diff Detail

Repository
R260 Gwenview
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
huoni requested review of this revision.Mar 24 2018, 6:42 AM
huoni created this revision.
rkflx added a subscriber: rkflx.Mar 24 2018, 8:55 AM

First of all, nice bug you caught here…

Nevertheless I think your patch is only the easy way out, while the problem should be solved properly:

This prevents the keypress from being passed to underlying QListView, therefore preventing F from jumping to images starting with "F".

As far as I can see, F (and others?) should search in Browse mode, and activate the action in View mode. That's more complicated than removing some code, but in general Qt should allow for implementing this (either manually enable/disable the shortcut, or set a context).

The other zoom modes do not have default shortcuts.

My long-term strategy would be to add sensible shortcuts for most of the tools and actions. F is great, and for 100% normally 1 is used, however here it is already taken for rating. Sounds like a larger effort with potential for bikeshedding, but eventually this should be tackled…

First of all, nice bug you caught here…

Nevertheless I think your patch is only the easy way out, while the problem should be solved properly:

This prevents the keypress from being passed to underlying QListView, therefore preventing F from jumping to images starting with "F".

As far as I can see, F (and others?) should search in Browse mode, and activate the action in View mode. That's more complicated than removing some code, but in general Qt should allow for implementing this (either manually enable/disable the shortcut, or set a context).

+1

My long-term strategy would be to add sensible shortcuts for most of the tools and actions. F is great, and for 100% normally 1 is used, however here it is already taken for rating. Sounds like a larger effort with potential for bikeshedding, but eventually this should be tackled…

Maybe 0 for Zoom to 100%?

rkflx added a comment.Mar 24 2018, 5:09 PM

Maybe 0 for Zoom to 100%?

Go to View mode and try what happens ;)

Maybe 0 for Zoom to 100%?

Go to View mode and try what happens ;)

Oops, how embarrassing.

First of all, nice bug you caught here…

Nevertheless I think your patch is only the easy way out, while the problem should be solved properly:

This prevents the keypress from being passed to underlying QListView, therefore preventing F from jumping to images starting with "F".

As far as I can see, F (and others?) should search in Browse mode, and activate the action in View mode. That's more complicated than removing some code, but in general Qt should allow for implementing this (either manually enable/disable the shortcut, or set a context).

Agree, but I wasn't sure if having keyboard shortcuts only work in some contexts was acceptable behaviour. Definitely a more complicated fix.
I was thinking perhaps this could be a temporary fix while working on the above, but I suppose one can just unbind the default.

The other zoom modes do not have default shortcuts.

My long-term strategy would be to add sensible shortcuts for most of the tools and actions. F is great, and for 100% normally 1 is used, however here it is already taken for rating. Sounds like a larger effort with potential for bikeshedding, but eventually this should be tackled…

= is generally the key used in browsers for 100%.

huoni updated this revision to Diff 30908.Mar 30 2018, 9:03 AM
  • Implement @rkflx's suggestion of disabling View shortcuts in Browse
huoni retitled this revision from Remove default keyboard shortcut F for Zoom to Fit action to Disable View mode shortcuts in Browse mode.Mar 30 2018, 9:10 AM
huoni edited the summary of this revision. (Show Details)
huoni edited the test plan for this revision. (Show Details)
huoni added a project: Gwenview.

As far as I can see, F (and others?) should search in Browse mode, and activate the action in View mode. That's more complicated than removing some code, but in general Qt should allow for implementing this (either manually enable/disable the shortcut, or set a context).

Agree, but I wasn't sure if having keyboard shortcuts only work in some contexts was acceptable behaviour. Definitely a more complicated fix.
I was thinking perhaps this could be a temporary fix while working on the above, but I suppose one can just unbind the default.

Looked at this again, turns out most of the work had been done, it just wasn't triggered when switching views.

+1, works for me!

rkflx added a comment.May 6 2018, 10:07 PM

When starting in Browse, View actions such as Zoom to Fit are correctly ignored

Hm, I cannot confirm that part: Even starting in Browse, I'm unable to jump to f.png when pressing f (it does work with d.png / d). Interestingly, F works for f.png.

Anyway, as mentioned in the duplicate before, the patch works. Looking at the code now, I noticed something when adding qDebug() to every call site of updateActions(), though:

# Press Enter to switch to View mode
setView();
slotViewModeChanged();
slotViewModeChanged();
slotAdapterChanged();

# Press Enter again to switch back to Browse mode
slotViewModeChanged();

I'm aware in ImageOpsContextManagerItem Gwenview does something similar as your patch is proposing, but I wondered if we can avoid those duplicate calls and at the same time make the patch simpler. Adding a call to slotViewModeChanged in ViewMainPage::reset also fixed the bug for me (but maybe call it DocumentViewController::reset then?).

Could you check whether this makes any sense?

huoni updated this revision to Diff 33737.May 7 2018, 12:11 AM
huoni retitled this revision from Disable View mode shortcuts in Browse mode to Disable View mode shortcuts outside of View mode.
huoni edited the summary of this revision. (Show Details)
  • Simplify patch to prevent duplicate calls
huoni added a comment.May 7 2018, 12:13 AM

When starting in Browse, View actions such as Zoom to Fit are correctly ignored

Hm, I cannot confirm that part: Even starting in Browse, I'm unable to jump to f.png when pressing f (it does work with d.png / d). Interestingly, F works for f.png.

Need to start Gwenview in Browse, i.e. by using gwenview /path/to/images.

Anyway, as mentioned in the duplicate before, the patch works. Looking at the code now, I noticed something when adding qDebug() to every call site of updateActions(), though:

# Press Enter to switch to View mode
setView();
slotViewModeChanged();
slotViewModeChanged();
slotAdapterChanged();

# Press Enter again to switch back to Browse mode
slotViewModeChanged();

I'm aware in ImageOpsContextManagerItem Gwenview does something similar as your patch is proposing, but I wondered if we can avoid those duplicate calls and at the same time make the patch simpler. Adding a call to slotViewModeChanged in ViewMainPage::reset also fixed the bug for me (but maybe call it DocumentViewController::reset then?).

Could you check whether this makes any sense?

Yep that does make more sense, and makes it much simpler. Thanks! It's essentially your patch now :)

rkflx accepted this revision.May 7 2018, 8:33 AM

Thanks, LGTM. I'd say this can go to the stable branch (18.04.1, if you are fast with committing…).


When starting in Browse, View actions such as Zoom to Fit are correctly ignored

Hm, I cannot confirm that part: Even starting in Browse, I'm unable to jump to f.png when pressing f (it does work with d.png / d). Interestingly, F works for f.png.

Need to start Gwenview in Browse, i.e. by using gwenview /path/to/images.

I did exactly that. Perhaps your file was named F.png, while mine read f.png?

Yep that does make more sense, and makes it much simpler. Thanks! It's essentially your patch now :)

Oh no, not at all. You discovered updateActions(), which was the important part ;)

This revision is now accepted and ready to land.May 7 2018, 8:33 AM
huoni added a comment.EditedMay 8 2018, 1:08 AM

I did exactly that. Perhaps your file was named F.png, while mine read f.png?

That's weird, I tried both F and f (and my files start with the lower case f), although only the latter is relevant since that is what the default Zoom to Fit shortcut is.

This revision was automatically updated to reflect the committed changes.
rkflx added a comment.May 8 2018, 10:37 AM

Thanks, LGTM. I'd say this can go to the stable branch (18.04.1, if you are fast with committing…).

You could still cherry-pick to the stable branch, if you want the fix to be part of 18.04.2…

huoni added a comment.May 9 2018, 3:53 AM

Thanks, LGTM. I'd say this can go to the stable branch (18.04.1, if you are fast with committing…).

You could still cherry-pick to the stable branch, if you want the fix to be part of 18.04.2…

Why not! Done, hopefully correctly...