Register a custom opener for ImageEditSessions on the Project class

This commit is contained in:
Nathan Sobo
2013-05-14 20:32:16 -06:00
parent aa86362a0a
commit 5aac826ec1
2 changed files with 11 additions and 18 deletions

View File

@@ -8,8 +8,16 @@ module.exports=
class ImageEditSession
registerDeserializer(this)
# Files with these extensions will be opened as images
@imageExtensions: ['.gif', '.jpeg', '.jpg', '.png']
### Internal ###
Project = require 'project'
Project.registerOpener (path) =>
new ImageEditSession(path) if _.include(@imageExtensions, fsUtils.extension(path))
@deserialize: (state) ->
if fsUtils.exists(state.path)
project.open(state.path)
@@ -27,19 +35,6 @@ class ImageEditSession
### Public ###
# Identifies if a path can be opened by the image viewer.
#
# path - The {String} name of the path to check
#
# Returns a {Boolean}.
@canOpen: (path) ->
_.indexOf([
'.gif'
'.jpeg'
'.jpg'
'.png'
], fsUtils.extension(path), true) >= 0
# Retrieves the filename of the open file.
#
# This is `'untitled'` if the file is new and not saved to the disk.

View File

@@ -4,7 +4,6 @@ $ = require 'jquery'
Range = require 'range'
Buffer = require 'text-buffer'
EditSession = require 'edit-session'
ImageEditSession = require 'image-edit-session'
EventEmitter = require 'event-emitter'
Directory = require 'directory'
BufferedProcess = require 'buffered-process'
@@ -160,10 +159,7 @@ class Project
for opener in @constructor.openers
return resource if resource = opener(filePath, options)
if ImageEditSession.canOpen(filePath)
new ImageEditSession(filePath)
else
@buildEditSessionForBuffer(@bufferForPath(filePath), options)
@buildEditSessionForBuffer(@bufferForPath(filePath), options)
# Retrieves all the {EditSession}s in the project; that is, the `EditSession`s for all open files.
#
@@ -311,3 +307,5 @@ class Project
@on 'buffer-created', (buffer) -> callback(buffer)
_.extend Project.prototype, EventEmitter
require 'image-edit-session'