Adding a context menu for selection tools
ClosedPublic

Authored by scottpetrovic on Aug 19 2017, 1:59 PM.

Details

Reviewers
dkazakov
Group Reviewers
Krita
Summary

This is the first step in trying to add context/right-click menus to different tools. This one is for most of the selection tools (except bezier because that is going to need a bigger change to get that working I think).

There is at least one wishlist item with the selection tools specifically
https://bugs.kde.org/show_bug.cgi?id=337380

I am not sure of the exact list of the right click options are final, but those can be changed easily enough.

Test Plan

activated different selection tools and went through the different right-click functions to make sure they work.

Diff Detail

Repository
R37 Krita
Lint
Lint Skipped
Unit
Unit Tests Skipped
scottpetrovic created this revision.Aug 19 2017, 1:59 PM
dkazakov requested changes to this revision.Aug 23 2017, 1:45 PM

Hi, @scottpetrovic!

There is at least one major bug in the patch: the actions are not in sync with main actions used in Krita. As far as I can tell, you should *not* create the actions for you menu. Instead, you should fetch the actions from the actions registry. Like it is done in KisLayerBox::slotContextMenuRequested. If you do so, the enable-ness state of the actions will always be correct and in sync. It might also allow you to avoid creation of a separate class for it. It might happen that a simple function will be enough.

Steps to reproduce:

  1. Make sure you have no selection
  2. Activate Select Rectangular tool
  3. Right-click

You see that all the actions are enabled whereas the corresponding actions in the Select menu are not enabled.

And concerning the contents of the menu, I guess that most of the current actions should be moved into sub-menues. The most expected actions are: Select All, Deselect, Invert, Cut/Copy/Paste, Transform Selection (we don't have this action yes). The rest of the action like "Feather" can be easily moves to sub-menues.

This revision now requires changes to proceed.Aug 23 2017, 1:45 PM
scottpetrovic added a comment.EditedAug 23 2017, 2:06 PM

Two questions.

  1. If I make the context menu a function (instead of a class) that all the different tools will use, where would that live? Would I move that functionality to one of the parent classes of the selection tools?
  2. with this comment... "most of the current actions should be moved into sub-menues". Are you saying we want to add a lot more menu items to the context menu and group them with sub-menus? Do you have a list of all the items that you would expect to be in this menu but aren't. So far the items you want added are the following: Select All, Deselect, Cut, Copy, Paste
  1. If I make the context menu a function (instead of a class) that all the different tools will use, where would that live? Would I move that functionality to one of the parent classes of the selection tools?

We have quite a few helper classes in libs/ui/tools, you could put it here

  1. with this comment... "most of the current actions should be moved into sub-menues". Are you saying we want to add a lot more menu items to the context menu and group them with sub-menus? Do you have a list of all the items that you would expect to be in this menu but aren't. So far the items you want added are the following: Select All, Deselect, Invert, Cut, Copy, Paste

I mean that I would like to hide the current items into submenus, so the user would not see it all the time, since they are not extremely popular. I would expect the menu look something like:

  • Select All
  • Deselect
  • Invert
  • ---
  • Cut
  • Copy
  • Paste
  • ---
  • Transform Selection
    • Grow
    • Shrink
    • Feather
    • etc
  • <Some nice name> (do we need this group at all?)
    • Crop Image by Selection
    • Crop Layer by Selection
  • Options
    • Show Selection
    • Show Global Selection Mask

It would also be nice to be able to select the currently active mode (Replace, Add, Subtract, Intersect) with the context menu, but I'm not sure it is needed/possible. It needs discussion with painters.

I think the primary focus ought to be getting the disabled state in both menus.

After that Scott can do some tweaking to improve the usability. :)

I think the primary focus ought to be getting the disabled state in both menus.

After that Scott can do some tweaking to improve the usability. :)

Yep, the main issue is "reusing" already existing actions, which guarantees proper synchronization. The layout is an extremely disputable thing.

scottpetrovic edited edge metadata.

hey @dkazakov !

I have updated my patch with all your recommendations. I think there was one option I couldn't find for adding in the menu, but everything else should be there. There were some nice recommendations.

I also removed the new class I made and stuck it in the selection_tool_helper class

It seems to be working still when I test it. The state of the display options in the menu stay in sync too like you mentioned!

dkazakov accepted this revision.Sep 1 2017, 5:41 PM

Hi, @scottpetrovic!

I have tested your patch, it works perfectly now! Please check my comments about making the function static and push the patch! That translatable string is the only weirdness of the patch :)

libs/ui/tool/kis_selection_tool_helper.cpp
269

Please make this function static, so that you would not have to create a helper object with a translatable string :)

plugins/tools/selectiontools/kis_tool_select_contiguous.cc
254

It would be difficult to explain translators why they should translate this string, though it is not used anywhere :)

This revision is now accepted and ready to land.Sep 1 2017, 5:41 PM
scottpetrovic closed this revision.Sep 5 2017, 11:52 PM

made it static and pushed it out.