UIHelpTool.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2772 647f186ccb22
child 2933 a4f4d63953b3
permissions -rw-r--r--
category of:15 methods
cg@156
     1
"
cg@156
     2
 COPYRIGHT (c) 1995 by eXept Software AG
ca@1669
     3
	      All Rights Reserved
cg@156
     4
cg@156
     5
 This software is furnished under a license and may be used
cg@156
     6
 only in accordance with the terms of that license and with the
cg@156
     7
 inclusion of the above copyright notice.   This software may not
cg@156
     8
 be provided or otherwise made available to, or used by, any
cg@156
     9
 other person.  No title to or ownership of the software is
cg@156
    10
 hereby transferred.
cg@156
    11
"
cg@1554
    12
"{ Package: 'stx:libtool2' }"
cg@1554
    13
sv@1772
    14
ResourceSpecEditor subclass:#UIHelpTool
sv@1772
    15
	instanceVariableNames:'classItemList classItemModel keyItemModel helpTextView
sv@1772
    16
		modifiedHolder contentsModifiedChannel editModel'
ca@148
    17
	classVariableNames:''
ca@148
    18
	poolDictionaries:''
ca@148
    19
	category:'Interface-UIPainter'
ca@148
    20
!
ca@148
    21
ca@1669
    22
HierarchicalItem subclass:#ClassItem
ca@1669
    23
	instanceVariableNames:'theClass list modified'
ca@1669
    24
	classVariableNames:''
ca@1669
    25
	poolDictionaries:''
ca@1669
    26
	privateIn:UIHelpTool
ca@1669
    27
!
ca@1669
    28
ca@1669
    29
HierarchicalItem subclass:#KeyItem
cg@1681
    30
	instanceVariableNames:'helpKey helpText flyByText modified icon'
ca@1669
    31
	classVariableNames:''
ca@1669
    32
	poolDictionaries:''
ca@1669
    33
	privateIn:UIHelpTool
ca@1669
    34
!
ca@1669
    35
ca@148
    36
!UIHelpTool class methodsFor:'documentation'!
ca@148
    37
cg@156
    38
copyright
cg@156
    39
"
cg@156
    40
 COPYRIGHT (c) 1995 by eXept Software AG
ca@1669
    41
	      All Rights Reserved
cg@156
    42
cg@156
    43
 This software is furnished under a license and may be used
cg@156
    44
 only in accordance with the terms of that license and with the
cg@156
    45
 inclusion of the above copyright notice.   This software may not
cg@156
    46
 be provided or otherwise made available to, or used by, any
cg@156
    47
 other person.  No title to or ownership of the software is
cg@156
    48
 hereby transferred.
cg@156
    49
"
cg@156
    50
!
cg@156
    51
ca@148
    52
documentation
ca@148
    53
"
tz@779
    54
    The Help Tool allows you to define help dictionaries for the widgets in
tz@761
    55
    window applications. The tool are able to run stand alone or in other master 
tz@740
    56
    applications like the GUI Painter and the Menu Editor.
tz@740
    57
    If the application responds to the selector #showHelp:aHelpText for:aView,
tz@740
    58
    this selector is called by the widget's view when the mouse cursor moves over. 
tz@740
    59
    If the application does not responds to that selector, and the activeHelp mode
tz@740
    60
    is enabled, an active help bubble is shown at the widget's view.
cg@156
    61
tz@779
    62
    [instance variables:]
ca@1669
    63
	specClass       <Symbol>        class implementing the help spec
ca@1669
    64
	specSelector    <Symbol>        selector returning the help spec
ca@1669
    65
	classItemList                   the list of classItems
ca@1669
    66
	classItemModel                  keeps the selected class
ca@1669
    67
	keyItemModel                    keeps the selected helpKey
ca@1669
    68
	modifiedHolder  <ValueHolder>   true if the editField or contents changed
ca@1669
    69
	editModel                       keeps the current helpKey
ca@1669
    70
	helpTextView                    the view which shows the helpText
ca@1669
    71
	contentsModifiedChannel         true if the helpText is modified
tz@779
    72
cg@156
    73
    [author:]
ca@1669
    74
	Claus Atzkern, eXept Software AG
ca@1669
    75
	Thomas Zwick,  eXept Software AG
ca@148
    76
"
ca@148
    77
! !
ca@148
    78
ca@286
    79
!UIHelpTool class methodsFor:'instance creation'!
ca@286
    80
cg@832
    81
open
cg@833
    82
    ^ self openOnClass:nil.
cg@832
    83
!
cg@832
    84
ca@286
    85
openOnClass:aClass
ca@1669
    86
    "opens a Help Tool on aClass
ca@1669
    87
    "
ca@1646
    88
    ^ self openOnClass:aClass andSelector:#helpSpec
tz@750
    89
! !
tz@750
    90
ca@286
    91
!UIHelpTool class methodsFor:'constants'!
ca@286
    92
ca@286
    93
label
ca@1669
    94
    "returns the label; used if embedded as sub canvas in the GUI Painter or Menu Editor
ca@1669
    95
    "
tz@696
    96
    ^'Help'
ca@286
    97
! !
ca@286
    98
sv@1772
    99
!UIHelpTool class methodsFor:'defaults'!
sv@1772
   100
sv@1772
   101
resourceType
sv@1772
   102
    "get the type of the resource of the method generated by the UIHelpTool"
sv@1772
   103
sv@1772
   104
    ^ #help
sv@1772
   105
! !
sv@1772
   106
ca@151
   107
!UIHelpTool class methodsFor:'help specs'!
ca@151
   108
ca@151
   109
helpSpec
tz@740
   110
    "This resource specification was automatically generated
tz@740
   111
     by the UIHelpTool of ST/X."
tz@740
   112
tz@740
   113
    "Do not manually edit this!! If it is corrupted,
tz@740
   114
     the UIHelpTool may not be able to read the specification."
ca@292
   115
ca@172
   116
    "
tz@740
   117
     UIHelpTool openOnClass:UIHelpTool    
ca@292
   118
    "
ca@292
   119
tz@740
   120
    <resource: #help>
tz@740
   121
ca@1669
   122
    ^ super helpSpec addPairsFrom:#(
ca@151
   123
tz@696
   124
#addHelpTextKey
cg@1340
   125
'Adds the key to the help spec.'
tz@696
   126
tz@696
   127
#currentHelpTexts
tz@696
   128
'Selected help text key.'
tz@696
   129
tz@696
   130
#deleteHelpTextKey
cg@1340
   131
'Deletes the key from the help spec.'
cg@1340
   132
tz@750
   133
#fileLoad
tz@750
   134
'Opens a dialog for selecting and loading a help spec from a class.'
tz@750
   135
tz@750
   136
#fileSave
cg@1340
   137
'Saves the current help spec.'
cg@1340
   138
cg@1340
   139
#fileUpdate
cg@1340
   140
'Reload the help spec.'
tz@696
   141
tz@696
   142
#helpTextView
sv@1622
   143
'Shows the help text. Menu action ''Accept'' commits changes'
tz@696
   144
ca@1646
   145
#listOfClasses
cg@1340
   146
'Classes where help specs can be/are implemented.'
tz@696
   147
tz@696
   148
#listOfHelpTexts
cg@1340
   149
'List of help text keys.'
tz@696
   150
tz@696
   151
#removeHelpTextKey
cg@1340
   152
'Removes the help message from the widget.'
ca@151
   153
ca@1646
   154
#updateHelpTextKey
ca@1646
   155
'Refetch the help spec.'
ca@1646
   156
ca@172
   157
)
ca@151
   158
! !
ca@151
   159
ca@148
   160
!UIHelpTool class methodsFor:'interface specs'!
ca@148
   161
cg@1982
   162
innerSpec
tz@740
   163
    "This resource specification was automatically generated
tz@740
   164
     by the UIPainter of ST/X."
ca@148
   165
tz@740
   166
    "Do not manually edit this!! If it is corrupted,
tz@740
   167
     the UIPainter may not be able to read the specification."
ca@148
   168
ca@148
   169
    "
cg@1982
   170
     UIPainter new openOnClass:UIHelpTool andSelector:#innerSpec
cg@1982
   171
     UIHelpTool new openInterface:#innerSpec
ca@148
   172
    "
ca@148
   173
ca@148
   174
    <resource: #canvas>
ca@148
   175
ca@1302
   176
    ^ 
sv@1737
   177
     #(FullSpec
cg@1982
   178
        name: innerSpec
sv@1737
   179
        window: 
sv@1737
   180
       (WindowSpec
sv@1737
   181
          label: 'UIHelpTool'
sv@1737
   182
          name: 'UIHelpTool'
sv@1737
   183
          min: (Point 10 10)
cg@1973
   184
          bounds: (Rectangle 0 0 461 293)
sv@1737
   185
        )
sv@1737
   186
        component: 
sv@1737
   187
       (SpecCollection
sv@1737
   188
          collection: (
sv@1737
   189
           (VariableVerticalPanelSpec
sv@1737
   190
              name: 'PanelVrt'
sv@1737
   191
              layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
sv@1737
   192
              component: 
sv@1737
   193
             (SpecCollection
sv@1737
   194
                collection: (
sv@1737
   195
                 (VariableHorizontalPanelSpec
sv@1737
   196
                    name: 'PanelHrz'
sv@1737
   197
                    component: 
sv@1737
   198
                   (SpecCollection
sv@1737
   199
                      collection: (
sv@1737
   200
                       (HierarchicalListViewSpec
sv@1737
   201
                          name: 'keyItemModel'
sv@1737
   202
                          model: keyItemModel
sv@1737
   203
                          menu: keyItemMenu
sv@1737
   204
                          hasHorizontalScrollBar: true
sv@1737
   205
                          hasVerticalScrollBar: true
sv@1737
   206
                          miniScrollerHorizontal: true
sv@1737
   207
                          miniScrollerVertical: false
sv@1737
   208
                          listModel: keyItemListHolder
sv@1737
   209
                          useIndex: false
sv@1737
   210
                          highlightMode: label
sv@1737
   211
                          showLines: false
sv@1737
   212
                          showIndicators: false
sv@1737
   213
                          showLeftIndicators: false
sv@1737
   214
                          useDefaultIcons: false
sv@1737
   215
                          autoScrollHorizontal: false
sv@1737
   216
                        )
sv@1737
   217
                       (ViewSpec
sv@1737
   218
                          name: 'classItemList'
sv@1737
   219
                          component: 
sv@1737
   220
                         (SpecCollection
sv@1737
   221
                            collection: (
sv@1737
   222
                             (InputFieldSpec
sv@1737
   223
                                name: 'editModel'
sv@1737
   224
                                layout: (LayoutFrame 0 0.0 2 0 -1 1.0 25 0)
sv@1737
   225
                                activeHelpKey: currentHelpTexts
sv@1737
   226
                                model: editModel
sv@1737
   227
                                immediateAccept: true
sv@1737
   228
                                acceptOnReturn: false
sv@1737
   229
                                acceptOnTab: false
sv@1737
   230
                                acceptOnLostFocus: false
sv@1737
   231
                                acceptOnPointerLeave: false
sv@1737
   232
                              )
sv@1737
   233
                             (SelectionInListModelViewSpec
sv@1737
   234
                                name: 'classItemModel'
sv@1737
   235
                                layout: (LayoutFrame 0 0.0 27 0.0 0 1.0 0 1.0)
sv@1737
   236
                                model: classItemModel
sv@1737
   237
                                hasHorizontalScrollBar: true
sv@1737
   238
                                hasVerticalScrollBar: true
sv@1737
   239
                                miniScrollerHorizontal: true
sv@1737
   240
                                miniScrollerVertical: true
sv@1737
   241
                                autoHideScrollBars: false
sv@1737
   242
                                listModel: classItemListHolder
sv@1737
   243
                                useIndex: false
sv@1737
   244
                                highlightMode: label
sv@1737
   245
                              )
sv@1737
   246
                             )
ca@1646
   247
                           
sv@1737
   248
                          )
sv@1737
   249
                        )
sv@1737
   250
                       )
ca@1646
   251
                     
sv@1737
   252
                    )
sv@1737
   253
                    handles: (Any 0.607375 1.0)
sv@1737
   254
                  )
sv@1737
   255
                 (ArbitraryComponentSpec
sv@1737
   256
                    name: 'helpTextView'
sv@1737
   257
                    hasHorizontalScrollBar: true
sv@1737
   258
                    hasVerticalScrollBar: true
sv@1737
   259
                    miniScrollerHorizontal: true
sv@1737
   260
                    miniScrollerVertical: true
sv@1737
   261
                    hasBorder: false
sv@1737
   262
                    component: helpTextView
sv@1737
   263
                  )
sv@1737
   264
                 )
ca@1302
   265
               
sv@1737
   266
              )
sv@1737
   267
              handles: (Any 0.679181 1.0)
sv@1737
   268
            )
sv@1737
   269
           )
ca@1302
   270
         
sv@1737
   271
        )
ca@148
   272
      )
tz@696
   273
!
tz@696
   274
cg@1982
   275
windowSpec
tz@740
   276
    "This resource specification was automatically generated
tz@740
   277
     by the UIPainter of ST/X."
tz@696
   278
tz@740
   279
    "Do not manually edit this!! If it is corrupted,
tz@740
   280
     the UIPainter may not be able to read the specification."
tz@696
   281
tz@696
   282
    "
cg@1982
   283
     UIPainter new openOnClass:UIHelpTool andSelector:#windowSpec
cg@1982
   284
     UIHelpTool new openInterface:#windowSpec
cg@1982
   285
     UIHelpTool open
tz@696
   286
    "
tz@696
   287
tz@696
   288
    <resource: #canvas>
tz@696
   289
ca@1646
   290
    ^ 
sv@1737
   291
     #(FullSpec
cg@1982
   292
        name: windowSpec
sv@1737
   293
        window: 
sv@1737
   294
       (WindowSpec
sv@1737
   295
          label: 'Help Tool'
sv@1737
   296
          name: 'Help Tool'
sv@1737
   297
          min: (Point 300 300)
cg@1982
   298
          bounds: (Rectangle 0 0 498 429)
sv@1737
   299
          menu: menu
sv@1737
   300
        )
sv@1737
   301
        component: 
sv@1737
   302
       (SpecCollection
sv@1737
   303
          collection: (
cg@2002
   304
           (ViewSpec
cg@2002
   305
              name: 'mainPanel'
cg@2002
   306
              layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 -24 1.0)
cg@2002
   307
              component: 
cg@2002
   308
             (SpecCollection
cg@2002
   309
                collection: (
cg@2002
   310
                 (UISubSpecification
cg@2002
   311
                    name: 'innerSpec'
cg@2002
   312
                    layout: (LayoutFrame 0 0.0 0 0.0 0 1.0 -24 1.0)
cg@2002
   313
                    minorKey: innerSpec
cg@2002
   314
                  )
cg@2002
   315
                 (UISubSpecification
cg@2002
   316
                    name: 'windowSpecForCommit'
cg@2002
   317
                    layout: (LayoutFrame 0 0.0 -24 1.0 0 1.0 0 1.0)
cg@2002
   318
                    majorKey: ToolApplicationModel
cg@2002
   319
                    minorKey: windowSpecForCommit
cg@2002
   320
                  )
cg@2002
   321
                 )
cg@2002
   322
               
cg@2002
   323
              )
sv@1737
   324
            )
sv@1737
   325
           (UISubSpecification
cg@2002
   326
              name: 'infoBarSubSpec'
sv@1737
   327
              layout: (LayoutFrame 0 0 -24 1 0 1 0 1)
sv@1737
   328
              majorKey: ToolApplicationModel
sv@1737
   329
              minorKey: windowSpecForInfoBar
sv@1737
   330
            )
sv@1737
   331
           )
ca@1646
   332
         
sv@1737
   333
        )
tz@696
   334
      )
tz@696
   335
! !
tz@696
   336
tz@696
   337
!UIHelpTool class methodsFor:'menu specs'!
tz@696
   338
ca@1646
   339
helpTextMenu
ca@1646
   340
    "This resource specification was automatically generated
ca@1646
   341
     by the MenuEditor of ST/X."
ca@1646
   342
ca@1646
   343
    "Do not manually edit this!! If it is corrupted,
ca@1646
   344
     the MenuEditor may not be able to read the specification."
ca@1646
   345
ca@1646
   346
    "
ca@1646
   347
     MenuEditor new openOnClass:UIHelpTool andSelector:#helpTextMenu
ca@1646
   348
     (Menu new fromLiteralArrayEncoding:(UIHelpTool helpTextMenu)) startUp
ca@1646
   349
    "
ca@1646
   350
ca@1646
   351
    <resource: #menu>
ca@1646
   352
ca@1646
   353
    ^ 
ca@1646
   354
     #(#Menu
ca@1669
   355
	#(
ca@1669
   356
	 #(#MenuItem
ca@1669
   357
	    #activeHelpKey: #commitOK
ca@1669
   358
	    #enabled: #contentsModifiedChannel
ca@1669
   359
	    #label: 'Accept'
ca@1669
   360
	    #itemValue: #accept
ca@1669
   361
	    #translateLabel: true
ca@1669
   362
	  )
ca@1669
   363
	 #(#MenuItem
ca@1669
   364
	    #activeHelpKey: #commitCancel
ca@1669
   365
	    #enabled: #contentsModifiedChannel
ca@1669
   366
	    #label: 'Cancel'
ca@1669
   367
	    #itemValue: #cancel
ca@1669
   368
	    #translateLabel: true
ca@1669
   369
	  )
ca@1669
   370
	 )
ca@1669
   371
	nil
ca@1669
   372
	nil
ca@1669
   373
      )
ca@1669
   374
!
ca@1669
   375
ca@1669
   376
keyItemMenu
ca@1669
   377
    "This resource specification was automatically generated
ca@1669
   378
     by the MenuEditor of ST/X."
ca@1669
   379
ca@1669
   380
    "Do not manually edit this!! If it is corrupted,
ca@1669
   381
     the MenuEditor may not be able to read the specification."
ca@1669
   382
ca@1669
   383
    "
ca@1669
   384
     MenuEditor new openOnClass:UIHelpTool andSelector:#keyItemMenu
ca@1669
   385
     (Menu new fromLiteralArrayEncoding:(UIHelpTool keyItemMenu)) startUp
ca@1669
   386
    "
ca@1669
   387
ca@1669
   388
    <resource: #menu>
ca@1669
   389
ca@1669
   390
    ^ 
ca@1669
   391
     #(#Menu
ca@1669
   392
	#(
ca@1669
   393
	 #(#MenuItem
ca@1669
   394
	    #activeHelpKey: #deleteHelpTextKey
ca@1669
   395
	    #label: 'Delete'
ca@1669
   396
	    #itemValue: #doDelete
ca@1669
   397
	    #translateLabel: true
ca@1669
   398
	  )
ca@1669
   399
	 )
ca@1669
   400
	nil
ca@1669
   401
	nil
ca@1646
   402
      )
ca@1646
   403
!
ca@1646
   404
ca@1646
   405
listOfKeysMenu
ca@1646
   406
    "This resource specification was automatically generated
ca@1646
   407
     by the MenuEditor of ST/X."
ca@1646
   408
ca@1646
   409
    "Do not manually edit this!! If it is corrupted,
ca@1646
   410
     the MenuEditor may not be able to read the specification."
ca@1646
   411
ca@1646
   412
    "
ca@1646
   413
     MenuEditor new openOnClass:UIHelpTool andSelector:#listOfKeysMenu
ca@1646
   414
     (Menu new fromLiteralArrayEncoding:(UIHelpTool listOfKeysMenu)) startUp
ca@1646
   415
    "
ca@1646
   416
ca@1646
   417
    <resource: #menu>
ca@1646
   418
ca@1646
   419
    ^ 
ca@1646
   420
     #(#Menu
ca@1669
   421
	#(
ca@1669
   422
	 #(#MenuItem
ca@1669
   423
	    #activeHelpKey: #deleteHelpTextKey
ca@1669
   424
	    #label: 'Delete'
ca@1669
   425
	    #itemValue: #doDelete
ca@1669
   426
	    #translateLabel: true
ca@1669
   427
	  )
ca@1669
   428
	 )
ca@1669
   429
	nil
ca@1669
   430
	nil
ca@1646
   431
      )
ca@1646
   432
!
ca@1646
   433
tz@696
   434
menu
tz@740
   435
    "This resource specification was automatically generated
tz@740
   436
     by the MenuEditor of ST/X."
tz@696
   437
tz@740
   438
    "Do not manually edit this!! If it is corrupted,
tz@740
   439
     the MenuEditor may not be able to read the specification."
tz@696
   440
tz@696
   441
    "
tz@696
   442
     MenuEditor new openOnClass:UIHelpTool andSelector:#menu
tz@696
   443
     (Menu new fromLiteralArrayEncoding:(UIHelpTool menu)) startUp
tz@696
   444
    "
tz@696
   445
tz@696
   446
    <resource: #menu>
tz@696
   447
ca@1646
   448
    ^ 
ca@1775
   449
     #(Menu
ca@1775
   450
        (
ca@1775
   451
         (MenuItem
ca@1775
   452
            label: 'File'
ca@1775
   453
            translateLabel: true
ca@1775
   454
            submenu: 
ca@1775
   455
           (Menu
ca@1775
   456
              (
ca@1775
   457
               (MenuItem
cg@1973
   458
                  label: 'New'
cg@1973
   459
                  itemValue: doNew
cg@1973
   460
                  translateLabel: true
cg@1973
   461
                )
cg@1973
   462
               (MenuItem
cg@1973
   463
                  label: '-'
cg@1973
   464
                )
cg@1973
   465
               (MenuItem
ca@1775
   466
                  activeHelpKey: fileLoad
ca@1775
   467
                  label: 'Load...'
ca@1775
   468
                  itemValue: doLoad
ca@1775
   469
                  translateLabel: true
ca@1775
   470
                )
ca@1775
   471
               (MenuItem
ca@1775
   472
                  activeHelpKey: fileSave
ca@1775
   473
                  label: 'Save'
ca@1775
   474
                  itemValue: doSave
ca@1775
   475
                  translateLabel: true
ca@1775
   476
                )
ca@1775
   477
               (MenuItem
ca@1775
   478
                  label: '-'
cg@1982
   479
                  isVisible: isStandAlone
ca@1775
   480
                )
ca@1775
   481
               (MenuItem
ca@1775
   482
                  activeHelpKey: fileExit
ca@1775
   483
                  label: 'Exit'
ca@1775
   484
                  itemValue: closeRequest
ca@1775
   485
                  translateLabel: true
cg@1982
   486
                  isVisible: isStandAlone
ca@1775
   487
                )
ca@1775
   488
               )
ca@1775
   489
              nil
ca@1775
   490
              nil
ca@1775
   491
            )
ca@1775
   492
          )
ca@1775
   493
         (MenuItem
ca@1775
   494
            label: 'Edit'
ca@1775
   495
            translateLabel: true
ca@1775
   496
            submenuChannel: keyItemMenu
ca@1775
   497
            keepLinkedMenu: true
ca@1775
   498
          )
ca@1775
   499
         (MenuItem
cg@1973
   500
            label: 'History'
cg@1973
   501
            translateLabel: true
cg@1982
   502
            isVisible: isStandAlone
cg@1973
   503
            submenuChannel: menuHistory
cg@1973
   504
          )
cg@1973
   505
         (MenuItem
cg@2665
   506
            label: 'MENU_Help'
ca@1775
   507
            translateLabel: true
cg@2127
   508
            startGroup: conditionalRight
ca@1775
   509
            submenuChannel: menuHelp
ca@1775
   510
          )
ca@1775
   511
         )
ca@1775
   512
        nil
ca@1775
   513
        nil
tz@696
   514
      )
ca@148
   515
! !
ca@148
   516
ca@148
   517
!UIHelpTool methodsFor:'accessing'!
ca@148
   518
ca@1669
   519
helpKey
ca@1669
   520
    "returns the helpKey as symbol or nil
ca@1669
   521
    "
ca@1669
   522
    |key|
tz@779
   523
ca@1669
   524
    key := editModel value.
tz@710
   525
ca@1669
   526
    key size ~~ 0 ifTrue:[
ca@1669
   527
	key := key withoutSeparators.
ca@1669
   528
	key notEmpty ifTrue:[ ^ key asSymbol ]
ca@286
   529
    ].
ca@286
   530
    ^ nil
ca@286
   531
!
ca@286
   532
ca@286
   533
helpKey:aKey
ca@1669
   534
    "change the helpKey without any change notification (modifiedHolder).
ca@1669
   535
    "
ca@286
   536
    |key|
ca@1646
   537
ca@1669
   538
    self withoutModifyDo:[
ca@1669
   539
	aKey size ~~ 0 ifTrue:[
ca@1669
   540
	    key := aKey withoutSeparators.
ca@1669
   541
	    key isEmpty ifTrue:[ key := nil ]
ca@1669
   542
	] ifFalse:[
ca@1669
   543
	    key := nil
ca@1669
   544
	].
ca@1669
   545
	editModel value:key.
ca@286
   546
    ].
ca@1646
   547
    self cancel.
ca@151
   548
!
ca@151
   549
tz@740
   550
modified
cg@2020
   551
    "true if any items are added, deleted or modified
cg@2020
   552
    "
cg@2020
   553
    classItemList do:[:aClassItem|
cg@2020
   554
	aClassItem modified ifTrue:[^ true].
cg@2020
   555
    ].
cg@2020
   556
    ^ false
tz@700
   557
!
tz@700
   558
ca@1669
   559
modified:aBoolean
ca@1669
   560
    "true if any items are added, deleted or modified
ca@1646
   561
    "
ca@1669
   562
    classItemList do:[:aClassItem| aClassItem modified:aBoolean ].
ca@1669
   563
!
ca@1669
   564
ca@1669
   565
modifiedHolder
ca@1669
   566
    "boolean holder which is set to true if the helpKey or contents changed
ca@1669
   567
    "
ca@1669
   568
    ^ modifiedHolder
tz@700
   569
!
tz@700
   570
ca@286
   571
modifiedHolder:aValueHolder
ca@1669
   572
    "boolean holder which is set to true if the helpKey or contents changed
ca@1669
   573
    "
ca@286
   574
    modifiedHolder notNil ifTrue:[
ca@1669
   575
	modifiedHolder removeDependent:self. 
ca@286
   576
    ].
ca@1646
   577
    modifiedHolder := aValueHolder.
ca@148
   578
ca@1646
   579
    modifiedHolder notNil ifTrue:[
ca@1669
   580
	modifiedHolder addDependent:self.
ca@1669
   581
    ].
ca@1604
   582
!
ca@1604
   583
tz@715
   584
specClass
ca@1669
   585
    "returns the class on which the help tool works on
ca@1646
   586
    "
ca@1646
   587
    ^ specClass
ca@1646
   588
!
tz@779
   589
ca@1646
   590
specSelector
cg@1681
   591
    "returns the selector of the edited helpSpec method
ca@1646
   592
    "
cg@1681
   593
    ^ specSelector ? #helpSpec
cg@354
   594
! !
cg@354
   595
ca@148
   596
!UIHelpTool methodsFor:'aspects'!
ca@148
   597
ca@1669
   598
classItemListHolder
ca@1669
   599
    "returns the holder which keeps the class items
ca@1669
   600
    "
ca@1669
   601
    |holder|
ca@1669
   602
ca@1669
   603
    holder := builder bindingAt:#classItemListHolder.
ca@1669
   604
ca@1669
   605
    holder isNil ifTrue:[
ca@1669
   606
	holder := nil asValue.
ca@1669
   607
	holder value:classItemList.
ca@1669
   608
	builder aspectAt:#classItemListHolder put:holder.
ca@1669
   609
    ].
ca@1669
   610
    ^ holder
ca@1669
   611
!
ca@1669
   612
ca@1669
   613
classItemModel
ca@1669
   614
    "returns the holder which keeps the current selected class
ca@1669
   615
    "
ca@1669
   616
    ^ classItemModel
ca@1669
   617
!
ca@1669
   618
ca@1646
   619
contentsModifiedChannel
ca@1669
   620
    "boolean holder, which is set to true if the contents assigned to the
ca@1669
   621
     helpKey changed
ca@1646
   622
    "
ca@1646
   623
    ^ contentsModifiedChannel
ca@148
   624
!
ca@148
   625
ca@1646
   626
editModel
ca@1669
   627
    "string holder, which keeps the current editing helpKey as string
ca@1646
   628
    "
ca@1669
   629
    ^ editModel.
tz@696
   630
!
tz@696
   631
cg@1989
   632
enablingCommitButtonsHolder
cg@1989
   633
    "returns the enabling of the commit of this tool as value holder"
cg@1989
   634
cg@1989
   635
    masterApplication notNil ifTrue:[
cg@1989
   636
        ^ masterApplication enablingCommitButtonsHolder
cg@1989
   637
    ].
cg@1989
   638
    ^ contentsModifiedChannel
cg@1989
   639
!
cg@1989
   640
ca@1669
   641
helpTextView
ca@1669
   642
    "the editView which keeps the current help contents assigned to the key
ca@1646
   643
    "
ca@1669
   644
    ^ helpTextView
tz@696
   645
!
tz@696
   646
cg@1989
   647
infoLabelHolder
cg@1989
   648
    "returns the info label as value holder"
cg@1989
   649
cg@1989
   650
    masterApplication notNil ifTrue:[
cg@2037
   651
        builder aspectAt:#useAlienInfoLabelHolder put:true.
cg@1989
   652
        ^ masterApplication infoLabelHolder
cg@1989
   653
    ].
cg@1989
   654
    ^ super infoLabelHolder
cg@1989
   655
!
cg@1989
   656
ca@1669
   657
keyItemListHolder
ca@1669
   658
    "holder, which keeps the current hierarchical list
ca@1669
   659
     assigned to the selected class item
ca@1646
   660
    "
ca@1669
   661
    |holder|
ca@1669
   662
ca@1669
   663
    holder := builder bindingAt:#keyItemListHolder.
ca@1669
   664
ca@1669
   665
    holder isNil ifTrue:[
ca@1669
   666
	holder := nil asValue.
ca@1669
   667
	holder value:(classItemList last list).
ca@1669
   668
	builder aspectAt:#keyItemListHolder put:holder.
ca@1669
   669
    ].
ca@1669
   670
    ^ holder
ca@1646
   671
!
tz@779
   672
ca@1669
   673
keyItemModel
ca@1669
   674
    "model which keeps the current selected helpKey or nil
ca@1646
   675
    "
ca@1669
   676
    ^ keyItemModel.
ca@148
   677
! !
ca@148
   678
tz@750
   679
!UIHelpTool methodsFor:'building'!
tz@750
   680
ca@1663
   681
buildAndMergeFromClass:aClass
ca@1669
   682
     "setup a new specClass, merge the current items into
ca@1669
   683
     "
ca@1669
   684
     |root mergeItems|
ca@1663
   685
ca@1669
   686
     root := classItemList first.
ca@1663
   687
ca@1669
   688
     root isUnspecified ifTrue:[ mergeItems := root children ]
cg@1973
   689
                       ifFalse:[ mergeItems := nil ].
ca@1663
   690
cg@1973
   691
     self loadFromClass:aClass.
ca@1669
   692
ca@1669
   693
     mergeItems size ~~ 0 ifTrue:[
cg@1973
   694
        root := classItemList first.
ca@1669
   695
cg@1973
   696
        mergeItems do:[:anItem| |item hkey|
cg@1973
   697
            hkey := anItem helpKey.
cg@1973
   698
            item := root detectItemWithKey:hkey.
ca@1669
   699
cg@1973
   700
            item isNil ifTrue:[
cg@1973
   701
                item := KeyItem helpKey:hkey helpText:(anItem helpText).
cg@1973
   702
                root add:item sortBlock:[:a :b| a label < b label ].
cg@1973
   703
            ] ifFalse:[
cg@1973
   704
                item helpText:(anItem helpText).
cg@1973
   705
            ]
cg@1973
   706
        ]
ca@1663
   707
    ].
ca@1663
   708
!
ca@1663
   709
cg@1973
   710
loadFromClass:aClass
tz@779
   711
    "reads the help dictionary from aClass and find remaining classes 
ca@1669
   712
     'between' aClass and ApplicationModel
ca@1669
   713
    " 
cg@1973
   714
    |lastContents root list helpSpecSelector|
tz@779
   715
cg@1681
   716
    helpSpecSelector := self specSelector.
ca@1646
   717
    specClass := self getHelpSpecClassFromClass:aClass.
ca@1646
   718
ca@1669
   719
    list := OrderedCollection new.
ca@1669
   720
ca@1669
   721
    (specClass isClass and:[specClass isLoaded]) ifTrue:[
ca@1670
   722
        lastContents := nil.
cg@1973
   723
cg@1973
   724
        self addHistoryEntryForClass:specClass selector:helpSpecSelector.
ca@1669
   725
ca@1670
   726
        specClass withAllSuperclasses reverse do:[:aClass| |value name|
ca@1670
   727
            lastContents isNil ifTrue:[
ca@1670
   728
                aClass == ApplicationModel ifTrue:[ 
ca@1670
   729
                    lastContents := IdentityDictionary new
ca@1670
   730
                ].
ca@1670
   731
            ] ifFalse:[
ca@1670
   732
                root := ClassItem onClass:aClass.
ca@1669
   733
cg@1973
   734
                (aClass respondsTo: helpSpecSelector) ifTrue:[ 
cg@1973
   735
                    value := aClass perform: helpSpecSelector.
cg@1973
   736
                ].
ca@1669
   737
cg@1973
   738
                value notNil ifTrue:[
ca@1670
   739
                    value keysAndValuesDo:[:k :v| |cval|
ca@1670
   740
                        cval := lastContents at:k ifAbsent:self.
ca@1670
   741
                        cval = v ifFalse:[ root add:(KeyItem helpKey:k helpText:v) ].
ca@1670
   742
                    ].
ca@1670
   743
                    lastContents := value.
ca@1670
   744
                ].
ca@1670
   745
                root sort:[:a :b| a label < b label ].
ca@1670
   746
                root modified:false.
ca@1670
   747
                list add:root.
ca@1670
   748
            ]
ca@1670
   749
        ]
ca@1669
   750
    ].
ca@1669
   751
    list isEmpty ifTrue:[
ca@1670
   752
        list add:(ClassItem onClass:nil)
ca@1646
   753
    ].
ca@1646
   754
ca@1669
   755
    self withoutModifyDo:[
ca@1670
   756
        classItemList contents:list.
ca@1670
   757
        self updateIcons.
ca@1670
   758
        classItemModel value:(list last)
ca@1646
   759
    ].
cg@1340
   760
!
cg@1340
   761
cg@1973
   762
loadFromClass:aClass andSelector:aSelector
cg@1973
   763
    "reads the help dictionary from aClass"
cg@1973
   764
cg@1973
   765
    self assert:(aClass isNil or:[aClass isClass]).
cg@1973
   766
cg@1340
   767
    specSelector := aSelector.
cg@1973
   768
    self loadFromClass:aClass
cg@1340
   769
!
cg@1340
   770
cg@1973
   771
loadFromHelpTool:aHelpTool
ca@1669
   772
    "build from another helpTool
ca@1669
   773
    "
ca@1669
   774
    specClass     := aHelpTool specClass.
ca@1669
   775
    specSelector  := aHelpTool specSelector.
ca@1669
   776
    classItemList := aHelpTool classItemListHolder value.
cg@1340
   777
ca@1669
   778
    self classItemListHolder value:classItemList.
cg@1340
   779
ca@1669
   780
    classItemModel triggerValue:(classItemList last).
ca@1646
   781
! !
ca@1646
   782
ca@1646
   783
!UIHelpTool methodsFor:'change & update'!
ca@1646
   784
ca@1646
   785
editModelChanged
ca@1669
   786
    "called if the editModel changed
ca@1646
   787
    "
ca@1646
   788
    |key|
ca@1646
   789
ca@1646
   790
    key := self helpKey.
ca@1646
   791
ca@1669
   792
    modifiedHolder notNil ifTrue:[
cg@1989
   793
        modifiedHolder value:true
ca@1669
   794
    ].
ca@1646
   795
ca@1669
   796
    contentsModifiedChannel value:false.
ca@1646
   797
ca@1646
   798
    key notNil ifTrue:[
cg@1989
   799
        keyItemModel value = key ifTrue:[^ self].
ca@1646
   800
cg@1989
   801
        classItemList reverseDo:[:root| |item|
cg@1989
   802
            item := root detectItemWithKey:key.
ca@1669
   803
cg@1989
   804
            item notNil ifTrue:[
cg@1989
   805
                classItemModel value:root.
cg@1989
   806
                keyItemModel   value:item.
cg@1989
   807
                ^ self.
cg@1989
   808
            ].
cg@1989
   809
        ].
ca@1669
   810
cg@1989
   811
        masterApplication isNil ifTrue:[
cg@1989
   812
            "entered a new helpKey
cg@1989
   813
            "
cg@1989
   814
            self enablingCommitButtonsHolder value:true.
cg@1989
   815
        ].
tz@750
   816
    ].
ca@1669
   817
    keyItemModel value:nil.
ca@1646
   818
!
cg@963
   819
ca@1646
   820
update:something with:aParameter from:changedObject
ca@1669
   821
    "Invoked when an object that I depend upon sends a change notification.
ca@1669
   822
    "
ca@1669
   823
    |root item list|
cg@963
   824
ca@1669
   825
    changedObject == keyItemModel ifTrue:[
ca@1669
   826
	item := keyItemModel value.
ca@1669
   827
ca@1669
   828
	item notNil ifTrue:[
ca@1669
   829
	    editModel value:(item helpKey).
ca@1669
   830
	].
ca@1669
   831
	self cancel.
ca@1669
   832
	^ self
tz@750
   833
    ].
tz@750
   834
ca@1669
   835
    changedObject == classItemModel ifTrue:[
ca@1669
   836
	root := classItemModel value.
ca@1669
   837
ca@1669
   838
	root notNil ifTrue:[
ca@1669
   839
	    item := root detectItemWithKey:(self helpKey).
ca@1669
   840
	    list := root list.
ca@1669
   841
	] ifFalse:[
ca@1669
   842
	    list := item := nil.
ca@1669
   843
	].
ca@1669
   844
ca@1669
   845
	item notNil ifTrue:[
ca@1669
   846
	    keyItemModel value:nil withoutNotifying:self.
ca@1669
   847
	].
ca@1669
   848
	self keyItemListHolder value:list.
ca@1669
   849
	keyItemModel value:item.
ca@1669
   850
	^ self
ca@1646
   851
    ].
tz@750
   852
ca@1669
   853
    changedObject == editModel ifTrue:[
ca@1669
   854
	self editModelChanged.
ca@1669
   855
	^ self
ca@1646
   856
    ].
ca@148
   857
ca@1669
   858
    changedObject == contentsModifiedChannel ifTrue:[
ca@1669
   859
	modifiedHolder notNil ifTrue:[
ca@1669
   860
	    modifiedHolder value:true
ca@1669
   861
	].
ca@1669
   862
	^ self
ca@1646
   863
    ].
ca@1669
   864
    super update:something with:aParameter from:changedObject
ca@1669
   865
!
tz@779
   866
ca@1669
   867
withoutModifyDo:aBlock
ca@1669
   868
    "discard modifications; trigger not the modifiedHolder during
sv@1723
   869
     the action is active"
sv@1723
   870
ca@1669
   871
    |holder|
ca@286
   872
sv@1723
   873
    modifiedHolder isNil ifTrue:[
sv@1723
   874
        ^ aBlock value
sv@1723
   875
    ].
ca@1669
   876
    holder := modifiedHolder.
sv@1723
   877
    ^ aBlock ensure:[modifiedHolder := holder]
tz@750
   878
! !
tz@750
   879
ca@286
   880
!UIHelpTool methodsFor:'private'!
ca@286
   881
cg@1973
   882
getHelpSpecClassFromClass:aClass
cg@1973
   883
    |cls|
tz@696
   884
cg@1973
   885
    aClass isNil ifTrue:[^ nil].
tz@779
   886
cg@1973
   887
    cls := self resolveName:aClass.
cg@1973
   888
    cls isNil ifTrue:[ ^ nil ].
tz@696
   889
cg@1973
   890
    cls := cls perform:#helpSpecClass ifNotUnderstood:cls.
ca@1646
   891
cg@1973
   892
    (cls isBehavior and:[cls isLoaded]) ifTrue:[
cg@1973
   893
        ^ cls
tz@696
   894
    ].
ca@1669
   895
    ^ nil
tz@696
   896
!
tz@696
   897
cg@1973
   898
loadFromMessage:classAndSelector
ca@1669
   899
    "Set and rebuild the specClass and specSelector from a resource string.
ca@1669
   900
     On success true is returned otherwise false. If the current spec is
cg@1973
   901
     modified, a dialog is launched."
tz@761
   902
cg@1973
   903
    self askForModification ifFalse:[ ^ false].
cg@896
   904
cg@1973
   905
    classAndSelector notNil ifTrue:[
cg@1973
   906
        self loadFromClass:(classAndSelector methodClass) andSelector:(classAndSelector methodSelector).
cg@1973
   907
        ^ true
tz@740
   908
    ].
ca@1669
   909
    ^ false
ca@1670
   910
!
ca@1670
   911
ca@1670
   912
updateIcons
ca@1670
   913
    "update all icons (redefinitions below above or both)
ca@1670
   914
    "
ca@1670
   915
    |iconBelow iconAbove iconAboveAndBelow isBehind redefinedAbove redefinedBelow icon|
ca@1670
   916
ca@1670
   917
    "/ if only one class exists, its not possible to have redefinitions
ca@1670
   918
    classItemList size > 1 ifFalse:[ ^ self ].
ca@1670
   919
ca@1670
   920
    iconBelow         := SystemBrowser medium_methodRedefinedBelowIcon.
ca@1670
   921
    iconAbove         := SystemBrowser medium_methodInheritedFromAboveIcon.
ca@1670
   922
    iconAboveAndBelow := SystemBrowser medium_methodInheritedFromAboveAndRedefinedBelowIcon.
ca@1670
   923
ca@1670
   924
    classItemList do:[:runClass|
ca@1670
   925
        runClass do:[:aKeyItem|
ca@1670
   926
            isBehind := redefinedBelow := redefinedAbove := false.
ca@1670
   927
ca@1670
   928
            classItemList do:[:testClass|
ca@1670
   929
                testClass == runClass ifTrue:[
ca@1670
   930
                    isBehind := true
ca@1670
   931
                ] ifFalse:[
ca@1670
   932
                    (testClass detectItemWithKey:(aKeyItem helpKey)) notNil ifTrue:[
ca@1670
   933
                        isBehind ifTrue:[ redefinedBelow := true ]
ca@1670
   934
                                ifFalse:[ redefinedAbove := true ].
ca@1670
   935
                    ]
ca@1670
   936
                ]
ca@1670
   937
            ].
ca@1670
   938
ca@1670
   939
            redefinedBelow ifTrue:[
ca@1670
   940
                redefinedAbove ifTrue:[ icon := iconAboveAndBelow ]
ca@1670
   941
                              ifFalse:[ icon := iconBelow ]
ca@1670
   942
            ] ifFalse:[
ca@1670
   943
                redefinedAbove ifTrue:[ icon := iconAbove ]
ca@1670
   944
                              ifFalse:[ icon := nil ]
ca@1670
   945
            ].
ca@1670
   946
            aKeyItem icon:icon.
ca@1670
   947
        ]
ca@1670
   948
    ].
ca@286
   949
! !
ca@286
   950
ca@1669
   951
!UIHelpTool methodsFor:'startup & release'!
ca@369
   952
ca@369
   953
closeRequest
sv@1772
   954
    "asks for permission before closing"
sv@1772
   955
sv@1772
   956
    masterApplication isNil ifTrue:[
sv@1772
   957
        super closeRequest.
ca@1669
   958
    ].
tz@740
   959
!
tz@740
   960
cg@2002
   961
commonPostBuild
cg@2002
   962
    "/ using masters infoHolder ?
cg@2002
   963
    (builder aspectAt:#useAlienInfoLabelHolder) == true ifTrue:[
cg@2002
   964
        (builder componentAt:#mainPanel) layout bottomOffset:0.
cg@2002
   965
        (builder componentAt:#infoBarSubSpec) beInvisible
cg@2002
   966
    ]
cg@2002
   967
!
cg@2002
   968
tz@740
   969
initialize
ca@1669
   970
    "setup default attributes
ca@1669
   971
    "
ca@1669
   972
    super initialize.
ca@1669
   973
    self createBuilder.
tz@779
   974
ca@1669
   975
    specSelector   := #helpSpec.
tz@740
   976
ca@1669
   977
    classItemList  := List new.
ca@1669
   978
ca@1669
   979
    classItemModel := nil asValue.
ca@1669
   980
    classItemModel addDependent:self.
ca@1669
   981
ca@1669
   982
    keyItemModel := nil asValue.
ca@1669
   983
    keyItemModel addDependent:self.
ca@1669
   984
ca@1669
   985
    contentsModifiedChannel := false asValue.
ca@1669
   986
    contentsModifiedChannel addDependent:self.
ca@1669
   987
ca@1669
   988
    helpTextView := EditTextView new.
ca@1669
   989
    helpTextView acceptAction:[:dummy| self accept ].
ca@1669
   990
    helpTextView modifiedChannel:contentsModifiedChannel.
tz@740
   991
ca@1646
   992
    editModel := nil asValue.
ca@1646
   993
    editModel addDependent:self.
ca@1646
   994
cg@1973
   995
    self loadFromClass:nil.
tz@750
   996
!
tz@750
   997
tz@750
   998
openOnClass:aClass
ca@1669
   999
    "opens the UIHelpTool on aClass
ca@1669
  1000
    "
cg@1597
  1001
    self openOnClass:aClass andSelector:nil
tz@940
  1002
!
tz@940
  1003
tz@940
  1004
openOnClass:aClass andSelector: aSelector
tz@940
  1005
    "opens the UIHelpTool on aClass and aSelector"
tz@940
  1006
cg@1982
  1007
    self openInterface:#windowSpec "ForStandAlone".
cg@1597
  1008
cg@1973
  1009
    builder window label:'Help Tool'.
cg@1973
  1010
    self loadFromClass:aClass andSelector:aSelector
ca@369
  1011
! !
ca@369
  1012
tz@740
  1013
!UIHelpTool methodsFor:'user actions'!
ca@286
  1014
tz@722
  1015
accept
ca@1669
  1016
    "accepts the help text
ca@1669
  1017
    "
ca@1669
  1018
    |helpKey helpItem root|
tz@779
  1019
ca@1669
  1020
    helpKey := self helpKey.
ca@1669
  1021
    helpKey isNil ifTrue:[^ self].
tz@722
  1022
ca@1669
  1023
    root := classItemModel value.
ca@1669
  1024
    root isNil ifTrue:[^ self].
tz@722
  1025
ca@1669
  1026
    helpItem := root detectItemWithKey:helpKey.
cg@1648
  1027
ca@1669
  1028
    helpItem isNil ifTrue:[
ca@1670
  1029
        helpItem := KeyItem helpKey:helpKey helpText:(helpTextView contents).
ca@1670
  1030
        root add:helpItem sortBlock:[:a :b| a label < b label ].
ca@1670
  1031
        self updateIcons.
ca@1669
  1032
    ] ifFalse:[
ca@1670
  1033
        helpItem helpText:(helpTextView contents).
ca@1646
  1034
    ].
ca@1646
  1035
ca@1669
  1036
    contentsModifiedChannel value:false.
ca@1669
  1037
    keyItemModel triggerValue:helpItem.
tz@722
  1038
!
tz@722
  1039
ca@1646
  1040
cancel
cg@2069
  1041
    "cancel modifications, reload helpText"
cg@2069
  1042
ca@1669
  1043
    |item contents modified|
tz@779
  1044
ca@1669
  1045
    item := keyItemModel value.
ca@1669
  1046
    modified := false.
cg@835
  1047
ca@1669
  1048
    item notNil ifTrue:[
cg@2069
  1049
        contents := item helpText.
ca@1669
  1050
    ] ifFalse:[
cg@2069
  1051
        contents := nil.
ca@1669
  1052
cg@2069
  1053
        modifiedHolder isNil ifTrue:[
cg@2069
  1054
            modified := self helpKey notNil
cg@2069
  1055
        ]
ca@1646
  1056
    ].
ca@1669
  1057
    helpTextView contents:contents.
ca@1669
  1058
    contentsModifiedChannel value:modified.
cg@2069
  1059
cg@2069
  1060
    "Modified: / 29-08-2006 / 10:20:37 / cg"
tz@722
  1061
!
tz@722
  1062
tz@750
  1063
doDelete
ca@1646
  1064
    "deletes the selected help key
ca@1646
  1065
    "
ca@1669
  1066
    |item|
tz@779
  1067
ca@1669
  1068
    item := keyItemModel value.
ca@1670
  1069
ca@1670
  1070
    item notNil ifTrue:[
ca@1670
  1071
        item remove.
ca@1670
  1072
        item icon notNil ifTrue:[ self updateIcons ].
ca@1670
  1073
    ].    
ca@1669
  1074
    editModel value:nil.
tz@722
  1075
!
tz@722
  1076
tz@750
  1077
doLoad
cg@1973
  1078
    "opens a Resource Selection Browser in order to get a resource message"
cg@1973
  1079
tz@750
  1080
    self loadFromMessage: 
cg@1681
  1081
        (ResourceSelectionBrowser
cg@1681
  1082
            request: 'Load Help Spec From Class'
cg@1681
  1083
            onSuperclass: nil
cg@1681
  1084
            andClass: specClass
cg@1681
  1085
            andSelector: (self specSelector)
cg@1681
  1086
            withResourceTypes: (Array with: #help)).
tz@779
  1087
tz@779
  1088
    self updateInfoLabel
tz@750
  1089
!
tz@750
  1090
tz@750
  1091
doNew
ca@1669
  1092
    "reset all to empty
ca@1669
  1093
    "
ca@1669
  1094
    contentsModifiedChannel value:false.
ca@1669
  1095
    self helpKey:nil.
cg@1973
  1096
    self loadFromClass:nil.
tz@750
  1097
!
tz@750
  1098
tz@722
  1099
doSave
cg@1973
  1100
    "save the help spec to the spec-class(es)"
cg@1973
  1101
ca@1669
  1102
    specClass isNil ifTrue:[
ca@1669
  1103
        self information:(resources string:'No class specified !!').
ca@1669
  1104
        ^ nil
ca@1669
  1105
    ].
cg@1777
  1106
"/ cg: the following test is rubbish !!
cg@1777
  1107
"/    (specClass isSubclassOf:ApplicationModel) ifFalse:[
cg@1777
  1108
"/        self information:(resources string:'Cannot save help into non-Application class').
cg@1777
  1109
"/        ^ nil
cg@1777
  1110
"/    ].
tz@779
  1111
cg@1681
  1112
    classItemList do:[:aClassItem| 
cg@1681
  1113
        aClassItem createHelpMethodNamed:(self specSelector) 
cg@1681
  1114
    ].
ca@1669
  1115
!
ca@1669
  1116
cg@2020
  1117
openDocumentation
cg@2020
  1118
    "opens the documentation file of the Help Tool
cg@2020
  1119
    "
cg@2020
  1120
    self openHTMLDocument: 'tools/uipainter/HelpTool.html'
cg@2020
  1121
! !
ca@1669
  1122
cg@2020
  1123
!UIHelpTool::ClassItem class methodsFor:'instance creation'!
cg@2020
  1124
cg@2020
  1125
onClass:aClass
cg@2020
  1126
    |root|
cg@2020
  1127
cg@2020
  1128
    root := self new.
cg@2020
  1129
    root onClass:aClass.
cg@2020
  1130
    ^ root
cg@2020
  1131
! !
cg@2020
  1132
cg@2020
  1133
!UIHelpTool::ClassItem methodsFor:'accessing'!
ca@1669
  1134
ca@1669
  1135
list
ca@1669
  1136
    "returns the hierarchical list assigned to the classItem; the
ca@1669
  1137
     list contains the keyItems
ca@1669
  1138
    "
ca@1669
  1139
    list isNil ifTrue:[
ca@1669
  1140
	list := HierarchicalList new.
ca@1669
  1141
	list showRoot:false.
ca@1669
  1142
	list root:self.
ca@1669
  1143
    ].
ca@1669
  1144
    ^ list
ca@1669
  1145
!
ca@1669
  1146
ca@1669
  1147
theClass
ca@1669
  1148
    "returns the class or nil if unspecified
ca@1669
  1149
    "
ca@1669
  1150
    ^ theClass
ca@1669
  1151
! !
ca@1669
  1152
cg@2020
  1153
!UIHelpTool::ClassItem methodsFor:'change & update'!
ca@1669
  1154
ca@1669
  1155
helpTextChangedFor:anItem
ca@1669
  1156
    "called if an helpKey changed its contents
ca@1669
  1157
    "
ca@1669
  1158
    self model notNil ifTrue:[
ca@1669
  1159
	self   modified:true.
ca@1669
  1160
	anItem modified:true.
ca@1669
  1161
    ].
ca@1669
  1162
! !
ca@1669
  1163
ca@1669
  1164
!UIHelpTool::ClassItem methodsFor:'code generation'!
ca@1669
  1165
ca@1669
  1166
createHelpMethodNamed:aMethodName
ca@1669
  1167
    |stream|
ca@1669
  1168
ca@1669
  1169
    (modified and:[theClass notNil]) ifFalse:[
ca@1669
  1170
        ^ self
ca@1669
  1171
    ].
ca@1669
  1172
    stream := '' writeStream.
ca@1669
  1173
ca@1669
  1174
    stream nextPutAll:
ca@1669
  1175
        aMethodName, '\' withCRs,
ca@1669
  1176
        (ResourceSpecEditor codeGenerationCommentForClass:UIHelpTool) withCRs,
ca@1669
  1177
    '\\' withCRs,
ca@1669
  1178
    '    "\' withCRs,
ca@1669
  1179
    '     UIHelpTool openOnClass:', theClass name asString ,'    
ca@1669
  1180
    "
ca@1669
  1181
ca@1669
  1182
    <resource: #help>
ca@1669
  1183
ca@1669
  1184
    ^ super ', aMethodName, ' addPairsFrom:#(
ca@1669
  1185
ca@1669
  1186
'.
ca@1669
  1187
ca@1669
  1188
    self do:[:aKeyItem| |helpText|
ca@1669
  1189
        helpText := aKeyItem helpText.
ca@1669
  1190
        helpText isNil ifTrue:[ helpText := '' ].
ca@1669
  1191
ca@1669
  1192
        stream nextPutLine:(aKeyItem helpKey storeString).
ca@1669
  1193
        stream nextPutLine:(helpText storeString); cr.
ca@1669
  1194
    ].
ca@1669
  1195
    stream nextPutLine:')'.
ca@1669
  1196
ca@1669
  1197
    Compiler 
ca@1669
  1198
        compile:(stream contents)
ca@1669
  1199
        forClass:theClass class 
ca@1669
  1200
        inCategory:'help specs'.
ca@1669
  1201
ca@1669
  1202
    self modified:false.
cg@2020
  1203
! !
ca@1669
  1204
cg@2020
  1205
!UIHelpTool::ClassItem methodsFor:'displaying'!
cg@2020
  1206
cg@2020
  1207
icon
cg@2020
  1208
    "returns the display icon (always nil)
cg@2020
  1209
    "
cg@2020
  1210
    ^ nil
cg@2020
  1211
!
cg@2020
  1212
cg@2020
  1213
label
cg@2020
  1214
    "returns the display label
cg@2020
  1215
    "
cg@2020
  1216
    |label|
cg@2020
  1217
cg@2020
  1218
    theClass notNil ifTrue:[ label := theClass name ]
cg@2020
  1219
		   ifFalse:[ label := '** not yet defined **' ].
cg@2020
  1220
cg@2020
  1221
    modified ifTrue:[
cg@2020
  1222
	label := Text string:label color:(Color red).
cg@2020
  1223
    ].
cg@2020
  1224
    ^ label
cg@2020
  1225
! !
cg@2020
  1226
cg@2020
  1227
!UIHelpTool::ClassItem methodsFor:'instance creation'!
ca@1669
  1228
ca@1669
  1229
initialize
ca@1669
  1230
    "setup defaults
ca@1669
  1231
    "
ca@1669
  1232
    super initialize.
ca@1669
  1233
ca@1669
  1234
    children   := OrderedCollection new.
ca@1669
  1235
    isExpanded := true.
ca@1669
  1236
    modified   := false.
ca@1669
  1237
!
ca@1669
  1238
ca@1669
  1239
onClass:aClass
ca@1669
  1240
    "the class the ys are assigned to; if the class is nil,
ca@1669
  1241
     the class is not yet specified.
ca@1669
  1242
    "
ca@1669
  1243
    theClass := aClass.
ca@1669
  1244
! !
ca@1669
  1245
ca@1669
  1246
!UIHelpTool::ClassItem methodsFor:'private'!
ca@1669
  1247
ca@1669
  1248
basicAdd:aChild sortBlock:aBlock
ca@1669
  1249
    "catch low-level add to update the modification flag
ca@1669
  1250
    "
ca@1669
  1251
    self   modified:true.
ca@1669
  1252
    aChild modified:true.
ca@1669
  1253
ca@1669
  1254
    ^ super basicAdd:aChild sortBlock:aBlock.
ca@1669
  1255
!
ca@1669
  1256
ca@1669
  1257
basicAddAll:aList beforeIndex:anIndex
ca@1669
  1258
    "catch low-level add to update the modification flag
ca@1669
  1259
    "
ca@1669
  1260
    self modified:true.
ca@1669
  1261
cg@2020
  1262
    aList do:[:el| el modified:true ].
cg@2020
  1263
    ^ super basicAddAll:aList beforeIndex:anIndex.
cg@2020
  1264
!
ca@1669
  1265
ca@1669
  1266
basicRemoveFromIndex:startIndex toIndex:stopIndex
ca@1669
  1267
    "catch low-level remove to update the modification flag
ca@1669
  1268
    "
ca@1669
  1269
    self isUnspecified ifFalse:[
ca@1669
  1270
	self modified:true.
ca@1669
  1271
    ].
ca@1669
  1272
    ^ super basicRemoveFromIndex:startIndex toIndex:stopIndex
ca@1669
  1273
! !
ca@1669
  1274
ca@1669
  1275
!UIHelpTool::ClassItem methodsFor:'queries'!
ca@1669
  1276
ca@1669
  1277
isUnspecified
ca@1669
  1278
    "true if the class is unspecified
ca@1669
  1279
    "
ca@1669
  1280
    ^ theClass isNil
ca@1669
  1281
!
ca@1669
  1282
ca@1669
  1283
modified
cg@2020
  1284
    "true, if any item is modified, created or deleted
cg@2020
  1285
    "
cg@2020
  1286
    ^ modified
cg@2020
  1287
!
ca@1669
  1288
ca@1669
  1289
modified:aBoolean
ca@1669
  1290
    "true, if any item is modified, created or deleted
ca@1669
  1291
    "
ca@1669
  1292
    modified ~~ aBoolean ifTrue:[
ca@1669
  1293
	modified := aBoolean.
ca@1669
  1294
ca@1669
  1295
	modified ifFalse:[
ca@1669
  1296
	    self do:[:el| el modified:false ].
ca@1669
  1297
	].
ca@1669
  1298
    ].
ca@1669
  1299
! !
ca@1669
  1300
ca@1669
  1301
!UIHelpTool::ClassItem methodsFor:'searching'!
ca@1669
  1302
ca@1669
  1303
detectItemWithKey:aKey
ca@1669
  1304
    "returns the item assigned to a helpKey or nil
ca@1669
  1305
    "
ca@1669
  1306
    |key|
ca@1669
  1307
cg@2037
  1308
    aKey isEmptyOrNil ifTrue:[ ^ nil ].
cg@2037
  1309
    key := aKey asSymbol.
ca@1669
  1310
cg@2037
  1311
    self do:[:anItem|
cg@2037
  1312
        anItem helpKey == key ifTrue:[ ^ anItem ].
ca@1669
  1313
    ].
cg@2020
  1314
    ^ nil
ca@1669
  1315
! !
ca@1669
  1316
cg@2020
  1317
!UIHelpTool::KeyItem class methodsFor:'instance creation'!
ca@1669
  1318
cg@2020
  1319
helpKey:aKey helpText:aText 
cg@2020
  1320
    |key|
ca@1669
  1321
cg@2020
  1322
    key := self new.
cg@2020
  1323
    key helpKey:aKey helpText:aText.
cg@2020
  1324
    ^ key
cg@2020
  1325
! !
cg@2020
  1326
cg@2020
  1327
!UIHelpTool::KeyItem methodsFor:'accessing'!
ca@1669
  1328
ca@1669
  1329
helpKey
ca@1669
  1330
    "returns the helpKey, a symbol
ca@1669
  1331
    "
ca@1669
  1332
    ^ helpKey
ca@1669
  1333
!
ca@1669
  1334
ca@1669
  1335
helpText
ca@1669
  1336
    "returns the contents assigned to the helpKey or nil
ca@1669
  1337
    "
ca@1669
  1338
    ^ helpText
ca@1669
  1339
!
ca@1669
  1340
ca@1669
  1341
helpText:aText
cg@1681
  1342
    "set the contents assigned to the helpKey; if the contents changes,
ca@1669
  1343
     a notification is raised.
ca@1669
  1344
    "
ca@1669
  1345
    |text|
ca@1669
  1346
ca@1669
  1347
    text := self formatText:aText.
ca@1669
  1348
ca@1669
  1349
    text ~= helpText ifTrue:[
cg@1681
  1350
        helpText := text.
ca@1669
  1351
cg@1681
  1352
        (modified or:[parent isNil]) ifFalse:[
cg@1681
  1353
            parent helpTextChangedFor:self.
cg@1681
  1354
        ]
ca@1669
  1355
    ].
ca@1669
  1356
! !
ca@1669
  1357
cg@2020
  1358
!UIHelpTool::KeyItem methodsFor:'displaying'!
cg@2020
  1359
cg@2020
  1360
icon
cg@2020
  1361
    "returns the display icon (always nil)
cg@2020
  1362
    "
cg@2020
  1363
    ^ icon
ca@1670
  1364
!
ca@1670
  1365
cg@2020
  1366
icon:anIcon
cg@2020
  1367
cg@2020
  1368
    icon ~= anIcon ifTrue:[
cg@2020
  1369
        icon := anIcon.
cg@2020
  1370
        self changed:#icon.
cg@2020
  1371
    ].
cg@2020
  1372
!
cg@2020
  1373
cg@2020
  1374
label
cg@2020
  1375
    "returns the display label
cg@2020
  1376
    "
cg@2020
  1377
    modified ifTrue:[
cg@2020
  1378
	^ Text string:helpKey color:(Color red)
cg@2020
  1379
    ].
cg@2020
  1380
    ^ helpKey
cg@2020
  1381
! !
cg@2020
  1382
cg@2020
  1383
!UIHelpTool::KeyItem methodsFor:'instance creation'!
cg@2020
  1384
ca@1669
  1385
helpKey:aKey helpText:aText
ca@1669
  1386
    "set the key and contents without a change notification
ca@1669
  1387
    "
ca@1669
  1388
    helpKey  := aKey asSymbol.
ca@1669
  1389
    helpText := self formatText:aText.
ca@1669
  1390
!
ca@1669
  1391
ca@1669
  1392
initialize
ca@1669
  1393
    "setup defaults
ca@1669
  1394
    "
ca@1669
  1395
    super initialize.
ca@1669
  1396
    children := #().
ca@1669
  1397
    modified := false.
ca@1669
  1398
! !
ca@1669
  1399
ca@1669
  1400
!UIHelpTool::KeyItem methodsFor:'private'!
ca@1669
  1401
ca@1669
  1402
formatText:aText
ca@1669
  1403
    "format the text, replace carriage return by spaces and compress spaces
ca@1669
  1404
    "
ca@1669
  1405
    |text result|
ca@1669
  1406
ca@1669
  1407
    aText size ~~ 0 ifTrue:[
ca@1669
  1408
	text := aText asString asCollectionOfWords.
ca@1669
  1409
ca@1669
  1410
	text notEmpty ifTrue:[
ca@1669
  1411
	    result := text first.
ca@1669
  1412
ca@1669
  1413
	    text from:2 do:[:t| result := result, ' ', t ].
cg@2020
  1414
	    ^ result
cg@2020
  1415
       ].
cg@2020
  1416
    ].
cg@2020
  1417
    ^ nil
cg@2020
  1418
! !
cg@2020
  1419
cg@2020
  1420
!UIHelpTool::KeyItem methodsFor:'queries'!
cg@2020
  1421
cg@2020
  1422
modified
cg@2020
  1423
    "returns true if the helpText is modified
cg@2020
  1424
    "
cg@2020
  1425
    ^ modified
cg@2020
  1426
!
ca@1669
  1427
ca@1669
  1428
modified:aBoolean
ca@1669
  1429
    "set the modification flag
ca@1669
  1430
    "
ca@1669
  1431
    aBoolean == modified ifFalse:[
ca@1669
  1432
	modified := aBoolean.
ca@1669
  1433
	self changed:#redraw.
ca@1669
  1434
    ].
ca@148
  1435
! !
ca@148
  1436
ca@148
  1437
!UIHelpTool class methodsFor:'documentation'!
ca@148
  1438
ca@148
  1439
version
ca@148
  1440
    ^ '$Header$'
cg@2665
  1441
!
cg@2665
  1442
cg@2665
  1443
version_CVS
cg@2665
  1444
    ^ '$Header$'
ca@148
  1445
! !