mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
tabs
This commit is contained in:
parent
9e21d8da04
commit
c67917efa3
@ -1,48 +0,0 @@
|
||||
$ = require 'jquery'
|
||||
|
||||
Extension = require 'extension'
|
||||
File = require 'fs'
|
||||
TabsPane = require 'tabs/tabspane'
|
||||
|
||||
module.exports =
|
||||
class Tabs extends Extension
|
||||
# The Editor pane we're managing.
|
||||
editor: null
|
||||
|
||||
keymap: ->
|
||||
'Command-W': 'closeActiveTab'
|
||||
'Command-Shift-[': 'prevTab'
|
||||
'Command-Shift-]': 'nextTab'
|
||||
'Command-1': -> @pane.switchToTab 1
|
||||
'Command-2': -> @pane.switchToTab 2
|
||||
'Command-3': -> @pane.switchToTab 3
|
||||
'Command-4': -> @pane.switchToTab 4
|
||||
'Command-5': -> @pane.switchToTab 5
|
||||
'Command-6': -> @pane.switchToTab 6
|
||||
'Command-7': -> @pane.switchToTab 7
|
||||
'Command-8': -> @pane.switchToTab 8
|
||||
'Command-9': -> @pane.switchToTab 9
|
||||
|
||||
constructor: (args...) ->
|
||||
super args...
|
||||
|
||||
@pane = new TabsPane @window, @
|
||||
@pane.toggle()
|
||||
|
||||
@window.on 'open', ({filename}) =>
|
||||
return if File.isDirectory filename # Ignore directories
|
||||
@pane.addTab filename
|
||||
|
||||
@window.on 'close', ({filename}) =>
|
||||
@pane.removeTab filename
|
||||
|
||||
# Move all of this methods below to pane? I think so
|
||||
closeActiveTab: ->
|
||||
activeTab = $('#tabs ul .active')
|
||||
@window.close activeTab.data 'path'
|
||||
|
||||
nextTab: ->
|
||||
@pane.switchToTab $('#tabs ul .active').next()
|
||||
|
||||
prevTab: ->
|
||||
@switchToTab $('#tabs ul .active').prev()
|
14
extensions/tabs/key-bindings.coffee
Normal file
14
extensions/tabs/key-bindings.coffee
Normal file
@ -0,0 +1,14 @@
|
||||
tabs:
|
||||
'cmd-w': (tabs) -> tabs.pane.closeActiveTab()
|
||||
'cmd-shift-[': (tabs) -> tabs.pane.prevTab()
|
||||
'cmd-shift-]': (tabs) -> tabs.pane.nextTab()
|
||||
'cmd-1': (tabs) -> tabs.pane.switchToTab 1
|
||||
'cmd-2': (tabs) -> tabs.pane.switchToTab 2
|
||||
'cmd-3': (tabs) -> tabs.pane.switchToTab 3
|
||||
'cmd-4': (tabs) -> tabs.pane.switchToTab 4
|
||||
'cmd-5': (tabs) -> tabs.pane.switchToTab 5
|
||||
'cmd-6': (tabs) -> tabs.pane.switchToTab 6
|
||||
'cmd-7': (tabs) -> tabs.pane.switchToTab 7
|
||||
'cmd-8': (tabs) -> tabs.pane.switchToTab 8
|
||||
'cmd-9': (tabs) -> tabs.pane.switchToTab 9
|
||||
|
28
extensions/tabs/tabs.coffee
Normal file
28
extensions/tabs/tabs.coffee
Normal file
@ -0,0 +1,28 @@
|
||||
$ = require 'jquery'
|
||||
|
||||
Extension = require 'extension'
|
||||
KeyBinder = require 'key-binder'
|
||||
Event = require 'event'
|
||||
TabsPane = require 'tabs/tabspane'
|
||||
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class Tabs extends Extension
|
||||
constructor: () ->
|
||||
KeyBinder.register "tabs", @
|
||||
KeyBinder.load require.resolve "tabs/key-bindings.coffee"
|
||||
|
||||
@pane = new TabsPane @
|
||||
|
||||
Event.on 'window:open', (e) =>
|
||||
path = e.details
|
||||
return if fs.isDirectory path # Ignore directories
|
||||
@pane.addTab path
|
||||
|
||||
Event.on 'editor:close', (e) =>
|
||||
path = e.details
|
||||
@pane.removeTab path
|
||||
|
||||
startup: ->
|
||||
@pane.show()
|
@ -2,7 +2,6 @@ $ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
Pane = require 'pane'
|
||||
File = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class TabsPane extends Pane
|
||||
@ -10,9 +9,7 @@ class TabsPane extends Pane
|
||||
|
||||
html: $ require 'tabs/tabs.html'
|
||||
|
||||
constructor: (@window, @tabs) ->
|
||||
super @window
|
||||
|
||||
constructor: ->
|
||||
# Style html
|
||||
@html.parents('.pane').css height: 'inherit'
|
||||
css = $('<style id="tabs-style"></style>').html require 'tabs/tabs.css'
|
||||
@ -20,17 +17,27 @@ class TabsPane extends Pane
|
||||
|
||||
# click tab
|
||||
tabPane = this
|
||||
$('#tabs ul li').live 'click', ->
|
||||
$('#tabs ul li').live 'mousedown', ->
|
||||
tabPane.switchToTab this
|
||||
false
|
||||
|
||||
closeActiveTab: ->
|
||||
activeTab = $('#tabs ul .active')
|
||||
window.editor.close activeTab.data 'path'
|
||||
|
||||
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.open $(tab).data 'path'
|
||||
window.editor.open $(tab).data 'path'
|
||||
|
||||
addTab: (path) ->
|
||||
existing = $("#tabs [data-path='#{path}']")
|
@ -64,7 +64,9 @@ class Editor
|
||||
@ace.getSession().setMode new mode
|
||||
|
||||
open: (path) ->
|
||||
if not path or fs.isDirectory path
|
||||
return if fs.isDirectory path
|
||||
|
||||
if not path
|
||||
@activePath = null
|
||||
@ace.setSession @newSession()
|
||||
else
|
||||
@ -85,7 +87,7 @@ class Editor
|
||||
|
||||
# ICK, clean this up... too many assumptions being made
|
||||
session = @sessions[path]
|
||||
if not session or session.$atom_dirty
|
||||
if session?.$atom_dirty or (not session and @code.length > 0)
|
||||
detailedMessage = if @activePath
|
||||
"#{@activePath} has changes."
|
||||
else
|
||||
|
@ -13,6 +13,7 @@ class Event
|
||||
window.document.removeEventListener name, callback
|
||||
|
||||
@trigger: (name, data, bubbleToApp=true) ->
|
||||
console.log name
|
||||
if bubbleToApp and name.match /^app:/
|
||||
OSX.NSApp.triggerGlobalEvent_data name, data
|
||||
return
|
||||
|
@ -1,18 +1,12 @@
|
||||
KeyBinder = require 'key-binder'
|
||||
App = require 'app'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class Extension
|
||||
constructor: ->
|
||||
console.log "#{@.constructor.name}: Loaded"
|
||||
register @identifier(), @
|
||||
console.log "#{@constructor.name}: Loaded"
|
||||
|
||||
# Unique key for the extension. Used in key bindings and settings.
|
||||
identifier: ->
|
||||
throw "#{@constructor.name}: You have to supply a unique identifier to extensions"
|
||||
|
||||
storageNamespace: -> "storage-#{@identifier()}"
|
||||
storageNamespace: -> @constructor.name
|
||||
|
||||
startup: ->
|
||||
|
||||
|
@ -57,7 +57,11 @@ class KeyBinder
|
||||
return false if not callbacks
|
||||
|
||||
# Only use the most recently added binding
|
||||
_.last(callbacks)()
|
||||
try
|
||||
_.last(callbacks)()
|
||||
catch e
|
||||
console.warn "Failed to run binding #{binding}. #{e}"
|
||||
|
||||
true
|
||||
|
||||
@bindingParser: (binding) ->
|
||||
|
@ -30,10 +30,16 @@ class Pane
|
||||
else
|
||||
throw "I DON'T KNOW HOW TO DEAL WITH #{@position}"
|
||||
|
||||
show: ->
|
||||
@add this
|
||||
@showing = true
|
||||
|
||||
hide: ->
|
||||
@html.parent().detach()
|
||||
@showing = false
|
||||
|
||||
toggle: ->
|
||||
if @showing
|
||||
@html.parent().detach()
|
||||
@hide()
|
||||
else
|
||||
@add this
|
||||
|
||||
@showing = not @showing
|
||||
@show()
|
||||
|
@ -1,4 +1,5 @@
|
||||
resourcePath = OSX.NSBundle.mainBundle.resourcePath
|
||||
#resourcePath = OSX.NSBundle.mainBundle.resourcePath
|
||||
resourcePath = "/Users/corey/code/mine/Atomicity"
|
||||
|
||||
paths = [
|
||||
"#{resourcePath}/src"
|
||||
|
@ -1,4 +1,5 @@
|
||||
Editor = require 'editor'
|
||||
Extension = require 'extension'
|
||||
Event = require 'event'
|
||||
KeyBinder = require 'key-binder'
|
||||
Native = require 'native'
|
||||
@ -15,13 +16,13 @@ windowAdditions =
|
||||
appRoot: OSX.NSBundle.mainBundle.resourcePath
|
||||
|
||||
startup: () ->
|
||||
KeyBinder.register "window", window
|
||||
|
||||
if atomController.path
|
||||
@setRecentPath atomController.path
|
||||
else
|
||||
atomController.path = @recentPath()
|
||||
|
||||
KeyBinder.register "window", window
|
||||
|
||||
@editor = if atomController.path and fs.isFile atomController.path
|
||||
new Editor atomController.path
|
||||
else
|
||||
@ -32,7 +33,6 @@ windowAdditions =
|
||||
|
||||
Event.on "editor:open", (e) =>
|
||||
path = e.details
|
||||
console.log path
|
||||
basename = fs.base path
|
||||
@setTitle basename
|
||||
|
||||
@ -47,7 +47,7 @@ windowAdditions =
|
||||
for extensionPath in extensionPaths when fs.isDirectory extensionPath
|
||||
try
|
||||
extension = require extensionPath
|
||||
extensions.push new Extension()
|
||||
extensions.push new extension()
|
||||
catch error
|
||||
console.warn "window: Loading Extension #{fs.base extensionPath} failed."
|
||||
console.warn error
|
||||
@ -100,8 +100,6 @@ windowAdditions =
|
||||
parent = atomController.path.replace(/([^\/])$/, "$1/")
|
||||
child = path.replace(/([^\/])$/, "$1/")
|
||||
|
||||
console.log parent
|
||||
console.log child
|
||||
window.x = parent
|
||||
window.y = child
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user