mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge branch 'snippets' into dev
Conflicts: src/app/package.coffee src/packages/snippets/src/snippets.coffee
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
Range = require 'range'
|
||||
EventEmitter = require 'event-emitter'
|
||||
Subscriber = require 'subscriber'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class AnchorRange
|
||||
@@ -6,11 +9,14 @@ class AnchorRange
|
||||
end: null
|
||||
buffer: null
|
||||
editSession: null # optional
|
||||
destroyed: false
|
||||
|
||||
constructor: (bufferRange, @buffer, @editSession) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
@startAnchor = @buffer.addAnchorAtPosition(bufferRange.start, ignoreChangesStartingOnAnchor: true)
|
||||
@endAnchor = @buffer.addAnchorAtPosition(bufferRange.end)
|
||||
@subscribe @startAnchor, 'destroyed', => @destroy()
|
||||
@subscribe @endAnchor, 'destroyed', => @destroy()
|
||||
|
||||
getBufferRange: ->
|
||||
new Range(@startAnchor.getBufferPosition(), @endAnchor.getBufferPosition())
|
||||
@@ -22,7 +28,14 @@ class AnchorRange
|
||||
@getBufferRange().containsPoint(bufferPosition)
|
||||
|
||||
destroy: ->
|
||||
return if @destroyed
|
||||
@unsubscribe()
|
||||
@startAnchor.destroy()
|
||||
@endAnchor.destroy()
|
||||
@buffer.removeAnchorRange(this)
|
||||
@editSession?.removeAnchorRange(this)
|
||||
@destroyed = true
|
||||
@trigger 'destroyed'
|
||||
|
||||
_.extend(AnchorRange.prototype, EventEmitter)
|
||||
_.extend(AnchorRange.prototype, Subscriber)
|
||||
|
||||
@@ -10,6 +10,7 @@ class Anchor
|
||||
screenPosition: null
|
||||
ignoreChangesStartingOnAnchor: false
|
||||
strong: false
|
||||
destroyed: false
|
||||
|
||||
constructor: (@buffer, options = {}) ->
|
||||
{ @editSession, @ignoreChangesStartingOnAnchor, @strong } = options
|
||||
@@ -81,8 +82,10 @@ class Anchor
|
||||
@setScreenPosition(screenPosition, bufferChange: options.bufferChange, clip: false, assignBufferPosition: false, autoscroll: options.autoscroll)
|
||||
|
||||
destroy: ->
|
||||
return if @destroyed
|
||||
@buffer.removeAnchor(this)
|
||||
@editSession?.removeAnchor(this)
|
||||
@destroyed = true
|
||||
@trigger 'destroyed'
|
||||
|
||||
_.extend(Anchor.prototype, EventEmitter)
|
||||
|
||||
@@ -9,15 +9,18 @@ class AtomPackage extends Package
|
||||
constructor: (@name) ->
|
||||
super
|
||||
@keymapsDirPath = fs.join(@path, 'keymaps')
|
||||
if @requireModule
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
|
||||
load: ->
|
||||
@loadMetadata()
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@name, @module) if @module
|
||||
try
|
||||
if @requireModule
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
@loadMetadata()
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@name, @module) if @module
|
||||
catch e
|
||||
console.warn "Failed to load package named '#{@name}'", e.stack
|
||||
|
||||
loadMetadata: ->
|
||||
if metadataPath = fs.resolveExtension(fs.join(@path, "package"), ['cson', 'json'])
|
||||
|
||||
@@ -12,7 +12,23 @@ _.extend atom,
|
||||
|
||||
pendingBrowserProcessCallbacks: {}
|
||||
|
||||
getAvailablePackages: ->
|
||||
loadPackages: ->
|
||||
pack.load() for pack in @getPackages()
|
||||
|
||||
getPackages: ->
|
||||
@getPackageNames().map (name) -> Package.build(name)
|
||||
|
||||
loadTextMatePackages: ->
|
||||
pack.load() for pack in @getTextMatePackages()
|
||||
|
||||
getTextMatePackages: ->
|
||||
@getPackages().filter (pack) -> pack instanceof TextMatePackage
|
||||
|
||||
loadPackage: (name) ->
|
||||
Package.build(name).load()
|
||||
|
||||
getPackageNames: ->
|
||||
disabledPackages = config.get("core.disabledPackages") ? []
|
||||
allPackageNames = []
|
||||
for packageDirPath in config.packageDirPaths
|
||||
packageNames = fs.list(packageDirPath)
|
||||
@@ -20,17 +36,7 @@ _.extend atom,
|
||||
.map((packagePath) -> fs.base(packagePath))
|
||||
allPackageNames.push(packageNames...)
|
||||
_.unique(allPackageNames)
|
||||
|
||||
getAvailableTextMateBundles: ->
|
||||
@getAvailablePackages().filter (packageName) => TextMatePackage.testName(packageName)
|
||||
|
||||
loadPackages: (packageNames=@getAvailablePackages()) ->
|
||||
disabledPackages = config.get("core.disabledPackages") ? []
|
||||
for packageName in packageNames
|
||||
@loadPackage(packageName) unless _.contains(disabledPackages, packageName)
|
||||
|
||||
loadPackage: (name) ->
|
||||
Package.load(name)
|
||||
.filter (name) -> not _.contains(disabledPackages, name)
|
||||
|
||||
loadThemes: ->
|
||||
themeNames = config.get("core.themes") ? ['IR_Black']
|
||||
|
||||
@@ -2,18 +2,13 @@ fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class Package
|
||||
@load: (name) ->
|
||||
@build: (name) ->
|
||||
AtomPackage = require 'atom-package'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
|
||||
try
|
||||
if TextMatePackage.testName(name)
|
||||
new TextMatePackage(name).load()
|
||||
else
|
||||
new AtomPackage(name).load()
|
||||
catch e
|
||||
console.warn "Failed to load package named '#{name}'", e.stack
|
||||
|
||||
if TextMatePackage.testName(name)
|
||||
new TextMatePackage(name)
|
||||
else
|
||||
new AtomPackage(name)
|
||||
|
||||
name: null
|
||||
path: null
|
||||
@@ -29,10 +24,3 @@ class Package
|
||||
else
|
||||
@requireModule = true
|
||||
@path = fs.directory(@path)
|
||||
|
||||
load: ->
|
||||
for grammar in @getGrammars()
|
||||
syntax.addGrammar(grammar)
|
||||
|
||||
for { selector, properties } in @getScopedProperties()
|
||||
syntax.addProperties(selector, properties)
|
||||
|
||||
@@ -23,6 +23,16 @@ class TextMatePackage extends Package
|
||||
@preferencesPath = fs.join(@path, "Preferences")
|
||||
@syntaxesPath = fs.join(@path, "Syntaxes")
|
||||
|
||||
load: ->
|
||||
try
|
||||
for grammar in @getGrammars()
|
||||
syntax.addGrammar(grammar)
|
||||
|
||||
for { selector, properties } in @getScopedProperties()
|
||||
syntax.addProperties(selector, properties)
|
||||
catch e
|
||||
console.warn "Failed to load package named '#{@name}'", e.stack
|
||||
|
||||
getGrammars: ->
|
||||
return @grammars if @grammars
|
||||
@grammars = []
|
||||
|
||||
Reference in New Issue
Block a user