Add up/down/confirm event handling

This commit is contained in:
Kevin Sawicki
2013-06-10 12:06:27 -07:00
parent 135a285596
commit 1894901930
2 changed files with 52 additions and 19 deletions

View File

@@ -37,6 +37,13 @@ class ArchiveView extends ScrollView
@tree.append(new FileView(@path, entry))
@tree.show()
@tree.find('.file').view()?.select()
focusSelectedFile: ->
@tree.find('.selected').view()?.focus()
focus: ->
@focusSelectedFile()
setModel: (editSession) ->
@setPath(editSession?.getPath())

View File

@@ -1,4 +1,5 @@
{View} = require 'space-pen'
$ = require 'jquery'
fsUtils = require 'fs-utils'
path = require 'path'
temp = require 'temp'
@@ -7,26 +8,51 @@ archive = require 'ls-archive'
module.exports =
class FileView extends View
@content: (archivePath, entry) ->
@div class: 'entry', =>
@div class: 'entry', tabindex: -1, =>
@span entry.getName(), class: 'file', outlet: 'name'
initialize: (archivePath, entry) ->
@name.addClass('symlink') if entry.isSymbolicLink()
initialize: (@archivePath, @entry) ->
@name.addClass('symlink') if @entry.isSymbolicLink()
@on 'click', =>
@closest('.archive-view').find('.selected').removeClass('selected')
@name.addClass('selected')
archive.readFile archivePath, entry.getPath(), (error, contents) ->
if error?
console.error("Error reading: #{entry.getPath()} from #{archivePath}", error.stack ? error)
else
temp.mkdir 'atom-', (error, tempDirPath) ->
if error?
console.error("Error creating temp directory: #{tempDirPath}", error.stack ? error)
else
tempFilePath = path.join(tempDirPath, path.basename(archivePath), entry.getName())
fsUtils.writeAsync tempFilePath, contents, (error) ->
if error?
console.error("Error writing to #{tempFilePath}", error.stack ? error)
else
rootView.open(tempFilePath)
@select()
@openFile()
@on 'core:confirm', =>
@openFile() if @isSelected()
@on 'core:move-down', =>
if @isSelected()
files = @closest('.archive-view').find('.file')
$(files[files.index(@name) + 1]).view()?.select()
@on 'core:move-up', =>
if @isSelected()
files = @closest('.archive-view').find('.file')
$(files[files.index(@name) - 1]).view()?.select()
isSelected: -> @name.hasClass('selected')
logError: (message, error) ->
console.error(message, error.stack ? error)
openFile: ->
archive.readFile @archivePath, @entry.getPath(), (error, contents) =>
if error?
@logError("Error reading: #{@entry.getPath()} from #{@archivePath}", error)
else
temp.mkdir 'atom-', (error, tempDirPath) =>
if error?
@logError("Error creating temp directory: #{tempDirPath}", error)
else
tempFilePath = path.join(tempDirPath, path.basename(@archivePath), @entry.getName())
fsUtils.writeAsync tempFilePath, contents, (error) ->
if error?
@logError("Error writing to #{tempFilePath}", error)
else
rootView.open(tempFilePath)
select: ->
@closest('.archive-view').find('.selected').view()?.name.removeClass('selected')
@name.addClass('selected')
@focus()