Skip to content

Instantly share code, notes, and snippets.

@saikat
Created October 28, 2009 20:32
Show Gist options
  • Save saikat/220804 to your computer and use it in GitHub Desktop.
Save saikat/220804 to your computer and use it in GitHub Desktop.
//Menu creation code
- (void)applicationWillFinishLaunching:(CPNotification)aNotification
{
// Create menu bar
var menuBackground = [CPColor
colorWithPatternImage:[[CPImage alloc]
initWithContentsOfFile:"Resources/menubar.png"
size:CGSizeMake(1.0, 29.0)]],
menu = [[CPMenu alloc] initWithTitle:@"Menu"];
[CPMenu setMenuBarAttributes:[CPDictionary dictionaryWithObjects:
[menuBackground,
[CPColor whiteColor],
[CPColor blackColor],
[CPColor whiteColor],
[CPColor colorWithCalibratedRed:115.0/255.0 green:166.0/255.0 blue:217.0/255.0 alpha:1.0]
]
forKeys:[@"CPMenuBarBackgroundColor",
@"CPMenuBarTextShadowColor",
@"CPMenuBarTextColor",
@"CPMenuBarTitleShadowColor",
@"CPMenuBarHighlightColor"]]];
[[CPApplication sharedApplication] setMainMenu:menu];
var bundle = [CPBundle bundleForClass:[CPWindow class]];
menuSpinner = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(16.0, 16.0)];
[CPMenu setMenuBarVisible:YES];
[CPMenu setMenuBarIconImage:[[CPImage alloc]
initWithContentsOfFile:@"Resources/menubar-document-icon.png" size:CPSizeMake(16.0,16.0)]];
// Add menu items
newItem = [menu addItemWithTitle:"New" action:@selector(new) keyEquivalent:"N"];
[newItem setEnabled:YES];
loadItem = [menu addItemWithTitle:"Open" action:@selector(load) keyEquivalent:"O"];
[loadItem setEnabled:YES];
var saveMenu = [[CPMenu alloc] initWithTitle:@"Save"];
saveItem = [[CPMenuItem alloc] initWithTitle:@"Save" action:@selector(save)
keyEquivalent:nil];
[saveItem setEnabled:YES];
[saveMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Save" action:@selector(save)
keyEquivalent:@"S"]];
[saveMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Save As" action:@selector(saveAs)
keyEquivalent:nil]];
[saveItem setSubmenu:saveMenu];
[menu addItem:saveItem];
var editMenu = [[CPMenu alloc] initWithTitle:@"Edit"],
editMenuItem = [[CPMenuItem alloc] initWithTitle:@"Edit" action:nil
keyEquivalent:nil];
[editMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Copy" action:@selector(copyWidget)
keyEquivalent:"C"]];
[editMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Paste" action:@selector(pasteWidget)
keyEquivalent:"V"]];
[editMenuItem setEnabled:YES];
[editMenuItem setSubmenu:editMenu];
[menu addItem:editMenuItem];
[CPPlatformWindow preventCharacterKeysFromPropagating:["S", "O", "N", "D", "C", "V", CPUndoKeyEquivalent, CPRedoKeyEquivalent]];
}
- (void)copyWidget
{
var windowController = [self currentWindowController];
if ([windowController class] === [EditWindowController class]) {
var editLayer = [[windowController editCanvas] editLayer],
selectedWidgets = [editLayer selectedWidgets];
console.log(selectedWidgets);
if ([selectedWidgets count] > 0) {
var pasteboard = [CPPasteboard generalPasteboard];
[pasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:selectedWidgets]
forType:WidgetType];
}
}
}
- (void)pasteWidget
{
var windowController = [self currentWindowController];
if ([windowController class] === [EditWindowController class]) {
var pasteboard = [CPPasteboard generalPasteboard],
widgets = [CPKeyedUnarchiver unarchiveObjectWithData:
[pasteboard dataForType:WidgetType]];
console.log(widgets);
[[windowController editCanvas] addAndSelectMultipleWidgets:widgets];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment