FileApplicationNoteBook.st
changeset 3892 321c1729db5b
child 3906 8a76cb4f5884
equal deleted inserted replaced
3891:bd4e9d606e98 3892:321c1729db5b
       
     1 "{ Package: 'stx:libtool' }"
       
     2 
       
     3 AbstractFileBrowser subclass:#FileApplicationNoteBook
       
     4 	instanceVariableNames:'canvasHolder selectedEditorPage listOfApplications tabMenuIndex
       
     5 		tabList selectionHistoryList privateTabList'
       
     6 	classVariableNames:''
       
     7 	poolDictionaries:''
       
     8 	category:'Interface-Tools-File'
       
     9 !
       
    10 
       
    11 AbstractFileApplicationNoteBookComponent subclass:#ArchiveViewApplication
       
    12 	instanceVariableNames:'archiveFileList enableStopButton fileTable currentSortOrder
       
    13 		selectionHolder tableColumns commandProcess errorListHolder
       
    14 		viewErrorList temporaryDirectory enableRemoveErrorOutput
       
    15 		errorListVisibilityHolder hasListEntriesHolder archiver process
       
    16 		terminateByMe columnDescriptors'
       
    17 	classVariableNames:''
       
    18 	poolDictionaries:''
       
    19 	privateIn:FileApplicationNoteBook
       
    20 !
       
    21 
       
    22 Object subclass:#ArchivItem
       
    23 	instanceVariableNames:'fileName size dateAndTime permissions icon ownerGroup method crc
       
    24 		compressSize ratio version type isDirectory'
       
    25 	classVariableNames:''
       
    26 	poolDictionaries:''
       
    27 	privateIn:FileApplicationNoteBook::ArchiveViewApplication
       
    28 !
       
    29 
       
    30 AbstractFileApplicationNoteBookComponent subclass:#CommandResult
       
    31 	instanceVariableNames:'resultStream enableStopButton process labelHolder'
       
    32 	classVariableNames:''
       
    33 	poolDictionaries:''
       
    34 	privateIn:FileApplicationNoteBook
       
    35 !
       
    36 
       
    37 AbstractFileApplicationNoteBookComponent subclass:#HtmlViewApplication
       
    38 	instanceVariableNames:'htmlView labelHolder infoLabelHolder'
       
    39 	classVariableNames:''
       
    40 	poolDictionaries:''
       
    41 	privateIn:FileApplicationNoteBook
       
    42 !
       
    43 
       
    44 AbstractFileApplicationNoteBookComponent subclass:#ImageViewApplication
       
    45 	instanceVariableNames:'imageFile imageView image fitSize fitMode'
       
    46 	classVariableNames:''
       
    47 	poolDictionaries:''
       
    48 	privateIn:FileApplicationNoteBook
       
    49 !
       
    50 
       
    51 AbstractFileApplicationNoteBookComponent subclass:#Terminal
       
    52 	instanceVariableNames:'terminalView'
       
    53 	classVariableNames:''
       
    54 	poolDictionaries:''
       
    55 	privateIn:FileApplicationNoteBook
       
    56 !
       
    57 
       
    58 AbstractFileApplicationNoteBookComponent subclass:#TextEditor
       
    59 	instanceVariableNames:'fileContentsModel doSaveFile modifiedChannel editView enableSave
       
    60 		enableReload presentation changeItemProcess closeApplication
       
    61 		semaChangeItem printAsHexDump itemChanged itemRemoved
       
    62 		enableHexToggle textEditorChangeModificationTime'
       
    63 	classVariableNames:''
       
    64 	poolDictionaries:''
       
    65 	privateIn:FileApplicationNoteBook
       
    66 !
       
    67 
       
    68 AbstractFileApplicationNoteBookComponent subclass:#XViewApplication
       
    69 	instanceVariableNames:'xView xFile vncServerPID vncPortNr vncConnection viewerPID
       
    70 		vncLock vncServerIsTerminated xItem ext'
       
    71 	classVariableNames:''
       
    72 	poolDictionaries:''
       
    73 	privateIn:FileApplicationNoteBook
       
    74 !
       
    75 
       
    76 
       
    77 !FileApplicationNoteBook class methodsFor:'application list'!
       
    78 
       
    79 applicationList
       
    80 " returns a list of all applications to start by the NoteBookApplication with 
       
    81                 #className                         #type                    
       
    82 
       
    83             example:
       
    84             #(  #'FooEditor'                       nil                      )
       
    85 "
       
    86 
       
    87     ^ #(
       
    88             #(  #'TextEditor'                      #file                    )
       
    89             #(  #'TextEditor'                      #directoryDescription    )
       
    90             #(  #'HtmlViewApplication'             nil                      )
       
    91             #(  #'FindFileApplication'             nil                      )
       
    92             #(  #'Terminal'                        nil                      )
       
    93             #(  #'ImageViewApplication'            nil                      )
       
    94             #(  #'ArchiveViewApplication'          nil                      )
       
    95             #(  #'CommandResult'                   nil                      )
       
    96             #(  #'XViewApplication'                nil                      )
       
    97        )
       
    98 !
       
    99 
       
   100 classFor:aApplicationListItem
       
   101     |rawName cls|
       
   102 
       
   103     rawName := aApplicationListItem at:1.
       
   104     (cls := self privateClassesAt:rawName) isNil ifTrue:[
       
   105         cls := Smalltalk at:rawName.
       
   106     ].
       
   107     ^ cls
       
   108 !
       
   109 
       
   110 defaultApplication
       
   111 " returns the application to be started if no itemQuery returns true or no supportedSuffix is supported
       
   112 "
       
   113 
       
   114     ^ self applicationList detect:[: applItem|
       
   115         (((self classFor:applItem) == self textEditorClass)
       
   116         and:[(self typeFor:applItem) == #file])
       
   117     ] ifNone:[nil].
       
   118 !
       
   119 
       
   120 typeFor:aApplicationListItem
       
   121 
       
   122     ^ aApplicationListItem at:2
       
   123 ! !
       
   124 
       
   125 !FileApplicationNoteBook class methodsFor:'classAccess'!
       
   126 
       
   127 textEditorClass
       
   128 
       
   129     ^ TextEditor
       
   130 ! !
       
   131 
       
   132 !FileApplicationNoteBook class methodsFor:'defaults'!
       
   133 
       
   134 openAnotherApplicationOnSameItem
       
   135 
       
   136     ^ false
       
   137 ! !
       
   138 
       
   139 !FileApplicationNoteBook class methodsFor:'interface specs'!
       
   140 
       
   141 windowSpec
       
   142     "This resource specification was automatically generated
       
   143      by the UIPainter of ST/X."
       
   144 
       
   145     "Do not manually edit this!! If it is corrupted,
       
   146      the UIPainter may not be able to read the specification."
       
   147 
       
   148     "
       
   149      UIPainter new openOnClass:NoteBookApplication andSelector:#windowSpec
       
   150      NoteBookApplication new openInterface:#windowSpec
       
   151      NoteBookApplication open
       
   152     "
       
   153 
       
   154     <resource: #canvas>
       
   155 
       
   156     ^ 
       
   157      #(#FullSpec
       
   158         #name: #windowSpec
       
   159         #window: 
       
   160        #(#WindowSpec
       
   161           #label: 'FileBrowserV2TextEditor'
       
   162           #name: 'FileBrowserV2TextEditor'
       
   163           #min: #(#Point 10 10)
       
   164           #max: #(#Point 1024 768)
       
   165           #bounds: #(#Rectangle 16 42 316 342)
       
   166         )
       
   167         #component: 
       
   168        #(#SpecCollection
       
   169           #collection: #(
       
   170            #(#NoteBookViewSpec
       
   171               #name: 'CommandAndTextEditor'
       
   172               #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
   173               #model: #selectedEditorPage
       
   174               #menu: #tabList
       
   175               #useIndex: true
       
   176               #accessTabMenuAction: #tabMenuAt:
       
   177               #canvas: #canvasHolder
       
   178               #keepCanvasAlive: true
       
   179             )
       
   180            )
       
   181          
       
   182         )
       
   183       )
       
   184 ! !
       
   185 
       
   186 !FileApplicationNoteBook class methodsFor:'menu specs'!
       
   187 
       
   188 tabMenu
       
   189     "This resource specification was automatically generated
       
   190      by the MenuEditor of ST/X."
       
   191 
       
   192     "Do not manually edit this!! If it is corrupted,
       
   193      the MenuEditor may not be able to read the specification."
       
   194 
       
   195     "
       
   196      MenuEditor new openOnClass:FileApplicationNoteBook andSelector:#tabMenu
       
   197      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook tabMenu)) startUp
       
   198     "
       
   199 
       
   200     <resource: #menu>
       
   201 
       
   202     ^ 
       
   203      #(#Menu
       
   204         #(
       
   205          #(#MenuItem
       
   206             #label: 'Close'
       
   207             #translateLabel: true
       
   208             #value: #doCloseApplication
       
   209           )
       
   210          )
       
   211         nil
       
   212         nil
       
   213       )
       
   214 ! !
       
   215 
       
   216 !FileApplicationNoteBook methodsFor:'accessing'!
       
   217 
       
   218 listOfApplications
       
   219     "return the value of the instance variable 'listOfApplications' (automatically generated)"
       
   220 
       
   221     listOfApplications isNil ifTrue:[
       
   222         listOfApplications := OrderedCollection new.
       
   223     ].
       
   224     ^ listOfApplications
       
   225 !
       
   226 
       
   227 selectionHistoryList
       
   228 
       
   229     selectionHistoryList isNil ifTrue:[
       
   230         selectionHistoryList := OrderedCollection new.
       
   231     ].
       
   232     ^ selectionHistoryList
       
   233 !
       
   234 
       
   235 selectionHistoryList:aCol
       
   236 
       
   237     selectionHistoryList := aCol 
       
   238 ! !
       
   239 
       
   240 !FileApplicationNoteBook methodsFor:'accessing applications'!
       
   241 
       
   242 getAllApplicationsByClass:aClass andType:aType
       
   243 
       
   244     ^ self listOfApplications select:[ : appl  |
       
   245         ((appl class = aClass)
       
   246         and:[appl type = aType])
       
   247     ].
       
   248 !
       
   249 
       
   250 getApplicationByType:aType
       
   251 
       
   252     ^ self listOfApplications detect:[ : appl  | 
       
   253         (appl type == aType)
       
   254     ] ifNone:[nil].
       
   255 !
       
   256 
       
   257 getIndexFor:aApplication
       
   258 
       
   259     | index |
       
   260 
       
   261     index := self listOfApplications indexOf:aApplication.
       
   262     index ~~ 0 ifTrue:[
       
   263         ^ index.
       
   264     ].
       
   265     ^ nil.
       
   266 !
       
   267 
       
   268 getSameApplicationsFor:aApplication
       
   269 
       
   270     ^ self listOfApplications select:[ : appl |
       
   271         ( (appl ~= aApplication)    
       
   272         and:[ (appl isKindOf:(aApplication class)) 
       
   273         and:[ (appl item = (aApplication item)) 
       
   274         and:[ (appl type == aApplication type) ]]])
       
   275     ].
       
   276 ! !
       
   277 
       
   278 !FileApplicationNoteBook methodsFor:'actions-app-common'!
       
   279 
       
   280 changeItem:aItem for:aAppl
       
   281 
       
   282     | applIndex string|
       
   283 
       
   284     applIndex := self getIndexFor:aAppl.
       
   285     (aItem notNil and:[aItem isDirectory not]) ifTrue:[
       
   286         (aAppl changeItem:aItem) ifFalse:[ ^ self].
       
   287         self fileHistory add:aItem.
       
   288         self enableFileHistory value:true.
       
   289     ].
       
   290     string := aAppl getTabString.
       
   291     self privateTabList at:applIndex put:string.
       
   292     self doSelect:aAppl.
       
   293 !
       
   294 
       
   295 closeSubCanvas:aApplication
       
   296 
       
   297     | applIndex historyList localHistoryList|
       
   298 
       
   299     applIndex := self getIndexFor:aApplication.
       
   300     applIndex notNil ifTrue:[
       
   301 "/        "/ UPDATE THE LAST SELECTION BECAUSE SEL INDEX IS DECREMENTED FOR HIGHER INDEXES
       
   302 "/        self lastSelection:applIndex.
       
   303 
       
   304         historyList := self selectionHistoryList.
       
   305         historyList remove:applIndex ifAbsent:nil.
       
   306         localHistoryList := OrderedCollection new.
       
   307         historyList notEmpty ifTrue:[
       
   308             self selectedEditorPage value:(historyList last).
       
   309         ] ifFalse:[
       
   310             self selectedEditorPage value:1.
       
   311         ].
       
   312         historyList do:[ : index |
       
   313             index <= applIndex ifTrue:[
       
   314                 localHistoryList add:index
       
   315             ] ifFalse:[
       
   316                 localHistoryList add:(index - 1)
       
   317             ]
       
   318         ].
       
   319         self selectionHistoryList:localHistoryList.
       
   320         self listOfApplications removeIndex:applIndex.
       
   321         self privateTabList removeIndex:applIndex.
       
   322         self privateTabList isEmpty ifTrue:[
       
   323             self viewNoteBookApplicationHolder value:false.
       
   324             self enableViewNoteBookApplication value:false.
       
   325         ] ifFalse:[
       
   326             historyList notEmpty ifTrue:[
       
   327                 self selectedEditorPage value:(self selectionHistoryList last).
       
   328             ]
       
   329         ]
       
   330     ].
       
   331 
       
   332     "/ because subCanvas was configured to keep its view,
       
   333     "/ we must destroy it here.
       
   334     [aApplication window destroy] fork.
       
   335 !
       
   336 
       
   337 doCloseApplication
       
   338 
       
   339     | appl |
       
   340 
       
   341     appl := self listOfApplications at:tabMenuIndex.
       
   342     appl doClose.
       
   343 !
       
   344 
       
   345 openApplByFileItem:aItem
       
   346 
       
   347 " use the default class list for open of applications by item "
       
   348 
       
   349     | applList applItem itemClass|
       
   350 
       
   351     aItem isNil ifTrue:[ ^ self ].
       
   352     applList := self applicationList.
       
   353     applItem := applList detect:[: aApplItem|
       
   354         itemClass := self class classFor:aApplItem.
       
   355         (itemClass canOpenItem:aItem).
       
   356     ] ifNone:[nil].
       
   357     applItem isNil ifTrue:[ ^ self openDefaultApplicationByItem:aItem].
       
   358     applItem notNil ifTrue:[
       
   359         |  itemType |
       
   360         itemType := self class typeFor:applItem.
       
   361         itemClass := self class classFor:applItem.
       
   362         (self openApplicationClass:itemClass withItem:aItem withType:itemType) isNil ifTrue:[
       
   363             ^ self openDefaultApplicationByItem:aItem.            
       
   364         ].
       
   365     ].
       
   366 !
       
   367 
       
   368 openApplicationClass:aClass withItem:aItem withType:aType
       
   369 
       
   370     | existingAppl newAppl|
       
   371 
       
   372     " do not open not readable items "
       
   373     (aItem notNil and:[aItem isDirectory not and:[aItem fileName isReadable not]]) ifTrue:[
       
   374         Dialog warn:'Can not open unreadable file ', aItem fileName baseName.
       
   375         AbortSignal raise.
       
   376     ].
       
   377     existingAppl := self tryToGetExistingApplFor:aClass withItem:aItem withType:aType.
       
   378     existingAppl notNil ifTrue:[
       
   379         self doSelect:existingAppl.
       
   380         ^ existingAppl
       
   381     ].
       
   382     newAppl := aClass new.
       
   383     newAppl type:aType.
       
   384     (newAppl item:aItem) ifFalse:[ ^ nil ].
       
   385     (aItem notNil and:[aItem isDirectory not]) ifTrue:[
       
   386         self fileHistory add:aItem.
       
   387         self enableFileHistory value:true.
       
   388     ].
       
   389     self setSameFileIndexFor:newAppl.
       
   390     self startApplication:newAppl.
       
   391     ^ newAppl
       
   392 !
       
   393 
       
   394 openDefaultApplicationByItem:aItem
       
   395 " open the default application if no application for item is available or the start of the
       
   396   available application failed
       
   397 "
       
   398     | applItem |
       
   399 
       
   400     applItem := self class defaultApplication.
       
   401     applItem notNil ifTrue:[
       
   402         |  itemType itemClass|
       
   403         itemType := self class typeFor:applItem.
       
   404         itemClass := self class classFor:applItem.
       
   405         ^ self openApplicationClass:itemClass withItem:aItem withType:itemType.
       
   406     ].
       
   407     ^ nil
       
   408 !
       
   409 
       
   410 setSameFileIndexFor:anAppl
       
   411 
       
   412     |sameFiles index item|
       
   413 
       
   414     self class openAnotherApplicationOnSameItem not ifTrue:[
       
   415         anAppl sameFileIndex:nil.
       
   416         ^ self.
       
   417     ].
       
   418     item := anAppl item.
       
   419     item notNil ifTrue:[
       
   420         | hasSameFiles |
       
   421         sameFiles := self getSameApplicationsFor:anAppl.
       
   422         hasSameFiles := sameFiles notEmpty.
       
   423         hasSameFiles ifTrue:[
       
   424             (sameFiles size == 1 and:[sameFiles first sameFileIndex isNil]) ifTrue:[
       
   425                 anAppl sameFileIndex:1.
       
   426                 ^ self
       
   427             ] ifFalse:[
       
   428                 index :=  (sameFiles collect:[:el | (el sameFileIndex ? 1)]) max.
       
   429                 anAppl sameFileIndex:index + 1.
       
   430                 ^ self
       
   431             ]
       
   432         ]. 
       
   433         anAppl sameFileIndex:nil.
       
   434     ].
       
   435 !
       
   436 
       
   437 startApplication:aApplication
       
   438 
       
   439     | window|
       
   440 
       
   441     aApplication masterApplication:self.
       
   442     aApplication window ifNil:[
       
   443         window := ApplicationSubView new.
       
   444         aApplication createBuilder.
       
   445         window client:aApplication.
       
   446     ].
       
   447     self listOfApplications add:aApplication.
       
   448     self privateTabList add:(aApplication getTabString).
       
   449     self viewNoteBookApplicationHolder value:true.
       
   450     self enableViewNoteBookApplication value:true.
       
   451     self doSelect:aApplication.
       
   452     [
       
   453         aApplication postOpenWith:aApplication builder.
       
   454     ] forkAt:Processor activePriority.
       
   455 !
       
   456 
       
   457 tabStringAdd:aString for:aAppl
       
   458 
       
   459     | index text stream|
       
   460 
       
   461     index := self getIndexFor:aAppl.
       
   462     index isNil ifTrue:[ ^ self].
       
   463     text := self privateTabList at:index.
       
   464     stream := WriteStream on:''.
       
   465     stream nextPutAll:text.
       
   466     stream space.
       
   467     stream nextPutAll:aString.
       
   468     self privateTabList at:index put:stream contents.
       
   469     stream close.
       
   470 !
       
   471 
       
   472 tabStringChangeTo:aString for:aAppl
       
   473 
       
   474     | index|
       
   475 
       
   476     index := self getIndexFor:aAppl.
       
   477     index isNil ifTrue:[ ^ self].
       
   478     self privateTabList at:index put:aString.
       
   479 !
       
   480 
       
   481 tryToGetExistingApplFor:aClass withItem:aItem withType:aType
       
   482 
       
   483 
       
   484     |sameAppl changeAppl selAppl|
       
   485 
       
   486     aClass wantNewApplicationAnyway ifTrue:[^ nil].
       
   487     sameAppl := self getAllApplicationsByClass:aClass andType:aType.
       
   488     sameAppl isEmpty ifTrue:[^ nil].
       
   489     ((aType == #directoryDescription) or:[aType == #commandResult]) ifTrue:[
       
   490         changeAppl := sameAppl first.
       
   491     ] ifFalse:[
       
   492         (self openMultipleApplicationsForType value) ifTrue:[
       
   493         "/ open more than one application for a class and a type
       
   494             (self class openAnotherApplicationOnSameItem) ifTrue:[
       
   495                 "/ open a new application anyway, no matters if item already open
       
   496                 ^ nil
       
   497             ] ifFalse:[
       
   498                 "/ if item already changed select the application
       
   499                 selAppl := sameAppl detect:[ : appl  | 
       
   500                         (appl item = aItem) 
       
   501                 ] ifNone:[nil].
       
   502             ].
       
   503         ] ifFalse:[
       
   504             "/ keep in same application change the first application of the same class and type - if item not changed otherwise open new
       
   505                 changeAppl := sameAppl detect:[ : appl  | 
       
   506                         (appl isModified not)
       
   507                 ] ifNone:[nil].
       
   508         ].
       
   509     ].
       
   510     changeAppl notNil ifTrue:[
       
   511         self changeItem:aItem for:changeAppl.
       
   512         selAppl := changeAppl.
       
   513     ].
       
   514     ^ selAppl.
       
   515 ! !
       
   516 
       
   517 !FileApplicationNoteBook methodsFor:'actions-app-spec'!
       
   518 
       
   519 changeDirectoryDescription
       
   520 
       
   521     | aInfoItem|
       
   522 
       
   523     aInfoItem := self getInfoItem.
       
   524     aInfoItem isNil ifTrue:[ ^ self closeDirectoryDescription ].
       
   525     self openDirectoryDescription.
       
   526 !
       
   527 
       
   528 closeDirectoryDescription
       
   529 
       
   530     | dirContApll |
       
   531 
       
   532     dirContApll := self getApplicationByType:#directoryDescription.
       
   533     dirContApll notNil ifTrue:[
       
   534         dirContApll doClose.
       
   535     ].
       
   536 !
       
   537 
       
   538 openArchiveViewApplication:aItem
       
   539 
       
   540     | result |
       
   541     result := self openApplicationClass:ArchiveViewApplication withItem:aItem withType:nil.
       
   542     result isNil ifTrue:[
       
   543         Dialog warn:'file type of ', aItem fileName baseName, ' not yet supported'.
       
   544         ^ self.
       
   545     ].
       
   546 !
       
   547 
       
   548 openCommandResultApplication
       
   549 
       
   550 
       
   551     ^ self openApplicationClass:CommandResult withItem:nil withType:#commandResult
       
   552 !
       
   553 
       
   554 openDirectoryDescription
       
   555 
       
   556     | appl aInfoItem|
       
   557 
       
   558     aInfoItem := self getInfoItem.
       
   559     aInfoItem notNil ifTrue:[
       
   560         appl := self openTextEditorOn:aInfoItem type:#directoryDescription.
       
   561     ].
       
   562 !
       
   563 
       
   564 openSearchFileOn:aItem
       
   565 
       
   566     ^ self openApplicationClass:FindFileApplication withItem:aItem withType:nil
       
   567 !
       
   568 
       
   569 openTerminalApplication:aItem
       
   570 
       
   571     ^ self openApplicationClass:Terminal withItem:aItem withType:nil
       
   572 !
       
   573 
       
   574 openTextEditorOn:aItem 
       
   575 
       
   576     ^ self openTextEditorOn:aItem type:#file 
       
   577 !
       
   578 
       
   579 openTextEditorOn:aItem type:aDirDescrOrFile
       
   580 
       
   581     ^ self openApplicationClass:TextEditor withItem:aItem withType:aDirDescrOrFile
       
   582 ! !
       
   583 
       
   584 !FileApplicationNoteBook methodsFor:'applicationlist access'!
       
   585 
       
   586 applicationList
       
   587     ^ self class applicationList
       
   588 ! !
       
   589 
       
   590 !FileApplicationNoteBook methodsFor:'aspects'!
       
   591 
       
   592 canvasHolder
       
   593 
       
   594     canvasHolder isNil ifTrue:[
       
   595         canvasHolder := ValueHolder new.
       
   596     ].
       
   597     ^ canvasHolder.
       
   598 !
       
   599 
       
   600 privateTabList
       
   601 
       
   602     privateTabList isNil ifTrue:[
       
   603         privateTabList := List new.
       
   604         privateTabList addDependent:self.
       
   605     ].
       
   606     ^ privateTabList.
       
   607 !
       
   608 
       
   609 selectedEditorPage
       
   610 
       
   611     selectedEditorPage isNil ifTrue:[
       
   612         selectedEditorPage := ValueHolder new.
       
   613 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
   614        selectedEditorPage addDependent:self.
       
   615 "/       selectedEditorPage onChangeSend:#selectedEditorPageChanged to:self.
       
   616     ].
       
   617     ^ selectedEditorPage.
       
   618 !
       
   619 
       
   620 tabList
       
   621 
       
   622     tabList isNil ifTrue:[
       
   623         tabList := (List new) asValue.
       
   624     ].
       
   625     ^ tabList.
       
   626 !
       
   627 
       
   628 tabList:aValue
       
   629 
       
   630     tabList := aValue.
       
   631 ! !
       
   632 
       
   633 !FileApplicationNoteBook methodsFor:'change & update'!
       
   634 
       
   635 update:something with:aParameter from:changedObject
       
   636     "Invoked when an object that I depend upon sends a change notification."
       
   637 
       
   638     "stub code automatically generated - please change as required"
       
   639 
       
   640     | appl sel viewDirDescr|
       
   641 
       
   642 
       
   643     changedObject == self currentDirectories ifTrue:[
       
   644         self viewDirectoryDescription value ifTrue:[
       
   645             self changeDirectoryDescription.  
       
   646         ].
       
   647         ^ self.
       
   648     ].
       
   649     changedObject == self viewDirectoryDescription ifTrue:[
       
   650         viewDirDescr := changedObject value.
       
   651         viewDirDescr ifTrue:[
       
   652             self openDirectoryDescription.
       
   653         ] ifFalse:[
       
   654             self closeDirectoryDescription.
       
   655         ].
       
   656         ^ self.
       
   657     ].
       
   658     changedObject == self privateTabList ifTrue:[
       
   659         | privateListOfTabs |
       
   660         privateListOfTabs := changedObject.
       
   661         privateListOfTabs size > 1 ifTrue:[
       
   662             self tabList value:privateListOfTabs.
       
   663             self tabList changed.
       
   664         ] ifFalse:[
       
   665             self tabList value:nil.
       
   666         ].
       
   667         ^ self
       
   668     ].
       
   669     changedObject == self selectedEditorPage ifTrue:[
       
   670         | listOfEdits indexOfLastSel list |
       
   671 
       
   672         sel := changedObject value.
       
   673         "/ dont want the tabs with one application - thats why i have to change my tablist
       
   674         "/ sel goes to if - i want select the last selection
       
   675         sel = 0 ifTrue:[
       
   676             ^ self.
       
   677         ].
       
   678         list := self selectionHistoryList.
       
   679         (list includes:sel) ifTrue:[
       
   680             list remove:sel
       
   681         ].
       
   682         list add:sel.
       
   683         self selectionHistoryList:list.
       
   684         appl := self listOfApplications at:sel.
       
   685         self doSelect:appl.
       
   686     ].
       
   687 
       
   688     ^ super update:something with:aParameter from:changedObject
       
   689 ! !
       
   690 
       
   691 !FileApplicationNoteBook methodsFor:'menu & actions'!
       
   692 
       
   693 tabMenuAt:aTab
       
   694 
       
   695     |menu|
       
   696 
       
   697     menu :=  Menu new fromLiteralArrayEncoding:self class tabMenu.
       
   698     menu ifNil:[ ^ nil ].
       
   699     tabMenuIndex := aTab.
       
   700     menu receiver:self.
       
   701     ^ menu
       
   702 ! !
       
   703 
       
   704 !FileApplicationNoteBook methodsFor:'queries'!
       
   705 
       
   706 getSameFilesModifiedFor:aAppl
       
   707 
       
   708     | sameFileAppl colOfChanged |
       
   709 
       
   710     sameFileAppl := self getSameApplicationsFor:aAppl.
       
   711     sameFileAppl notEmpty ifTrue:[
       
   712         colOfChanged := OrderedCollection new.
       
   713         sameFileAppl do:[ : el |
       
   714             el modifiedChannel value ifTrue:[
       
   715                 colOfChanged add:el.
       
   716             ]
       
   717         ]
       
   718     ].
       
   719     ^ colOfChanged
       
   720 ! !
       
   721 
       
   722 !FileApplicationNoteBook methodsFor:'selection'!
       
   723 
       
   724 doSelect:anAppl
       
   725 
       
   726     | index fileName|
       
   727 
       
   728     fileName := anAppl fileName.
       
   729     fileName notNil ifTrue:[
       
   730         self changeFileBrowserTitleTo:fileName baseName.
       
   731     ].
       
   732     index := self getIndexFor:anAppl.
       
   733 
       
   734     index notNil ifTrue:[
       
   735         canvasHolder value:(anAppl window).
       
   736         self selectedEditorPage value:index.
       
   737     ]
       
   738 ! !
       
   739 
       
   740 !FileApplicationNoteBook methodsFor:'startup & release'!
       
   741 
       
   742 makeDependent
       
   743 
       
   744     self viewDirectoryDescription addDependent:self.
       
   745     self currentDirectories addDependent:self.
       
   746 !
       
   747 
       
   748 postOpenAsSubcanvasWith:aBuilder
       
   749 
       
   750     self viewDirectoryDescription changed.
       
   751     ^ super postOpenAsSubcanvasWith:aBuilder.
       
   752 !
       
   753 
       
   754 postOpenWith:aBuilder
       
   755 
       
   756     "
       
   757     only invoked if the application not started from a master
       
   758     "
       
   759     self openTextEditorOn:(DirectoryContentsBrowser itemClass with:(Filename homeDirectory construct:'.bashrc')).
       
   760     ^ super postOpenWith:aBuilder
       
   761 !
       
   762 
       
   763 preBuildWith:aBuilder
       
   764 
       
   765     self masterApplication isNil ifTrue:[
       
   766         self masterApplication:nil.
       
   767     ].
       
   768     ^ super preBuildWith:aBuilder.
       
   769 ! !
       
   770 
       
   771 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'common options'!
       
   772 
       
   773 SupportedFiles
       
   774 
       
   775     | dict |
       
   776     dict := Dictionary new.
       
   777 
       
   778     #(
       
   779         'application/x-tar-compressed'      tarGZipArchive
       
   780         'application/x-tar'                 tarArchive
       
   781         'application/x-gzip-compressed'     gzipArchive
       
   782         'application/x-zip-compressed'      zipArchive
       
   783     ) pairWiseDo:[ : mimeType :classSelector |
       
   784         dict at:mimeType put:classSelector.
       
   785     ].
       
   786     ^ dict
       
   787 !
       
   788 
       
   789 classSelectorFor:aItem
       
   790 
       
   791     | class |
       
   792     aItem hasMimeType ifFalse:[^nil].
       
   793     class := self SupportedFiles at:(aItem mimeType) ifAbsent:nil.
       
   794     class isNil ifTrue:[
       
   795         (aItem lastButOneSuffix = 'tar' and:[aItem lastSuffix = 'gz']) ifTrue:[
       
   796             class := #tarGZipArchive.
       
   797         ].
       
   798     ].
       
   799     ^ class.
       
   800 ! !
       
   801 
       
   802 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'defaults'!
       
   803 
       
   804 tabStringFor:aApplicationType
       
   805 
       
   806     ^ 'Archive for:'
       
   807 ! !
       
   808 
       
   809 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'image specs'!
       
   810 
       
   811 removeError
       
   812     "This resource specification was automatically generated
       
   813      by the ImageEditor of ST/X."
       
   814 
       
   815     "Do not manually edit this!! If it is corrupted,
       
   816      the ImageEditor may not be able to read the specification."
       
   817 
       
   818     "
       
   819      self removeError inspect
       
   820      ImageEditor openOnClass:self andSelector:#removeError
       
   821      Icon flushCachedIcons
       
   822     "
       
   823 
       
   824     <resource: #image>
       
   825 
       
   826     ^Icon
       
   827         constantNamed:#'FileApplicationNoteBook::ArchiveViewApplication class removeError'
       
   828         ifAbsentPut:[(Depth8Image new) width: 28; height: 22; photometric:(#palette); bitsPerSample:(#(8 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
       
   829 @@@@@@@@@@@FA @@@@@@@@XF@@@@@@@@@@@@@@@@@@@@@@@@@@XF@@@@@@XF@@@@@@@@@@@@@@@@@@@@@@@@@@@@A X@@@XF@@@@@@@@@@@@@@@@@@@@@@@@
       
   830 @@@@@@@FA XF@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@XF@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@XFA X@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@XF
       
   831 @@@FA @@@@@@@@@@@@@@@@@@@@@@@@@@@@XF@@@@@@XF@@@@@@@@@@@@@@@@@@@@@@@@@@XF@@@@@@@@A X@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
   832 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
   833 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
   834 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
   835 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 8 4 8 105 133 190 121 133 157 129 129 129 194 194 194 255 0 0]; mask:((Depth1Image new) width: 28; height: 22; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@LC@@@A!! @@@L0@@@A8@@@@L@@@@G @@@CL@@@A!! @@@0L@@@@@@@BY=5LAIUUT S5UU8D!!UUPAFU\#@@@@@@@LR9@@D)J @A:R(@@P$*@@CIN @@@@@@@@@a') ; yourself); yourself]
       
   836 ! !
       
   837 
       
   838 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'interface specs'!
       
   839 
       
   840 windowSpec
       
   841     "This resource specification was automatically generated
       
   842      by the UIPainter of ST/X."
       
   843 
       
   844     "Do not manually edit this!! If it is corrupted,
       
   845      the UIPainter may not be able to read the specification."
       
   846 
       
   847     "
       
   848      UIPainter new openOnClass:NoteBookApplication::ArchiveViewApplication andSelector:#windowSpec
       
   849      NoteBookApplication::ArchiveViewApplication new openInterface:#windowSpec
       
   850      NoteBookApplication::ArchiveViewApplication open
       
   851     "
       
   852 
       
   853     <resource: #canvas>
       
   854 
       
   855     ^ 
       
   856      #(#FullSpec
       
   857         #name: #windowSpec
       
   858         #window: 
       
   859        #(#WindowSpec
       
   860           #label: 'Archive Application'
       
   861           #name: 'Archive Application'
       
   862           #min: #(#Point 10 10)
       
   863           #max: #(#Point 1024 768)
       
   864           #bounds: #(#Rectangle 12 22 688 514)
       
   865           #menu: #mainMenu
       
   866         )
       
   867         #component: 
       
   868        #(#SpecCollection
       
   869           #collection: #(
       
   870            #(#MenuPanelSpec
       
   871               #name: 'MenuTerminal'
       
   872               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
   873               #menu: #menu
       
   874               #textDefault: true
       
   875             )
       
   876            #(#'FileBrowserV2UISpecifications::PanelSpec'
       
   877               #name: 'VerticalPanel'
       
   878               #layout: #(#LayoutFrame 0 0.0 32 0.0 0 1.0 0 1.0)
       
   879               #borderWidth: 1
       
   880               #whichView: #last
       
   881               #orientation: #vertical
       
   882               #visibility: #errorListVisibilityHolder
       
   883               #component: 
       
   884              #(#SpecCollection
       
   885                 #collection: #(
       
   886                  #(#DataSetSpec
       
   887                     #name: 'Table1'
       
   888                     #model: #selectionHolder
       
   889                     #menu: #fileListMenu
       
   890                     #hasHorizontalScrollBar: true
       
   891                     #hasVerticalScrollBar: true
       
   892                     #dataList: #archiveFileList
       
   893                     #useIndex: false
       
   894                     #has3Dsepartors: false
       
   895                     #doubleClickSelector: #dblClick
       
   896                     #columnHolder: #tableColumns
       
   897                     #multipleSelectOk: true
       
   898                     #verticalSpacing: 0
       
   899                     #postBuildCallback: #postBuildFileTable:
       
   900                     #properties: 
       
   901                    #(#PropertyListDictionary
       
   902                       #dragArgument: #archivApplication
       
   903                       #startDragSelector: #doStartDrag:in:
       
   904                       #displayObjectSelector: #getDisplayObjects:
       
   905                       #dropObjectSelector: #getDropObjects:
       
   906                       #dropArgument: #archivApplication
       
   907                       #canDropSelector: #canDrop:argument:
       
   908                       #dropSelector: #doDrop:argument:
       
   909                     )
       
   910                   )
       
   911                  #(#SequenceViewSpec
       
   912                     #name: 'ErrorList'
       
   913                     #initiallyDisabled: true
       
   914                     #hasHorizontalScrollBar: true
       
   915                     #hasVerticalScrollBar: true
       
   916                     #backgroundColor: #(#Color 100.0 100.0 100.0)
       
   917                     #isMultiSelect: true
       
   918                     #useIndex: false
       
   919                     #sequenceList: #errorListHolder
       
   920                   )
       
   921                  )
       
   922                
       
   923               )
       
   924               #handles: #(#Any 0.5 1.0)
       
   925             )
       
   926            )
       
   927          
       
   928         )
       
   929       )
       
   930 ! !
       
   931 
       
   932 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'menu specs'!
       
   933 
       
   934 fileListMenu
       
   935     "This resource specification was automatically generated
       
   936      by the MenuEditor of ST/X."
       
   937 
       
   938     "Do not manually edit this!! If it is corrupted,
       
   939      the MenuEditor may not be able to read the specification."
       
   940 
       
   941     "
       
   942      MenuEditor new openOnClass:NoteBookApplication::ArchiveViewApplication andSelector:#fileListMenu
       
   943      (Menu new fromLiteralArrayEncoding:(NoteBookApplication::ArchiveViewApplication fileListMenu)) startUp
       
   944     "
       
   945 
       
   946     <resource: #menu>
       
   947 
       
   948     ^ 
       
   949      #(#Menu
       
   950         #(
       
   951          #(#MenuItem
       
   952             #label: 'Extract to Directory'
       
   953             #translateLabel: true
       
   954             #value: #extractAll
       
   955             #enabled: #hasSelectionInList
       
   956           )
       
   957          #(#MenuItem
       
   958             #label: 'Delete from Archiv'
       
   959             #translateLabel: true
       
   960             #value: #removeFilesFromArchiv
       
   961             #enabled: #canDelete
       
   962             #shortcutKeyCharacter: #Delete
       
   963           )
       
   964          #(#MenuItem
       
   965             #label: 'View'
       
   966             #translateLabel: true
       
   967             #isVisible: #isEmbeddedApplication
       
   968             #value: #viewFile
       
   969             #enabled: #hasOneSelectionInList
       
   970           )
       
   971          #(#MenuItem
       
   972             #label: 'Copy Filenames'
       
   973             #translateLabel: true
       
   974             #value: #copyFilesToClipboard
       
   975             #enabled: #hasSelectionInList
       
   976           )
       
   977          #(#MenuItem
       
   978             #label: 'Select All'
       
   979             #translateLabel: true
       
   980             #value: #selectAll
       
   981             #enabled: #hasListEntriesHolder
       
   982           )
       
   983          )
       
   984         nil
       
   985         nil
       
   986       )
       
   987 !
       
   988 
       
   989 menu
       
   990     "This resource specification was automatically generated
       
   991      by the MenuEditor of ST/X."
       
   992 
       
   993     "Do not manually edit this!! If it is corrupted,
       
   994      the MenuEditor may not be able to read the specification."
       
   995 
       
   996     "
       
   997      MenuEditor new openOnClass:FileApplicationNoteBook::ArchiveViewApplication andSelector:#menu
       
   998      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook::ArchiveViewApplication menu)) startUp
       
   999     "
       
  1000 
       
  1001     <resource: #menu>
       
  1002 
       
  1003     ^ 
       
  1004      #(#Menu
       
  1005         #(
       
  1006          #(#MenuItem
       
  1007             #label: 'Stop'
       
  1008             #translateLabel: true
       
  1009             #isButton: true
       
  1010             #nameKey: #Stop
       
  1011             #value: #doStopProcess
       
  1012             #enabled: #enableStopButton
       
  1013             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #stop22x22Icon)
       
  1014           )
       
  1015          #(#MenuItem
       
  1016             #label: 'Exctract'
       
  1017             #translateLabel: true
       
  1018             #isButton: true
       
  1019             #value: #extractAll
       
  1020             #enabled: #hasListEntriesHolder
       
  1021             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #extract28x28Icon)
       
  1022           )
       
  1023          #(#MenuItem
       
  1024             #label: 'Remove Output'
       
  1025             #translateLabel: true
       
  1026             #isButton: true
       
  1027             #value: #removeErrorOutput
       
  1028             #enabled: #enableRemoveErrorOutput
       
  1029             #labelImage: #(#ResourceRetriever nil #removeError)
       
  1030           )
       
  1031          #(#MenuItem
       
  1032             #label: 'Close'
       
  1033             #translateLabel: true
       
  1034             #isButton: true
       
  1035             #hideMenuOnActivated: false
       
  1036             #isVisible: #isEmbeddedApplication
       
  1037             #startGroup: #right
       
  1038             #value: #doClose
       
  1039             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  1040           )
       
  1041          )
       
  1042         nil
       
  1043         nil
       
  1044       )
       
  1045 ! !
       
  1046 
       
  1047 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'queries'!
       
  1048 
       
  1049 canOpenItem:aItem
       
  1050 
       
  1051     ^ (aItem hasMimeType and:[(aItem mimeType isArchiv) and:[OperatingSystem isUNIXlike]])
       
  1052 !
       
  1053 
       
  1054 wantNewApplicationAnyway
       
  1055 
       
  1056     ^ false
       
  1057 ! !
       
  1058 
       
  1059 !FileApplicationNoteBook::ArchiveViewApplication class methodsFor:'tableColumns specs'!
       
  1060 
       
  1061 tableColumns
       
  1062     "This resource specification was automatically generated
       
  1063      by the DataSetBuilder of ST/X."
       
  1064 
       
  1065     "Do not manually edit this!! If it is corrupted,
       
  1066      the DataSetBuilder may not be able to read the specification."
       
  1067 
       
  1068     "
       
  1069      DataSetBuilder new openOnClass:NoteBookApplication::ArchiveViewApplication andSelector:#tableColumns
       
  1070     "
       
  1071 
       
  1072     <resource: #tableColumns>
       
  1073 
       
  1074     ^#(
       
  1075       #(#DataSetColumnSpec
       
  1076          #id: 'icon'
       
  1077          #labelButtonType: #Button
       
  1078          #labelActionSelector: #sortList:
       
  1079          #labelActionArgument: 'directory'
       
  1080          #width: 25
       
  1081          #minWidth: 20
       
  1082          #height: 16
       
  1083          #model: #icon
       
  1084          #canSelect: false
       
  1085          #isResizeable: false
       
  1086          #showRowSeparator: false
       
  1087          #showColSeparator: false
       
  1088        )
       
  1089       #(#DataSetColumnSpec
       
  1090          #label: 'File Name'
       
  1091          #id: 'fileName'
       
  1092          #labelAlignment: #left
       
  1093          #labelButtonType: #Button
       
  1094          #labelActionSelector: #sortList:
       
  1095          #labelActionArgument: 'fileName'
       
  1096          #model: #fileName
       
  1097          #canSelect: false
       
  1098          #showRowSeparator: false
       
  1099          #showColSeparator: false
       
  1100        )
       
  1101       #(#DataSetColumnSpec
       
  1102          #label: 'Perm'
       
  1103          #id: 'permissions'
       
  1104          #labelButtonType: #Button
       
  1105          #labelActionSelector: #sortList:
       
  1106          #labelActionArgument: 'permissions'
       
  1107          #usePreferredWidth: true
       
  1108          #width: 75
       
  1109          #model: #permissions
       
  1110          #canSelect: false
       
  1111          #showRowSeparator: false
       
  1112          #showColSeparator: false
       
  1113        )
       
  1114       #(#DataSetColumnSpec
       
  1115          #label: 'Version'
       
  1116          #id: 'version'
       
  1117          #labelButtonType: #Button
       
  1118          #labelActionSelector: #sortList:
       
  1119          #labelActionArgument: 'version'
       
  1120          #columnAlignment: #right
       
  1121          #width: 100
       
  1122          #minWidth: 50
       
  1123          #model: #version
       
  1124          #canSelect: false
       
  1125          #showRowSeparator: false
       
  1126          #showColSeparator: false
       
  1127        )
       
  1128       #(#DataSetColumnSpec
       
  1129          #label: 'Type'
       
  1130          #id: 'type'
       
  1131          #labelButtonType: #Button
       
  1132          #labelActionSelector: #sortList:
       
  1133          #labelActionArgument: 'type'
       
  1134          #columnAlignment: #right
       
  1135          #width: 100
       
  1136          #minWidth: 50
       
  1137          #model: #type
       
  1138          #canSelect: false
       
  1139          #showRowSeparator: false
       
  1140          #showColSeparator: false
       
  1141        )
       
  1142       #(#DataSetColumnSpec
       
  1143          #label: 'Owner/Group'
       
  1144          #id: 'ownerGroup'
       
  1145          #labelButtonType: #Button
       
  1146          #labelActionSelector: #sortList:
       
  1147          #labelActionArgument: 'ownerGroup'
       
  1148          #columnAlignment: #right
       
  1149          #width: 100
       
  1150          #minWidth: 50
       
  1151          #model: #ownerGroup
       
  1152          #canSelect: false
       
  1153          #showRowSeparator: false
       
  1154          #showColSeparator: false
       
  1155        )
       
  1156       #(#DataSetColumnSpec
       
  1157          #label: 'Size'
       
  1158          #id: 'size'
       
  1159          #labelButtonType: #Button
       
  1160          #labelActionSelector: #sortList:
       
  1161          #labelActionArgument: 'sizeAsNumber'
       
  1162          #columnAlignment: #right
       
  1163          #width: 80
       
  1164          #model: #size
       
  1165          #canSelect: false
       
  1166          #showRowSeparator: false
       
  1167          #showColSeparator: false
       
  1168        )
       
  1169       #(#DataSetColumnSpec
       
  1170          #label: 'Date & Time'
       
  1171          #id: 'dateAndTime'
       
  1172          #labelAlignment: #right
       
  1173          #labelButtonType: #Button
       
  1174          #labelActionSelector: #sortList:
       
  1175          #labelActionArgument: 'dateAndTime'
       
  1176          #columnAlignment: #right
       
  1177          #usePreferredWidth: true
       
  1178          #width: 140
       
  1179          #model: #dateAndTime
       
  1180          #canSelect: false
       
  1181          #showRowSeparator: false
       
  1182          #showColSeparator: false
       
  1183        )
       
  1184       #(#DataSetColumnSpec
       
  1185          #label: 'Method'
       
  1186          #id: 'method'
       
  1187          #labelButtonType: #Button
       
  1188          #labelActionSelector: #sortList:
       
  1189          #labelActionArgument: 'method'
       
  1190          #columnAlignment: #center
       
  1191          #usePreferredWidth: true
       
  1192          #width: 140
       
  1193          #model: #method
       
  1194          #canSelect: false
       
  1195          #showRowSeparator: false
       
  1196          #showColSeparator: false
       
  1197        )
       
  1198       #(#DataSetColumnSpec
       
  1199          #label: 'CRC'
       
  1200          #id: 'crc'
       
  1201          #labelButtonType: #Button
       
  1202          #labelActionSelector: #sortList:
       
  1203          #labelActionArgument: 'crc'
       
  1204          #usePreferredWidth: true
       
  1205          #width: 140
       
  1206          #model: #crc
       
  1207          #canSelect: false
       
  1208          #showRowSeparator: false
       
  1209          #showColSeparator: false
       
  1210        )
       
  1211       #(#DataSetColumnSpec
       
  1212          #label: 'Compress Size'
       
  1213          #id: 'compressSize'
       
  1214          #labelButtonType: #Button
       
  1215          #labelActionSelector: #sortList:
       
  1216          #labelActionArgument: 'compressSize'
       
  1217          #usePreferredWidth: true
       
  1218          #width: 140
       
  1219          #model: #compressSize
       
  1220          #canSelect: false
       
  1221          #showRowSeparator: false
       
  1222          #showColSeparator: false
       
  1223        )
       
  1224       #(#DataSetColumnSpec
       
  1225          #label: 'Ratio'
       
  1226          #id: 'ratio'
       
  1227          #labelButtonType: #Button
       
  1228          #labelActionSelector: #sortList:
       
  1229          #labelActionArgument: 'ratio'
       
  1230          #usePreferredWidth: true
       
  1231          #width: 140
       
  1232          #model: #ratio
       
  1233          #canSelect: false
       
  1234          #showRowSeparator: false
       
  1235          #showColSeparator: false
       
  1236        )
       
  1237       )
       
  1238 ! !
       
  1239 
       
  1240 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'accessing'!
       
  1241 
       
  1242 archiver
       
  1243     "return the value of the instance variable 'archiver' (automatically generated)"
       
  1244 
       
  1245     ^ archiver
       
  1246 !
       
  1247 
       
  1248 archiver:something
       
  1249     "set the value of the instance variable 'archiver' (automatically generated)"
       
  1250 
       
  1251     archiver := something.
       
  1252 !
       
  1253 
       
  1254 columnDescriptors
       
  1255     "return the value of the instance variable 'columnDescriptors' (automatically generated)"
       
  1256 
       
  1257     ^ columnDescriptors
       
  1258 !
       
  1259 
       
  1260 columnDescriptors:aListOfColumns
       
  1261     "set the value of the instance variable 'columnDescriptors' (automatically generated)"
       
  1262 
       
  1263     columnDescriptors = aListOfColumns ifTrue:[
       
  1264         ^ self
       
  1265     ].
       
  1266 
       
  1267     columnDescriptors    := OrderedCollection new.
       
  1268 
       
  1269     aListOfColumns keysAndValuesDo:[:anIndex :aDesc| |col|
       
  1270         col := aDesc isSequenceable ifTrue:[DataSetColumnSpec new fromLiteralArrayEncoding:aDesc]
       
  1271                                    ifFalse:[aDesc].
       
  1272         columnDescriptors add:col.
       
  1273     ].
       
  1274 !
       
  1275 
       
  1276 item:aItem
       
  1277     "set the value of the instance variable 'item' (automatically generated)"
       
  1278 
       
  1279     | classSelector|
       
  1280     
       
  1281     super item:aItem.
       
  1282     classSelector := self class classSelectorFor:aItem.
       
  1283     (classSelector notNil and:[(Archiver respondsTo:classSelector) notNil]) ifTrue:[
       
  1284         self makeProcessFor:[
       
  1285             self archiver:((Archiver perform:classSelector) with:(self fileName)).
       
  1286             self setColumnsForArchiver.
       
  1287         ] with:'setup archiv'.
       
  1288         ^ true
       
  1289     ]. 
       
  1290     ^ false
       
  1291 !
       
  1292 
       
  1293 temporaryDirectory
       
  1294     "return the value of the instance variable 'temporaryDirectory' (automatically generated)"
       
  1295 
       
  1296     temporaryDirectory isNil ifTrue:[
       
  1297         temporaryDirectory := Filename newTemporary.
       
  1298         temporaryDirectory makeDirectory.
       
  1299     ].
       
  1300     ^ temporaryDirectory
       
  1301 ! !
       
  1302 
       
  1303 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'actions'!
       
  1304 
       
  1305 changeItem:aItem
       
  1306 
       
  1307     self item:aItem.
       
  1308     self emptyList.
       
  1309     self listAllFilesFromArchiv.
       
  1310     ^ true
       
  1311 !
       
  1312 
       
  1313 copyFilesToClipboard
       
  1314 
       
  1315 
       
  1316     |sel list stream|
       
  1317 
       
  1318     sel := self selectionHolder value.
       
  1319     list := self archiveFileList.
       
  1320     (sel notNil and:[sel notEmpty]) ifTrue:[
       
  1321         stream := WriteStream on:''.
       
  1322         sel do:[: key |
       
  1323             stream nextPutAll:(key fileName asString).
       
  1324             stream cr.
       
  1325         ].
       
  1326         self window setTextSelection:stream contents.
       
  1327         stream close.
       
  1328     ].
       
  1329 !
       
  1330 
       
  1331 dblClick
       
  1332 
       
  1333     self viewFile.
       
  1334 !
       
  1335 
       
  1336 doStopProcess
       
  1337 
       
  1338     | archiver |
       
  1339     self stopProcess.
       
  1340     archiver := self archiver.
       
  1341     archiver notNil ifTrue:[
       
  1342         self archiver stopProcess.
       
  1343     ].
       
  1344     self enableStopButton value:false.
       
  1345 !
       
  1346 
       
  1347 emptyList
       
  1348 
       
  1349     self archiveFileList value removeAll.
       
  1350 !
       
  1351 
       
  1352 removeErrorOutput
       
  1353 
       
  1354     self viewErrorList value:false.
       
  1355     self errorListHolder removeAll.
       
  1356 !
       
  1357 
       
  1358 removeTemporaryDirectory
       
  1359 
       
  1360     | tmp |
       
  1361 
       
  1362     temporaryDirectory notNil ifTrue:[
       
  1363         tmp := self temporaryDirectory.
       
  1364         (FileDirectory directoryNamed:(tmp directory)) removeDirectory:tmp baseName.
       
  1365         temporaryDirectory := nil.
       
  1366     ].
       
  1367 !
       
  1368 
       
  1369 selectAll
       
  1370 
       
  1371     | sel listOfFiles|
       
  1372 
       
  1373     sel := OrderedCollection new.
       
  1374     listOfFiles := self archiveFileList value.
       
  1375     1 to:(listOfFiles size) do:[ : el |
       
  1376         sel add:el
       
  1377     ].
       
  1378     self selectionHolder value:sel.
       
  1379 !
       
  1380 
       
  1381 updateFileBrowserIfPresentWith:aDirectory
       
  1382 
       
  1383     | master|
       
  1384 
       
  1385     master := self masterApplication.
       
  1386     master notNil ifTrue:[
       
  1387         master updateAndSelect:(OrderedCollection with:aDirectory).
       
  1388     ].
       
  1389 !
       
  1390 
       
  1391 viewFile
       
  1392 
       
  1393     | master item file tempDir|
       
  1394 
       
  1395     master := self masterApplication.
       
  1396     self selectionHolder value size = 1 ifFalse:[
       
  1397         Dialog warn:'only one file have to be selected'.
       
  1398         ^ self.
       
  1399     ].
       
  1400     tempDir := self temporaryDirectory.
       
  1401     self extractSelectedFilesTo:tempDir askForExtractOptions:false.
       
  1402     process notNil ifTrue:[
       
  1403         process waitUntilTerminated.
       
  1404     ].
       
  1405     file := tempDir construct:self selectionHolder value first fileName.
       
  1406     file exists ifTrue:[
       
  1407         item := DirectoryContentsBrowser itemClass with:file.
       
  1408     ].
       
  1409     master notNil ifTrue:[
       
  1410         master openApplByFileItem:item.
       
  1411     ].
       
  1412 ! !
       
  1413 
       
  1414 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'aspects'!
       
  1415 
       
  1416 archiveFileList
       
  1417 
       
  1418     archiveFileList isNil ifTrue:[
       
  1419         archiveFileList := List new.
       
  1420         archiveFileList addDependent:self.
       
  1421     ].
       
  1422     ^ archiveFileList.
       
  1423 !
       
  1424 
       
  1425 enableRemoveErrorOutput
       
  1426     "return/create the 'enableRemoveErrorOutput' value holder (automatically generated)"
       
  1427 
       
  1428     enableRemoveErrorOutput isNil ifTrue:[
       
  1429         enableRemoveErrorOutput := false asValue.
       
  1430     ].
       
  1431     ^ enableRemoveErrorOutput
       
  1432 !
       
  1433 
       
  1434 enableStopButton
       
  1435 
       
  1436     enableStopButton isNil ifTrue:[
       
  1437         enableStopButton := false asValue.
       
  1438     ].
       
  1439     ^ enableStopButton
       
  1440 !
       
  1441 
       
  1442 errorListHolder
       
  1443 
       
  1444     errorListHolder isNil ifTrue:[
       
  1445         errorListHolder := List new.
       
  1446     ].
       
  1447     ^ errorListHolder.
       
  1448 !
       
  1449 
       
  1450 errorListVisibilityHolder
       
  1451 
       
  1452     errorListVisibilityHolder isNil ifTrue:[
       
  1453         errorListVisibilityHolder := false asValue.
       
  1454     ].
       
  1455     ^ errorListVisibilityHolder
       
  1456 !
       
  1457 
       
  1458 hasListEntriesHolder
       
  1459     "return/create the 'hasListEntriesHolder' value holder (automatically generated)"
       
  1460 
       
  1461     hasListEntriesHolder isNil ifTrue:[
       
  1462         hasListEntriesHolder := false asValue.
       
  1463     ].
       
  1464     ^ hasListEntriesHolder
       
  1465 !
       
  1466 
       
  1467 hasOneSelectionInList
       
  1468 
       
  1469     | sel |
       
  1470     sel := self selectionHolder value.
       
  1471     ^ (sel notNil and:[sel notEmpty and:[sel size = 1]])
       
  1472 !
       
  1473 
       
  1474 hasSelectionInList
       
  1475 
       
  1476     | sel |
       
  1477     sel := self selectionHolder value.
       
  1478     ^ (sel notNil and:[sel notEmpty])
       
  1479 !
       
  1480 
       
  1481 selectionHolder
       
  1482 
       
  1483     selectionHolder isNil ifTrue:[
       
  1484         selectionHolder := ValueHolder new.
       
  1485         selectionHolder addDependent:self.
       
  1486     ].
       
  1487     ^ selectionHolder.
       
  1488 !
       
  1489 
       
  1490 tableColumns
       
  1491 
       
  1492     tableColumns isNil ifTrue:[
       
  1493         tableColumns := self class tableColumns asValue.
       
  1494     ].
       
  1495     ^ tableColumns.
       
  1496 !
       
  1497 
       
  1498 viewErrorList
       
  1499     "return/create the 'viewErrorList' value holder (automatically generated)"
       
  1500 
       
  1501     viewErrorList isNil ifTrue:[
       
  1502         viewErrorList := false asValue.
       
  1503         viewErrorList onChangeSend:#viewErrorListChanged to:self.
       
  1504     ].
       
  1505     ^ viewErrorList
       
  1506 ! !
       
  1507 
       
  1508 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'change & update'!
       
  1509 
       
  1510 update:something with:aParameter from:changedObject
       
  1511     "Invoked when an object that I depend upon sends a change notification."
       
  1512 
       
  1513     "stub code automatically generated - please change as required"
       
  1514 
       
  1515     changedObject == self archiveFileList ifTrue:[
       
  1516         self hasListEntriesHolder value:(changedObject notEmpty).
       
  1517         ^ self
       
  1518     ].
       
  1519     super update:something with:aParameter from:changedObject
       
  1520 !
       
  1521 
       
  1522 viewErrorListChanged
       
  1523 
       
  1524     | viewListValue|
       
  1525 
       
  1526     viewListValue := self viewErrorList value.
       
  1527     self enableRemoveErrorOutput value:viewListValue.
       
  1528     self errorListVisibilityHolder value:viewListValue.
       
  1529 ! !
       
  1530 
       
  1531 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'command execution'!
       
  1532 
       
  1533 getErrorBlock
       
  1534 
       
  1535     ^
       
  1536     [: x |
       
  1537         self viewErrorList value:true.
       
  1538         self errorListHolder value add:x.
       
  1539     ]
       
  1540 !
       
  1541 
       
  1542 getErrorStream
       
  1543 
       
  1544     |errStream|
       
  1545 
       
  1546     errStream := ActorStream new.
       
  1547     errStream nextPutLineBlock:(self getErrorBlock).
       
  1548     ^ errStream
       
  1549 !
       
  1550 
       
  1551 getOutBlock
       
  1552 
       
  1553     |firstLineNotReaded key|
       
  1554 
       
  1555     firstLineNotReaded := true.
       
  1556     ^ [: line |
       
  1557         | words ownerGroup item archiverColumns itemWriter index itemWordCount|
       
  1558 
       
  1559         (firstLineNotReaded and:[archiver class hasTitleLine]) ifTrue:[
       
  1560             firstLineNotReaded := false.
       
  1561         ]ifFalse:[
       
  1562             words := line asCollectionOfWords.
       
  1563             archiverColumns := archiver class columns.
       
  1564             item := ArchivItem new.
       
  1565             index := 1.
       
  1566             archiverColumns do:[:colDescr |
       
  1567                 | itemStream |
       
  1568                 itemWordCount := colDescr second.
       
  1569                 itemWriter := ((colDescr first) asString, ':') asSymbol.
       
  1570                 itemStream := WriteStream on:''.
       
  1571                 index to:(index + itemWordCount - 1) do:[:i|
       
  1572                     itemStream nextPutAll:(words at:i).
       
  1573                     itemStream space.
       
  1574                 ].
       
  1575                 item perform:itemWriter with:(itemStream contents).
       
  1576                 itemStream close.
       
  1577                 index := index + itemWordCount.
       
  1578             ].
       
  1579             ((archiverColumns collect:[:el| el first]) includes:#permissions) ifTrue:[
       
  1580                 (item permissions startsWith:$d) ifTrue:[
       
  1581                     key := #directory.
       
  1582                     item isDirectory:true.
       
  1583                 ] ifFalse:[
       
  1584                     key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName).
       
  1585                     item isDirectory:false.
       
  1586                 ].
       
  1587             ] ifFalse:[
       
  1588                 key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName).
       
  1589             ].
       
  1590             item icon:(FileBrowser iconForKeyMatching:key).
       
  1591             self archiveFileList value add:item
       
  1592         ].
       
  1593     ]
       
  1594 !
       
  1595 
       
  1596 getOutStream
       
  1597 
       
  1598     |outStream|
       
  1599 
       
  1600     outStream := ActorStream new.
       
  1601     outStream nextPutLineBlock:(self getOutBlock).
       
  1602     ^ outStream
       
  1603 !
       
  1604 
       
  1605 makeProcessFor:aBlock
       
  1606 
       
  1607     self makeProcessFor:aBlock with:''
       
  1608 !
       
  1609 
       
  1610 makeProcessFor:aBlock with:string
       
  1611 
       
  1612     | locBlock |
       
  1613 
       
  1614     process notNil ifTrue:[
       
  1615         process waitUntilTerminated.
       
  1616         terminateByMe ifTrue:[
       
  1617             terminateByMe := false.
       
  1618             ^ self
       
  1619         ].
       
  1620     ].
       
  1621     locBlock := [   [        
       
  1622                     self notifyChannel value:string.
       
  1623                     aBlock value.
       
  1624                     self notifyChannel value:''.
       
  1625                     ] valueNowOrOnUnwindDo:[ 
       
  1626                         process := nil.
       
  1627                         self enableStopButton value:false.
       
  1628                     ] 
       
  1629                 ].
       
  1630     process := locBlock newProcess.
       
  1631     process priority:(Processor systemBackgroundPriority).
       
  1632     process name:'ArchiveApplicationProcess'.
       
  1633     self enableStopButton value:true.
       
  1634     process resume.
       
  1635 !
       
  1636 
       
  1637 setColumnsForArchiver
       
  1638 
       
  1639     | newColumns archiverColumns allColumns iconColumn|
       
  1640 
       
  1641     archiverColumns := archiver class columns collect:[:el| el  first].
       
  1642     allColumns := OrderedCollection new.
       
  1643     newColumns := OrderedCollection new.
       
  1644     self class tableColumns do:[:el|
       
  1645         allColumns add:(DataSetColumnSpec new fromLiteralArrayEncoding:el).
       
  1646     ].
       
  1647     iconColumn := allColumns detect:[: col | (col id asSymbol) = #icon] ifNone:[nil].
       
  1648     iconColumn notNil ifTrue:[
       
  1649         newColumns add:iconColumn.
       
  1650     ].
       
  1651     allColumns do:[:col|
       
  1652         (archiverColumns includes:(col id asSymbol)) ifTrue:[
       
  1653             newColumns add:col.
       
  1654         ].
       
  1655     ].
       
  1656     self tableColumns value:newColumns.
       
  1657     self columnDescriptors:(self tableColumns value).
       
  1658 !
       
  1659 
       
  1660 stopProcess
       
  1661 
       
  1662     |task|
       
  1663 
       
  1664     terminateByMe := true.
       
  1665     (task := process) notNil ifTrue:[
       
  1666         process := nil.
       
  1667 
       
  1668         Object errorSignal handle:[:ex|
       
  1669             Dialog warn:ex description.
       
  1670         ]do:[
       
  1671             task isDead ifFalse:[
       
  1672                 task terminateWithAllSubprocesses.
       
  1673                 task waitUntilTerminated.
       
  1674             ]
       
  1675         ]
       
  1676     ].
       
  1677 ! !
       
  1678 
       
  1679 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'command helper'!
       
  1680 
       
  1681 selectDirectoryDialog
       
  1682 
       
  1683     | dir directory haveDirectory|
       
  1684 
       
  1685     directory := self fileName directory.
       
  1686     haveDirectory := false.
       
  1687     [haveDirectory] whileFalse:[
       
  1688         dir := Dialog requestDirectoryName:'Which directory ?' default:dir.
       
  1689         dir isEmpty ifTrue:[ ^ self].
       
  1690         dir := dir asFilename.
       
  1691         (dir isExecutable not or:[dir isWritable not]) ifTrue:[
       
  1692             Dialog warn:'cant write to: ', dir asString.
       
  1693         ].
       
  1694         haveDirectory := true.
       
  1695     ].
       
  1696     ^ dir
       
  1697 ! !
       
  1698 
       
  1699 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'commands add'!
       
  1700 
       
  1701 addFilesToArchiv:colOfFiles
       
  1702 
       
  1703 
       
  1704     self archiver outStream:nil errorStream:(self getErrorStream) synchron:true.
       
  1705     self makeProcessFor:[
       
  1706         self archiver addFilesToArchiv:colOfFiles.
       
  1707     ] with:'add Files to archiv'.
       
  1708     (self archiver class == Archiver zipArchive) ifTrue:[
       
  1709         self listAllFilesFromArchiv.
       
  1710     ] ifFalse:[
       
  1711         self listFilesFromArchiv:colOfFiles.
       
  1712     ].
       
  1713     ^ true.
       
  1714 ! !
       
  1715 
       
  1716 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'commands extract'!
       
  1717 
       
  1718 extractAll
       
  1719 
       
  1720     self extractSelectedFilesTo:nil withSelection:#all
       
  1721 !
       
  1722 
       
  1723 extractSelectedFilesTo:aDirectory askForExtractOptions:askForExtractOptionsBoolean
       
  1724 
       
  1725     self extractSelectedFilesTo:aDirectory withSelection:#selection askForExtractOptions:askForExtractOptionsBoolean
       
  1726 !
       
  1727 
       
  1728 extractSelectedFilesTo:aDirectory withSelection:selectOrAll
       
  1729 
       
  1730     self extractSelectedFilesTo:aDirectory withSelection:selectOrAll askForExtractOptions:true.
       
  1731 !
       
  1732 
       
  1733 extractSelectedFilesTo:aDirectory withSelection:selectOrAll askForExtractOptions:askForExtractOptionsBoolean
       
  1734 
       
  1735     | dir|
       
  1736 
       
  1737     aDirectory isNil ifTrue:[
       
  1738         dir := self selectDirectoryDialog.
       
  1739         dir isNil ifTrue:[^ self].
       
  1740     ] ifFalse:[
       
  1741         dir := aDirectory.
       
  1742     ].
       
  1743     selectOrAll == #all ifTrue:[
       
  1744        self extractAllTo:dir.
       
  1745     ].
       
  1746     selectOrAll == #selection ifTrue:[
       
  1747         self extractSelectionTo:dir askForExtractOptions:askForExtractOptionsBoolean
       
  1748     ].
       
  1749     self updateFileBrowserIfPresentWith:dir.
       
  1750 ! !
       
  1751 
       
  1752 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'commands extract private'!
       
  1753 
       
  1754 extractAllTo:aDirectory 
       
  1755 
       
  1756     self archiver outStream:nil errorStream:(self getErrorStream) synchron:true.
       
  1757     self makeProcessFor:[
       
  1758         self archiver extractTo:aDirectory.
       
  1759     ] with:'extract all files'.
       
  1760     ^ true.
       
  1761 !
       
  1762 
       
  1763 extractSelectionTo:aDirectory askForExtractOptions:askForExtractOptionsBoolean
       
  1764 
       
  1765     |  sel index extractWithDirectoryPart extractAllFilesInSelectedDirectories extractFiles|
       
  1766 
       
  1767     extractWithDirectoryPart := true.
       
  1768     extractAllFilesInSelectedDirectories := false.
       
  1769     sel := self selectionHolder value.
       
  1770     (sel isNil or:[sel isEmpty]) ifTrue:[
       
  1771         sel := self archiveFileList value.
       
  1772     ].
       
  1773     sel := sel do:[:item|
       
  1774         item fileName: item fileName
       
  1775     ].
       
  1776     (askForExtractOptionsBoolean and:[self archiver class ~= Archiver zipArchive]) ifTrue:[
       
  1777         extractFiles := self selRemoveFilesForDirs:sel.
       
  1778     ] ifFalse:[
       
  1779         extractFiles := sel.
       
  1780     ].
       
  1781     
       
  1782     askForExtractOptionsBoolean ifTrue:[
       
  1783         index := extractFiles findFirst:[: el | el hasDirectoryPart].
       
  1784         index ~= 0 ifTrue:[
       
  1785             extractWithDirectoryPart := (Dialog confirmWithCancel:'Extract with directory part?' default:true).
       
  1786             extractWithDirectoryPart isNil ifTrue:[^ false].
       
  1787         ].
       
  1788     ].
       
  1789     extractWithDirectoryPart ifTrue:[
       
  1790         self extractWithDirectoryPartTo:aDirectory with:extractFiles.
       
  1791     ] ifFalse:[
       
  1792         self extractWithOutDirectoryPartTo:aDirectory with:extractFiles.
       
  1793     ].
       
  1794     ^ true
       
  1795 !
       
  1796 
       
  1797 extractWithDirectoryPartTo:aDirectory with:extractFiles
       
  1798 
       
  1799     self archiver outStream:nil errorStream:(self getErrorStream) synchron:true.
       
  1800     self makeProcessFor:[
       
  1801         self archiver extractTo:aDirectory with:extractFiles.
       
  1802     ] with:('extract Files to ', aDirectory asString).
       
  1803     ^ true.
       
  1804 !
       
  1805 
       
  1806 extractWithOutDirectoryPartTo:aDirectory with:extractFiles
       
  1807 
       
  1808     self archiver outStream:nil errorStream:(self getErrorStream) synchron:true.
       
  1809     self makeProcessFor:[
       
  1810         self archiver extractWithOutDirectoryTo:aDirectory 
       
  1811                       with:(extractFiles collect:[:item| item fileName]).
       
  1812     ] with:('extract Files to ', aDirectory asString).
       
  1813     ^ true.
       
  1814 ! !
       
  1815 
       
  1816 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'commands list'!
       
  1817 
       
  1818 listAllFilesFromArchiv
       
  1819 
       
  1820     self archiveFileList value removeAll.
       
  1821     self listFilesFromArchiv:nil
       
  1822 !
       
  1823 
       
  1824 listFilesFromArchiv:newColOfFiles
       
  1825 
       
  1826     process notNil ifTrue:[
       
  1827         process waitUntilTerminated.
       
  1828     ].
       
  1829     self archiver outStream:(self getOutStream) errorStream:(self getErrorStream) synchron:true.
       
  1830     self makeProcessFor:[
       
  1831         self archiver listFilesFromArchiv:newColOfFiles.
       
  1832     ] with:'list Files'.
       
  1833 ! !
       
  1834 
       
  1835 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'commands remove'!
       
  1836 
       
  1837 removeFilesFromArchiv
       
  1838 
       
  1839     | sel realSel list firtsPre stringCol stringRealSel|
       
  1840 
       
  1841     sel := self selectionHolder value.
       
  1842     stringCol := sel collect:[: item| item fileName].
       
  1843     firtsPre := stringCol at:1.
       
  1844     stringCol from:2 do:[:el|
       
  1845          firtsPre :=  firtsPre commonPrefixWith:el.
       
  1846     ].
       
  1847     list := self archiveFileList value.
       
  1848     realSel := OrderedCollection new.
       
  1849     list do:[:item|
       
  1850         ((item fileName) startsWith:firtsPre) ifTrue:[
       
  1851             realSel add:item.
       
  1852         ].
       
  1853     ].
       
  1854     stringRealSel := realSel collect:[: item| item fileName].
       
  1855 
       
  1856     self archiver outStream:nil errorStream:(self getErrorStream) synchron:true.
       
  1857     self makeProcessFor:[
       
  1858         self archiver removeFilesFromArchiv:stringCol.
       
  1859     ] with:'remove files'.
       
  1860 
       
  1861     self archiveFileList value removeAll:realSel
       
  1862 ! !
       
  1863 
       
  1864 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'drag & drop'!
       
  1865 
       
  1866 canDrop:aContext argument:arg2 
       
  1867 
       
  1868 
       
  1869     |arg |
       
  1870     archiver class canAddFiles ifFalse:[^ false].
       
  1871     arg := aContext dropSource argument.
       
  1872     (arg == #browser or:[arg == #directoryTreeBrowser]) ifTrue:[
       
  1873         ^ true
       
  1874     ].
       
  1875     ^ false.
       
  1876 !
       
  1877 
       
  1878 doDrop:aContext
       
  1879 
       
  1880     |col source arg objects|
       
  1881 
       
  1882     source := aContext dropSource.
       
  1883     arg := source argument.
       
  1884     objects := aContext dropObjects.
       
  1885     col := OrderedCollection new.
       
  1886     objects do:[:obj|
       
  1887         col add:(obj theObject).
       
  1888     ].
       
  1889     ^ self addFilesToArchiv:col.
       
  1890 !
       
  1891 
       
  1892 doDrop:aContext argument:arg2 
       
  1893 
       
  1894     | aBoolean |
       
  1895 
       
  1896     aBoolean := self doDrop:aContext.
       
  1897     ^ aBoolean.
       
  1898 !
       
  1899 
       
  1900 doStartDrag:aDropSource in:aView
       
  1901     "set the cursors before starting the drag & drop operation
       
  1902     "
       
  1903     |hdl sel|
       
  1904 
       
  1905     archiver class canRemoveFiles ifFalse:[^ self].
       
  1906     sel := self selectionHolder value.
       
  1907 
       
  1908     hdl := DragAndDropManager new.
       
  1909 
       
  1910     hdl disabledCursor:self class DisabledCursorImage.
       
  1911     hdl enabledCursor:self class EnabledCursorImage.
       
  1912     hdl alienCursor:nil.
       
  1913 
       
  1914     hdl startDragFrom:aView dropSource:aDropSource offset:#topLeft
       
  1915 !
       
  1916 
       
  1917 getDisplayObjects:anArgument
       
  1918 
       
  1919     | sel string size fnName stream|
       
  1920     sel := self selectionHolder value.
       
  1921     size := sel size.
       
  1922     size == 0  ifTrue:[^ ''].
       
  1923     stream := WriteStream on:''.
       
  1924     stream nextPutAll:(sel first fileName asFilename baseName asString).
       
  1925     size == 1 ifTrue:[
       
  1926         fnName := 'ui_menuitem.xpm'.
       
  1927     ] ifFalse:[
       
  1928         fnName := 'ui_submenu_open.xpm'.
       
  1929         stream nextPutAll:' ... '.
       
  1930         stream nextPutAll:(sel last fileName asFilename baseName asString).
       
  1931     ].
       
  1932     string := stream contents.
       
  1933     stream close.
       
  1934     ^ Array with:(LabelAndIcon icon:(Image fromFile:fnName)
       
  1935                              string:(Text string:string emphasis:#bold)
       
  1936                  )
       
  1937 !
       
  1938 
       
  1939 getDropObjects:anArgument
       
  1940 
       
  1941     | sel ret|
       
  1942     sel := self selectionHolder value.
       
  1943     ret := sel collect:[:el| 
       
  1944         DropObject new:(el fileName)
       
  1945     ].
       
  1946     ^ ret
       
  1947 ! !
       
  1948 
       
  1949 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'event handling'!
       
  1950 
       
  1951 processEvent:anEvent
       
  1952     "filter keyboard events.
       
  1953      Return true, if I have eaten the event"
       
  1954 
       
  1955     |focusView key rawKey|
       
  1956 
       
  1957     anEvent isKeyPressEvent ifTrue:[
       
  1958         focusView := anEvent targetView.
       
  1959         key := anEvent key.
       
  1960         rawKey := anEvent rawKey.
       
  1961 
       
  1962         (focusView isSameOrComponentOf:self window) ifTrue:[
       
  1963 "/            (key ~= #'Alt_L') ifTrue:[self halt.].
       
  1964             (key == #Delete) ifTrue:[
       
  1965                 self removeFilesFromArchiv.
       
  1966                 ^ true
       
  1967             ].
       
  1968         ]
       
  1969     ].
       
  1970     ^ false
       
  1971 ! !
       
  1972 
       
  1973 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'initialization & release'!
       
  1974 
       
  1975 postBuildFileTable:aWidget
       
  1976 
       
  1977     fileTable := aWidget scrolledView.
       
  1978     fileTable wantsFocusWithPointerEnter.
       
  1979 "/    FileBrowser icons keysAndValuesDo:[:aKey :anIcon|
       
  1980 "/        fileTable registerImage:anIcon key:aKey.
       
  1981 "/    ].
       
  1982     self columnDescriptors:(self class tableColumns).
       
  1983 !
       
  1984 
       
  1985 postOpenWith:aBuilder
       
  1986 
       
  1987     | currentDir contents suffix fileName file archivItem|
       
  1988 
       
  1989     self windowGroup addPreEventHook:self.
       
  1990     self masterApplication isNil ifTrue:[
       
  1991         self masterApplication:nil.
       
  1992         currentDir := Filename homeDirectory.
       
  1993         contents := currentDir directoryContents.
       
  1994         fileName := contents detect:[: file |
       
  1995             suffix := file asFilename suffix asLowercase.
       
  1996             suffix = 'tgz'
       
  1997         ] ifNone:[nil].
       
  1998         fileName isNil ifTrue:[ 
       
  1999             Dialog warn:'cant find a Zip file in ', currentDir asString.
       
  2000             ^ self
       
  2001         ].
       
  2002         file := currentDir construct:fileName.
       
  2003         archivItem := DirectoryContentsBrowser itemClass with:file.
       
  2004         (self item:archivItem) ifFalse:[
       
  2005             Dialog warn:'file type of ', item fileName asString, ' not supported'.
       
  2006             ^ self.
       
  2007         ].
       
  2008     ].
       
  2009     self listAllFilesFromArchiv.
       
  2010     ^ super postOpenWith:aBuilder.
       
  2011 !
       
  2012 
       
  2013 release
       
  2014 
       
  2015     self archiver release.
       
  2016     ^ super release.
       
  2017 ! !
       
  2018 
       
  2019 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'queries'!
       
  2020 
       
  2021 archivType
       
  2022 
       
  2023     | file firstsuffix secondsuffix|
       
  2024 
       
  2025     file := self fileName.
       
  2026     firstsuffix := file withoutSuffix suffix.
       
  2027     secondsuffix := file suffix.
       
  2028     (secondsuffix = 'tgz' or:[firstsuffix = 'tar' and:[secondsuffix = 'gz']]) ifTrue:[
       
  2029         ^ #tarFileCompressed
       
  2030     ].
       
  2031     (secondsuffix = 'tar') ifTrue:[
       
  2032         ^ #tarFile
       
  2033     ].
       
  2034     (secondsuffix = 'gz') ifTrue:[
       
  2035         ^ #gzipFile
       
  2036     ].
       
  2037     (secondsuffix = 'zip') ifTrue:[
       
  2038         ^ #zipFile
       
  2039     ].
       
  2040 !
       
  2041 
       
  2042 canDelete
       
  2043 
       
  2044     ^ (self hasOneSelectionInList and:[archiver class canRemoveFiles])
       
  2045 !
       
  2046 
       
  2047 selRemoveFilesForDirs:aSel
       
  2048 
       
  2049     |stringCol newSel string|
       
  2050 
       
  2051     stringCol := (aSel collect:[: item| item fileName]).
       
  2052     newSel := aSel copy.
       
  2053     aSel do:[:item |
       
  2054         item isDirectory ifTrue:[
       
  2055             string := item fileName.
       
  2056             stringCol doWithIndex:[:filename : index|
       
  2057                 (filename ~= string and:[filename startsWith:string]) ifTrue:[
       
  2058                     newSel remove:(aSel at:index) ifAbsent:[nil].
       
  2059                 ]
       
  2060             ]
       
  2061         ].
       
  2062     ].
       
  2063     ^ newSel.
       
  2064 ! !
       
  2065 
       
  2066 !FileApplicationNoteBook::ArchiveViewApplication methodsFor:'sorting'!
       
  2067 
       
  2068 generateSortBlock:instanceName
       
  2069 
       
  2070     | aSymbol cmpOp sortCaselessLocal|
       
  2071 
       
  2072     aSymbol := instanceName asSymbol.
       
  2073     sortCaselessLocal := self sortCaseless value.
       
  2074     currentSortOrder isNil ifTrue:[
       
  2075         currentSortOrder := aSymbol.
       
  2076         currentSortOrder := Dictionary new.
       
  2077         currentSortOrder at:#column put:aSymbol.
       
  2078         currentSortOrder at:#reverse put:false.
       
  2079         currentSortOrder at:#sortCaseless put:sortCaselessLocal.
       
  2080     ] ifFalse:[
       
  2081         (currentSortOrder at:#column) = aSymbol ifTrue:[
       
  2082             "/ same column like before - change sort order
       
  2083             | isReverse |
       
  2084             isReverse := currentSortOrder at:#reverse.
       
  2085             currentSortOrder at:#reverse put:(isReverse not).
       
  2086         ] ifFalse:[
       
  2087             "/ another column - remark column
       
  2088             currentSortOrder at:#column put:aSymbol.
       
  2089         ]
       
  2090     ].
       
  2091     (currentSortOrder at:#reverse) ifTrue:[
       
  2092         cmpOp := #'>'
       
  2093     ] ifFalse:[
       
  2094         cmpOp := #'<'
       
  2095     ].
       
  2096     ^ [:a :b | 
       
  2097             |entry1 entry2|
       
  2098 
       
  2099             entry1 := (a perform:aSymbol).
       
  2100             entry2 := (b perform:aSymbol).
       
  2101             aSymbol = #fileName ifTrue:[
       
  2102                 sortCaselessLocal ifTrue:[
       
  2103                     entry1 := entry1 asString asLowercase.
       
  2104                     entry2 := entry2 asString asLowercase.
       
  2105                 ] ifFalse:[
       
  2106                     entry1 := entry1 asString.
       
  2107                     entry2 := entry2 asString.
       
  2108                 ].
       
  2109             ].
       
  2110             entry1 perform:cmpOp with:entry2
       
  2111     ].
       
  2112 !
       
  2113 
       
  2114 sortList:instanceName 
       
  2115 
       
  2116 
       
  2117     |sortBlock fileList sortCol|
       
  2118 
       
  2119     sortBlock := self generateSortBlock:instanceName.
       
  2120     fileList := self archiveFileList value.
       
  2121     sortCol := SortedCollection sortBlock:sortBlock.
       
  2122     sortCol addAll:fileList.
       
  2123     fileList removeAll.
       
  2124     fileList addAll:sortCol.
       
  2125 ! !
       
  2126 
       
  2127 !FileApplicationNoteBook::ArchiveViewApplication::ArchivItem methodsFor:'accessing'!
       
  2128 
       
  2129 compressSize
       
  2130     "return the value of the instance variable 'compressSize' (automatically generated)"
       
  2131 
       
  2132     ^ compressSize
       
  2133 !
       
  2134 
       
  2135 compressSize:something
       
  2136     "set the value of the instance variable 'compressSize' (automatically generated)"
       
  2137 
       
  2138     compressSize := something.
       
  2139 !
       
  2140 
       
  2141 crc
       
  2142     "return the value of the instance variable 'crc' (automatically generated)"
       
  2143 
       
  2144     ^ crc
       
  2145 !
       
  2146 
       
  2147 crc:something
       
  2148     "set the value of the instance variable 'crc' (automatically generated)"
       
  2149 
       
  2150     crc := something.
       
  2151 !
       
  2152 
       
  2153 dateAndTime
       
  2154     "return the value of the instance variable 'dateAndTime' (automatically generated)"
       
  2155 
       
  2156     ^ dateAndTime
       
  2157 !
       
  2158 
       
  2159 dateAndTime:something
       
  2160     "set the value of the instance variable 'dateAndTime' (automatically generated)"
       
  2161 
       
  2162     dateAndTime := something.
       
  2163 !
       
  2164 
       
  2165 fileName
       
  2166     "return the value of the instance variable 'fileName' (automatically generated)"
       
  2167 
       
  2168     ^ fileName
       
  2169 !
       
  2170 
       
  2171 fileName:something
       
  2172     "set the value of the instance variable 'fileName' (automatically generated)"
       
  2173 
       
  2174     fileName := something withoutSpaces.
       
  2175 !
       
  2176 
       
  2177 icon
       
  2178     "return the value of the instance variable 'icon' (automatically generated)"
       
  2179 
       
  2180     ^ icon
       
  2181 !
       
  2182 
       
  2183 icon:something
       
  2184     "set the value of the instance variable 'icon' (automatically generated)"
       
  2185 
       
  2186     icon := something.
       
  2187 !
       
  2188 
       
  2189 isDirectory
       
  2190     "return the value of the instance variable 'directory' (automatically generated)"
       
  2191 
       
  2192     ^ isDirectory
       
  2193 !
       
  2194 
       
  2195 isDirectory:something
       
  2196     "set the value of the instance variable 'isDirectory' (automatically generated)"
       
  2197 
       
  2198     isDirectory := something.
       
  2199 !
       
  2200 
       
  2201 method
       
  2202     "return the value of the instance variable 'method' (automatically generated)"
       
  2203 
       
  2204     ^ method
       
  2205 !
       
  2206 
       
  2207 method:something
       
  2208     "set the value of the instance variable 'method' (automatically generated)"
       
  2209 
       
  2210     method := something.
       
  2211 !
       
  2212 
       
  2213 ownerGroup
       
  2214     "return the value of the instance variable 'owner' (automatically generated)"
       
  2215 
       
  2216     ^ ownerGroup
       
  2217 !
       
  2218 
       
  2219 ownerGroup:something
       
  2220     "set the value of the instance variable 'owner' (automatically generated)"
       
  2221 
       
  2222     ownerGroup := something.
       
  2223 !
       
  2224 
       
  2225 permissions
       
  2226     "return the value of the instance variable 'permissions' (automatically generated)"
       
  2227 
       
  2228     ^ permissions
       
  2229 !
       
  2230 
       
  2231 permissions:something
       
  2232     "set the value of the instance variable 'permissions' (automatically generated)"
       
  2233 
       
  2234     permissions := something.
       
  2235 !
       
  2236 
       
  2237 ratio
       
  2238     "return the value of the instance variable 'ratio' (automatically generated)"
       
  2239 
       
  2240     ^ ratio
       
  2241 !
       
  2242 
       
  2243 ratio:something
       
  2244     "set the value of the instance variable 'ratio' (automatically generated)"
       
  2245 
       
  2246     ratio := something.
       
  2247 !
       
  2248 
       
  2249 size
       
  2250     "return the value of the instance variable 'size' (automatically generated)"
       
  2251 
       
  2252     ^ size
       
  2253 !
       
  2254 
       
  2255 size:something
       
  2256     "set the value of the instance variable 'size' (automatically generated)"
       
  2257 
       
  2258     size := something.
       
  2259 !
       
  2260 
       
  2261 sizeAsNumber
       
  2262     "return the value of the instance variable 'size' (automatically generated)"
       
  2263 
       
  2264     ^ size asInteger
       
  2265 !
       
  2266 
       
  2267 type
       
  2268     "return the value of the instance variable 'type' (automatically generated)"
       
  2269 
       
  2270     ^ type
       
  2271 !
       
  2272 
       
  2273 type:something
       
  2274     "set the value of the instance variable 'type' (automatically generated)"
       
  2275 
       
  2276     type := something.
       
  2277 !
       
  2278 
       
  2279 version
       
  2280     "return the value of the instance variable 'version' (automatically generated)"
       
  2281 
       
  2282     ^ version
       
  2283 !
       
  2284 
       
  2285 version:something
       
  2286     "set the value of the instance variable 'version' (automatically generated)"
       
  2287 
       
  2288     version := something.
       
  2289 ! !
       
  2290 
       
  2291 !FileApplicationNoteBook::ArchiveViewApplication::ArchivItem methodsFor:'printing'!
       
  2292 
       
  2293 printString
       
  2294 
       
  2295     ^ self fileName asString
       
  2296 ! !
       
  2297 
       
  2298 !FileApplicationNoteBook::ArchiveViewApplication::ArchivItem methodsFor:'queries'!
       
  2299 
       
  2300 hasDirectoryPart
       
  2301 
       
  2302     ^ self fileName asFilename components size ~= 1
       
  2303 ! !
       
  2304 
       
  2305 !FileApplicationNoteBook::CommandResult class methodsFor:'defaults'!
       
  2306 
       
  2307 tabStringFor:aApplicationType
       
  2308 
       
  2309     ^ 'Execution result'
       
  2310 !
       
  2311 
       
  2312 wantNewApplicationAnyway
       
  2313 
       
  2314     ^ false
       
  2315 ! !
       
  2316 
       
  2317 !FileApplicationNoteBook::CommandResult class methodsFor:'interface specs'!
       
  2318 
       
  2319 windowSpec
       
  2320     "This resource specification was automatically generated
       
  2321      by the UIPainter of ST/X."
       
  2322 
       
  2323     "Do not manually edit this!! If it is corrupted,
       
  2324      the UIPainter may not be able to read the specification."
       
  2325 
       
  2326     "
       
  2327      UIPainter new openOnClass:NoteBookApplication::CommandResult andSelector:#windowSpec
       
  2328      NoteBookApplication::CommandResult new openInterface:#windowSpec
       
  2329      NoteBookApplication::CommandResult open
       
  2330     "
       
  2331 
       
  2332     <resource: #canvas>
       
  2333 
       
  2334     ^ 
       
  2335      #(#FullSpec
       
  2336         #name: #windowSpec
       
  2337         #window: 
       
  2338        #(#WindowSpec
       
  2339           #label: 'NoteBookApplication::CommandResult'
       
  2340           #name: 'NoteBookApplication::CommandResult'
       
  2341           #min: #(#Point 10 10)
       
  2342           #max: #(#Point 1024 768)
       
  2343           #bounds: #(#Rectangle 16 42 519 395)
       
  2344           #menu: #mainMenu
       
  2345         )
       
  2346         #component: 
       
  2347        #(#SpecCollection
       
  2348           #collection: #(
       
  2349            #(#MenuPanelSpec
       
  2350               #name: 'ToolBar1'
       
  2351               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
  2352               #menu: #menu
       
  2353               #textDefault: true
       
  2354             )
       
  2355            #(#ArbitraryComponentSpec
       
  2356               #name: 'ArbitraryComponent1'
       
  2357               #layout: #(#LayoutFrame 0 0.0 32 0 0 1.0 0 1)
       
  2358               #hasHorizontalScrollBar: true
       
  2359               #hasVerticalScrollBar: true
       
  2360               #hasBorder: false
       
  2361               #component: #TextCollector
       
  2362               #postBuildCallback: #postBuildTextCollector:
       
  2363             )
       
  2364            #(#LabelSpec
       
  2365               #label: 'FileLabel'
       
  2366               #name: 'FileLabel'
       
  2367               #layout: #(#LayoutFrame 87 0 2 0 -36 1 30 0)
       
  2368               #level: -1
       
  2369               #translateLabel: true
       
  2370               #labelChannel: #labelHolder
       
  2371               #adjust: #left
       
  2372             )
       
  2373            )
       
  2374          
       
  2375         )
       
  2376       )
       
  2377 ! !
       
  2378 
       
  2379 !FileApplicationNoteBook::CommandResult class methodsFor:'menu specs'!
       
  2380 
       
  2381 menu
       
  2382     "This resource specification was automatically generated
       
  2383      by the MenuEditor of ST/X."
       
  2384 
       
  2385     "Do not manually edit this!! If it is corrupted,
       
  2386      the MenuEditor may not be able to read the specification."
       
  2387 
       
  2388     "
       
  2389      MenuEditor new openOnClass:FileApplicationNoteBook::CommandResult andSelector:#menu
       
  2390      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook::CommandResult menu)) startUp
       
  2391     "
       
  2392 
       
  2393     <resource: #menu>
       
  2394 
       
  2395     ^ 
       
  2396      #(#Menu
       
  2397         #(
       
  2398          #(#MenuItem
       
  2399             #label: 'Stop'
       
  2400             #translateLabel: true
       
  2401             #isButton: true
       
  2402             #nameKey: #Stop
       
  2403             #value: #doStopProcess
       
  2404             #enabled: #enableStopButton
       
  2405             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #stop22x22Icon 'Stop')
       
  2406           )
       
  2407          #(#MenuItem
       
  2408             #label: 'Close'
       
  2409             #translateLabel: true
       
  2410             #isButton: true
       
  2411             #nameKey: #Close
       
  2412             #isVisible: #isEmbeddedApplication
       
  2413             #startGroup: #right
       
  2414             #value: #doClose
       
  2415             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  2416           )
       
  2417          )
       
  2418         nil
       
  2419         nil
       
  2420       )
       
  2421 ! !
       
  2422 
       
  2423 !FileApplicationNoteBook::CommandResult methodsFor:'accessing'!
       
  2424 
       
  2425 resultStream
       
  2426     "return the value of the instance variable 'resultStream' (automatically generated)"
       
  2427 
       
  2428     ^ resultStream
       
  2429 !
       
  2430 
       
  2431 resultStream:something
       
  2432     "set the value of the instance variable 'resultStream' (automatically generated)"
       
  2433 
       
  2434     resultStream := something.
       
  2435 ! !
       
  2436 
       
  2437 !FileApplicationNoteBook::CommandResult methodsFor:'actions'!
       
  2438 
       
  2439 changeTabTo:aString 
       
  2440 
       
  2441     | masterApplication |
       
  2442 
       
  2443     self labelHolder value:aString.
       
  2444     masterApplication := self masterApplication.
       
  2445     masterApplication isNil ifFalse:[
       
  2446         masterApplication tabStringChangeTo:aString for:self.
       
  2447     ].
       
  2448 !
       
  2449 
       
  2450 doStopProcess
       
  2451 
       
  2452     | myProcess |
       
  2453 
       
  2454     myProcess := self process value.
       
  2455     myProcess notNil ifTrue:[
       
  2456         self notifyChannel value:('kill ', myProcess name).
       
  2457         myProcess terminate.    
       
  2458         self backgroundProcesses remove:myProcess ifAbsent:[].
       
  2459     ].
       
  2460 ! !
       
  2461 
       
  2462 !FileApplicationNoteBook::CommandResult methodsFor:'aspects'!
       
  2463 
       
  2464 enableStopButton
       
  2465 
       
  2466     enableStopButton isNil ifTrue:[
       
  2467         enableStopButton := false asValue.
       
  2468     ].
       
  2469     ^ enableStopButton
       
  2470 !
       
  2471 
       
  2472 labelHolder
       
  2473 
       
  2474     labelHolder isNil ifTrue:[
       
  2475         labelHolder := '' asValue.
       
  2476     ].
       
  2477     ^ labelHolder.
       
  2478 !
       
  2479 
       
  2480 process
       
  2481     "return/create the 'process' value holder (automatically generated)"
       
  2482 
       
  2483     process isNil ifTrue:[
       
  2484         process := ValueHolder new.
       
  2485         process addDependent:self.
       
  2486     ].
       
  2487     ^ process
       
  2488 ! !
       
  2489 
       
  2490 !FileApplicationNoteBook::CommandResult methodsFor:'change & update'!
       
  2491 
       
  2492 update:something with:aParameter from:changedObject
       
  2493     "Invoked when an object that I depend upon sends a change notification."
       
  2494 
       
  2495     "stub code automatically generated - please change as required"
       
  2496 
       
  2497     changedObject == self process ifTrue:[
       
  2498         self enableStopButton value:changedObject value notNil.
       
  2499         ^ self
       
  2500     ].
       
  2501     super update:something with:aParameter from:changedObject
       
  2502 ! !
       
  2503 
       
  2504 !FileApplicationNoteBook::CommandResult methodsFor:'initialization & release'!
       
  2505 
       
  2506 postBuildTextCollector:aBuilder
       
  2507 
       
  2508     self resultStream:aBuilder scrolledView.
       
  2509 !
       
  2510 
       
  2511 postBuildWith:aBuilder
       
  2512     "This is a hook method generated by the Browser.
       
  2513      It will be invoked during the initialization of your app/dialog,
       
  2514      after all of the visual components have been built, 
       
  2515      but BEFORE the top window is made visible.
       
  2516      Add any app-specific actions here (reading files, setting up values etc.)
       
  2517      See also #postOpenWith:, which is invoked after opening."
       
  2518 
       
  2519     "/ add any code here ...
       
  2520 
       
  2521     ^ super postBuildWith:aBuilder
       
  2522 !
       
  2523 
       
  2524 postOpenWith:aBuilder
       
  2525     "This is a hook method generated by the Browser.
       
  2526      It will be invoked right after the applications window has been opened.
       
  2527      Add any app-specific actions here (starting background processes etc.).
       
  2528      See also #postBuildWith:, which is invoked before opening."
       
  2529 
       
  2530     "/ add any code here ...
       
  2531 
       
  2532     self masterApplication isNil ifTrue:[
       
  2533         self masterApplication:nil.
       
  2534     ].
       
  2535     ^ super postOpenWith:aBuilder
       
  2536 !
       
  2537 
       
  2538 release
       
  2539 
       
  2540     self doStopProcess.
       
  2541     ^ super release
       
  2542 ! !
       
  2543 
       
  2544 !FileApplicationNoteBook::CommandResult methodsFor:'printing'!
       
  2545 
       
  2546 printString
       
  2547 
       
  2548     ^ 'CommandResult Application'
       
  2549 ! !
       
  2550 
       
  2551 !FileApplicationNoteBook::HtmlViewApplication class methodsFor:'defaults'!
       
  2552 
       
  2553 tabStringFor:aApplicationType
       
  2554 
       
  2555     ^ 'HTML View for:'
       
  2556 ! !
       
  2557 
       
  2558 !FileApplicationNoteBook::HtmlViewApplication class methodsFor:'interface specs'!
       
  2559 
       
  2560 windowSpec
       
  2561     "This resource specification was automatically generated
       
  2562      by the UIPainter of ST/X."
       
  2563 
       
  2564     "Do not manually edit this!! If it is corrupted,
       
  2565      the UIPainter may not be able to read the specification."
       
  2566 
       
  2567     "
       
  2568      UIPainter new openOnClass:NoteBookApplication::HtmlViewApplication andSelector:#windowSpec
       
  2569      NoteBookApplication::HtmlViewApplication new openInterface:#windowSpec
       
  2570      NoteBookApplication::HtmlViewApplication open
       
  2571     "
       
  2572 
       
  2573     <resource: #canvas>
       
  2574 
       
  2575     ^ 
       
  2576      #(#FullSpec
       
  2577         #name: #windowSpec
       
  2578         #window: 
       
  2579        #(#WindowSpec
       
  2580           #label: 'NoteBookApplication::HtmlView'
       
  2581           #name: 'NoteBookApplication::HtmlView'
       
  2582           #min: #(#Point 10 10)
       
  2583           #max: #(#Point 1024 768)
       
  2584           #bounds: #(#Rectangle 16 42 692 534)
       
  2585           #menu: #mainMenu
       
  2586         )
       
  2587         #component: 
       
  2588        #(#SpecCollection
       
  2589           #collection: #(
       
  2590            #(#MenuPanelSpec
       
  2591               #name: 'MenuHtml'
       
  2592               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
  2593               #visibilityChannel: #isEmbeddedApplication
       
  2594               #menu: #menu
       
  2595               #textDefault: true
       
  2596             )
       
  2597            #(#ArbitraryComponentSpec
       
  2598               #name: 'HTMLView'
       
  2599               #layout: #(#LayoutFrame 0 0.0 32 0.0 0 1.0 0 1)
       
  2600               #hasHorizontalScrollBar: true
       
  2601               #hasVerticalScrollBar: true
       
  2602               #miniScrollerHorizontal: false
       
  2603               #miniScrollerVertical: false
       
  2604               #hasBorder: false
       
  2605               #component: #HTMLDocumentView
       
  2606               #postBuildCallback: #postBuildHtmlView:
       
  2607             )
       
  2608            #(#LabelSpec
       
  2609               #label: 'FileLabel'
       
  2610               #name: 'FileLabel'
       
  2611               #layout: #(#LayoutFrame 212 0 2 0 -73 1 30 0)
       
  2612               #level: -1
       
  2613               #translateLabel: true
       
  2614               #labelChannel: #labelHolder
       
  2615               #adjust: #left
       
  2616             )
       
  2617            )
       
  2618          
       
  2619         )
       
  2620       )
       
  2621 ! !
       
  2622 
       
  2623 !FileApplicationNoteBook::HtmlViewApplication class methodsFor:'menu specs'!
       
  2624 
       
  2625 menu
       
  2626     "This resource specification was automatically generated
       
  2627      by the MenuEditor of ST/X."
       
  2628 
       
  2629     "Do not manually edit this!! If it is corrupted,
       
  2630      the MenuEditor may not be able to read the specification."
       
  2631 
       
  2632     "
       
  2633      MenuEditor new openOnClass:FileApplicationNoteBook::HtmlViewApplication andSelector:#menu
       
  2634      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook::HtmlViewApplication menu)) startUp
       
  2635     "
       
  2636 
       
  2637     <resource: #menu>
       
  2638 
       
  2639     ^ 
       
  2640      #(#Menu
       
  2641         #(
       
  2642          #(#MenuItem
       
  2643             #label: 'Reload'
       
  2644             #translateLabel: true
       
  2645             #isButton: true
       
  2646             #value: #doReload
       
  2647             #labelImage: #(#ResourceRetriever nil #htmlReloadIcon)
       
  2648           )
       
  2649          #(#MenuItem
       
  2650             #label: 'Back'
       
  2651             #translateLabel: true
       
  2652             #isButton: true
       
  2653             #value: #doGoBack
       
  2654             #labelImage: #(#ResourceRetriever #Icon #leftIcon)
       
  2655           )
       
  2656          #(#MenuItem
       
  2657             #label: 'Print'
       
  2658             #translateLabel: true
       
  2659             #isButton: true
       
  2660             #value: #doPrint
       
  2661             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #printer22x22Icon)
       
  2662           )
       
  2663          #(#MenuItem
       
  2664             #label: 'Close'
       
  2665             #translateLabel: true
       
  2666             #isButton: true
       
  2667             #hideMenuOnActivated: false
       
  2668             #startGroup: #right
       
  2669             #value: #doClose
       
  2670             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  2671           )
       
  2672          )
       
  2673         nil
       
  2674         nil
       
  2675       )
       
  2676 ! !
       
  2677 
       
  2678 !FileApplicationNoteBook::HtmlViewApplication class methodsFor:'queries'!
       
  2679 
       
  2680 canOpenItem:aItem
       
  2681 
       
  2682     ^ (aItem hasMimeType and:[aItem mimeType isHtml])
       
  2683 !
       
  2684 
       
  2685 wantNewApplicationAnyway
       
  2686 
       
  2687     ^ false
       
  2688 ! !
       
  2689 
       
  2690 !FileApplicationNoteBook::HtmlViewApplication methodsFor:'accessing'!
       
  2691 
       
  2692 htmlView
       
  2693     "return the value of the instance variable 'imageView' (automatically generated)"
       
  2694 
       
  2695     ^ htmlView
       
  2696 !
       
  2697 
       
  2698 htmlView:something
       
  2699     "set the value of the instance variable 'imageView' (automatically generated)"
       
  2700 
       
  2701     htmlView := something.
       
  2702 !
       
  2703 
       
  2704 item:aItem 
       
  2705 
       
  2706     |retVal|
       
  2707 
       
  2708     self labelHolder value:aItem fileName asString.
       
  2709     retVal := super item:aItem.
       
  2710     self setupHtmlView.
       
  2711     ^ retVal
       
  2712 ! !
       
  2713 
       
  2714 !FileApplicationNoteBook::HtmlViewApplication methodsFor:'actions'!
       
  2715 
       
  2716 doGoBack
       
  2717 
       
  2718     self htmlView menu_back.
       
  2719 !
       
  2720 
       
  2721 doGoHome
       
  2722 
       
  2723     self htmlView menu_home.
       
  2724 !
       
  2725 
       
  2726 doHelp
       
  2727 
       
  2728     self htmlView menu_help.
       
  2729 !
       
  2730 
       
  2731 doPrint
       
  2732 
       
  2733     self htmlView menu_print.
       
  2734 !
       
  2735 
       
  2736 doReload
       
  2737 
       
  2738     self htmlView menu_reload.
       
  2739 !
       
  2740 
       
  2741 setupHtmlView
       
  2742 
       
  2743     | html file directory|
       
  2744 
       
  2745     html := self htmlView.
       
  2746     html isNil ifTrue:[^ self].
       
  2747     file := self fileName.
       
  2748     directory := file directoryName.
       
  2749     html homeDocument:(file asString).
       
  2750     html setTopDirectoryName:directory.
       
  2751     html uriHolder:self labelHolder.
       
  2752     html infoHolder:self notifyChannel.
       
  2753     html linkButtonPanel:nil.
       
  2754     ^ html
       
  2755 ! !
       
  2756 
       
  2757 !FileApplicationNoteBook::HtmlViewApplication methodsFor:'aspects'!
       
  2758 
       
  2759 labelHolder
       
  2760 
       
  2761     labelHolder isNil ifTrue:[
       
  2762         labelHolder := '' asValue.
       
  2763     ].
       
  2764     ^ labelHolder.
       
  2765 ! !
       
  2766 
       
  2767 !FileApplicationNoteBook::HtmlViewApplication methodsFor:'initialization & release'!
       
  2768 
       
  2769 postBuildHtmlView:aWidget
       
  2770 
       
  2771     self htmlView: aWidget scrolledView.
       
  2772     self htmlView wantsFocusWithPointerEnter.
       
  2773 !
       
  2774 
       
  2775 postOpenWith:aBuilder 
       
  2776     "
       
  2777     only invoked if the application not started from a master
       
  2778     "
       
  2779 
       
  2780     |currentDir contents suffix fileName|
       
  2781 
       
  2782     self masterApplication isNil ifTrue:[
       
  2783         self masterApplication:nil.
       
  2784         currentDir := Filename homeDirectory.
       
  2785 
       
  2786         contents := currentDir directoryContents.
       
  2787         fileName := contents 
       
  2788                     detect:[:file | 
       
  2789                         suffix := file asFilename suffix asLowercase.
       
  2790                         suffix = 'html'
       
  2791                     ]
       
  2792                     ifNone:[nil].
       
  2793         fileName isNil ifTrue:[
       
  2794             Dialog warn:'cant find a HTML file in ' , currentDir asString.
       
  2795             ^ self
       
  2796         ].
       
  2797         self item:(DirectoryContentsBrowser itemClass with:('../../doc/online/english/TOP.html' asFilename)).
       
  2798     ].
       
  2799     self setupHtmlView.
       
  2800     ^ super postOpenWith:aBuilder
       
  2801 ! !
       
  2802 
       
  2803 !FileApplicationNoteBook::ImageViewApplication class methodsFor:'defaults'!
       
  2804 
       
  2805 tabStringFor:aApplicationType
       
  2806 
       
  2807     ^ 'Image for:'
       
  2808 ! !
       
  2809 
       
  2810 !FileApplicationNoteBook::ImageViewApplication class methodsFor:'image specs'!
       
  2811 
       
  2812 fitSize20x20Icon
       
  2813     "This resource specification was automatically generated
       
  2814      by the ImageEditor of ST/X."
       
  2815 
       
  2816     "Do not manually edit this!! If it is corrupted,
       
  2817      the ImageEditor may not be able to read the specification."
       
  2818 
       
  2819     "
       
  2820      self fitSize20x20Icon inspect
       
  2821      ImageEditor openOnClass:self andSelector:#fitSize20x20Icon
       
  2822     "
       
  2823 
       
  2824     <resource: #image>
       
  2825 
       
  2826     ^Icon
       
  2827         constantNamed:#'FileApplicationNoteBook::ImageViewApplication class fitSize20x20Icon'
       
  2828         ifAbsentPut:[(Depth4Image new) width: 20; height: 20; photometric:(#palette); bitsPerSample:(#(4 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
       
  2829 @@DQDQDQDQDP@@@PDQDQDQDQ@P@A@ADQDQDQDP@PD@@PDQDQDPD@@QDQ@ADQDQ@@DQDQD@@@@@@@@@DQDQDPQDQDQ@DQDQDQDDQUUTPADQDQDQAEUUUT@QDQ
       
  2830 DQDPQEUUQ@DQDQDQDDQFQDPADQDQDQADQ$QD@QDQDQDPL3X3Q@DQDQDQDCL3L3LADQDQD@@@@@@@@@DQDQD@DQDQDP@QDQ@@DADQDQDA@@DA@ADQDQDQDP@P
       
  2831 @@@QDQDQDQDA@@@ADQDQDQDQD@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
  2832 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
  2833 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@a') ; colorMapFromArray:#[0 0 0 255 255 255 0 0 0 0 137 0 174 218 230 0 206 0 133 60 36]; mask:((Depth1Image new) width: 20; height: 20; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'
       
  2834 8@A00@@0(@APE@J@C@L@G?>@A?8@A?8@A?8@A?8@A?8@A?8@A?8@A?8@G?>@C@L@E@J@(@AP0@@08@A0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
  2835 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
  2836 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
  2837 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       
  2838 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@a') ; yourself); yourself]
       
  2839 ! !
       
  2840 
       
  2841 !FileApplicationNoteBook::ImageViewApplication class methodsFor:'interface specs'!
       
  2842 
       
  2843 windowSpec
       
  2844     "This resource specification was automatically generated
       
  2845      by the UIPainter of ST/X."
       
  2846 
       
  2847     "Do not manually edit this!! If it is corrupted,
       
  2848      the UIPainter may not be able to read the specification."
       
  2849 
       
  2850     "
       
  2851      UIPainter new openOnClass:FileApplicationNoteBook::ImageViewApplication andSelector:#windowSpec
       
  2852      FileApplicationNoteBook::ImageViewApplication new openInterface:#windowSpec
       
  2853      FileApplicationNoteBook::ImageViewApplication open
       
  2854     "
       
  2855 
       
  2856     <resource: #canvas>
       
  2857 
       
  2858     ^ 
       
  2859      #(#FullSpec
       
  2860         #name: #windowSpec
       
  2861         #window: 
       
  2862        #(#WindowSpec
       
  2863           #label: 'ImageViewer'
       
  2864           #name: 'ImageViewer'
       
  2865           #min: #(#Point 10 10)
       
  2866           #max: #(#Point 1024 768)
       
  2867           #bounds: #(#Rectangle 16 42 692 534)
       
  2868           #menu: #mainMenu
       
  2869         )
       
  2870         #component: 
       
  2871        #(#SpecCollection
       
  2872           #collection: #(
       
  2873            #(#MenuPanelSpec
       
  2874               #name: 'MenuTerminal'
       
  2875               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
  2876               #visibilityChannel: #isEmbeddedApplication
       
  2877               #menu: #menu
       
  2878               #textDefault: true
       
  2879             )
       
  2880            #(#ArbitraryComponentSpec
       
  2881               #name: 'TerminalView'
       
  2882               #layout: #(#LayoutFrame 0 0.0 32 0.0 0 1.0 0 1.0)
       
  2883               #hasHorizontalScrollBar: true
       
  2884               #hasVerticalScrollBar: true
       
  2885               #miniScrollerHorizontal: false
       
  2886               #miniScrollerVertical: false
       
  2887               #hasBorder: false
       
  2888               #component: #ImageView
       
  2889               #postBuildCallback: #postBuildImageView:
       
  2890             )
       
  2891            )
       
  2892          
       
  2893         )
       
  2894       )
       
  2895 ! !
       
  2896 
       
  2897 !FileApplicationNoteBook::ImageViewApplication class methodsFor:'menu specs'!
       
  2898 
       
  2899 menu
       
  2900     "This resource specification was automatically generated
       
  2901      by the MenuEditor of ST/X."
       
  2902 
       
  2903     "Do not manually edit this!! If it is corrupted,
       
  2904      the MenuEditor may not be able to read the specification."
       
  2905 
       
  2906     "
       
  2907      MenuEditor new openOnClass:FileApplicationNoteBook::ImageViewApplication andSelector:#menu
       
  2908      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook::ImageViewApplication menu)) startUp
       
  2909     "
       
  2910 
       
  2911     <resource: #menu>
       
  2912 
       
  2913     ^ 
       
  2914      #(#Menu
       
  2915         #(
       
  2916          #(#MenuItem
       
  2917             #label: 'Edit'
       
  2918             #translateLabel: true
       
  2919             #isButton: true
       
  2920             #nameKey: #EditImage
       
  2921             #value: #editImage
       
  2922           )
       
  2923          #(#MenuItem
       
  2924             #label: '-'
       
  2925           )
       
  2926          #(#MenuItem
       
  2927             #label: 'FitSize'
       
  2928             #translateLabel: true
       
  2929             #isButton: true
       
  2930             #triggerOnDown: true
       
  2931             #labelImage: #(#ResourceRetriever #'FileApplicationNoteBook::ImageViewApplication' #fitSize20x20Icon)
       
  2932             #indication: #fitSize
       
  2933           )
       
  2934          #(#MenuItem
       
  2935             #label: '-'
       
  2936           )
       
  2937          #(#MenuItem
       
  2938             #label: 'Close'
       
  2939             #translateLabel: true
       
  2940             #isButton: true
       
  2941             #hideMenuOnActivated: false
       
  2942             #startGroup: #right
       
  2943             #value: #doClose
       
  2944             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  2945           )
       
  2946          )
       
  2947         nil
       
  2948         nil
       
  2949       )
       
  2950 ! !
       
  2951 
       
  2952 !FileApplicationNoteBook::ImageViewApplication class methodsFor:'queries'!
       
  2953 
       
  2954 canOpenItem:aItem
       
  2955 
       
  2956     ^ (aItem hasMimeType and:[aItem mimeType isImage])
       
  2957 !
       
  2958 
       
  2959 wantNewApplicationAnyway
       
  2960 
       
  2961     ^ false
       
  2962 ! !
       
  2963 
       
  2964 !FileApplicationNoteBook::ImageViewApplication methodsFor:'accessing'!
       
  2965 
       
  2966 image:something
       
  2967     "set the value of the instance variable 'image' (automatically generated)"
       
  2968 
       
  2969     image := something.
       
  2970 !
       
  2971 
       
  2972 imageView
       
  2973     "return the value of the instance variable 'imageView' (automatically generated)"
       
  2974 
       
  2975     ^ imageView
       
  2976 !
       
  2977 
       
  2978 imageView:something
       
  2979     "set the value of the instance variable 'imageView' (automatically generated)"
       
  2980 
       
  2981     imageView := something.
       
  2982 ! !
       
  2983 
       
  2984 !FileApplicationNoteBook::ImageViewApplication methodsFor:'actions'!
       
  2985 
       
  2986 changeItem:aItem
       
  2987 
       
  2988     self item:aItem.
       
  2989     self setupImageView.
       
  2990     ^ true
       
  2991 !
       
  2992 
       
  2993 editImage
       
  2994     |img|
       
  2995 
       
  2996     img := self image.
       
  2997     img notNil ifTrue:[
       
  2998         img edit.
       
  2999     ].
       
  3000 !
       
  3001 
       
  3002 image
       
  3003     |img fn e|
       
  3004 
       
  3005     fn := self fileName.
       
  3006     img := Image fromFile:fn.
       
  3007     img isNil ifTrue:[
       
  3008         fn exists ifTrue:[
       
  3009             e := 'Unknown/unsupported image format'
       
  3010         ] ifFalse:[
       
  3011             e := 'No such image'
       
  3012         ].
       
  3013         Dialog warn:e.
       
  3014         ^ nil
       
  3015     ].
       
  3016     ^ img.
       
  3017 !
       
  3018 
       
  3019 setupImageView
       
  3020     |img|
       
  3021 
       
  3022     self window topView withWaitCursorDo:[
       
  3023         img := self image.
       
  3024         img notNil ifTrue:[
       
  3025             self image:img.
       
  3026             imageView image:img
       
  3027         ]
       
  3028     ]
       
  3029 ! !
       
  3030 
       
  3031 !FileApplicationNoteBook::ImageViewApplication methodsFor:'aspects'!
       
  3032 
       
  3033 fitSize
       
  3034     "return/create the 'fitSize' value holder (automatically generated)"
       
  3035 
       
  3036     fitSize isNil ifTrue:[
       
  3037         fitSize := ValueHolder new.
       
  3038         fitSize addDependent:self.
       
  3039     ].
       
  3040     ^ fitSize
       
  3041 ! !
       
  3042 
       
  3043 !FileApplicationNoteBook::ImageViewApplication methodsFor:'change & update'!
       
  3044 
       
  3045 update:something with:aParameter from:changedObject
       
  3046     changedObject == self fitSize ifTrue:[
       
  3047         changedObject value ifTrue:[
       
  3048             imageView adjust:#fitBig.
       
  3049         ] ifFalse:[
       
  3050             imageView adjust:nil.
       
  3051         ].
       
  3052         ^ self
       
  3053     ].
       
  3054     super update:something with:aParameter from:changedObject
       
  3055 ! !
       
  3056 
       
  3057 !FileApplicationNoteBook::ImageViewApplication methodsFor:'initialization & release'!
       
  3058 
       
  3059 postBuildImageView:aWidget
       
  3060 
       
  3061     self imageView: aWidget scrolledView.
       
  3062     self imageView wantsFocusWithPointerEnter.
       
  3063 !
       
  3064 
       
  3065 postOpenWith:aBuilder 
       
  3066     "
       
  3067     only invoked if the application not started from a master
       
  3068     "
       
  3069 
       
  3070     |currentDir contents suffix fileName|
       
  3071 
       
  3072     self masterApplication isNil ifTrue:[
       
  3073         self masterApplication:nil.
       
  3074         currentDir := Filename currentDirectory.
       
  3075         contents := currentDir directoryContents.
       
  3076         fileName := contents 
       
  3077                     detect:[:file | 
       
  3078                         suffix := file asFilename suffix asLowercase.
       
  3079                         Image isImageFileSuffix:suffix
       
  3080                     ]
       
  3081                     ifNone:[nil].
       
  3082         fileName isNil ifTrue:[
       
  3083             Dialog warn:'cant find a Image in ' , currentDir asString.
       
  3084             ^ self
       
  3085         ].
       
  3086         self item:(DirectoryContentsBrowser itemClass with:(currentDir construct:fileName))
       
  3087     ].
       
  3088     self setupImageView.
       
  3089     ^ super postOpenWith:aBuilder
       
  3090 ! !
       
  3091 
       
  3092 !FileApplicationNoteBook::Terminal class methodsFor:'defaults'!
       
  3093 
       
  3094 tabStringFor:aApplicationType
       
  3095 
       
  3096     ^ 'Terminal in:'
       
  3097 ! !
       
  3098 
       
  3099 !FileApplicationNoteBook::Terminal class methodsFor:'interface specs'!
       
  3100 
       
  3101 windowSpec
       
  3102     "This resource specification was automatically generated
       
  3103      by the UIPainter of ST/X."
       
  3104 
       
  3105     "Do not manually edit this!! If it is corrupted,
       
  3106      the UIPainter may not be able to read the specification."
       
  3107 
       
  3108     "
       
  3109      UIPainter new openOnClass:NoteBookApplication::Terminal andSelector:#windowSpec
       
  3110      NoteBookApplication::Terminal new openInterface:#windowSpec
       
  3111      NoteBookApplication::Terminal open
       
  3112     "
       
  3113 
       
  3114     <resource: #canvas>
       
  3115 
       
  3116     ^ 
       
  3117      #(#FullSpec
       
  3118         #name: #windowSpec
       
  3119         #window: 
       
  3120        #(#WindowSpec
       
  3121           #label: 'NoteBookApplication::Terminal'
       
  3122           #name: 'NoteBookApplication::Terminal'
       
  3123           #min: #(#Point 10 10)
       
  3124           #max: #(#Point 1024 768)
       
  3125           #bounds: #(#Rectangle 16 42 692 534)
       
  3126           #menu: #mainMenu
       
  3127         )
       
  3128         #component: 
       
  3129        #(#SpecCollection
       
  3130           #collection: #(
       
  3131            #(#MenuPanelSpec
       
  3132               #name: 'MenuTerminal'
       
  3133               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
  3134               #menu: #menu
       
  3135               #textDefault: true
       
  3136             )
       
  3137            #(#ArbitraryComponentSpec
       
  3138               #name: 'TerminalView'
       
  3139               #layout: #(#LayoutFrame 0 0.0 32 0.0 0 1.0 0 1.0)
       
  3140               #hasHorizontalScrollBar: true
       
  3141               #hasVerticalScrollBar: true
       
  3142               #miniScrollerHorizontal: false
       
  3143               #miniScrollerVertical: false
       
  3144               #hasBorder: false
       
  3145               #component: #terminalView
       
  3146             )
       
  3147            )
       
  3148          
       
  3149         )
       
  3150       )
       
  3151 ! !
       
  3152 
       
  3153 !FileApplicationNoteBook::Terminal class methodsFor:'menu specs'!
       
  3154 
       
  3155 menu
       
  3156     "This resource specification was automatically generated
       
  3157      by the MenuEditor of ST/X."
       
  3158 
       
  3159     "Do not manually edit this!! If it is corrupted,
       
  3160      the MenuEditor may not be able to read the specification."
       
  3161 
       
  3162     "
       
  3163      MenuEditor new openOnClass:FileApplicationNoteBook::Terminal andSelector:#menu
       
  3164      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook::Terminal menu)) startUp
       
  3165     "
       
  3166 
       
  3167     <resource: #menu>
       
  3168 
       
  3169     ^ 
       
  3170      #(#Menu
       
  3171         #(
       
  3172          #(#MenuItem
       
  3173             #label: 'Save'
       
  3174             #translateLabel: true
       
  3175             #isButton: true
       
  3176             #nameKey: #Save
       
  3177             #value: #saveAs
       
  3178             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #saveToFile28x22Icon)
       
  3179           )
       
  3180          #(#MenuItem
       
  3181             #label: 'Close'
       
  3182             #translateLabel: true
       
  3183             #isButton: true
       
  3184             #hideMenuOnActivated: false
       
  3185             #isVisible: #isEmbeddedApplication
       
  3186             #startGroup: #right
       
  3187             #value: #doClose
       
  3188             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  3189           )
       
  3190          )
       
  3191         nil
       
  3192         nil
       
  3193       )
       
  3194 ! !
       
  3195 
       
  3196 !FileApplicationNoteBook::Terminal methodsFor:'accessing'!
       
  3197 
       
  3198 terminalView
       
  3199 
       
  3200     terminalView isNil ifTrue:[
       
  3201         terminalView := VT100TerminalView new.
       
  3202     ].
       
  3203     ^ terminalView.
       
  3204 ! !
       
  3205 
       
  3206 !FileApplicationNoteBook::Terminal methodsFor:'actions'!
       
  3207 
       
  3208 saveAs
       
  3209 
       
  3210     self terminalView save.
       
  3211 ! !
       
  3212 
       
  3213 !FileApplicationNoteBook::Terminal methodsFor:'initialization & release'!
       
  3214 
       
  3215 postBuildWith:aBuilder
       
  3216 
       
  3217     ^ super postBuildWith:aBuilder
       
  3218 !
       
  3219 
       
  3220 shellFinished
       
  3221 
       
  3222     | master text string|
       
  3223 
       
  3224     master := self masterApplication.
       
  3225     master notNil ifTrue:[
       
  3226         string := ' - closed'.
       
  3227         master tabStringAdd:string for:self.
       
  3228     ].
       
  3229     self notifyChannel value:'shell in ' , self fileName asString, ' finished'.
       
  3230     terminalView cr.
       
  3231     text := '>> shell closed' asText allBold.
       
  3232     text colorizeAllWith:Color red.
       
  3233     terminalView nextPutAll:text.
       
  3234 !
       
  3235 
       
  3236 startShell
       
  3237     |vt100|
       
  3238 
       
  3239     vt100 := self terminalView.
       
  3240     vt100 shellTerminateAction:[ self shellFinished ].
       
  3241     vt100 startShellIn:(self fileName).
       
  3242 ! !
       
  3243 
       
  3244 !FileApplicationNoteBook::Terminal methodsFor:'printing'!
       
  3245 
       
  3246 printString
       
  3247 
       
  3248     ^ ('Terminal on:', self fileName baseName)
       
  3249 ! !
       
  3250 
       
  3251 !FileApplicationNoteBook::Terminal methodsFor:'queries'!
       
  3252 
       
  3253 getTabStringEnd
       
  3254 
       
  3255 " get the tab string from the application list on the class side "
       
  3256 
       
  3257     ^ '..', OperatingSystem fileSeparator, self fileName baseName, OperatingSystem fileSeparator
       
  3258 ! !
       
  3259 
       
  3260 !FileApplicationNoteBook::Terminal methodsFor:'startup & release'!
       
  3261 
       
  3262 postOpenWith:aBuilder
       
  3263 
       
  3264     "
       
  3265     only invoked if the application not started from a master
       
  3266     "
       
  3267     self masterApplication isNil ifTrue:[
       
  3268         self masterApplication:nil.
       
  3269         self item:(DirectoryContentsBrowser itemClass with:(Filename currentDirectory asAbsoluteFilename)).
       
  3270     ].
       
  3271     self startShell.
       
  3272     ^ super postOpenWith:aBuilder.
       
  3273 ! !
       
  3274 
       
  3275 !FileApplicationNoteBook::TextEditor class methodsFor:'defaults'!
       
  3276 
       
  3277 tabStringFor:aApplicationType
       
  3278 
       
  3279     aApplicationType == #directoryDescription ifTrue:[
       
  3280         ^ 'Directory description for:'
       
  3281     ] ifFalse:[
       
  3282         ^ 'Editor on:'
       
  3283     ].
       
  3284 !
       
  3285 
       
  3286 wantNewApplicationAnyway
       
  3287 
       
  3288     ^ false
       
  3289 ! !
       
  3290 
       
  3291 !FileApplicationNoteBook::TextEditor class methodsFor:'interface - specs'!
       
  3292 
       
  3293 windowSpec
       
  3294     "This resource specification was automatically generated
       
  3295      by the UIPainter of ST/X."
       
  3296 
       
  3297     "Do not manually edit this!! If it is corrupted,
       
  3298      the UIPainter may not be able to read the specification."
       
  3299 
       
  3300     "
       
  3301      UIPainter new openOnClass:NoteBookApplication::TextEditor andSelector:#windowSpec
       
  3302      NoteBookApplication::TextEditor new openInterface:#windowSpec
       
  3303      NoteBookApplication::TextEditor open
       
  3304     "
       
  3305 
       
  3306     <resource: #canvas>
       
  3307 
       
  3308     ^ 
       
  3309      #(#FullSpec
       
  3310         #name: #windowSpec
       
  3311         #window: 
       
  3312        #(#WindowSpec
       
  3313           #label: 'TextEditor'
       
  3314           #name: 'TextEditor'
       
  3315           #min: #(#Point 10 10)
       
  3316           #max: #(#Point 1024 768)
       
  3317           #bounds: #(#Rectangle 12 22 662 322)
       
  3318         )
       
  3319         #component: 
       
  3320        #(#SpecCollection
       
  3321           #collection: #(
       
  3322            #(#MenuPanelSpec
       
  3323               #name: 'MenuTextEditor'
       
  3324               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
  3325               #menu: #menu
       
  3326               #textDefault: true
       
  3327             )
       
  3328            #(#TextEditorSpec
       
  3329               #name: 'TextEditor'
       
  3330               #layout: #(#LayoutFrame 0 0.0 32 0 0 1.0 0 1.0)
       
  3331               #model: #fileContentsModel
       
  3332               #hasHorizontalScrollBar: true
       
  3333               #hasVerticalScrollBar: true
       
  3334               #modifiedChannel: #modifiedChannel
       
  3335               #acceptCallBack: #accept
       
  3336               #postBuildCallback: #postBuildTextEditor:
       
  3337             )
       
  3338            )
       
  3339          
       
  3340         )
       
  3341       )
       
  3342 ! !
       
  3343 
       
  3344 !FileApplicationNoteBook::TextEditor class methodsFor:'menu specs'!
       
  3345 
       
  3346 menu
       
  3347     "This resource specification was automatically generated
       
  3348      by the MenuEditor of ST/X."
       
  3349 
       
  3350     "Do not manually edit this!! If it is corrupted,
       
  3351      the MenuEditor may not be able to read the specification."
       
  3352 
       
  3353     "
       
  3354      MenuEditor new openOnClass:FileApplicationNoteBook::TextEditor andSelector:#menu
       
  3355      (Menu new fromLiteralArrayEncoding:(FileApplicationNoteBook::TextEditor menu)) startUp
       
  3356     "
       
  3357 
       
  3358     <resource: #menu>
       
  3359 
       
  3360     ^ 
       
  3361      #(#Menu
       
  3362         #(
       
  3363          #(#MenuItem
       
  3364             #label: 'Save'
       
  3365             #translateLabel: true
       
  3366             #isButton: true
       
  3367             #nameKey: #Save
       
  3368             #value: #accept
       
  3369             #enabled: #enableSave
       
  3370             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #saveToFile28x22Icon)
       
  3371           )
       
  3372          #(#MenuItem
       
  3373             #label: 'Reload'
       
  3374             #translateLabel: true
       
  3375             #isButton: true
       
  3376             #nameKey: #Reload
       
  3377             #value: #reload
       
  3378             #enabled: #enableReload
       
  3379             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #reloadFromFile28x22Icon)
       
  3380           )
       
  3381          #(#MenuItem
       
  3382             #label: ''
       
  3383           )
       
  3384          #(#MenuItem
       
  3385             #label: 'Print'
       
  3386             #translateLabel: true
       
  3387             #isButton: true
       
  3388             #nameKey: #Print
       
  3389             #value: #doPrint
       
  3390             #enabled: #enableHexToggle
       
  3391             #labelImage: #(#ResourceRetriever #ToolbarIconLibrary #printer22x22Icon)
       
  3392           )
       
  3393          #(#MenuItem
       
  3394             #label: ''
       
  3395           )
       
  3396          #(#MenuItem
       
  3397             #label: 'Hex'
       
  3398             #translateLabel: true
       
  3399             #isButton: true
       
  3400             #enabled: #enableHexToggle
       
  3401             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #hexToggle22x22Icon)
       
  3402             #indication: #printAsHexDump
       
  3403           )
       
  3404          #(#MenuItem
       
  3405             #label: 'Close'
       
  3406             #translateLabel: true
       
  3407             #isButton: true
       
  3408             #hideMenuOnActivated: false
       
  3409             #isVisible: #isEmbeddedApplication
       
  3410             #startGroup: #right
       
  3411             #value: #doClose
       
  3412             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  3413           )
       
  3414          )
       
  3415         nil
       
  3416         nil
       
  3417       )
       
  3418 ! !
       
  3419 
       
  3420 !FileApplicationNoteBook::TextEditor methodsFor:'accessing'!
       
  3421 
       
  3422 item:aDirContentsItem
       
  3423 
       
  3424 
       
  3425     self stopChangeItemProcess.
       
  3426     super item:aDirContentsItem.
       
  3427     (self askForChange) isNil ifTrue:[ ^ false].
       
  3428     self setContents.
       
  3429     self startChangeItemProcess.
       
  3430     ^ true
       
  3431 !
       
  3432 
       
  3433 presentation
       
  3434     "return the value of the instance variable 'presentation' (automatically generated)"
       
  3435 
       
  3436     presentation isNil ifTrue:[
       
  3437         presentation := #asText.
       
  3438     ].
       
  3439     ^ presentation
       
  3440 !
       
  3441 
       
  3442 presentation:something
       
  3443     "set the value of the instance variable 'presentation' (automatically generated)"
       
  3444 
       
  3445     presentation := something.
       
  3446 !
       
  3447 
       
  3448 semaChangeItem
       
  3449 
       
  3450     semaChangeItem isNil ifTrue:[
       
  3451         semaChangeItem := Semaphore forMutualExclusion.
       
  3452     ].
       
  3453     ^ semaChangeItem
       
  3454 ! !
       
  3455 
       
  3456 !FileApplicationNoteBook::TextEditor methodsFor:'actions'!
       
  3457 
       
  3458 accept
       
  3459 
       
  3460     | dir |
       
  3461 
       
  3462     self masterApplication class openAnotherApplicationOnSameItem ifTrue:[
       
  3463         self updateSameFiles ifFalse:[ ^ self ].
       
  3464     ].
       
  3465     self notifyChannel value:self fileName asString, ' saved'.
       
  3466     dir := self fileName directory.
       
  3467     dir exists not ifTrue:[
       
  3468         dir recursiveMakeDirectory.
       
  3469     ].
       
  3470     editView saveAs:(self fileName).
       
  3471     self notifyChannel value:self fileName asString, ' saved'.
       
  3472     self semaChangeItem critical:[
       
  3473         self item resetItemForTextEditorChange.
       
  3474         textEditorChangeModificationTime := nil.
       
  3475         self itemChanged value:false.
       
  3476     ].
       
  3477     self modifiedChannel value:false.
       
  3478     self itemRemoved value:false.
       
  3479 !
       
  3480 
       
  3481 askForChange
       
  3482     "ask for save changes
       
  3483     "
       
  3484 
       
  3485     |answer string|
       
  3486 
       
  3487     answer := false.
       
  3488     self modifiedChannel value ifTrue:[
       
  3489         self itemChanged value ifTrue:[
       
  3490             string := self fileName asString , ' was changed by someone else' 
       
  3491                         , Character cr , 'want to save your changes anyway ?'
       
  3492         ].
       
  3493         self itemRemoved value ifTrue:[
       
  3494             string := self fileName asString , ' was removed by someone else' 
       
  3495                         , Character cr , 'want to save your changes anyway ?'
       
  3496         ].
       
  3497         string := 'save changed file ' , self fileName asString , ' ?'
       
  3498     ].
       
  3499     string notNil ifTrue:[
       
  3500         answer := (Dialog confirmWithCancel:string).
       
  3501         answer isNil ifTrue:[^ answer].
       
  3502         answer == true ifTrue:[
       
  3503             self accept
       
  3504         ] ifFalse:[
       
  3505             self setContents.
       
  3506         ]
       
  3507     ].
       
  3508     ^ answer
       
  3509 !
       
  3510 
       
  3511 changeInformation 
       
  3512 
       
  3513     | stream |
       
  3514 
       
  3515     stream := WriteStream with:(self getTabString).
       
  3516     masterApplication isNil ifTrue:[
       
  3517         self window label:stream contents.
       
  3518 
       
  3519     ] ifFalse:[
       
  3520         masterApplication tabStringChangeTo:stream contents for:self.
       
  3521     ].
       
  3522     stream close.
       
  3523 !
       
  3524 
       
  3525 doClose
       
  3526 
       
  3527     (self askForChange) isNil ifTrue:[ ^ false].
       
  3528     self masterApplication notNil ifTrue:[
       
  3529         super doClose
       
  3530     ].
       
  3531     ^ true
       
  3532 !
       
  3533 
       
  3534 doPrint
       
  3535     "print the contents
       
  3536     "
       
  3537     (Dialog confirm:'printing ?') ifTrue:[
       
  3538         editView doPrint.
       
  3539     ].
       
  3540 !
       
  3541 
       
  3542 reload
       
  3543 
       
  3544     self setContents.
       
  3545 !
       
  3546 
       
  3547 setContents
       
  3548 
       
  3549 
       
  3550     |file contents present|
       
  3551 
       
  3552     file := self fileName.
       
  3553     RecursionInterruptSignal handle:[ : ex |
       
  3554         Dialog warn:file asString, ' is too big to be loaded !!'.
       
  3555         ^ false.
       
  3556     ] do:[
       
  3557         present := self presentation.
       
  3558         present == #asText ifTrue:[
       
  3559             contents := file contents.
       
  3560         ] ifFalse:[
       
  3561             present == #hexDump ifTrue:[
       
  3562                 contents := self getFileHexContents:file.
       
  3563             ]
       
  3564         ]
       
  3565     ].
       
  3566     self fileContentsModel value:contents.
       
  3567     self enableReload value:false.
       
  3568     self itemChanged value:false.
       
  3569     self modifiedChannel setValue:false.
       
  3570     self modifiedChannel changed.
       
  3571     ^ true
       
  3572 !
       
  3573 
       
  3574 updateSameFiles
       
  3575 
       
  3576     | master modifiedApplications stream filename action|
       
  3577 
       
  3578     master := self masterApplication.
       
  3579     master notNil ifTrue:[
       
  3580         modifiedApplications := master getSameFilesModifiedFor:self.
       
  3581         (modifiedApplications isNil or:[modifiedApplications isEmpty]) ifTrue:[^ true ].
       
  3582         filename := self fileName asString.
       
  3583         stream := WriteStream on:''.
       
  3584         stream nextPutAll:filename.
       
  3585         stream nextPutAll:' is modified in tab'.
       
  3586         modifiedApplications size > 1 ifTrue:[
       
  3587             stream nextPutAll:'s'.
       
  3588         ].
       
  3589         stream cr.
       
  3590         modifiedApplications do:[ : el |
       
  3591             stream space.
       
  3592             stream nextPutAll:filename.
       
  3593             stream space.
       
  3594             el sameFileIndex notNil ifTrue:[
       
  3595                 stream nextPutAll:el sameFileIndex asString.        
       
  3596             ].
       
  3597             stream cr.
       
  3598         ].
       
  3599         stream nextPutAll:'forget changes on other tab'.        
       
  3600         modifiedApplications size > 1 ifTrue:[
       
  3601             stream nextPutAll:'s'.
       
  3602         ].
       
  3603         stream nextPutAll:' ?'.        
       
  3604         action := Dialog 
       
  3605             choose:stream contents 
       
  3606             labels:#('cancel' 'no' 'yes') 
       
  3607             values:#(#cancel #no #yes) 
       
  3608             default:#cancel. 
       
  3609 
       
  3610         stream close.
       
  3611         action == #cancel ifTrue:[ ^ false ].
       
  3612         action == #yes ifTrue:[
       
  3613             "/ here force reload for other applications
       
  3614             modifiedApplications do:[ : el |
       
  3615                 el reload.
       
  3616             ]            
       
  3617         ].
       
  3618     ].
       
  3619     ^ true.
       
  3620 ! !
       
  3621 
       
  3622 !FileApplicationNoteBook::TextEditor methodsFor:'aspects'!
       
  3623 
       
  3624 doSaveFile
       
  3625 
       
  3626     doSaveFile isNil ifTrue:[
       
  3627         doSaveFile := ValueHolder new.
       
  3628     ].
       
  3629     ^ doSaveFile.
       
  3630 !
       
  3631 
       
  3632 enableHexToggle
       
  3633 
       
  3634     enableHexToggle isNil ifTrue:[
       
  3635         enableHexToggle := true asValue.
       
  3636     ].
       
  3637     ^ enableHexToggle
       
  3638 !
       
  3639 
       
  3640 enableReload
       
  3641 
       
  3642     enableReload isNil ifTrue:[
       
  3643         enableReload := false asValue.
       
  3644 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
  3645 "/       enableReload addDependent:self.
       
  3646 "/       enableReload onChangeSend:#enableReloadChanged to:self.
       
  3647     ].
       
  3648     ^ enableReload.
       
  3649 !
       
  3650 
       
  3651 enableSave
       
  3652 
       
  3653     enableSave isNil ifTrue:[
       
  3654         enableSave := false asValue.
       
  3655 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
  3656 "/       enableSave addDependent:self.
       
  3657 "/       enableSave onChangeSend:#enableSaveChanged to:self.
       
  3658     ].
       
  3659     ^ enableSave.
       
  3660 !
       
  3661 
       
  3662 fileContentsModel
       
  3663 
       
  3664     fileContentsModel isNil ifTrue:[
       
  3665         fileContentsModel := ValueHolder new.
       
  3666 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
  3667 "/       fileContentsModel addDependent:self.
       
  3668 "/       fileContentsModel onChangeSend:#fileContentsModelChanged to:self.
       
  3669     ].
       
  3670     ^ fileContentsModel.
       
  3671 !
       
  3672 
       
  3673 itemChanged
       
  3674 
       
  3675     itemChanged isNil ifTrue:[
       
  3676         itemChanged := false asValue.
       
  3677         itemChanged addDependent:self.
       
  3678     ].
       
  3679     ^ itemChanged
       
  3680 !
       
  3681 
       
  3682 itemRemoved
       
  3683 
       
  3684     itemRemoved isNil ifTrue:[
       
  3685         itemRemoved := false asValue.
       
  3686         itemRemoved addDependent:self.
       
  3687     ].
       
  3688     ^ itemRemoved
       
  3689 !
       
  3690 
       
  3691 modifiedChannel
       
  3692 
       
  3693     modifiedChannel isNil ifTrue:[
       
  3694         modifiedChannel := false asValue.
       
  3695 "/ if your app needs to be notified of changes, uncomment one of the lines below:
       
  3696         modifiedChannel addDependent:self.
       
  3697 "/       modifiedChannel onChangeSend:#modifiedChannelChanged to:self.
       
  3698     ].
       
  3699     ^ modifiedChannel.
       
  3700 !
       
  3701 
       
  3702 printAsHexDump
       
  3703 
       
  3704     printAsHexDump isNil ifTrue:[
       
  3705         printAsHexDump := false asValue.
       
  3706         printAsHexDump addDependent:self.
       
  3707     ].
       
  3708     ^ printAsHexDump.
       
  3709 ! !
       
  3710 
       
  3711 !FileApplicationNoteBook::TextEditor methodsFor:'change & update'!
       
  3712 
       
  3713 changeEnableReload
       
  3714 
       
  3715     | modified changed removed |
       
  3716 
       
  3717     modified := self modifiedChannel value.
       
  3718     changed := self itemChanged value.    
       
  3719     removed := self itemRemoved value.    
       
  3720 
       
  3721     self enableReload value:((modified or:[changed]) and:[removed not]).
       
  3722 !
       
  3723 
       
  3724 update:something with:aParameter from:changedObject
       
  3725     "Invoked when an object that I depend upon sends a change notification."
       
  3726 
       
  3727     "stub code automatically generated - please change as required"
       
  3728 
       
  3729     |modified itemRem|
       
  3730 
       
  3731     changedObject == self modifiedChannel ifTrue:[
       
  3732         modified := changedObject value.
       
  3733         self enableSave value:modified.
       
  3734         self changeEnableReload.
       
  3735         ^ self
       
  3736     ].
       
  3737     changedObject == self itemRemoved ifTrue:[
       
  3738         itemRem := changedObject value.
       
  3739         itemRem == true ifTrue:[
       
  3740             self enableSave value:true.
       
  3741         ].
       
  3742         self enableHexToggle value:itemRem not.
       
  3743         self changeEnableReload.
       
  3744         ^ self
       
  3745     ].
       
  3746     changedObject == self itemChanged ifTrue:[
       
  3747         self changeEnableReload.
       
  3748         changedObject value == true ifTrue:[
       
  3749             self enableSave value:true.
       
  3750         ].
       
  3751         ^ self
       
  3752     ].
       
  3753     changedObject == self printAsHexDump ifTrue:[
       
  3754         (self askForChange) isNil ifTrue:[ 
       
  3755             self printAsHexDump value:changedObject value not withoutNotifying:self.
       
  3756             ^ self
       
  3757         ].
       
  3758         changedObject value ifTrue:[
       
  3759             self presentation:#hexDump.
       
  3760         ] ifFalse:[
       
  3761             self presentation:#asText.
       
  3762         ].
       
  3763         self changeInformation.
       
  3764         self setContents.
       
  3765         (self presentation == #hexDump) ifTrue:[
       
  3766             editView readOnly:true.   
       
  3767         ] ifFalse:[
       
  3768             editView readOnly:false.   
       
  3769         ].
       
  3770          ^ self
       
  3771     ].
       
  3772 
       
  3773     super update:something with:aParameter from:changedObject
       
  3774 ! !
       
  3775 
       
  3776 !FileApplicationNoteBook::TextEditor methodsFor:'printing'!
       
  3777 
       
  3778 printString
       
  3779 
       
  3780     ^ ('TextEditor for:', self fileName baseName)
       
  3781 ! !
       
  3782 
       
  3783 !FileApplicationNoteBook::TextEditor methodsFor:'privat-process'!
       
  3784 
       
  3785 checkMyItemForChanges
       
  3786 
       
  3787     | dir exist myItem|
       
  3788 
       
  3789     dir := self fileName directory.
       
  3790     myItem := self item.
       
  3791     exist := myItem exists.
       
  3792     self itemRemoved value:(exist not).
       
  3793     exist ifTrue:[
       
  3794         self semaChangeItem critical:[
       
  3795             | time info|
       
  3796             info := self fileName asAbsoluteFilename info.
       
  3797             time := info modified.
       
  3798             textEditorChangeModificationTime isNil ifTrue:[
       
  3799                 textEditorChangeModificationTime := time.
       
  3800             ].
       
  3801             ((textEditorChangeModificationTime = time) not) ifTrue:[
       
  3802                 "/ contents changed by someone else
       
  3803                 textEditorChangeModificationTime := time.
       
  3804                 self notifyChannel value:item fileName asString, ' was changed by someone else'.
       
  3805                 self itemChanged value:true.
       
  3806             ].
       
  3807         ]
       
  3808     ]
       
  3809 !
       
  3810 
       
  3811 getFileHexContents:f
       
  3812 
       
  3813     |fileName stream data offs 
       
  3814      addrDigits col line lineStream asciiLineStream lines|
       
  3815     
       
  3816     fileName := f baseName.
       
  3817     f isDirectory ifTrue:[
       
  3818         ^ Dialog warn:(resources string:'%1 is a directory.' with:fileName).
       
  3819     ].
       
  3820     f exists ifFalse:[
       
  3821         Dialog warn:(resources string:'oops, ''%1'' is gone or unreadable.' with:fileName).
       
  3822         ^ self
       
  3823     ].
       
  3824     f isReadable ifFalse:[
       
  3825         Dialog warn:(resources string:'''%1'' is unreadable.' with:fileName).
       
  3826         ^ self
       
  3827     ].
       
  3828     f fileSize > (512*1024) ifTrue:[
       
  3829         (Dialog confirm:'Warning: the file is big (', (f fileSize//1024) printString , 'Kb). Show anyway ?')
       
  3830         ifFalse:[
       
  3831             ^ self
       
  3832         ]
       
  3833     ].
       
  3834     stream := f readStream binary.
       
  3835     data := stream contents.
       
  3836     stream close.
       
  3837 
       
  3838 "/        subView list:nil.
       
  3839     col := 1.
       
  3840     offs := 0.
       
  3841     lines := StringCollection new.
       
  3842 
       
  3843     addrDigits := ((f fileSize + 1) log:16) truncated + 1.
       
  3844 
       
  3845     lineStream := '' writeStream.
       
  3846     asciiLineStream := '' writeStream.
       
  3847 
       
  3848     lineStream nextPutAll:(offs hexPrintString:addrDigits).
       
  3849     lineStream nextPutAll:': '.
       
  3850 
       
  3851     data do:[:byte |
       
  3852         lineStream nextPutAll:(byte hexPrintString:2).
       
  3853         (byte between:32 and:127) ifTrue:[
       
  3854             asciiLineStream nextPut:(Character value:byte)
       
  3855         ] ifFalse:[
       
  3856             asciiLineStream nextPut:$.
       
  3857         ].
       
  3858 
       
  3859         offs := offs + 1.
       
  3860         col := col + 1.
       
  3861         col > 16 ifTrue:[
       
  3862             lineStream nextPutAll:'        '.
       
  3863             lineStream nextPutAll:asciiLineStream contents.
       
  3864             lines add:(lineStream contents).
       
  3865             (offs bitAnd:16rFF) == 0 ifTrue:[
       
  3866                 lines add:nil
       
  3867             ].
       
  3868             lineStream reset.
       
  3869             asciiLineStream reset.
       
  3870 
       
  3871             lineStream nextPutAll:(offs hexPrintString:addrDigits).
       
  3872             lineStream nextPutAll:': '.
       
  3873             col := 1.
       
  3874         ] ifFalse:[
       
  3875             lineStream space
       
  3876         ]
       
  3877     ].
       
  3878     line := lineStream contents paddedTo:(3*16 + addrDigits + 1).
       
  3879     lines add:(line , '        ' , asciiLineStream contents).
       
  3880     ^ lines
       
  3881 !
       
  3882 
       
  3883 startChangeItemProcess
       
  3884 
       
  3885     changeItemProcess isNil ifTrue:[
       
  3886         self itemRemoved value:false.
       
  3887         self itemChanged value:false.
       
  3888         changeItemProcess := Process for:[ [   [true] whileTrue:[
       
  3889 
       
  3890                                             self checkMyItemForChanges.
       
  3891                                             Delay waitForSeconds:1.0
       
  3892                                     ]
       
  3893                                 ] valueNowOrOnUnwindDo:[
       
  3894                                     changeItemProcess := nil.
       
  3895                                     textEditorChangeModificationTime := nil.
       
  3896                                 ]
       
  3897                               ]
       
  3898                      priority:(Processor systemBackgroundPriority).
       
  3899 
       
  3900         changeItemProcess name:('TextEditorLookForModify[', self fileName baseName, ']').
       
  3901         changeItemProcess resume.
       
  3902     ].
       
  3903 !
       
  3904 
       
  3905 stopChangeItemProcess
       
  3906 
       
  3907     | task |
       
  3908 
       
  3909     task := changeItemProcess.
       
  3910     task notNil ifTrue:[
       
  3911         changeItemProcess := nil.
       
  3912 
       
  3913         Object errorSignal handle:[:ex|
       
  3914             Dialog warn:ex description.
       
  3915         ]do:[
       
  3916             task isDead ifFalse:[
       
  3917                 task terminate.
       
  3918                 task waitUntilTerminated.
       
  3919             ]
       
  3920         ]
       
  3921     ].
       
  3922 ! !
       
  3923 
       
  3924 !FileApplicationNoteBook::TextEditor methodsFor:'queries'!
       
  3925 
       
  3926 isModified
       
  3927 
       
  3928     ^ self modifiedChannel value
       
  3929 ! !
       
  3930 
       
  3931 !FileApplicationNoteBook::TextEditor methodsFor:'startup & release'!
       
  3932 
       
  3933 closeRequest
       
  3934 
       
  3935     (self doClose) ifTrue:[
       
  3936         ^ super closeRequest.
       
  3937     ].
       
  3938 !
       
  3939 
       
  3940 postBuildTextEditor:aWidget
       
  3941 
       
  3942     editView       := aWidget scrolledView.
       
  3943 !
       
  3944 
       
  3945 postBuildWith:aBuilder
       
  3946 
       
  3947     super postBuildWith:aBuilder.
       
  3948 !
       
  3949 
       
  3950 postOpenWith:aBuilder
       
  3951 
       
  3952     self masterApplication isNil ifTrue:[
       
  3953         self masterApplication:nil.
       
  3954         self item:(DirectoryContentsBrowser itemClass with:(Filename homeDirectory construct:'/lala/.bashrc')).
       
  3955     ].
       
  3956     self setUpTextView.
       
  3957     self changeInformation.
       
  3958     ^ super postOpenWith:aBuilder
       
  3959 !
       
  3960 
       
  3961 release
       
  3962     "release my resources
       
  3963     "                    
       
  3964     self stopChangeItemProcess.
       
  3965     super release.
       
  3966 !
       
  3967 
       
  3968 setUpTextView
       
  3969 
       
  3970     |paranthesis col|
       
  3971 
       
  3972     self item hasMimeType ifFalse:[^nil].
       
  3973     (self item mimeType isHtml) ifTrue:[
       
  3974         paranthesis := editView parenthesisSpecification.
       
  3975         ((paranthesis at:#open) includes:$<) ifFalse:[
       
  3976             col := (paranthesis at:#open) asOrderedCollection add:$<.
       
  3977             paranthesis at:#open put:col.
       
  3978         ].
       
  3979         ((paranthesis at:#close) includes:$>) ifFalse:[
       
  3980             col := (paranthesis at:#close) asOrderedCollection add:$>.
       
  3981             paranthesis at:#close put:col.
       
  3982         ]
       
  3983     ].
       
  3984 ! !
       
  3985 
       
  3986 !FileApplicationNoteBook::XViewApplication class methodsFor:'defaults'!
       
  3987 
       
  3988 maxNumberOfVNCRestarts
       
  3989 
       
  3990     ^ 10
       
  3991 !
       
  3992 
       
  3993 mimeTypeUnixApplicationMapping
       
  3994 
       
  3995 " here insert the application and mime type pairs to open by XviewApplication
       
  3996 "
       
  3997 
       
  3998     ^
       
  3999     #(
       
  4000         #(#'application/postscript'     #gv            )
       
  4001         #(#'application/pdf'            #acroread      )
       
  4002     )
       
  4003 !
       
  4004 
       
  4005 tabStringFor:aApplicationType
       
  4006 
       
  4007     ^ 'VNC for:'
       
  4008 !
       
  4009 
       
  4010 wantNewApplicationAnyway
       
  4011 
       
  4012     ^ false
       
  4013 ! !
       
  4014 
       
  4015 !FileApplicationNoteBook::XViewApplication class methodsFor:'interface specs'!
       
  4016 
       
  4017 windowSpec
       
  4018     "This resource specification was automatically generated
       
  4019      by the UIPainter of ST/X."
       
  4020 
       
  4021     "Do not manually edit this!! If it is corrupted,
       
  4022      the UIPainter may not be able to read the specification."
       
  4023 
       
  4024     "
       
  4025      UIPainter new openOnClass:NoteBookApplication::XViewApplication andSelector:#windowSpec
       
  4026      NoteBookApplication::XViewApplication new openInterface:#windowSpec
       
  4027      NoteBookApplication::XViewApplication open
       
  4028     "
       
  4029 
       
  4030     <resource: #canvas>
       
  4031 
       
  4032     ^ 
       
  4033      #(#FullSpec
       
  4034         #name: #windowSpec
       
  4035         #window: 
       
  4036        #(#WindowSpec
       
  4037           #label: 'XView'
       
  4038           #name: 'XView'
       
  4039           #min: #(#Point 10 10)
       
  4040           #max: #(#Point 1024 768)
       
  4041           #bounds: #(#Rectangle 12 22 688 514)
       
  4042           #menu: #mainMenu
       
  4043         )
       
  4044         #component: 
       
  4045        #(#SpecCollection
       
  4046           #collection: #(
       
  4047            #(#MenuPanelSpec
       
  4048               #name: 'MenuTerminal'
       
  4049               #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
       
  4050               #visibilityChannel: #isEmbeddedApplication
       
  4051               #menu: #menu
       
  4052               #textDefault: true
       
  4053             )
       
  4054            #(#ArbitraryComponentSpec
       
  4055               #name: 'TerminalView'
       
  4056               #layout: #(#LayoutFrame 0 0.0 32 0.0 0 1.0 0 1.0)
       
  4057               #hasHorizontalScrollBar: true
       
  4058               #hasVerticalScrollBar: true
       
  4059               #miniScrollerHorizontal: false
       
  4060               #miniScrollerVertical: false
       
  4061               #hasBorder: false
       
  4062               #component: #VNCFrameBufferView
       
  4063               #postBuildCallback: #postBuildXView:
       
  4064             )
       
  4065            )
       
  4066          
       
  4067         )
       
  4068       )
       
  4069 ! !
       
  4070 
       
  4071 !FileApplicationNoteBook::XViewApplication class methodsFor:'menu specs'!
       
  4072 
       
  4073 menu
       
  4074     "This resource specification was automatically generated
       
  4075      by the MenuEditor of ST/X."
       
  4076 
       
  4077     "Do not manually edit this!! If it is corrupted,
       
  4078      the MenuEditor may not be able to read the specification."
       
  4079 
       
  4080     "
       
  4081      MenuEditor new openOnClass:NoteBookApplication::ImageViewApplication andSelector:#menu
       
  4082      (Menu new fromLiteralArrayEncoding:(NoteBookApplication::ImageViewApplication menu)) startUp
       
  4083     "
       
  4084 
       
  4085     <resource: #menu>
       
  4086 
       
  4087     ^ 
       
  4088      #(#Menu
       
  4089         #(
       
  4090          #(#MenuItem
       
  4091             #label: 'Close'
       
  4092             #translateLabel: true
       
  4093             #isButton: true
       
  4094             #hideMenuOnActivated: false
       
  4095             #startGroup: #right
       
  4096             #value: #doClose
       
  4097             #labelImage: #(#ResourceRetriever #AbstractFileBrowser #closeIcon)
       
  4098           )
       
  4099          )
       
  4100         nil
       
  4101         nil
       
  4102       )
       
  4103 ! !
       
  4104 
       
  4105 !FileApplicationNoteBook::XViewApplication class methodsFor:'queries'!
       
  4106 
       
  4107 canOpenItem:aItem
       
  4108 
       
  4109     | keySym canOpen|
       
  4110     
       
  4111     keySym := aItem mimeType asSymbol.
       
  4112     (OperatingSystem isUNIXlike) not ifTrue:[^ false].
       
  4113     canOpen := self mimeTypeUnixApplicationMapping detect:[ : el | (el at:1) == keySym ] ifNone:[nil].
       
  4114     canOpen isNil ifTrue:[^ false].
       
  4115      (OperatingSystem executeCommand:('which ', self UnixVNCCommand)) ifTrue:[
       
  4116         ^ true
       
  4117     ] ifFalse:[
       
  4118         (Dialog warn:'cant start viewer for '
       
  4119                         , aItem fileName baseName
       
  4120         )
       
  4121     ].
       
  4122     ^ false.
       
  4123 ! !
       
  4124 
       
  4125 !FileApplicationNoteBook::XViewApplication methodsFor:'accessing'!
       
  4126 
       
  4127 xView
       
  4128     "return the value of the instance variable 'imageView' (automatically generated)"
       
  4129 
       
  4130     ^ xView
       
  4131 !
       
  4132 
       
  4133 xView:something
       
  4134     "set the value of the instance variable 'imageView' (automatically generated)"
       
  4135 
       
  4136     xView := something.
       
  4137 ! !
       
  4138 
       
  4139 !FileApplicationNoteBook::XViewApplication methodsFor:'actions'!
       
  4140 
       
  4141 changeInformation 
       
  4142 
       
  4143     | stream|
       
  4144 
       
  4145     stream := WriteStream on:''.
       
  4146     stream nextPutAll:'XView on: '.
       
  4147     stream nextPutAll:self fileName baseName.
       
  4148     masterApplication isNil ifTrue:[
       
  4149         self window label:stream contents.
       
  4150 
       
  4151     ] ifFalse:[
       
  4152         masterApplication tabStringChangeTo:stream contents for:self.
       
  4153     ].
       
  4154     stream close.
       
  4155 !
       
  4156 
       
  4157 setupXView
       
  4158 
       
  4159     |xExt yExt fileBrowserWindow|
       
  4160 
       
  4161     self startVNCserver.
       
  4162     xExt := self xView width asString.
       
  4163     fileBrowserWindow := self application:#FileBrowserV2 do:#window.
       
  4164     fileBrowserWindow isNil ifTrue:[
       
  4165         yExt := self xView height asString.
       
  4166     ] ifFalse:[
       
  4167         yExt := fileBrowserWindow height asString.
       
  4168     ].
       
  4169     ext := xExt, 'x', yExt.    
       
  4170     self startViewer.
       
  4171 ! !
       
  4172 
       
  4173 !FileApplicationNoteBook::XViewApplication methodsFor:'actions VNC'!
       
  4174 
       
  4175 setupView
       
  4176     |  renderer view|
       
  4177 
       
  4178     view := xView.
       
  4179     renderer := VNCRenderer for:vncConnection targetWindow:view device:xView device.
       
  4180 
       
  4181     view renderer:renderer.
       
  4182     view connection:vncConnection.
       
  4183 
       
  4184     VNCException handle:[:ex|
       
  4185         self stopViewer.
       
  4186     ] do:[
       
  4187         vncConnection 
       
  4188             startMessageHandlerProcessForRenderer:renderer
       
  4189             errorHandler:[:ex | self stopViewer].
       
  4190     ].
       
  4191 !
       
  4192 
       
  4193 startVNCserver
       
  4194     |cmd blocked connected numberOfVncStarts|
       
  4195 
       
  4196     connected := false.
       
  4197     numberOfVncStarts isNil ifTrue:[
       
  4198         numberOfVncStarts := 1.
       
  4199     ] ifFalse:[
       
  4200         numberOfVncStarts := numberOfVncStarts + 1.
       
  4201     ].
       
  4202 
       
  4203     vncLock isNil ifTrue:[vncLock := Semaphore forMutualExclusion].
       
  4204 
       
  4205     vncServerPID isNil ifTrue:[
       
  4206         cmd := ('/usr/X11R6/bin/', self class UnixVNCCommand).
       
  4207         cmd asFilename exists ifFalse:[
       
  4208             cmd := self class UnixVNCCommand.
       
  4209         ].
       
  4210         vncPortNr isNil ifTrue:[
       
  4211             vncPortNr := 29
       
  4212         ].
       
  4213         cmd := cmd , ' :' , vncPortNr printString , ' nologo -nevershared -localhost -depth 16 -geometry 1024x1024'.
       
  4214 
       
  4215         blocked := OperatingSystem blockInterrupts.
       
  4216 
       
  4217         vncServerPID := Processor
       
  4218                    monitor:[
       
  4219                       vncServerIsTerminated := false.
       
  4220                       OperatingSystem
       
  4221                           exec:'/bin/sh'
       
  4222                           withArguments:(Array with:'sh' with:'-c' with:cmd)
       
  4223                           fileDescriptors:#()
       
  4224                           closeDescriptors:#()
       
  4225                           fork:true
       
  4226                           newPgrp:true
       
  4227                           inDirectory:nil.
       
  4228                    ]
       
  4229                    action:[:status |
       
  4230                       status stillAlive ifFalse:[
       
  4231                           OperatingSystem closePid:vncServerPID.
       
  4232                           vncLock critical:[  
       
  4233                              vncServerPID := nil.
       
  4234                              self vncServerTerminated.
       
  4235                           ].
       
  4236                       ].
       
  4237                   ].
       
  4238 
       
  4239         blocked ifFalse:[
       
  4240             OperatingSystem unblockInterrupts
       
  4241         ].
       
  4242     ].
       
  4243 
       
  4244     self waitForTerminationOfServer ifTrue:[
       
  4245 "/        Transcript showCR:'server has terminated really - try with next port'.
       
  4246         (numberOfVncStarts < self class maxNumberOfVNCRestarts) ifTrue:[
       
  4247             vncPortNr := vncPortNr + 1.
       
  4248 "/            Transcript showCR:'try next port ', vncPortNr asString.
       
  4249             self startVNCserver.
       
  4250         ] ifFalse:[
       
  4251             Dialog warn:'have started servers from port '
       
  4252                       , (vncPortNr - self class maxNumberOfVNCRestarts) asString
       
  4253                       , ' to '
       
  4254                       , vncPortNr
       
  4255                       , ' - cant connect anyway'.
       
  4256 "/            Transcript showCR:'have started servers from port ', vncPortNr - self class maxNumberOfVNCRestarts, ' to ', vncPortNr.
       
  4257         ].
       
  4258     ] ifFalse:[
       
  4259         vncLock critical:[  
       
  4260             vncServerPID isNil ifTrue:[
       
  4261                 Dialog warn:'Cannot start Xvnc'.
       
  4262             ] ifFalse:[
       
  4263                 VNCAuthenticationFailure handle:[:ex |
       
  4264                     Dialog warn:'Wrong password'.
       
  4265                 ] do:[
       
  4266                     connected := self vncConnect.
       
  4267                 ].
       
  4268                 connected ifTrue:[self setupView].
       
  4269             ].
       
  4270         ].
       
  4271     ].
       
  4272 !
       
  4273 
       
  4274 stopVNCServer
       
  4275 
       
  4276     vncServerPID notNil ifTrue:[
       
  4277         OperatingSystem terminateProcess:vncServerPID.
       
  4278         Delay waitForSeconds:0.2.
       
  4279         vncServerPID notNil ifTrue:[
       
  4280             OperatingSystem killProcess:vncServerPID.
       
  4281             vncServerPID := nil.
       
  4282         ].
       
  4283     ].
       
  4284     self vncServerTerminated.
       
  4285 !
       
  4286 
       
  4287 vncConnect
       
  4288     |  tryConnects|
       
  4289 
       
  4290     vncConnection notNil ifTrue:[
       
  4291         vncConnection close
       
  4292     ].
       
  4293 
       
  4294     vncConnection := VNCServerConnection new.
       
  4295     tryConnects := 1.
       
  4296     [tryConnects < 3] whileTrue:[
       
  4297         VNCConnectionFailure handle:[:ex |
       
  4298             Delay waitForSeconds:0.5.
       
  4299             tryConnects := tryConnects + 1.
       
  4300         ] do:[
       
  4301             vncConnection connectTo:'localhost' port:vncPortNr.
       
  4302             ^ true.
       
  4303         ].
       
  4304     ].
       
  4305     ^ false
       
  4306 !
       
  4307 
       
  4308 vncServerTerminated
       
  4309 "/    Transcript showCR:'vnc server has terminated'.
       
  4310 "/    'vnc server has terminated' errorPrintCR.
       
  4311     "/ Dialog information:'vnc server has terminated'.
       
  4312 
       
  4313     self stopViewer.
       
  4314     vncConnection notNil ifTrue:[
       
  4315         vncConnection close.
       
  4316         vncConnection := nil
       
  4317     ].
       
  4318     vncServerIsTerminated := true.
       
  4319 !
       
  4320 
       
  4321 waitForTerminationOfServer
       
  4322     | cycles |
       
  4323 
       
  4324     cycles := 1.
       
  4325     [vncServerIsTerminated] whileFalse:[
       
  4326         (cycles > 3) ifTrue:[^ false].
       
  4327         cycles := cycles + 1.
       
  4328         Delay waitForSeconds:0.5.
       
  4329     ].
       
  4330     ^ true
       
  4331 ! !
       
  4332 
       
  4333 !FileApplicationNoteBook::XViewApplication methodsFor:'actions viewer'!
       
  4334 
       
  4335 startViewer
       
  4336     |cmd keySym applItem |
       
  4337 
       
  4338     keySym := self item mimeType asSymbol.
       
  4339     applItem := self class mimeTypeUnixApplicationMapping detect:[ : el | (el at:1) == keySym ] ifNone:[nil].
       
  4340     applItem isNil ifTrue:[ ^ self].
       
  4341     
       
  4342     cmd := (applItem at:2) asString, ' -geometry ', ext, ' -display :' , vncPortNr printString , ' ' , self fileName asString.
       
  4343     self startViewer:cmd
       
  4344 !
       
  4345 
       
  4346 startViewer:viewerCommand
       
  4347     |blocked|
       
  4348 
       
  4349     viewerPID notNil ifTrue:[
       
  4350         ^ self
       
  4351     ].
       
  4352 
       
  4353     blocked := OperatingSystem blockInterrupts.
       
  4354 
       
  4355     viewerPID := Processor
       
  4356                monitor:[
       
  4357                   OperatingSystem
       
  4358                       exec:'/bin/sh'
       
  4359                       withArguments:(Array with:'sh' with:'-c' with:viewerCommand)
       
  4360                       fileDescriptors:#()
       
  4361                       closeDescriptors:#()
       
  4362                       fork:true
       
  4363                       newPgrp:true
       
  4364                       inDirectory:nil.
       
  4365                ]
       
  4366                action:[:status |
       
  4367                   status stillAlive ifFalse:[
       
  4368                       OperatingSystem closePid:viewerPID.
       
  4369                       viewerPID := nil.
       
  4370                       self viewerTerminated.
       
  4371                   ].
       
  4372                ].
       
  4373 
       
  4374     blocked ifFalse:[
       
  4375         OperatingSystem unblockInterrupts
       
  4376     ].
       
  4377 
       
  4378     viewerPID isNil ifTrue:[
       
  4379         Dialog warn:'Cannot start ', viewerCommand.
       
  4380     ].
       
  4381 !
       
  4382 
       
  4383 startXterm
       
  4384     |cmd|
       
  4385 
       
  4386     cmd := 'xterm -geometry 600x800 -display :' , vncPortNr printString.
       
  4387     self startViewer:cmd
       
  4388 !
       
  4389 
       
  4390 stopViewer
       
  4391     viewerPID notNil ifTrue:[
       
  4392         OperatingSystem terminateProcess:viewerPID.
       
  4393         Delay waitForSeconds:0.2.
       
  4394         viewerPID notNil ifTrue:[
       
  4395             OperatingSystem killProcess:viewerPID.
       
  4396             viewerPID := nil.
       
  4397         ]
       
  4398     ].
       
  4399 !
       
  4400 
       
  4401 viewerTerminated
       
  4402 "/    Transcript showCR:'viewer has terminated'.
       
  4403 "/    'viewer has terminated' errorPrintCR.
       
  4404     "/ Dialog information:'viewer has terminated'.
       
  4405 ! !
       
  4406 
       
  4407 !FileApplicationNoteBook::XViewApplication methodsFor:'initialization & release'!
       
  4408 
       
  4409 postBuildXView:aWidget
       
  4410 
       
  4411     self xView:aWidget scrolledView.
       
  4412     self xView wantsFocusWithPointerEnter.
       
  4413     aWidget autoHideScrollBars:true.
       
  4414 !
       
  4415 
       
  4416 postOpenWith:aBuilder 
       
  4417     "
       
  4418     only invoked if the application not started from a master
       
  4419     "
       
  4420 
       
  4421     |currentDir contents suffix fileName|
       
  4422 
       
  4423     self masterApplication isNil ifTrue:[
       
  4424         self masterApplication:nil.
       
  4425         currentDir := Filename homeDirectory.
       
  4426         contents := currentDir directoryContents.
       
  4427         fileName := contents 
       
  4428                     detect:[:file | 
       
  4429                         suffix := file asFilename suffix asLowercase.
       
  4430                         suffix = 'pdf'
       
  4431                     ]
       
  4432                     ifNone:[nil].
       
  4433         fileName isNil ifTrue:[
       
  4434             Dialog warn:'cant find a PDF File in ' , currentDir asString.
       
  4435             ^ self
       
  4436         ].
       
  4437         self item:(DirectoryContentsBrowser itemClass with:(currentDir construct:fileName)).
       
  4438     ].
       
  4439     self changeInformation.
       
  4440     self setupXView.
       
  4441     ^ super postOpenWith:aBuilder
       
  4442 !
       
  4443 
       
  4444 release
       
  4445 "/Transcript showCR:'release'.
       
  4446     self stopViewer.
       
  4447     self stopVNCServer.
       
  4448     ^ super release
       
  4449 ! !
       
  4450 
       
  4451 !FileApplicationNoteBook class methodsFor:'documentation'!
       
  4452 
       
  4453 version
       
  4454     ^ '$Header: /cvs/stx/stx/libtool/FileApplicationNoteBook.st,v 1.1 2002-09-25 07:59:29 penk Exp $'
       
  4455 ! !