-
-
Save sebmck/6ea229efa74437c43d00 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 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 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 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 OpenDialog | |
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: -> | |
@window.title = pathFilename @path | |
fs.writeFile @path, @editor.value, (err) -> | |
console.log err | |
os.registerApplication TextEditor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment