MenuEditor.st
changeset 2331 938a31972544
parent 2297 ee43ce83094d
child 2334 dc1388cc7160
equal deleted inserted replaced
2330:58ace5744c59 2331:938a31972544
   359 #fileNew
   359 #fileNew
   360 'Create a new menu spec.'
   360 'Create a new menu spec.'
   361 
   361 
   362 #filePickAMenu
   362 #filePickAMenu
   363 'Select a menu from an open view and read its specification'
   363 'Select a menu from an open view and read its specification'
       
   364 
       
   365 #fileChooseAMenu
       
   366 'Select a menu from an open view and edit its spec-method'
   364 
   367 
   365 #fileSave
   368 #fileSave
   366 'Save the menu spec (and the help spec, if modified).'
   369 'Save the menu spec (and the help spec, if modified).'
   367 
   370 
   368 #fileSaveAs
   371 #fileSaveAs
   927      (Menu new fromLiteralArrayEncoding:(MenuEditor fileMenu)) startUp
   930      (Menu new fromLiteralArrayEncoding:(MenuEditor fileMenu)) startUp
   928     "
   931     "
   929 
   932 
   930     <resource: #menu>
   933     <resource: #menu>
   931 
   934 
   932     ^
   935     ^ 
   933      #(Menu
   936      #(Menu
   934 	(
   937         (
   935 	 (MenuItem
   938          (MenuItem
   936 	    activeHelpKey: fileNew
   939             activeHelpKey: fileNew
   937 	    label: 'New'
   940             label: 'New'
   938 	    itemValue: doNew
   941             itemValue: doNew
   939 	    translateLabel: true
   942             translateLabel: true
   940 	  )
   943           )
   941 	 (MenuItem
   944          (MenuItem
   942 	    label: '-'
   945             label: '-'
   943 	  )
   946           )
   944 	 (MenuItem
   947          (MenuItem
   945 	    activeHelpKey: fileLoad
   948             activeHelpKey: fileLoad
   946 	    label: 'Load...'
   949             label: 'Load...'
   947 	    itemValue: doLoad
   950             itemValue: doLoad
   948 	    translateLabel: true
   951             translateLabel: true
   949 	  )
   952           )
   950 	 (MenuItem
   953          (MenuItem
   951 	    label: '-'
   954             label: '-'
   952 	  )
   955           )
   953 	 (MenuItem
   956          (MenuItem
   954 	    activeHelpKey: fileSave
   957             activeHelpKey: fileSave
   955 	    label: 'Save'
   958             label: 'Save'
   956 	    itemValue: doSave
   959             itemValue: doSave
   957 	    translateLabel: true
   960             translateLabel: true
   958 	  )
   961           )
   959 	 (MenuItem
   962          (MenuItem
   960 	    activeHelpKey: fileSaveAs
   963             activeHelpKey: fileSaveAs
   961 	    label: 'Save As...'
   964             label: 'Save As...'
   962 	    itemValue: doSaveAs
   965             itemValue: doSaveAs
   963 	    translateLabel: true
   966             translateLabel: true
   964 	  )
   967           )
   965 	 (MenuItem
   968          (MenuItem
   966 	    label: '-'
   969             label: '-'
   967 	  )
   970           )
   968 	 (MenuItem
   971          (MenuItem
   969 	    activeHelpKey: filePickAMenu
   972             activeHelpKey: filePickAMenu
   970 	    label: 'Pick a Menu...'
   973             label: 'Pick a Menu...'
   971 	    itemValue: doPickAMenu
   974             itemValue: doPickAMenu
   972 	    translateLabel: true
   975             translateLabel: true
   973 	  )
   976           )
   974 	 (MenuItem
   977          (MenuItem
   975 	    label: '-'
   978             activeHelpKey: fileChooseAMenu
   976 	    isVisible: isStandAlone
   979             label: 'Choose a Menu...'
   977 	  )
   980             itemValue: doChooseAMenu
   978 	 (MenuItem
   981             translateLabel: true
   979 	    activeHelpKey: fileBrowseClass
   982           )
   980 	    enabled: hasValidSpecClass
   983          (MenuItem
   981 	    label: 'Browse Class'
   984             label: '-'
   982 	    itemValue: doBrowseClass
   985             isVisible: isStandAlone
   983 	    translateLabel: true
   986           )
   984 	    isVisible: isStandAlone
   987          (MenuItem
   985 	  )
   988             activeHelpKey: fileBrowseClass
   986 	 (MenuItem
   989             enabled: hasValidSpecClass
   987 	    activeHelpKey: fileShowMenuSpec
   990             label: 'Browse Class'
   988 	    label: 'Show Menu Spec'
   991             itemValue: doBrowseClass
   989 	    itemValue: doShowMenuSpec
   992             translateLabel: true
   990 	    translateLabel: true
   993             isVisible: isStandAlone
   991 	    isVisible: isStandAlone
   994           )
   992 	  )
   995          (MenuItem
   993 	 (MenuItem
   996             activeHelpKey: fileShowMenuSpec
   994 	    label: '-'
   997             label: 'Show Menu Spec'
   995 	    isVisible: isStandAlone
   998             itemValue: doShowMenuSpec
   996 	  )
   999             translateLabel: true
   997 	 (MenuItem
  1000             isVisible: isStandAlone
   998 	    activeHelpKey: fileExit
  1001           )
   999 	    label: 'Exit'
  1002          (MenuItem
  1000 	    itemValue: closeRequest
  1003             label: '-'
  1001 	    translateLabel: true
  1004             isVisible: isStandAlone
  1002 	    isVisible: isStandAlone
  1005           )
  1003 	  )
  1006          (MenuItem
  1004 	 )
  1007             activeHelpKey: fileExit
  1005 	nil
  1008             label: 'Exit'
  1006 	nil
  1009             itemValue: closeRequest
       
  1010             translateLabel: true
       
  1011             isVisible: isStandAlone
       
  1012           )
       
  1013          )
       
  1014         nil
       
  1015         nil
  1007       )
  1016       )
  1008 !
  1017 !
  1009 
  1018 
  1010 generateMenu
  1019 generateMenu
  1011     "This resource specification was automatically generated
  1020     "This resource specification was automatically generated
  2519             createActionMethodFor:selector in:cls
  2528             createActionMethodFor:selector in:cls
  2520             category:category
  2529             category:category
  2521             redefine:(self redefineAspectMethodsChannel value).
  2530             redefine:(self redefineAspectMethodsChannel value).
  2522     ].
  2531     ].
  2523 
  2532 
  2524     UserPreferences current systemBrowserClass
  2533     UserPreferences current systemBrowse 
  2525         openInClass:cls selector:selector.
       
  2526 !
  2534 !
  2527 
  2535 
  2528 doGenerateAspectMethods
  2536 doGenerateAspectMethods
  2529     "compile aspect and action methods"
  2537     "compile aspect and action methods"
  2530 
  2538 
  2559     ].
  2567     ].
  2560 ! !
  2568 ! !
  2561 
  2569 
  2562 !MenuEditor methodsFor:'user actions-building'!
  2570 !MenuEditor methodsFor:'user actions-building'!
  2563 
  2571 
       
  2572 doChooseAMenu
       
  2573     "pick a menu and edit its spec method"
       
  2574 
       
  2575     |view subSpec app bldr spec menuSelector1 menuSelector2 info|
       
  2576 
       
  2577     self askForModification ifTrue:[
       
  2578         view := Screen current viewFromUser.
       
  2579         (view isNil or:[view == Screen current rootView]) ifTrue:[
       
  2580             ^ self
       
  2581         ].
       
  2582         view specClass == MenuPanelSpec ifTrue:[
       
  2583             (app := view application) isNil ifTrue:[
       
  2584                 info := 'Could not figure out the application class.'
       
  2585             ] ifFalse:[
       
  2586                 (bldr := app builder) isNil ifTrue:[ 
       
  2587                     info := 'Application has no builder.'
       
  2588                 ] ifFalse:[
       
  2589                     menuSelector1 := bldr namedComponents keyAtValue:view ifAbsent:nil.
       
  2590                     (spec := bldr spec) isNil ifTrue:[
       
  2591                         info := 'Cannot fetch spec from applications builder.'
       
  2592                     ] ifFalse:[
       
  2593                         subSpec := spec findSpecForWhich:[:subSpec | subSpec name = view name].
       
  2594                         subSpec isNil ifTrue:[
       
  2595                             info := 'Cannot find view-spec for ',view name asString,'.'
       
  2596                         ] ifFalse:[
       
  2597                             menuSelector2 := subSpec menu.
       
  2598                         ]
       
  2599                     ].
       
  2600                     (menuSelector1 isNil and:[ menuSelector2 isNil ]) ifTrue:[
       
  2601                         info := 'menu is probably not provided by a menuSelector.'
       
  2602                     ] ifFalse:[
       
  2603                         (app class respondsTo:menuSelector1) ifTrue:[
       
  2604                             self loadFromClass:app class andSelector:menuSelector1.
       
  2605                             ^ self.
       
  2606                         ].
       
  2607                         (app class respondsTo:menuSelector2) ifTrue:[
       
  2608                             self loadFromClass:app class andSelector:menuSelector2.
       
  2609                             ^ self.
       
  2610                         ].
       
  2611                         info := 'menu is probably not provided by a menuSelector.'
       
  2612                     ].
       
  2613                 ]
       
  2614             ].
       
  2615             info notNil ifTrue:[
       
  2616                 app notNil ifTrue:[
       
  2617                     (Dialog confirm:(info,'\\Browse ?' withCRs)) ifTrue:[
       
  2618                         app browse.
       
  2619                     ].
       
  2620                 ] ifFalse:[
       
  2621                     Dialog information:info.
       
  2622                 ].
       
  2623             ].
       
  2624             ^ self.
       
  2625         ].
       
  2626     ].
       
  2627 !
       
  2628 
  2564 doNew
  2629 doNew
  2565     "clear editing menu; start from scratch
  2630     "clear editing menu; start from scratch
  2566     "
  2631     "
  2567     super doNew ifTrue:[ self helpTool doNew ].
  2632     super doNew ifTrue:[ self helpTool doNew ].
  2568 !
  2633 !
  2569 
  2634 
  2570 doPickAMenu
  2635 doPickAMenu
  2571     "pick a menu from user"
  2636     "let user pick a menu and create a new spec"
  2572 
  2637 
  2573     |view|
  2638     |view|
  2574 
  2639 
  2575     self askForModification ifTrue:[
  2640     self askForModification ifTrue:[
  2576 	view := Screen current viewFromUser.
  2641         view := Screen current viewFromUser.
  2577 	(view isNil or:[view == Screen current rootView]) ifTrue:[
  2642         (view isNil or:[view == Screen current rootView]) ifTrue:[
  2578 	    ^ self
  2643             ^ self
  2579 	].
  2644         ].
  2580 	view specClass == MenuPanelSpec ifTrue:[
  2645         view specClass == MenuPanelSpec ifTrue:[
  2581 	    specSelector := #pickedMenu.
  2646             specSelector := #pickedMenu.
  2582 	    self buildFromMenu:(view asMenu) selector:specSelector.
  2647             self buildFromMenu:(view asMenu) selector:specSelector.
  2583 	].
  2648         ].
  2584     ].
  2649     ].
  2585 !
  2650 !
  2586 
  2651 
  2587 doSave
  2652 doSave
  2588     "save current editing menu to
  2653     "save current editing menu to