62 [author:] |
69 [author:] |
63 Thomas Zwick, eXept Software AG |
70 Thomas Zwick, eXept Software AG |
64 Claus Gittinger, eXept Software AG |
71 Claus Gittinger, eXept Software AG |
65 " |
72 " |
66 |
73 |
|
74 ! |
|
75 |
|
76 examples |
|
77 " |
|
78 reopening a standard launcher (without any added tools) |
|
79 [exBegin] |
|
80 NewLauncher removeAllUserAddedTools. |
|
81 NewLauncher open. |
|
82 [exEnd] |
|
83 |
|
84 |
|
85 |
|
86 adding your own menu items (for user-applications) |
|
87 |
|
88 an additional item in the tools menu: |
|
89 [exBegin] |
|
90 Transcript topView application |
|
91 addMenuItem:(MenuItem new |
|
92 label: 'Foo'; |
|
93 value: [Transcript showCR:'foo invoked']; |
|
94 isButton: false; |
|
95 labelImage: nil; |
|
96 nameKey: #foo; |
|
97 activeHelpKey: #Foo) |
|
98 in:#menu |
|
99 position:(#before #workspace) |
|
100 space:true |
|
101 [exEnd] |
|
102 |
|
103 an additional item in the tools menu: |
|
104 [exBegin] |
|
105 Transcript topView application |
|
106 addMenuItem:(MenuItem new |
|
107 label: 'Foo'; |
|
108 value: [Transcript showCR:'foo invoked']; |
|
109 isButton: false; |
|
110 labelImage: nil; |
|
111 activeHelpKey: #Foo) |
|
112 in:#menu |
|
113 position:(#after #guiPainter) |
|
114 space:true |
|
115 [exEnd] |
|
116 |
|
117 an additional item in one of the tools sub menus: |
|
118 [exBegin] |
|
119 Transcript topView application |
|
120 addMenuItem:(MenuItem new |
|
121 label: 'Foo'; |
|
122 value: [Transcript showCR:'foo invoked']; |
|
123 isButton: false; |
|
124 labelImage: nil; |
|
125 activeHelpKey: #Foo) |
|
126 in:#menu |
|
127 position:'Workspace' |
|
128 before:true |
|
129 space:true |
|
130 [exEnd] |
|
131 " |
|
132 |
67 ! ! |
133 ! ! |
68 |
134 |
69 !NewLauncher class methodsFor:'accessing'! |
135 !NewLauncher class methodsFor:'accessing'! |
70 |
136 |
71 label |
137 label |
72 |
138 |
73 ^'Launcher' |
139 ^'Launcher' |
74 |
140 |
75 |
141 |
|
142 ! |
|
143 |
|
144 removeAllUserAddedTools |
|
145 UserAddedTools := nil |
76 ! ! |
146 ! ! |
77 |
147 |
78 !NewLauncher class methodsFor:'defaults'! |
148 !NewLauncher class methodsFor:'defaults'! |
79 |
149 |
80 windowIcon |
150 windowIcon |
2367 |
2437 |
2368 ! ! |
2438 ! ! |
2369 |
2439 |
2370 !NewLauncher methodsFor:'menu configuration'! |
2440 !NewLauncher methodsFor:'menu configuration'! |
2371 |
2441 |
2372 addUserTool:toolName action:actionBlock icon:iconOrNil |
2442 addMenuItem:newItem in:where position:positionSpecOrNilArg space:space |
2373 "adds a menu item labeled toolName, and action and icon both to the |
2443 "adds a menu item; |
2374 sub menu 'Tools' and the tool bar. |
|
2375 This can be invoked by a classes #initialize method, to add an item |
|
2376 for itself to the toolbar. |
|
2377 " |
|
2378 |
|
2379 self |
|
2380 addUserTool:toolName |
|
2381 action:actionBlock |
|
2382 in:nil |
|
2383 icon:iconOrNil |
|
2384 space:true |
|
2385 |
|
2386 " |
|
2387 Transcript topView application |
|
2388 addUserTool:'Foo' |
|
2389 action:[Transcript showCR:'foo'] |
|
2390 icon:nil |
|
2391 " |
|
2392 ! |
|
2393 |
|
2394 addUserTool:toolName action:actionBlock in:where after:afterOrNil icon:icon space:space |
|
2395 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2396 where == #menu - menu item is added at the end of the sub menu 'Tools', |
2444 where == #menu - menu item is added at the end of the sub menu 'Tools', |
2397 where == #toolbar - menu item is added at the end of the tool bar, |
2445 where == #toolbar - menu item is added at the end of the tool bar, |
2398 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
2446 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
2399 |
2447 |
|
2448 position may be one of: |
|
2449 ( #before <someItemPath> ) |
|
2450 ( #after <someItemPath> ) |
|
2451 ( #first ) or #first |
|
2452 ( #last ) or #last |
|
2453 nil (same as last) |
|
2454 |
2400 If space is true, some empty space is inserted. |
2455 If space is true, some empty space is inserted. |
2401 This can be invoked by a classes #initialize method, to add an item |
2456 This can be invoked by a classes #initialize method, to add an item |
2402 for itself to the toolbar or menu. |
2457 for itself to the toolbar or menu. |
2403 " |
2458 " |
2404 |
2459 |
2405 ^ self |
|
2406 addUserTool:toolName action:actionBlock in:where position:afterOrNil before:false icon:icon space:space |
|
2407 |
|
2408 " |
|
2409 Transcript topView application |
|
2410 addUserTool:'Foo' |
|
2411 action:[Transcript showCR:'foo'] |
|
2412 in:#menu |
|
2413 icon:nil |
|
2414 space:false |
|
2415 " |
|
2416 " |
|
2417 Transcript topView application |
|
2418 addUserTool:'Bar' |
|
2419 action:[Transcript showCR:'bar'] |
|
2420 in:#menu |
|
2421 icon:nil |
|
2422 space:false |
|
2423 " |
|
2424 ! |
|
2425 |
|
2426 addUserTool:toolName action:actionBlock in:where before:afterOrNil icon:icon space:space |
|
2427 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2428 where == #menu - menu item is added at the end of the sub menu 'Tools', |
|
2429 where == #toolbar - menu item is added at the end of the tool bar, |
|
2430 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
|
2431 |
|
2432 If space is true, some empty space is inserted. |
|
2433 This can be invoked by a classes #initialize method, to add an item |
|
2434 for itself to the toolbar or menu. |
|
2435 " |
|
2436 |
|
2437 ^ self |
|
2438 addUserTool:toolName action:actionBlock in:where position:afterOrNil before:true icon:icon space:space |
|
2439 ! |
|
2440 |
|
2441 addUserTool:toolName action:actionBlock in:what icon:icon space:space |
|
2442 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2443 for what == #menu menu item is added at the end of the sub menu 'Tools', |
|
2444 for what == #toolbar menu item is added at the end of the tool bar, |
|
2445 If space is true, some empty space is inserted. |
|
2446 This can be invoked by a classes #initialize method, to add an item |
|
2447 for itself to the toolbar or menu. |
|
2448 " |
|
2449 |
|
2450 ^ self |
|
2451 addUserTool:toolName |
|
2452 action:actionBlock |
|
2453 in:what |
|
2454 after:nil |
|
2455 icon:icon |
|
2456 space:space |
|
2457 |
|
2458 " |
|
2459 Transcript topView application |
|
2460 addUserTool:'Foo' |
|
2461 action:[Transcript showCR:'foo'] |
|
2462 in:#menu |
|
2463 icon:nil |
|
2464 space:false |
|
2465 " |
|
2466 " |
|
2467 Transcript topView application |
|
2468 addUserTool:'Bar' |
|
2469 action:[Transcript showCR:'bar'] |
|
2470 in:#menu |
|
2471 icon:nil |
|
2472 space:false |
|
2473 " |
|
2474 |
|
2475 ! |
|
2476 |
|
2477 addUserTool:toolName action:actionBlock in:where position:itemNameOrNil before:before icon:icon space:space |
|
2478 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2479 where == #menu - menu item is added at the end of the sub menu 'Tools', |
|
2480 where == #toolbar - menu item is added at the end of the tool bar, |
|
2481 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
|
2482 |
|
2483 If space is true, some empty space is inserted. |
|
2484 This can be invoked by a classes #initialize method, to add an item |
|
2485 for itself to the toolbar or menu. |
|
2486 " |
|
2487 |
|
2488 |what menuPanel freeMenuIndex mainMenuPanel item subViews subMenuPath |
2460 |what menuPanel freeMenuIndex mainMenuPanel item subViews subMenuPath |
2489 rest subMenu subItem menuWithNewItem nItems| |
2461 rest subMenu subItem nItems idx |
|
2462 positionSpecOrNil itemNameOrNil before| |
|
2463 |
|
2464 positionSpecOrNil := positionSpecOrNilArg. |
|
2465 positionSpecOrNil isArray ifTrue:[ |
|
2466 positionSpecOrNil size > 1 ifTrue:[ |
|
2467 itemNameOrNil := positionSpecOrNil at:2. |
|
2468 ]. |
|
2469 positionSpecOrNil := positionSpecOrNil at:1. |
|
2470 ]. |
|
2471 before := (positionSpecOrNil == #first) or:[positionSpecOrNil == #before]. |
2490 |
2472 |
2491 what := where. |
2473 what := where. |
2492 (what isNil or: [what = 'toolbar']) ifTrue:[ |
2474 (what isNil or: [what = 'toolbar']) ifTrue:[ |
|
2475 "/ look if not already in the toolBar |
2493 menuPanel := builder namedComponents at: #menuToolbarView. |
2476 menuPanel := builder namedComponents at: #menuToolbarView. |
2494 |
2477 |
2495 (menuPanel findFirst: [:i| i activeHelpKey = toolName or:[i label = toolName]]) == 0 |
2478 idx := 0. |
2496 ifTrue:[ |
2479 newItem nameKey notNil ifTrue:[ |
|
2480 idx := menuPanel findFirst: [:i| i nameKey = newItem nameKey]. |
|
2481 ]. |
|
2482 idx == 0 ifTrue:[ |
|
2483 idx := menuPanel findFirst: [:i| (newItem activeHelpKey notNil and:[ i activeHelpKey = newItem activeHelpKey]) |
|
2484 or:[ newItem label notNil and:[ i label = newItem label] ]] |
|
2485 ]. |
|
2486 idx == 0 ifTrue:[ |
|
2487 "/ ok, not there; search for the position to put the item |
2497 nItems := menuPanel numberOfItems. |
2488 nItems := menuPanel numberOfItems. |
2498 freeMenuIndex := 0. |
2489 freeMenuIndex := 0. |
2499 itemNameOrNil notNil ifTrue:[ |
2490 itemNameOrNil notNil ifTrue:[ |
2500 freeMenuIndex := menuPanel findFirst: [:i| i nameKey = itemNameOrNil]. |
2491 freeMenuIndex := menuPanel findFirst: [:i| i nameKey = itemNameOrNil]. |
2501 freeMenuIndex == 0 ifTrue:[ |
2492 freeMenuIndex == 0 ifTrue:[ |
2502 freeMenuIndex := menuPanel findFirst: [:i| i activeHelpKey = itemNameOrNil or:[i label = itemNameOrNil]]. |
2493 freeMenuIndex := menuPanel findFirst: [:i| i activeHelpKey = itemNameOrNil or:[i label = itemNameOrNil]]. |
2503 ] |
2494 ] |
2504 ]. |
2495 ]. |
|
2496 |
2505 freeMenuIndex == 0 ifTrue:[ |
2497 freeMenuIndex == 0 ifTrue:[ |
2506 freeMenuIndex := (before ifTrue:1 ifFalse:[nItems + 1]). |
2498 freeMenuIndex := before ifTrue:1 ifFalse:[nItems + 1]. |
|
2499 ] ifFalse:[ |
|
2500 before ifFalse:[freeMenuIndex := freeMenuIndex +1]. |
2507 ]. |
2501 ]. |
2508 |
2502 |
2509 space ifTrue:[ |
2503 space ifTrue:[ |
2510 (menuPanel createAtIndex: freeMenuIndex) menuItem: (MenuItem labeled: ''). |
2504 (menuPanel createAtIndex: freeMenuIndex) menuItem: (MenuItem labeled: ''). |
2511 freeMenuIndex := freeMenuIndex + (before ifTrue:0 ifFalse:1). |
2505 freeMenuIndex := freeMenuIndex + (before ifTrue:0 ifFalse:1). |
|
2506 |
2512 ]. |
2507 ]. |
2513 |
2508 |
2514 (menuPanel createAtIndex: freeMenuIndex) menuItem: |
2509 (menuPanel createAtIndex: freeMenuIndex) menuItem:newItem. |
2515 (MenuItem new |
2510 |
2516 label: toolName; |
2511 UserAddedToolBarItems isNil ifTrue: [UserAddedToolBarItems := Dictionary new]. |
2517 value: actionBlock; |
2512 UserAddedToolBarItems at:newItem put:(AddedToolInfo new |
2518 isButton: true; |
2513 item:newItem; |
2519 labelImage: icon; |
2514 positionSpec:positionSpecOrNilArg; |
2520 activeHelpKey: toolName asSymbol) |
2515 space:space; |
|
2516 before:before; |
|
2517 menuWithNewItem:menuPanel; |
|
2518 yourself) |
2521 ]. |
2519 ]. |
2522 ]. |
2520 ]. |
2523 |
2521 |
2524 subMenuPath := #( 'tools' ). |
2522 subMenuPath := #( 'tools' ). |
2525 (what notNil and:[what includes:$.]) ifTrue:[ |
2523 (what notNil and:[what includes:$.]) ifTrue:[ |
2569 ]. |
2567 ]. |
2570 |
2568 |
2571 item isNil ifTrue:[^ self]. |
2569 item isNil ifTrue:[^ self]. |
2572 menuPanel := item submenu. |
2570 menuPanel := item submenu. |
2573 |
2571 |
2574 (menuPanel findFirst: [:i| i activeHelpKey = toolName or:[i label = toolName]]) == 0 |
2572 "/ look if not already in the menu |
2575 ifTrue:[ |
2573 idx := 0. |
|
2574 newItem nameKey notNil ifTrue:[ |
|
2575 idx := menuPanel findFirst: [:i| i nameKey = newItem nameKey]. |
|
2576 ]. |
|
2577 idx == 0 ifTrue:[ |
|
2578 idx := menuPanel findFirst: [:i| (newItem activeHelpKey notNil and:[ i activeHelpKey = newItem activeHelpKey]) |
|
2579 or:[ newItem label notNil and:[ i label = newItem label] ]] |
|
2580 ]. |
|
2581 |
|
2582 idx == 0 ifTrue:[ |
|
2583 "/ ok, not there; search for the position to put the item |
|
2584 |
2576 nItems := menuPanel numberOfItems. |
2585 nItems := menuPanel numberOfItems. |
2577 freeMenuIndex := 0. |
2586 freeMenuIndex := 0. |
2578 itemNameOrNil notNil ifTrue:[ |
2587 itemNameOrNil notNil ifTrue:[ |
2579 freeMenuIndex := menuPanel findFirst: [:i| i nameKey = itemNameOrNil]. |
2588 freeMenuIndex := menuPanel findFirst: [:i| i nameKey = itemNameOrNil]. |
2580 freeMenuIndex == 0 ifTrue:[ |
2589 freeMenuIndex == 0 ifTrue:[ |
2581 freeMenuIndex := menuPanel findFirst: [:i| i activeHelpKey = itemNameOrNil or:[i label = itemNameOrNil]]. |
2590 freeMenuIndex := menuPanel findFirst: [:i| i activeHelpKey = itemNameOrNil or:[i label = itemNameOrNil]]. |
2582 ] |
2591 ] |
2583 ]. |
2592 ]. |
2584 freeMenuIndex == 0 ifTrue:[ |
2593 freeMenuIndex == 0 ifTrue:[ |
2585 freeMenuIndex := (before ifTrue:1 ifFalse:[nItems + 1]). |
2594 freeMenuIndex := before ifTrue:1 ifFalse:[nItems + 1]. |
|
2595 ] ifFalse:[ |
|
2596 before ifFalse:[freeMenuIndex := freeMenuIndex +1]. |
2586 ]. |
2597 ]. |
2587 space ifTrue:[ |
2598 space ifTrue:[ |
2588 (menuPanel createAtIndex: freeMenuIndex) menuItem: (MenuItem labeled: '-'). |
2599 (menuPanel createAtIndex: freeMenuIndex) menuItem: (MenuItem labeled: '-'). |
2589 freeMenuIndex := freeMenuIndex + (before ifTrue:0 ifFalse:1). |
2600 freeMenuIndex := freeMenuIndex + (before ifTrue:0 ifFalse:1). |
2590 ]. |
2601 ]. |
2591 |
2602 |
2592 (menuPanel createAtIndex:freeMenuIndex) menuItem: |
2603 (menuPanel createAtIndex:freeMenuIndex) menuItem:newItem. |
2593 (MenuItem new |
2604 |
2594 label: toolName; |
2605 UserAddedMenuItems isNil ifTrue: [UserAddedMenuItems := Dictionary new]. |
2595 value: actionBlock; |
2606 UserAddedMenuItems at:newItem put:(AddedToolInfo new |
2596 labelImage: (LabelAndIcon icon: icon string: toolName); |
2607 item:newItem; |
2597 activeHelpKey: toolName asSymbol) . |
2608 positionSpec:positionSpecOrNilArg; |
2598 menuWithNewItem := menuPanel. |
2609 space:space; |
|
2610 before:before; |
|
2611 menuWithNewItem:menuPanel; |
|
2612 yourself) |
2599 ]. |
2613 ]. |
2600 ]. |
2614 ]. |
2601 |
2615 |
2602 UserAddedTools isNil ifTrue: [UserAddedTools := Dictionary new]. |
2616 " |
2603 UserAddedTools |
2617 UserAddedToolBarItems := nil. |
2604 at:toolName |
2618 UserAddedMenuItems := nil. |
2605 put:(Array with:actionBlock with:what with:icon with:space with:itemNameOrNil with:before with:menuWithNewItem) |
2619 NewLauncher open. |
|
2620 |
|
2621 Transcript topView application |
|
2622 addMenuItem:(MenuItem new |
|
2623 label: 'Foo'; |
|
2624 value: [Transcript showCR:'foo']; |
|
2625 isButton: false; |
|
2626 labelImage: nil; |
|
2627 nameKey: #foo) |
|
2628 in:#menu |
|
2629 position:#(#before 'Workspace') |
|
2630 space:true |
|
2631 |
|
2632 Transcript topView application |
|
2633 addMenuItem:(MenuItem new |
|
2634 label: 'Bar'; |
|
2635 value: [Transcript showCR:'bar']; |
|
2636 isButton: false; |
|
2637 labelImage: nil; |
|
2638 nameKey: #bar) |
|
2639 in:#menu |
|
2640 position:#(#after #foo) |
|
2641 space:true |
|
2642 |
|
2643 Transcript topView application |
|
2644 addMenuItem:(MenuItem new |
|
2645 label: 'Baz'; |
|
2646 value: [Transcript showCR:'baz']; |
|
2647 isButton: false; |
|
2648 labelImage: nil; |
|
2649 nameKey: #baz) |
|
2650 in:#menu |
|
2651 position:#(#before #bar) |
|
2652 space:false |
|
2653 |
|
2654 Transcript topView application |
|
2655 addMenuItem:(MenuItem new |
|
2656 label: 'Baz2'; |
|
2657 value: [Transcript showCR:'baz2']; |
|
2658 isButton: false; |
|
2659 labelImage: nil; |
|
2660 nameKey: #baz2) |
|
2661 in:#menu |
|
2662 position:#(#after #bar) |
|
2663 space:false |
|
2664 |
|
2665 Transcript topView application |
|
2666 addMenuItem:(MenuItem new |
|
2667 label: 'Foo2'; |
|
2668 value: [Transcript showCR:'foo2']; |
|
2669 isButton: false; |
|
2670 labelImage: nil; |
|
2671 nameKey: #foo2) |
|
2672 in:'menu.classes' |
|
2673 position:#last |
|
2674 space:false |
|
2675 |
|
2676 Transcript topView application |
|
2677 addMenuItem:(MenuItem new |
|
2678 label: 'Foo3'; |
|
2679 value: [Transcript showCR:'foo3']; |
|
2680 isButton: false; |
|
2681 labelImage: nil; |
|
2682 nameKey: #foo3) |
|
2683 in:'menu.classes.special' |
|
2684 position:#first |
|
2685 space:true |
|
2686 " |
|
2687 ! |
|
2688 |
|
2689 addUserTool:toolName action:actionBlock icon:iconOrNil |
|
2690 "adds a menu item labeled toolName, and action and icon both to the |
|
2691 sub menu 'Tools' and the tool bar. |
|
2692 This can be invoked by a classes #initialize method, to add an item |
|
2693 for itself to the toolbar. |
|
2694 OBSOLETE |
|
2695 " |
|
2696 |
|
2697 self |
|
2698 addUserTool:toolName |
|
2699 action:actionBlock |
|
2700 in:nil |
|
2701 icon:iconOrNil |
|
2702 space:true |
|
2703 |
|
2704 " |
|
2705 Transcript topView application |
|
2706 addUserTool:'Foo' |
|
2707 action:[Transcript showCR:'foo'] |
|
2708 icon:nil |
|
2709 " |
|
2710 ! |
|
2711 |
|
2712 addUserTool:toolName action:actionBlock in:where after:afterOrNil icon:icon space:space |
|
2713 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2714 where == #menu - menu item is added at the end of the sub menu 'Tools', |
|
2715 where == #toolbar - menu item is added at the end of the tool bar, |
|
2716 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
|
2717 |
|
2718 If space is true, some empty space is inserted. |
|
2719 This can be invoked by a classes #initialize method, to add an item |
|
2720 for itself to the toolbar or menu. |
|
2721 OBSOLETE |
|
2722 " |
|
2723 |
|
2724 ^ self |
|
2725 addUserTool:toolName action:actionBlock in:where position:afterOrNil before:false icon:icon space:space |
2606 |
2726 |
2607 " |
2727 " |
2608 Transcript topView application |
2728 Transcript topView application |
2609 addUserTool:'Foo' |
2729 addUserTool:'Foo' |
2610 action:[Transcript showCR:'foo'] |
2730 action:[Transcript showCR:'foo'] |
2620 icon:nil |
2740 icon:nil |
2621 space:false |
2741 space:false |
2622 " |
2742 " |
2623 ! |
2743 ! |
2624 |
2744 |
2625 removeUserTool:toolName |
2745 addUserTool:toolName action:actionBlock in:where before:afterOrNil icon:icon space:space |
|
2746 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2747 where == #menu - menu item is added at the end of the sub menu 'Tools', |
|
2748 where == #toolbar - menu item is added at the end of the tool bar, |
|
2749 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
|
2750 |
|
2751 If space is true, some empty space is inserted. |
|
2752 This can be invoked by a classes #initialize method, to add an item |
|
2753 for itself to the toolbar or menu. |
|
2754 OBSOLETE |
|
2755 " |
|
2756 |
|
2757 ^ self |
|
2758 addUserTool:toolName action:actionBlock in:where position:afterOrNil before:true icon:icon space:space |
|
2759 ! |
|
2760 |
|
2761 addUserTool:toolName action:actionBlock in:what icon:icon space:space |
|
2762 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2763 for what == #menu menu item is added at the end of the sub menu 'Tools', |
|
2764 for what == #toolbar menu item is added at the end of the tool bar, |
|
2765 If space is true, some empty space is inserted. |
|
2766 This can be invoked by a classes #initialize method, to add an item |
|
2767 for itself to the toolbar or menu. |
|
2768 OBSOLETE |
|
2769 " |
|
2770 |
|
2771 ^ self |
|
2772 addUserTool:toolName |
|
2773 action:actionBlock |
|
2774 in:what |
|
2775 after:nil |
|
2776 icon:icon |
|
2777 space:space |
|
2778 |
|
2779 " |
|
2780 UserAddedTools := nil. |
|
2781 NewLauncher open. |
|
2782 |
|
2783 Transcript topView application |
|
2784 addUserTool:'Foo' |
|
2785 action:[Transcript showCR:'foo'] |
|
2786 in:#menu |
|
2787 icon:nil |
|
2788 space:false |
|
2789 " |
|
2790 " |
|
2791 Transcript topView application |
|
2792 addUserTool:'Bar' |
|
2793 action:[Transcript showCR:'bar'] |
|
2794 in:#menu |
|
2795 icon:nil |
|
2796 space:true |
|
2797 " |
|
2798 |
|
2799 ! |
|
2800 |
|
2801 addUserTool:toolName action:actionBlock in:where position:itemNameOrNil before:before icon:icon space:space |
|
2802 "adds a menu item labeled toolName, and actionBlock and icon; |
|
2803 where == #menu - menu item is added at the end of the sub menu 'Tools', |
|
2804 where == #toolbar - menu item is added at the end of the tool bar, |
|
2805 where == #menu.<name> - menu item is added at the end of the sub menu named 'name', |
|
2806 |
|
2807 If space is true, some empty space is inserted. |
|
2808 This can be invoked by a classes #initialize method, to add an item |
|
2809 for itself to the toolbar or menu. |
|
2810 OBSOLETE |
|
2811 " |
|
2812 |
|
2813 |newItem positionSpecOrNilArg| |
|
2814 |
|
2815 newItem := (MenuItem new |
|
2816 label: toolName; |
|
2817 value: actionBlock; |
|
2818 isButton: false; |
|
2819 labelImage: icon; |
|
2820 nameKey: toolName asSymbol; |
|
2821 activeHelpKey: toolName asSymbol). |
|
2822 |
|
2823 itemNameOrNil isNil ifTrue:[ |
|
2824 positionSpecOrNilArg := before ifTrue:[#first] ifFalse:[#last]. |
|
2825 ] ifFalse:[ |
|
2826 positionSpecOrNilArg := before ifTrue:[#before] ifFalse:[#after]. |
|
2827 positionSpecOrNilArg := Array with:itemNameOrNil with:positionSpecOrNilArg. |
|
2828 ]. |
|
2829 |
|
2830 ^ self addMenuItem:newItem in:where position:positionSpecOrNilArg space:space |
|
2831 |
|
2832 ! |
|
2833 |
|
2834 removeUserTool:toolNameOrMenuItem |
2626 "removes a menu item labeled toolName |
2835 "removes a menu item labeled toolName |
2627 This can be invoked by a classes #deinitialize method, |
2836 This can be invoked by a classes #deinitialize method, |
2628 to remove its item from the toolbar or menu. |
2837 to remove its item from the toolbar or menu. |
2629 " |
2838 " |
2630 |
2839 |
2631 |userToolInfo space menuIndex removeInMenuBlock whichMenu before| |
2840 self removeUserTool:toolNameOrMenuItem from:UserAddedToolBarItems. |
2632 |
2841 self removeUserTool:toolNameOrMenuItem from:UserAddedMenuItems. |
2633 UserAddedTools isNil ifTrue: [^nil]. |
2842 |
2634 userToolInfo := UserAddedTools at: toolName ifAbsent: [^nil]. |
2843 " |
2635 space := userToolInfo at: 4. |
2844 Transcript topView application |
2636 before := userToolInfo at: 6. |
2845 removeUserTool:'Bar' |
2637 whichMenu := userToolInfo at: 7. |
2846 " |
2638 |
2847 " |
2639 removeInMenuBlock := |
2848 Transcript topView application |
2640 [:menuPanel| |
2849 removeUserTool:'Foo' |
2641 (menuIndex := menuPanel findFirst: [:i| i activeHelpKey = toolName]) ~~ 0 |
2850 " |
2642 ifTrue: |
2851 |
2643 [ |
2852 ! |
2644 menuPanel remove: menuIndex. |
2853 |
|
2854 removeUserTool:toolNameOrMenuItem from:addedToolsCollection |
|
2855 "removes a menu item labeled toolName |
|
2856 This can be invoked by a classes #deinitialize method, |
|
2857 to remove its item from the toolbar or menu. |
|
2858 " |
|
2859 |
|
2860 |info space menuIndex removeInMenuBlock whichMenu before menuItemToRemove| |
|
2861 |
|
2862 addedToolsCollection size == 0 ifTrue: [^nil]. |
|
2863 |
|
2864 [true] whileTrue:[ |
|
2865 (toolNameOrMenuItem isString or:[toolNameOrMenuItem isSymbol]) ifTrue:[ |
|
2866 info := addedToolsCollection detect:[:eachInfo | |eachItem| |
|
2867 eachItem := eachInfo item. |
|
2868 (eachItem nameKey notNil and:[ toolNameOrMenuItem = eachItem nameKey]) |
|
2869 or:[ (eachItem activeHelpKey notNil and:[ toolNameOrMenuItem = eachItem activeHelpKey]) |
|
2870 or:[ (eachItem label notNil and:[ toolNameOrMenuItem = eachItem label])]] |
|
2871 ] |
|
2872 ifNone:nil. |
|
2873 ] ifFalse:[ |
|
2874 info := addedToolsCollection detect:[:eachInfo | |eachItem| eachItem := eachInfo item. (eachItem == toolNameOrMenuItem)] ifNone:nil. |
|
2875 ]. |
|
2876 info isNil ifTrue:[^ self]. |
|
2877 |
|
2878 space := info space. |
|
2879 whichMenu := info menuWithNewItem. |
|
2880 menuItemToRemove := info item. |
|
2881 before := info before. |
|
2882 |
|
2883 menuIndex := whichMenu findFirst:[:item | |
|
2884 (item nameKey notNil and:[item nameKey == menuItemToRemove nameKey]) |
|
2885 or:[ (item activeHelpKey notNil and:[item activeHelpKey == menuItemToRemove activeHelpKey]) |
|
2886 or:[ (item label notNil and:[item label = menuItemToRemove label]) ]] |
|
2887 ]. |
|
2888 menuIndex ~~ 0 ifTrue:[ |
|
2889 whichMenu remove: menuIndex. |
2645 space ifTrue: [ |
2890 space ifTrue: [ |
2646 menuPanel remove:(menuIndex - (before ifTrue:0 ifFalse:1)) |
2891 whichMenu remove:(menuIndex - (before ifTrue:0 ifFalse:1)) |
2647 ]. |
2892 ]. |
|
2893 addedToolsCollection removeKey:menuItemToRemove |
|
2894 ] ifFalse:[ |
|
2895 self halt. |
2648 ]. |
2896 ]. |
2649 ]. |
2897 ]. |
2650 |
2898 |
2651 removeInMenuBlock value: (builder namedComponents at: #menuToolbarView). |
2899 |
2652 removeInMenuBlock value: ((self builder window subViews at: 1 ifAbsent: [^self]) itemAt: 4) submenu. |
2900 " |
2653 whichMenu notNil ifTrue:[removeInMenuBlock value: whichMenu]. |
2901 Transcript topView application |
2654 |
2902 removeUserTool:'Bar' |
2655 UserAddedTools removeKey: toolName |
2903 " |
2656 |
|
2657 " |
2904 " |
2658 Transcript topView application |
2905 Transcript topView application |
2659 removeUserTool:'Foo' |
2906 removeUserTool:'Foo' |
2660 " |
2907 " |
2661 " |
2908 |
2662 Transcript topView application |
2909 ! |
2663 removeUserTool:'Bar' |
2910 |
2664 " |
2911 userAddedMenuItems |
2665 |
2912 "return a dictionary of user-added menu item infos. |
2666 ! |
2913 " |
2667 |
2914 |
2668 userAddedTools |
2915 ^ UserAddedMenuItems ? #() |
2669 "return a collection of user-added tools. |
2916 |
2670 " |
2917 |
2671 |
2918 ! |
2672 ^ UserAddedTools ? #() |
2919 |
|
2920 userAddedToolBarItems |
|
2921 "return a dictionary of user-added toolBar item infos. |
|
2922 " |
|
2923 |
|
2924 ^ UserAddedToolBarItems ? #() |
2673 |
2925 |
2674 |
2926 |
2675 ! ! |
2927 ! ! |
2676 |
2928 |
2677 !NewLauncher methodsFor:'private'! |
2929 !NewLauncher methodsFor:'private'! |