SelectionInListModelView.st
changeset 2228 5268b9c3be4a
parent 2225 d785c9d86aa3
child 2245 546c6e5d0951
equal deleted inserted replaced
2227:c5e6912cc6b2 2228:5268b9c3be4a
    12 
    12 
    13 
    13 
    14 "{ Package: 'stx:libwidg2' }"
    14 "{ Package: 'stx:libwidg2' }"
    15 
    15 
    16 ListModelView subclass:#SelectionInListModelView
    16 ListModelView subclass:#SelectionInListModelView
    17 	instanceVariableNames:'selection multipleSelectOk actionBlock doubleClickActionBlock
    17 	instanceVariableNames:'selection multipleSelectOk selectOnButtomMenu actionBlock
    18 		selectConditionBlock clickLine highlightMode useIndex
    18 		doubleClickActionBlock selectConditionBlock clickLine
    19 		ignoreReselect toggleSelect hilightFgColor hilightBgColor
    19 		highlightMode useIndex ignoreReselect toggleSelect hilightFgColor
    20 		hilightLevel hilightFrameColor hilightStyle dragAccessPoint
    20 		hilightBgColor hilightLevel hilightFrameColor hilightStyle
    21 		dropTarget dropSource editorView openEditorAction'
    21 		dragAccessPoint dropTarget dropSource editorView openEditorAction'
    22 	classVariableNames:'DefaultHilightStyle DefaultHilightBackgroundColor
    22 	classVariableNames:'DefaultHilightStyle DefaultHilightBackgroundColor
    23 		DefaultHilightForegroundColor DefaultHilightLevel
    23 		DefaultHilightForegroundColor DefaultHilightLevel
    24 		DefaultHilightFrameColor'
    24 		DefaultHilightFrameColor'
    25 	poolDictionaries:''
    25 	poolDictionaries:''
    26 	category:'Views-Lists'
    26 	category:'Views-Lists'
    48     SelectionInListModelView is mostly like SelectionInListView,
    48     SelectionInListModelView is mostly like SelectionInListView,
    49     but derives from the ListModelView and thus the list is kept
    49     but derives from the ListModelView and thus the list is kept
    50     by the model.
    50     by the model.
    51 
    51 
    52     [Instance variables:]
    52     [Instance variables:]
    53         selection               <misc>     the current selection. nil, a number or collection of numbers
    53 
    54         multipleSelectOk        <Boolean>  allow/disallow multiple selections( default:false )
    54         selection               <misc>       the current selection. nil, a number or collection of numbers
    55         actionBlock             <Block>    action evaluated on single click
    55         multipleSelectOk        <Boolean>    allow/disallow multiple selections( default:false )
    56         doubleClickActionBlock  <Block>    action evaluated on double click
    56         selectOnButtomMenu      <Boolean>    enable/disable selection will change on menu pressed
    57         clickPosition           <Point>    internal use
    57 
    58         highlightMode           <Symbol>   how to draw the selection
    58         actionBlock             <Block>      action evaluated on single click
    59         useIndex                <Boolean>  representation of the model selection
    59         doubleClickActionBlock  <Block>      action evaluated on double click
    60         ignoreReselect          <Boolean>  if set, a click on an already selected entry is ignored
    60         selectConditionBlock
    61         toggleSelect            <Boolean>  a click on an entry unselects it and vice versa
    61 
    62         hilightFgColor          <Color>    foregroundColor of highlighted items       
    62         clickLine               <Number>     clicked line during button motion
    63         hilightBgColor          <Color>    backgroundColor of highlighted items
    63         useIndex                <Boolean>    representation of the model selection
    64         hilightLevel            <Integer>  level to draw selections (i.e. for 3D effect)
    64 
    65         hilightFrameColor       <Color>    rectangle around highlighted items
    65         ignoreReselect          <Boolean>    if set, a click on an already selected entry is ignored
    66         hilightStyle            <Boolean>  actions on widget are enabled/disabled
    66         toggleSelect            <Boolean>    a click on an entry unselects it and vice versa
       
    67 
       
    68         highlightMode           <Symbol>     how to draw the selection
       
    69         hilightFgColor          <Color>      foregroundColor of highlighted items       
       
    70         hilightBgColor          <Color>      backgroundColor of highlighted items
       
    71         hilightLevel            <Integer>    level to draw selections (i.e. for 3D effect)
       
    72         hilightFrameColor       <Color>      rectangle around highlighted items
       
    73         hilightStyle            <Boolean>    actions on widget are enabled/disabled
       
    74 
       
    75         dragAccessPoint         <Point>      point where the drag operation starts from
       
    76         dropTarget              <DropTarget> keeps information about the drop operation
       
    77         dropSource              <DropSource> keeps information about the drag operation
       
    78 
       
    79         editorView              <View>       editor on current selected item
       
    80         openEditorAction        <Action>     action to get an editor on the current selection from user
    67 
    81 
    68     [author:]
    82     [author:]
    69         Claus Atzkern
    83         Claus Atzkern
    70 
    84 
    71     [see also:]
    85     [see also:]
    72 
    86 
    73         ListModelView
    87         ListModelView
    74         HierarchicalListView
    88         HierarchicalListView
    75 "
    89 "
    76 
       
    77 
       
    78 !
    90 !
    79 
    91 
    80 examples
    92 examples
    81 "
    93 "
    82                                                                         [exBegin]
    94                                                                         [exBegin]
   347 
   359 
   348 multipleSelectOk:aState
   360 multipleSelectOk:aState
   349     "allow/disallow multiple selections; the default is false
   361     "allow/disallow multiple selections; the default is false
   350     "
   362     "
   351     multipleSelectOk := aState ? false.
   363     multipleSelectOk := aState ? false.
       
   364 !
       
   365 
       
   366 selectOnButtomMenu
       
   367     "define the button-menu-press behavior; if true the line under the mouse
       
   368      will be selected before the menu is opened. Otherwise the menu is opened
       
   369      on the current selection.
       
   370     "
       
   371     ^ selectOnButtomMenu
       
   372 !
       
   373 
       
   374 selectOnButtomMenu:aBoolean
       
   375     "define the button-menu-press behavior; if true the line under the mouse
       
   376      will be selected before the menu is opened. Otherwise the menu is opened
       
   377      on the current selection.
       
   378     "
       
   379     selectOnButtomMenu := aBoolean.
   352 !
   380 !
   353 
   381 
   354 toggleSelect
   382 toggleSelect
   355     "get the toggleSelect flag - see method #toggleSelect: for more details
   383     "get the toggleSelect flag - see method #toggleSelect: for more details
   356     "
   384     "
   880 !
   908 !
   881 
   909 
   882 buttonPress:button x:x y:y
   910 buttonPress:button x:x y:y
   883     "a button was pressed - handle selection here
   911     "a button was pressed - handle selection here
   884     "
   912     "
   885     |sensor nsel start step item menu appl isInSelection|
   913     |sensor nsel start step item menu appl isInSelection lineNr|
   886 
   914 
   887     clickLine       := nil.
   915     clickLine       := nil.
   888     dragAccessPoint := nil.
   916     dragAccessPoint := nil.
   889 
   917 
   890     enabled ifFalse:[^ self].
   918     enabled ifFalse:[^ self].
   891 
   919 
       
   920     sensor := self sensor.
       
   921     sensor notNil ifTrue:[ lineNr := self yVisibleToLineNr:y ]
       
   922                  ifFalse:[ lineNr := nil ].
       
   923 
   892     ((button == 2) or:[button == #menu]) ifTrue:[
   924     ((button == 2) or:[button == #menu]) ifTrue:[
   893         (     (item := self selectedElement) notNil
   925         selectOnButtomMenu ifTrue:[
   894          and:[(menu := item perform:#middleButtonMenu ifNotUnderstood:nil) notNil]
   926             (     lineNr notNil
   895         ) ifTrue:[
   927              and:[lineNr ~~ self selectedIndex
   896             menu isCollection ifTrue:[
   928              and:[self canSelectIndex:lineNr forAdd:false ]]
   897                 menu := Menu new fromLiteralArrayEncoding:menu.
   929             ) ifTrue:[
   898                 appl := self application.
   930                 (self selectWithoutScroll:lineNr redraw:true) ifTrue:[
   899 
   931                     self selectionChanged
   900                 appl notNil ifTrue:[
   932                 ].
   901                     menu findGuiResourcesIn:appl.
   933                 item := self selectedElement.
   902                     "/ menu receiver:appl  -- now done in findGuiResources ...
   934             ] ifFalse:[
   903                 ] ifFalse:[
   935                 item := nil
   904                     menu receiver:item
   936             ]
   905                 ]
   937         ] ifFalse:[
   906             ].
   938             item := self selectedElement.
   907             ^ menu startUp
   939         ].
   908         ].
   940 
   909         ^ super buttonPress:button x:x y:y
   941         item ifNotNil:[
   910     ].
   942             item ifNotNil:[ self makeSelectionVisible ].
   911 
   943 
   912     (    (sensor    := self sensor) isNil 
   944             menu := item perform:#middleButtonMenu ifNotUnderstood:nil.
   913      or:[(clickLine := self yVisibleToLineNr:y) isNil]
   945 
   914     ) ifTrue:[
   946             menu ifNotNil:[
   915         ^ self
   947                 menu isCollection ifTrue:[
   916     ].
   948                     menu := Menu new fromLiteralArrayEncoding:menu.
       
   949                     appl := self application.
       
   950 
       
   951                     appl notNil ifTrue:[
       
   952                         menu findGuiResourcesIn:appl.
       
   953                         "/ menu receiver:appl  -- now done in findGuiResources ...
       
   954                     ] ifFalse:[
       
   955                         menu receiver:item
       
   956                     ]
       
   957                 ].
       
   958                 menu startUp.
       
   959               ^ self
       
   960             ]
       
   961         ].
       
   962         super buttonPress:button x:x y:y.
       
   963       ^ self
       
   964     ].
       
   965 
       
   966     (clickLine := lineNr) ifNil:[ ^ self ].
       
   967 
   917     isInSelection := self isInSelection:clickLine.
   968     isInSelection := self isInSelection:clickLine.
   918 
   969 
   919     multipleSelectOk ifTrue:[
   970     multipleSelectOk ifTrue:[
   920         sensor ctrlDown ifTrue:[
   971         sensor ctrlDown ifTrue:[
   921             (isInSelection or:[self canSelectIndex:clickLine forAdd:true]) ifTrue:[
   972             (isInSelection or:[self canSelectIndex:clickLine forAdd:true]) ifTrue:[
  1210 !
  1261 !
  1211 
  1262 
  1212 initStyle
  1263 initStyle
  1213     "setup viewStyle specifics
  1264     "setup viewStyle specifics
  1214     "
  1265     "
  1215     |h|
       
  1216 
       
  1217     super initStyle.
  1266     super initStyle.
  1218 
  1267 
  1219     DefaultHilightLevel isNil ifTrue:[
  1268     hilightFrameColor   := nil.
  1220         self updateStyleCache
  1269     hilightStyle        := DefaultHilightStyle.
  1221     ].
  1270     highlightMode       := #label.
  1222 
  1271     textStartLeft       := 4.
  1223     hilightFrameColor := nil.
  1272     selectOnButtomMenu  := false.
  1224     hilightStyle      := DefaultHilightStyle.
       
  1225     highlightMode     := #label.
       
  1226     textStartLeft     := 4.
       
  1227 
  1273 
  1228     super font:(styleSheet fontAt:#'selection.font').
  1274     super font:(styleSheet fontAt:#'selection.font').
  1229 
  1275 
  1230     device hasGrayscales ifTrue:[
  1276     device hasGrayscales ifTrue:[
  1231         "
  1277         "
  1683 ! !
  1729 ! !
  1684 
  1730 
  1685 !SelectionInListModelView class methodsFor:'documentation'!
  1731 !SelectionInListModelView class methodsFor:'documentation'!
  1686 
  1732 
  1687 version
  1733 version
  1688     ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.51 2002-09-27 11:53:27 penk Exp $'
  1734     ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.52 2002-09-28 04:57:55 ca Exp $'
  1689 ! !
  1735 ! !