Merge remote-tracking branch 'origin/master' into cj-make-packages-async

This commit is contained in:
probablycorey
2013-10-14 15:54:22 -07:00
48 changed files with 350 additions and 777 deletions

View File

@@ -28,26 +28,28 @@ class AtomPackage extends Package
getType: -> 'atom'
load: ->
@metadata = {}
@stylesheets = []
@keymaps = []
@menus = []
@grammars = []
@scopedProperties = []
@measure 'loadTime', =>
try
@metadata = Package.loadMetadata(@path)
if @isTheme()
@stylesheets = []
@keymaps = []
@menus = []
@grammars = []
@scopedProperties = []
else
@loadKeymaps()
@loadMenus()
@loadStylesheets()
@loadGrammars()
@loadScopedProperties()
return if @isTheme()
if @metadata.activationEvents?
@registerDeferredDeserializers()
else
@requireMainModule()
@loadKeymaps()
@loadMenus()
@loadStylesheets()
@loadGrammars()
@loadScopedProperties()
if @metadata.activationEvents?
@registerDeferredDeserializers()
else
@requireMainModule()
catch e
console.warn "Failed to load package named '#{@name}'", e.stack ? e

View File

@@ -24,7 +24,8 @@ class ApplicationMenu
# An Object where the keys are commands and the values are Arrays containing
# the keystrokes.
update: (template, keystrokesByCommand) ->
@translateTemplate template, keystrokesByCommand
@translateTemplate(template, keystrokesByCommand)
@substituteVersion(template)
@menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(@menu)
@@ -34,11 +35,24 @@ class ApplicationMenu
# A complete menu configuration object for atom-shell's menu API.
#
# Returns an Array of native menu items.
allItems: (menu=@menu) ->
flattenMenuItems: (menu) ->
items = []
for index, item of menu.items or {}
items.push(item)
items = items.concat(@allItems(item.submenu)) if item.submenu
items = items.concat(@flattenMenuItems(item.submenu)) if item.submenu
items
# Private: Flattens the given menu template into an single Array.
#
# * template:
# An object describing the menu item.
#
# Returns an Array of native menu items.
flattenMenuTemplate: (template) ->
items = []
for item in template
items.push(item)
items = items.concat(@flattenMenuTemplate(item.submenu)) if item.submenu
items
# Public: Used to make all window related menu items are active.
@@ -47,9 +61,14 @@ class ApplicationMenu
# If true enables all window specific items, if false disables all window
# specific items.
enableWindowSpecificItems: (enable) ->
for item in @allItems()
for item in @flattenMenuItems(@menu)
item.enabled = enable if item.metadata?['windowSpecific']
# Private: Replaces VERSION with the current version.
substituteVersion: (template) ->
if (item = _.find(@flattenMenuTemplate(template), (i) -> i.label == 'VERSION'))
item.label = "Version #{@version}"
# Public: Makes the download menu item visible if available.
#
# Note: The update menu item's must match 'Install update' exactly otherwise
@@ -60,10 +79,9 @@ class ApplicationMenu
# * quitAndUpdateCallback:
# Function to call when the install menu item has been clicked.
showDownloadUpdateItem: (newVersion, quitAndUpdateCallback) ->
downloadUpdateItem = _.find @allItems(), (item) -> item.label == 'Install update'
if downloadUpdateItem
downloadUpdateItem.visible = true
downloadUpdateItem.click = quitAndUpdateCallback
if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Install update'))
item.visible = true
item.click = quitAndUpdateCallback
# Private: Default list of menu items.
#

View File

@@ -1,6 +1,6 @@
AtomWindow = require 'atom-window'
ApplicationMenu = require 'application-menu'
AtomProtocolHandler = require 'atom-protocol-handler'
AtomWindow = require './atom-window'
ApplicationMenu = require './application-menu'
AtomProtocolHandler = require './atom-protocol-handler'
Menu = require 'menu'
autoUpdater = require 'auto-updater'
app = require 'app'
@@ -251,7 +251,7 @@ class AtomApplication
bootstrapScript = require.resolve(path.join(global.devResourcePath, 'src', 'window-bootstrap'))
else
resourcePath = @resourcePath
bootstrapScript = require.resolve('./window-bootstrap')
bootstrapScript = require.resolve('../window-bootstrap')
openedWindow = new AtomWindow({pathToOpen, initialLine, bootstrapScript, resourcePath, devMode, initialSize})
if pidToKillWhenClosed?
@@ -279,8 +279,8 @@ class AtomApplication
# Boolean to control the opened window's dev mode.
openUrl: ({urlToOpen, devMode}) ->
unless @packages?
PackageManager = require './package-manager'
fsUtils = require './fs-utils'
PackageManager = require '../package-manager'
fsUtils = require '../fs-utils'
@packages = new PackageManager
configDirPath: fsUtils.absolute('~/.atom')
devMode: devMode
@@ -314,7 +314,7 @@ class AtomApplication
try
bootstrapScript = require.resolve(path.resolve(global.devResourcePath, 'spec', 'spec-bootstrap'))
catch error
bootstrapScript = require.resolve(path.resolve(__dirname, '..', 'spec', 'spec-bootstrap'))
bootstrapScript = require.resolve(path.resolve(__dirname, '..', '..', 'spec', 'spec-bootstrap'))
isSpec = true
devMode = true
@@ -324,9 +324,9 @@ class AtomApplication
try
bootstrapScript = require.resolve(path.resolve(global.devResourcePath, 'benchmark', 'benchmark-bootstrap'))
catch error
bootstrapScript = require.resolve(path.resolve(__dirname, '..', 'benchmark', 'benchmark-bootstrap'))
bootstrapScript = require.resolve(path.resolve(__dirname, '..', '..', 'benchmark', 'benchmark-bootstrap'))
isSpec = true # Needed because this flag adds the spec directory to the NODE_PATH
isSpec = true
new AtomWindow({bootstrapScript, @resourcePath, isSpec})
# Private: Opens a native dialog to prompt the user for a path.

View File

@@ -1,7 +1,6 @@
BrowserWindow = require 'browser-window'
Menu = require 'menu'
MenuItem = require 'menu-item'
ContextMenu = require 'context-menu'
ContextMenu = require './context-menu'
dialog = require 'dialog'
ipc = require 'ipc'
path = require 'path'
@@ -84,7 +83,7 @@ class AtomWindow
when 1 then @browserWindow.restart()
@browserWindow.on 'context-menu', (menuTemplate) =>
new ContextMenu(menuTemplate)
new ContextMenu(menuTemplate, @browserWindow)
if @isSpec
# Spec window's web view should always have focus

View File

@@ -1,12 +1,11 @@
Menu = require 'menu'
BrowserWindow = require 'browser-window'
module.exports =
class ContextMenu
constructor: (template) ->
constructor: (template, browserWindow) ->
template = @createClickHandlers(template)
menu = Menu.buildFromTemplate(template)
menu.popup(BrowserWindow.getFocusedWindow())
menu.popup(browserWindow)
# Private: It's necessary to build the event handlers in this process, otherwise
# closures are drug across processes and failed to be garbage collected

View File

@@ -14,6 +14,10 @@ dialog = require 'dialog'
console.log = (args...) ->
nslog(args.map((arg) -> JSON.stringify(arg)).join(" "))
process.on 'uncaughtException', (error={}) ->
nslog(error.message) if error.message?
nslog(error.stack) if error.stack?
delegate.browserMainParts.preMainMessageLoopRun = ->
args = parseCommandLine()
@@ -47,12 +51,9 @@ delegate.browserMainParts.preMainMessageLoopRun = ->
require('coffee-script')
if args.devMode
require(path.join(args.resourcePath, 'src', 'coffee-cache')).register()
module.globalPaths.push(path.join(args.resourcePath, 'src'))
AtomApplication = require path.join(args.resourcePath, 'src', 'browser', 'atom-application')
else
appSrcPath = path.resolve(process.argv[0], "../../Resources/app/src")
module.globalPaths.push(appSrcPath)
AtomApplication = require 'atom-application'
AtomApplication = require './atom-application'
AtomApplication.open(args)
console.log("App load time: #{new Date().getTime() - startTime}ms")
@@ -112,6 +113,6 @@ parseCommandLine = ->
fs.statSync resourcePath
catch e
devMode = false
resourcePath = path.dirname(__dirname)
resourcePath = path.dirname(path.dirname(__dirname))
{resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, newWindow, specDirectory}

View File

@@ -66,8 +66,9 @@ class PackageManager
if packagePath = @resolvePackagePath(name)
return pack if pack = @getLoadedPackage(name)
pack = Package.load(packagePath, options)
if pack.metadata.theme
if pack.metadata?.theme
atom.themes.register(pack)
else
@loadedPackages[pack.name] = pack

View File

@@ -4,7 +4,6 @@ url = require 'url'
Q = require 'q'
_ = require './underscore-extensions'
$ = require './jquery-extensions'
telepath = require 'telepath'
{Range} = telepath
TextBuffer = require './text-buffer'
@@ -132,19 +131,6 @@ class Project
getRootDirectory: ->
@rootDirectory
# Public: Fetches the name of every file (that's not `git ignore`d) in the
# project.
#
# Returns an {Array} of {String}s.
getFilePaths: ->
deferred = $.Deferred()
paths = []
onFile = (path) => paths.push(path) unless @isPathIgnored(path)
onDirectory = -> true
fsUtils.traverseTreeSync(@getPath(), onFile, onDirectory)
deferred.resolve(paths)
deferred.promise()
# Public: Determines if a path is ignored via Atom configuration.
isPathIgnored: (path) ->
for segment in path.split("/")
@@ -316,7 +302,7 @@ class Project
iterator = options
options = {}
deferred = $.Deferred()
deferred = Q.defer()
searchOptions =
ignoreCase: regex.ignoreCase
@@ -335,7 +321,7 @@ class Project
task.on 'scan:paths-searched', (numberOfPathsSearched) ->
options.onPathsSearched(numberOfPathsSearched)
deferred
deferred.promise
# Private:
buildEditSessionForBuffer: (buffer, editSessionOptions) ->