1537 self resize:resizedObject right:aPoint. |
1544 self resize:resizedObject right:aPoint. |
1538 self resize:resizedObject top:aPoint. |
1545 self resize:resizedObject top:aPoint. |
1539 |
1546 |
1540 ! ! |
1547 ! ! |
1541 |
1548 |
|
1549 !UIObjectView::UndoHistory class methodsFor:'constants'! |
|
1550 |
|
1551 maxHistorySize |
|
1552 "returns maximum size of history before removing oldest |
|
1553 record |
|
1554 " |
|
1555 ^ 50 |
|
1556 |
|
1557 |
|
1558 ! ! |
|
1559 |
|
1560 !UIObjectView::UndoHistory class methodsFor:'instance creation'! |
|
1561 |
|
1562 new |
|
1563 ^ self basicNew initialize |
|
1564 |
|
1565 |
|
1566 ! ! |
|
1567 |
|
1568 !UIObjectView::UndoHistory methodsFor:'accessing'! |
|
1569 |
|
1570 modifiedAction:aBlockWithOneArg |
|
1571 "the block is evaluated whenever the history changed; the argument to the |
|
1572 block is the newest transaction identifier retrived from 'openTransaction' |
|
1573 " |
|
1574 modifiedAction := aBlockWithOneArg |
|
1575 |
|
1576 |
|
1577 ! ! |
|
1578 |
|
1579 !UIObjectView::UndoHistory methodsFor:'initialization'! |
|
1580 |
|
1581 initialize |
|
1582 super initialize. |
|
1583 self reinitialize. |
|
1584 |
|
1585 |
|
1586 ! |
|
1587 |
|
1588 reinitialize |
|
1589 "reinitialize all attributes |
|
1590 " |
|
1591 history := OrderedCollection new. |
|
1592 transaction := nil. |
|
1593 enabled := true. |
|
1594 |
|
1595 |
|
1596 ! ! |
|
1597 |
|
1598 !UIObjectView::UndoHistory methodsFor:'notifications'! |
|
1599 |
|
1600 modified |
|
1601 "raise notification; history changed |
|
1602 " |
|
1603 modifiedAction notNil ifTrue:[ |
|
1604 |what| |
|
1605 |
|
1606 history isEmpty ifTrue:[what := nil] |
|
1607 ifFalse:[what := history last first]. |
|
1608 |
|
1609 modifiedAction value:what |
|
1610 ] |
|
1611 |
|
1612 |
|
1613 ! ! |
|
1614 |
|
1615 !UIObjectView::UndoHistory methodsFor:'testing'! |
|
1616 |
|
1617 isEmpty |
|
1618 "returns true if undo history is empty |
|
1619 " |
|
1620 ^ history isEmpty |
|
1621 |
|
1622 |
|
1623 ! |
|
1624 |
|
1625 isTransactionOpen |
|
1626 ^ (enabled and:[transaction notNil]) |
|
1627 ! |
|
1628 |
|
1629 notEmpty |
|
1630 "returns true if undo history is not empty |
|
1631 " |
|
1632 ^ history notEmpty |
|
1633 |
|
1634 |
|
1635 ! ! |
|
1636 |
|
1637 !UIObjectView::UndoHistory methodsFor:'transaction'! |
|
1638 |
|
1639 addUndoBlock:anUndoBlock |
|
1640 "undo block to restore changes; add block to current transaction |
|
1641 " |
|
1642 enabled ifTrue:[ |
|
1643 transaction isNil ifTrue:[ |
|
1644 "no existing transaction |
|
1645 " |
|
1646 self halt |
|
1647 ] ifFalse:[ |
|
1648 (transaction at:2) add:anUndoBlock |
|
1649 ] |
|
1650 ] |
|
1651 |
|
1652 |
|
1653 ! |
|
1654 |
|
1655 closeTransaction |
|
1656 "close current transaction |
|
1657 " |
|
1658 self isTransactionOpen ifTrue:[ |
|
1659 transaction last isEmpty ifTrue:[ |
|
1660 "empty undo transaction |
|
1661 " |
|
1662 transaction := nil |
|
1663 ] ifFalse:[ |
|
1664 history addLast:transaction. |
|
1665 transaction := nil. |
|
1666 |
|
1667 history size > (self class maxHistorySize) ifTrue:[ |
|
1668 history removeFirst |
|
1669 ]. |
|
1670 self modified |
|
1671 ] |
|
1672 ] |
|
1673 |
|
1674 |
|
1675 ! |
|
1676 |
|
1677 disabledTransitionDo:aBlock |
|
1678 "disable transitions during evaluating the block |
|
1679 " |
|
1680 |oldState| |
|
1681 |
|
1682 oldState := enabled. |
|
1683 enabled := false. |
|
1684 aBlock value. |
|
1685 enabled := oldState. |
|
1686 ! |
|
1687 |
|
1688 openTransaction:what |
|
1689 "open a new transaction |
|
1690 " |
|
1691 enabled ifTrue:[ |
|
1692 transaction notNil ifTrue:[ |
|
1693 "transaction within transaction |
|
1694 " |
|
1695 self halt. |
|
1696 ] ifFalse:[ |
|
1697 transaction := Array with:what with:OrderedCollection new |
|
1698 ] |
|
1699 ] |
|
1700 |
|
1701 ! |
|
1702 |
|
1703 transactionNamed:what do:aBlock |
|
1704 "open a transaction; perform the block; at least close the transaction |
|
1705 " |
|
1706 self isTransactionOpen ifFalse:[ |
|
1707 self openTransaction:what. |
|
1708 aBlock value. |
|
1709 self closeTransaction |
|
1710 ] ifTrue:[ |
|
1711 aBlock value |
|
1712 ] |
|
1713 ! ! |
|
1714 |
|
1715 !UIObjectView::UndoHistory methodsFor:'undo'! |
|
1716 |
|
1717 undoLast |
|
1718 "undo last transactions; an open transaction will be closed; |
|
1719 transactions during undo are disabled |
|
1720 " |
|
1721 self undoLast:1 |
|
1722 |
|
1723 |
|
1724 ! |
|
1725 |
|
1726 undoLast:nTransactions |
|
1727 "undo last n transactions; an open transaction will be closed; |
|
1728 transactions during undo are disabled |
|
1729 " |
|
1730 |actions n| |
|
1731 |
|
1732 transaction := nil. |
|
1733 n := nTransactions min:(history size). |
|
1734 |
|
1735 n ~~ 0 ifTrue:[ |
|
1736 enabled := false. |
|
1737 |
|
1738 n timesRepeat:[ |
|
1739 actions := (history removeLast) last. |
|
1740 |
|
1741 actions reverseDo:[:aUndoBlock| |
|
1742 aUndoBlock value |
|
1743 ] |
|
1744 ]. |
|
1745 enabled := true. |
|
1746 self modified. |
|
1747 ] |
|
1748 |
|
1749 |
|
1750 ! ! |
|
1751 |
1542 !UIObjectView class methodsFor:'documentation'! |
1752 !UIObjectView class methodsFor:'documentation'! |
1543 |
1753 |
1544 version |
1754 version |
1545 ^ '$Header$' |
1755 ^ '$Header$' |
1546 ! ! |
1756 ! ! |