ProjectBrowser.st
changeset 1026 ee8a738cd35d
parent 1025 33c3db52cdc8
child 1037 3a75844e668a
equal deleted inserted replaced
1025:33c3db52cdc8 1026:ee8a738cd35d
     1 ApplicationModel subclass:#ProjectBrowser
     1 ApplicationModel subclass:#ProjectBrowser
     2 	instanceVariableNames:'knownProjects'
     2 	instanceVariableNames:'projectTree'
     3 	classVariableNames:''
     3 	classVariableNames:''
     4 	poolDictionaries:''
     4 	poolDictionaries:''
     5 	category:'Interface-Smalltalk'
     5 	category:'Interface-Smalltalk'
     6 !
     6 !
     7 
     7 
     8 TreeItem subclass:#ProjectTreeItem
     8 TreeItem subclass:#ProjectTreeItem
     9 	instanceVariableNames:'action'
     9 	instanceVariableNames:'action'
       
    10 	classVariableNames:''
       
    11 	poolDictionaries:''
       
    12 	privateIn:ProjectBrowser
       
    13 !
       
    14 
       
    15 ProjectBrowser::ProjectTreeItem subclass:#ProjectNode
       
    16 	instanceVariableNames:''
    10 	classVariableNames:''
    17 	classVariableNames:''
    11 	poolDictionaries:''
    18 	poolDictionaries:''
    12 	privateIn:ProjectBrowser
    19 	privateIn:ProjectBrowser
    13 !
    20 !
    14 
    21 
    58               )
    65               )
    59           )
    66           )
    60       )
    67       )
    61 !
    68 !
    62 
    69 
       
    70 rightCanvasSpecForEditableText
       
    71     "This resource specification was automatically generated
       
    72      by the UIPainter of ST/X."
       
    73 
       
    74     "Do not manually edit this!! If it is corrupted,
       
    75      the UIPainter may not be able to read the specification."
       
    76 
       
    77     "
       
    78      UIPainter new openOnClass:ProjectBrowser andSelector:#emptyRightCanvasSpec
       
    79      ProjectBrowser new openInterface:#emptyRightCanvasSpec
       
    80     "
       
    81 
       
    82     <resource: #canvas>
       
    83 
       
    84     ^
       
    85      
       
    86        #(#FullSpec
       
    87           #window: 
       
    88            #(#WindowSpec
       
    89               #name: 'NewApplication'
       
    90               #layout: #(#LayoutFrame 216 0 173 0 515 0 472 0)
       
    91               #label: 'NewApplication'
       
    92               #min: #(#Point 10 10)
       
    93               #max: #(#Point 1280 1024)
       
    94               #bounds: #(#Rectangle 216 173 516 473)
       
    95               #usePreferredExtent: false
       
    96           )
       
    97           #component: 
       
    98            #(#SpecCollection
       
    99               #collection: 
       
   100                #(
       
   101                  #(#TextEditorSpec
       
   102                     #name: 'TextEditor1'
       
   103                     #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
   104                     #model: #rightCanvasTextHolder
       
   105                     #hasHorizontalScrollBar: true
       
   106                     #hasVerticalScrollBar: true
       
   107                     #miniScrollerHorizontal: true
       
   108                     #isReadOnly: false
       
   109                 )
       
   110               )
       
   111           )
       
   112       )
       
   113 !
       
   114 
       
   115 rightCanvasSpecForReadOnlyText
       
   116     "This resource specification was automatically generated
       
   117      by the UIPainter of ST/X."
       
   118 
       
   119     "Do not manually edit this!! If it is corrupted,
       
   120      the UIPainter may not be able to read the specification."
       
   121 
       
   122     "
       
   123      UIPainter new openOnClass:ProjectBrowser andSelector:#emptyRightCanvasSpec
       
   124      ProjectBrowser new openInterface:#emptyRightCanvasSpec
       
   125     "
       
   126 
       
   127     <resource: #canvas>
       
   128 
       
   129     ^
       
   130      
       
   131        #(#FullSpec
       
   132           #window: 
       
   133            #(#WindowSpec
       
   134               #name: 'NewApplication'
       
   135               #layout: #(#LayoutFrame 216 0 173 0 515 0 472 0)
       
   136               #label: 'NewApplication'
       
   137               #min: #(#Point 10 10)
       
   138               #max: #(#Point 1280 1024)
       
   139               #bounds: #(#Rectangle 216 173 516 473)
       
   140               #usePreferredExtent: false
       
   141           )
       
   142           #component: 
       
   143            #(#SpecCollection
       
   144               #collection: 
       
   145                #(
       
   146                  #(#TextEditorSpec
       
   147                     #name: 'TextEditor1'
       
   148                     #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
   149                     #model: #rightCanvasTextHolder
       
   150                     #hasHorizontalScrollBar: true
       
   151                     #hasVerticalScrollBar: true
       
   152                     #miniScrollerHorizontal: true
       
   153                     #isReadOnly: true
       
   154                 )
       
   155               )
       
   156           )
       
   157       )
       
   158 !
       
   159 
    63 windowSpec
   160 windowSpec
    64     "This resource specification was automatically generated
   161     "This resource specification was automatically generated
    65      by the UIPainter of ST/X."
   162      by the UIPainter of ST/X."
    66 
   163 
    67     "Do not manually edit this!! If it is corrupted,
   164     "Do not manually edit this!! If it is corrupted,
    79      
   176      
    80        #(#FullSpec
   177        #(#FullSpec
    81           #window: 
   178           #window: 
    82            #(#WindowSpec
   179            #(#WindowSpec
    83               #name: 'ProjectBrowser'
   180               #name: 'ProjectBrowser'
    84               #layout: #(#LayoutFrame 16 0 31 0 579 0 353 0)
   181               #layout: #(#LayoutFrame 216 0 173 0 779 0 495 0)
    85               #label: 'ProjectBrowser'
   182               #label: 'ProjectBrowser'
    86               #min: #(#Point 10 10)
   183               #min: #(#Point 10 10)
    87               #max: #(#Point 1024 768)
   184               #max: #(#Point 1024 768)
    88               #bounds: #(#Rectangle 16 31 580 354)
   185               #bounds: #(#Rectangle 216 173 780 496)
    89               #menu: #mainMenu
   186               #menu: #mainMenu
    90               #usePreferredExtent: false
   187               #usePreferredExtent: false
    91           )
   188           )
    92           #component: 
   189           #component: 
    93            #(#SpecCollection
   190            #(#SpecCollection
   107                         #collection: 
   204                         #collection: 
   108                          #(
   205                          #(
   109                            #(#SelectionInTreeViewSpec
   206                            #(#SelectionInTreeViewSpec
   110                               #name: 'TreeList1'
   207                               #name: 'TreeList1'
   111                               #model: #selectedTreeNode
   208                               #model: #selectedTreeNode
       
   209                               #menu: #itemMenuHolder
   112                               #hasHorizontalScrollBar: true
   210                               #hasHorizontalScrollBar: true
   113                               #hasVerticalScrollBar: true
   211                               #hasVerticalScrollBar: true
   114                               #miniScrollerHorizontal: true
   212                               #miniScrollerHorizontal: true
   115                               #showRoot: false
   213                               #showRoot: false
   116                               #showDirectoryIndicatorForRoot: false
   214                               #showDirectoryIndicatorForRoot: false
   125                               #hasVerticalScrollBar: false
   223                               #hasVerticalScrollBar: false
   126                               #specHolder: #currentCanvasHolder
   224                               #specHolder: #currentCanvasHolder
   127                           )
   225                           )
   128                         )
   226                         )
   129                     )
   227                     )
   130                     #handles: #(#Any 0.274823 1.0)
   228                     #handles: #(#Any 0.379433 1.0)
   131                 )
   229                 )
   132               )
   230               )
   133           )
   231           )
   134       )
   232       )
   135 ! !
   233 ! !
   180                       )
   278                       )
   181                        #(#MenuItem
   279                        #(#MenuItem
   182                           #label: 'Save'
   280                           #label: 'Save'
   183                           #translateLabel: true
   281                           #translateLabel: true
   184                           #value: #saveProject
   282                           #value: #saveProject
       
   283                           #enabled: #hasProjectSelectedHolder
   185                       )
   284                       )
   186                        #(#MenuItem
   285                        #(#MenuItem
   187                           #label: 'Save As...'
   286                           #label: 'Save As...'
   188                           #translateLabel: true
   287                           #translateLabel: true
   189                           #value: #saveProjectAs
   288                           #value: #saveProjectAs
       
   289                           #enabled: #hasProjectSelectedHolder
   190                       )
   290                       )
   191                        #(#MenuItem
   291                        #(#MenuItem
   192                           #label: '-'
   292                           #label: '-'
   193                       )
   293                       )
   194                        #(#MenuItem
   294                        #(#MenuItem
   197                           #value: #closeRequest
   297                           #value: #closeRequest
   198                       )
   298                       )
   199                     ) nil
   299                     ) nil
   200                     nil
   300                     nil
   201                 )
   301                 )
       
   302             )
       
   303              #(#MenuItem
       
   304                 #label: 'Project'
       
   305                 #translateLabel: true
       
   306                 #submenuChannel: #projectItemMenu
   202             )
   307             )
   203              #(#MenuItem
   308              #(#MenuItem
   204                 #label: 'Help'
   309                 #label: 'Help'
   205                 #translateLabel: true
   310                 #translateLabel: true
   206                 #startGroup: #right
   311                 #startGroup: #right
   271                 #labelImage: #(#ResourceRetriever #Icon #saveIcon)
   376                 #labelImage: #(#ResourceRetriever #Icon #saveIcon)
   272             )
   377             )
   273           ) nil
   378           ) nil
   274           nil
   379           nil
   275       )
   380       )
       
   381 !
       
   382 
       
   383 projectItemMenu
       
   384     "This resource specification was automatically generated
       
   385      by the MenuEditor of ST/X."
       
   386 
       
   387     "Do not manually edit this!! If it is corrupted,
       
   388      the MenuEditor may not be able to read the specification."
       
   389 
       
   390     "
       
   391      MenuEditor new openOnClass:ProjectBrowser andSelector:#projectItemMenu
       
   392      (Menu new fromLiteralArrayEncoding:(ProjectBrowser projectItemMenu)) startUp
       
   393     "
       
   394 
       
   395     <resource: #menu>
       
   396 
       
   397     ^
       
   398      
       
   399        #(#Menu
       
   400           
       
   401            #(
       
   402              #(#MenuItem
       
   403                 #label: 'Rename...'
       
   404                 #translateLabel: true
       
   405                 #value: #renameProject
       
   406                 #enabled: #hasProjectSelectedHolder
       
   407             )
       
   408              #(#MenuItem
       
   409                 #label: '-'
       
   410             )
       
   411              #(#MenuItem
       
   412                 #label: 'New SubProject'
       
   413                 #translateLabel: true
       
   414                 #value: #newSubProject
       
   415                 #enabled: #hasProjectSelectedHolder
       
   416             )
       
   417              #(#MenuItem
       
   418                 #label: '-'
       
   419             )
       
   420              #(#MenuItem
       
   421                 #label: 'Remove...'
       
   422                 #translateLabel: true
       
   423                 #value: #removeProject
       
   424                 #enabled: #hasProjectSelectedHolder
       
   425             )
       
   426           ) nil
       
   427           nil
       
   428       )
   276 ! !
   429 ! !
   277 
   430 
   278 !ProjectBrowser methodsFor:'aspects'!
   431 !ProjectBrowser methodsFor:'aspects'!
   279 
   432 
   280 currentCanvasHolder
   433 currentCanvasHolder
   290         builder aspectAt:#currentCanvasHolder put:(holder :=  ValueHolder new).
   443         builder aspectAt:#currentCanvasHolder put:(holder :=  ValueHolder new).
   291     ].
   444     ].
   292     ^ holder.
   445     ^ holder.
   293 !
   446 !
   294 
   447 
       
   448 hasProjectSelectedHolder
       
   449     ^ [
       
   450         self hasProjectNodeSelected
       
   451       ]
       
   452 !
       
   453 
   295 projectTreeHolder
   454 projectTreeHolder
   296     "automatically generated by UIPainter ..."
   455     "automatically generated by UIPainter ..."
   297 
   456 
   298     "*** the code below creates a default model when invoked."
   457     "*** the code below creates a default model when invoked."
   299     "*** (which may not be the one you wanted)"
   458     "*** (which may not be the one you wanted)"
   339 ! !
   498 ! !
   340 
   499 
   341 !ProjectBrowser methodsFor:'initialization'!
   500 !ProjectBrowser methodsFor:'initialization'!
   342 
   501 
   343 postBuildWith:aBuiler
   502 postBuildWith:aBuiler
   344     self setupCanvasForNoSelection
   503     self setupCanvasForNoSelection.
       
   504     ^ super postBuildWith:aBuiler
   345 !
   505 !
   346 
   506 
   347 setupCanvasForNoSelection
   507 setupCanvasForNoSelection
   348     self currentCanvasHolder value:(self class emptyRightCanvasSpec).
   508     self showReadOnlyText:'Please select an existing,
   349     self rightCanvasTextHolder value:'Please select an existing,
       
   350 or create a new project.'.
   509 or create a new project.'.
   351 ! !
   510 ! !
   352 
   511 
       
   512 !ProjectBrowser methodsFor:'menus'!
       
   513 
       
   514 itemMenu
       
   515     self hasProjectNodeSelected ifTrue:[
       
   516         ^ self class projectItemMenu
       
   517     ].      
       
   518 
       
   519     ^ nil
       
   520 !
       
   521 
       
   522 itemMenuHolder
       
   523     ^ [ self itemMenu]
       
   524 ! !
       
   525 
   353 !ProjectBrowser methodsFor:'private'!
   526 !ProjectBrowser methodsFor:'private'!
   354 
   527 
       
   528 hasProjectNodeSelected
       
   529     |selectedNode|
       
   530 
       
   531     selectedNode := self selectedTreeNode value.
       
   532     selectedNode isNil ifTrue:[^ false].
       
   533 
       
   534     ^ selectedNode isProjectNode
       
   535 
       
   536 !
       
   537 
   355 nodeFor:aProject
   538 nodeFor:aProject
       
   539     "generate and return a treeNode for some project"
       
   540 
   356     |projectName pNode 
   541     |projectName pNode 
   357      propertiesNode docNode classesNode subprojectsNode filesNode
   542      propertiesNode docNode classesNode subprojectsNode filesNode
   358      commentNode|
   543      commentNode prerequisitesNode|
   359 
   544 
   360     projectName := aProject name.
   545     projectName := aProject name.
   361     pNode := ProjectTreeItem name:projectName.
   546     pNode := ProjectNode name:projectName.
   362     pNode contents:aProject.
   547     pNode contents:aProject.
   363 
   548 
   364     pNode add:(commentNode := ProjectTreeItem name:'Comment').
   549     pNode add:(commentNode := ProjectTreeItem name:'Comment').
   365     pNode add:(docNode := ProjectTreeItem name:'Documentation').
   550     pNode add:(docNode := ProjectTreeItem name:'Documentation').
   366     pNode add:(propertiesNode := ProjectTreeItem name:'Properties').
   551     pNode add:(propertiesNode := ProjectTreeItem name:'Properties').
   367     pNode add:(classesNode := ProjectTreeItem name:'Classes').
   552     pNode add:(classesNode := ProjectTreeItem name:'Classes').
       
   553     pNode add:(prerequisitesNode := ProjectTreeItem name:'Prerequisites').
   368     pNode add:(subprojectsNode := ProjectTreeItem name:'SubProjects').
   554     pNode add:(subprojectsNode := ProjectTreeItem name:'SubProjects').
   369     pNode add:(filesNode := ProjectTreeItem name:'Files').
   555     pNode add:(filesNode := ProjectTreeItem name:'Files').
   370 
   556 
   371     aProject subProjects do:[:aSubProject |
   557     aProject subProjects do:[:aSubProject |
   372         subprojectsNode add:(self nodeFor:aSubProject)
   558         subprojectsNode add:(self nodeFor:aSubProject)
   373     ].
   559     ].
   374 
   560 
   375     commentNode action:[:item | self showCommentOf:item].
   561     commentNode action:[:item | self showCommentOf:item].
   376     docNode contents:nil.
   562     commentNode contents:#comment.
   377     propertiesNode contents:nil.
   563 
   378     classesNode contents:nil.
   564     docNode contents:#documentation.
   379     subprojectsNode contents:nil.
   565 
   380     filesNode contents:nil.
   566     propertiesNode contents:#properties.
       
   567 
       
   568     prerequisitesNode contents:#prerequisites.
       
   569 
       
   570     subprojectsNode contents:#subprojects.
       
   571 
       
   572     filesNode contents:#files.
   381 
   573 
   382     ^ pNode
   574     ^ pNode
       
   575 
   383 !
   576 !
   384 
   577 
   385 projectTree
   578 projectTree
   386     |tree root|
   579     |tree root|
   387 
   580 
   388     tree := SelectionInTree new.
   581     projectTree isNil ifTrue:[
   389     tree root:(root := TreeItem name:'invisibleRoot').
   582         tree := SelectionInTree new.
   390 
   583         tree root:(root := TreeItem name:'invisibleRoot').
   391     Project knownProjects do:[:aProject |
   584 
   392         root add:(self nodeFor:aProject).
   585         Project knownProjects do:[:aProject |
   393     ].
   586             root add:(self nodeFor:aProject).
   394 
   587         ].
   395     ^ root
   588         projectTree := root.
       
   589     ].
       
   590 
       
   591     ^ projectTree
   396 !
   592 !
   397 
   593 
   398 updateRightCanvas
   594 updateRightCanvas
   399     |selectedNode nodeContents|
   595     |selectedNode nodeContents|
   400 
   596 
   401     selectedNode := self selectedTreeNode value.
   597     selectedNode := self selectedTreeNode value.
   402     selectedNode isNil ifTrue:[
   598     selectedNode isNil ifTrue:[
   403         self setupCanvasForNoSelection.
   599         self setupCanvasForNoSelection.
   404         ^ self
   600         ^ self
   405     ].
   601     ].
   406     nodeContents := selectedNode contents.
   602 
   407     (nodeContents isMemberOf:Project) ifTrue:[
   603     selectedNode isProjectNode ifTrue:[
   408         self currentCanvasHolder value:(self class emptyRightCanvasSpec).
   604         self showCommentOf:selectedNode.
   409         self rightCanvasTextHolder value:nodeContents comment.
       
   410         ^ self.
   605         ^ self.
   411     ].
   606     ].
   412 
   607 
   413     self currentCanvasHolder value:(self class emptyRightCanvasSpec).
   608     self currentCanvasHolder value:(self class emptyRightCanvasSpec).
   414     self rightCanvasTextHolder value:''.
   609     self rightCanvasTextHolder value:''.
   427     action notNil ifTrue:[
   622     action notNil ifTrue:[
   428         action value:item.
   623         action value:item.
   429     ].
   624     ].
   430 !
   625 !
   431 
   626 
       
   627 newProject
       
   628     |newNode newProject|
       
   629 
       
   630     newProject := Project new.
       
   631     newNode := self nodeFor:newProject.
       
   632     projectTree add:newNode.
       
   633     self projectTreeHolder root:projectTree.
       
   634 
       
   635 !
       
   636 
       
   637 newSubProject
       
   638     |selectedNode subNode newNode parentProject newProject|
       
   639 
       
   640     self hasProjectNodeSelected ifTrue:[
       
   641         selectedNode := self selectedTreeNode value.
       
   642         parentProject := selectedNode contents.
       
   643 
       
   644         newProject := Project new.
       
   645         newNode := self nodeFor:newProject.
       
   646 
       
   647         parentProject addSubProject:newProject.
       
   648         subNode := selectedNode children detect:[:child | child contents == #subprojects].
       
   649         subNode add:newNode.
       
   650         self projectTreeHolder root:projectTree.
       
   651     ]
       
   652 !
       
   653 
       
   654 removeSubProject
       
   655     |projectToRemove selectedNode subNode newNode parentProject newProject|
       
   656 
       
   657     self hasProjectNodeSelected ifTrue:[
       
   658         selectedNode := self selectedTreeNode value.
       
   659         projectToRemove := selectedNode contents.
       
   660 
       
   661         selectedNode parentNode isProjectNode.
       
   662 
       
   663         parentProject addSubProject:newProject.
       
   664         subNode := selectedNode children detect:[:child | child contents == #subprojects].
       
   665         subNode add:newNode.
       
   666         self projectTreeHolder root:projectTree.
       
   667     ]
       
   668 !
       
   669 
   432 showCommentOf:anItem
   670 showCommentOf:anItem
   433     |project|
   671     |projectItem project|
   434 
   672 
   435     project := anItem parent contents.
   673     anItem contents == #comment ifTrue:[
   436 
   674         projectItem := anItem parent
   437     self currentCanvasHolder value:(self class emptyRightCanvasSpec).
   675     ] ifFalse:[
       
   676         projectItem := anItem
       
   677     ].
       
   678     project := projectItem contents.
       
   679 
       
   680     self currentCanvasHolder value:(self class rightCanvasSpecForEditableText).
   438     self rightCanvasTextHolder value:project comment.
   681     self rightCanvasTextHolder value:project comment.
       
   682 
       
   683 !
       
   684 
       
   685 showReadOnlyText:someText
       
   686     self currentCanvasHolder value:(self class rightCanvasSpecForReadOnlyText).
       
   687     self rightCanvasTextHolder value:someText.
   439 
   688 
   440 !
   689 !
   441 
   690 
   442 showTreeItem:anItem
   691 showTreeItem:anItem
   443     anItem contents == #comment ifTrue:[
   692     anItem contents == #comment ifTrue:[
   456 action:something
   705 action:something
   457     "set the value of the instance variable 'action' (automatically generated)"
   706     "set the value of the instance variable 'action' (automatically generated)"
   458 
   707 
   459     action := something.! !
   708     action := something.! !
   460 
   709 
       
   710 !ProjectBrowser::ProjectTreeItem methodsFor:'queries'!
       
   711 
       
   712 isProjectNode
       
   713     ^ false
       
   714 ! !
       
   715 
       
   716 !ProjectBrowser::ProjectNode methodsFor:'queries'!
       
   717 
       
   718 isProjectNode
       
   719     ^ true
       
   720 
       
   721 
       
   722 ! !
       
   723 
   461 !ProjectBrowser class methodsFor:'documentation'!
   724 !ProjectBrowser class methodsFor:'documentation'!
   462 
   725 
   463 version
   726 version
   464     ^ '$Header$'
   727     ^ '$Header$'
   465 ! !
   728 ! !