2699 |
2703 |
2700 treeView selectedNodeChangeSequenceOrder:-1. |
2704 treeView selectedNodeChangeSequenceOrder:-1. |
2701 modified := true. |
2705 modified := true. |
2702 ! ! |
2706 ! ! |
2703 |
2707 |
|
2708 !MenuEditor::TreeView class methodsFor:'documentation'! |
|
2709 |
|
2710 documentation |
|
2711 " |
|
2712 This tree view class provides a hierarchical representation |
|
2713 of the components of a menu. |
|
2714 |
|
2715 [see also:] |
|
2716 SelectionInTreeView |
|
2717 SelectionInTree |
|
2718 TreeItem |
|
2719 |
|
2720 [author:] |
|
2721 Claus Atzkern |
|
2722 " |
|
2723 ! ! |
|
2724 |
|
2725 !MenuEditor::TreeView methodsFor:'accessing'! |
|
2726 |
|
2727 canTab |
|
2728 ^ true |
|
2729 ! |
|
2730 |
|
2731 selectorName |
|
2732 "get the selector of the menu spec" |
|
2733 |
|
2734 ^(listOfNodes first contents label) asSymbol |
|
2735 ! |
|
2736 |
|
2737 selectorName: aSymbol |
|
2738 "set the selector for the menu spec" |
|
2739 |
|
2740 listOfNodes first contents label: aSymbol |
|
2741 ! ! |
|
2742 |
|
2743 !MenuEditor::TreeView methodsFor:'building'! |
|
2744 |
|
2745 buildFromClass:aClass andSelector:aSelector |
|
2746 "read a menu spec from aClass and aSelector and put |
|
2747 the encoded menu into the tree view" |
|
2748 |
|
2749 |spec cls menu firstNode firstNodeLabel| |
|
2750 |
|
2751 "if opened on a menu" |
|
2752 (aClass isNil and: [aSelector isNil and: [listOfNodes size > 0]]) ifTrue: [^nil]. |
|
2753 |
|
2754 self selection:nil. |
|
2755 |
|
2756 (aClass notNil and:[aSelector notNil]) ifTrue:[ |
|
2757 cls := self application resolveName:aClass. |
|
2758 |
|
2759 (cls respondsTo:aSelector) ifTrue:[ |
|
2760 spec := cls perform:aSelector |
|
2761 ] |
|
2762 ]. |
|
2763 |
|
2764 spec isNil ifFalse:[ |
|
2765 (spec isMemberOf:Menu) ifFalse:[ |
|
2766 menu := Menu new fromLiteralArrayEncoding:spec. |
|
2767 ] ifTrue:[ |
|
2768 menu := spec. |
|
2769 ]. |
|
2770 firstNode := self nodeLabel:(aSelector asString). |
|
2771 self subMenu:menu parent:firstNode. |
|
2772 ] ifTrue:[ |
|
2773 (aClass notNil and: [aSelector isNil and: [listOfNodes size > 0]]) |
|
2774 ifTrue: |
|
2775 [ |
|
2776 firstNode := listOfNodes first |
|
2777 ] |
|
2778 ifFalse: |
|
2779 [ |
|
2780 aSelector notNil ifTrue:[firstNodeLabel := aSelector asString] |
|
2781 ifFalse:[firstNodeLabel := 'menu']. |
|
2782 firstNode := self nodeLabel:firstNodeLabel. |
|
2783 ] |
|
2784 ]. |
|
2785 |
|
2786 firstNode expand. |
|
2787 model root: firstNode. |
|
2788 |
|
2789 firstNode hasChildren ifFalse:[ |
|
2790 model add:(self nodeLabel:'Item 1') below:firstNode |
|
2791 ]. |
|
2792 |
|
2793 |
|
2794 ! |
|
2795 |
|
2796 buildFromMenu:aMenu |
|
2797 "put aMenu into the tree view" |
|
2798 |
|
2799 |node| |
|
2800 |
|
2801 self selection:nil. |
|
2802 |
|
2803 node := self nodeLabel:'menu'. |
|
2804 self subMenu:aMenu parent:node. |
|
2805 |
|
2806 node hasChildren ifFalse:[ |
|
2807 node add:(self nodeLabel:'Item 1') |
|
2808 ]. |
|
2809 node expand. |
|
2810 model root:node. |
|
2811 ! |
|
2812 |
|
2813 menuItem:anItem |
|
2814 |
|
2815 |node| |
|
2816 |
|
2817 node := self nodeLabel: anItem label. |
|
2818 node contents buildFromMenuItem:anItem. |
|
2819 self subMenu: anItem submenu parent:node. |
|
2820 ^node. |
|
2821 |
|
2822 |
|
2823 ! |
|
2824 |
|
2825 subMenu:aMenu parent:aParent |
|
2826 |
|
2827 |idx grp| |
|
2828 |
|
2829 aMenu isNil ifFalse:[ |
|
2830 grp := aMenu groupSizes. |
|
2831 aMenu itemsDo:[:i| aParent add:(self menuItem:i)]. |
|
2832 |
|
2833 grp notNil ifTrue:[ |
|
2834 idx := 0. |
|
2835 |
|
2836 grp do:[:i| |
|
2837 idx := idx + i + 1. |
|
2838 aParent add:(self nodeLabel:nil) beforeIndex:idx. |
|
2839 ] |
|
2840 ] |
|
2841 ] |
|
2842 ! ! |
|
2843 |
|
2844 !MenuEditor::TreeView methodsFor:'conversion'! |
|
2845 |
|
2846 asMenu |
|
2847 |menu root| |
|
2848 |
|
2849 root := self root. |
|
2850 |
|
2851 root hasChildren ifTrue:[ |
|
2852 menu := Menu new. |
|
2853 root children do:[:aChild| menu addItem:(self asMenuItem:aChild)]. |
|
2854 ]. |
|
2855 ^ menu |
|
2856 ! |
|
2857 |
|
2858 asMenuItem:aNode |
|
2859 |
|
2860 |menu item| |
|
2861 |
|
2862 item := aNode contents asMenuItem. |
|
2863 |
|
2864 aNode hasChildren ifTrue:[ |
|
2865 menu := Menu new. |
|
2866 aNode children do:[:aChild| menu addItem:(self asMenuItem:aChild)]. |
|
2867 item submenu:menu |
|
2868 ]. |
|
2869 ^ item |
|
2870 |
|
2871 ! ! |
|
2872 |
|
2873 !MenuEditor::TreeView methodsFor:'drawing basics'! |
|
2874 |
|
2875 redrawLabelAt:x y:yTop index:anIndex |
|
2876 "draw text label assigned to a node at x y( center)" |
|
2877 |
|
2878 |isSelected y0 x0 x1 w type item| |
|
2879 |
|
2880 item := (listOfNodes at:anIndex) contents. |
|
2881 type := item separatorType. |
|
2882 |
|
2883 type isNil ifTrue:[ |
|
2884 ^ super redrawLabelAt:x y:yTop index:anIndex |
|
2885 ]. |
|
2886 isSelected := self isInSelection:anIndex. |
|
2887 x0 := x. |
|
2888 |
|
2889 highlightMode == #label ifTrue:[ |
|
2890 x0 := x + 4. |
|
2891 |
|
2892 isSelected ifTrue:[ |
|
2893 w := 80 + 8. |
|
2894 self paint:hilightBgColor. |
|
2895 self fillRectangleX:x y:yTop width:w height:fontHeight. |
|
2896 ] |
|
2897 ] ifFalse:[ |
|
2898 w := 0. |
|
2899 ]. |
|
2900 type == #blank ifFalse:[ |
|
2901 isSelected ifTrue:[self paint:hilightFgColor] |
|
2902 ifFalse:[self paint:fgColor]. |
|
2903 |
|
2904 x1 := x0 + 80. |
|
2905 y0 := yTop - 1 + (fontHeight // 2). |
|
2906 self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
2907 |
|
2908 type == #double ifTrue:[ |
|
2909 y0 := y0 + 2. |
|
2910 self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
2911 ] |
|
2912 ]. |
|
2913 |
|
2914 (isSelected and:[highlightMode == #label]) ifTrue:[ |
|
2915 self redrawSelFrameAtX:x y:yTop toX:(x + w) |
|
2916 ]. |
|
2917 |
|
2918 ! ! |
|
2919 |
|
2920 !MenuEditor::TreeView methodsFor:'event handling'! |
|
2921 |
|
2922 keyPress:key x:x y:y |
|
2923 "invoked if any key was pressed" |
|
2924 |
|
2925 <resource: #keyboard (#Delete #BackSpace #Cut #Copy #Paste)> |
|
2926 |
|
2927 (key == #Delete or:[key == #BackSpace]) ifTrue: [^self doDelete]. |
|
2928 key == #Cut ifTrue:[^self doCut]. |
|
2929 key == #Copy ifTrue:[^self doCopy]. |
|
2930 key == #Paste ifTrue:[^self doPaste]. |
|
2931 |
|
2932 super keyPress:key x:x y:y |
|
2933 |
|
2934 ! ! |
|
2935 |
|
2936 !MenuEditor::TreeView methodsFor:'initialization'! |
|
2937 |
|
2938 initialize |
|
2939 "initialize the tree view of the menu components" |
|
2940 |
|
2941 super initialize. |
|
2942 |
|
2943 self multipleSelectOk:true. |
|
2944 self showDirectoryIndicator: true. |
|
2945 self showDirectoryIndicatorForRoot: false. |
|
2946 self selectConditionBlock: [:i|self application askForItemModification]. |
|
2947 self validateDoubleClickBlock: [:node| node ~~ listOfNodes first]. |
|
2948 self model iconAction: [:aNode| aNode contents iconFor: aNode]. |
|
2949 self model labelAction: [:aNode| aNode contents treeViewLabel] |
|
2950 ! ! |
|
2951 |
|
2952 !MenuEditor::TreeView methodsFor:'menus'! |
|
2953 |
|
2954 XXdoDeleteSelectionBuffered:aBool |
|
2955 |appl idx| |
|
2956 |
|
2957 appl := self topView application. |
|
2958 |
|
2959 (appl hasValidSelection value and: [self askForItemModification]) ifFalse:[ |
|
2960 ^ self |
|
2961 ]. |
|
2962 aBool ifTrue:[ |
|
2963 self doCopy |
|
2964 ]. |
|
2965 |
|
2966 idx := 10000. |
|
2967 self selection do:[:aNumber| idx := idx min:aNumber ]. |
|
2968 |
|
2969 self selectedNodesRemove. |
|
2970 self selection:(idx min:(self list size)). |
|
2971 self setModified. |
|
2972 |
|
2973 aBool ifTrue:[ |
|
2974 "/ must update copy&paste indication |
|
2975 appl updateAllToolInstances. |
|
2976 ] |
|
2977 ! |
|
2978 |
|
2979 doCopy |
|
2980 |clip| |
|
2981 |
|
2982 self hasSelection ifTrue:[ |
|
2983 self application clipboard:(clip := OrderedCollection new). |
|
2984 self selectionDo:[:i | clip add:((listOfNodes at:i) copy)]. |
|
2985 self topView application updateAllToolInstances. |
|
2986 ] |
|
2987 ! |
|
2988 |
|
2989 doCreateItem |
|
2990 |
|
2991 self addElement: (self nodeLabel:'Item') |
|
2992 ! |
|
2993 |
|
2994 doCreateLink |
|
2995 |
|
2996 |node item| |
|
2997 |
|
2998 node := self nodeLabel:'Submenu Link'. |
|
2999 item := node contents. |
|
3000 item submenuChannel:#menuDefaultLink. |
|
3001 self addElement:node. |
|
3002 self setModified. |
|
3003 |
|
3004 |
|
3005 ! |
|
3006 |
|
3007 doCreateMenu |
|
3008 |
|
3009 |node| |
|
3010 node := self nodeLabel:'Submenu'. |
|
3011 node parent: self selectedNode. |
|
3012 node add:(self nodeLabel:'Item 1'). |
|
3013 self addElement:node |
|
3014 ! |
|
3015 |
|
3016 doCreateSep |
|
3017 |
|
3018 self addElement:(self nodeLabel:nil) |
|
3019 ! |
|
3020 |
|
3021 doCreateStandardEditMenu |
|
3022 |
|
3023 |node| |
|
3024 node := self nodeLabel:'Edit'. |
|
3025 node parent: self selectedNode. |
|
3026 node add:(self nodeLabel:'Copy' selector:#copySelection). |
|
3027 node add:(self nodeLabel:'Cut' selector:#cutSelection). |
|
3028 node add:(self nodeLabel:'Paste' selector:#paste). |
|
3029 self addElement:node |
|
3030 |
|
3031 "Created: / 23.8.1998 / 15:52:16 / cg" |
|
3032 "Modified: / 23.8.1998 / 15:59:36 / cg" |
|
3033 ! |
|
3034 |
|
3035 doCreateStandardFileMenu |
|
3036 |
|
3037 |node| |
|
3038 node := self nodeLabel:'File'. |
|
3039 node parent: self selectedNode. |
|
3040 node add:(self nodeLabel:'New' selector:#menuNew). |
|
3041 node add:(self nodeLabel:'-' ). |
|
3042 node add:(self nodeLabel:'Open...' selector:#menuOpen). |
|
3043 node add:(self nodeLabel:'-' ). |
|
3044 node add:(self nodeLabel:'Save' selector:#menuSave). |
|
3045 node add:(self nodeLabel:'Save As...' selector:#menuSaveAs). |
|
3046 node add:(self nodeLabel:'-' ). |
|
3047 node add:(self nodeLabel:'Exit' selector:#closeRequest). |
|
3048 self addElement:node |
|
3049 |
|
3050 "Created: / 23.8.1998 / 15:51:55 / cg" |
|
3051 "Modified: / 23.8.1998 / 16:04:24 / cg" |
|
3052 ! |
|
3053 |
|
3054 doCreateStandardHelpMenu |
|
3055 |
|
3056 |node| |
|
3057 node := self nodeLabel:'Help'. |
|
3058 node parent: self selectedNode. |
|
3059 node contents startGroup:#right. |
|
3060 node add:(self nodeLabel:'Documentation' selector:#openDocumentation). |
|
3061 node add:(self nodeLabel:'-'). |
|
3062 node add:(self nodeLabel:'About this Application' selector:#openAboutThisApplication). |
|
3063 self addElement:node |
|
3064 |
|
3065 "Created: / 23.8.1998 / 15:52:46 / cg" |
|
3066 "Modified: / 23.8.1998 / 17:30:12 / cg" |
|
3067 ! |
|
3068 |
|
3069 doCut |
|
3070 ^ self doDeleteSelectionBuffered:true |
|
3071 ! |
|
3072 |
|
3073 doDelete |
|
3074 ^ self doDeleteSelectionBuffered:false |
|
3075 ! |
|
3076 |
|
3077 doDeleteSelectionBuffered:aBool |
|
3078 |appl nsel list item prnt| |
|
3079 |
|
3080 appl := self topView application. |
|
3081 |
|
3082 (appl hasValidSelection value and: [self askForItemModification]) ifFalse:[ |
|
3083 ^ self |
|
3084 ]. |
|
3085 aBool ifTrue:[ |
|
3086 self doCopy |
|
3087 ]. |
|
3088 list := self list. |
|
3089 nsel := list size. |
|
3090 self selection do:[:aNumber| nsel := nsel min:aNumber ]. |
|
3091 |
|
3092 ( (item := list at:nsel ifAbsent:nil) notNil |
|
3093 and:[(prnt := item parent) notNil |
|
3094 and:[prnt children last == item]] |
|
3095 ) ifTrue:[ |
|
3096 nsel := nsel - 1 |
|
3097 ]. |
|
3098 |
|
3099 self selectedNodesRemove. |
|
3100 self selection:(nsel min:(list size)). |
|
3101 self setModified. |
|
3102 |
|
3103 aBool ifTrue:[ |
|
3104 "/ must update copy&paste indication |
|
3105 appl updateAllToolInstances. |
|
3106 ] |
|
3107 ! |
|
3108 |
|
3109 doPaste |
|
3110 |clip| |
|
3111 |
|
3112 clip := self application clipboard. |
|
3113 (clip notNil and:[self selectedNode notNil]) ifTrue:[ |
|
3114 self addElement:(clip collect:[:el| el copy]) |
|
3115 ]. |
|
3116 ! ! |
|
3117 |
|
3118 !MenuEditor::TreeView methodsFor:'private'! |
|
3119 |
|
3120 addElement: aNode |
|
3121 "add something after selection" |
|
3122 |
|
3123 |label sel| |
|
3124 |
|
3125 self askForItemModification ifTrue:[ |
|
3126 self selectedNodeAdd:aNode. |
|
3127 (aNode isCollection not |
|
3128 and: [aNode name = 'Item']) |
|
3129 ifTrue:[ |
|
3130 sel := self selectedNode. |
|
3131 label := aNode name , ' ', |
|
3132 (sel parent notNil |
|
3133 ifTrue: |
|
3134 [ |
|
3135 (((sel children size = 0 |
|
3136 ifTrue: [sel parent children] |
|
3137 ifFalse: [sel children]) |
|
3138 select:[:node| |
|
3139 |lab| |
|
3140 lab := node contents label. |
|
3141 ((node children size = 0) & |
|
3142 node contents submenuChannel isNil & |
|
3143 (lab ~= '-') & (lab ~= '=') & (lab ~= '')) |
|
3144 ]) size) printString |
|
3145 ] |
|
3146 ifFalse: ['1']). |
|
3147 |
|
3148 aNode name: label string asBoldText. |
|
3149 aNode contents label: label string. |
|
3150 ]. |
|
3151 aNode isCollection ifFalse: [self selectNode: aNode] ifTrue: [self selection: (aNode collect: [:node| self indexOfNode: node])]. |
|
3152 self setModified. |
|
3153 ] |
|
3154 ! |
|
3155 |
|
3156 askForItemModification |
|
3157 |
|
3158 ^self topView application askForItemModification |
|
3159 ! |
|
3160 |
|
3161 nodeLabel:aLabel |
|
3162 |
|
3163 ^TreeItem new contents: ((MenuEditor::Item new label:aLabel) translateLabel:true) |
|
3164 |
|
3165 "Modified: / 6.6.1998 / 17:22:35 / cg" |
|
3166 ! |
|
3167 |
|
3168 nodeLabel:aLabel selector:aSelector |
|
3169 |
|
3170 ^TreeItem new contents: (((MenuEditor::Item new label:aLabel) value:aSelector) translateLabel:true) |
|
3171 |
|
3172 "Modified: / 6.6.1998 / 17:22:35 / cg" |
|
3173 "Created: / 23.8.1998 / 15:58:59 / cg" |
|
3174 ! |
|
3175 |
|
3176 selectedNodeAdd:something |
|
3177 |
|
3178 |node numChildren| |
|
3179 |
|
3180 something notNil ifTrue:[ |
|
3181 (node := self selectedNode) notNil ifTrue:[ |
|
3182 numChildren := node children size. |
|
3183 |
|
3184 node parent notNil ifTrue:[ |
|
3185 node isCollapsable ifTrue:[ |
|
3186 model add:something afterIndex:numChildren below:node |
|
3187 ] ifFalse:[ |
|
3188 model add:something after:node |
|
3189 ] |
|
3190 ] ifFalse:[ |
|
3191 model add:something afterIndex:numChildren below:(self root) |
|
3192 ] |
|
3193 ] |
|
3194 ] |
|
3195 |
|
3196 |
|
3197 ! |
|
3198 |
|
3199 setModified |
|
3200 |app| |
|
3201 |
|
3202 (app := self topView application) modified: true. |
|
3203 app updateChannels |
|
3204 ! ! |
|
3205 |
2704 !MenuEditor::Item class methodsFor:'constants'! |
3206 !MenuEditor::Item class methodsFor:'constants'! |
2705 |
3207 |
2706 separatorList |
3208 separatorList |
2707 "get the list of available separator types" |
3209 "get the list of available separator types" |
2708 |
3210 |
3054 |
3556 |
3055 |
3557 |
3056 " |
3558 " |
3057 ! ! |
3559 ! ! |
3058 |
3560 |
3059 !MenuEditor::TreeView class methodsFor:'documentation'! |
|
3060 |
|
3061 documentation |
|
3062 " |
|
3063 This tree view class provides a hierarchical representation |
|
3064 of the components of a menu. |
|
3065 |
|
3066 [see also:] |
|
3067 SelectionInTreeView |
|
3068 SelectionInTree |
|
3069 TreeItem |
|
3070 |
|
3071 [author:] |
|
3072 Claus Atzkern |
|
3073 " |
|
3074 ! ! |
|
3075 |
|
3076 !MenuEditor::TreeView methodsFor:'accessing'! |
|
3077 |
|
3078 canTab |
|
3079 ^ true |
|
3080 ! |
|
3081 |
|
3082 selectorName |
|
3083 "get the selector of the menu spec" |
|
3084 |
|
3085 ^(listOfNodes first contents label) asSymbol |
|
3086 ! |
|
3087 |
|
3088 selectorName: aSymbol |
|
3089 "set the selector for the menu spec" |
|
3090 |
|
3091 listOfNodes first contents label: aSymbol |
|
3092 ! ! |
|
3093 |
|
3094 !MenuEditor::TreeView methodsFor:'building'! |
|
3095 |
|
3096 buildFromClass:aClass andSelector:aSelector |
|
3097 "read a menu spec from aClass and aSelector and put |
|
3098 the encoded menu into the tree view" |
|
3099 |
|
3100 |spec cls menu firstNode firstNodeLabel| |
|
3101 |
|
3102 "if opened on a menu" |
|
3103 (aClass isNil and: [aSelector isNil and: [listOfNodes size > 0]]) ifTrue: [^nil]. |
|
3104 |
|
3105 self selection:nil. |
|
3106 |
|
3107 (aClass notNil and:[aSelector notNil]) ifTrue:[ |
|
3108 cls := self application resolveName:aClass. |
|
3109 |
|
3110 (cls respondsTo:aSelector) ifTrue:[ |
|
3111 spec := cls perform:aSelector |
|
3112 ] |
|
3113 ]. |
|
3114 |
|
3115 spec isNil ifFalse:[ |
|
3116 (spec isMemberOf:Menu) ifFalse:[ |
|
3117 menu := Menu new fromLiteralArrayEncoding:spec. |
|
3118 ] ifTrue:[ |
|
3119 menu := spec. |
|
3120 ]. |
|
3121 firstNode := self nodeLabel:(aSelector asString). |
|
3122 self subMenu:menu parent:firstNode. |
|
3123 ] ifTrue:[ |
|
3124 (aClass notNil and: [aSelector isNil and: [listOfNodes size > 0]]) |
|
3125 ifTrue: |
|
3126 [ |
|
3127 firstNode := listOfNodes first |
|
3128 ] |
|
3129 ifFalse: |
|
3130 [ |
|
3131 aSelector notNil ifTrue:[firstNodeLabel := aSelector asString] |
|
3132 ifFalse:[firstNodeLabel := 'menu']. |
|
3133 firstNode := self nodeLabel:firstNodeLabel. |
|
3134 ] |
|
3135 ]. |
|
3136 |
|
3137 firstNode expand. |
|
3138 model root: firstNode. |
|
3139 |
|
3140 firstNode hasChildren ifFalse:[ |
|
3141 model add:(self nodeLabel:'Item 1') below:firstNode |
|
3142 ]. |
|
3143 |
|
3144 |
|
3145 ! |
|
3146 |
|
3147 buildFromMenu:aMenu |
|
3148 "put aMenu into the tree view" |
|
3149 |
|
3150 |node| |
|
3151 |
|
3152 self selection:nil. |
|
3153 |
|
3154 node := self nodeLabel:'menu'. |
|
3155 self subMenu:aMenu parent:node. |
|
3156 |
|
3157 node hasChildren ifFalse:[ |
|
3158 node add:(self nodeLabel:'Item 1') |
|
3159 ]. |
|
3160 node expand. |
|
3161 model root:node. |
|
3162 ! |
|
3163 |
|
3164 menuItem:anItem |
|
3165 |
|
3166 |node| |
|
3167 |
|
3168 node := self nodeLabel: anItem label. |
|
3169 node contents buildFromMenuItem:anItem. |
|
3170 self subMenu: anItem submenu parent:node. |
|
3171 ^node. |
|
3172 |
|
3173 |
|
3174 ! |
|
3175 |
|
3176 subMenu:aMenu parent:aParent |
|
3177 |
|
3178 |idx grp| |
|
3179 |
|
3180 aMenu isNil ifFalse:[ |
|
3181 grp := aMenu groupSizes. |
|
3182 aMenu itemsDo:[:i| aParent add:(self menuItem:i)]. |
|
3183 |
|
3184 grp notNil ifTrue:[ |
|
3185 idx := 0. |
|
3186 |
|
3187 grp do:[:i| |
|
3188 idx := idx + i + 1. |
|
3189 aParent add:(self nodeLabel:nil) beforeIndex:idx. |
|
3190 ] |
|
3191 ] |
|
3192 ] |
|
3193 ! ! |
|
3194 |
|
3195 !MenuEditor::TreeView methodsFor:'conversion'! |
|
3196 |
|
3197 asMenu |
|
3198 |menu root| |
|
3199 |
|
3200 root := self root. |
|
3201 |
|
3202 root hasChildren ifTrue:[ |
|
3203 menu := Menu new. |
|
3204 root children do:[:aChild| menu addItem:(self asMenuItem:aChild)]. |
|
3205 ]. |
|
3206 ^ menu |
|
3207 ! |
|
3208 |
|
3209 asMenuItem:aNode |
|
3210 |
|
3211 |menu item| |
|
3212 |
|
3213 item := aNode contents asMenuItem. |
|
3214 |
|
3215 aNode hasChildren ifTrue:[ |
|
3216 menu := Menu new. |
|
3217 aNode children do:[:aChild| menu addItem:(self asMenuItem:aChild)]. |
|
3218 item submenu:menu |
|
3219 ]. |
|
3220 ^ item |
|
3221 |
|
3222 ! ! |
|
3223 |
|
3224 !MenuEditor::TreeView methodsFor:'drawing basics'! |
|
3225 |
|
3226 redrawLabelAt:x y:yTop index:anIndex |
|
3227 "draw text label assigned to a node at x y( center)" |
|
3228 |
|
3229 |isSelected y0 x0 x1 w type item| |
|
3230 |
|
3231 item := (listOfNodes at:anIndex) contents. |
|
3232 type := item separatorType. |
|
3233 |
|
3234 type isNil ifTrue:[ |
|
3235 ^ super redrawLabelAt:x y:yTop index:anIndex |
|
3236 ]. |
|
3237 isSelected := self isInSelection:anIndex. |
|
3238 x0 := x. |
|
3239 |
|
3240 highlightMode == #label ifTrue:[ |
|
3241 x0 := x + 4. |
|
3242 |
|
3243 isSelected ifTrue:[ |
|
3244 w := 80 + 8. |
|
3245 self paint:hilightBgColor. |
|
3246 self fillRectangleX:x y:yTop width:w height:fontHeight. |
|
3247 ] |
|
3248 ] ifFalse:[ |
|
3249 w := 0. |
|
3250 ]. |
|
3251 type == #blank ifFalse:[ |
|
3252 isSelected ifTrue:[self paint:hilightFgColor] |
|
3253 ifFalse:[self paint:fgColor]. |
|
3254 |
|
3255 x1 := x0 + 80. |
|
3256 y0 := yTop - 1 + (fontHeight // 2). |
|
3257 self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
3258 |
|
3259 type == #double ifTrue:[ |
|
3260 y0 := y0 + 2. |
|
3261 self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
3262 ] |
|
3263 ]. |
|
3264 |
|
3265 (isSelected and:[highlightMode == #label]) ifTrue:[ |
|
3266 self redrawSelFrameAtX:x y:yTop toX:(x + w) |
|
3267 ]. |
|
3268 |
|
3269 ! ! |
|
3270 |
|
3271 !MenuEditor::TreeView methodsFor:'event handling'! |
|
3272 |
|
3273 keyPress:key x:x y:y |
|
3274 "invoked if any key was pressed" |
|
3275 |
|
3276 <resource: #keyboard (#Delete #BackSpace #Cut #Copy #Paste)> |
|
3277 |
|
3278 (key == #Delete or:[key == #BackSpace]) ifTrue: [^self doDelete]. |
|
3279 key == #Cut ifTrue:[^self doCut]. |
|
3280 key == #Copy ifTrue:[^self doCopy]. |
|
3281 key == #Paste ifTrue:[^self doPaste]. |
|
3282 |
|
3283 super keyPress:key x:x y:y |
|
3284 |
|
3285 ! ! |
|
3286 |
|
3287 !MenuEditor::TreeView methodsFor:'initialization'! |
|
3288 |
|
3289 initialize |
|
3290 "initialize the tree view of the menu components" |
|
3291 |
|
3292 super initialize. |
|
3293 |
|
3294 self multipleSelectOk:true. |
|
3295 self showDirectoryIndicator: true. |
|
3296 self showDirectoryIndicatorForRoot: false. |
|
3297 self selectConditionBlock: [:i|self application askForItemModification]. |
|
3298 self validateDoubleClickBlock: [:node| node ~~ listOfNodes first]. |
|
3299 self model iconAction: [:aNode| aNode contents iconFor: aNode]. |
|
3300 self model labelAction: [:aNode| aNode contents treeViewLabel] |
|
3301 ! ! |
|
3302 |
|
3303 !MenuEditor::TreeView methodsFor:'menus'! |
|
3304 |
|
3305 XXdoDeleteSelectionBuffered:aBool |
|
3306 |appl idx| |
|
3307 |
|
3308 appl := self topView application. |
|
3309 |
|
3310 (appl hasValidSelection value and: [self askForItemModification]) ifFalse:[ |
|
3311 ^ self |
|
3312 ]. |
|
3313 aBool ifTrue:[ |
|
3314 self doCopy |
|
3315 ]. |
|
3316 |
|
3317 idx := 10000. |
|
3318 self selection do:[:aNumber| idx := idx min:aNumber ]. |
|
3319 |
|
3320 self selectedNodesRemove. |
|
3321 self selection:(idx min:(self list size)). |
|
3322 self setModified. |
|
3323 |
|
3324 aBool ifTrue:[ |
|
3325 "/ must update copy&paste indication |
|
3326 appl updateAllToolInstances. |
|
3327 ] |
|
3328 ! |
|
3329 |
|
3330 doCopy |
|
3331 |clip| |
|
3332 |
|
3333 self hasSelection ifTrue:[ |
|
3334 self application clipboard:(clip := OrderedCollection new). |
|
3335 self selectionDo:[:i | clip add:((listOfNodes at:i) copy)]. |
|
3336 self topView application updateAllToolInstances. |
|
3337 ] |
|
3338 ! |
|
3339 |
|
3340 doCreateItem |
|
3341 |
|
3342 self addElement: (self nodeLabel:'Item') |
|
3343 ! |
|
3344 |
|
3345 doCreateLink |
|
3346 |
|
3347 |node item| |
|
3348 |
|
3349 node := self nodeLabel:'Submenu Link'. |
|
3350 item := node contents. |
|
3351 item submenuChannel:#menuDefaultLink. |
|
3352 self addElement:node. |
|
3353 self setModified. |
|
3354 |
|
3355 |
|
3356 ! |
|
3357 |
|
3358 doCreateMenu |
|
3359 |
|
3360 |node| |
|
3361 node := self nodeLabel:'Submenu'. |
|
3362 node parent: self selectedNode. |
|
3363 node add:(self nodeLabel:'Item 1'). |
|
3364 self addElement:node |
|
3365 ! |
|
3366 |
|
3367 doCreateSep |
|
3368 |
|
3369 self addElement:(self nodeLabel:nil) |
|
3370 ! |
|
3371 |
|
3372 doCreateStandardEditMenu |
|
3373 |
|
3374 |node| |
|
3375 node := self nodeLabel:'Edit'. |
|
3376 node parent: self selectedNode. |
|
3377 node add:(self nodeLabel:'Copy' selector:#copySelection). |
|
3378 node add:(self nodeLabel:'Cut' selector:#cutSelection). |
|
3379 node add:(self nodeLabel:'Paste' selector:#paste). |
|
3380 self addElement:node |
|
3381 |
|
3382 "Created: / 23.8.1998 / 15:52:16 / cg" |
|
3383 "Modified: / 23.8.1998 / 15:59:36 / cg" |
|
3384 ! |
|
3385 |
|
3386 doCreateStandardFileMenu |
|
3387 |
|
3388 |node| |
|
3389 node := self nodeLabel:'File'. |
|
3390 node parent: self selectedNode. |
|
3391 node add:(self nodeLabel:'New' selector:#menuNew). |
|
3392 node add:(self nodeLabel:'-' ). |
|
3393 node add:(self nodeLabel:'Open...' selector:#menuOpen). |
|
3394 node add:(self nodeLabel:'-' ). |
|
3395 node add:(self nodeLabel:'Save' selector:#menuSave). |
|
3396 node add:(self nodeLabel:'Save As...' selector:#menuSaveAs). |
|
3397 node add:(self nodeLabel:'-' ). |
|
3398 node add:(self nodeLabel:'Exit' selector:#closeRequest). |
|
3399 self addElement:node |
|
3400 |
|
3401 "Created: / 23.8.1998 / 15:51:55 / cg" |
|
3402 "Modified: / 23.8.1998 / 16:04:24 / cg" |
|
3403 ! |
|
3404 |
|
3405 doCreateStandardHelpMenu |
|
3406 |
|
3407 |node| |
|
3408 node := self nodeLabel:'Help'. |
|
3409 node parent: self selectedNode. |
|
3410 node contents startGroup:#right. |
|
3411 node add:(self nodeLabel:'Documentation' selector:#openDocumentation). |
|
3412 node add:(self nodeLabel:'-'). |
|
3413 node add:(self nodeLabel:'About this Application' selector:#openAboutThisApplication). |
|
3414 self addElement:node |
|
3415 |
|
3416 "Created: / 23.8.1998 / 15:52:46 / cg" |
|
3417 "Modified: / 23.8.1998 / 17:30:12 / cg" |
|
3418 ! |
|
3419 |
|
3420 doCut |
|
3421 ^ self doDeleteSelectionBuffered:true |
|
3422 ! |
|
3423 |
|
3424 doDelete |
|
3425 ^ self doDeleteSelectionBuffered:false |
|
3426 ! |
|
3427 |
|
3428 doDeleteSelectionBuffered:aBool |
|
3429 |appl nsel list item prnt| |
|
3430 |
|
3431 appl := self topView application. |
|
3432 |
|
3433 (appl hasValidSelection value and: [self askForItemModification]) ifFalse:[ |
|
3434 ^ self |
|
3435 ]. |
|
3436 aBool ifTrue:[ |
|
3437 self doCopy |
|
3438 ]. |
|
3439 list := self list. |
|
3440 nsel := list size. |
|
3441 self selection do:[:aNumber| nsel := nsel min:aNumber ]. |
|
3442 |
|
3443 ( (item := list at:nsel ifAbsent:nil) notNil |
|
3444 and:[(prnt := item parent) notNil |
|
3445 and:[prnt children last == item]] |
|
3446 ) ifTrue:[ |
|
3447 nsel := nsel - 1 |
|
3448 ]. |
|
3449 |
|
3450 self selectedNodesRemove. |
|
3451 self selection:(nsel min:(list size)). |
|
3452 self setModified. |
|
3453 |
|
3454 aBool ifTrue:[ |
|
3455 "/ must update copy&paste indication |
|
3456 appl updateAllToolInstances. |
|
3457 ] |
|
3458 ! |
|
3459 |
|
3460 doPaste |
|
3461 |clip| |
|
3462 |
|
3463 clip := self application clipboard. |
|
3464 (clip notNil and:[self selectedNode notNil]) ifTrue:[ |
|
3465 self addElement:(clip collect:[:el| el copy]) |
|
3466 ]. |
|
3467 ! ! |
|
3468 |
|
3469 !MenuEditor::TreeView methodsFor:'private'! |
|
3470 |
|
3471 addElement: aNode |
|
3472 "add something after selection" |
|
3473 |
|
3474 |label sel| |
|
3475 |
|
3476 self askForItemModification ifTrue:[ |
|
3477 self selectedNodeAdd:aNode. |
|
3478 (aNode isCollection not |
|
3479 and: [aNode name = 'Item']) |
|
3480 ifTrue:[ |
|
3481 sel := self selectedNode. |
|
3482 label := aNode name , ' ', |
|
3483 (sel parent notNil |
|
3484 ifTrue: |
|
3485 [ |
|
3486 (((sel children size = 0 |
|
3487 ifTrue: [sel parent children] |
|
3488 ifFalse: [sel children]) |
|
3489 select:[:node| |
|
3490 |lab| |
|
3491 lab := node contents label. |
|
3492 ((node children size = 0) & |
|
3493 node contents submenuChannel isNil & |
|
3494 (lab ~= '-') & (lab ~= '=') & (lab ~= '')) |
|
3495 ]) size) printString |
|
3496 ] |
|
3497 ifFalse: ['1']). |
|
3498 |
|
3499 aNode name: label string asBoldText. |
|
3500 aNode contents label: label string. |
|
3501 ]. |
|
3502 aNode isCollection ifFalse: [self selectNode: aNode] ifTrue: [self selection: (aNode collect: [:node| self indexOfNode: node])]. |
|
3503 self setModified. |
|
3504 ] |
|
3505 ! |
|
3506 |
|
3507 askForItemModification |
|
3508 |
|
3509 ^self topView application askForItemModification |
|
3510 ! |
|
3511 |
|
3512 nodeLabel:aLabel |
|
3513 |
|
3514 ^TreeItem new contents: ((MenuEditor::Item new label:aLabel) translateLabel:true) |
|
3515 |
|
3516 "Modified: / 6.6.1998 / 17:22:35 / cg" |
|
3517 ! |
|
3518 |
|
3519 nodeLabel:aLabel selector:aSelector |
|
3520 |
|
3521 ^TreeItem new contents: (((MenuEditor::Item new label:aLabel) value:aSelector) translateLabel:true) |
|
3522 |
|
3523 "Modified: / 6.6.1998 / 17:22:35 / cg" |
|
3524 "Created: / 23.8.1998 / 15:58:59 / cg" |
|
3525 ! |
|
3526 |
|
3527 selectedNodeAdd:something |
|
3528 |
|
3529 |node numChildren| |
|
3530 |
|
3531 something notNil ifTrue:[ |
|
3532 (node := self selectedNode) notNil ifTrue:[ |
|
3533 numChildren := node children size. |
|
3534 |
|
3535 node parent notNil ifTrue:[ |
|
3536 node isCollapsable ifTrue:[ |
|
3537 model add:something afterIndex:numChildren below:node |
|
3538 ] ifFalse:[ |
|
3539 model add:something after:node |
|
3540 ] |
|
3541 ] ifFalse:[ |
|
3542 model add:something afterIndex:numChildren below:(self root) |
|
3543 ] |
|
3544 ] |
|
3545 ] |
|
3546 |
|
3547 |
|
3548 ! |
|
3549 |
|
3550 setModified |
|
3551 |app| |
|
3552 |
|
3553 (app := self topView application) modified: true. |
|
3554 app updateChannels |
|
3555 ! ! |
|
3556 |
|
3557 !MenuEditor class methodsFor:'documentation'! |
3561 !MenuEditor class methodsFor:'documentation'! |
3558 |
3562 |
3559 version |
3563 version |
3560 ^ '$Header$' |
3564 ^ '$Header$' |
3561 ! ! |
3565 ! ! |