mirror of
https://github.com/atom/atom.git
synced 2026-02-10 06:35:00 -05:00
Can move files from the tree view
This commit is contained in:
@@ -5,7 +5,10 @@ EventEmitter = require 'event-emitter'
|
||||
|
||||
module.exports =
|
||||
class Directory
|
||||
@idCounter = 0
|
||||
|
||||
constructor: (@path) ->
|
||||
@id = ++Directory.idCounter
|
||||
|
||||
getName: ->
|
||||
fs.base(@path) + '/'
|
||||
|
||||
@@ -4,3 +4,5 @@ window.keymap.bindKeys '.tree-view'
|
||||
'enter': 'tree-view:open-selected-entry'
|
||||
'm': 'tree-view:move'
|
||||
|
||||
window.keymap.bindKeys '.move-dialog .mini.editor'
|
||||
'enter': 'tree-view:confirm'
|
||||
|
||||
@@ -29,8 +29,7 @@ class TreeView extends View
|
||||
@rootView.on 'active-editor-path-change', => @selectActiveFile()
|
||||
|
||||
deactivate: ->
|
||||
@find('.expanded.directory').each ->
|
||||
$(this).view().unwatchEntries()
|
||||
@root.unwatchEntries()
|
||||
|
||||
selectActiveFile: ->
|
||||
activeFilePath = @rootView.activeEditor()?.buffer.path
|
||||
@@ -96,6 +95,7 @@ class DirectoryView extends View
|
||||
@disclosureArrow.on 'click', => @toggleExpansion()
|
||||
|
||||
buildEntries: ->
|
||||
@unwatchDescendantEntries()
|
||||
@entries?.remove()
|
||||
@entries = $$ -> @ol class: 'entries'
|
||||
for entry in @directory.getEntries()
|
||||
@@ -123,7 +123,6 @@ class DirectoryView extends View
|
||||
@removeClass('expanded')
|
||||
@disclosureArrow.text('▸')
|
||||
@unwatchEntries()
|
||||
@find('.expanded.directory').each -> $(this).view().unwatchEntries()
|
||||
@entries.remove()
|
||||
@entries = null
|
||||
@isExpanded = false
|
||||
@@ -133,8 +132,13 @@ class DirectoryView extends View
|
||||
@buildEntries()
|
||||
|
||||
unwatchEntries: ->
|
||||
@unwatchDescendantEntries()
|
||||
@directory.off ".#{@directory.path}"
|
||||
|
||||
unwatchDescendantEntries: ->
|
||||
@find('.expanded.directory').each ->
|
||||
$(this).view().unwatchEntries()
|
||||
|
||||
serializeEntryExpansionStates: ->
|
||||
entryStates = {}
|
||||
@entries.find('> .directory.expanded').each ->
|
||||
@@ -156,12 +160,17 @@ class MoveDialog extends View
|
||||
@div class: 'move-dialog', =>
|
||||
@subview 'editor', new Editor(mini: true)
|
||||
|
||||
initialize: (@project, path) ->
|
||||
initialize: (@project, @path) ->
|
||||
@editor.focus()
|
||||
@editor.on 'focusout', => @remove()
|
||||
@on 'tree-view:confirm', => @confirm()
|
||||
|
||||
relativePath = @project.relativize(path)
|
||||
relativePath = @project.relativize(@path)
|
||||
@editor.setText(relativePath)
|
||||
baseName = fs.base(path)
|
||||
range = [[0, relativePath.length - baseName.length], [0, relativePath.length]]
|
||||
@editor.setSelectionBufferRange(range)
|
||||
|
||||
confirm: ->
|
||||
fs.move(@path, @project.resolve(@editor.getText()))
|
||||
@remove()
|
||||
|
||||
@@ -53,6 +53,9 @@ module.exports =
|
||||
listTree: (path) ->
|
||||
$native.list(path, true)
|
||||
|
||||
move: (source, target) ->
|
||||
$native.move(source, target)
|
||||
|
||||
# Remove a file at the given path. Throws an error if path is not a
|
||||
# file or a symbolic link to a file.
|
||||
remove: (path) ->
|
||||
|
||||
Reference in New Issue
Block a user