Move image-view to a package

This removes the ugliness of having project.coffee require
image-edit-session at the end since the image-edit-session can
now register itself in an @activate callback and as a deferred
deserializer in the package.cson file.
This commit is contained in:
Kevin Sawicki
2013-06-07 10:15:32 -07:00
parent 3029137cb8
commit fca1c13d03
8 changed files with 24 additions and 28 deletions

View File

@@ -36,10 +36,3 @@
'.editor !important, .editor.mini !important':
'escape': 'editor:consolidate-selections'
'.image-view':
'meta-+': 'image-view:zoom-in'
'meta-=': 'image-view:zoom-in'
'meta--': 'image-view:zoom-out'
'meta-_': 'image-view:zoom-out'
'meta-0': 'image-view:reset-zoom'

View File

@@ -317,5 +317,3 @@ class Project
@on 'buffer-created', (buffer) -> callback(buffer)
_.extend Project.prototype, EventEmitter
require 'image-edit-session'

View File

@@ -0,0 +1,6 @@
'.image-view':
'meta-+': 'image-view:zoom-in'
'meta-=': 'image-view:zoom-in'
'meta--': 'image-view:zoom-out'
'meta-_': 'image-view:zoom-out'
'meta-0': 'image-view:reset-zoom'

View File

@@ -8,21 +8,19 @@ module.exports=
class ImageEditSession
registerDeserializer(this)
# Files with these extensions will be opened as images
@imageExtensions: ['.gif', '.jpeg', '.jpg', '.png']
@activate: ->
# Files with these extensions will be opened as images
imageExtensions = ['.gif', '.jpeg', '.jpg', '.png']
Project = require 'project'
Project.registerOpener (filePath) ->
if _.include(imageExtensions, fsUtils.extension(filePath))
new ImageEditSession(filePath)
### 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)
@deserialize: ({path}={}) ->
if fsUtils.exists(path)
new ImageEditSession(path)
else
console.warn "Could not build edit session for path '#{state.path}' because that file no longer exists"
console.warn "Could not build image edit session for path '#{path}' because that file no longer exists"
constructor: (@path) ->
@@ -31,7 +29,7 @@ class ImageEditSession
path: @path
getViewClass: ->
require 'image-view'
require './image-view'
### Public ###

View File

@@ -16,8 +16,6 @@ class ImageView extends ScrollView
initialize: (imageEditSession) ->
super
requireStylesheet 'image-view'
@image.load =>
@originalHeight = @image.height()
@originalWidth = @image.width()

View File

@@ -0,0 +1,3 @@
'description': 'View images in the editor'
'main': './lib/image-edit-session'
'deferredDeserializers': ['ImageEditSession']

View File

@@ -1,7 +1,7 @@
ImageView = require 'image-view'
ImageEditSession = require 'image-edit-session'
ImageView = require '../lib/image-view'
ImageEditSession = require '../lib/image-edit-session'
describe "ImageView", ->
fdescribe "ImageView", ->
[view, path] = []
beforeEach ->