UIObjectView.st
changeset 134 d5ab85ec27fd
parent 132 8649766ce095
child 138 035c98964c38
equal deleted inserted replaced
133:e12f82d3afb7 134:d5ab85ec27fd
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'Interface-UIPainter'
     7 	category:'Interface-UIPainter'
     8 !
     8 !
     9 
     9 
    10 Object subclass:#UndoHistory
    10 Object subclass:#UndoHistory
    11 	instanceVariableNames:'history transaction enabled'
    11 	instanceVariableNames:'startIdentifier identifier painter history transaction enabled'
    12 	classVariableNames:''
    12 	classVariableNames:''
    13 	poolDictionaries:''
    13 	poolDictionaries:''
    14 	privateIn:UIObjectView
    14 	privateIn:UIObjectView
    15 !
    15 !
    16 
    16 
    17 Object subclass:#Transaction
    17 Object subclass:#Transaction
    18 	instanceVariableNames:'type text actions'
    18 	instanceVariableNames:'identifier type text actions'
    19 	classVariableNames:''
    19 	classVariableNames:''
    20 	poolDictionaries:''
    20 	poolDictionaries:''
    21 	privateIn:UIObjectView::UndoHistory
    21 	privateIn:UIObjectView::UndoHistory
    22 !
    22 !
    23 
    23 
   260 
   260 
   261 
   261 
   262 
   262 
   263 !
   263 !
   264 
   264 
       
   265 resetModification
       
   266     "set modification state to false
       
   267     "
       
   268     undoHistory resetModification
       
   269 !
       
   270 
   265 testMode
   271 testMode
   266     "returns true if running test
   272     "returns true if running test
   267     "
   273     "
   268     ^ enableChannel value not
   274     ^ enableChannel value not
   269 
   275 
   380     inputView enableButtonEvents.
   386     inputView enableButtonEvents.
   381     inputView enableButtonMotionEvents.
   387     inputView enableButtonMotionEvents.
   382 
   388 
   383     self setDefaultActions.
   389     self setDefaultActions.
   384 
   390 
   385     undoHistory          := UndoHistory new.
   391     undoHistory          := UndoHistory on:self.
   386     enableChannel        := true asValue.
   392     enableChannel        := true asValue.
   387     clipChildren         := true.
   393     clipChildren         := true.
   388     selectionHiddenLevel := 0.
   394     selectionHiddenLevel := 0.
   389 
   395 
   390     (self class gridShown) ifTrue:[
   396     (self class gridShown) ifTrue:[
   663         delta := aPoint - org.
   669         delta := aPoint - org.
   664         delta := (self alignToGrid:aPoint) - org.
   670         delta := (self alignToGrid:aPoint) - org.
   665         dX := delta x.
   671         dX := delta x.
   666         dY := delta y.
   672         dY := delta y.
   667 
   673 
   668         undoHistory disabledTransitionDo:[
   674         undoHistory withoutTransactionDo:[
   669             self shiftLayout:anObject top:dY bottom:dY left:dX right:dX
   675             self shiftLayout:anObject top:dY bottom:dY left:dX right:dX
   670         ]
   676         ]
   671     ]
   677     ]
   672 
   678 
   673 !
   679 !
   687         aPoint - aView computeOrigin
   693         aPoint - aView computeOrigin
   688     ].
   694     ].
   689 
   695 
   690     self transaction:#move objects:movedObject do:[:aView|
   696     self transaction:#move objects:movedObject do:[:aView|
   691         self invertOutlineOf:aView.
   697         self invertOutlineOf:aView.
   692         self undoLayoutView:aView
   698         self createUndoLayout:aView
   693     ].
   699     ].
   694 
   700 
   695 !
   701 !
   696 
   702 
   697 startSelectMoreOrMove:aPoint
   703 startSelectMoreOrMove:aPoint
   828 
   834 
   829     object := self singleSelection.
   835     object := self singleSelection.
   830     self actionResize:object selector:b.
   836     self actionResize:object selector:b.
   831 
   837 
   832     self transaction:#resize selectionDo:[:aView|
   838     self transaction:#resize selectionDo:[:aView|
   833         self undoLayoutView:aView
   839         self createUndoLayout:aView
   834     ].
   840     ].
   835     self setSelection:nil withRedraw:true.
   841     self setSelection:nil withRedraw:true.
   836 
   842 
   837     motionAction  := [:movePoint | self doDragResize:movePoint].
   843     motionAction  := [:movePoint | self doDragResize:movePoint].
   838     releaseAction := [self endResize].
   844     releaseAction := [self endResize].
   970 !UIObjectView methodsFor:'private resizing-subviews'!
   976 !UIObjectView methodsFor:'private resizing-subviews'!
   971 
   977 
   972 resize:aView bottom:aPoint
   978 resize:aView bottom:aPoint
   973     "resize a views bottom
   979     "resize a views bottom
   974     "
   980     "
   975     undoHistory disabledTransitionDo:[
   981     undoHistory withoutTransactionDo:[
   976         self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
   982         self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
   977     ]
   983     ]
   978 !
   984 !
   979 
   985 
   980 resize:aView bottomLeft:aPoint
   986 resize:aView bottomLeft:aPoint
   981     "resize a views bottom and left
   987     "resize a views bottom and left
   982     "
   988     "
   983     undoHistory disabledTransitionDo:[
   989     undoHistory withoutTransactionDo:[
   984         self shiftLayout:aView top:0
   990         self shiftLayout:aView top:0
   985                             bottom:((aPoint y) - (aView computeCorner y))
   991                             bottom:((aPoint y) - (aView computeCorner y))
   986                               left:((aPoint x) - (aView computeOrigin x))
   992                               left:((aPoint x) - (aView computeOrigin x))
   987                              right:0
   993                              right:0
   988 
   994 
   996     "
  1002     "
   997     |delta|
  1003     |delta|
   998 
  1004 
   999     delta := aPoint - aView computeCorner.
  1005     delta := aPoint - aView computeCorner.
  1000 
  1006 
  1001     undoHistory disabledTransitionDo:[
  1007     undoHistory withoutTransactionDo:[
  1002         self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
  1008         self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
  1003     ]
  1009     ]
  1004 !
  1010 !
  1005 
  1011 
  1006 resize:aView left:aPoint
  1012 resize:aView left:aPoint
  1007     "resize a views left
  1013     "resize a views left
  1008     "
  1014     "
  1009     undoHistory disabledTransitionDo:[
  1015     undoHistory withoutTransactionDo:[
  1010         self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
  1016         self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
  1011     ]
  1017     ]
  1012 
  1018 
  1013 !
  1019 !
  1014 
  1020 
  1017     "
  1023     "
  1018     |delta|
  1024     |delta|
  1019 
  1025 
  1020     delta := aPoint - aView computeOrigin.
  1026     delta := aPoint - aView computeOrigin.
  1021 
  1027 
  1022     undoHistory disabledTransitionDo:[
  1028     undoHistory withoutTransactionDo:[
  1023         self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0
  1029         self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0
  1024     ]
  1030     ]
  1025 
  1031 
  1026 !
  1032 !
  1027 
  1033 
  1028 resize:aView right:aPoint
  1034 resize:aView right:aPoint
  1029     "resize a views right
  1035     "resize a views right
  1030     "
  1036     "
  1031     undoHistory disabledTransitionDo:[
  1037     undoHistory withoutTransactionDo:[
  1032         self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
  1038         self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
  1033     ]
  1039     ]
  1034 !
  1040 !
  1035 
  1041 
  1036 resize:aView top:aPoint
  1042 resize:aView top:aPoint
  1037     "resize a views top
  1043     "resize a views top
  1038     "
  1044     "
  1039     undoHistory disabledTransitionDo:[
  1045     undoHistory withoutTransactionDo:[
  1040         self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
  1046         self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
  1041     ]
  1047     ]
  1042 !
  1048 !
  1043 
  1049 
  1044 resize:aView topRight:aPoint
  1050 resize:aView topRight:aPoint
  1045     "resize a views top and right
  1051     "resize a views top and right
  1046     "
  1052     "
  1047     undoHistory disabledTransitionDo:[
  1053     undoHistory withoutTransactionDo:[
  1048         self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y))
  1054         self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y))
  1049                             bottom:0
  1055                             bottom:0
  1050                               left:0
  1056                               left:0
  1051                              right:((aPoint x) - (aView computeCorner x))
  1057                              right:((aPoint x) - (aView computeCorner x))
  1052 
  1058 
  1080     |type layout oldExt|
  1086     |type layout oldExt|
  1081 
  1087 
  1082     type := self class layoutType:aView.
  1088     type := self class layoutType:aView.
  1083 
  1089 
  1084     type notNil ifTrue:[
  1090     type notNil ifTrue:[
  1085         self undoLayoutView:aView.
  1091         self createUndoLayout:aView.
  1086 
  1092 
  1087         type == #Extent ifTrue:[
  1093         type == #Extent ifTrue:[
  1088             oldExt := aView extent.
  1094             oldExt := aView extent.
  1089             aView extent:(oldExt + ((r-l) @ (b-t))).
  1095             aView extent:(oldExt + ((r-l) @ (b-t))).
  1090             ^ self 
  1096             ^ self 
  1472     "
  1478     "
  1473     ^ self numberOfSelections ~~ 0
  1479     ^ self numberOfSelections ~~ 0
  1474 
  1480 
  1475 !
  1481 !
  1476 
  1482 
  1477 hasUndos
       
  1478     "returns true if undoHistory not empty
       
  1479     "
       
  1480     ^ undoHistory notEmpty
       
  1481 !
       
  1482 
       
  1483 isHorizontalResizable:aComponent
  1483 isHorizontalResizable:aComponent
  1484     "returns true if instance is horizontal resizeable
  1484     "returns true if instance is horizontal resizeable
  1485     "
  1485     "
  1486     ^ self subclassResponsibility
  1486     ^ self subclassResponsibility
  1487 
  1487 
  1488 
  1488 
  1489 !
  1489 !
  1490 
  1490 
       
  1491 isModified
       
  1492     "returns true if painter is modified
       
  1493     "
       
  1494   ^ undoHistory isModified
       
  1495 !
       
  1496 
  1491 isSelected:anObject
  1497 isSelected:anObject
  1492     "return true, if the argument, anObject is selected
  1498     "return true, if the argument, anObject is selected
  1493     "
  1499     "
  1494     anObject notNil ifTrue:[
  1500     anObject notNil ifTrue:[
  1495         self selectionDo:[:el| el == anObject ifTrue:[^ true]]
  1501         self selectionDo:[:el| el == anObject ifTrue:[^ true]]
  1513 
  1519 
  1514 
  1520 
  1515 ! !
  1521 ! !
  1516 
  1522 
  1517 !UIObjectView methodsFor:'transaction'!
  1523 !UIObjectView methodsFor:'transaction'!
       
  1524 
       
  1525 createUndoLayout:aView
       
  1526     "prepare undo action for a view changing its layout
       
  1527     "
       
  1528     self subclassResponsibility
       
  1529 
       
  1530 !
  1518 
  1531 
  1519 transaction:aType objects:something do:aOneArgBlock
  1532 transaction:aType objects:something do:aOneArgBlock
  1520     "opens a transaction and evaluates a block within the transaction; the
  1533     "opens a transaction and evaluates a block within the transaction; the
  1521      argument to the block is a view from derived from something
  1534      argument to the block is a view from derived from something
  1522     "
  1535     "
  1529     "opens a transaction and evaluates a block within the transaction; the
  1542     "opens a transaction and evaluates a block within the transaction; the
  1530      argument to the block is a view from the selection
  1543      argument to the block is a view from the selection
  1531     "
  1544     "
  1532     self transaction:aType objects:(self selection) do:aOneArgBlock
  1545     self transaction:aType objects:(self selection) do:aOneArgBlock
  1533 
  1546 
  1534 
       
  1535 !
       
  1536 
       
  1537 undoLayoutView:aView
       
  1538     "prepare undo action for a view changing its layout
       
  1539     "
       
  1540     self subclassResponsibility
       
  1541 
  1547 
  1542 ! !
  1548 ! !
  1543 
  1549 
  1544 !UIObjectView methodsFor:'user actions - arrange'!
  1550 !UIObjectView methodsFor:'user actions - arrange'!
  1545 
  1551 
  1598 
  1604 
  1599 pasteExtent
  1605 pasteExtent
  1600     "paste the copied extent to all objects in the selection
  1606     "paste the copied extent to all objects in the selection
  1601     "
  1607     "
  1602     copiedExtent notNil ifTrue:[
  1608     copiedExtent notNil ifTrue:[
  1603         self transition:#pasteExtent dimensionDo:[:v|
  1609         self transaction:#pasteExtent dimensionDo:[:v|
  1604             self resize:v corner:(v computeOrigin + copiedExtent)
  1610             self resize:v corner:(v computeOrigin + copiedExtent)
  1605         ]    
  1611         ]    
  1606     ]    
  1612     ]    
  1607 !
  1613 !
  1608 
  1614 
  1609 pasteHeight
  1615 pasteHeight
  1610     "paste the copied extent height to all objects in the selection
  1616     "paste the copied extent height to all objects in the selection
  1611     "
  1617     "
  1612     copiedExtent notNil ifTrue:[
  1618     copiedExtent notNil ifTrue:[
  1613         self transition:#pasteHeight dimensionDo:[:v|
  1619         self transaction:#pasteHeight dimensionDo:[:v|
  1614             self resize:v bottom:(v computeOrigin + copiedExtent)
  1620             self resize:v bottom:(v computeOrigin + copiedExtent)
  1615         ]    
  1621         ]    
  1616     ]    
  1622     ]    
  1617 
  1623 
  1618 !
  1624 !
  1619 
  1625 
  1620 pasteLayout
  1626 pasteLayout
  1621     "paste layout to all objects in the selection
  1627     "paste layout to all objects in the selection
  1622     "
  1628     "
  1623     copiedLayout notNil ifTrue:[
  1629     copiedLayout notNil ifTrue:[
  1624         self transition:#pasteLayout dimensionDo:[:v|
  1630         self transaction:#pasteLayout dimensionDo:[:v|
  1625             v geometryLayout:(copiedLayout copy)
  1631             v geometryLayout:(copiedLayout copy)
  1626         ]    
  1632         ]    
  1627     ]    
  1633     ]    
  1628 !
  1634 !
  1629 
  1635 
  1630 pasteWidth
  1636 pasteWidth
  1631     "paste the copied extent width to all objects in the selection
  1637     "paste the copied extent width to all objects in the selection
  1632     "
  1638     "
  1633     copiedExtent notNil ifTrue:[
  1639     copiedExtent notNil ifTrue:[
  1634         self transition:#pasteWidth dimensionDo:[:v|
  1640         self transaction:#pasteWidth dimensionDo:[:v|
  1635             self resize:v right:(v computeOrigin + copiedExtent)
  1641             self resize:v right:(v computeOrigin + copiedExtent)
  1636         ]    
  1642         ]    
  1637     ]    
  1643     ]    
  1638 
  1644 
  1639 !
  1645 !
  1640 
  1646 
  1641 setDimension:aLayout
  1647 setDimension:aLayout
  1642     "change layout for all selected objects
  1648     "change layout for all selected objects
  1643     "
  1649     "
  1644     self transition:#layout dimensionDo:[:v|
  1650     self transaction:#layout dimensionDo:[:v|
  1645         v geometryLayout:(aLayout copy)
  1651         v geometryLayout:(aLayout copy)
  1646     ].    
  1652     ].    
  1647 
  1653 
  1648 !
  1654 !
  1649 
  1655 
  1650 setExtent:anExtent
  1656 setExtent:anExtent
  1651     "change extent for all selected objects
  1657     "change extent for all selected objects
  1652     "
  1658     "
  1653     self transition:#extent dimensionDo:[:v|
  1659     self transaction:#extent dimensionDo:[:v|
  1654         v geometryLayout:nil.
  1660         v geometryLayout:nil.
  1655         v extent:anExtent.
  1661         v extent:anExtent.
  1656     ].
  1662     ].
  1657 
  1663 
  1658     "Modified: 28.2.1997 / 12:49:00 / cg"
  1664     "Modified: 28.2.1997 / 12:49:00 / cg"
  1659 !
  1665 !
  1660 
  1666 
  1661 setToDefaultExtent
  1667 setToDefaultExtent
  1662     "change extent of all selected views to their default extent
  1668     "change extent of all selected views to their default extent
  1663     "
  1669     "
  1664     self transition:#defaultExtent dimensionDo:[:v|
  1670     self transaction:#defaultExtent dimensionDo:[:v|
  1665         self resize:v corner:(v computeOrigin + (v preferredExtent))
  1671         self resize:v corner:(v computeOrigin + (v preferredExtent))
  1666     ]    
  1672     ]    
  1667 
  1673 
  1668 !
  1674 !
  1669 
  1675 
  1670 setToDefaultHeight
  1676 setToDefaultHeight
  1671     "change height of all selected views to their default height
  1677     "change height of all selected views to their default height
  1672     "
  1678     "
  1673     self transition:#defaultHeight dimensionDo:[:v|
  1679     self transaction:#defaultHeight dimensionDo:[:v|
  1674         self resize:v bottom:(v computeOrigin + (v preferredExtent))
  1680         self resize:v bottom:(v computeOrigin + (v preferredExtent))
  1675     ]    
  1681     ]    
  1676 
  1682 
  1677 !
  1683 !
  1678 
  1684 
  1679 setToDefaultWidth
  1685 setToDefaultWidth
  1680     "change width of all selected views to their default width
  1686     "change width of all selected views to their default width
  1681     "
  1687     "
  1682     self transition:#defaultWidth dimensionDo:[:v|
  1688     self transaction:#defaultWidth dimensionDo:[:v|
  1683         self resize:v right:(v computeOrigin + (v preferredExtent))
  1689         self resize:v right:(v computeOrigin + (v preferredExtent))
  1684     ]    
  1690     ]    
  1685 
  1691 
  1686 !
  1692 !
  1687 
  1693 
  1688 transition:aType dimensionDo:aOneArgBlock
  1694 transaction:aType dimensionDo:aOneArgBlock
  1689     "change dimension within a transaction for the selected elements by evaluating
  1695     "change dimension within a transaction for the selected elements by evaluating
  1690      the block with the argument a view.
  1696      the block with the argument a view.
  1691     "
  1697     "
  1692     self withSelectionHiddenDo:[
  1698     self withSelectionHiddenDo:[
  1693         self transaction:aType selectionDo:[:aView|
  1699         self transaction:aType selectionDo:[:aView|
  1694             (self class layoutType:aView) notNil ifTrue:[
  1700             (self class layoutType:aView) notNil ifTrue:[
  1695                 self undoLayoutView:aView.
  1701                 self createUndoLayout:aView.
  1696                 aOneArgBlock value:aView.
  1702                 aOneArgBlock value:aView.
  1697                 self elementChangedSize:aView.
  1703                 self elementChangedSize:aView.
  1698             ]
  1704             ]
  1699         ]
  1705         ]
  1700     ].
  1706     ].
  1950                 self transaction:#alignLeftRight selectionDo:[:aView|
  1956                 self transaction:#alignLeftRight selectionDo:[:aView|
  1951                     |layout|
  1957                     |layout|
  1952                     layout := self class asLayoutFrameFromView:aView.
  1958                     layout := self class asLayoutFrameFromView:aView.
  1953 
  1959 
  1954                     layout notNil ifTrue:[
  1960                     layout notNil ifTrue:[
  1955                         self undoLayoutView:aView.
  1961                         self createUndoLayout:aView.
  1956                         aView geometryLayout:layout.
  1962                         aView geometryLayout:layout.
  1957 
  1963 
  1958                         undoHistory disabledTransitionDo:[    
  1964                         undoHistory withoutTransactionDo:[    
  1959                             self shiftLayout:aView left:(lmost - (aView computeOrigin x))
  1965                             self shiftLayout:aView left:(lmost - (aView computeOrigin x))
  1960                                                   right:(rmost - (aView computeCorner x)).
  1966                                                   right:(rmost - (aView computeCorner x)).
  1961                         ].
  1967                         ].
  1962                         self elementChangedSize:aView
  1968                         self elementChangedSize:aView
  1963                     ]
  1969                     ]
  2046                 self transaction:#alignTopBottom selectionDo:[:aView|
  2052                 self transaction:#alignTopBottom selectionDo:[:aView|
  2047                     |layout|
  2053                     |layout|
  2048                     layout := self class asLayoutFrameFromView:aView.
  2054                     layout := self class asLayoutFrameFromView:aView.
  2049 
  2055 
  2050                     layout notNil ifTrue:[
  2056                     layout notNil ifTrue:[
  2051                         self undoLayoutView:aView.
  2057                         self createUndoLayout:aView.
  2052                         aView geometryLayout:layout.
  2058                         aView geometryLayout:layout.
  2053 
  2059 
  2054                         undoHistory disabledTransitionDo:[    
  2060                         undoHistory withoutTransactionDo:[    
  2055                             self shiftLayout:aView top:(tmost - (aView computeOrigin y))
  2061                             self shiftLayout:aView top:(tmost - (aView computeOrigin y))
  2056                                                 bottom:(bmost - (aView computeCorner y)).
  2062                                                 bottom:(bmost - (aView computeCorner y)).
  2057                         ].
  2063                         ].
  2058                         self elementChangedSize:aView
  2064                         self elementChangedSize:aView
  2059                     ]
  2065                     ]
  2147 
  2153 
  2148     self transaction:type selectionDo:[:aView|
  2154     self transaction:type selectionDo:[:aView|
  2149         layout := self class asLayoutFrameFromView:aView.
  2155         layout := self class asLayoutFrameFromView:aView.
  2150 
  2156 
  2151         layout notNil ifTrue:[
  2157         layout notNil ifTrue:[
  2152             self undoLayoutView:aView.
  2158             self createUndoLayout:aView.
  2153             aBlock value:layout.
  2159             aBlock value:layout.
  2154             aView geometryLayout:layout.
  2160             aView geometryLayout:layout.
  2155             self elementChangedSize:aView.
  2161             self elementChangedSize:aView.
  2156         ]
  2162         ]
  2157     ]
  2163     ]
  2251 !
  2257 !
  2252 
  2258 
  2253 openUndoMenu
  2259 openUndoMenu
  2254     "open undo menu
  2260     "open undo menu
  2255     "
  2261     "
  2256     self select:nil.
  2262     undoHistory isEmpty ifFalse:[
  2257 
  2263         self select:nil.
  2258     self withSelectionHiddenDo:[
  2264 
  2259         undoHistory openUndoMenu
  2265         self withSelectionHiddenDo:[
       
  2266             undoHistory openUndoMenu
       
  2267         ]
  2260     ].
  2268     ].
  2261 
  2269 
  2262 !
  2270 !
  2263 
  2271 
  2264 removeUndoHistory
  2272 removeUndoHistory
  2265     "delete total undo history
  2273     "delete total undo history
  2266     "
  2274     "
  2267     undoHistory reinitialize
  2275     undoHistory on:self
  2268 !
  2276 !
  2269 
  2277 
  2270 undoLast
  2278 undoLast
  2271     "undo last action
  2279     "undo last action
  2272     "
  2280     "
  2273     self select:nil.
  2281     undoHistory isEmpty ifFalse:[
  2274 
  2282         self select:nil.
  2275     self withSelectionHiddenDo:[
  2283 
  2276         undoHistory undoLast:1
  2284         self withSelectionHiddenDo:[
       
  2285             undoHistory undoLast:1
       
  2286         ]
  2277     ].
  2287     ].
  2278 
  2288 
  2279 ! !
  2289 ! !
  2280 
  2290 
  2281 !UIObjectView::UndoHistory class methodsFor:'constants'!
  2291 !UIObjectView::UndoHistory class methodsFor:'constants'!
  2282 
  2292 
  2283 maxHistorySize
  2293 maxHistorySize
  2284     "returns maximum size of history before removing oldest
  2294     "returns maximum size of history before removing oldest
  2285      record
  2295      record
  2286     "
  2296     "
  2287     ^ 50
  2297     ^ 100
  2288 
  2298 
  2289 
  2299 
  2290 ! !
  2300 ! !
  2291 
  2301 
  2292 !UIObjectView::UndoHistory class methodsFor:'documentation'!
  2302 !UIObjectView::UndoHistory class methodsFor:'documentation'!
  2305 
  2315 
  2306 ! !
  2316 ! !
  2307 
  2317 
  2308 !UIObjectView::UndoHistory class methodsFor:'instance creation'!
  2318 !UIObjectView::UndoHistory class methodsFor:'instance creation'!
  2309 
  2319 
  2310 new
  2320 on:aPainter
  2311     ^ self basicNew initialize
  2321     |history|
       
  2322 
       
  2323     history := self new.
       
  2324     history on:aPainter.
       
  2325   ^ history
  2312 
  2326 
  2313 
  2327 
  2314 ! !
  2328 ! !
  2315 
  2329 
  2316 !UIObjectView::UndoHistory methodsFor:'accessing'!
  2330 !UIObjectView::UndoHistory methodsFor:'accessing'!
       
  2331 
       
  2332 addUndoSelector:aSelector withArgs:anArray
       
  2333     "add a selector with arguments to the current opened transaction; in case that no
       
  2334      transaction is opened or disabled the block will not be kept in the history.
       
  2335     "
       
  2336     self isTransactionOpen ifTrue:[
       
  2337         transaction add:(Association key:aSelector value:anArray)
       
  2338     ]
       
  2339 
       
  2340 
       
  2341 ! !
       
  2342 
       
  2343 !UIObjectView::UndoHistory methodsFor:'accessing behavior'!
  2317 
  2344 
  2318 enabled
  2345 enabled
  2319     ^ enabled
  2346     ^ enabled
  2320 !
  2347 !
  2321 
  2348 
  2322 enabled:aState
  2349 enabled:aState
  2323     enabled := aState
  2350     enabled := aState
  2324 !
  2351 !
  2325 
  2352 
  2326 historySize
  2353 resetModification
  2327     ^ history size
  2354     "set modification state to false
  2328 !
  2355     "
  2329 
  2356     startIdentifier := identifier
  2330 lastTypeAsString
  2357 ! !
  2331     "returns type of last undo asString or nil
  2358 
  2332     "
  2359 !UIObjectView::UndoHistory methodsFor:'activation'!
  2333     history notEmpty ifTrue:[
  2360 
  2334         ^ history last typeAsString
  2361 withinTransaction:aType text:aTextOrNil do:aBlock
  2335     ].
  2362     "open a transaction; perform the block; at least close the transaction
  2336     ^ nil
  2363     "
  2337 
  2364     (enabled and:[transaction isNil]) ifTrue:[
  2338 
  2365         transaction := Transaction type:aType text:aTextOrNil.
       
  2366 
       
  2367         aBlock value.
       
  2368 
       
  2369         transaction isEmpty ifFalse:[
       
  2370             identifier := identifier + 1.
       
  2371             transaction identifier:identifier.
       
  2372             history addLast:transaction.
       
  2373             history size > (self class maxHistorySize) ifTrue:[history removeFirst]
       
  2374         ].
       
  2375         transaction := nil
       
  2376 
       
  2377     ] ifFalse:[
       
  2378         aBlock value
       
  2379     ]
       
  2380 !
       
  2381 
       
  2382 withoutTransactionDo:aNoneArgBlock
       
  2383     "evaluate the block without opening a transaction or keeping changes
       
  2384      within a still opened transaction
       
  2385     "
       
  2386     |oldState|
       
  2387 
       
  2388     oldState := enabled.
       
  2389     enabled  := false.
       
  2390     aNoneArgBlock value.
       
  2391     enabled  := oldState.
  2339 ! !
  2392 ! !
  2340 
  2393 
  2341 !UIObjectView::UndoHistory methodsFor:'initialization'!
  2394 !UIObjectView::UndoHistory methodsFor:'initialization'!
  2342 
  2395 
  2343 initialize
  2396 on:aPainter
  2344     super initialize.
  2397     "setup for a painter and delete all existing history records
  2345     self  reinitialize.
  2398     "
  2346 
  2399     identifier      := 0.
  2347 
  2400     startIdentifier := 0.
  2348 !
  2401 
  2349 
  2402     painter     := aPainter.
  2350 reinitialize
       
  2351     "reinitialize all attributes
       
  2352     "
       
  2353     history     := OrderedCollection new.
  2403     history     := OrderedCollection new.
  2354     transaction := nil.
  2404     transaction := nil.
  2355     enabled     := true.
  2405     enabled     := true.
  2356 
  2406 
  2357 
  2407 
  2411     ^ history isEmpty
  2461     ^ history isEmpty
  2412 
  2462 
  2413 
  2463 
  2414 !
  2464 !
  2415 
  2465 
       
  2466 isModified
       
  2467     "returns true if history is modified
       
  2468     "
       
  2469     self isEmpty ifTrue:[
       
  2470         ^ false
       
  2471     ].
       
  2472   ^ history last identifier ~~ startIdentifier
       
  2473 !
       
  2474 
  2416 isTransactionOpen
  2475 isTransactionOpen
  2417     ^ (enabled and:[transaction notNil])
  2476     ^ (enabled and:[transaction notNil])
  2418 !
       
  2419 
       
  2420 notEmpty
       
  2421     "returns true if undo history is not empty
       
  2422     "
       
  2423     ^ history notEmpty
       
  2424 
       
  2425 
       
  2426 ! !
       
  2427 
       
  2428 !UIObjectView::UndoHistory methodsFor:'transaction'!
       
  2429 
       
  2430 addUndoBlock:anUndoBlock
       
  2431     "undo block to restore changes; add block to current transaction
       
  2432     "
       
  2433     self isTransactionOpen ifTrue:[
       
  2434         transaction add:anUndoBlock
       
  2435     ]
       
  2436 
       
  2437 
       
  2438 !
       
  2439 
       
  2440 disabledTransitionDo:aBlock
       
  2441     "disable transitions during evaluating the block
       
  2442     "
       
  2443     |oldState|
       
  2444 
       
  2445     oldState := enabled.
       
  2446     enabled  := false.
       
  2447     aBlock value.
       
  2448     enabled  := oldState.
       
  2449 !
       
  2450 
       
  2451 transaction:aType do:aBlock
       
  2452     self transaction:aType text:nil do:aBlock
       
  2453 !
       
  2454 
       
  2455 transaction:aType text:aTextOrNil do:aBlock
       
  2456     "open a transaction; perform the block; at least close the transaction
       
  2457     "
       
  2458     (enabled and:[transaction isNil]) ifTrue:[
       
  2459         transaction := Transaction type:aType text:aTextOrNil.
       
  2460 
       
  2461         aBlock value.
       
  2462 
       
  2463         transaction isEmpty ifFalse:[
       
  2464             history addLast:transaction.
       
  2465             history size > (self class maxHistorySize) ifTrue:[history removeFirst]
       
  2466         ].
       
  2467         transaction := nil
       
  2468 
       
  2469     ] ifFalse:[
       
  2470         aBlock value
       
  2471     ]
       
  2472 ! !
  2477 ! !
  2473 
  2478 
  2474 !UIObjectView::UndoHistory methodsFor:'undo'!
  2479 !UIObjectView::UndoHistory methodsFor:'undo'!
  2475 
  2480 
  2476 undoLast:nTransactions
  2481 undoLast:nTransactions
  2477     "undo last n transactions; an open transaction will be closed;
  2482     "undo last n transactions; an open transaction will be closed;
  2478      transactions during undo are disabled
  2483      transactions during undo are disabled
  2479     "
  2484     "
  2480     |n|
  2485     |repeatTimes transaction actions|
  2481 
  2486 
  2482     transaction := nil.
  2487     transaction := nil.
  2483     n := nTransactions min:(history size).
  2488     enabled     := false.
  2484 
  2489     repeatTimes := nTransactions min:(history size).
  2485     n ~~ 0 ifTrue:[
  2490 
  2486         enabled := false.
  2491     repeatTimes timesRepeat:[
  2487         n timesRepeat:[ (history removeLast) undo ].
  2492         transaction := history removeLast.
  2488         enabled := true.
  2493         actions     := transaction actions.
  2489     ]
  2494 
  2490 
  2495         actions isCollection ifTrue:[
  2491 
  2496             actions reverseDo:[:aBlock|
       
  2497                 painter perform:(aBlock key) with:(aBlock value)
       
  2498             ]
       
  2499         ] ifFalse:[
       
  2500             painter perform:(actions key) with:(actions value)
       
  2501         ]
       
  2502     ].
       
  2503     enabled := true.
  2492 ! !
  2504 ! !
  2493 
  2505 
  2494 !UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'!
  2506 !UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'!
  2495 
  2507 
  2496 documentation
  2508 documentation
  2512 
  2524 
  2513 ! !
  2525 ! !
  2514 
  2526 
  2515 !UIObjectView::UndoHistory::Transaction methodsFor:'accessing'!
  2527 !UIObjectView::UndoHistory::Transaction methodsFor:'accessing'!
  2516 
  2528 
       
  2529 actions
       
  2530     "returns actions associated with transaction
       
  2531     "
       
  2532   ^ actions
       
  2533 !
       
  2534 
       
  2535 identifier
       
  2536     "gets my identifier
       
  2537     "
       
  2538   ^ identifier
       
  2539 !
       
  2540 
       
  2541 identifier:anIdentifier
       
  2542     "sets my identifier
       
  2543     "
       
  2544     identifier := anIdentifier
       
  2545 !
       
  2546 
  2517 text
  2547 text
  2518     "returns text or nil assigned to transition
  2548     "returns text or nil assigned to transaction
  2519     "
  2549     "
  2520     ^ text
  2550     ^ text
  2521 !
  2551 !
  2522 
  2552 
  2523 type
  2553 type
  2524     "returns type assigned to transition
  2554     "returns type assigned to transaction
  2525     "
  2555     "
  2526     ^ type
  2556     ^ type
  2527 !
  2557 !
  2528 
  2558 
  2529 type:aType
  2559 type:aType
  2530     "change type assigned to transition
  2560     "change type assigned to transaction
  2531     "
  2561     "
  2532     type := aType
  2562     type := aType
  2533 !
  2563 !
  2534 
  2564 
  2535 typeAsString
  2565 typeAsString
  2556         size := size + 1
  2586         size := size + 1
  2557     ].
  2587     ].
  2558     ^ name
  2588     ^ name
  2559 ! !
  2589 ! !
  2560 
  2590 
  2561 !UIObjectView::UndoHistory::Transaction methodsFor:'add & undo'!
  2591 !UIObjectView::UndoHistory::Transaction methodsFor:'adding'!
  2562 
  2592 
  2563 add:anUndoBlock
  2593 add:anUndoBlock
  2564     "add an undo action to the transition
  2594     "add an undo action to the current transaction
  2565     "
  2595     "
  2566     actions isNil ifTrue:[
  2596     actions isNil ifTrue:[
  2567         actions := anUndoBlock
  2597         actions := anUndoBlock
  2568     ] ifFalse:[
  2598     ] ifFalse:[
  2569         actions isCollection ifFalse:[
  2599         actions isCollection ifFalse:[
  2570             |temp|
  2600             actions := OrderedCollection with:actions
  2571 
       
  2572             temp := OrderedCollection new.
       
  2573             temp add:actions.
       
  2574             actions := temp.
       
  2575         ].
  2601         ].
  2576         actions add:anUndoBlock.
  2602         actions add:anUndoBlock.
  2577     ]
  2603     ]
  2578 !
       
  2579 
       
  2580 undo
       
  2581     "undo transition
       
  2582     "
       
  2583     actions notNil ifTrue:[
       
  2584         actions isCollection ifFalse:[
       
  2585             actions value
       
  2586         ] ifTrue:[
       
  2587             actions reverseDo:[:anUndoBlock| anUndoBlock value ]
       
  2588         ]
       
  2589     ]
       
  2590 ! !
  2604 ! !
  2591 
  2605 
  2592 !UIObjectView::UndoHistory::Transaction methodsFor:'initialization'!
  2606 !UIObjectView::UndoHistory::Transaction methodsFor:'initialization'!
  2593 
  2607 
  2594 type:aType text:aTextOrNil
  2608 type:aType text:aTextOrNil
  2595     "initialize transition
  2609     "initialize transaction
  2596     "
  2610     "
  2597     type := aType.
  2611     type := aType.
  2598     text := aTextOrNil.
  2612     text := aTextOrNil.
  2599 ! !
  2613 ! !
  2600 
  2614 
  2602 
  2616 
  2603 isEmpty
  2617 isEmpty
  2604     "returns true if no undo action is registered
  2618     "returns true if no undo action is registered
  2605     "
  2619     "
  2606     ^ actions isNil
  2620     ^ actions isNil
  2607 !
       
  2608 
       
  2609 notEmpty
       
  2610     "returns true if any undo action is registered
       
  2611     "
       
  2612     ^ actions notNil
       
  2613 ! !
  2621 ! !
  2614 
  2622 
  2615 !UIObjectView class methodsFor:'documentation'!
  2623 !UIObjectView class methodsFor:'documentation'!
  2616 
  2624 
  2617 version
  2625 version