adobe/brackets — pull request #5495 by couzteau (2013-10-11 22:34:32+00:00)
Title: Preview Images

This implementation provides a new class namely ImageViewer that enables EditorManager to display images in the editor-holder container.

Implementation highlights:
- DocumentCommmandHandler owns the decision of opening a file in an Editor or in a custom viewer. -
- EditorManager maintains the view state in a new local variable _currentlyViewedFile and associated and exported getter and setter methods for the same to store path to the file in view, i.e. a text document in the editor or the path in the image viewer. ProjectManager no longer uses getCurrentDocument to maintain the project tree, but uses getCurrentFile instead.
- To determine whether a file is an image or a text document LanguageManager's method getLanguageForPath should be used. For image files it detects a new mode with id 'image'.
- Changing the file in view always fires a _onCurrentDocumentChange-event. This also happens when the user switches views from one image to another. EditorManager's event handler for _onCurrentDocumentChange holds the logic to show and hide ImageViewers similar to the way editors are hidden and shown.
- ImageViewer is the only custom viewer at this point, but the design is made to make the addition of more custom viewers easy, i.e. SVG viewer, video player, audio player, ...? To keep EditorManager code independent of ImageViewer implementation details, only the method showCustomViewer and the resize event handler have references to image viewer. These are wrapped with a language / mode test, so that these areas can easily be extended to accomodate othe viewers.
References:
- Trello: https://trello.com/c/l9AcILkC/24-8-preview-images
- Spec: https://github.com/adobe/brackets/wiki/Preview-Images-Spec

Note: The code in this review does not yet include unit tests, and some tweaks to drag and drop and file open. That said drag & drop and file open do work.