HierarchicalListEditor.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 14 Nov 2018 12:07:51 +0100
branchjv
changeset 3630 5e718e0a754e
parent 3306 a2d6e8a1bcaf
permissions -rw-r--r--
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present

- All source *.st files are now Unicode UTF8 without BOM
Files are in two groups (fileOut works this way in Smalltalk/X):
- containing a unicode character have "{ Encoding: utf8 }" at the header
- ASCII only are without the header
     1 "
     2  COPYRIGHT (c) 1997 by eXept Software AG
     3               All Rights Reserved
     4 
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice. This software may not
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    11 "
    12 "{ Package: 'stx:libtool2' }"
    13 
    14 "{ NameSpace: Smalltalk }"
    15 
    16 ResourceSpecEditor subclass:#HierarchicalListEditor
    17 	instanceVariableNames:'treeView'
    18 	classVariableNames:''
    19 	poolDictionaries:''
    20 	category:'Interface-UIPainter'
    21 !
    22 
    23 !HierarchicalListEditor class methodsFor:'documentation'!
    24 
    25 copyright
    26 "
    27  COPYRIGHT (c) 1997 by eXept Software AG
    28               All Rights Reserved
    29 
    30  This software is furnished under a license and may be used
    31  only in accordance with the terms of that license and with the
    32  inclusion of the above copyright notice. This software may not
    33  be provided or otherwise made available to, or used by, any
    34  other person.  No title to or ownership of the software is
    35  hereby transferred.
    36 "
    37 
    38 
    39 
    40 !
    41 
    42 documentation
    43 "
    44     The HierarchicalListEditor allows you to create, modify or just inspect
    45     (statical) hierarchical lists for the SelectionInListView.
    46 
    47     [start with:]
    48         HierarchicalListEditor open
    49 
    50     [see also:]
    51         UIPainter
    52 
    53     [author:]
    54         Claus Atzkern, eXept Software AG
    55         Thomas Zwick, eXept Software AG
    56 "
    57 
    58 
    59 
    60 ! !
    61 
    62 !HierarchicalListEditor class methodsFor:'instance creation'!
    63 
    64 openModalOnTreeItem: aTreeItem
    65     "Open a HierarchicalListEditor modal on aTreeItem"
    66     "self openModalOnTreeItem: (TreeItem name: 'Label' contents: #Contents)"
    67 
    68     ^self new openModalOnTreeItem: aTreeItem
    69 
    70 ! !
    71 
    72 !HierarchicalListEditor class methodsFor:'accessing'!
    73 
    74 resourceType
    75     "get the type of resource of the method generated by the HierarchicalListEditor"
    76 
    77     ^#hierarchicalList
    78 
    79 ! !
    80 
    81 !HierarchicalListEditor class methodsFor:'help specs'!
    82 
    83 helpSpec
    84     "This resource specification was automatically generated
    85      by the UIHelpTool of ST/X."
    86 
    87     "Do not manually edit this!! If it is corrupted,
    88      the UIHelpTool may not be able to read the specification."
    89 
    90     "
    91      UIHelpTool openOnClass:HierarchicalListEditor    
    92     "
    93 
    94     <resource: #help>
    95 
    96     ^super helpSpec addPairsFrom:#(
    97 
    98 #addChild
    99 'Adds a new child item.'
   100 
   101 #addSister
   102 'Adds a new sister item.'
   103 
   104 #contents
   105 'Contents of the tree item.'
   106 
   107 #fileLoad
   108 'Opens a dialog for selecting and loading a hierarchical list spec from a class.'
   109 
   110 #fileNew
   111 'Creates a new hierarchical list. '
   112 
   113 #fileSave
   114 'Saves current hierarchical list spec.'
   115 
   116 #fileSaveAs
   117 'Opens a dialog to save current hierarchical list spec.'
   118 
   119 #label
   120 'Label of the tree item.'
   121 
   122 )
   123 ! !
   124 
   125 !HierarchicalListEditor class methodsFor:'image specs'!
   126 
   127 createChildIcon
   128     "This resource specification was automatically generated
   129      by the ImageEditor of ST/X."
   130 
   131     "Do not manually edit this!! If it is corrupted,
   132      the ImageEditor may not be able to read the specification."
   133 
   134     "
   135      ImageEditor openOnClass:self andSelector:#createChildIcon
   136     "
   137 
   138     <resource: #image>
   139 
   140     ^Icon
   141         constantNamed:#'HierarchicalListEditor createChildIcon'
   142         ifAbsentPut:[(Depth2Image new) width: 22; height: 22; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@AUUUUP@@A????2@@A????2 @A????0@@A?????8@A?????8@A?????8@A?????8@A?????8@A?????8@A?????8@A?????8@A?????8@A<3L308@A33L33H@A30L33H@A33L33H@A<3L008@A?????8@C*****(@@@@@@@@@') ; colorMapFromArray:#[0 0 0 255 255 255 127 127 127 170 170 170]; mask:((Depth1Image new) width: 22; height: 22; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'_?>@_??@_?? _??0_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8') ; yourself); yourself]
   143 !
   144 
   145 createSisterIcon
   146     "This resource specification was automatically generated
   147      by the ImageEditor of ST/X."
   148 
   149     "Do not manually edit this!! If it is corrupted,
   150      the ImageEditor may not be able to read the specification."
   151 
   152     "
   153      ImageEditor openOnClass:self andSelector:#createSisterIcon
   154     "
   155 
   156     <resource: #image>
   157 
   158     ^Icon
   159         constantNamed:#'HierarchicalListEditor createSisterIcon'
   160         ifAbsentPut:[(Depth2Image new) width: 22; height: 22; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@AUUUUP@@A????2@@A????2 @A????0@@A?????8@A?????8@A?????8@A<L<O?8@A3<3??8@A<<<<C8@A?L?O?8@A0<0??8@A?????8@A0LCC?8@A<<?L?8@A<<CC?8@A<<?L?8@A<<CL?8@A?????8@C*****(@@@@@@@@@') ; colorMapFromArray:#[0 0 0 255 255 255 127 127 127 170 170 170]; mask:((Depth1Image new) width: 22; height: 22; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'_?>@_??@_?? _??0_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8_??8') ; yourself); yourself]
   161 ! !
   162 
   163 !HierarchicalListEditor class methodsFor:'interface specs'!
   164 
   165 windowSpec
   166     "This resource specification was automatically generated
   167      by the UIPainter of ST/X."
   168 
   169     "Do not manually edit this!! If it is corrupted,
   170      the UIPainter may not be able to read the specification."
   171 
   172     "
   173      UIPainter new openOnClass:HierarchicalListEditor andSelector:#windowSpec
   174      HierarchicalListEditor new openInterface:#windowSpec
   175      HierarchicalListEditor open
   176     "
   177 
   178     <resource: #canvas>
   179 
   180     ^ 
   181      #(#FullSpec
   182         #name: #windowSpec
   183         #window: 
   184        #(#WindowSpec
   185           #label: 'Hierarchical List Editor'
   186           #name: 'Hierarchical List Editor'
   187           #min: #(#Point 450 280)
   188           #max: #(#Point 1152 900)
   189           #bounds: #(#Rectangle 16 46 486 376)
   190           #menu: #menu
   191         )
   192         #component: 
   193        #(#SpecCollection
   194           #collection: #(
   195            #(#MenuPanelSpec
   196               #name: 'menuToolbarView'
   197               #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 32 0)
   198               #menu: #menuToolbar
   199             )
   200            #(#VariableHorizontalPanelSpec
   201               #name: 'VariableHorizontalPanel'
   202               #layout: #(#LayoutFrame 0 0.0 34 0.0 0 1.0 -26 1.0)
   203               #component: 
   204              #(#SpecCollection
   205                 #collection: #(
   206                  #(#ArbitraryComponentSpec
   207                     #name: 'TreeView'
   208                     #menu: #menuEdit
   209                     #hasHorizontalScrollBar: true
   210                     #hasVerticalScrollBar: true
   211                     #miniScrollerHorizontal: true
   212                     #miniScrollerVertical: true
   213                     #hasBorder: false
   214                     #component: #treeView
   215                   )
   216                  #(#ViewSpec
   217                     #name: 'SpecView'
   218                     #level: -1
   219                     #component: 
   220                    #(#SpecCollection
   221                       #collection: #(
   222                        #(#LabelSpec
   223                           #label: 'Label:'
   224                           #name: 'nameLabel'
   225                           #layout: #(#AlignmentOrigin 98 0 26 0 1 0.5)
   226                           #resizeForLabel: true
   227                     translateLabel: true
   228                         )
   229                        #(#InputFieldSpec
   230                           #name: 'labelInputField'
   231                           #layout: #(#LayoutFrame 100 0 15 0 -5 1.0 37 0)
   232                           #activeHelpKey: #label
   233                           #tabable: true
   234                           #model: #itemName
   235                           #acceptOnLeave: true
   236                           #acceptOnLostFocus: true
   237                           #acceptChannel: #acceptChannel
   238                           #modifiedChannel: #modifiedChannel
   239                           #acceptOnPointerLeave: true
   240                         )
   241                        #(#LabelSpec
   242                           #label: 'Contents:'
   243                           #name: 'valueLabel'
   244                           #layout: #(#AlignmentOrigin 98 0 52 0 1 0.5)
   245                           #activeHelpKey: #contents
   246                           #resizeForLabel: true
   247                     translateLabel: true
   248                         )
   249                        #(#InputFieldSpec
   250                           #name: 'valueInputField'
   251                           #layout: #(#LayoutFrame 100 0 41 0 -5 1.0 63 0)
   252                           #activeHelpKey: #contents
   253                           #tabable: true
   254                           #model: #itemValue
   255                           #type: #smalltalkObject
   256                           #acceptOnLeave: true
   257                           #acceptOnLostFocus: true
   258                           #acceptChannel: #acceptChannel
   259                           #modifiedChannel: #modifiedChannel
   260                           #acceptOnPointerLeave: true
   261                         )
   262                        #(#UISubSpecification
   263                           #name: 'SubSpecification'
   264                           #layout: #(#LayoutFrame 2 0.0 -26 1.0 -2 1.0 -2 1.0)
   265                           #majorKey: #ToolApplicationModel
   266                           #minorKey: #windowSpecForCommit
   267                         )
   268                        )
   269                      
   270                     )
   271                   )
   272                  )
   273                
   274               )
   275               #handles: #(#Any 0.368421 1.0)
   276             )
   277            #(#UISubSpecification
   278               #name: 'InfoBarSubSpec'
   279               #layout: #(#LayoutFrame 0 0.0 -24 1 0 1.0 0 1.0)
   280               #majorKey: #ToolApplicationModel
   281               #minorKey: #windowSpecForInfoBar
   282             )
   283            )
   284          
   285         )
   286       )
   287 ! !
   288 
   289 !HierarchicalListEditor class methodsFor:'menu specs'!
   290 
   291 menu
   292     "This resource specification was automatically generated
   293      by the MenuEditor of ST/X."
   294 
   295     "Do not manually edit this!! If it is corrupted,
   296      the MenuEditor may not be able to read the specification."
   297 
   298     "
   299      MenuEditor new openOnClass:HierarchicalListEditor andSelector:#menu
   300      (Menu new fromLiteralArrayEncoding:(HierarchicalListEditor menu)) startUp
   301     "
   302 
   303     <resource: #menu>
   304 
   305     ^
   306      
   307        #(#Menu
   308           
   309            #(
   310              #(#MenuItem
   311                 #label: 'File'
   312                 #submenu: 
   313                  #(#Menu
   314                     
   315                      #(
   316                        #(#MenuItem
   317                           #label: 'New'
   318                           #value: #doNew
   319                           #activeHelpKey: #fileNew
   320                       )
   321                        #(#MenuItem
   322                           #label: '-'
   323                       )
   324                        #(#MenuItem
   325                           #label: 'Load...'
   326                           #translateLabel: true
   327                           #value: #doLoad
   328                           #activeHelpKey: #fileLoad
   329                       )
   330                        #(#MenuItem
   331                           #label: '-'
   332                       )
   333                        #(#MenuItem
   334                           #label: 'Save'
   335                           #value: #doSave
   336                           #activeHelpKey: #fileSave
   337                       )
   338                        #(#MenuItem
   339                           #label: 'Save As...'
   340                           #value: #doSaveAs
   341                           #activeHelpKey: #fileSaveAs
   342                       )
   343                        #(#MenuItem
   344                           #label: '-'
   345                       )
   346                        #(#MenuItem
   347                           #label: 'Browse Class'
   348                           #value: #doBrowseClass
   349                           #activeHelpKey: #fileBrowseClass
   350                           #enabled: #hasValidClass
   351                       )
   352                        #(#MenuItem
   353                           #label: '-'
   354                       )
   355                        #(#MenuItem
   356                           #label: 'Exit'
   357                           #value: #closeRequest
   358                           #activeHelpKey: #fileExit
   359                       )
   360                     ) nil
   361                     nil
   362                 )
   363             )
   364              #(#MenuItem
   365                 #label: 'Edit'
   366                 #submenuChannel: #menuEdit
   367             )
   368              #(#MenuItem
   369                 #label: 'Add'
   370                 #submenu: 
   371                  #(#Menu
   372                     
   373                      #(
   374                        #(#MenuItem
   375                           #label: 'Child'
   376                           #value: #doCreateChild
   377                           #activeHelpKey: #addChild
   378                           #enabled: #canCreateChildChannel
   379                           #labelImage: #(#ResourceRetriever #HierarchicalListEditor #createChildIcon 'Child')
   380                       )
   381                        #(#MenuItem
   382                           #label: 'Sister'
   383                           #value: #doCreateSister
   384                           #activeHelpKey: #addSister
   385                           #enabled: #canCreateSisterChannel
   386                           #labelImage: #(#ResourceRetriever #HierarchicalListEditor #createSisterIcon 'Sister')
   387                       )
   388                     ) nil
   389                     nil
   390                 )
   391             )
   392              #(#MenuItem
   393                 #label: 'History'
   394                 #submenuChannel: #menuHistory
   395             )
   396              #(#MenuItem
   397                 #label: 'Help'
   398                 #startGroup: #right
   399                 #submenuChannel: #menuHelp
   400             )
   401           ) nil
   402           nil
   403       )
   404 !
   405 
   406 menuEdit
   407     "This resource specification was automatically generated
   408      by the MenuEditor of ST/X."
   409 
   410     "Do not manually edit this!! If it is corrupted,
   411      the MenuEditor may not be able to read the specification."
   412 
   413     "
   414      MenuEditor new openOnClass:HierarchicalListEditor andSelector:#menuEdit
   415      (Menu new fromLiteralArrayEncoding:(HierarchicalListEditor menuEdit)) startUp
   416     "
   417 
   418     <resource: #menu>
   419 
   420     ^
   421      
   422        #(#Menu
   423           
   424            #(
   425              #(#MenuItem
   426                 #label: 'Cut'
   427                 #value: #doCut
   428                 #activeHelpKey: #editCut
   429                 #enabled: #valueOfCanCut
   430             )
   431              #(#MenuItem
   432                 #label: 'Copy'
   433                 #value: #doCopy
   434                 #activeHelpKey: #editCopy
   435                 #enabled: #valueOfCanCopy
   436             )
   437              #(#MenuItem
   438                 #label: 'Paste'
   439                 #value: #doPaste
   440                 #activeHelpKey: #editPaste
   441                 #enabled: #valueOfCanPaste
   442             )
   443              #(#MenuItem
   444                 #label: 'Delete'
   445                 #value: #doDelete
   446                 #activeHelpKey: #editPaste
   447                 #enabled: #valueOfCanCut
   448             )
   449              #(#MenuItem
   450                 #label: '-'
   451             )
   452              #(#MenuItem
   453                 #label: 'Move Up'
   454                 #value: #doStepUp
   455                 #activeHelpKey: #editMoveUp
   456                 #enabled: #canStepOverChannel
   457                 #labelImage: #(#ResourceRetriever #Icon #upIcon 'Move Up')
   458             )
   459              #(#MenuItem
   460                 #label: 'Move Down'
   461                 #value: #doStepDown
   462                 #activeHelpKey: #editMoveDown
   463                 #enabled: #canStepOverChannel
   464                 #labelImage: #(#ResourceRetriever #Icon #downIcon 'Move Down')
   465             )
   466              #(#MenuItem
   467                 #label: 'Move In'
   468                 #value: #doStepIn
   469                 #activeHelpKey: #editMoveIn
   470                 #enabled: #canStepInChannel
   471                 #labelImage: #(#ResourceRetriever #Icon #downRightIcon 'Move In')
   472             )
   473              #(#MenuItem
   474                 #label: 'Move Out'
   475                 #value: #doStepOut
   476                 #activeHelpKey: #editMoveOut
   477                 #enabled: #canStepOutChannel
   478                 #labelImage: #(#ResourceRetriever #Icon #leftDownIcon 'Move Out')
   479             )
   480           ) nil
   481           nil
   482       )
   483 !
   484 
   485 menuToolbar
   486     "This resource specification was automatically generated
   487      by the MenuEditor of ST/X."
   488 
   489     "Do not manually edit this!! If it is corrupted,
   490      the MenuEditor may not be able to read the specification."
   491 
   492     "
   493      MenuEditor new openOnClass:HierarchicalListEditor andSelector:#menuToolbar
   494      (Menu new fromLiteralArrayEncoding:(HierarchicalListEditor menuToolbar)) startUp
   495     "
   496 
   497     <resource: #menu>
   498 
   499     ^
   500      
   501        #(#Menu
   502           
   503            #(
   504              #(#MenuItem
   505                 #label: 'New'
   506                 #isButton: true
   507                 #value: #doNew
   508                 #activeHelpKey: #fileNew
   509                 #labelImage: #(#ResourceRetriever #Icon #newIcon)
   510             )
   511              #(#MenuItem
   512                 #label: 'Load'
   513                 #isButton: true
   514                 #value: #doLoad
   515                 #activeHelpKey: #fileLoad
   516                 #labelImage: #(#ResourceRetriever #Icon #loadIcon)
   517             )
   518              #(#MenuItem
   519                 #label: 'Save'
   520                 #isButton: true
   521                 #value: #doSave
   522                 #activeHelpKey: #fileSave
   523                 #labelImage: #(#ResourceRetriever #Icon #saveIcon)
   524             )
   525              #(#MenuItem
   526                 #label: ''
   527             )
   528              #(#MenuItem
   529                 #label: 'Cut'
   530                 #isButton: true
   531                 #value: #doCut
   532                 #activeHelpKey: #editCut
   533                 #enabled: #valueOfCanCut
   534                 #labelImage: #(#ResourceRetriever #Icon #cutIcon)
   535             )
   536              #(#MenuItem
   537                 #label: 'Copy'
   538                 #isButton: true
   539                 #value: #doCopy
   540                 #activeHelpKey: #editCopy
   541                 #enabled: #valueOfCanCopy
   542                 #labelImage: #(#ResourceRetriever #Icon #copyIcon)
   543             )
   544              #(#MenuItem
   545                 #label: 'Paste'
   546                 #isButton: true
   547                 #value: #doPaste
   548                 #activeHelpKey: #editPaste
   549                 #enabled: #valueOfCanPaste
   550                 #labelImage: #(#ResourceRetriever #Icon #pasteIcon)
   551             )
   552              #(#MenuItem
   553                 #label: 'Delete'
   554                 #isButton: true
   555                 #value: #doDelete
   556                 #activeHelpKey: #editDelete
   557                 #enabled: #valueOfCanCut
   558                 #labelImage: #(#ResourceRetriever #Icon #deleteIcon)
   559             )
   560              #(#MenuItem
   561                 #label: ''
   562             )
   563              #(#MenuItem
   564                 #label: 'Add Child'
   565                 #isButton: true
   566                 #value: #doCreateChild
   567                 #activeHelpKey: #addChild
   568                 #enabled: #canCreateChildChannel
   569                 #labelImage: #(#ResourceRetriever nil #createChildIcon)
   570             )
   571              #(#MenuItem
   572                 #label: 'Add Sister'
   573                 #isButton: true
   574                 #value: #doCreateSister
   575                 #activeHelpKey: #addSister
   576                 #enabled: #canCreateSisterChannel
   577                 #labelImage: #(#ResourceRetriever nil #createSisterIcon)
   578             )
   579              #(#MenuItem
   580                 #label: ''
   581             )
   582              #(#MenuItem
   583                 #label: 'Move Up'
   584                 #isButton: true
   585                 #value: #doStepUp
   586                 #activeHelpKey: #editMoveUp
   587                 #enabled: #canStepOverChannel
   588                 #labelImage: #(#ResourceRetriever #Icon #upIcon)
   589             )
   590              #(#MenuItem
   591                 #label: 'Move Down'
   592                 #isButton: true
   593                 #value: #doStepDown
   594                 #activeHelpKey: #editMoveDown
   595                 #enabled: #canStepOverChannel
   596                 #labelImage: #(#ResourceRetriever #Icon #downIcon)
   597             )
   598              #(#MenuItem
   599                 #label: 'Move In'
   600                 #isButton: true
   601                 #value: #doStepIn
   602                 #activeHelpKey: #editMoveIn
   603                 #enabled: #canStepInChannel
   604                 #labelImage: #(#ResourceRetriever #Icon #downRightIcon)
   605             )
   606              #(#MenuItem
   607                 #label: 'Move Out'
   608                 #isButton: true
   609                 #value: #doStepOut
   610                 #activeHelpKey: #editMoveOut
   611                 #enabled: #canStepOutChannel
   612                 #labelImage: #(#ResourceRetriever #Icon #leftDownIcon)
   613             )
   614           ) nil
   615           nil
   616       )
   617 ! !
   618 
   619 !HierarchicalListEditor class methodsFor:'printing'!
   620 
   621 prettyPrintArray:anArray on:aStream indent:anIndent
   622     "print a literal array in a nice format
   623     "
   624     |arg sol|
   625 
   626     sol := aStream position.
   627     aStream spaces:anIndent.
   628     aStream nextPutAll:'#('.
   629 
   630     anArray first isSymbol ifTrue:[
   631         arg := anArray first.
   632         aStream nextPut:$#.
   633         aStream nextPutAll:anArray first.
   634         aStream cr.
   635         anArray size == 2 ifTrue:[
   636             self prettyPrintArray:(anArray last)
   637                                on:aStream
   638                            indent:(anIndent + 4).
   639         ].
   640         aStream spaces:anIndent.
   641         aStream nextPut:$).
   642       ^ self  
   643     ].
   644 
   645     aStream nextPut:$'.
   646     aStream nextPutAll:(anArray at:1).
   647     aStream nextPut:$'.
   648     arg := anArray at:2 ifAbsent:nil.
   649 
   650     arg isString ifTrue:[
   651         aStream spaces:((50 - (aStream position - sol)) max:4).
   652 
   653         arg isSymbol ifTrue:[
   654             aStream nextPut:$#.
   655         ].
   656         aStream nextPut:$'.
   657         aStream nextPutAll:arg.
   658         aStream nextPut:$'.
   659         arg := anArray at:3 ifAbsent:nil.
   660     ].
   661     arg isArray ifTrue:[
   662         aStream nextPutAll:' #('.
   663         aStream cr.
   664         arg do:[:e|self prettyPrintArray:e on:aStream indent:(anIndent + 4)].
   665         aStream spaces:anIndent.
   666         aStream nextPut:$).
   667     ].
   668     aStream nextPut:$).
   669     aStream cr.
   670 ! !
   671 
   672 !HierarchicalListEditor methodsFor:'aspects'!
   673 
   674 canCreateChildChannel
   675 
   676     ^builder booleanValueAspectFor:#canCreateChildChannel
   677 
   678 !
   679 
   680 canCreateSisterChannel
   681 
   682     ^builder booleanValueAspectFor:#canCreateSisterChannel
   683 
   684 !
   685 
   686 canStepInChannel
   687 
   688     ^builder booleanValueAspectFor:#canStepInChannel
   689 
   690 !
   691 
   692 canStepOutChannel
   693 
   694     ^builder booleanValueAspectFor:#canStepOutChannel
   695 
   696 !
   697 
   698 canStepOverChannel
   699 
   700     ^builder booleanValueAspectFor:#canStepOverChannel
   701 
   702 !
   703 
   704 itemName
   705 
   706     |holder|
   707 
   708     (holder := builder bindingAt:#itemName) isNil ifTrue:[
   709         builder aspectAt:#itemName put:(holder :=  ValueHolder new).
   710         holder addDependent:self.
   711     ].
   712     ^ holder
   713 !
   714 
   715 itemValue
   716 
   717     |holder|
   718 
   719     (holder := builder bindingAt:#itemValue) isNil ifTrue:[
   720         builder aspectAt:#itemValue put:(holder :=  ValueHolder new).
   721         holder addDependent:self.
   722     ].
   723     ^ holder
   724 !
   725 
   726 treeView
   727 
   728     ^treeView
   729 ! !
   730 
   731 !HierarchicalListEditor methodsFor:'building'!
   732 
   733 buildFromClass:aClass andSelector:aSelector
   734     "rebuild window from a class and selector"
   735 
   736     |cls sel anchor|
   737 
   738     cls := self resolveName:aClass.
   739     specSelector := nil.
   740 
   741     aSelector size ~~ 0 
   742     ifTrue:
   743     [
   744         sel := aSelector asString withoutSeparators.
   745         sel size ~~ 0 ifTrue:[specSelector := sel asSymbol]
   746     ].
   747     treeView selection:nil.
   748 
   749     (specSelector notNil and:[cls notNil]) 
   750     ifTrue:
   751     [
   752         (cls respondsTo:specSelector) 
   753         ifTrue:
   754         [
   755             anchor := cls perform:specSelector.
   756             anchor isArray ifTrue:[anchor := anchor decodeAsLiteralArray]
   757         ].
   758     ].              
   759     anchor notNil     
   760         ifTrue:  [anchor expand. treeView root:anchor] 
   761         ifFalse: [treeView root isNil ifTrue: [self buildRoot]].
   762 
   763     treeView selection: 1.
   764 
   765     self updateHistory.
   766     self updateInfoLabel.
   767 
   768 
   769 
   770 !
   771 
   772 buildFromResourceSpec: aListSpec
   773 
   774     treeView root: aListSpec
   775 
   776 !
   777 
   778 buildRoot
   779     "build just a root"
   780 
   781     treeView root:(TreeItem name:'Root' contents:#Anchor).
   782     treeView selection:1.
   783 ! !
   784 
   785 !HierarchicalListEditor methodsFor:'menu accessing'!
   786 
   787 menu
   788     ^ self class menu
   789 !
   790 
   791 menuEdit
   792     ^ self class menuEdit
   793 !
   794 
   795 menuToolbar
   796     ^ self class menuToolbar
   797 ! !
   798 
   799 !HierarchicalListEditor methodsFor:'private'!
   800 
   801 getDepthAndSistersNumberOfNode: aNode onParentNode: aParentNode
   802     "return depth of selected node"
   803 
   804     |parent childNode depthAndSistersNumbers str|
   805 
   806     depthAndSistersNumbers := OrderedCollection new.
   807     childNode := aNode.
   808     parent := aParentNode.
   809     [parent notNil] 
   810     whileTrue: 
   811     [
   812         depthAndSistersNumbers add: (parent children indexOf: childNode). 
   813         childNode := parent. 
   814         parent := parent parent. 
   815     ].
   816     depthAndSistersNumbers removeFirst; addFirst: aParentNode children size.
   817     str := ''.
   818     depthAndSistersNumbers reverseDo: [:n| str := str, n printString, '.'].
   819     ^str copyFrom: 1 to: str size - 1
   820 !
   821 
   822 newItem
   823     "creates and returns a new default item"
   824 
   825     ^TreeItem name: 'Item' contents: nil
   826 !
   827 
   828 updateChannels
   829     "update channels"
   830 
   831     |node parent chnStepIn chnStepOut chnStepOvr chnChild chnSister|
   832 
   833     chnStepIn := chnStepOut := chnStepOvr := chnChild := chnSister := false.
   834 
   835     (node := treeView selectedNode) notNil 
   836     ifTrue:
   837     [
   838         (builder componentAt: #SpecView) beVisible.
   839         chnChild := true.
   840         (parent := node parent) notNil 
   841         ifTrue:
   842         [
   843             chnSister  := true.
   844             chnStepOvr := parent numberOfChildren > 1.
   845             chnStepOut := parent parent notNil.
   846             chnStepIn  := node ~~ parent lastChild
   847         ]
   848     ]
   849     ifFalse:
   850     [
   851         (builder componentAt: #SpecView) beInvisible
   852     ].
   853     self canCreateChildChannel  value:chnChild.
   854     self canCreateSisterChannel value:chnSister.
   855     self canStepOverChannel     value:chnStepOvr.
   856     self canStepOutChannel      value:chnStepOut.
   857     self canStepInChannel       value:chnStepIn.
   858 
   859     self valueOfCanCut value: (treeView selection notNil      
   860         ifTrue:[(treeView isInSelection:1) not] 
   861         ifFalse: [false]).
   862 
   863     self valueOfCanCopy value: self valueOfCanCut value.
   864 
   865     self valueOfCanPaste value: treeView selectedNode notNil & self valueOfCanPaste value.
   866 !
   867 
   868 updateInputFields
   869     "reload item value into input fields"
   870 
   871     |node|
   872 
   873     (node := treeView selectedNode) notNil 
   874     ifTrue:
   875     [
   876         self itemName  value:node name.
   877         self itemValue value:node contents
   878     ] 
   879     ifFalse:
   880     [
   881         self itemName  value:''.
   882         self itemValue value:nil
   883     ].
   884     self valueOfEnablingCommitButtons value: false
   885 ! !
   886 
   887 !HierarchicalListEditor methodsFor:'startup & release'!
   888 
   889 initialize
   890     "setup default values"
   891 
   892     super initialize.
   893 
   894     treeView := SelectionInTreeView new.
   895     treeView multipleSelectOk: true.
   896     treeView showDirectoryIndicator: true.
   897     treeView showDirectoryIndicatorForRoot: false.
   898     treeView action:[:aNr| self updateChannels. self updateInputFields].
   899     treeView selectConditionBlock: [:i|self askForItemModification].
   900     treeView validateDoubleClickBlock: [:node| node ~~ treeView model list first].
   901 !
   902 
   903 openModalOnTreeItem: aTreeItem
   904     "build a tree from aTreeItem and open it modal"
   905 
   906     super openModalOnResourceSpec: aTreeItem
   907 ! !
   908 
   909 !HierarchicalListEditor methodsFor:'user actions'!
   910 
   911 accept
   912     "invoked by button 'OK'"
   913 
   914     |node index|
   915 
   916     (index := treeView selectedIndex) ~~ 0 
   917     ifTrue:
   918     [
   919         node := treeView nodeAtIndex:index.
   920         node name: self itemName value.
   921         node contents: self itemValue value.
   922         treeView redrawLine:index.
   923     ].
   924     modified := true.
   925     self valueOfEnablingCommitButtons value: false
   926 !
   927 
   928 cancel
   929     "invoked by button 'Cancel'"
   930 
   931     self updateInputFields.
   932 
   933     modified := false.
   934     self valueOfEnablingCommitButtons value: false
   935 !
   936 
   937 doCopy
   938     "copy current selected nodes into copy buffer"
   939 
   940     self class clipboard: OrderedCollection new.
   941     treeView selectedNodesDo:[:aNode| self class clipboard add: aNode copy].
   942     self updateAllToolInstances
   943 !
   944 
   945 doCreateChild
   946     "create a child within selected parent"
   947 
   948     |node newItem|
   949 
   950     ((node := treeView selectedNode) notNil and: [self askForItemModification])
   951     ifTrue:
   952     [
   953         treeView model add: (newItem := self newItem) afterIndex: node children size below:node.
   954         newItem name: 'Child ', (self getDepthAndSistersNumberOfNode: newItem onParentNode: node).
   955         treeView selectedNodeExpand:true.
   956         treeView selectNode: newItem.
   957         self updateChannels.
   958         modified := true
   959     ]
   960 !
   961 
   962 doCreateSister
   963     "create a sister next to selected item
   964     "
   965     |node newItem|
   966 
   967     ((node := treeView selectedNode) notNil and: [self askForItemModification]) 
   968     ifTrue:
   969     [
   970         newItem := self newItem.
   971         node parent notNil 
   972             ifTrue: [treeView model add: newItem after:node] 
   973             ifFalse:[treeView model add: newItem beforeIndex:1 below:node].
   974 
   975         newItem name: 'Child ', (self getDepthAndSistersNumberOfNode: newItem onParentNode: node parent).
   976         treeView selectNode: newItem.
   977         self updateChannels.
   978         modified := true
   979     ]
   980 !
   981 
   982 doCut
   983     "cut current selected nodes"
   984 
   985     |selection|
   986     (treeView hasSelection and: [self askForItemModification]) 
   987     ifTrue:
   988     [
   989         self doCopy.
   990         selection := treeView selection asSortedCollection.
   991         treeView selectedNodesRemove.
   992         treeView selection: selection first - 1.
   993         self updateAllToolInstances.
   994         modified := true
   995     ]
   996 !
   997 
   998 doDelete
   999     "delete current selected nodes"
  1000 
  1001     |selection|
  1002     (treeView hasSelection and: [self askForItemModification]) 
  1003     ifTrue:
  1004     [
  1005         selection := treeView selection asSortedCollection.
  1006         treeView selectedNodesRemove.
  1007         treeView selection: selection first - 1.
  1008         self updateChannels.
  1009         modified := true
  1010     ]
  1011 !
  1012 
  1013 doNew
  1014     "first do super new; then make a build 
  1015      of a resource spec containing a root"
  1016 
  1017     super doNew ifTrue: [self buildRoot]
  1018 
  1019 
  1020 
  1021 !
  1022 
  1023 doPaste
  1024     "paste after current selected item"
  1025 
  1026     (self askForItemModification and: [self class clipboard notNil])
  1027     ifTrue:
  1028     [
  1029         |copiedNode|
  1030         self class clipboard do:
  1031         [:node|
  1032             copiedNode := node copy.
  1033             treeView selectedNodeAdd: copiedNode. 
  1034             treeView selectNode: copiedNode.
  1035         ].
  1036         self updateChannels.
  1037         modified := true
  1038     ]
  1039 !
  1040 
  1041 doReload
  1042     "reload spec from current class and selector"
  1043 
  1044     self buildFrom:specClass andSelector:specSelector
  1045 
  1046 !
  1047 
  1048 doSave
  1049     "install code"
  1050 
  1051     |cls code spec category mthd stream|
  1052 
  1053     (specClass notNil and:[specSelector notNil])
  1054     ifFalse:
  1055     [
  1056         ^self doSaveAs
  1057     ].
  1058 
  1059     cls := self resolveName: specClass.
  1060     spec   := (treeView nodeAtIndex:1) literalArrayEncoding.
  1061     stream := WriteStream on:String new.
  1062     self class prettyPrintArray:spec on:stream indent:4.
  1063     spec       := stream contents.
  1064     category   := 'list specs'.
  1065 
  1066     (mthd := cls class compiledMethodAt:specSelector) notNil 
  1067     ifTrue:
  1068     [
  1069         category := mthd category
  1070     ].
  1071 
  1072     code := Character excla asString 
  1073             , cls name , ' class methodsFor:' , category storeString
  1074             , Character excla asString , '\\'
  1075 
  1076             , specSelector , '\'
  1077             , (self class codeGenerationComment replChar:$!! withString:'!!!!')
  1078             , '\\    "\'
  1079             , '     HierarchicalListEditor openOnClass:' , cls name , ' andSelector:#' , specSelector , '\'
  1080             , '    "\'.
  1081 
  1082     code := code 
  1083             , '\'
  1084             , '    <resource: #hierarchicalList>\\'
  1085             , '    ^\' 
  1086             , spec
  1087             , ' decodeAsLiteralArray\'
  1088             , Character excla asString
  1089             , ' '
  1090             , Character excla asString
  1091             , '\\'.
  1092 
  1093     code := code withCRs.
  1094     (ReadStream on:code) fileIn.
  1095 
  1096     self updateHistory.
  1097     hasSaved := true.
  1098     modified := false.
  1099 !
  1100 
  1101 doStepDown
  1102     "move selected item after next item"
  1103 
  1104     treeView selectedNodeChangeSequenceOrder:1.
  1105     self updateChannels.
  1106     modified := true
  1107 
  1108 !
  1109 
  1110 doStepIn
  1111     "lets become the selected item a child of its next sister"
  1112 
  1113     treeView selectedNodeBecomeChildOfNext.
  1114     self updateChannels.
  1115     modified := true
  1116 
  1117 
  1118 
  1119 !
  1120 
  1121 doStepOut
  1122     "let selected node become a sister of its current parent"
  1123 
  1124     treeView selectedNodeBecomeSisterOfParent.
  1125     self updateChannels.
  1126     modified := true
  1127 
  1128 
  1129 
  1130 !
  1131 
  1132 doStepUp
  1133     "move selected item before previous item"
  1134 
  1135     treeView selectedNodeChangeSequenceOrder:-1.
  1136     self updateChannels.
  1137     modified := true
  1138 
  1139 
  1140 
  1141 !
  1142 
  1143 openDocumentation
  1144    self openHTMLDocument:'tools/uipainter/HierarchicalListEditor.html'.
  1145 ! !
  1146 
  1147 !HierarchicalListEditor class methodsFor:'documentation'!
  1148 
  1149 version
  1150     ^ '$Header$'
  1151 ! !
  1152