Plugin does a lot of things we thought Pane would.

This commit is contained in:
Corey Johnson 2011-09-21 17:38:14 -07:00
parent 012fc4826d
commit 620538a6b5
2 changed files with 36 additions and 42 deletions

View File

@ -6,52 +6,17 @@ class Pane
html: null
keymap: ->
showing: false
constructor: (options={}) ->
for option, value of options
@[option] = value
for shortcut, method of @keymap()
bindKey @, shortcut, method
@initialize options
get: (key, defaultValue) ->
try
object = JSON.parse(localStorage[@storageNamespace()] ? "{}")
catch error
error.message += "\nGetting #{key}"
console.log(error)
object[key] ? defaultValue
set: (key, value) ->
try
object = JSON.parse(localStorage[@storageNamespace()] ? "{}")
catch error
error.message += "\nSetting #{key}: #{value}"
console.log(error)
# Putting data in
if value == undefined
delete object[key]
else
object[key] = value
localStorage[@storageNamespace()] = JSON.stringify(object)
constructor: (@window) ->
toggle: ->
if @showing
@html.parent().detach()
else
# This require should be at the top of the file, BUT it doesn't work.
# Would like to figure out why.
{activeWindow} = require 'app'
activeWindow.addPane this
@window.addPane this
@showing = not @showing
# Override these in your subclass
initialize: ->
storageNamespace: -> @.constructor.name

View File

@ -1,11 +1,40 @@
{bindKey} = require 'keybinder'
module.exports =
class Plugin
constructor: (@window) ->
console.log "Loaded Plugin: " + @.constructor.name
# Called after the window is fully loaded
initialize: ->
for shortcut, method of @keymap()
bindKey @, shortcut, method
pane: ->
keymap: ->
storageNamespace: -> @.constructor.name
get: (key, defaultValue) ->
try
object = JSON.parse(localStorage[@storageNamespace()] ? "{}")
catch error
error.message += "\nGetting #{key}"
console.log(error)
object[key] ? defaultValue
set: (key, value) ->
try
object = JSON.parse(localStorage[@storageNamespace()] ? "{}")
catch error
error.message += "\nSetting #{key}: #{value}"
console.log(error)
# Putting data in
if value == undefined
delete object[key]
else
object[key] = value
localStorage[@storageNamespace()] = JSON.stringify(object)
# Called when @window is closed
destroy: ->