Browsing files with the GTInspector

Files are everywhere, and almost all significant applications I know deal with them in one way or another. They read from files, they write to files, they manipulate files. Given the importance of files, it is very likely that you will end up needing to explore problems related to these files.

Pharo comes with a neat library called FileSystem (originally developed by Colin Puttney and later enhanced by several others) that allows you to programmatically handle files using elegant expressions like:

FileSystem disk workingDirectory / ’hello.txt’ 
writeStreamDo: [ :stream | stream nextPutAll: ‘Hello World’ ]

You can learn more about the library in the Deep into Pharo book.

Having a powerful file library is important, but when you play with files you might want to explore them visually, like you can do it at the operating system level. Pharo offers such a visual interface embodied in the File Browser that comes bundled by default.


That is nice, but the problem is that combining the two worlds (visual and programmatic) is poorly supported. GTInspector solves that dilemma with a simple user interface.

For example, inspecting FileSystem disk workingDirectory offers a dedicated presentation showing the items of the folder. Selecting a file allows you to take a look at the contents of that file. The picture below shows the same folder as the one above.


As you can see, the items are available only for a reference to a folder, and the contents only for a reference to a file. Combined with the default finder-like behavior of the GTInspector, you can obtain an experience similar to the OS X Finder.


But, that is not all. What if you have special files that you would like to see in a higher level way? For example, if you have happen to have a picture available, would it not be nice to preview it in place? Of course it would be.


This is possible with a simple extension:

FileReference>>gtInspectorPngIn: composite
  <gtInspectorPresentationOrder: 10>
  composite morph
    title: 'Morph';
    display: [ self binaryReadStreamDo: [ :stream | 
                    PNGReadWriter formFromStream: stream ] ];
    when: [ self mimeTypes notNil and: [ 
              self mimeTypes first matches: ZnMimeType imagePng ] ] 

If you want to handle your own file types, you can just add similar extensions. You can explore how it works in the latest Moose 5.0 development image.

The inspector is indeed the most basic tool available. However, this should not mean that the inspection experience has to remain basic. Programmers deserve better.

Posted by Tudor Girba at 2 February 2014, 11:03 pm with tags assessment, moose, pharo, analysis, tooling link