eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SelectionInListView':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SelectionInListView


Inheritance:

   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

Description:


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

copyright

COPYRIGHT (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.

Class protocol:

defaults
o  defaultAspectMessage

o  defaultBackgroundColor

o  defaultChangeMessage

o  defaultListMessage

o  defaultSelectionMessage

o  rightArrowFormOn: aDevice
return the form used for the right arrow (non 3D)

o  rightArrowLightFormOn: aDevice
return the form used for the right arrow light pixels (3D only)

o  rightArrowShadowFormOn: aDevice
return the form used for the right arrow light pixels (3D only)

o  smallRightArrowLightFormOn: aDevice
return the form used for the small right arrow light pixels (3D only)

o  smallRightArrowShadowFormOn: aDevice
return the form used for the small right arrow light pixels (3D only)

o  updateStyleCache
extract values from the styleSheet and cache them in class variables

Usage example(s):

     self updateStyleCache

instance creation
o  on: aModel aspect: aspect change: change list: list initialSelection: initial

o  on: aModel aspect: aspect change: change list: list menu: menu initialSelection: initial

o  on: aModel printItems: print oneItem: one aspect: aspect change: change list: list menu: menu initialSelection: initial
for ST-80 compatibility

o  on: aModel printItems: print oneItem: one aspect: aspect change: change list: list menu: menu initialSelection: initial useIndex: useIndex
for ST-80 compatibility


Instance protocol:

Compatibility-ST80
o  isSingleSelect: aBool

o  sequence
same as #list - for ST80 compatibility

o  setValidTargetIndex: index
ignored for now - for ST80 compatibility

o  targetIndex: index

accessing-actions
o  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.

o  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.

o  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.

o  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

o  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

o  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

o  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

o  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.

o  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
o  attributeAt: index
return the line attribute of list line index.
currently supported are:
#halfIntensity
#disabled
#bold

o  attributeAt: index add: aSymbolOrCollectionOfSymbols
add to a lines attribute(s);
currently supported are:
#halfIntensity
#disabled
#bold

o  attributeAt: index put: aSymbolOrCollectionOfSymbolsOrNil
set a lines attribute(s);
currently supported are:
#halfIntensity
#disabled
#bold

o  attributeAt: index remove: aSymbolOrCollectionOfSymbols
remove a line attribute;
currently supported are:
#halfIntensity
#disabled
#bold

o  line: lineNr hasAttribute: aSymbol
return true, if line nr has attribute, aSymbol;
currently supported attributes are:
#halfIntensity
#disabled
#bold

o  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).

o  strikeOut: aBoolean
turn on/off strikeOut mode

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  strikeout: aBoolean
turn on/off strikeOut mode

accessing-behavior
o  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.

o  enabled
return true if widget is enabled - i.e. if selections are possible

o  enabled: aBoolean
enable/disable the view - selection changes are allowed/disallowed

o  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

o  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.

o  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.

o  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.

o  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).

o  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
o  add: aValue beforeIndex: index
must recompute our current selections

o  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).

o  list: aCollection
set the list - redefined, since setting the list implies unselecting
and clearing attributes.

o  list: aCollection keepSelection: aBoolean
set the list - redefined, since setting the list implies unselecting
and clearing attributes.

o  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.

o  removeFromIndex: startLineNr toIndex: endLineNr
must recompute our current selections

o  removeIndexWithoutRedraw: lineNr
delete line - no redraw;
return true, if something was really deleted.
Redefined since we have to care for selection

o  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).

o  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
o  noHighlighting
switch off higlighting of selected lines

o  selectedVisualBlock

o  selectedVisualBlock: aBlock
ST-80 compatibility: provide a block, which returns a displayObject to be drawn for
selected items.

o  visualBlock

o  visualBlock: aBlock
ST-80 compatibility: provide a block, which returns a displayObject to be drawn for
unselected items.

accessing-mvc
o  addModelInterfaceTo: aDictionary
see comment in View>>modelInterface

o  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) **

o  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.

o  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.

o  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.

o  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.

o  on: aModel aspect: aspectSymbol change: changeSymbol list: listSymbol menu: menuSymbol
ST-80 compatibility

o  on: aModel printItems: print oneItem: one aspect: aspectSymbol change: changeSymbol list: listSymbol menu: menuSymbol initialSelection: initialSymbol useIndex: use
ST-80 compatibility

accessing-selection
o  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.

o  addToSelection: aNumber
add entry, aNumber to the selection. No scrolling is done.
*** No model and/or actionBlock notification is done here.

o  removeFromSelection: aNumber
remove entry, aNumber from the selection.
*** No model and/or actionBlock notification is done here.

change & update
o  update: something with: aParameter from: changedObject
ca's "optimizations" are only correct if we do not have items

drag & drop
o  allowDrag: aBoolean
enable/disable dragging support

o  canDrag
returns true if dragging is enabled

o  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)

o  dropSource
returns the dropSource or nil

o  dropSource: aDropSourceOrNil
set the dropSource or nil

o  startDragAt: aPoint

drawing
o  drawRightArrowInVisibleLine: visLineNr
draw a right arrow (for submenus).
This method is not used here, but provided for subclasses such
as menus or file-lists.

o  drawSelectionHighlightFrameForItemAtY: yLine with: fg
a line above and below

o  drawVisibleLineSelected: visLineNr
redraw a single line as selected.

o  drawVisibleLineSelected: visLineNr with: fg and: bg
redraw a single line as selected.

o  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.

o  invalidateSelection
invalidate (force async redraw) the current selection

event handling
o  buttonControlPress: button x: x y: y
if multipleSelectOk: add to the selection;
otherwise, behave like normal select

o  buttonMotion: buttonState x: x y: y
mouse-move while button was pressed - handle selection changes

o  buttonMultiPress: button x: x y: y
doubleClickActionBlock isNil ifTrue:[

o  buttonPress: button x: x y: y
clicked into the selection ?

o  buttonRelease: button x: x y: y
stop any autoscroll

o  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) **

o  contentsChanged
size of contents changed - move origin up if possible

o  doubleClicked
can only happen if claus modifies the selection within

o  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.

o  keyPress: key x: x y: y
handle keyboard input

o  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
o  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.

o  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.

o  wantsFocusWithPointerEnter
return true, if I want the focus when
the mouse pointer enters

help
o  helpTextAt: aPoint
ask the line for its help text

o  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
o  fetchDeviceResources
fetch device colors, to avoid reallocation at redraw time

o  initCursor
set the cursor - a hand

o  initStyle
setup viewStyle specifics

o  initialize
fontHeight := font height + lineSpacing.

o  realize
(comment from inherited method)
old: fetch models value on realize;

native widget support
o  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
o  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)

o  characterSearchItemStringAt: lineNr
for first-character search:
return a lines item-string.
For multi-col items, this may be different from the actual string

o  checkRemovingSelection: lineNr
when a line is removed, we have to adjust selection

o  checkRemovingSelectionFrom: startNr to: endNr
when a range of lines is removed, we have to adjust the selection

o  getListFromModel
if I have a model, get my list from it using the listMessage.
If listMessage is nil, try aspectMessage for backward compatibilty.

o  getSelectionFromModel
if I have a model and an initialSelectionMsg, get my selection from it

o  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

o  isValidSelection: aNumberOrCollection
return true, if aNumber is ok as a selection index

o  lineIsEnabled: lineNr

o  positionToSelectionX: x y: y
given a click position, return the selection lineNo

o  scrollSelectDown
auto scroll action; scroll and reinstall timed-block

o  scrollSelectUp
auto scroll action;
scroll and reinstall timed-block

o  selectOrToggleAtX: x y: y

o  selectOrToggleAtX: x y: y forRightClickMenu: forRightClickMenu
self visibleLineToListLine:(self visibleLineOfY:y).

o  visibleLineNeedsSpecialCare: visLineNr

o  widthForScrollBetween: start and: end
has to be redefined since WHOLE line is inverted/modified sometimes

private-drag and drop
o  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
o  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.

o  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
o  redrawElement: aNumber
redraw an individual element

o  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.

o  redrawVisibleLine: visLineNr
redraw a single line.
Must check, if any is in the selection and handle this case.
Otherwise draw using supers method.

o  redrawVisibleLine: visLineNr col: colNr
redraw a single character.
Must check, if it's in the selection and handle this case.

o  redrawVisibleLine: visLineNr from: startCol
redraw from a col to the right end.
Must check, if it's in the selection and handle this case.

o  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
o  deselect
deselect; Model or actionBlock notifications are made.
To deselect without notifications, use #setSelection:nil.

o  deselectWithoutRedraw
deselect without redraw or notifications.
No model or actionBlock notifications are made.

o  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

o  firstInSelection
return the index of the first selected line - nil if there is no selection

o  hasSelection
return true, if an item is selected

o  is: aNumber inSelection: aSelection
return true, if line, aNumber is in the selection

o  isInSelection: aNumber
return true, if line, aNumber is in the selection

o  lastInSelection
return the index of the last selected line - nil if there is no selection

o  makeSelectionVisible
scroll to make the selection line visible

o  nextAfterSelection
return the index of the next selectable entry after the selection.
Wrap at end.

o  nextSelectableAfter: indexOrIndexCollection
return the index of the next selectable entry after the indexOrIndexCollection.
Wrap at end.

o  numberOfSelections
return the number of selected entries

o  previousBeforeSelection
return the index of the previous selectable entry before the selection.
Wrap at beginning.

o  previousSelectableBefore: indexOrIndexCollection
return the index of the previous selectable entry before the indexOrIndexCollection.
Wrap at beginning.

o  selectAll
select all entries.
Model and/or actionBlock notification IS done.

o  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.

o  selectElementWithoutScroll: anObject
select the element with same printString as the argument, anObject.
Do not scroll.
*** No model and/or actionBlock notification is done here.

o  selectFirst
select the first selectable element.
Model and/or actionBlock notification IS done.

o  selectFirstVisibleLine
select the first selectable element.
Model and/or actionBlock notification IS done.

o  selectLast
select the last selectable element.
Model and/or actionBlock notification IS done.

o  selectNext
select next line or first visible if there is currently no selection.
Wrap at end.
Model and/or actionBlock notification IS done.

o  selectPrevious
select previous line or previous visible if there is currently no selection.
Wrap at beginning.
Model and/or actionBlock notification IS done.

o  selectWithoutScroll: aNumberOrNilOrCollection
select line, aNumber or deselect if argument is nil.
*** No model and/or actionBlock notification is done here.

o  selection
return the selection index or collection of indices (if multipleSelect is on)

o  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.

o  selectionAsCollection
return the selection as a collection of line numbers.
This allows users of this class to enumerate independent of
the multipleSelect style.

o  selectionChangedFrom: oldSelection
selection has changed. Call actionblock and/or send changeMessage if defined

o  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.

o  selectionValue
return the selection value i.e. the text in the selected line.
For multiple selections a collection containing the entries is returned.

o  selectionValueAsCollection
return the selection values as a collection - allows selectionValues to
be enumerated independent of the multiSelect settings

o  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.

o  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.

o  toggleSelection: aNumber
toggle selection-state of entry, aNumber.
*** No model and/or actionBlock notification is done here.

o  valueIsInSelection: someString
return true, if someString is in the selection


Examples:


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


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 06:28:02 GMT