Skip to content

Instantly share code, notes, and snippets.

@sebmck
Created July 1, 2012 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmck/2e641e7476c7222bf2aa to your computer and use it in GitHub Desktop.
Save sebmck/2e641e7476c7222bf2aa to your computer and use it in GitHub Desktop.
class TextEditor extends OS.Application
options:
name: 'Text Editor'
alias: 'texteditor'
icon:
small: '/images/icons/16/document-text.png'
medium: '/images/icons/24/document-text.png'
large: '/images/icons/32/document-text.png'
accept: ['txt', 'js', 'coffee', 'html', 'css']
init: (path) ->
@window = new @Window
width: 800
height: 400
@window.layout = 'border'
@registerWindow @window
@toolbar = new @Control.Toolbar
@toolbar.preferredHeight = 32
open = new @toolbar.Item 'Open'
open.on 'click', => do @openFile
save = new @toolbar.Item 'Save'
save.on 'click', => do @saveFile
@toolbar.add open
@toolbar.add save
@window.add @toolbar, 'top'
@ace = new @Control.Ace
@ace.preferredHeight = 0
@window.add @ace, 'bottom'
do @ace.init
@ace.theme = 'tomorrow_night'
@loadFile path if path
@ace.on 'change', =>
@window.title = "#{pathFilename @path} •"
openFile: ->
dialog = new @Control.OpenDialog
@registerWindow dialog.window
dialog.on 'open', (path) => @loadFile path
loadFile: (@path) ->
@ace.extension = pathExtension @path
fs.readFile @path, 'utf8', (err, data) =>
@ace.value = data
@window.title = pathFilename @path
saveFile: ->
fs.writeFile @path, @editor.value, (err) =>
@window.title = pathFilename @path
os.registerApplication TextEditor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment