Support built-in context menu items

This commit is contained in:
Ivan Zuzak
2014-08-27 13:54:55 +02:00
parent cd3bd048fd
commit 096255f283
3 changed files with 15 additions and 3 deletions

View File

@@ -6,7 +6,8 @@ describe "ContextMenuManager", ->
[contextMenu] = []
beforeEach ->
contextMenu = new ContextMenuManager
resourcePath = atom.getLoadSettings().resourcePath
contextMenu = new ContextMenuManager({resourcePath})
describe "adding definitions", ->
it 'loads', ->

View File

@@ -159,7 +159,7 @@ class Atom extends Model
@keymap = @keymaps # Deprecated
@packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode})
@themes = new ThemeManager({packageManager: @packages, configDirPath, resourcePath, safeMode})
@contextMenu = new ContextMenuManager(devMode)
@contextMenu = new ContextMenuManager({resourcePath, devMode})
@menu = new MenuManager({resourcePath})
@clipboard = new Clipboard()

View File

@@ -1,6 +1,9 @@
{$} = require './space-pen-extensions'
_ = require 'underscore-plus'
remote = require 'remote'
path = require 'path'
CSON = require 'season'
fs = require 'fs-plus'
# Public: Provides a registry for commands that you'd like to appear in the
# context menu.
@@ -9,7 +12,7 @@ remote = require 'remote'
# global.
module.exports =
class ContextMenuManager
constructor: (@devMode=false) ->
constructor: ({@resourcePath, @devMode}) ->
@definitions = {}
@devModeDefinitions = {}
@activeElement = null
@@ -21,6 +24,14 @@ class ContextMenuManager
@commandOptions = x: e.pageX, y: e.pageY
]
atom.keymaps.on 'bundled-keymaps-loaded', => @loadPlatformItems()
loadPlatformItems: ->
menusDirPath = path.join(@resourcePath, 'menus')
platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json'])
map = CSON.readFileSync(platformMenuPath)
atom.contextMenu.add(platformMenuPath, map['context-menu'])
# Public: Creates menu definitions from the object specified by the menu
# cson API.
#