mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
I'm an idiot
This commit is contained in:
57
extensions/tabs/tabs-pane.coffee
Normal file
57
extensions/tabs/tabs-pane.coffee
Normal file
@@ -0,0 +1,57 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
Pane = require 'pane'
|
||||
|
||||
module.exports =
|
||||
class TabsPane extends Pane
|
||||
position: 'top'
|
||||
|
||||
html: $ require 'tabs/tabs.html'
|
||||
|
||||
constructor: ->
|
||||
# Style html
|
||||
@html.parents('.pane').css height: 'inherit'
|
||||
css = $('<style id="tabs-style"></style>').html require 'tabs/tabs.css'
|
||||
$('head').append css
|
||||
|
||||
# click tab
|
||||
tabPane = this
|
||||
$('#tabs ul li').live 'mousedown', ->
|
||||
tabPane.switchToTab this
|
||||
false
|
||||
|
||||
nextTab: ->
|
||||
@switchToTab $('#tabs ul .active').next()
|
||||
|
||||
prevTab: ->
|
||||
@switchToTab $('#tabs ul .active').prev()
|
||||
|
||||
switchToTab: (tab) ->
|
||||
tab = $("#tabs ul li").get(tab - 1) if _.isNumber tab
|
||||
return if tab.length is 0
|
||||
|
||||
$("#tabs ul .active").removeClass("active")
|
||||
$(tab).addClass 'active'
|
||||
window.editor.focusBuffer $(tab).data 'path'
|
||||
|
||||
addTab: (path) ->
|
||||
existing = $("#tabs [data-path='#{path}']")
|
||||
if existing.length
|
||||
return @switchToTab existing
|
||||
|
||||
name = if path then _.last path.split '/' else "untitled"
|
||||
$("#tabs ul .active").removeClass()
|
||||
$("#tabs ul").append """
|
||||
<li data-path='#{path}'><a href='#'>#{name}</a></li>
|
||||
"""
|
||||
$("#tabs ul li:last").addClass 'active'
|
||||
|
||||
removeTab: (path) ->
|
||||
tab = $("#tabs li[data-path='#{path}']")
|
||||
if tab.hasClass("active")
|
||||
nextTab = tab.next()
|
||||
nextTab = tab.prev() if nextTab.length == 0
|
||||
@switchToTab nextTab if nextTab.length != 0
|
||||
|
||||
tab.remove()
|
||||
@@ -26,17 +26,15 @@ class TreePane extends Pane
|
||||
|
||||
if fs.isDirectory path
|
||||
window.x = @tree
|
||||
openedDirs = @tree.getOpenedDirs()
|
||||
if el.hasClass 'open'
|
||||
openedDirs = _.without openedDirs, path
|
||||
@tree.hideDir path
|
||||
el.removeClass 'open'
|
||||
el.children("ul").remove()
|
||||
else
|
||||
openedDirs.push path unless path in openedDirs
|
||||
@tree.showDir path
|
||||
el.addClass 'open'
|
||||
list = @createList path
|
||||
el.append list
|
||||
@tree.setOpenedDirs openedDirs
|
||||
else
|
||||
el.addClass 'active'
|
||||
window.open path
|
||||
@@ -58,14 +56,14 @@ class TreePane extends Pane
|
||||
paths = fs.list root
|
||||
|
||||
list = $('<ul>')
|
||||
console.log @tree.shownDirs()
|
||||
for path in paths
|
||||
filename = path.replace(root, "").substring 1
|
||||
type = if fs.isDirectory path then 'dir' else 'file'
|
||||
encodedPath = encodeURIComponent path
|
||||
listItem = $("<li class='#{type}' data-path='#{encodedPath}'>#{filename}</li>")
|
||||
openedDirs = @tree.getOpenedDirs()
|
||||
|
||||
if path in openedDirs and fs.isDirectory path
|
||||
if path in @tree.shownDirs() and fs.isDirectory path
|
||||
listItem.append @createList path
|
||||
listItem.addClass "open"
|
||||
list.append listItem
|
||||
|
||||
@@ -15,21 +15,23 @@ class Tree extends Extension
|
||||
KeyBinder.load require.resolve "tree/key-bindings.coffee"
|
||||
|
||||
# Remove dirs that no longer exist
|
||||
openedPaths = @getOpenedDirs()
|
||||
for dir in openedPaths when not fs.exists dir
|
||||
openedDirs = _.without openedDirs, path
|
||||
@setOpenedDirs openedDirs
|
||||
@hideDir(dir) for dir in @shownDirs() when not fs.exists dir
|
||||
|
||||
@pane = new TreePane @
|
||||
|
||||
storageNamespace: ->
|
||||
@.constructor.name + ":" + atomController.path
|
||||
|
||||
getOpenedDirs: ->
|
||||
Storage.get @storageNamespace() + ':openedDirs', []
|
||||
|
||||
setOpenedDirs: (value) ->
|
||||
Storage.set @storageNamespace() + ':openedDirs', value
|
||||
|
||||
startup: ->
|
||||
@pane.show()
|
||||
|
||||
shownDirStorageKey: ->
|
||||
@.constructor.name + ":" + atomController.path + ":shownDirs"
|
||||
|
||||
shownDirs: ->
|
||||
Storage.get @shownDirStorageKey(), []
|
||||
|
||||
showDir: (dir) ->
|
||||
dirs = @shownDirs().concat dir
|
||||
Storage.set @shownDirStorageKey(), dirs
|
||||
|
||||
hideDir: (dir) ->
|
||||
dirs = _.without @shownDirs(), dir
|
||||
Storage.set @shownDirStorageKey(), dirs
|
||||
|
||||
Reference in New Issue
Block a user