mirror of
https://github.com/atom/atom.git
synced 2026-02-15 17:15:24 -05:00
Clearing the mini editor when closing is something all sub-classes were already doing so it makes sense to pull it up to the base class as the default cancelled() implementation that can still be overridden if needed.
51 lines
1.1 KiB
CoffeeScript
51 lines
1.1 KiB
CoffeeScript
SelectList = require 'select-list'
|
|
{$$} = require 'space-pen'
|
|
|
|
module.exports =
|
|
class GrammarView extends SelectList
|
|
|
|
@viewClass: -> "#{super} grammar-view"
|
|
|
|
filterKey: 'name'
|
|
|
|
initialize: (@editor) ->
|
|
@currentGrammar = @editor.getGrammar()
|
|
@path = @editor.getPath()
|
|
@autoDetect = name: 'Auto Detect'
|
|
requireStylesheet 'grammar-view.css'
|
|
@command 'editor:select-grammar', =>
|
|
@cancel()
|
|
false
|
|
super
|
|
|
|
@populate()
|
|
@attach()
|
|
|
|
itemForElement: (grammar) ->
|
|
if grammar is @currentGrammar
|
|
grammarClass = 'current-grammar'
|
|
else
|
|
grammarClass = 'grammar'
|
|
|
|
$$ ->
|
|
@li grammar.name, class: grammarClass
|
|
|
|
populate: ->
|
|
grammars = new Array(syntax.grammars...)
|
|
grammars.unshift(@autoDetect)
|
|
@setArray(grammars)
|
|
|
|
confirmed: (grammar) ->
|
|
@cancel()
|
|
if grammar is @autoDetect
|
|
rootView.project.removeGrammarOverrideForPath(@path)
|
|
else
|
|
rootView.project.addGrammarOverrideForPath(@path, grammar)
|
|
@editor.reloadGrammar()
|
|
|
|
attach: ->
|
|
super
|
|
|
|
@editor.rootView()?.append(this)
|
|
@miniEditor.focus()
|