mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add initial image viewer
An image session will be opened by project.buildEditSession() for known image extensions. Closes #203
This commit is contained in:
33
src/app/image-edit-session.coffee
Normal file
33
src/app/image-edit-session.coffee
Normal file
@@ -0,0 +1,33 @@
|
||||
fsUtils = require 'fs-utils'
|
||||
|
||||
module.exports=
|
||||
class ImageEditSession
|
||||
registerDeserializer(this)
|
||||
|
||||
@deserialize: (state) ->
|
||||
if fsUtils.exists(state.path)
|
||||
project.buildEditSession(state.path)
|
||||
else
|
||||
console.warn "Could not build edit session for path '#{state.path}' because that file no longer exists"
|
||||
|
||||
constructor: (@path) ->
|
||||
|
||||
serialize: ->
|
||||
deserializer: 'ImageEditSession'
|
||||
path: @path
|
||||
|
||||
getViewClass: ->
|
||||
require 'image-view'
|
||||
|
||||
getTitle: ->
|
||||
if path = @getPath()
|
||||
fsUtils.base(path)
|
||||
else
|
||||
'untitled'
|
||||
|
||||
getUri: -> @path
|
||||
|
||||
getPath: -> @path
|
||||
|
||||
isEqual: (other) ->
|
||||
other instanceof ImageEditSession and @getUri() is other.getUri()
|
||||
43
src/app/image-view.coffee
Normal file
43
src/app/image-view.coffee
Normal file
@@ -0,0 +1,43 @@
|
||||
ScrollView = require 'scroll-view'
|
||||
|
||||
module.exports =
|
||||
class ImageView extends ScrollView
|
||||
@content: ->
|
||||
@div class: 'image-view', tabindex: -1, =>
|
||||
@img outlet: 'image'
|
||||
|
||||
initialize: (imageEditSession) ->
|
||||
requireStylesheet 'image-view'
|
||||
|
||||
@image.load => @updateSize()
|
||||
@setPath(imageEditSession?.getPath())
|
||||
|
||||
afterAttach: (onDom) ->
|
||||
return unless onDom
|
||||
|
||||
if pane = @getPane()
|
||||
@active = @is(pane.activeView)
|
||||
@subscribe pane, 'pane:active-item-changed', (event, item) =>
|
||||
wasActive = @active
|
||||
@active = @is(pane.activeView)
|
||||
@updateSize() if @active and not wasActive
|
||||
|
||||
updateSize: ->
|
||||
return unless @isVisible()
|
||||
|
||||
@image.css
|
||||
'margin-left': -@image.width() / 2
|
||||
'margin-top': -@image.height() / 2
|
||||
@image.show()
|
||||
|
||||
setPath: (path) ->
|
||||
if path?
|
||||
@image.hide().attr('src', path) if @image.attr('src') isnt path
|
||||
else
|
||||
@image.hide()
|
||||
|
||||
setModel: (imageEditSession) ->
|
||||
@setPath(imageEditSession?.getPath())
|
||||
|
||||
getPane: ->
|
||||
@parent('.item-views').parent('.pane').view()
|
||||
@@ -4,6 +4,7 @@ $ = 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'
|
||||
@@ -85,7 +86,10 @@ class Project
|
||||
setSoftWrap: (@softWrap) ->
|
||||
|
||||
buildEditSession: (filePath, editSessionOptions={}) ->
|
||||
@buildEditSessionForBuffer(@bufferForPath(filePath), editSessionOptions)
|
||||
if fsUtils.isImageExtension(fsUtils.extension(filePath))
|
||||
new ImageEditSession(filePath)
|
||||
else
|
||||
@buildEditSessionForBuffer(@bufferForPath(filePath), editSessionOptions)
|
||||
|
||||
buildEditSessionForBuffer: (buffer, editSessionOptions) ->
|
||||
options = _.extend(@defaultEditSessionOptions(), editSessionOptions)
|
||||
|
||||
Reference in New Issue
Block a user