Filename.st
changeset 23632 5b8f61358650
parent 23630 484d0fd2e425
child 23654 63bb455ac3fd
equal deleted inserted replaced
23631:4d23b8c410b0 23632:5b8f61358650
  4356     ^ (ProgrammingLanguage forFile: self) fileIn: self
  4356     ^ (ProgrammingLanguage forFile: self) fileIn: self
  4357 
  4357 
  4358     "Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
  4358     "Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
  4359 ! !
  4359 ! !
  4360 
  4360 
  4361 !Filename methodsFor:'inspecting'!
       
  4362 
       
  4363 inspector2TabContentsView
       
  4364     <inspector2Tab>      
       
  4365     
       
  4366     "provide an additional tab, which presents the file's contents.
       
  4367         '.' asFilename inspect
       
  4368         'smalltalk.rc' asFilename inspect
       
  4369     "
       
  4370 
       
  4371     | mimetype |
       
  4372 
       
  4373     self isDirectory ifTrue:[ 
       
  4374         | tab |    
       
  4375 
       
  4376         ^ (tab := Tools::Inspector2Tab new)
       
  4377             label: 'Contents';
       
  4378             priority: 50;
       
  4379             applicationHolder: [   
       
  4380                 | browser |
       
  4381 
       
  4382                 browser := DirectoryContentsBrowser new.
       
  4383                 browser
       
  4384                     initializeAspects;
       
  4385                     aspectFor:#currentFileNameHolder put:((OrderedCollection with:self) asValue);
       
  4386                     updateCurrentFileNameHolderWhenSelectionChanges:false.
       
  4387                 browser viewDirsInContentsBrowser value:true.
       
  4388                 browser enterActionBlock:[:item|
       
  4389                     | app |                        
       
  4390                     app := tab view topView application.
       
  4391                     app notNil ifTrue:[
       
  4392                         app inspect: item fileName.
       
  4393                     ].
       
  4394                 ].
       
  4395                 browser
       
  4396             ];
       
  4397             yourself
       
  4398     ].
       
  4399     mimetype := self mimeTypeFromName.
       
  4400     (mimetype notNil and:[mimetype isTextType or:[ mimetype endsWith: '-source']]) ifTrue:[ 
       
  4401         ^ Tools::Inspector2Tab new
       
  4402             label: 'Contents';
       
  4403             priority: 50;
       
  4404             view: [   
       
  4405                 | view model |
       
  4406 
       
  4407                 self exists ifTrue:[
       
  4408                     model := self contents asValue.
       
  4409                 ] ifFalse:[
       
  4410                     model := 'File does not (no longer?) exist' asValue.
       
  4411                 ].
       
  4412                 view := Tools::CodeView2 new.
       
  4413                 view model: model.
       
  4414                 view acceptAction:[ :contents |
       
  4415                     self writingFileDo:[:s|
       
  4416                         contents do:[:line | s nextPutLine: line ].
       
  4417                     ].
       
  4418                     model value: contents.
       
  4419                 ].
       
  4420                 view
       
  4421             ];
       
  4422             yourself
       
  4423     ].
       
  4424 
       
  4425     ^ nil
       
  4426 
       
  4427     "
       
  4428      '/tmp' asFilename inspect
       
  4429     "
       
  4430 
       
  4431     "Created: / 13-02-2015 / 15:08:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  4432     "Modified: / 13-02-2015 / 20:57:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  4433     "Modified (comment): / 14-09-2018 / 18:27:06 / Claus Gittinger"
       
  4434 ! !
       
  4435 
  4361 
  4436 !Filename methodsFor:'instance creation'!
  4362 !Filename methodsFor:'instance creation'!
  4437 
  4363 
  4438 / subname
  4364 / subname
  4439     "Same as construct: Taking the receiver as a directory name, construct a new
  4365     "Same as construct: Taking the receiver as a directory name, construct a new
  6156      '/foo/bar' asFilename isDirectory
  6082      '/foo/bar' asFilename isDirectory
  6157      '/tmp' asFilename isDirectory
  6083      '/tmp' asFilename isDirectory
  6158      'Makefile' asFilename isDirectory
  6084      'Makefile' asFilename isDirectory
  6159      'c:\' asFilename isDirectory
  6085      'c:\' asFilename isDirectory
  6160      'd:\' asFilename isDirectory
  6086      'd:\' asFilename isDirectory
  6161     "
  6087      '\\host\dir' asFilename isDirectory
  6162 
  6088      OperatingSystem isDirectory:'\\host\dir'
  6163     "Modified: / 21.9.1998 / 15:53:10 / cg"
  6089     "
       
  6090 
       
  6091     "Modified: / 21-09-1998 / 15:53:10 / cg"
       
  6092     "Modified (comment): / 22-01-2019 / 15:14:45 / Stefan Vogel"
  6164 !
  6093 !
  6165 
  6094 
  6166 isNonEmptyDirectory
  6095 isNonEmptyDirectory
  6167     "return true, if the receiver represents an existing,
  6096     "return true, if the receiver represents an existing,
  6168      readable directories pathname, and the directory is not empty."
  6097      readable directories pathname, and the directory is not empty."