diff --git a/build/tasks/compile-packages-slug-task.coffee b/build/tasks/compile-packages-slug-task.coffee index 4e24f948e..613a4a380 100644 --- a/build/tasks/compile-packages-slug-task.coffee +++ b/build/tasks/compile-packages-slug-task.coffee @@ -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)) diff --git a/src/context-menu-manager.coffee b/src/context-menu-manager.coffee index 00b635251..8397da33d 100644 --- a/src/context-menu-manager.coffee +++ b/src/context-menu-manager.coffee @@ -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. # diff --git a/src/keymap-extensions.coffee b/src/keymap-extensions.coffee index 551c6580d..7ffd3d7ef 100644 --- a/src/keymap-extensions.coffee +++ b/src/keymap-extensions.coffee @@ -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. diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 1991cba95..bd42dddb9 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -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. diff --git a/src/package.coffee b/src/package.coffee index dd6701527..74c4f0eb8 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -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.