Don't use atom.{themes,menu,contextMenu} global in Package

This commit is contained in:
Antonio Scandurra
2015-10-06 19:07:58 +02:00
committed by Nathan Sobo
parent 7b25af5ad4
commit 4108939201
4 changed files with 19 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ ThemePackage = require '../src/theme-package'
describe "Package", ->
build = (constructor, path) ->
new constructor(path: path, packageManager: atom.packages, config: atom.config, styleManager: atom.styles, notificationManager: atom.notifications, keymapManager: atom.keymaps, commandRegistry: atom.command, grammarRegistry: atom.grammars, inDevMode: atom.inDevMode)
new constructor(path: path, packageManager: atom.packages, config: atom.config, styleManager: atom.styles, notificationManager: atom.notifications, keymapManager: atom.keymaps, commandRegistry: atom.command, grammarRegistry: atom.grammars, themeManager: atom.themes, menuManager: atom.menu, contextMenuManager: atom.contextMenu, inDevMode: atom.inDevMode)
buildPackage = (packagePath) -> build(Package, packagePath)

View File

@@ -163,6 +163,10 @@ class AtomEnvironment extends Model
ContextMenuManager = require './context-menu-manager'
@contextMenu = new ContextMenuManager({resourcePath, devMode, keymapManager: @keymaps})
@packages.setMenuManager(@menu)
@packages.setContextMenuManager(@contextMenu)
@packages.setThemeManager(@themes)
Clipboard = require './clipboard'
@clipboard = new Clipboard()

View File

@@ -46,6 +46,12 @@ class PackageManager
@packageActivators = []
@registerPackageActivator(this, ['atom', 'textmate'])
setContextMenuManager: (@contextMenuManager) ->
setMenuManager: (@menuManager) ->
setThemeManager: (@themeManager) ->
###
Section: Event Subscription
###
@@ -355,7 +361,7 @@ class PackageManager
options = {
path: packagePath, metadata, packageManager: this,
@config, @styleManager, @commandRegistry, @keymapManager, @inDevMode, @notificationManager, @grammarRegistry
@config, @styleManager, @commandRegistry, @keymapManager, @inDevMode, @notificationManager, @grammarRegistry, @themeManager, @menuManager, @contextMenuManager
}
if metadata.theme
pack = new ThemePackage(options)

View File

@@ -29,7 +29,7 @@ class Package
Section: Construction
###
constructor: ({@path, @metadata, @packageManager, @config, @styleManager, @commandRegistry, @keymapManager, @inDevMode, @notificationManager, @grammarRegistry}) ->
constructor: ({@path, @metadata, @packageManager, @config, @styleManager, @commandRegistry, @keymapManager, @inDevMode, @notificationManager, @grammarRegistry, @themeManager, @menuManager, @contextMenuManager}) ->
@emitter = new Emitter
@metadata ?= @packageManager.loadPackageMetadata(@path)
@bundledPackage = @packageManager.isBundledPackagePath(@path)
@@ -161,14 +161,14 @@ class Package
for [menuPath, map] in @menus when map['context-menu']?
try
itemsBySelector = map['context-menu']
@activationDisposables.add(atom.contextMenu.add(itemsBySelector))
@activationDisposables.add(@contextMenuManager.add(itemsBySelector))
catch error
if error.code is 'EBADSELECTOR'
error.message += " in #{menuPath}"
error.stack += "\n at #{menuPath}:1:1"
throw error
@activationDisposables.add(atom.menu.add(map['menu'])) for [menuPath, map] in @menus when map['menu']?
@activationDisposables.add(@menuManager.add(map['menu'])) for [menuPath, map] in @menus when map['menu']?
unless @grammarsActivated
grammar.activate() for grammar in @grammars
@@ -183,7 +183,7 @@ class Package
@keymapDisposables = new CompositeDisposable()
@keymapDisposables.add(@keymapManager.add(keymapPath, map)) for [keymapPath, map] in @keymaps
atom.menu.update()
@menuManager.update()
@keymapActivated = true
@@ -191,7 +191,7 @@ class Package
return if not @keymapActivated
@keymapDisposables?.dispose()
atom.menu.update()
@menuManager.update()
@keymapActivated = false
@@ -244,8 +244,8 @@ class Package
fs.listSync(menusDirPath, ['cson', 'json'])
loadStylesheets: ->
@stylesheets = @getStylesheetPaths().map (stylesheetPath) ->
[stylesheetPath, atom.themes.loadStylesheet(stylesheetPath, true)]
@stylesheets = @getStylesheetPaths().map (stylesheetPath) =>
[stylesheetPath, @themeManager.loadStylesheet(stylesheetPath, true)]
getStylesheetsPath: ->
path.join(@path, 'styles')