forked from erndev/EDSidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEDSidebarAppDelegate.m
79 lines (69 loc) · 3.04 KB
/
EDSidebarAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// EDSidebarAppDelegate.m
// EDSidebar
//
// Created by erndev
// BSD license.
//
#import "EDSidebarAppDelegate.h"
#import "BlackCell.h"
@implementation EDSidebarAppDelegate
@synthesize window;
-(NSImage*)buildSelectionImage
{
// Create the selection image on the fly, instead of loading from a file resource.
NSInteger imageWidth=12, imageHeight=22;
NSImage* destImage = [[NSImage alloc] initWithSize:NSMakeSize(imageWidth,imageHeight)];
[destImage lockFocus];
// Constructing the path
NSBezierPath *triangle = [NSBezierPath bezierPath];
[triangle setLineWidth:1.0];
[triangle moveToPoint:NSMakePoint(imageWidth+1, 0.0)];
[triangle lineToPoint:NSMakePoint( 0, imageHeight/2.0)];
[triangle lineToPoint:NSMakePoint( imageWidth+1, imageHeight)];
[triangle closePath];
[[NSColor controlColor] setFill];
[[NSColor darkGrayColor] setStroke];
[triangle fill];
[triangle stroke];
[destImage unlockFocus];
return destImage;
}
-(void)awakeFromNib
{
// Setup sidebar with default cell (EDSideBarCell)
// Buttons top-aligned. Selection animated
[sideBarDefault setLayoutMode:ECSideBarLayoutTop];
sideBarDefault.animateSelection =YES;
sideBarDefault.sidebarDelegate=self;
NSImage *selImage =[self buildSelectionImage];
[sideBarDefault setSelectionImage:selImage];
[selImage release];
[sideBarDefault addButtonWithTitle:@"Button 1" image:[NSImage imageNamed:@"icon1-white.png"] alternateImage:[NSImage imageNamed:@"icon1-gray.png"]];
[sideBarDefault addButtonWithTitle:@"Button 2" image:[NSImage imageNamed:@"icon1-white.png"] alternateImage:[NSImage imageNamed:@"icon1-gray.png"]];
[sideBarDefault addButtonWithTitle:@"Button 3" image:[NSImage imageNamed:@"icon1-white.png"] alternateImage:[NSImage imageNamed:@"icon1-gray.png"]];
[sideBarDefault selectButtonAtRow:2];
// Setup sidebar with blackCell (BlackCell)
// Buttons centered. Selection is not animated
sideBarBlack.backgroundColor = [NSColor blackColor];
[sideBarBlack setLayoutMode:ECSideBarLayoutCenter];
sideBarBlack.animateSelection =NO;
sideBarBlack.sidebarDelegate=self;
sideBarBlack.cellClass = [BlackCell class];
[sideBarBlack setSelectionImage:[NSImage imageNamed:@"blue.png"]];
[sideBarBlack addButtonWithTitle:@"Btn1" image:[NSImage imageNamed:@"icon1-blue.png"] alternateImage:[NSImage imageNamed:@"icon1-gray.png"]];
[sideBarBlack addButtonWithTitle:@"Btn2" image:[NSImage imageNamed:@"icon1-blue.png"] alternateImage:[NSImage imageNamed:@"icon1-gray.png"]];
[sideBarBlack addButtonWithTitle:@"Btn3" image:[NSImage imageNamed:@"icon1-blue.png"] alternateImage:[NSImage imageNamed:@"icon1-gray.png"]];
[sideBarBlack selectButtonAtRow:0];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
-(void)sideBar:(EDSideBar*)tabBar didSelectButton:(NSInteger)button
{
NSString *str = [NSString stringWithFormat:@"Selected button #%d in %@",
button, [tabBar isEqualTo:sideBarBlack]?@"Right sidebar":@"Left sidebar"];
NSLog(@"Button selected: %d", button );
[textField setStringValue:str];
}
@end