[squeak-dev] The Trunk: Morphic-ct.1960.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Apr 6 17:33:24 UTC 2022
Christoph Thiede uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-ct.1960.mcz
==================== Summary ====================
Name: Morphic-ct.1960
Author: ct
Time: 6 April 2022, 7:32:52.190385 pm
UUID: 7632c359-d7f1-5b46-abf1-a988d4e4db7c
Ancestors: Morphic-mt.1957
Minor clean-up of MenuMorph's matchString. Add public accessors for filtering. Simplifies the value range of the match string by automatically converting '' to nil. Deprecates unused #unfilterOrEscape:.
=============== Diff against Morphic-mt.1957 ===============
Item was changed:
----- Method: MenuMorph>>displayFiltered: (in category 'keyboard control') -----
displayFiltered: evt
| matchStr allItems matches feedbackMorph |
+ matchStr := self matchString.
- matchStr := self valueOfProperty: #matchString.
allItems := self submorphs select: [:m | m isKindOf: MenuItemMorph].
matches := allItems select: [:m | | isMatch |
isMatch :=
+ matchStr isNil or: [
- matchStr isEmpty or: [
m contents includesSubstring: matchStr caseSensitive: false].
m isEnabled: isMatch.
isMatch].
feedbackMorph := self valueOfProperty: #feedbackMorph.
feedbackMorph ifNil: [
feedbackMorph := TextMorph new
color: Color darkGray;
yourself.
self
addLine;
addMorphBack: feedbackMorph lock.
self setProperty: #feedbackMorph toValue: feedbackMorph.
self fullBounds. "Lay out for submorph adjacency"].
feedbackMorph contents: '<', matchStr, '>'.
+ matchStr ifNil: [
- matchStr isEmpty ifTrue: [
feedbackMorph delete.
self submorphs last delete.
self removeProperty: #feedbackMorph].
" This method is invoked with evt = nil from MenuMorph >> removeMatchString.
The current implementation can't select an item without an event. "
(evt notNil and: [ matches size >= 1 ]) ifTrue: [
self selectItem: matches first event: evt]!
Item was changed:
----- Method: MenuMorph>>handleDelStroke: (in category 'keystroke helpers') -----
handleDelStroke: evt
evt keyCharacter = Character delete ifFalse: [^ false].
+ self matchString ifNotNil: [
+ self removeMatchString].
- self
- valueOfProperty: #matchString
- ifPresentDo: [:str | "reset filter"
- self setProperty: #matchString toValue: String new.
- self selectItem: nil event: evt.
- self displayFiltered: evt].
^ true!
Item was changed:
----- Method: MenuMorph>>handleEscStroke: (in category 'keystroke helpers') -----
handleEscStroke: evt
evt keyValue = 27 ifFalse: [ ^false ].
+ self matchString ifNotNil: [
+ self removeMatchString.
+ ^true].
- self
- valueOfProperty: #matchString
- ifPresentDo: [ :str |
- str isEmpty ifFalse: [ "If filtered, first ESC removes filter"
- self setProperty: #matchString toValue: String new.
- self selectItem: nil event: evt.
- self displayFiltered: evt.
- ^true ] ].
self deactivate: evt.
^true!
Item was changed:
----- Method: MenuMorph>>handleFiltering: (in category 'keystroke helpers') -----
handleFiltering: evt
| matchString |
+ matchString := self matchString.
- matchString := self valueOfProperty: #matchString ifAbsentPut: [ String new ].
matchString := true
caseOf: {
[ evt keyCharacter = Character backspace ] ->
+ [matchString ifNotNil: [ matchString allButLast ] ].
- [ matchString isEmpty
- ifTrue: [ matchString ]
- ifFalse: [ matchString allButLast ] ].
[ evt keyValue >= 32 ] ->
+ [ (matchString ifNil: ['']) , evt keyCharacter ] }
- [ matchString , evt keyCharacter ] }
otherwise: [ matchString ].
+ self matchString: matchString event: evt.!
- self setProperty: #matchString toValue: matchString.
- self displayFiltered: evt!
Item was added:
+ ----- Method: MenuMorph>>matchString (in category 'accessing') -----
+ matchString
+ "Answer the current match string for filtering the menu, or nil if no filter is active. The matchString will never be an empty string."
+
+ ^ self valueOfProperty: #matchString!
Item was added:
+ ----- Method: MenuMorph>>matchString: (in category 'accessing') -----
+ matchString: aString
+
+ ^ self matchString: aString event: nil!
Item was added:
+ ----- Method: MenuMorph>>matchString:event: (in category 'keyboard control') -----
+ matchString: aString event: anEvent
+ "Set the current match string and display the filtered the menu items."
+
+ aString ifNotNil: [aString ifEmpty: [^ self matchString: nil event: anEvent]].
+
+ self setProperty: #matchString toValue: aString.
+ self displayFiltered: anEvent.!
Item was changed:
----- Method: MenuMorph>>removeMatchString (in category 'keyboard control') -----
removeMatchString
+
+ ^ self removeMatchString: self currentEvent!
- "Remove the matchString, if any."
- self setProperty: #matchString toValue: String new.
- self displayFiltered: nil!
Item was added:
+ ----- Method: MenuMorph>>removeMatchString: (in category 'keyboard control') -----
+ removeMatchString: anEvent
+ "Remove the matchString, if any."
+
+ self selectItem: nil event: anEvent.
+ self matchString: nil event: anEvent.!
Item was removed:
- ----- Method: MenuMorph>>unfilterOrEscape: (in category 'keyboard control') -----
- unfilterOrEscape: evt
- self valueOfProperty: #matchString
- ifPresentDo:
- [:str |
-
- str isEmpty
- ifFalse:
- ["If filtered, first ESC removes filter"
-
- self setProperty: #matchString toValue: String new.
- self selectItem: nil event: evt.
- self displayFiltered: evt]].
- "If a stand-alone menu, just delete it"
- popUpOwner ifNil: [^self delete].
- "If a sub-menu, then deselect, and return focus to outer menu"
- self selectSuperMenu: evt!
More information about the Squeak-dev
mailing list
|