12 |
12 |
13 "{ Package: 'stx:libtool2' }" |
13 "{ Package: 'stx:libtool2' }" |
14 |
14 |
15 ResourceSpecEditor subclass:#MenuEditor |
15 ResourceSpecEditor subclass:#MenuEditor |
16 instanceVariableNames:'selectionHolder tabHolder listOfItems listOfTabs |
16 instanceVariableNames:'selectionHolder tabHolder listOfItems listOfTabs |
17 selectedSuperItems notifyDisabledCounter wizards listOfItemsView' |
17 selectedSuperItems notifyDisabledCounter wizards listOfItemsView |
|
18 dropOverLine' |
18 classVariableNames:'ImageRetrieverClasses' |
19 classVariableNames:'ImageRetrieverClasses' |
19 poolDictionaries:'' |
20 poolDictionaries:'' |
20 category:'Interface-UIPainter' |
21 category:'Interface-UIPainter' |
21 ! |
22 ! |
22 |
23 |
99 menus. |
100 menus. |
100 |
101 |
101 |
102 |
102 [Instance variables:] |
103 [Instance variables:] |
103 |
104 |
104 selectionHolder <ValueHolder> collection of current selected items |
105 listOfItemsView <HierarcicalListView> the view which shows the list of items |
105 tabHolder <ValueHolder> selected tab label holder |
106 listOfItems <HierarchicalList> hierarchical list of menu items |
106 listOfItems <HierarchicalList> hierarchical list of menu items |
107 listOfTabs <List> list of current shown tab-labels |
107 listOfTabs <List> list of current shown tab-labels |
108 |
108 wizards <IdentityDictionary> keeps all created wizard dialogs |
109 selectionHolder <ValueHolder> collection of current selected items |
109 selectedSuperItems <Collection> collection of superItems derived from selection |
110 selectedSuperItems <Collection> collection of superItems derived from selection |
110 notifyDisabledCounter <SmallInteger> ~~ 0 than change notifications are discard |
111 |
111 |
112 tabHolder <ValueHolder> selected tab label holder |
|
113 notifyDisabledCounter <SmallInteger> ~~ 0 than change notifications are discard |
|
114 wizards <IdentityDictionary> keeps all created wizard dialogs |
|
115 |
|
116 dropOverLine <nil or SmallInteger> nil: drop context not dropabel. |
|
117 = 0: drop context dropable but no item specified |
|
118 ~ 0: drop context dropable for item at lineNumber |
|
119 used t6o restore drop indication drawings |
|
120 |
112 [Class variables:] |
121 [Class variables:] |
113 ImageRetrieverClasses <Collection> sorted collection of image receivers |
122 ImageRetrieverClasses <Collection> sorted collection of image receivers |
114 |
123 |
115 [start with:] |
124 [start with:] |
116 MenuEditor open |
125 MenuEditor open |
117 MenuEditor openOnClass:MenuEditor andSelector:#menu |
126 MenuEditor openOnClass:MenuEditor andSelector:#menu |
118 |
127 |
119 [author:] |
128 [author:] |
120 Claus Atzkern, eXept Software AG |
129 Claus Atzkern, eXept Software AG |
121 Thomas Zwick, eXept Software AG |
130 Thomas Zwick, eXept Software AG |
122 " |
131 " |
123 ! ! |
132 ! ! |
124 |
133 |
125 !MenuEditor class methodsFor:'initialization'! |
134 !MenuEditor class methodsFor:'initialization'! |
126 |
135 |
459 #selectConditionSelector: #canSelect: |
468 #selectConditionSelector: #canSelect: |
460 #showLeftIndicators: false |
469 #showLeftIndicators: false |
461 #indicatorSelector: #indicatorClickedAt: |
470 #indicatorSelector: #indicatorClickedAt: |
462 #properties: |
471 #properties: |
463 #(#PropertyListDictionary |
472 #(#PropertyListDictionary |
|
473 #enterSelector: #dropEnter: |
464 #dragArgument: nil |
474 #dragArgument: nil |
465 #dropObjectSelector: #dropObjects |
475 #dropObjectSelector: #dropObjects |
466 #dropArgument: nil |
476 #dropArgument: nil |
467 #canDropSelector: #canDrop: |
477 #canDropSelector: #canDrop: |
|
478 #leaveSelector: #dropLeave: |
|
479 #overSelector: #dropOver: |
468 #dropSelector: #doDrop: |
480 #dropSelector: #doDrop: |
469 ) |
481 ) |
470 #postBuildCallback: #postBuildListOfItemsView: |
482 #postBuildCallback: #postBuildListOfItemsView: |
471 ) |
483 ) |
472 #(#ViewSpec |
484 #(#ViewSpec |
1740 ! ! |
1752 ! ! |
1741 |
1753 |
1742 !MenuEditor methodsFor:'drag & drop'! |
1754 !MenuEditor methodsFor:'drag & drop'! |
1743 |
1755 |
1744 canDrop:aContext |
1756 canDrop:aContext |
1745 "return true, if the DropContext can be dropped into |
1757 "return true, if the DropContext can be dropped into the list of items. |
1746 the hierachical list of items |
1758 The dropable objects are already validated by: #dropEnter: |
1747 " |
1759 " |
1748 |objects modified| |
1760 ^ (dropOverLine notNil and:[dropOverLine ~~ 0]) |
1749 |
1761 ! |
1750 modified := self valueOfEnablingCommitButtons value. |
1762 |
1751 modified ifTrue:[^ false]. |
1763 changeDropLineTo:aLineOrNil in:aContext |
1752 |
1764 "the over dropLine changed; redraw drop indication stuff |
1753 self selectedItem ifNil:[^ false]. |
1765 " |
1754 |
1766 |x0 x1 y0| |
1755 aContext sourceWidget == aContext targetWidget ifTrue:[ |
1767 |
1756 ^ false |
1768 aLineOrNil == dropOverLine ifTrue:[ |
1757 ]. |
1769 ^ self. "/ nothing changed |
1758 |
1770 ]. |
|
1771 x0 := listOfItemsView margin + 2. |
|
1772 x1 := listOfItemsView width - x0. |
|
1773 |
|
1774 "/ inform the DragAndDrop handler that the draw contents will change |
|
1775 aContext contentsWillChange. |
|
1776 |
|
1777 (dropOverLine notNil and:[dropOverLine ~~ 0]) ifTrue:[ |
|
1778 "/ restore old draw |
|
1779 y0 := listOfItemsView yVisibleOfLine:(dropOverLine + 1). |
|
1780 y0 := y0 - 3. |
|
1781 |
|
1782 listOfItemsView invalidate:(Rectangle left:x0 top:y0 width:(x1-x0+1) height:2) |
|
1783 repairNow:true. |
|
1784 ]. |
|
1785 |
|
1786 dropOverLine := aLineOrNil. |
|
1787 |
|
1788 (dropOverLine notNil and:[dropOverLine ~~ 0]) ifTrue:[ |
|
1789 "/ highlight new drop target |
|
1790 y0 := listOfItemsView yVisibleOfLine:(dropOverLine + 1). |
|
1791 y0 := y0 - 3. |
|
1792 |
|
1793 listOfItemsView paint:(Color white). |
|
1794 listOfItemsView displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
1795 y0 := y0 + 1. |
|
1796 listOfItemsView paint:(Color black). |
|
1797 listOfItemsView displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
1798 ]. |
|
1799 ! |
|
1800 |
|
1801 doDrop:aContext |
|
1802 "drop the DropContext into the hierachical list of items |
|
1803 " |
|
1804 |done item| |
|
1805 |
|
1806 dropOverLine ifNil:[^ false ]. "/ context not valid to me ... |
|
1807 |
|
1808 item := listOfItems at:dropOverLine ifAbsent:nil. |
|
1809 self dropLeave:aContext. |
|
1810 item ifNil:[^ false]. |
|
1811 |
|
1812 selectionHolder setValue:(Array with:item). |
|
1813 |
|
1814 done := false. |
|
1815 |
|
1816 self addAndSelect:[ |
|
1817 done := true. |
|
1818 aContext dropObjects collect:[:el| Item menuItem:(el theObject) ] |
|
1819 ]. |
|
1820 ^ done |
|
1821 ! |
|
1822 |
|
1823 dropEnter:aContext |
|
1824 "a drop operation enters my widget; validate dropable objects. |
|
1825 If the objects are not dropable, dropOverLine is set to nil, |
|
1826 otherwise to 0 (can drop the contents but not). |
|
1827 " |
|
1828 |objects| |
|
1829 |
|
1830 dropOverLine := nil. |
|
1831 |
|
1832 self valueOfEnablingCommitButtons value ifTrue:[ |
|
1833 "/ current editing spec is modified (couldn't accept operation) |
|
1834 ^ self |
|
1835 ]. |
1759 objects := aContext dropObjects. |
1836 objects := aContext dropObjects. |
1760 objects isEmpty ifTrue:[ ^ false ]. |
1837 objects isEmpty ifTrue:[ ^ self ]. "/ nothing to drop ??? |
1761 |
1838 |
|
1839 "/ test whether all objects are dropable (kind of MenuItem) |
1762 objects do:[:el| |
1840 objects do:[:el| |
1763 el theObject class == MenuItem ifFalse:[^ false]. |
1841 el theObject class == MenuItem ifFalse:[ |
1764 ]. |
1842 "/ contains none-dropable objects |
1765 ^ true |
1843 ^ self |
1766 ! |
1844 ]. |
1767 |
1845 ]. |
1768 doDrop:aDropContext |
1846 |
1769 "drop the DropContext into the hierachical list of items |
1847 "/ ok, the contents is dropable |
1770 " |
1848 dropOverLine := 0. |
1771 |objects| |
1849 ! |
1772 |
1850 |
1773 (self canDrop:aDropContext) ifFalse:[^ false]. |
1851 dropLeave:aContext |
1774 |
1852 "the widget is leaved; restore drop indications drawn ... |
1775 objects := aDropContext dropObjects collect:[:el| el theObject ]. |
1853 " |
1776 self doPaste:objects. |
1854 self changeDropLineTo:nil in:aContext. |
1777 ^ true |
|
1778 ! |
1855 ! |
1779 |
1856 |
1780 dropObjects |
1857 dropObjects |
1781 "returns list of DropObjects |
1858 "returns list of DropObjects |
1782 " |
1859 " |
1788 ^ items collect:[:el| |
1865 ^ items collect:[:el| |
1789 obj := DropObject new:(el menuItem). |
1866 obj := DropObject new:(el menuItem). |
1790 obj displayObject:(el rawLabel). |
1867 obj displayObject:(el rawLabel). |
1791 obj |
1868 obj |
1792 ]. |
1869 ]. |
|
1870 ! |
|
1871 |
|
1872 dropOver:aContext |
|
1873 "called during drag & drop over the widget |
|
1874 compute new drop target source |
|
1875 " |
|
1876 |lnNr item| |
|
1877 |
|
1878 dropOverLine ifNil:[^ self ]. "/ context not valid to me ... |
|
1879 |
|
1880 lnNr := listOfItemsView yVisibleToLineNr:(aContext targetPoint y). |
|
1881 item := nil. |
|
1882 |
|
1883 lnNr ifNotNil:[ |
|
1884 item := listOfItems at:lnNr ifAbsent:nil. |
|
1885 item ifNotNil:[ |
|
1886 (item isAction and:[item hasDelayedMenu]) ifTrue:[ |
|
1887 item := nil |
|
1888 ] |
|
1889 ] |
|
1890 ]. |
|
1891 item ifNil:[ lnNr := 0 ]. "/ not dropable for item |
|
1892 |
|
1893 "/ redraw drop indication |
|
1894 self changeDropLineTo:lnNr in:aContext. |
1793 ! ! |
1895 ! ! |
1794 |
1896 |
1795 !MenuEditor methodsFor:'event processing'! |
1897 !MenuEditor methodsFor:'event processing'! |
1796 |
1898 |
1797 processEvent:anEvent |
1899 processEvent:anEvent |
1893 |
1995 |
1894 self askForItemModification ifFalse:[ ^ nil ]. |
1996 self askForItemModification ifFalse:[ ^ nil ]. |
1895 |
1997 |
1896 index := 1. |
1998 index := 1. |
1897 |
1999 |
1898 ( intoItem canAddChildren |
2000 (intoItem canAddChildren and:[intoItem isExpanded]) ifFalse:[ |
1899 and:[(intoItem isExpanded or:[intoItem isDelayedMenu]) ] |
2001 [ intoItem parent canAddChildren ] whileFalse:[ |
1900 ) ifFalse:[ |
2002 intoItem := intoItem parent. |
1901 [ intoItem parent canAddChildren ] whileFalse:[ |
2003 ]. |
1902 intoItem := intoItem parent. |
2004 index := intoItem parent identityIndexOf:intoItem. |
1903 ]. |
2005 index := index + 1. |
1904 index := intoItem parent identityIndexOf:intoItem. |
2006 intoItem := intoItem parent. |
1905 index := index + 1. |
|
1906 intoItem := intoItem parent. |
|
1907 ]. |
2007 ]. |
1908 newItem := aNoneArgBlockOrItem value. |
2008 newItem := aNoneArgBlockOrItem value. |
1909 |
2009 |
1910 newItem ifNotNil:[ |
2010 newItem ifNotNil:[ |
1911 selectionHolder setValue:nil. |
2011 selectionHolder setValue:nil. |
1912 intoItem expand. |
2012 intoItem expand. |
1913 |
2013 |
1914 newItem isCollection ifTrue:[ |
2014 newItem isCollection ifTrue:[ |
1915 intoItem addAll:newItem beforeIndex:index. |
2015 intoItem addAll:newItem beforeIndex:index. |
1916 selectionHolder value:newItem. |
2016 selectionHolder value:newItem. |
1917 ] ifFalse:[ |
2017 ] ifFalse:[ |
1918 intoItem add:newItem beforeIndex:index. |
2018 intoItem add:newItem beforeIndex:index. |
1919 selectionHolder value:(Array with:newItem). |
2019 selectionHolder value:(Array with:newItem). |
1920 ]. |
2020 ]. |
1921 modified := true. |
2021 modified := true. |
1922 ]. |
2022 ]. |
1923 ^ newItem |
2023 ^ newItem |
1924 ! |
2024 ! |
1925 |
2025 |
1926 clearModified |
2026 clearModified |