Skip to content

Commit

Permalink
Fix #983. Bypass panel multi-select when only shift and tool utilizes…
Browse files Browse the repository at this point in the history
… shift.
  • Loading branch information
cmeyer committed Aug 14, 2024
1 parent 670f28a commit e29571c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions nion/swift/DisplayCanvasItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def create_lattice(self, u_pos: Geometry.FloatSize) -> Graphics.LatticeGraphic:


class DisplayCanvasItem(CanvasItem.CanvasItemComposition):
"""Allow display canvas items (tools) to bypass multi-select.
In cases where only_shift is used in the tool, the tool should bypass multi-select and the result will be as if
the user clicked in the target display panel without modifiers. For instance, if the user shift-clicks using the
crop tool to restrict the crop to a square shape, the crop tool should bypass multi-select and the result will be
as if the user clicked in the target display panel without modifiers, selecting the target panel.
"""
bypass_multi_select = False

@property
def key_contexts(self) -> typing.Sequence[str]:
Expand Down
6 changes: 5 additions & 1 deletion nion/swift/DisplayPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,11 @@ def drop(mime_data: UserInterface.MimeData, region: str, x: int, y: int) -> str:
return "ignore"

def adjust_secondary_focus(modifiers: UserInterface.KeyboardModifiers) -> None:
if modifiers.only_shift:
display_canvas_item = self.display_canvas_item
if display_canvas_item and display_canvas_item.bypass_multi_select:
display_canvas_item.bypass_multi_select = False
self.__document_controller.selected_display_panel = self
elif modifiers.only_shift:
self.__document_controller.add_secondary_display_panel(self)
elif modifiers.only_control:
self.__document_controller.toggle_secondary_display_panel(self)
Expand Down
4 changes: 4 additions & 0 deletions nion/swift/ImageCanvasItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,10 @@ async def _reactor_loop(self, r: Stream.ValueChangeStreamReactorInterface[MouseP
pos = widget_mapping.map_point_widget_to_image_norm(mouse_pos)
start_drag_pos = mouse_pos

# bypass multi-select if this tool is started with only the shift key selected. see notes where
# bypass_multi_select is defined.
image_canvas_item.bypass_multi_select = modifiers.only_shift

with delegate.create_create_graphic_task(self.graphic_type, pos) as create_create_graphic_task:
# create the graphic and assign a drag part
graphic = getattr(create_create_graphic_task, "_graphic")
Expand Down

0 comments on commit e29571c

Please sign in to comment.