mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
it remembers what buffers a window has open
This commit is contained in:
parent
9a596734ff
commit
fe734a1b11
@ -17,7 +17,10 @@ class Tabs extends Extension
|
||||
|
||||
Event.on 'editor:bufferAdd', (e) =>
|
||||
path = e.details
|
||||
return if fs.isDirectory path # Ignore directories
|
||||
@pane.addTab path
|
||||
|
||||
Event.on 'editor:bufferFocus', (e) =>
|
||||
path = e.details
|
||||
@pane.addTab path
|
||||
|
||||
Event.on 'editor:bufferRemove', (e) =>
|
||||
|
@ -18,11 +18,6 @@ class Editor
|
||||
constructor: (path) ->
|
||||
KeyBinder.register "editor", @
|
||||
|
||||
# Resize editor when panes are added/removed
|
||||
el = document.body
|
||||
el.addEventListener 'DOMNodeInsertedIntoDocument', => @resize()
|
||||
el.addEventListener 'DOMNodeRemovedFromDocument', => @resize()
|
||||
|
||||
@ace = ace.edit "ace-editor"
|
||||
|
||||
# This stuff should all be grabbed from the .atomicity dir
|
||||
@ -37,6 +32,11 @@ class Editor
|
||||
|
||||
@addBuffer path
|
||||
|
||||
# Resize editor when panes are added/removed
|
||||
el = document.body
|
||||
el.addEventListener 'DOMNodeInsertedIntoDocument', => @resize()
|
||||
el.addEventListener 'DOMNodeRemovedFromDocument', => @resize()
|
||||
|
||||
modeMap:
|
||||
js: 'javascript'
|
||||
c: 'c_cpp'
|
||||
@ -119,6 +119,8 @@ class Editor
|
||||
@ace.setSession new EditSession ''
|
||||
|
||||
focusBuffer: (path) ->
|
||||
return if @activePath == path
|
||||
|
||||
@activePath = path
|
||||
|
||||
buffer = @buffers[path] or @addBuffer path
|
||||
|
@ -13,7 +13,6 @@ 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
|
||||
|
16
src/storage.coffee
Normal file
16
src/storage.coffee
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports =
|
||||
class Storage
|
||||
@get: (key, defaultValue) ->
|
||||
try
|
||||
object = JSON.parse(localStorage[key] ? "{}")
|
||||
catch error
|
||||
error.message += "\nGetting #{key}"
|
||||
console.error(error)
|
||||
|
||||
object ? defaultValue
|
||||
|
||||
@set: (key, value) ->
|
||||
if value == undefined
|
||||
delete localStorage[key]
|
||||
else
|
||||
localStorage[key] = JSON.stringify(value.valueOf())
|
@ -3,6 +3,7 @@ Extension = require 'extension'
|
||||
Event = require 'event'
|
||||
KeyBinder = require 'key-binder'
|
||||
Native = require 'native'
|
||||
Storage = require 'storage'
|
||||
|
||||
fs = require 'fs'
|
||||
|
||||
@ -31,6 +32,37 @@ windowAdditions =
|
||||
@loadExtensions()
|
||||
@loadKeyBindings()
|
||||
|
||||
@restoreEditorState()
|
||||
|
||||
storageKey: ->
|
||||
"project:" + atomController.path
|
||||
|
||||
restoreEditorState: ->
|
||||
storage = Storage.get @storageKey(), {}
|
||||
@editor.addBuffer path for path in storage.openPaths ? []
|
||||
@editor.focusBuffer storage.lastOpenedPath
|
||||
|
||||
# Remember what buffers were open and closed
|
||||
Event.on "editor:bufferFocus", (e) =>
|
||||
path = e.details
|
||||
storage = Storage.get @storageKey(), {}
|
||||
storage.lastOpenedPath = path.valueOf()
|
||||
Storage.set @storageKey(), storage
|
||||
|
||||
Event.on "editor:bufferAdd", (e) =>
|
||||
path = e.details
|
||||
storage = Storage.get @storageKey(), {}
|
||||
storage.openPaths ?= []
|
||||
unless path.valueOf() in storage.openPaths
|
||||
storage.openPaths.push path.valueOf()
|
||||
Storage.set @storageKey(), storage
|
||||
|
||||
Event.on "editor:bufferRemove", (e) =>
|
||||
path = e.details
|
||||
storage = Storage.get @storageKey(), {}
|
||||
storage.openPaths = (p for p in storage.openPaths when p != path)
|
||||
Storage.set @storageKey(), storage
|
||||
|
||||
loadExtensions: ->
|
||||
extension.shutdown() for extension in @extensions
|
||||
@extensions = []
|
||||
@ -69,7 +101,7 @@ windowAdditions =
|
||||
atomController.window.title = title
|
||||
|
||||
reload: ->
|
||||
@close()
|
||||
atomController.close
|
||||
Native.newWindow atomController.path
|
||||
|
||||
open: (path) ->
|
||||
@ -93,9 +125,6 @@ windowAdditions =
|
||||
parent = atomController.path.replace(/([^\/])$/, "$1/")
|
||||
child = path.replace(/([^\/])$/, "$1/")
|
||||
|
||||
window.x = parent
|
||||
window.y = child
|
||||
|
||||
# If the child is contained by the parent, it can be opened by this window
|
||||
return child.match "^" + parent
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user