|
Class: SelectionInListView
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--View
|
+--ListView
|
+--SelectionInListView
|
+--FileSelectionList
|
+--MenuView
|
+--SelectionInTreeView
- Package:
- stx:libwidg
- Category:
- Views-Lists
- Version:
- rev:
1.352
date: 2023/11/11 15:24:53
- user: stefan
- file: SelectionInListView.st directory: libwidg
- module: stx stc-classLibrary: libwidg
this one is a ListView with a selected line (which is shown highlighted)
If multipleSelectionsOk is true, it is also allowed to shift-click multiple
entries.
If toggleSelect is true, clicking toggles (i.e. click on a seleted item
will deselect).
Whenever the selection changes, an action-block is evaluated, passing the
current selection as argument.
Currently, the selection can be nil, aNumber or a collection of numbers;
this will change to be either nil or a collection, making selection handling
easier in the future. (this stupid behavior is due to the multiple
select feature being added later - the first implementation used to support
only single selections).
The actionBlock is called with the current selection (single number or
collection of numbers) as argument.
Also, to support ST-80 MVC-style use, the model (if nonNil) is notified
by the change mechanism (performs changeMsg) and vice versa, the view
updates if the model changes (with aspect of either #list or #selectionIndex).
Before actually adding entries to the selection, a checkBlock (if non-nil) is evaluated
passing the number of the entry whch is about to be selected as argument.
The select change operation is only done if this returns true. This allows
interception of select, for example to query the user if he/she wants to save
the old contents before (see uses in SystemBrowser and FileBrowser), or to
disable individual entries.
It is also possible to select entries with the keyboard; use the cursor up/
down keys to select prev/next, Home- and End-keys to select first/last.
Use the return key to apply the double-click-action to the current selection.
Also, alphabetic keys will select the next entry starting with that key.
The keyboard behavior can be further controlled with the keyActionStyle
instance variable (see SelectionInListView>>keyActionStyle:).
Finally, ignoreReselect controls if pressing on an already selected item
triggers the action or not. For some applications it is useful to allow
reselects (for example, the SystemBrowsers method-list updates the
source code in this case).
Currently, some limited form of line attributes are supported. These
are kept in the instance variable lineAttributes.
This may change (using mechanisms similar to MultiColListEntry), so
be prepared. (don't use the listAttributes instvar directly; if possible,
use MultiColListEntry or subclasses of it.
Although currently based on the listAttributes instVar, the implementation of
text attributes will be changed in the near future (when Text/DisplayText are
available).
However, the protocol will probably be kept for backward compatibility
(i.e. use #attributeAt: / #attributeAt:put etc. - at least, these are easy to find
when migrating to the new attributed text handling).
[Instance variables:]
selection <misc> the current selection. nil, a number or collection of numbers
actionBlock <Block> block to be evaluated on selection changes
(1-arg blocks gets selectionIndex or selectionValue
as arg - depending upon the useIndex setting)
useIndex <Boolean> if true, the index of a selection is passed to
the actionBlock or stuffed into the selection valueHolder;
if false, the seelction-value is passed.
enabled <Boolean> true: selection changes allowed; false: ignore clicks
hilightFgColor
hilightBgColor <Color> how highlighted items are drawn
halfIntensityColor <Color> foreground for disabled items
selectCondition <Block> if non-nil, this block can decide if selection is ok.
or its invoked with the itemNr of the
<ValueHolder> 'to-be-selected' item.
If the block returns true, the item is selected
(or added to the selection); if false is returned,
no action is taken.
selectionChangeCondition
<Block> much like above, but invoked without argument,
or on any change of the selection (i.e. also when items
<ValueHolder> are deselected).
Can return false to suppress change.
doubleClickActionBlock <Block> action to perform on double-click
(1-arg blocks gets selectionIndex or selectionValue
as arg - depending upon the useIndex setting)
listAttributes dont use - will vanish
hilightLevel <Integer> level to draw selections (i.e. for 3D effect)
hilightFrameColor <Color> rectangle around highlighted items
multipleSelectOk <Boolean> if true, multiple selections (with shift) are ok.
default: false
ignoreReselect <Boolean> if true, selecting same again does not trigger action;
if false, every select triggers it.
default: true
toggleSelect <Boolean> if true, click toggles;
if false, click selects.
default: false
arrowLevel <Integer> level to draw right-arrows (for submenus etc.)
smallArrow <Boolean> if true, uses a small arrow bitmap
listMsg if non-nil, use ST-80 style (model-access)
initialSelectionMsg
printItems
oneItem
keyActionStyle <Symbol> controls how to respond to keyboard selects
returnKeyActionStyle <Symbol> controls how to respond to return key
written spring/summer 89 by claus
3D Jan 90 by claus
multiselect Jun 92 by claus
keyboard-select jun 94 by claus
copyrightCOPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
defaults
-
defaultAspectMessage
-
-
defaultBackgroundColor
-
-
defaultChangeMessage
-
-
defaultListMessage
-
-
defaultSelectionMessage
-
-
rightArrowFormOn: aDevice
-
return the form used for the right arrow (non 3D)
-
rightArrowLightFormOn: aDevice
-
return the form used for the right arrow light pixels (3D only)
-
rightArrowShadowFormOn: aDevice
-
return the form used for the right arrow light pixels (3D only)
-
smallRightArrowLightFormOn: aDevice
-
return the form used for the small right arrow light pixels (3D only)
-
smallRightArrowShadowFormOn: aDevice
-
return the form used for the small right arrow light pixels (3D only)
-
updateStyleCache
-
extract values from the styleSheet and cache them in class variables
Usage example(s):
instance creation
-
on: aModel aspect: aspect change: change list: list initialSelection: initial
-
-
on: aModel aspect: aspect change: change list: list menu: menu initialSelection: initial
-
-
on: aModel printItems: print oneItem: one aspect: aspect change: change list: list menu: menu initialSelection: initial
-
for ST-80 compatibility
-
on: aModel printItems: print oneItem: one aspect: aspect change: change list: list menu: menu initialSelection: initial useIndex: useIndex
-
for ST-80 compatibility
Compatibility-ST80
-
isSingleSelect: aBool
-
-
sequence
-
same as #list - for ST80 compatibility
-
setValidTargetIndex: index
-
ignored for now - for ST80 compatibility
-
targetIndex: index
-
accessing-actions
-
action
-
return the action block to be performed on select.
With useIndex==true, the block gets the selectionIndex as arg,
otherwise, it gets the selectionValue.
-
action: aBlock
-
set the action block to be performed on select.
With useIndex==true, the block gets the selectionIndex as arg,
otherwise, it gets the selectionValue.
-
doubleClickAction: aOneArgBlock
-
set the double click action block.
If non-nil, that one is evaluated on double click, passing the
selection-line-number (useIndex==true) or selectionValue (useIndex==false) as argument.
-
keyActionStyle: aSymbol
-
defines how the view should respond to alpha-keys pressed.
Possible values are:
#select -> will select next entry starting with that
character and perform the click-action
#selectAndDoubleclick -> will select next & perform double-click action
#pass -> will pass key to superclass (i.e. no special treatment)
nil -> will ignore key
the default (set in #initialize) is #select
-
returnKeyActionStyle: aSymbol
-
defines how the view should respond to a return key pressed.
Possible values are:
#doubleClick -> perform double-click action
#pass -> will pass key to superclass (i.e. no special treatment)
nil -> will ignore key
the default (set in #initialize) is #doubleClick
-
selectConditionBlock
-
get the select-conditionBlock; this block is evaluated before
any selection change is performed (passing the to-be-changed item index as arg).
The change will not be done, if the block returns false.
For example, this allows confirmation queries in the SystemBrowser
-
selectConditionBlock: aBlock
-
set the select-conditionBlock; this block is evaluated before
any selection change is performed (passing the to-be-changed item index as arg).
The change will not be done, if the block returns false.
For example, this allows confirmation queries in the SystemBrowser
-
useIndex
-
set/clear the useIndex flag. If set, both actionBlock and change-messages
are passed the index(indices) of the selection as argument.
If clear, the value(s) (i.e. the selected string) is passed.
Default is true.
-
useIndex: aBoolean
-
set/clear the useIndex flag. If set, both actionBlock and change-messages
are passed the index(indices) of the selection as argument.
If clear, the value(s) (i.e. the selected string) is passed.
Default is true.
accessing-attributes
-
attributeAt: index
-
return the line attribute of list line index.
currently supported are:
#halfIntensity
#disabled
#bold
-
attributeAt: index add: aSymbolOrCollectionOfSymbols
-
add to a lines attribute(s);
currently supported are:
#halfIntensity
#disabled
#bold
-
attributeAt: index put: aSymbolOrCollectionOfSymbolsOrNil
-
set a lines attribute(s);
currently supported are:
#halfIntensity
#disabled
#bold
-
attributeAt: index remove: aSymbolOrCollectionOfSymbols
-
remove a line attribute;
currently supported are:
#halfIntensity
#disabled
#bold
-
line: lineNr hasAttribute: aSymbol
-
return true, if line nr has attribute, aSymbol;
currently supported attributes are:
#halfIntensity
#disabled
#bold
-
setAttributes: aList
-
set the attribute list.
No redraw is done - the caller should make sure to redraw afterwards
(or use this only before the view is visible).
-
strikeOut: aBoolean
-
turn on/off strikeOut mode
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
strikeout: aBoolean
-
turn on/off strikeOut mode
accessing-behavior
-
dragObjectConverter: aBlock
-
set an optional dragObject converter;
if non-nil, this one will be evaluated on a drag-start,
for each dropItem as argument, and supposed
to convert it into a dragObject and return it.
If it returns nil, the object will not be dropped.
Useful, if the receiver view represents fileNames or other
names of the actual objects to be dragged.
-
enabled
-
return true if widget is enabled - i.e. if selections are possible
-
enabled: aBoolean
-
enable/disable the view - selection changes are allowed/disallowed
-
ignoreReselect
-
return the ignoreReselect flag -
if set, a click on an already selected entry is ignored.
Otherwise the notification is done, even if no
change in the selection occurs.
(for example, in browser to update a method).
Setting ignoreReselect to false makes sense if data is shown
which may change by itself (i.e. without the user doing anything)
For example, the inspector uses this, and redisplays the value,
if the selection is the same.
The default is true, meaning that a click on an already selected
does not lead to a notification via the actionBlock/change mechanism.
Usage example(s):
note by ca:
if multiple selection enabled, the ignoreReselect will have no influence
|
-
ignoreReselect: aBoolean
-
set/clear the ignoreReselect flag -
if set, a click on an already selected entry is ignored.
Otherwise the notification is done, even if no
change in the selection occurs.
(for example, in browser to update a method).
Setting ignoreReselect to false makes sense if data is shown
which may change by itself (i.e. without the user doing anything)
For example, the inspector uses this, and redisplays the value,
if the selection is the same.
The default is true, meaning that a click on an already selected
does not lead to a notification via the actionBlock/change mechanism.
-
multipleSelectOk
-
true if multiple selections are allowed. If enabled, the
user may select multiple entries in the list, and the program
always gets a collection of selected items (indexes if useIndex is true,
values otherwise). The default is false, for single selections.
-
multipleSelectOk: aBoolean
-
allow/disallow multiple selections. If enabled, the
user may select multiple entries in the list, and the program
always gets a collection of selected items (indexes if useIndex is true,
values otherwise). The default is false, for single selections.
-
toggleSelect
-
is toggle select enabled?.
If true, clicking on a selected entry unselects it and vice versa.
The default is false, which means
that clicking on an already selected entry does not change its
select status (see also ignoreReselect:, which has higher prio and is checked first).
-
toggleSelect: aBoolean
-
turn on/off toggle select.
If true, clicking on a selected entry unselects it and vice versa.
The default is false, which means
that clicking on an already selected entry does not change its
select status (see also ignoreReselect:, which has higher prio and is checked first).
accessing-contents
-
add: aValue beforeIndex: index
-
must recompute our current selections
-
contents: aCollection
-
set the list - redefined, since setting the list implies unselecting
and clearing attributes.
No redraw is done - the caller should make sure to redraw afterwards
(or use this only before the view is visible).
-
list: aCollection
-
set the list - redefined, since setting the list implies unselecting
and clearing attributes.
-
list: aCollection keepSelection: aBoolean
-
set the list - redefined, since setting the list implies unselecting
and clearing attributes.
-
printItems: aBoolean
-
set/clear the printItems flag. If set, items (as set via #list: or
as returned from the model) are sent #printString to display them.
If false, items are assumed to be either strings, or know how to
display themself in a GC (i.e. they are instances of ListEntry).
The default is false.
Caveat: printString seems to be too specialized - I'd rather have
a definable printSelector or - better - a printConverter.
This may be added in the future.
-
removeFromIndex: startLineNr toIndex: endLineNr
-
must recompute our current selections
-
removeIndexWithoutRedraw: lineNr
-
delete line - no redraw;
return true, if something was really deleted.
Redefined since we have to care for selection
-
setContents: aCollection
-
set the list - redefined, since setting the list implies unselecting
and clearing attributes.
No redraw is done - the caller should make sure to redraw afterwards
(or use this only before the view is visible).
-
setList: aCollection
-
set the list - redefined, since setting the list implies unselecting
and clearing attributes.
No redraw is done - the caller should make sure to redraw afterwards
(or use this only before the view is visible).
accessing-look
-
noHighlighting
-
switch off higlighting of selected lines
-
selectedVisualBlock
-
-
selectedVisualBlock: aBlock
-
ST-80 compatibility: provide a block, which returns a displayObject to be drawn for
selected items.
-
visualBlock
-
-
visualBlock: aBlock
-
ST-80 compatibility: provide a block, which returns a displayObject to be drawn for
unselected items.
accessing-mvc
-
addModelInterfaceTo: aDictionary
-
see comment in View>>modelInterface
-
doubleClick: aSymbol
-
set the symbol with which the model is informed about double-click.
OBSOLETE: please use #doubleClickMessage:
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
doubleClickMessage
-
return the symbol with which the model (if any) is informed about
double-click. If nil (which is the default), it is not informed.
-
doubleClickMessage: aSymbol
-
set the symbol with which the model (if any) is informed about double-click.
If nil (which is the default), it is not informed.
-
initialSelectionMessage
-
return the symbol by which the model informes me about a changed
selectionIndex. This is used both in change notification and to
actually acquire a new selection value.
-
initialSelectionMessage: aSymbol
-
set the symbol by which the model informes me about a changed
selectionIndex. This is used both in change notification and to
actually acquire a new selection value.
-
on: aModel aspect: aspectSymbol change: changeSymbol list: listSymbol menu: menuSymbol
-
ST-80 compatibility
-
on: aModel printItems: print oneItem: one aspect: aspectSymbol change: changeSymbol list: listSymbol menu: menuSymbol initialSelection: initialSymbol useIndex: use
-
ST-80 compatibility
accessing-selection
-
addElementToSelection: anObject
-
add the element with the same printstring as the argument, anObject
to the selection. The entry is searched by comparing printStrings.
No scrolling is done. Returns true, if ok, false if no such entry
was found.
*** No model and/or actionBlock notification is done here.
-
addToSelection: aNumber
-
add entry, aNumber to the selection. No scrolling is done.
*** No model and/or actionBlock notification is done here.
-
removeFromSelection: aNumber
-
remove entry, aNumber from the selection.
*** No model and/or actionBlock notification is done here.
change & update
-
update: something with: aParameter from: changedObject
-
ca's "optimizations" are only correct if we do not have items
drag & drop
-
allowDrag: aBoolean
-
enable/disable dragging support
-
canDrag
-
returns true if dragging is enabled
-
dragAutoScroll: aDropContext
-
called by the DragAndDropManager to scroll during a drag/drop operation
if required (decided by the widget itself).
If a scroll was done, return true;
otherwise false (used to restore the background)
-
dropSource
-
returns the dropSource or nil
-
dropSource: aDropSourceOrNil
-
set the dropSource or nil
-
startDragAt: aPoint
-
drawing
-
drawRightArrowInVisibleLine: visLineNr
-
draw a right arrow (for submenus).
This method is not used here, but provided for subclasses such
as menus or file-lists.
-
drawSelectionHighlightFrameForItemAtY: yLine with: fg
-
a line above and below
-
drawVisibleLineSelected: visLineNr
-
redraw a single line as selected.
-
drawVisibleLineSelected: visLineNr with: fg and: bg
-
redraw a single line as selected.
-
invalidateLine: aLineNr
-
(comment from inherited method)
invalidate the area of a single line.
This arranges for that line to be redrawn asynchronously (later).
If multiple such invalidations arrive, those areas may be lumped
together for a block update.
The update takes place when the windowGroup process gets a chance to
process expose events.
-
invalidateSelection
-
invalidate (force async redraw) the current selection
event handling
-
buttonControlPress: button x: x y: y
-
if multipleSelectOk: add to the selection;
otherwise, behave like normal select
-
buttonMotion: buttonState x: x y: y
-
mouse-move while button was pressed - handle selection changes
-
buttonMultiPress: button x: x y: y
-
doubleClickActionBlock isNil ifTrue:[
-
buttonPress: button x: x y: y
-
clicked into the selection ?
-
buttonRelease: button x: x y: y
-
stop any autoscroll
-
buttonShiftPress: button x: x y: y
-
marked as obsolete by Stefan Vogel at 26-Okt-2023
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
contentsChanged
-
size of contents changed - move origin up if possible
-
doubleClicked
-
can only happen if claus modifies the selection within
-
key: key select: index x: x y: y shifted: shifted
-
select an entry by a keyboard action.
This is treated like a doubleClick on that entry,
except if shift is down, and multiple selections are
allowed, this adds/removes the new item to the selection.
-
keyPress: key x: x y: y
-
handle keyboard input
-
sizeChanged: how from: oldExtentOrNil
-
my view has changed the size (not the contents);
if there is a selection, make certain, it is visible
after the sizechange.
focus handling
-
showFocus: explicit
-
(comment from inherited method)
highlight myself somehow to tell user that I have the focus.
If explicit is true, the focus came via focusStepping (i.e. tabbing);
if false, it came via the window manager (i.e. pointer entering).
Only change my border, if this is an explicit focusChange.
-
showNoFocus: explicit
-
(comment from inherited method)
undo the effect of showFocus.
Explicit tells if the focus came via focusStepping (i.e. tabbing)
or via the window manager (i.e. pointer entering).
Only change my border, if this is an explicit focusChange.
-
wantsFocusWithPointerEnter
-
return true, if I want the focus when
the mouse pointer enters
help
-
helpTextAt: aPoint
-
ask the line for its help text
-
helpTextForLine: lineNr
-
the fallback here is to ask the item if it is not a string,
otherwise, return the full label string
for lines which are clipped (longer than the view's width)
initialization
-
fetchDeviceResources
-
fetch device colors, to avoid reallocation at redraw time
-
initCursor
-
set the cursor - a hand
-
initStyle
-
setup viewStyle specifics
-
initialize
-
fontHeight := font height + lineSpacing.
-
realize
-
(comment from inherited method)
old: fetch models value on realize;
native widget support
-
nativeWindowType
-
return a symbol describing my native window type
(may be used internally by the device as a native window creation hint,
if the device supports native windows)
private
-
argForChangeMessage
-
return the argument for a selectionChange;
depending on the setting of useIndex, this is either the numeric
index of the selection or the value (i.e. the string)
-
characterSearchItemStringAt: lineNr
-
for first-character search:
return a lines item-string.
For multi-col items, this may be different from the actual string
-
checkRemovingSelection: lineNr
-
when a line is removed, we have to adjust selection
-
checkRemovingSelectionFrom: startNr to: endNr
-
when a range of lines is removed, we have to adjust the selection
-
getListFromModel
-
if I have a model, get my list from it using the listMessage.
If listMessage is nil, try aspectMessage for backward compatibilty.
-
getSelectionFromModel
-
if I have a model and an initialSelectionMsg, get my selection from it
-
highlightLineSpacing
-
true if the spacing between lines is to be drawn with selected color,
false if it remains white.
false for selection in list views; true for edit/text views
-
isValidSelection: aNumberOrCollection
-
return true, if aNumber is ok as a selection index
-
lineIsEnabled: lineNr
-
-
positionToSelectionX: x y: y
-
given a click position, return the selection lineNo
-
scrollSelectDown
-
auto scroll action; scroll and reinstall timed-block
-
scrollSelectUp
-
auto scroll action;
scroll and reinstall timed-block
-
selectOrToggleAtX: x y: y
-
-
selectOrToggleAtX: x y: y forRightClickMenu: forRightClickMenu
-
self visibleLineToListLine:(self visibleLineOfY:y).
-
visibleLineNeedsSpecialCare: visLineNr
-
-
widthForScrollBetween: start and: end
-
has to be redefined since WHOLE line is inverted/modified sometimes
private-drag and drop
-
collectionOfDragObjects
-
returns collection of dragable objects assigned to selection
Here, by default, a collection of text-dragObjects is generated;
however, if a dragObjectConverter is defined, that one gets a chance
to convert as appropriate.
queries
-
isCursorKeyConsumer
-
return true, if the receiver can be controlled by cursor keys;
i.e. it can handle some keyboard input,
isCursorKeyConsumer are potential candidates for getting the keyboard
focus initially within dialogBoxes, or when the focus-follows-pointer
mode is off.
-
specClass
-
returns my spec class (for UI editor)
Usage example(s):
redefined, since the name of my specClass is nonStandard (i.e. not SelectionInListSpec)
|
redrawing
-
redrawElement: aNumber
-
redraw an individual element
-
redrawFromVisibleLine: startVisLineNr to: endVisLineNr
-
redraw a range of lines.
Must check, if any is in the selection and handle this case.
Otherwise draw it en-bloque using supers method.
-
redrawVisibleLine: visLineNr
-
redraw a single line.
Must check, if any is in the selection and handle this case.
Otherwise draw using supers method.
-
redrawVisibleLine: visLineNr col: colNr
-
redraw a single character.
Must check, if it's in the selection and handle this case.
-
redrawVisibleLine: visLineNr from: startCol
-
redraw from a col to the right end.
Must check, if it's in the selection and handle this case.
-
redrawVisibleLine: visLineNr from: startCol to: endCol
-
redraw from a startCol to endCol.
Must check, if it's in the selection and handle this case.
selections
-
deselect
-
deselect; Model or actionBlock notifications are made.
To deselect without notifications, use #setSelection:nil.
-
deselectWithoutRedraw
-
deselect without redraw or notifications.
No model or actionBlock notifications are made.
-
expandSelectionToX: x y: y
-
used with button-motion and shift-press;
expand the selection to include all items from the clicked one,
up to the one under the mouse pointer
-
firstInSelection
-
return the index of the first selected line - nil if there is no selection
-
hasSelection
-
return true, if an item is selected
-
is: aNumber inSelection: aSelection
-
return true, if line, aNumber is in the selection
-
isInSelection: aNumber
-
return true, if line, aNumber is in the selection
-
lastInSelection
-
return the index of the last selected line - nil if there is no selection
-
makeSelectionVisible
-
scroll to make the selection line visible
-
nextAfterSelection
-
return the index of the next selectable entry after the selection.
Wrap at end.
-
nextSelectableAfter: indexOrIndexCollection
-
return the index of the next selectable entry after the indexOrIndexCollection.
Wrap at end.
-
numberOfSelections
-
return the number of selected entries
-
previousBeforeSelection
-
return the index of the previous selectable entry before the selection.
Wrap at beginning.
-
previousSelectableBefore: indexOrIndexCollection
-
return the index of the previous selectable entry before the indexOrIndexCollection.
Wrap at beginning.
-
selectAll
-
select all entries.
Model and/or actionBlock notification IS done.
-
selectElement: anObject
-
select the element with same printString as the argument, anObject.
Scroll to make the new selection visible.
Model and/or actionBlock notification IS done.
-
selectElementWithoutScroll: anObject
-
select the element with same printString as the argument, anObject.
Do not scroll.
*** No model and/or actionBlock notification is done here.
-
selectFirst
-
select the first selectable element.
Model and/or actionBlock notification IS done.
-
selectFirstVisibleLine
-
select the first selectable element.
Model and/or actionBlock notification IS done.
-
selectLast
-
select the last selectable element.
Model and/or actionBlock notification IS done.
-
selectNext
-
select next line or first visible if there is currently no selection.
Wrap at end.
Model and/or actionBlock notification IS done.
-
selectPrevious
-
select previous line or previous visible if there is currently no selection.
Wrap at beginning.
Model and/or actionBlock notification IS done.
-
selectWithoutScroll: aNumberOrNilOrCollection
-
select line, aNumber or deselect if argument is nil.
*** No model and/or actionBlock notification is done here.
-
selection
-
return the selection index or collection of indices (if multipleSelect is on)
-
selection: aNumberOrNilOrCollection
-
select line, aNumber or deselect if argument is nil;
scroll to make the selected line visible.
The model and/or actionBlock IS notified.
-
selectionAsCollection
-
return the selection as a collection of line numbers.
This allows users of this class to enumerate independent of
the multipleSelect style.
-
selectionChangedFrom: oldSelection
-
selection has changed. Call actionblock and/or send changeMessage if defined
-
selectionDo: aBlock
-
perform aBlock for each nr in the selection.
For single selection, it is called once for the items nr.
For multiple selections, it is called for each.
-
selectionValue
-
return the selection value i.e. the text in the selected line.
For multiple selections a collection containing the entries is returned.
-
selectionValueAsCollection
-
return the selection values as a collection - allows selectionValues to
be enumerated independent of the multiSelect settings
-
setSelectElement: anObject
-
select the element with same printString as the argument, anObject.
Scroll to make the new selection visible.
*** No model and/or actionBlock notification is done here.
-
setSelection: aNumberOrNilOrCollection
-
select line, aNumber or deselect if argument is nil;
scroll to make the selected line visible.
*** No model and/or actionBlock notification is done here.
-
toggleSelection: aNumber
-
toggle selection-state of entry, aNumber.
*** No model and/or actionBlock notification is done here.
-
valueIsInSelection: someString
-
return true, if someString is in the selection
SelectionInListView can be used both in the ST/X way, using action blocks
or in the traditional mvc way.
with actions:
basic interface:
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:#('one' 'two' 'three').
slv action:[:index | Transcript showCR:'selected ' , index printString].
top add:slv in:(0.0@0.0 corner:1.0@1.0).
top open
|
get element instead of index:
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:#('one' 'two' 'three').
slv action:[:element | Transcript showCR:'selected ' , element printString].
slv useIndex:false.
top add:slv in:(0.0@0.0 corner:1.0@1.0).
top open
|
concrete example; show filenames:
(notice: normally, you would use a FileSelectionList)
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index |
Transcript showCR:'selected ' , index printString.
Transcript showCR:' the value is: ', slv selectionValue].
top add:slv in:(0.0@0.0 corner:1.0@1.0).
top open
|
add a scrollbar:
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
allow reselect
(clicking on already selected entry
triggers action/changeNotification again):
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv ignoreReselect:false.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
allow multiple selections (shift-select):
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:indexList | Transcript showCR:'selected ' , indexList printString].
slv multipleSelectOk:true.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
same, not using index:
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:indexList | Transcript showCR:'selected ' , indexList printString].
slv multipleSelectOk:true; useIndex:false.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
strikeout mode (single):
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv strikeOut:true.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
strikeout mode (multiple):
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv strikeOut:true; multipleSelectOk:true.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
toggleSelect mode (clicking on selected entry deselects it):
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv toggleSelect:true.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
define what to do on double-click:
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv doubleClickAction:[:index | Transcript showCR:'doubleclick on ' , index printString].
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
enable / disable:
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv disable.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open.
Delay waitForSeconds:5.
slv enable.
|
enable / disable via a channel:
|top slv enableChannel t|
enableChannel := true asValue.
t := Toggle label:'enable'.
t model:enableChannel.
t open.
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:(Filename currentDirectory directoryContents).
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv enableChannel:enableChannel.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open.
|
using a Model:
|top slv model|
model := Plug new.
model respondTo:#getList with:[#('foo' 'bar' 'baz' 'hello')].
model respondTo:#initial with:[1].
model respondTo:#setSelection: with:[:arg | Transcript showCR:'model selected:', arg printString].
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView
on:model
aspect:#someAspect
change:#setSelection:
list:#getList
initialSelection:#initial.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
notice, that the ST-80 behavaior on reselect is to send a selection change
with an index of 0.
same, with useIndex false:
|top slv model|
model := Plug new.
model respondTo:#getList with:[#('foo' 'bar' 'baz' 'hello')].
model respondTo:#initial with:['bar'].
model respondTo:#setSelection: with:[:arg | Transcript showCR:'model selected:', arg printString].
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView
on:model
aspect:#someAspect
change:#setSelection:
list:#getList
initialSelection:#initial.
slv useIndex:false.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
self changing list:
(selectionInListView updates itself when button changes initial selection):
|top slv model sel changeButton|
sel := 'bar'.
model := Plug new.
model respondTo:#getList with:['getList' printNL. #('foo' 'bar' 'baz' 'hello')].
model respondTo:#initial with:['initial' printNL. sel].
model respondTo:#setSelection: with:[:arg | ('model selected:', arg) printNL. sel := arg].
changeButton := Button label:'change selection'.
changeButton action:[sel := 'foo'. model changed:#initial].
changeButton open.
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView
on:model
aspect:#someAspect
change:#setSelection:
list:#getList
initialSelection:#initial.
slv useIndex:false.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open
|
using a SelectionInList-Model:
(see how changes in the model (via list:...) are reflected in the view)
|top slv model|
model := SelectionInList with:#('foo' 'bar' 'baz' 'hello').
model selection:'bar'.
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView on:model.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open.
InspectorView openOn:model monitor:'selectionIndexHolder'
|
two selectionInListViews on the same selectionInList model:
|top1 slv1 top2 slv2 model|
model := SelectionInList with:#('foo' 'bar' 'baz' 'hello').
top1 := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv1 := SelectionInListView on:model.
top1 add:(ScrollableView forView:slv1) in:(0.0@0.0 corner:1.0@1.0).
top1 open.
top2 := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv2 := SelectionInListView on:model.
top2 add:(ScrollableView forView:slv2) in:(0.0@0.0 corner:1.0@1.0).
top2 open.
|
a MultiSelectionInList model:
|top slv model|
model := MultiSelectionInList with:#('foo' 'bar' 'baz' 'hello').
model selection:#('foo' 'bar').
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView on:model.
slv multipleSelectOk:true.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open.
InspectorView openOn:model monitor:'selectionIndexHolder'
|
with strikeOut:
|top slv model|
model := MultiSelectionInList with:#('foo' 'bar' 'baz' 'hello').
model selection:#('foo' 'bar').
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView on:model.
slv multipleSelectOk:true; toggleSelect:true; strikeOut:true.
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0).
top open.
InspectorView openOn:model monitor:'selectionIndexHolder'
|
two listViews on the same list, but separate selections
|top top2 lv1 lv2 selInL1 selInL2 listHolder l1 l2|
top := StandardSystemView new extent:300@300.
lv1 := SelectionInListView origin:0.0@0.0 corner:1.0@0.5 in:top.
lv1 level:-1.
lv1 toggleSelect:true.
lv2 := SelectionInListView origin:0.0@0.5 corner:1.0@1.0 in:top.
lv2 level:-1.
lv2 toggleSelect:true.
selInL1 := SelectionInList new.
selInL2 := SelectionInList new.
listHolder := #('foo' 'bar' 'baz') asValue.
selInL1 listHolder:listHolder.
selInL2 listHolder:listHolder.
lv1 model:selInL1.
lv2 model:selInL2.
top open.
top2 := StandardSystemView new extent:100 @ 30.
l1 := Label origin:0.0@0.0 corner:0.5@1.0 in:top2.
l2 := Label origin:0.5@0.0 corner:1.0@1.0 in:top2.
l1 model:(BlockValue with:[:arg | arg value printString] argument:selInL1 selectionIndexHolder).
l2 model:(BlockValue with:[:arg | arg value printString] argument:selInL2 selectionIndexHolder).
l1 labelMessage:#value.
l2 labelMessage:#value.
top2 open.
Delay waitForSeconds:2.
listHolder value:#('1' '2' '3' '4').
| non-string entries (text)
|top l slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
l := OrderedCollection new.
l add:(Text string:'red' emphasis:(#color->Color red)).
l add:(Text string:'green' emphasis:(#color->Color green)).
l add:(Text string:'blue' emphasis:(#color->Color blue)).
slv list:l.
slv action:[:index | Transcript showCR:'selected ' , index printString].
top add:slv in:(0.0@0.0 corner:1.0@1.0).
top open
|
non string entries
|top slv wrapper l fileImage dirImage m|
dirImage := Image fromFile:'DirObj.xbm'.
fileImage := Image fromFile:'FileObj.xbm'.
l := OrderedCollection new.
Filename currentDirectory directoryContents do:[:s |
s asFilename isDirectory ifTrue:[
l add:(LabelAndIcon icon:dirImage string:s)
] ifFalse:[
l add:(LabelAndIcon icon:fileImage string:s)
]
].
m := SelectionInList new.
m list:l.
slv := SelectionInListView new.
slv model:m.
wrapper := HVScrollableView forView:slv miniScrollerH:true.
top := StandardSystemView extent:150@200.
top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
top open.
|
|top slv|
top := StandardSystemView new
label:'select';
minExtent:100@100;
maxExtent:300@400;
extent:200@200.
slv := SelectionInListView new.
slv list:#('one' 'two' 'three').
slv action:[:index | Transcript showCR:'selected ' , index printString].
slv multipleSelectOk:true.
slv allowDrag:true.
top add:slv in:(0.0@0.0 corner:1.0@1.0).
top open
|
|