Merge remote-tracking branch 'origin/master' into vim-core-changes

Conflicts:
	src/app/pane.coffee
This commit is contained in:
Mutwin Kraus
2013-04-09 18:52:36 +02:00
34 changed files with 571 additions and 85 deletions

View File

@@ -156,6 +156,7 @@ class EditSession
saveAs: (path) -> @buffer.saveAs(path)
getFileExtension: -> @buffer.getExtension()
getPath: -> @buffer.getPath()
getBuffer: -> @buffer
getUri: -> @getPath()
isBufferRowBlank: (bufferRow) -> @buffer.isRowBlank(bufferRow)
nextNonBlankBufferRow: (bufferRow) -> @buffer.nextNonBlankRow(bufferRow)
@@ -167,7 +168,7 @@ class EditSession
scanInBufferRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInBufferRange: (args...) -> @buffer.backwardsScanInRange(args...)
isModified: -> @buffer.isModified()
hasEditors: -> @buffer.hasEditors()
shouldPromptToSave: -> @isModified() and not @buffer.hasMultipleEditors()
screenPositionForBufferPosition: (bufferPosition, options) -> @displayBuffer.screenPositionForBufferPosition(bufferPosition, options)
bufferPositionForScreenPosition: (screenPosition, options) -> @displayBuffer.bufferPositionForScreenPosition(screenPosition, options)

View File

@@ -442,6 +442,13 @@ class Editor extends View
@subscribe $(window), "resize.editor-#{@id}", => @requestDisplayUpdate()
@focus() if @isFocused
if pane = @getPane()
@active = @is(pane.activeView)
@subscribe pane, 'pane:active-item-changed', (event, item) =>
wasActive = @active
@active = @is(pane.activeView)
@redraw() if @active and not wasActive
@resetDisplay()
@trigger 'editor:attached', [this]
@@ -771,6 +778,7 @@ class Editor extends View
requestDisplayUpdate: ->
return if @pendingDisplayUpdate
return unless @isVisible()
@pendingDisplayUpdate = true
_.nextTick =>
@updateDisplay()
@@ -779,6 +787,10 @@ class Editor extends View
updateDisplay: (options={}) ->
return unless @attached and @activeEditSession
return if @activeEditSession.destroyed
unless @isVisible()
@redrawOnReattach = true
return
@updateRenderedLines()
@highlightCursorLine()
@updateCursorViews()
@@ -916,9 +928,8 @@ class Editor extends View
if intactRanges.length == 0
@renderedLines.empty()
else
else if currentLine = renderedLines.firstChild
domPosition = 0
currentLine = renderedLines.firstChild
for intactRange in intactRanges
while intactRange.domStart > domPosition
currentLine = killLine(currentLine)
@@ -1079,7 +1090,7 @@ class Editor extends View
@pixelPositionForScreenPosition(@screenPositionForBufferPosition(position))
pixelPositionForScreenPosition: (position) ->
return { top: 0, left: 0 } unless @isOnDom()
return { top: 0, left: 0 } unless @isOnDom() and @isVisible()
{row, column} = Point.fromObject(position)
actualRow = Math.floor(row)

View File

@@ -0,0 +1,42 @@
fsUtils = require 'fs-utils'
_ = require 'underscore'
module.exports=
class ImageEditSession
registerDeserializer(this)
@canOpen: (path) ->
_.indexOf([
'.gif'
'.jpeg'
'.jpg'
'.png'
], fsUtils.extension(path), true) >= 0
@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()

80
src/app/image-view.coffee Normal file
View File

@@ -0,0 +1,80 @@
ScrollView = require 'scroll-view'
_ = require 'underscore'
$ = require 'jquery'
module.exports =
class ImageView extends ScrollView
@content: ->
@div class: 'image-view', tabindex: -1, =>
@img outlet: 'image'
initialize: (imageEditSession) ->
super
requireStylesheet 'image-view'
@image.load =>
@originalHeight = @image.height()
@originalWidth = @image.width()
@loaded = true
@centerImage()
@setPath(imageEditSession?.getPath())
@subscribe $(window), 'resize', _.debounce((=> @centerImage()), 300)
@command 'image-view:zoom-in', => @zoomIn()
@command 'image-view:zoom-out', => @zoomOut()
@command 'image-view:reset-zoom', => @resetZoom()
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)
@centerImage() if @active and not wasActive
centerImage: ->
return unless @loaded and @isVisible()
@image.css
'top': Math.max((@height() - @image.outerHeight()) / 2, 0)
'left': Math.max((@width() - @image.outerWidth()) / 2, 0)
@image.show()
setPath: (path) ->
if path?
if @image.attr('src') isnt path
@loaded = false
@image.hide().attr('src', path)
else
@image.hide()
setModel: (imageEditSession) ->
@setPath(imageEditSession?.getPath())
getPane: ->
@parent('.item-views').parent('.pane').view()
adjustSize: (factor) ->
return unless @loaded and @isVisible()
newWidth = @image.width() * factor
newHeight = @image.height() * factor
@image.width(newWidth)
@image.height(newHeight)
@centerImage()
zoomOut: ->
@adjustSize(0.9)
zoomIn: ->
@adjustSize(1.1)
resetZoom: ->
return unless @loaded and @isVisible()
@image.width(@originalWidth)
@image.height(@originalHeight)
@centerImage()

View File

@@ -35,3 +35,9 @@
'.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-0': 'image-view:reset-zoom'

View File

@@ -55,7 +55,9 @@ class PaneContainer extends View
activePane.showItem(deserialize(lastItemState))
true
else
@append(new Pane(deserialize(lastItemState)))
newPane = new Pane(deserialize(lastItemState))
@append(newPane)
newPane.focus()
itemDestroyed: (item) ->
state = item.serialize?()

View File

@@ -58,7 +58,7 @@ class Pane extends View
return if @attached
@attached = true
@trigger 'pane:attached'
@trigger 'pane:attached', [this]
makeActive: ->
for pane in @getContainer().getPanes() when pane isnt this
@@ -148,7 +148,7 @@ class Pane extends View
@autosaveItem(item)
if promptToSave && item.isModified?()
if item.shouldPromptToSave?()
@promptToSaveItem(item, reallyDestroyItem)
else
reallyDestroyItem()
@@ -214,7 +214,9 @@ class Pane extends View
@trigger 'pane:item-moved', [item, newIndex]
moveItemToPane: (item, pane, index) ->
@isMovingItem = true
@removeItem(item)
@isMovingItem = false
pane.addItem(item, index)
itemForUri: (uri) ->
@@ -235,8 +237,12 @@ class Pane extends View
delete @viewsByClassName[viewClass.name]
if @items.length > 0
viewToRemove?.remove()
if @isMovingItem and item is viewToRemove
viewToRemove?.detach()
else
viewToRemove?.remove()
else
viewToRemove?.detach() if @isMovingItem and item is viewToRemove
@remove()
viewForItem: (item) ->

View File

@@ -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 ImageEditSession.canOpen(filePath)
new ImageEditSession(filePath)
else
@buildEditSessionForBuffer(@bufferForPath(filePath), editSessionOptions)
buildEditSessionForBuffer: (buffer, editSessionOptions) ->
options = _.extend(@defaultEditSessionOptions(), editSessionOptions)

View File

@@ -162,6 +162,10 @@ class RootView extends View
indexOfPane: (pane) ->
@panes.indexOfPane(pane)
eachPane: (callback) ->
callback(pane) for pane in @getPanes()
@on 'pane:attached', (e, pane) -> callback(pane)
eachEditor: (callback) ->
callback(editor) for editor in @getEditors()
@on 'editor:attached', (e, editor) -> callback(editor)

View File

@@ -142,6 +142,7 @@ class SelectList extends View
cancelled: ->
@miniEditor.setText('')
@miniEditor.updateDisplay()
cancel: ->
@list.empty()

View File

@@ -70,7 +70,7 @@ class Buffer
path: @getPath()
text: @getText() if @isModified()
hasEditors: -> @refcount > 1
hasMultipleEditors: -> @refcount > 1
subscribeToFile: ->
@file.on "contents-changed", =>

View File

@@ -25,12 +25,6 @@ window.setUpEnvironment = ->
$(document).on 'keydown', keymap.handleKeyEvent
keymap.bindDefaultKeys()
ignoreEvents = (e) ->
e.preventDefault()
e.stopPropagation()
$(document).on 'dragover', ignoreEvents
$(document).on 'drop', ignoreEvents
requireStylesheet 'reset'
requireStylesheet 'atom'
requireStylesheet 'overlay'
@@ -50,6 +44,7 @@ window.startup = ->
console.warn "Failed to install `atom` binary"
handleWindowEvents()
handleDragDrop()
config.load()
keymap.loadBundledKeymaps()
atom.loadThemes()
@@ -93,6 +88,18 @@ window.handleWindowEvents = ->
$(window).command 'window:close', => confirmClose()
$(window).command 'window:reload', => reload()
window.handleDragDrop = ->
$(document).on 'dragover', (e) ->
e.preventDefault()
e.stopPropagation()
$(document).on 'drop', onDrop
window.onDrop = (e) ->
e.preventDefault()
e.stopPropagation()
for file in e.originalEvent.dataTransfer.files
atom.open(file.path)
window.deserializeWindowState = ->
RootView = require 'root-view'
Project = require 'project'