SelectionInListModelView.st
changeset 2225 d785c9d86aa3
parent 2185 639d20ab5667
child 2228 5268b9c3be4a
--- a/SelectionInListModelView.st	Fri Sep 27 13:32:55 2002 +0200
+++ b/SelectionInListModelView.st	Fri Sep 27 13:53:27 2002 +0200
@@ -180,6 +180,70 @@
   ^ super list:aList
 ! !
 
+!SelectionInListModelView methodsFor:'accessing editor'!
+
+closeEditor
+    "close the current editor
+    "
+    |editor|
+
+    (editor := editorView) notNil ifTrue:[
+        editorView := nil.
+        editor destroy.
+    ].
+
+
+!
+
+openEditor
+    "opens the editor on the current selection;
+     returns the editorView or nil if no openEditorAction is defined
+     or no single selection exists ...
+    "
+    |numArgs lnNr|
+
+    self closeEditor.
+    shown ifFalse:[^ nil].
+    openEditorAction ifNil:[^ nil].
+    lnNr := self selectedIndex.
+    lnNr == 0 ifTrue:[^ nil].
+
+    self makeSelectionVisible.
+
+    numArgs := openEditorAction numArgs.
+
+    numArgs == 0 ifTrue:[
+        editorView := openEditorAction value
+    ] ifFalse:[
+        numArgs == 1 ifTrue:[editorView := openEditorAction value:lnNr]
+                    ifFalse:[editorView := openEditorAction value:lnNr value:self]
+    ].
+    editorView ifNil:[^ nil].
+
+    editorView superView ifNil:[
+        self addSubView:editorView
+    ].
+    self computeEditorLayout.
+    editorView realize.
+    self windowGroup focusView:editorView.
+  ^ editorView
+!
+
+openEditorAction
+    "get the block which is evaluated to get the editor which is set for the
+     line; the arguments to the block is the line number and the widget itself
+    "
+    ^ openEditorAction
+
+!
+
+openEditorAction:aTwoArgAction
+    "set the block which is evaluated to get the editor which is set for the
+     line; the arguments to the block is the line number and the widget itself
+    "
+    openEditorAction := aTwoArgAction.
+! !
+
 !SelectionInListModelView methodsFor:'accessing-actions'!
 
 action
@@ -210,21 +274,6 @@
 
 !
 
-openEditorAction
-    "get the block which is evaluated to get the editor which is set for the
-     line; the arguments to the block is the line number and the widget itself
-    "
-    ^ openEditorAction
-
-!
-
-openEditorAction:aTwoArgAction
-    "set the block which is evaluated to get the editor which is set for the
-     line; the arguments to the block is the line number and the widget itself
-    "
-    openEditorAction := aTwoArgAction.
-!
-
 selectConditionBlock
     "set the conditionBlock; this block is evaluated before a selection
      change is performed; the change will not be done, if the evaluation
@@ -504,7 +553,9 @@
             model setValue:(arg isNil ifTrue:[0] ifFalse:[nil]).
         ].
         self sendChangeMessage:#value: with:arg.
-        model addDependent:self.
+        model notNil ifTrue:[  "/ argggh could be nilled
+            model addDependent:self.
+        ]
     ].
 
     actionBlock notNil ifTrue:[
@@ -1119,9 +1170,10 @@
         or:[hilightLevel ~~ 0]]) ifTrue:[
            "/ invalidate the right-edge
             self invalidate:(((width-3) @ 0) corner:((width-1) @ (height-1))).
-        ]
+        ].
     ].
     super sizeChanged:how.
+    self makeSelectionVisible
 ! !
 
 !SelectionInListModelView methodsFor:'focus handling'!
@@ -1258,19 +1310,6 @@
 
 !SelectionInListModelView methodsFor:'private editor'!
 
-closeEditor
-    "close the current editor
-    "
-    |editor|
-
-    (editor := editorView) notNil ifTrue:[
-        editorView := nil.
-        editor destroy.
-    ].
-
-
-!
-
 computeEditorLayout
     "update the layout of the editor
     "
@@ -1297,46 +1336,31 @@
 openEditorAtX:x y:y
     "opens an editor on the current single selection
     "
-    |item lnNr x0 numArgs y0|
+    |item lnNr x0 y0 editor|
 
     self closeEditor.
+    shown          ifFalse:[^ self ].
+    openEditorAction ifNil:[^ self].
 
-    (    shown not
-     or:[openEditorAction isNil
-     or:[(lnNr := self selectedIndex) == 0
-     or:[(item := list at:lnNr ifAbsent:nil) isNil]]]
-    ) ifTrue:[
-        ^ self
-    ].
+    lnNr := self selectedIndex.
+    lnNr == 0 ifTrue:[^ self].
+
+    item := list at:lnNr ifAbsent:nil.
+    item ifNil:[^ self].
 
     x < (self xVisibleOfItem:item) ifTrue:[
         "/ not part of the selection frame; ignorre
         ^ self
     ].
-    numArgs := openEditorAction numArgs.
-    numArgs == 0 ifTrue:[
-        editorView := openEditorAction value
-    ] ifFalse:[
-        numArgs == 1 ifTrue:[editorView := openEditorAction value:lnNr]
-                    ifFalse:[editorView := openEditorAction value:lnNr value:self]
-    ].
-    editorView isNil ifTrue:[
-        ^ self
-    ].
+    editor := self openEditor.
+    editor ifNil:[^ self].
 
-    editorView superView isNil ifTrue:[
-        self addSubView:editorView
-    ].
-    self computeEditorLayout.
-    editorView realize.
-    self windowGroup focusView:editorView.
-
-    y0 := (y - editorView origin y) max:0.
-    x0 := (x - editorView origin x) max:0.
+    y0 := (y - editor origin y) max:0.
+    x0 := (x - editor origin x) max:0.
 
     "/ simulate clicking into the editor
-    self sensor pushEvent:(WindowEvent buttonPress:#select x:x0 y:y0 view:editorView).
-    self sensor pushEvent:(WindowEvent buttonRelease:#select x:x0 y:y0 view:editorView).
+    self sensor pushEvent:(WindowEvent buttonPress:#select x:x0 y:y0 view:editor).
+    self sensor pushEvent:(WindowEvent buttonRelease:#select x:x0 y:y0 view:editor).
 
     "/ to clear the selection
     self redrawLineAt:lnNr.
@@ -1661,5 +1685,5 @@
 !SelectionInListModelView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.50 2002-09-12 13:54:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.51 2002-09-27 11:53:27 penk Exp $'
 ! !