mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Remove menu code and tests
This commit is contained in:
parent
bce834aea0
commit
ffeaf7ed17
@ -30,38 +30,3 @@ describe "Window", ->
|
||||
|
||||
requireStylesheet('atom.css')
|
||||
expect($('head style').length).toBe 1
|
||||
|
||||
|
||||
xdescribe "bindMenuItem(path, keyPattern, action)", ->
|
||||
it "causes the given menu item to be added to the menu when the window is focused and removed when it is blurred", ->
|
||||
addedPaths = []
|
||||
spyOn(atom.native, 'addMenuItem').andCallFake (path) -> addedPaths.push(path)
|
||||
|
||||
window.bindMenuItem 'Submenu 1 > Item 1'
|
||||
window.bindMenuItem 'Submenu 1 > Item 2'
|
||||
window.bindMenuItem 'Submenu 2 > Item 1'
|
||||
|
||||
expect(atom.native.addMenuItem).not.toHaveBeenCalled()
|
||||
|
||||
$(window).focus()
|
||||
|
||||
expect(atom.native.addMenuItem).toHaveBeenCalled()
|
||||
expect(addedPaths).toContain('Submenu 1 > Item 1')
|
||||
expect(addedPaths).toContain('Submenu 1 > Item 2')
|
||||
expect(addedPaths).toContain('Submenu 2 > Item 1')
|
||||
|
||||
spyOn(atom.native, 'resetMainMenu')
|
||||
|
||||
$(window).blur()
|
||||
|
||||
expect(atom.native.resetMainMenu).toHaveBeenCalled()
|
||||
|
||||
it "causes the given action to be invoked when the menu item is selected", ->
|
||||
handler = jasmine.createSpy('menuItemHandler')
|
||||
window.bindMenuItem 'Submenu > Item', null, handler
|
||||
$(window).focus()
|
||||
|
||||
OSX.NSApp.mainMenu.itemWithTitle('Submenu').submenu.performActionForItemAtIndex(0)
|
||||
|
||||
expect(handler).toHaveBeenCalled()
|
||||
|
||||
|
@ -13,7 +13,6 @@ beforeEach ->
|
||||
window.resetTimeouts()
|
||||
|
||||
afterEach ->
|
||||
(new Native).resetMainMenu()
|
||||
$('#jasmine-content').empty()
|
||||
|
||||
# Use underscore's definition of equality for toEqual assertions
|
||||
|
@ -5,60 +5,3 @@ describe "Native", ->
|
||||
|
||||
beforeEach ->
|
||||
nativeModule = new Native
|
||||
|
||||
xdescribe "addMenuItem(path, keyPattern)", ->
|
||||
mainMenu = null
|
||||
mainMenuItems = null
|
||||
|
||||
beforeEach ->
|
||||
mainMenu = OSX.NSApp.mainMenu
|
||||
mainMenuItems = mainMenu.itemArray
|
||||
|
||||
it "adds the item at the path terminus to the main menu, adding submenus as needed", ->
|
||||
initialMenuCount = mainMenu.itemArray.length
|
||||
|
||||
nativeModule.addMenuItem('Submenu 1 > Item 1')
|
||||
|
||||
expect(mainMenu.itemArray.length).toBe initialMenuCount + 1
|
||||
submenu1 = mainMenu.itemWithTitle('Submenu 1').submenu
|
||||
item1 = submenu1.itemWithTitle('Item 1')
|
||||
expect(item1).toBeDefined()
|
||||
|
||||
nativeModule.addMenuItem('Submenu 1 > Item 2')
|
||||
|
||||
expect(mainMenu.itemArray.length).toBe initialMenuCount + 1
|
||||
expect(submenu1.itemArray.length).toBe 2
|
||||
item1 = submenu1.itemWithTitle('Item 2')
|
||||
expect(item1).toBeDefined()
|
||||
|
||||
nativeModule.addMenuItem('Submenu 2 > Item 1')
|
||||
|
||||
expect(mainMenu.itemArray.length).toBe initialMenuCount + 2
|
||||
expect(submenu1.itemArray.length).toBe 2
|
||||
submenu1 = mainMenu.itemWithTitle('Submenu 2').submenu
|
||||
item1 = submenu1.itemWithTitle('Item 1')
|
||||
expect(item1).toBeDefined()
|
||||
|
||||
xit "adds a key equivalent to menu item when one is given", ->
|
||||
nativeModule.addMenuItem('Submenu 1 > Item 1', "meta-r")
|
||||
|
||||
submenu1 = mainMenu.itemWithTitle('Submenu 1').submenu
|
||||
item1 = submenu1.itemWithTitle('Item 1')
|
||||
|
||||
expect(item1.keyEquivalent.valueOf()).toBe 'r'
|
||||
expect(item1.keyEquivalentModifierMask.valueOf()).toBe OSX.NSCommandKeyMask
|
||||
|
||||
it "does not add a key equivalent to menu item when no pattern is given", ->
|
||||
nativeModule.addMenuItem('Submenu 2 > Item 2')
|
||||
submenu2 = mainMenu.itemWithTitle('Submenu 2').submenu
|
||||
item2 = submenu2.itemWithTitle('Item 2')
|
||||
|
||||
expect(item2.keyEquivalent.valueOf()).toBe 0
|
||||
expect(item2.keyEquivalentModifierMask).toBe 0
|
||||
|
||||
it "does not add the same item twice", ->
|
||||
nativeModule.addMenuItem('Submenu > Item')
|
||||
expect(mainMenu.itemWithTitle('Submenu').submenu.itemArray.length).toBe(1)
|
||||
nativeModule.addMenuItem('Submenu > Item')
|
||||
expect(mainMenu.itemWithTitle('Submenu').submenu.itemArray.length).toBe(1)
|
||||
|
||||
|
@ -10,16 +10,15 @@ RootView = require 'root-view'
|
||||
|
||||
windowAdditions =
|
||||
rootView: null
|
||||
menuItemActions: null
|
||||
keymap: null
|
||||
|
||||
startup: (url) ->
|
||||
@menuItemActions = {}
|
||||
|
||||
@setupKeymap()
|
||||
@attachRootView(url)
|
||||
@registerEventHandlers()
|
||||
@bindMenuItems()
|
||||
|
||||
$(window).on 'close', =>
|
||||
@shutdown()
|
||||
@close()
|
||||
|
||||
$(window).focus()
|
||||
atom.windowOpened this
|
||||
@ -44,27 +43,6 @@ windowAdditions =
|
||||
return if $("head style[path='#{fullPath}']").length
|
||||
$('head').append "<style path='#{fullPath}'>#{content}</style>"
|
||||
|
||||
bindMenuItems: ->
|
||||
# we want to integrate this better with keybindings
|
||||
# @bindMenuItem "File > Save", "meta+s", => @rootView.editor.save()
|
||||
|
||||
bindMenuItem: (path, pattern, action) ->
|
||||
@menuItemActions[path] = {action: action, pattern: pattern}
|
||||
|
||||
registerEventHandlers: ->
|
||||
$(window).on 'close', =>
|
||||
@shutdown()
|
||||
@close()
|
||||
$(window).focus => @registerMenuItems()
|
||||
$(window).blur -> atom.native.resetMainMenu()
|
||||
|
||||
registerMenuItems: ->
|
||||
for path, {pattern} of @menuItemActions
|
||||
atom.native.addMenuItem(path, pattern)
|
||||
|
||||
performActionForMenuItemPath: (path) ->
|
||||
@menuItemActions[path].action()
|
||||
|
||||
showConsole: ->
|
||||
# $atomController.webView.inspector.showConsole true
|
||||
|
||||
@ -75,7 +53,6 @@ for key, value of windowAdditions
|
||||
console.warn "DOMWindow already has a key named `#{key}`" if window[key]
|
||||
window[key] = value
|
||||
|
||||
|
||||
requireStylesheet 'reset.css'
|
||||
requireStylesheet 'atom.css'
|
||||
|
||||
|
@ -35,42 +35,4 @@ class Native
|
||||
atom.native.writeToPasteboard text
|
||||
|
||||
readFromPasteboard: ->
|
||||
atom.native.readFromPasteboard()
|
||||
|
||||
resetMainMenu: (menu) ->
|
||||
# OSX.NSApp.resetMainMenu
|
||||
|
||||
addMenuItem: (itemPath, keyPattern) ->
|
||||
itemPathComponents = itemPath.split /\s*>\s*/
|
||||
submenu = @buildSubmenuPath(OSX.NSApp.mainMenu, itemPathComponents[0..-2])
|
||||
title = _.last(itemPathComponents)
|
||||
unless submenu.itemWithTitle(title)
|
||||
item = OSX.AtomMenuItem.alloc.initWithTitle_itemPath(title, itemPath).autorelease
|
||||
item.setKeyEquivalentModifierMask 0 # Because in Cocoa defaults it to NSCommandKeyMask
|
||||
|
||||
if keyPattern
|
||||
bindingSet = new (require('binding-set'))("*", {})
|
||||
keys = bindingSet.parseKeyPattern keyPattern
|
||||
|
||||
modifierMask = (keys.metaKey and OSX.NSCommandKeyMask ) |
|
||||
(keys.shiftKey and OSX.NSShiftKeyMask) |
|
||||
(keys.altKey and OSX.NSAlternateKeyMask) |
|
||||
(keys.ctrlKey and OSX.NSControlKeyMask)
|
||||
|
||||
item.setKeyEquivalent keys.key
|
||||
item.setKeyEquivalentModifierMask modifierMask
|
||||
submenu.addItem(item)
|
||||
|
||||
buildSubmenuPath: (menu, path) ->
|
||||
return menu if path.length == 0
|
||||
|
||||
first = path[0]
|
||||
unless item = menu.itemWithTitle(first)
|
||||
item = OSX.AtomMenuItem.alloc.initWithTitle_action_keyEquivalent(first, null, "").autorelease
|
||||
menu.addItem(item)
|
||||
unless submenu = item.submenu
|
||||
submenu = OSX.NSMenu.alloc.initWithTitle(first)
|
||||
item.submenu = submenu
|
||||
|
||||
@buildSubmenuPath(submenu, path[1..-1])
|
||||
|
||||
atom.native.readFromPasteboard()
|
Loading…
Reference in New Issue
Block a user