diff --git a/Atom.xcodeproj/project.pbxproj b/Atom.xcodeproj/project.pbxproj index 1340c765b..5295f0171 100644 --- a/Atom.xcodeproj/project.pbxproj +++ b/Atom.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 047F26021457978C006DC904 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 047F26011457978C006DC904 /* JavaScriptCore.framework */; }; 047F260414579792006DC904 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 047F260314579792006DC904 /* WebKit.framework */; }; 047F260E145883B9006DC904 /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 047F260D145883B9006DC904 /* Icon.icns */; }; + ECBB172814A4F92400ACAAC1 /* AtomMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = ECBB172714A4F92400ACAAC1 /* AtomMenuItem.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -69,6 +70,8 @@ 047F26011457978C006DC904 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 047F260314579792006DC904 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 047F260D145883B9006DC904 /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = ""; }; + ECBB172614A4F92400ACAAC1 /* AtomMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AtomMenuItem.h; path = Classes/AtomMenuItem.h; sourceTree = ""; }; + ECBB172714A4F92400ACAAC1 /* AtomMenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AtomMenuItem.m; path = Classes/AtomMenuItem.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -130,6 +133,8 @@ 043D7E91145795B70078D710 /* AtomApp.m */, 043D7E92145795B70078D710 /* AtomController.h */, 043D7E93145795B70078D710 /* AtomController.m */, + ECBB172614A4F92400ACAAC1 /* AtomMenuItem.h */, + ECBB172714A4F92400ACAAC1 /* AtomMenuItem.m */, 043D7E6B145795B20078D710 /* JSCocoa */, 043D7E79145795B20078D710 /* UKKQueue */, 043D7E52145794990078D710 /* Supporting Files */, @@ -281,6 +286,7 @@ 043D7E8D145795B20078D710 /* UKMainThreadProxy.m in Sources */, 043D7E94145795B70078D710 /* AtomApp.m in Sources */, 043D7E95145795B70078D710 /* AtomController.m in Sources */, + ECBB172814A4F92400ACAAC1 /* AtomMenuItem.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Atom/Classes/AtomApp.h b/Atom/Classes/AtomApp.h index 2afbdcf74..3fc19af8b 100644 --- a/Atom/Classes/AtomApp.h +++ b/Atom/Classes/AtomApp.h @@ -8,5 +8,6 @@ - (void)removeController:(AtomController *)controller; - (IBAction)runSpecs:(id)sender; +- (void)resetMainMenu; @end diff --git a/Atom/Classes/AtomApp.m b/Atom/Classes/AtomApp.m index ade1f7c20..317359eb1 100644 --- a/Atom/Classes/AtomApp.m +++ b/Atom/Classes/AtomApp.m @@ -1,9 +1,11 @@ #import "AtomApp.h" -#import "AtomController.h" -#import "JSCocoa.h" +#import "JSCocoa.h" #import +#import "AtomController.h" +#import "AtomMenuItem.h" + #define ATOM_USER_PATH ([[NSString stringWithString:@"~/.atom/"] stringByStandardizingPath]) #define ATOM_STORAGE_PATH ([ATOM_USER_PATH stringByAppendingPathComponent:@".app-storage"]) @@ -78,4 +80,24 @@ } } +- (void)resetMenu:(NSMenu *)menu { + for (AtomMenuItem *item in menu.itemArray) { + if (![item isKindOfClass:[AtomMenuItem class]]) continue; + + if (item.submenu) { + [self resetMenu:item.submenu]; + if (item.submenu.numberOfItems == 0) { + [menu removeItem:item]; + } + } + else if (!item.global) { + [menu removeItem:item]; + } + } +} + +- (void)resetMainMenu { + [self resetMenu:self.mainMenu]; +} + @end diff --git a/Atom/Classes/AtomMenuItem.h b/Atom/Classes/AtomMenuItem.h new file mode 100644 index 000000000..f7c9b6271 --- /dev/null +++ b/Atom/Classes/AtomMenuItem.h @@ -0,0 +1,7 @@ +#import + +@interface AtomMenuItem : NSMenuItem + +@property BOOL global; + +@end diff --git a/Atom/Classes/AtomMenuItem.m b/Atom/Classes/AtomMenuItem.m new file mode 100644 index 000000000..2aea538f4 --- /dev/null +++ b/Atom/Classes/AtomMenuItem.m @@ -0,0 +1,7 @@ +#import "AtomMenuItem.h" + +@implementation AtomMenuItem + +@synthesize global; + +@end diff --git a/Atom/en.lproj/MainMenu.xib b/Atom/en.lproj/MainMenu.xib index f78d17058..130f561d4 100644 --- a/Atom/en.lproj/MainMenu.xib +++ b/Atom/en.lproj/MainMenu.xib @@ -2,10 +2,10 @@ 1070 - 11C74 + 11B26 1938 - 1138.23 - 567.00 + 1138 + 566.00 com.apple.InterfaceBuilder.CocoaPlugin 1938 @@ -258,15 +258,77 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + AtomMenuItem + + IBUserDefinedRuntimeAttributesPlaceholderName + + IBUserDefinedRuntimeAttributesPlaceholderName + + + + com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.boolean + global + + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + AtomMenuItem + + IBUserDefinedRuntimeAttributesPlaceholderName + + IBUserDefinedRuntimeAttributesPlaceholderName + + + + com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.boolean + global + + + + + com.apple.InterfaceBuilder.CocoaPlugin + AtomMenuItem com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + AtomMenuItem + + IBUserDefinedRuntimeAttributesPlaceholderName + + IBUserDefinedRuntimeAttributesPlaceholderName + + + + com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.boolean + global + + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + AtomMenuItem + + IBUserDefinedRuntimeAttributesPlaceholderName + + IBUserDefinedRuntimeAttributesPlaceholderName + + + + com.apple.InterfaceBuilder.userDefinedRuntimeAttributeType.boolean + global + + + + + com.apple.InterfaceBuilder.CocoaPlugin + AtomMenuItem com.apple.InterfaceBuilder.CocoaPlugin @@ -296,6 +358,14 @@ ./Classes/AtomApp.h + + AtomMenuItem + NSMenuItem + + IBProjectSource + ./Classes/AtomMenuItem.h + + 0 diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 3b3b4a0c7..f9aceeab6 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -1,10 +1,13 @@ $ = require 'jquery' _ = require 'underscore' +Native = require 'native' + +afterEach -> + (new Native).resetMainMenu() window.atom = new (require 'app') window.keydown = (pattern) -> - $(document).trigger @createKeyEvent pattern window.createKeyEvent = (pattern) -> diff --git a/src/stdlib/native.coffee b/src/stdlib/native.coffee index e6ce3257e..fb2afc240 100644 --- a/src/stdlib/native.coffee +++ b/src/stdlib/native.coffee @@ -39,3 +39,7 @@ class Native pb = OSX.NSPasteboard.generalPasteboard pb.declareTypes_owner [OSX.NSStringPboardType], null pb.setString_forType text, OSX.NSStringPboardType + + resetMainMenu: (menu) -> + OSX.NSApp.resetMainMenu +