mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Incorporate Editor into templating framework.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -20,7 +20,7 @@ class Template
|
||||
@toHtml: (attributes) ->
|
||||
(new this).toHtml(attributes)
|
||||
|
||||
build: (attributes) ->
|
||||
build: (attributes={}) ->
|
||||
@builder = new Builder
|
||||
@content(attributes)
|
||||
view = @builder.toFragment()
|
||||
|
||||
Reference in New Issue
Block a user