mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Merge pull request #6297 from atom/ks-inline-menus-and-keymaps-in-package-dot-json
Inline core menus/keymaps into app package.json
This commit is contained in:
@@ -3,9 +3,30 @@ CSON = require 'season'
|
||||
fs = require 'fs-plus'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
OtherPlatforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32'].filter (platform) -> platform isnt process.platform
|
||||
|
||||
module.exports = (grunt) ->
|
||||
{spawn, rm} = require('./task-helpers')(grunt)
|
||||
|
||||
getMenu = (appDir) ->
|
||||
menusPath = path.join(appDir, 'menus')
|
||||
menuPath = path.join(menusPath, "#{process.platform}.json")
|
||||
menu = CSON.readFileSync(menuPath) if fs.isFileSync(menuPath)
|
||||
rm menusPath
|
||||
menu
|
||||
|
||||
getKeymaps = (appDir) ->
|
||||
keymapsPath = path.join(appDir, 'keymaps')
|
||||
keymaps = {}
|
||||
for keymapPath in fs.listSync(keymapsPath, ['.json'])
|
||||
name = path.basename(keymapPath, path.extname(keymapPath))
|
||||
continue unless OtherPlatforms.indexOf(name) is -1
|
||||
|
||||
keymap = CSON.readFileSync(keymapPath)
|
||||
keymaps[path.basename(keymapPath)] = keymap
|
||||
rm keymapsPath
|
||||
keymaps
|
||||
|
||||
grunt.registerTask 'compile-packages-slug', 'Add bundled package metadata information to the main package.json file', ->
|
||||
appDir = fs.realpathSync(grunt.config.get('atom.appDir'))
|
||||
|
||||
@@ -50,5 +71,7 @@ module.exports = (grunt) ->
|
||||
|
||||
metadata = grunt.file.readJSON(path.join(appDir, 'package.json'))
|
||||
metadata._atomPackages = packages
|
||||
metadata._atomMenu = getMenu(appDir)
|
||||
metadata._atomKeymaps = getKeymaps(appDir)
|
||||
|
||||
grunt.file.write(path.join(appDir, 'package.json'), JSON.stringify(metadata))
|
||||
|
||||
@@ -8,6 +8,7 @@ Grim = require 'grim'
|
||||
MenuHelpers = require './menu-helpers'
|
||||
{validateSelector} = require './selector-validator'
|
||||
|
||||
platformContextMenu = require('../package.json')?._atomMenu?['context-menu']
|
||||
SpecificityCache = {}
|
||||
|
||||
# Extended: Provides a registry for commands that you'd like to appear in the
|
||||
@@ -49,10 +50,13 @@ class ContextMenuManager
|
||||
atom.keymaps.onDidLoadBundledKeymaps => @loadPlatformItems()
|
||||
|
||||
loadPlatformItems: ->
|
||||
menusDirPath = path.join(@resourcePath, 'menus')
|
||||
platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json'])
|
||||
map = CSON.readFileSync(platformMenuPath)
|
||||
atom.contextMenu.add(map['context-menu'])
|
||||
if platformContextMenu?
|
||||
@add(platformContextMenu)
|
||||
else
|
||||
menusDirPath = path.join(@resourcePath, 'menus')
|
||||
platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json'])
|
||||
map = CSON.readFileSync(platformMenuPath)
|
||||
@add(map['context-menu'])
|
||||
|
||||
# Public: Add context menu items scoped by CSS selectors.
|
||||
#
|
||||
|
||||
@@ -5,11 +5,20 @@ CSON = require 'season'
|
||||
{jQuery} = require 'space-pen'
|
||||
Grim = require 'grim'
|
||||
|
||||
bundledKeymaps = require('../package.json')?._atomKeymaps
|
||||
|
||||
KeymapManager::onDidLoadBundledKeymaps = (callback) ->
|
||||
@emitter.on 'did-load-bundled-keymaps', callback
|
||||
|
||||
KeymapManager::loadBundledKeymaps = ->
|
||||
@loadKeymap(path.join(@resourcePath, 'keymaps'))
|
||||
keymapsPath = path.join(@resourcePath, 'keymaps')
|
||||
if bundledKeymaps?
|
||||
for keymapName, keymap of bundledKeymaps
|
||||
keymapPath = path.join(keymapsPath, keymapName)
|
||||
@add(keymapPath, keymap)
|
||||
else
|
||||
@loadKeymap(keymapsPath)
|
||||
|
||||
@emit 'bundled-keymaps-loaded' if Grim.includeDeprecatedAPIs
|
||||
@emitter.emit 'did-load-bundled-keymaps'
|
||||
|
||||
@@ -51,7 +60,7 @@ KeymapManager::subscribeToFileReadFailure = ->
|
||||
else
|
||||
error.message
|
||||
|
||||
atom.notifications.addError(message, {detail: detail, dismissable: true})
|
||||
atom.notifications.addError(message, {detail, dismissable: true})
|
||||
|
||||
# This enables command handlers registered via jQuery to call
|
||||
# `.abortKeyBinding()` on the `jQuery.Event` object passed to the handler.
|
||||
|
||||
@@ -8,6 +8,8 @@ fs = require 'fs-plus'
|
||||
|
||||
MenuHelpers = require './menu-helpers'
|
||||
|
||||
platformMenu = require('../package.json')?._atomMenu?.menu
|
||||
|
||||
# Extended: Provides a registry for menu items that you'd like to appear in the
|
||||
# application menu.
|
||||
#
|
||||
@@ -144,10 +146,13 @@ class MenuManager
|
||||
@sendToBrowserProcess(@template, keystrokesByCommand)
|
||||
|
||||
loadPlatformItems: ->
|
||||
menusDirPath = path.join(@resourcePath, 'menus')
|
||||
platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json'])
|
||||
{menu} = CSON.readFileSync(platformMenuPath)
|
||||
@add(menu)
|
||||
if platformMenu?
|
||||
@add(platformMenu)
|
||||
else
|
||||
menusDirPath = path.join(@resourcePath, 'menus')
|
||||
platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json'])
|
||||
{menu} = CSON.readFileSync(platformMenuPath)
|
||||
@add(menu)
|
||||
|
||||
# Merges an item in a submenu aware way such that new items are always
|
||||
# appended to the bottom of existing menus where possible.
|
||||
|
||||
@@ -11,10 +11,7 @@ Q = require 'q'
|
||||
ModuleCache = require './module-cache'
|
||||
ScopedProperties = require './scoped-properties'
|
||||
|
||||
try
|
||||
packagesCache = require('../package.json')?._atomPackages ? {}
|
||||
catch error
|
||||
packagesCache = {}
|
||||
packagesCache = require('../package.json')?._atomPackages ? {}
|
||||
|
||||
# Loads and activates a package's main module and resources such as
|
||||
# stylesheets, keymaps, grammar, editor properties, and menus.
|
||||
|
||||
Reference in New Issue
Block a user