#FEATURE by cg
class: UIPainter
added:
#hasMultipleSelectionOtherThanCanvas
#hasSelectionOtherThanCanvas
changed:7 methods
category of:42 methods
--- a/UIPainter.st Mon Dec 12 23:27:57 2016 +0100
+++ b/UIPainter.st Mon Dec 12 23:28:30 2016 +0100
@@ -2559,7 +2559,6 @@
enabled: canWrapSelection
label: 'Wrap Into...'
itemValue: doAskAndWrapWidgetInto
- isVisible: false
)
(MenuItem
label: '-'
@@ -2658,6 +2657,7 @@
activeHelpKey: editOpenSpecDocumentation
label: 'Open Widget Documentation'
itemValue: doOpenWidgetDocumentation
+ enabled: hasOneSelectionOtherThanCanvas
)
(MenuItem
activeHelpKey: referToConfigDatabase
@@ -2682,6 +2682,7 @@
activeHelpKey: sortItems
label: 'Sort Selected Items by Position'
itemValue: doSortItems
+ enabled: hasMultipleSelectionOtherThanCanvas
)
(MenuItem
activeHelpKey: groupWithLayout
@@ -2697,7 +2698,7 @@
)
(MenuItem
activeHelpKey: ungroupWithLayout
- enabled: canGroup
+ enabled: canUngroup
label: 'Ungroup with Layout'
itemValue: ungroupWithLayout
)
@@ -2720,11 +2721,13 @@
activeHelpKey: editBrowseViewClass
label: 'Browse Specification Class'
itemValue: doBrowseSpecificationClass
+ enabled: hasOneSelectionOtherThanCanvas
)
(MenuItem
activeHelpKey: editInspectSpec
label: 'Inspect Spec'
itemValue: doInspectSpec
+ enabled: hasOneSelectionOtherThanCanvas
)
(MenuItem
label: '-'
@@ -3355,6 +3358,7 @@
canMoveSelection
"true if move-in/move-out/move-up and down are enabled"
+ treeView hasOneSelectionOtherThanCanvas ifFalse:[^ false].
^ self canChangeOrderInContainer value
or: [ self canMoveSelectionOutOfContainer value
or: [ self canMoveSelectionIntoContainer value ]]
@@ -3388,7 +3392,7 @@
!
canReplaceSelection
- treeView isCanvasSelected ifTrue:[^ false].
+ treeView hasOneSelectionOtherThanCanvas ifFalse:[^ false].
^ true
!
@@ -3400,7 +3404,7 @@
!
canWrapSelection
- treeView isCanvasSelected ifTrue:[^ false].
+ treeView hasOneSelectionOtherThanCanvas ifFalse:[^ false].
^ true
!
@@ -3451,6 +3455,12 @@
^ holder
!
+hasMultipleSelectionOtherThanCanvas
+ "returns a value holder which is true in case that multiple widget other than the root are selected"
+
+ ^ builder booleanValueAspectFor:#hasMultipleSelectionOtherThanCanvas
+!
+
hasOneSelectionOtherThanCanvas
"returns a value holder which is true in case that one widget is selected
other than the root"
@@ -3458,6 +3468,12 @@
^ builder booleanValueAspectFor:#hasOneSelectionOtherThanCanvas
!
+hasSelectionOtherThanCanvas
+ "returns a value holder which is true in case that any widget other than the root is selected"
+
+ ^ builder booleanValueAspectFor:#hasSelectionOtherThanCanvas
+!
+
hasUndoHistory
^ self painter hasUndoHistory
!
@@ -4027,7 +4043,9 @@
self canMoveSelectionIntoContainer value:(treeView canMoveSelectionIntoContainer).
self canMoveSelectionOutOfContainer value:(treeView canMoveSelectionOutOfContainer).
self hasOneSelectionOtherThanCanvas value:(treeView hasOneSelectionOtherThanCanvas).
-
+ self hasSelectionOtherThanCanvas value:(treeView hasSelectionOtherThanCanvas).
+ self hasMultipleSelectionOtherThanCanvas value:(treeView hasMultipleSelectionOtherThanCanvas).
+
"/ the top-node cannot be cut, copied or pasted.
canCutOrCopy := treeView selection notEmptyOrNil and:[treeView selection first ~~ 1].
@@ -5376,6 +5394,114 @@
]
!
+hideEditToolbar
+ self editToolBarVisibleHolder value:false
+!
+
+hideToolbar
+ self toolBarVisibleHolder value:false
+!
+
+replaceWidgetByClass:aSpecOrWidgetClass
+ "replace the selected widget by a new instance of aSpecOrWidgetClass,
+ which gets the old widget's layout"
+
+ |newSpecClass oldSpec newSpec|
+
+ treeView isCanvasSelected ifTrue:[
+ ^ self
+ ].
+ (newSpecClass := self specClassFromUsersSpecOrWidgetClass:aSpecOrWidgetClass) isNil ifTrue:[
+ ^ newSpecClass
+ ].
+
+ oldSpec := self selectedSpec.
+ newSpec := newSpecClass cloneFrom:oldSpec.
+
+ self painter replaceSelectionBy:newSpec.
+
+ "Modified: / 05-09-2012 / 19:24:40 / cg"
+!
+
+setMoveByStep:nPixels
+ "change the number of pixels by which the step-buttons move the selected widget(s)"
+
+ self painter nPixelsForMoveSelection:nPixels
+!
+
+specClassFromUsersSpecOrWidgetClass:aSpecOrWidgetClass
+ |newSpecClass|
+
+ (aSpecOrWidgetClass isSubclassOf:UISpecification) ifTrue:[
+ newSpecClass := aSpecOrWidgetClass.
+ ] ifFalse:[
+ (aSpecOrWidgetClass isSubclassOf:View) ifTrue:[
+ newSpecClass := aSpecOrWidgetClass basicNew specClass.
+ ] ifFalse:[
+ newSpecClass := nil
+ ].
+ ].
+ newSpecClass isNil ifTrue:[
+ Dialog warn:'Invalid Spec- or View-Class: ' , aSpecOrWidgetClass name.
+ ^ nil.
+ ].
+ ^ newSpecClass
+!
+
+useBackgroundImage
+ "select bitmap to underly"
+
+ |fn|
+
+ fn := Dialog requestFileName:'Bitmap Image File ?' pattern:'*.gif;*.tiff;*.jpg;*.png' fromDirectory:'f:'.
+ fn isNil ifTrue:[
+ ^ self
+ ].
+ painter useSketchFile:fn
+
+ "Created: / 16-01-2008 / 17:49:20 / cg"
+!
+
+useSketch
+ "select sketchfile to underly.
+ Sketchfiles are generated by notepads, which can offline-store drawn sketches"
+
+ |fn|
+
+ fn := Dialog requestFileName:'Sketch (Notepad Drawing) ?' pattern:'*.TOP' fromDirectory:'f:'.
+ fn isNil ifTrue:[
+ ^ self
+ ].
+ painter useSketchFile:fn
+
+ "Created: / 16-01-2008 / 17:49:20 / cg"
+!
+
+wrapWidgetIntoClass:aSpecOrWidgetClass
+ "put the selected widget into a new instance of aSpecOrWidgetClass,
+ which gets the wrapped widget's layout"
+
+ |newSpecClass oldSpec newSpec|
+
+ treeView isCanvasSelected ifTrue:[
+ ^ self
+ ].
+ (newSpecClass := self specClassFromUsersSpecOrWidgetClass:aSpecOrWidgetClass) isNil ifTrue:[
+ ^ newSpecClass
+ ].
+
+ oldSpec := self selectedSpec.
+ newSpec := newSpecClass new.
+ newSpec layout:oldSpec layout.
+ newSpec component:oldSpec.
+
+ self painter replaceSelectionBy:newSpec.
+
+ "Modified: / 05-09-2012 / 19:24:40 / cg"
+! !
+
+!UIPainter methodsFor:'user actions-menu'!
+
doAskAndReplaceWidgetBy
"ask for a widget class,
and replace the selected widget by a new instance of that one,
@@ -5416,31 +5542,29 @@
and put the selected widget into a new instance of that one,
which gets the wrapped widget's layout"
-Dialog information:'sorry - unfinished.'.
-^ self.
-"/ |widgetClass list selectedSpec|
-"/
-"/ selectedSpec := self selectedSpec.
-"/ selectedSpec isNil ifTrue:[^ self].
-"/
-"/ list := UISpecification allSubclasses
-"/ select:[:cls |
-"/ [ cls viewClass notNil
-"/ and:[ cls supportsSubComponents ]]
-"/ on: NotFoundError
-"/ do:[ false ]
-"/ ].
-"/ list sort:[:a :b | a name < b name].
-"/
-"/ widgetClass := Dialog
-"/ requestClass:'Wrap into (Spec or View Class):'
-"/ list:list
-"/ okLabel:'OK'
-"/ initialAnswer:nil.
-"/ widgetClass isNil ifTrue:[
-"/ ^ self
-"/ ].
-"/ self wrapWidgetIntoClass:widgetClass
+ |widgetClass list selectedSpec|
+
+ selectedSpec := self selectedSpec.
+ selectedSpec isNil ifTrue:[^ self].
+
+ list := UISpecification allSubclasses
+ select:[:cls |
+ [ cls viewClass notNil
+ and:[ cls supportsSubComponents ]]
+ on: NotFoundError
+ do:[ false ]
+ ].
+ list sort:[:a :b | a name < b name].
+
+ widgetClass := Dialog
+ requestClass:'Wrap into (Spec or View Class):'
+ list:list
+ okLabel:'OK'
+ initialAnswer:nil.
+ widgetClass isNil ifTrue:[
+ ^ self
+ ].
+ self wrapWidgetIntoClass:widgetClass
!
doBrowseActionMethod:aspectSelector
@@ -6416,110 +6540,6 @@
openWith: self painter generateWindowSpecMethodSource
title: 'Window Spec'
-!
-
-hideEditToolbar
- self editToolBarVisibleHolder value:false
-!
-
-hideToolbar
- self toolBarVisibleHolder value:false
-!
-
-replaceWidgetByClass:aSpecOrWidgetClass
- "replace the selected widget by a new instance of aSpecOrWidgetClass,
- which gets the old widget's layout"
-
- |newSpecClass oldSpec newSpec|
-
- treeView isCanvasSelected ifTrue:[
- ^ self
- ].
- (newSpecClass := self specClassFromUsersSpecOrWidgetClass:aSpecOrWidgetClass) isNil ifTrue:[
- ^ newSpecClass
- ].
-
- oldSpec := self selectedSpec.
- newSpec := newSpecClass cloneFrom:oldSpec.
-
- self painter replaceSelectionBy:newSpec.
-
- "Modified: / 05-09-2012 / 19:24:40 / cg"
-!
-
-setMoveByStep:nPixels
- "change the number of pixels by which the step-buttons move the selected widget(s)"
-
- self painter nPixelsForMoveSelection:nPixels
-!
-
-specClassFromUsersSpecOrWidgetClass:aSpecOrWidgetClass
- |newSpecClass|
-
- (aSpecOrWidgetClass isSubclassOf:UISpecification) ifTrue:[
- newSpecClass := aSpecOrWidgetClass.
- ] ifFalse:[
- (aSpecOrWidgetClass isSubclassOf:View) ifTrue:[
- newSpecClass := aSpecOrWidgetClass basicNew specClass.
- ] ifFalse:[
- newSpecClass := nil
- ].
- ].
- newSpecClass isNil ifTrue:[
- Dialog warn:'Invalid Spec- or View-Class: ' , aSpecOrWidgetClass name.
- ^ nil.
- ].
- ^ newSpecClass
-!
-
-useBackgroundImage
- "select bitmap to underly"
-
- |fn|
-
- fn := Dialog requestFileName:'Bitmap Image File ?' pattern:'*.gif;*.tiff;*.jpg;*.png' fromDirectory:'f:'.
- fn isNil ifTrue:[
- ^ self
- ].
- painter useSketchFile:fn
-
- "Created: / 16-01-2008 / 17:49:20 / cg"
-!
-
-useSketch
- "select sketchfile to underly.
- Sketchfiles are generated by notepads, which can offline-store drawn sketches"
-
- |fn|
-
- fn := Dialog requestFileName:'Sketch (Notepad Drawing) ?' pattern:'*.TOP' fromDirectory:'f:'.
- fn isNil ifTrue:[
- ^ self
- ].
- painter useSketchFile:fn
-
- "Created: / 16-01-2008 / 17:49:20 / cg"
-!
-
-wrapWidgetIntoClass:aSpecOrWidgetClass
- "put the selected widget into a new instance of aSpecOrWidgetClass,
- which gets the wrapped widget's layout"
-
- |newSpecClass oldSpec newSpec|
-
- treeView isCanvasSelected ifTrue:[
- ^ self
- ].
- (newSpecClass := self specClassFromUsersSpecOrWidgetClass:aSpecOrWidgetClass) isNil ifTrue:[
- ^ newSpecClass
- ].
-
- oldSpec := self selectedSpec.
- newSpec := newSpecClass cloneFrom:oldSpec.
-
- self painter wrapSelectionInto:newSpec.
-
- "Modified: / 05-09-2012 / 19:24:40 / cg"
! !
!UIPainter::ApplicationClassQuery class methodsFor:'documentation'!
@@ -7283,12 +7303,24 @@
^ self canvas canResize:(self selectedViews)
!
+hasMultipleSelectionOtherThanCanvas
+ "returns true in case that any selection other than the canvas exists"
+
+ ^ selection size > 0 and:[ (selection count:[:anyindex | anyindex ~~ 1]) > 1]
+!
+
hasOneSelectionOtherThanCanvas
"returns true in case that one selection exists other than the canvas"
^ selection size == 1 and:[selection first ~~ 1]
!
+hasSelectionOtherThanCanvas
+ "returns true in case that any selection other than the canvas exists"
+
+ ^ selection size > 0 and:[selection contains:[:anyindex | anyindex ~~ 1]]
+!
+
isCanvasSelected
"returns true in case of a single selection and the
selection is the canvas (index 1)"