Skip to content

Commit

Permalink
Reworked remove shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Oct 13, 2023
1 parent 61685d2 commit 906e9e8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
20 changes: 20 additions & 0 deletions repository/OpenPonk-Spec/HandMorph.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Extension { #name : #HandMorph }

{ #category : #'*OpenPonk-Spec' }
HandMorph >> sendKeyboardEvent: anEvent [

OPDiagramRemoveFigureCommand lastEvent: anEvent.
"Send the event to the morph currently holding the focus, or if none to
the owner of the hand."
^ self
sendEvent: anEvent
focus: self keyboardFocus
clear: [self keyboardFocus: nil]
]

{ #category : #'*OpenPonk-Spec' }
HandMorph >> sendMouseEvent: anEvent [
OPDiagramRemoveFigureCommand lastEvent: anEvent.
"Send the event to the morph currently holding the focus, or if none to the owner of the hand."
^self sendEvent: anEvent focus: self mouseFocus clear:[self mouseFocus: nil]
]
3 changes: 3 additions & 0 deletions repository/OpenPonk-Spec/OPDiagramFigureCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Class {
'controllers',
'diagramElements'
],
#classInstVars : [
'lastEvent'
],
#category : #'OpenPonk-Spec-Diagram-Figure-Commands'
}

Expand Down
60 changes: 56 additions & 4 deletions repository/OpenPonk-Spec/OPDiagramRemoveFigureCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,27 @@ OPDiagramRemoveFigureCommand class >> canvasShortcutActivation [

<classAnnotation>
^ CmdShortcutActivation
by: ((KMSingleKeyCombination new key:
(KeyboardKey new withValue: 16rffff andName: #delete))
modifiedBy: KMModifier meta)
by: (KMKeyCombinationChoice withShortcuts: {
(KMSingleKeyCombination new key:
(KeyboardKey new withValue: 16rffff andName: #delete)).
((KMSingleKeyCombination new key:
(KeyboardKey new withValue: 16rffff andName: #delete))
modifiedBy: KMModifier meta) })
for: OPCanvasPresenter
]

{ #category : #accessing }
OPDiagramRemoveFigureCommand class >> lastEvent [

^ lastEvent
]

{ #category : #accessing }
OPDiagramRemoveFigureCommand class >> lastEvent: anEvent [

lastEvent := anEvent
]

{ #category : #accessing }
OPDiagramRemoveFigureCommand >> defaultMenuIcon [

Expand All @@ -36,13 +51,50 @@ OPDiagramRemoveFigureCommand >> defaultMenuItemName [
ifFalse: [ 'Remove all ' , models size asString , ' from model' ]
]

{ #category : #utilities }
OPDiagramRemoveFigureCommand >> doAndReturnFocus: aBlock [

| result window wasActive |
window := diagramController canvasPresenter window window.
wasActive := window isActive.
result := aBlock value.
window activate.
^ result
]

{ #category : #execution }
OPDiagramRemoveFigureCommand >> execute [

| lastEvent |
lastEvent := self class lastEvent.
(lastEvent isNotNil and: [
lastEvent controlKeyPressed or: [ lastEvent commandKeyPressed ] ])
ifTrue: [ self unsafeExecute ]
ifFalse: [ self safeExecute ]
]

{ #category : #execution }
OPDiagramRemoveFigureCommand >> safeExecute [

| result |
result := self doAndReturnFocus: [
UIManager default
proceed:
'Permanently remove from model? (to skip this confirmation, hold '
, OSPlatform current defaultModifier name
, ' next time)'
title: 'Remove?' ].
result ifNil: [ ^ self ].
result ifFalse: [ ^ self ].
self unsafeExecute
]

{ #category : #execution }
OPDiagramRemoveFigureCommand >> unsafeExecute [

diagramController deselectAll.
figures do: [ :each |
(diagramController hasControllerForFigure: each) ifTrue: [
diagramController removeFromCanvas: each ] ].
"diagramController selectedElements do: [ :each | diagramController removeFromCanvas: each]."
canvas signalUpdate
]

0 comments on commit 906e9e8

Please sign in to comment.