mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
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:
@@ -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'
|
||||
|
||||
@@ -317,5 +317,3 @@ class Project
|
||||
@on 'buffer-created', (buffer) -> callback(buffer)
|
||||
|
||||
_.extend Project.prototype, EventEmitter
|
||||
|
||||
require 'image-edit-session'
|
||||
|
||||
6
src/packages/image-view/keymaps/image-view.cson
Normal file
6
src/packages/image-view/keymaps/image-view.cson
Normal 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'
|
||||
@@ -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 ###
|
||||
|
||||
@@ -16,8 +16,6 @@ class ImageView extends ScrollView
|
||||
initialize: (imageEditSession) ->
|
||||
super
|
||||
|
||||
requireStylesheet 'image-view'
|
||||
|
||||
@image.load =>
|
||||
@originalHeight = @image.height()
|
||||
@originalWidth = @image.width()
|
||||
3
src/packages/image-view/package.cson
Normal file
3
src/packages/image-view/package.cson
Normal file
@@ -0,0 +1,3 @@
|
||||
'description': 'View images in the editor'
|
||||
'main': './lib/image-edit-session'
|
||||
'deferredDeserializers': ['ImageEditSession']
|
||||
@@ -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 ->
|
||||
Reference in New Issue
Block a user