The Trunk: Morphic-mt.1163.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Morphic-mt.1163.mcz

commits-2
Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.1163.mcz

==================== Summary ====================

Name: Morphic-mt.1163
Author: mt
Time: 4 June 2016, 6:53:04.95683 pm
UUID: cb5b0690-e94a-a945-8c0b-aa83a2b22cb8
Ancestors: Morphic-mt.1162

Use event filters to implement keyboard shortcuts (world, docking bar, system windows).

=============== Diff against Morphic-mt.1162 ===============

Item was added:
+ ----- Method: DockingBarMorph>>filterEvent:for: (in category 'events-processing') -----
+ filterEvent: aKeyboardEvent for: anObject
+ "Provide keyboard shortcuts."
+
+ | index itemToSelect |
+
+ aKeyboardEvent isKeyDown "No #isKeystroke to improve compatibility for all platforms."
+ ifFalse: [^ aKeyboardEvent].
+
+ aKeyboardEvent controlKeyPressed
+ ifFalse: [^ aKeyboardEvent].
+
+ "Search field."
+ aKeyboardEvent keyCharacter = $0
+ ifTrue: [
+ self searchBarMorph ifNotNil: [ :morph |
+ morph model activate: aKeyboardEvent in: morph ].
+ ^ aKeyboardEvent ignore "hit!!"].
+
+ "Select menu items."
+ (aKeyboardEvent keyValue
+ between: $1 asciiValue
+ and: $9 asciiValue)
+ ifFalse: [^ aKeyboardEvent].
+
+ index := aKeyboardEvent keyValue - $1 asciiValue + 1.
+ itemToSelect := (self submorphs select: [ :each |
+ each isKindOf: DockingBarItemMorph ])
+ at: index
+ ifAbsent: [^ aKeyboardEvent].
+
+ self activate: aKeyboardEvent.
+ self
+ selectItem: itemToSelect
+ event: aKeyboardEvent.
+
+ ^ aKeyboardEvent ignore "hit!!"!

Item was removed:
- ----- Method: DockingBarMorph>>handleListenEvent: (in category 'events-processing') -----
- handleListenEvent: anEvent
- " I am registered as a keyboardListener of the ActiveHand,
- watching for ctrl-<n> keystrokes, and upon them if I have
- an nth menu item, I'll activate myself and select it. "
-
- (anEvent controlKeyPressed and: [
- anEvent keyValue
- between: 48 " $0 asciiValue "
- and: 55 " $7 asciiValue " ]) ifTrue: [
- | index itemToSelect |
- index := anEvent keyValue - 48.
- itemToSelect := (submorphs select: [ :each |
- each isKindOf: DockingBarItemMorph ])
- at: index
- ifAbsent: [
- ^self searchBarMorph ifNotNil: [ :morph |
- morph model activate: anEvent in: morph ] ].
- self activate: anEvent.
- self
- selectItem: itemToSelect
- event: anEvent ]!

Item was removed:
- ----- Method: DockingBarMorph>>setupGlobalHotKeyEventListeners (in category 'initialize-release') -----
- setupGlobalHotKeyEventListeners
- PasteUpMorph globalCommandKeysEnabled
- ifTrue: [ ActiveHand addKeyboardListener: self ]
- ifFalse: [ ActiveHand removeKeyboardListener: self ]!

Item was changed:
  ----- Method: MorphicProject>>createOrUpdateMainDockingBar (in category 'docking bars support') -----
  createOrUpdateMainDockingBar
  "Private - create a new main docking bar or update the current one"
  | w mainDockingBars |
  w := self world.
  mainDockingBars := w mainDockingBars.
  mainDockingBars isEmpty ifTrue:
  [ "no docking bar, just create a new one"
  self dockingBar createDockingBar
+ openInWorld: w .
- openInWorld: w ;
- setupGlobalHotKeyEventListeners.
  ^ self ].
  "update if needed"
  mainDockingBars do:
+ [ : each | self dockingBar updateIfNeeded: each ]!
- [ : each | self dockingBar updateIfNeeded: each.
- each setupGlobalHotKeyEventListeners ]!

Item was changed:
  ----- Method: PasteUpMorph class>>globalCommandKeysEnabled: (in category 'preferences') -----
+ globalCommandKeysEnabled: aBoolean
+
+ GlobalCommandKeysEnabled = aBoolean ifTrue: [^ self].
- globalCommandKeysEnabled: aBoolean
  GlobalCommandKeysEnabled := aBoolean.
+
+ SystemWindow allSubInstancesDo: [:ea |
+ aBoolean
+ ifTrue: [ea addKeyboardShortcuts]
+ ifFalse: [ea removeKeyboardShortcuts]].
+
+ PasteUpMorph allSubInstancesDo: [:ea |
+ aBoolean
+ ifTrue: [ea addKeyboardShortcuts]
+ ifFalse: [ea removeKeyboardShortcuts]].!
- aBoolean
- ifTrue:
- [ ActiveHand
- addKeyboardListener: SystemWindow topWindow ;
- addKeyboardListener: ActiveWorld.
- ActiveWorld dockingBars do:
- [ : each | ActiveHand addKeyboardListener: each ] ]
- ifFalse:
- [ ActiveHand
- removeKeyboardListener: SystemWindow topWindow ;
- removeKeyboardListener: ActiveWorld.
- ActiveWorld dockingBars do:
- [ : each | ActiveHand removeKeyboardListener: each ] ].
- TheWorldMainDockingBar updateInstances!

Item was added:
+ ----- Method: PasteUpMorph>>addKeyboardShortcuts (in category 'initialization') -----
+ addKeyboardShortcuts
+ "Install an event capture filter to add shortcuts for global operations like opening a tool."
+
+ self addKeyboardCaptureFilter: self.!

Item was changed:
  ----- Method: PasteUpMorph>>becomeActiveDuring: (in category 'initialization') -----
  becomeActiveDuring: aBlock
  "Make the receiver the ActiveWorld during the evaluation of aBlock.
  Note that this method does deliberately *not* use #ensure: to prevent
  re-installation of the world on project switches."
  | priorWorld priorHand priorEvent |
  priorWorld := ActiveWorld.
  priorHand := ActiveHand.
  priorEvent := ActiveEvent.
- priorHand removeKeyboardListener: priorWorld.
  ActiveWorld := self.
  ActiveHand := self hands first. "default"
  ActiveEvent := nil. "not in event cycle"
- self class globalCommandKeysEnabled ifTrue: [ ActiveHand addKeyboardListener: self ].
  aBlock
  on: Error
  do: [:ex |
  ActiveWorld := priorWorld.
  ActiveEvent := priorEvent.
  ActiveHand := priorHand.
  ex pass]!

Item was added:
+ ----- Method: PasteUpMorph>>filterEvent:for: (in category 'events-processing') -----
+ filterEvent: aKeyboardEvent for: anObject
+ "Provide keyboard shortcuts."
+
+ "Delegate keyboard shortcuts to my docking bars."
+ self submorphsDo: [:ea | ea isDockingBar ifTrue: [
+ ea filterEvent: aKeyboardEvent for: anObject. "No support for converting events here!!"
+ aKeyboardEvent wasIgnored ifTrue: [^ aKeyboardEvent "early out"]]].
+
+ aKeyboardEvent isKeystroke
+ ifFalse: [^ aKeyboardEvent].
+
+ aKeyboardEvent commandKeyPressed ifTrue: [
+ aKeyboardEvent keyCharacter caseOf: {
+ [$R] -> [Utilities browseRecentSubmissions].
+ [$L] -> [self findAFileList: aKeyboardEvent].
+ [$O] -> [self findAMonticelloBrowser].
+ [$P] -> [self findAPreferencesPanel: aKeyboardEvent].
+ "[$Z] -> [ChangeList browseRecentLog]."
+ [$]] -> [Smalltalk snapshot: true andQuit: false].
+ } otherwise: [^ aKeyboardEvent "no hit"].
+ ^ aKeyboardEvent ignore "hit!!"].
+
+ ^ aKeyboardEvent "no hit"!

Item was removed:
- ----- Method: PasteUpMorph>>handleListenEvent: (in category 'events-processing') -----
- handleListenEvent: aUserInputEvent
- "Handlers for *global* keys, regardless of which widget has keyboard focus."
- aUserInputEvent type = #keystroke ifTrue:
- [ aUserInputEvent commandKeyPressed ifTrue:
- [ aUserInputEvent keyValue = $R asciiValue ifTrue: [ Utilities browseRecentSubmissions ].
- aUserInputEvent keyValue = $L asciiValue ifTrue: [ World findAFileList: aUserInputEvent ].
- aUserInputEvent keyValue = $O asciiValue ifTrue: [ World findAMonticelloBrowser ].
- aUserInputEvent keyValue = $P asciiValue ifTrue: [ World findAPreferencesPanel: aUserInputEvent ].
- "aUserInputEvent keyValue = $Z asciiValue ifTrue: [ ChangeList browseRecentLog ]."
- aUserInputEvent keyValue = $] asciiValue ifTrue:
- [ Smalltalk
- snapshot: true
- andQuit: false ] ] ]!

Item was changed:
  ----- Method: PasteUpMorph>>initialize (in category 'initialization') -----
  initialize
  "initialize the state of the receiver"
  super initialize.
  ""
  cursor := 1.
  padding := 3.
  self enableDragNDrop.
  self isWorldMorph
  ifTrue: [self setProperty: #automaticPhraseExpansion toValue: true].
+ self clipSubmorphs: true.
+ self initializeKeyboardShortcuts.!
- self clipSubmorphs: true!

Item was added:
+ ----- Method: PasteUpMorph>>initializeKeyboardShortcuts (in category 'initialization') -----
+ initializeKeyboardShortcuts
+ "Install an event capture filter to add shortcuts for global operations like opening a tool."
+
+ PasteUpMorph globalCommandKeysEnabled
+ ifTrue: [self addKeyboardShortcuts].!

Item was added:
+ ----- Method: PasteUpMorph>>removeKeyboardShortcuts (in category 'initialization') -----
+ removeKeyboardShortcuts
+
+ self removeKeyboardCaptureFilter: self.!

Item was added:
+ ----- Method: SystemWindow>>addKeyboardShortcuts (in category 'initialization') -----
+ addKeyboardShortcuts
+ "Install an event capture filter to add shortcuts for window control operations."
+
+ self addKeyboardCaptureFilter: self.!

Item was changed:
  ----- Method: SystemWindow>>beKeyWindow (in category 'top window') -----
  beKeyWindow
  "Let me be the most important window on the screen. I am at the top and I can have a shadow to get more attention by the user. I am the window that is responsible for window keyboard shortcuts."
 
  | oldKeyWindow |
  self isKeyWindow ifTrue: [^ self].
 
  oldKeyWindow := TopWindow.
  TopWindow := self.
 
- PasteUpMorph globalCommandKeysEnabled ifTrue:
- [ self activeHand addKeyboardListener: self ].
-
  self
  unlockWindowDecorations; "here, because all windows might be active anyway"
  activate; "if not already active, activate now"
  comeToFront. "key windows are on top"
 
  "Change appearance to get noticed."
  self hasDropShadow: Preferences menuAppearance3d.
  (self valueOfProperty: #borderWidthWhenActive)
  ifNotNil: [:bw | self acquireBorderWidth: bw].
 
  oldKeyWindow ifNotNil: [:wnd |
  wnd passivateIfNeeded.
 
- self activeHand removeKeyboardListener: oldKeyWindow.
-
  "Change appearance to not look prettier than the new key window."
  wnd hasDropShadow: false.
  (wnd valueOfProperty: #borderWidthWhenInactive)
  ifNotNil: [:bw | wnd acquireBorderWidth: bw]].
 
  "Synchronize focus look with position of current hand because any call could have made this window the new key window."
  self updateFocusLookAtHand.!

Item was added:
+ ----- Method: SystemWindow>>filterEvent:for: (in category 'events') -----
+ filterEvent: aKeyboardEvent for: anObject
+ "Provide keyboard shortcuts."
+
+ aKeyboardEvent isKeystroke
+ ifFalse: [^ aKeyboardEvent].
+
+ aKeyboardEvent commandKeyPressed ifTrue: [
+ aKeyboardEvent keyCharacter caseOf: {
+ [$\] -> [self class sendTopWindowToBack].
+ [Character escape] -> [self delete].
+ } otherwise: [^ aKeyboardEvent "no hit"].
+ ^ aKeyboardEvent ignore "hit!!"].
+
+ aKeyboardEvent controlKeyPressed ifTrue: [
+ aKeyboardEvent keyCharacter caseOf: {
+ [Character escape] -> [self world findWindow: aKeyboardEvent].
+ } otherwise: [^ aKeyboardEvent "no hit"].
+ ^ aKeyboardEvent ignore "hit!!"].
+
+ ^ aKeyboardEvent "no hit"!

Item was changed:
  ----- Method: SystemWindow>>handleListenEvent: (in category 'events') -----
  handleListenEvent: aUserInputEvent
+ "See #mouseEnterDragging:. Watch for finished drag-and-drop action and lock contents accordingly."
 
- "1) Handle keyboard shortcuts"
- aUserInputEvent type = #keystroke ifTrue:
- [ aUserInputEvent commandKeyPressed ifTrue:
- [ aUserInputEvent keyValue = $\ asciiValue ifTrue: [ self class sendTopWindowToBack ].
- "Command+Escape"
- aUserInputEvent keyValue = 27 ifTrue:
- [ aUserInputEvent wasHandled: true.
- self delete ] ].
- aUserInputEvent controlKeyPressed ifTrue:
- [ aUserInputEvent keyValue = 27 ifTrue: [ self world findWindow: aUserInputEvent ] ] ].
-
- "2) See #mouseEnterDragging:. Watch for finished drag-and-drop action and lock contents accordingly."
  (aUserInputEvent isMouse and: [ aUserInputEvent hand hasSubmorphs not ]) ifTrue:
  [ self isKeyWindow ifFalse: [ self passivateIfNeeded ].
  aUserInputEvent hand removeMouseListener: self ].!

Item was changed:
  ----- Method: SystemWindow>>initialize (in category 'initialization') -----
  initialize
  "Initialize a system window. Add label, stripes, etc., if desired"
 
  super initialize.
 
  self layoutPolicy: ProportionalLayout new.
 
  self wantsPaneSplitters: true.
  self layoutInset: ProportionalSplitterMorph gripThickness.
  self cellInset: ProportionalSplitterMorph gripThickness.
 
  self initializeLabelArea.
  self addCornerGrips.
  self setDefaultParameters.
 
  allowReframeHandles := true.
  isCollapsed := false.
  paneMorphs := Array new.
  mustNotClose := false.
+ updatablePanes := Array new.
+
+ self initializeKeyboardShortcuts.!
- updatablePanes := Array new.!

Item was added:
+ ----- Method: SystemWindow>>initializeKeyboardShortcuts (in category 'initialization') -----
+ initializeKeyboardShortcuts
+ "Install an event capture filter to add shortcuts for window control operations."
+
+ PasteUpMorph globalCommandKeysEnabled
+ ifTrue: [self addKeyboardShortcuts].!

Item was added:
+ ----- Method: SystemWindow>>removeKeyboardShortcuts (in category 'initialization') -----
+ removeKeyboardShortcuts
+
+ self removeKeyboardCaptureFilter: self.!

Item was changed:
+ (PackageInfo named: 'Morphic') postscript: 'SystemWindow allSubInstancesDo: [:ea |
+ ea initializeKeyboardShortcuts.
+ HandMorph allInstancesDo: [:hand | hand removeKeyboardListener: ea]].
+ PasteUpMorph allSubInstancesDo: [:ea |
+ ea initializeKeyboardShortcuts.
+ HandMorph allInstancesDo: [:hand | hand removeKeyboardListener: ea]].
+ DockingBarMorph allSubInstancesDo: [:ea |
+ HandMorph allInstancesDo: [:hand | hand removeKeyboardListener: ea]].'!
- (PackageInfo named: 'Morphic') postscript: 'SystemWindow reconfigureWindowsForFocus.'!