Incorporate Editor into templating framework.

This commit is contained in:
Corey Johnson & Nathan Sobo
2011-12-29 13:12:13 -06:00
parent 0285c3d94d
commit 35e4b0e969
5 changed files with 45 additions and 50 deletions

View File

@@ -1,42 +1,46 @@
Template = require 'template'
Buffer = require 'buffer'
{EditSession} = require 'ace/edit_session'
ace = require 'ace/ace'
$ = require 'jquery'
module.exports =
class Editor
aceEditor: null
buffer: null
editorElement: null
class Editor extends Template
content: ->
@div class: 'editor'
constructor: (url) ->
@buildAceEditor()
@open(url)
viewProperties:
aceEditor: null
buffer: null
editorElement: null
shutdown: ->
@destroy()
initialize: ({url}) ->
@buildAceEditor()
@open(url)
destroy: ->
@aceEditor.destroy()
shutdown: ->
@destroy()
open: (url) ->
$atomController.url = url
@buffer = new Buffer(url)
session = new EditSession(@buffer.aceDocument, @buffer.getMode())
@aceEditor.setSession(session)
destroy: ->
@aceEditor.destroy()
buildAceEditor: ->
@editorElement = $("<div class='editor'>").appendTo('#main')
@aceEditor = ace.edit @editorElement[0]
@aceEditor.setTheme(require "ace/theme/twilight")
open: (url) ->
$atomController.url = url
@buffer = new Buffer(url)
session = new EditSession(@buffer.aceDocument, @buffer.getMode())
@aceEditor.setSession(session)
getAceSession: ->
@aceEditor.getSession()
buildAceEditor: ->
@aceEditor = ace.edit this[0]
@aceEditor.setTheme(require "ace/theme/twilight")
save: ->
if @buffer.url
@buffer.save()
else if url = atom.native.savePanel()
@buffer.url = url
@buffer.save()
getAceSession: ->
@aceEditor.getSession()
save: ->
if @buffer.url
@buffer.save()
else if url = atom.native.savePanel()
@buffer.url = url
@buffer.save()

View File

@@ -15,12 +15,10 @@ class RootView extends Template
@link rel: 'stylesheet', href: "#{require.resolve('atom.css')}?#{(new Date).getTime()}"
@div id: 'app-horizontal', =>
@div id: 'app-vertical', outlet: 'vertical', =>
@div id: 'main', outlet: 'main'
@div id: 'main', outlet: 'main', =>
@subview 'editor', Editor.build(url: $atomController.url?.toString())
viewProperties:
initialize: ->
@editor = new Editor $atomController.url?.toString()
addPane: (view) ->
pane = $('<div class="pane">')
pane.append(view)

View File

@@ -20,7 +20,7 @@ class Template
@toHtml: (attributes) ->
(new this).toHtml(attributes)
build: (attributes) ->
build: (attributes={}) ->
@builder = new Builder
@content(attributes)
view = @builder.toFragment()