mirror of
https://github.com/atom/atom.git
synced 2026-02-17 18:11:29 -05:00
Register a custom opener for ImageEditSessions on the Project class
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user