-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCPToolbar.j
More file actions
69 lines (60 loc) · 2.26 KB
/
CPToolbar.j
File metadata and controls
69 lines (60 loc) · 2.26 KB
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
// (c) 2010-2011 by Anton Korenyushkin
@implementation CPToolbar (Utils)
- (void)reloadChangedToolbarItems // public
{
var newItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self];
for (var fromIndex = 0;; ++fromIndex) {
if (fromIndex == _itemIdentifiers.length || fromIndex == newItemIdentifiers.length)
return;
if (_itemIdentifiers[fromIndex] != newItemIdentifiers[fromIndex])
break;
}
for (var shift = 0;; ++shift)
if (_itemIdentifiers[_itemIdentifiers.length - 1 - shift] != newItemIdentifiers[newItemIdentifiers.length - 1 - shift])
break;
var args = [fromIndex, _itemIdentifiers.length - fromIndex - shift];
var toIndex = newItemIdentifiers.length - shift;
for (var i = fromIndex; i < toIndex; ++i) {
var identifier = newItemIdentifiers[i];
args.push([CPToolbarItem _standardItemWithItemIdentifier:identifier] ||
[_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES]);
}
Array.prototype.splice.apply(_items, args);
_itemsSortedByVisibilityPriority = _items;
_itemIdentifiers = newItemIdentifiers;
[_toolbarView reloadToolbarItemsFrom:fromIndex to:toIndex];
}
@end
@implementation _CPToolbarView (Utils)
- (void)reloadToolbarItemsFrom:(unsigned)fromIndex to:(unsigned)toIndex // public
{
var items = [_toolbar items];
var oldUIDs = {};
for (var i = 0; i < fromIndex; ++i)
oldUIDs[[items[i] UID]] = true;
for (var i = toIndex; i < items.length; ++i)
oldUIDs[[items[i] UID]] = true;
for (var uid in _viewsForToolbarItems) {
if (!oldUIDs.hasOwnProperty(uid)) {
var view = _viewsForToolbarItems[uid];
_minWidth -= [view minSize].width + 10;
[view removeFromSuperview];
delete _viewsForToolbarItems[uid];
}
}
for (var i = fromIndex; i < toIndex; ++i) {
var item = items[i];
var view = [[_CPToolbarItemView alloc] initWithToolbarItem:item toolbar:self];
_viewsForToolbarItems[[item UID]] = view;
[self addSubview:view];
_minWidth += [view minSize].width + 10;
}
[self tile];
}
@end
@implementation CPToolbarItem (Hack)
- (id)copy // public
{
return self;
}
@end