forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFSObjectBrowserToolbarButton.m
183 lines (150 loc) · 4.46 KB
/
FSObjectBrowserToolbarButton.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// FSObjectBrowserToolbarButton.m Copyright (c) 2002-2009 Philippe Mougin.
// This software is open source. See the license.
#import "FSObjectBrowserToolbarButton.h"
#import "FSObjectBrowserView.h"
#import "FSBlock.h"
#import "FSNSString.h"
@implementation FSObjectBrowserToolbarButton
- (FSBlock *)block
{
//[block inspect];
/*if (block == nil)
{
[self configure:self];
return nil;
}
else */
return block;
}
- (void) configure:(id)sender
{
[block inspect];
}
- (id)copyWithZone:(NSZone *)zone
{
FSObjectBrowserToolbarButton *r = [[[self class] alloc] initWithFrame:[self frame]];
[r setSegmentCount:1];
[r setSegmentStyle:NSSegmentStyleTexturedSquare];
//[r setSegmentStyle:NSSegmentStyleCapsule];
[r setWidth:80 forSegment:0];
[[r cell] setTrackingMode:NSSegmentSwitchTrackingMomentary];
[r setAction:[self action]];
[r setTarget:[self target]];
[r setBlock:block];
[r setIdentifier:identifier];
[r setToolbarItem:toolbarItem];
[r setName:[self name]];
return r;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[block release];
[identifier release];
[super dealloc];
}
- (id) initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self)
{
[self setSegmentCount:1];
[self setSegmentStyle:NSSegmentStyleTexturedSquare];
//[self setSegmentStyle:NSSegmentStyleCapsule];
[self setWidth:80 forSegment:0];
[[self cell] setTrackingMode:NSSegmentSwitchTrackingMomentary];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"FSObjectBrowserToolBarButtonUpdated" object:nil];
}
return self;
}
- (NSString *) identifier
{
return identifier;
}
- (void) inspectBlock:(id)sender
{
[[self block] inspect];
}
- (NSString *) name
{
return [self labelForSegment:0];
}
- (void) setBlock:(FSBlock *)theBlock
{
[theBlock retain];
[block release];
block = theBlock;
}
- (void) setIdentifier:(NSString *)theIdentifier
{
[theIdentifier retain];
[identifier release];
identifier = theIdentifier;
}
- (void)setName:(NSString *)name
{
[self setLabel:name forSegment:0];
[[toolbarItem menuFormRepresentation] setTitle:name];
// Note that the toolbar item will not notice this change in the menu promptly.
// But the messages below (setLabel:) will, as a side effect, make the toolbar item update itself and notice this change.
[toolbarItem setLabel:name];
[toolbarItem setPaletteLabel:name];
// not working
//[toolbarItem setMinSize:[[self cell] cellSize]];
[toolbarItem setMinSize:[[self cell] cellSize].width < 85 ? NSMakeSize(85, [self frame].size.height) : [[self cell] cellSize]];
[toolbarItem setMaxSize:([self frame].size.width < 85 ? NSMakeSize(85, [self frame].size.height) : [[self cell] cellSize])];
[[toolbarItem toolbar] validateVisibleItems];
//--------- force the toolBarItem to redisplay itself
/*[self retain];
[toolbarItem setView:nil];
[toolbarItem setView:self];
[self release];*/
//---------
}
- (void)setNameAndNotify:(NSString *)name
{
[self setName:name];
[FSObjectBrowserView saveCustomButtonsSettings];
[[NSNotificationCenter defaultCenter] postNotificationName:@"FSObjectBrowserToolBarButtonUpdated" object:self];
}
- (void) setToolbarItem:(NSToolbarItem *)item
{
toolbarItem = item; // No retain because it would create a cycle.
}
- (void)selectedFromMenuItem:(NSMenuItem *)menuItem
{
[self performClick:self];
}
- (void) takeNameFrom:(id)sender
{
[self setNameAndNotify:[sender stringValue]];
}
-(void)update:(NSNotification *)notification
{
FSObjectBrowserToolbarButton *master = [notification object];
if ([[master identifier] isEqualToString:identifier] && master != self)
{
[self setName:[master name]];
}
}
/*- (void)textDidEndEditing:(NSNotification *)aNotification
{
NSString *title;
NSMenuItem *menuFormRep;
NSText *textObject = [aNotification object];
title = [[textObject string] copy];
[[self cell] endEditing:textObject];
[textObject setString:@""];
[self setTitle:title];
[BigBrowserView setTitle:title forCustomButtonWithIdentifier:identifier];
[toolbarItem setLabel:title];
[toolbarItem setPaletteLabel:title];
menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[menuFormRep setTitle: title];
[menuFormRep setAction:@selector(selectedFromMenuItem:)];
[menuFormRep setTarget:self];
[toolbarItem setMenuFormRepresentation:menuFormRep];
[title release];
[[self cell] setEditable:NO];
}*/
@end