[squeak-dev] The Trunk: Morphic-mt.865.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Apr 12 12:52:55 UTC 2015


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

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

Name: Morphic-mt.865
Author: mt
Time: 12 April 2015, 2:52:20.375 pm
UUID: 68261d42-569e-3040-9d0d-fd6be8699f67
Ancestors: Morphic-mt.864

Add highlight for the matching filter term in lists. It is cached like icons and items are.

Why useful? If you do not reset the filter automatically, it is now easier to recognize after which term the list is filtered. It also makes the existing filter adaption visible, which tries to avoid empty results.

=============== Diff against Morphic-mt.864 ===============

Item was changed:
  Morph subclass: #LazyListMorph
+ 	instanceVariableNames: 'listItems listIcons listFilterOffsets font selectedRow selectedRows preSelectedRow listSource maxWidth'
- 	instanceVariableNames: 'listItems listIcons font selectedRow selectedRows preSelectedRow listSource maxWidth'
  	classVariableNames: 'ListPreSelectionColor ListSelectionColor ListSelectionTextColor'
  	poolDictionaries: ''
  	category: 'Morphic-Widgets'!
  
  !LazyListMorph commentStamp: 'efc 8/6/2005 11:34' prior: 0!
  The morph that displays the list in a PluggableListMorph.  It is "lazy" because it will only request the list items that it actually needs to display.
  
  I will cache the maximum width of my items in maxWidth to avoid this potentially expensive and frequent computation.!

Item was added:
+ ----- Method: LazyListMorph class>>listFilterHighlightColor (in category 'preferences') -----
+ listFilterHighlightColor
+ 
+ 	^ Color yellow paler alpha: 0.5!

Item was changed:
  ----- Method: LazyListMorph>>display:atRow:on: (in category 'drawing') -----
  display: item atRow: row on: canvas
  	"display the given item at row row"
  
  	| drawBounds emphasized rowColor itemAsText |
  	itemAsText := item asStringOrText.
+ 	
+ 	"If it is a text, we will only use the first character's emphasis."
  	emphasized := itemAsText isText 
  		ifTrue: [font emphasized: (itemAsText emphasisAt: 1)] 
  		ifFalse: [font].
+ 	
  	rowColor := self colorForRow: row.
+ 	
  	drawBounds := (self drawBoundsForRow: row) translateBy: (self hMargin @ 0).
  	drawBounds := drawBounds intersect: self bounds.
+ 
+ 	"Draw icon if existing. Adjust draw bounds in that case."
+ 	(self icon: row) ifNotNil: [ :icon || top |
- 	(self icon: row) ifNotNil: 
- 		[ :icon || top |
  		top := drawBounds top + ((drawBounds height - icon height) // 2).
  		canvas translucentImage: icon at: drawBounds left @ top.
  		drawBounds := drawBounds left: drawBounds left + icon width + 2 ].
+ 
+ 	"Draw filter matches if any."
+ 	(self filterOffsets: row) do: [:offset |
+ 		canvas
+ 			frameAndFillRoundRect: ((drawBounds left + offset first) @ drawBounds top corner: (drawBounds left + offset last) @ drawBounds bottom)
+ 			radius: 3
+ 			fillStyle: self class listFilterHighlightColor
+ 			borderWidth: 1
+ 			borderColor: self class listFilterHighlightColor twiceDarker].
+ 		
+ 	"We will only draw strings here."
+ 	canvas
+ 		drawString: itemAsText asString
+ 		in: drawBounds
+ 		font: emphasized
+ 		color: rowColor.!
- 	canvas drawString: itemAsText in: drawBounds font: emphasized color: rowColor!

Item was changed:
  ----- Method: LazyListMorph>>drawOn: (in category 'drawing') -----
  drawOn: aCanvas
+ 
+ 	| topRow bottomRow |
+ 	listItems ifEmpty: [ ^self ].
- 	| |
- 	listItems size = 0 ifTrue: [ ^self ].
  	 
  	self 
  		drawPreSelectionOn: aCanvas;
  		drawSelectionOn: aCanvas.
  
+ 	topRow := self topVisibleRowForCanvas: aCanvas.
+ 	bottomRow := self bottomVisibleRowForCanvas: aCanvas.
- 	(self topVisibleRowForCanvas: aCanvas) to: (self bottomVisibleRowForCanvas: aCanvas) do: [ :row |
- 		(listSource itemSelectedAmongMultiple:  row) ifTrue: [
- 			self drawBackgroundForMulti: row on: aCanvas. ]].
  
+ 	"Draw multi-selection."
+ 	topRow to: bottomRow do: [ :row |
+ 		(listSource itemSelectedAmongMultiple: row) ifTrue: [
+ 			self drawBackgroundForMulti: row on: aCanvas ] ].
+ 
+ 	"Draw hovered row if preference enabled."
  	PluggableListMorph highlightHoveredRow ifTrue: [
  		listSource hoverRow > 0 ifTrue: [
  			self highlightHoverRow: listSource hoverRow on: aCanvas ] ].
  
+ 	"Draw all visible rows."
+ 	topRow to: bottomRow do: [ :row |
+ 		self display: (self item: row) atRow: row on: aCanvas ].
- 	(self topVisibleRowForCanvas: aCanvas) to: (self bottomVisibleRowForCanvas: aCanvas) do: [ :row |
- 		self display: (self item: row) atRow: row on: aCanvas.
- 	].
  
+ 	"Finally, highlight drop row for drag/drop operations.."
  	listSource potentialDropRow > 0 ifTrue: [
  		self highlightPotentialDropRow: listSource potentialDropRow on: aCanvas ].!

Item was added:
+ ----- Method: LazyListMorph>>filterOffsets: (in category 'list access') -----
+ filterOffsets: row
+ 	"Get the character offsets for the matching filter term."
+ 	
+ 	| indexes |
+ 	"Migrate old instances if necessary."
+ 	listFilterOffsets ifNil: [listFilterOffsets := Array new: listItems size].
+ 	
+ 	row <= listFilterOffsets size ifFalse: [
+ 		^ self getFilterOffsets: row].
+ 	
+ 	(indexes := listFilterOffsets at: row) ifNil: [
+ 		indexes := self getFilterOffsets: row.
+ 		listFilterOffsets at: row put: indexes ].
+ 	
+ 	^ indexes!

Item was changed:
  ----- Method: LazyListMorph>>font: (in category 'drawing') -----
  font: newFont
  	font := (newFont ifNil: [ TextStyle default defaultFont ]).
  	self adjustHeight.
+ 	listFilterOffsets := Array new: self getListSize withAll: nil.
  	self changed.!

Item was added:
+ ----- Method: LazyListMorph>>getFilterOffsets: (in category 'list access') -----
+ getFilterOffsets: row
+ 	"Calculate matching character indexes for the current filter term."
+ 	
+ 	| item filter filterWidth offsets currentIndex |
+ 	filter := listSource filterTerm.
+ 	filter ifEmpty: [^ Array empty].
+ 	filterWidth := font widthOfString: filter.
+ 
+ 	item := self item: row.
+ 	offsets := OrderedCollection new.
+ 	
+ 	currentIndex := 1.
+ 	[currentIndex > 0] whileTrue: [
+ 		currentIndex := item findString: filter startingAt: currentIndex caseSensitive: false.
+ 		currentIndex > 0 ifTrue: [ | left |
+ 			left := font widthOfString: item from: 1 to: currentIndex-1.
+ 			offsets addLast: (left to: left + filterWidth).
+ 			currentIndex := currentIndex + 1] ].
+ 	^ offsets!

Item was added:
+ ----- Method: LazyListMorph>>getListIcon: (in category 'list access') -----
+ getListIcon: row
+ 	"Grab icon directly from the model."
+ 	
+ 	^ listSource iconAt: row
+ !

Item was changed:
+ ----- Method: LazyListMorph>>icon: (in category 'list access') -----
- ----- Method: LazyListMorph>>icon: (in category 'accessing') -----
  icon: row
+ 	
  	| icon |
+ 	"Migrate old instances if necessary."
  	listIcons ifNil: [listIcons := Array new: listItems size].
+ 	
+ 	row <= listIcons size ifFalse: [
+ 		^ self getListIcon: row].
+ 	
+ 	(icon := listIcons at: row) ifNil: [
+ 		icon := self getListIcon: row.
+ 		listIcons at: row put: icon ].
+ 	
- 	row <= listIcons size ifFalse: [^ listSource iconAt: row].
- 	icon := listIcons at: row.
- 	icon ifNil:
- 		[icon := listSource iconAt: row.
- 		listIcons at: row put: icon].
  	^ icon!

Item was changed:
  ----- Method: LazyListMorph>>initialize (in category 'initialization') -----
  initialize
  	super initialize.
  	self color: Color black.
  	font := Preferences standardListFont.
  	listItems := #().
  	listIcons := #().
+ 	listFilterOffsets := #().
  	selectedRow := nil.
  	selectedRows := PluggableSet integerSet.
  	preSelectedRow := nil.
  	self adjustHeight.!

Item was changed:
  ----- Method: LazyListMorph>>listChanged (in category 'list management') -----
  listChanged
  	"set newList to be the list of strings to display"
  	| size |
  	size := self getListSize.
  	listItems := Array new: size withAll: nil.
  	listIcons := Array new: size withAll: nil.
+ 	listFilterOffsets := Array new: size withAll: nil.
  	maxWidth := nil.
  	selectedRow := nil.
  	selectedRows := PluggableSet integerSet.
  	preSelectedRow := nil.
  	self adjustHeight.
  	self adjustWidth.
  	self changed.
  !

Item was added:
+ ----- Method: PluggableListMorph>>filterTerm (in category 'filtering') -----
+ filterTerm
+ 	^ lastKeystrokes ifNil: ['']!



More information about the Squeak-dev mailing list