-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWToolbar.m
113 lines (84 loc) · 2.59 KB
/
SWToolbar.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// SWToolbar.m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Samuel Williams on 21/03/06.
// Copyright 2006 Samuel Williams. All rights reserved.
//
#import "SWToolbar.h"
@implementation SWToolbar
- (IBAction) toggle:(id)sender {
[[window toolbar] setVisible:![[window toolbar] isVisible]];
}
- (IBAction) customize:(id)sender {
[[window toolbar] runCustomizationPalette:sender];
}
- (id) toolbarIdentifier {
return nil;
}
- (void) setupToolbar {
toolbar = [[NSToolbar alloc] initWithIdentifier:[self toolbarIdentifier]];
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
}
- (void) addDefaultItems {
[items setValue:self forKey:NSToolbarFlexibleSpaceItemIdentifier];
[items setValue:self forKey:NSToolbarSpaceItemIdentifier];
[items setValue:self forKey:NSToolbarSeparatorItemIdentifier];
}
- (void) finishSetup {
[window setToolbar:toolbar];
}
- (id) init {
if (self = [super init]) {
items = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void) dealloc {
[items release];
[super dealloc];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
return [items objectForKey:itemIdentifier];
}
- (NSArray *) toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar {
return [items allKeys];
}
- (NSArray *) toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar {
NSArray *keys = [items allKeys];
return keys;
}
- (void) toolbarWillAddItem: (NSNotification *) notification {
//NSToolbarItem *addedItem = [[notification userInfo] objectForKey:@"item"];
// set up the item here
}
- (void) toolbarDidRemoveItem:(NSNotification *)notification {
//NSToolbarItem *addedItem = [[notification userInfo] objectForKey:@"item"];
// clear associated info here
}
- (void) addItem: (NSToolbarItem*)item {
[items setValue:item forKey:[item itemIdentifier]];
}
@end
@implementation NSToolbarItem (SWToolbar)
+ (NSToolbarItem*) toolbarItemWithIdentifier: (id)identifier {
return [[[self class] alloc] initWithItemIdentifier:identifier];
}
- (NSToolbarItem*) setName: (id)name andDescription: (id)description {
[self setLabel:name];
[self setPaletteLabel:name];
[self setToolTip:description];
return self;
}
- (NSToolbarItem*) setTarget: (id)target andAction: (SEL)action {
[self setTarget:target];
[self setAction:action];
return self;
}
- (NSToolbarItem*) setImageNamed: (id)name {
[self setImage:[NSImage imageNamed:name]];
return self;
}
@end