-
-
Save sebmck/2e641e7476c7222bf2aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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