This repository has been archived by the owner on Sep 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
AppDelegate+Toolbar.m
151 lines (137 loc) · 6.94 KB
/
AppDelegate+Toolbar.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
//
// CocoaSlideShow+Toolbar.m
// CocoaSlideShow
//
// Created by Nicolas Seriot on 04.05.08.
// Copyright 2008 Sen:te. All rights reserved.
//
#import "AppDelegate+Toolbar.h"
#define kAlwaysSelected 0
#define kSelectedIfAtLeastOneImageSelected 1
#define kSelectedIfAtLeastOneGPSImageSelected 2
#define kSelectedIfGPSOrCanGoBackToImage 3
@implementation AppDelegate (Toolbar)
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
if ([itemIdentifier isEqualToString:@"setDirectory"]) {
[item setLabel:NSLocalizedString(@"Set Directory…", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Set Directory…", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Set Directory…", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"folder.png"]];
[item setTag:kAlwaysSelected];
[item setTarget:self];
[item setAction:@selector(setDirectory:)];
} else if ([itemIdentifier isEqualToString:@"addFiles"]) {
[item setLabel:NSLocalizedString(@"Add Files…", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Add Files…", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Add Files…", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"add.png"]];
[item setTag:kAlwaysSelected];
[item setTarget:self];
[item setAction:@selector(addDirectory:)];
} else if ([itemIdentifier isEqualToString:@"flag"]) {
[item setLabel:NSLocalizedString(@"Flag", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Flag", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Flag", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"flag.png"]];
[item setTag:kSelectedIfAtLeastOneImageSelected];
[item setTarget:self];
[item setAction:@selector(toggleFlags:)];
} else if ([itemIdentifier isEqualToString:@"fullScreen"]) {
[item setLabel:NSLocalizedString(@"Full Screen", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Full Screen", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Full Screen", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"fullscreen.png"]];
[item setTag:kAlwaysSelected];
[item setTarget:self];
[item setAction:@selector(fullScreenMode:)];
} else if ([itemIdentifier isEqualToString:@"slideShow"]) {
[item setLabel:NSLocalizedString(@"Slideshow", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Slideshow", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Slideshow", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"slideshow.png"]];
[item setTag:kAlwaysSelected];
[item setTarget:self];
[item setAction:@selector(startSlideShow:)];
} else if ([itemIdentifier isEqualToString:@"rotateLeft"]) {
[item setLabel:NSLocalizedString(@"Rotate Left", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Rotate Left", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Rotate Left", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"left.png"]];
[item setTag:kSelectedIfAtLeastOneImageSelected];
[item setTarget:self];
[item setAction:@selector(rotateLeft:)];
} else if ([itemIdentifier isEqualToString:@"rotateRight"]) {
[item setLabel:NSLocalizedString(@"Rotate Right", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Rotate Right", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Rotate Right", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"right.png"]];
[item setTag:kSelectedIfAtLeastOneImageSelected];
[item setTarget:self];
[item setAction:@selector(rotateRight:)];
} else if ([itemIdentifier isEqualToString:@"remove"]) {
[item setLabel:NSLocalizedString(@"Remove", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Remove", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Remove", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"remove.png"]];
[item setTag:kSelectedIfAtLeastOneImageSelected];
[item setTarget:self];
[item setAction:@selector(remove:)];
} else if ([itemIdentifier isEqualToString:@"trash"]) {
[item setLabel:NSLocalizedString(@"Move to Trash", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Trash", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Trash", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"trash.png"]];
[item setTag:kSelectedIfAtLeastOneImageSelected];
[item setTarget:self];
[item setAction:@selector(moveToTrash:)];
} else if ([itemIdentifier isEqualToString:@"gmap"]) {
[item setLabel:NSLocalizedString(@"Map", @"Toolbar item")];
[item setPaletteLabel:NSLocalizedString(@"Map", @"Toolbar customize")];
[item setToolTip:NSLocalizedString(@"Map", @"Toolbar tooltip")];
[item setImage:[NSImage imageNamed:@"gmap.png"]];
[item setTag:kSelectedIfGPSOrCanGoBackToImage];
[item setTarget:self];
[item setAction:@selector(toggleMap:)];
}
return item;
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar {
return [NSArray arrayWithObjects:@"setDirectory", @"addFiles",
NSToolbarSeparatorItemIdentifier, @"flag", @"fullScreen", @"slideShow", @"gmap", @"rotateLeft", @"rotateRight", @"remove",
NSToolbarFlexibleSpaceItemIdentifier, @"trash", nil];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar {
NSArray *standardItems = [NSArray arrayWithObjects:NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier, nil];
NSArray *moreItems = [NSArray array];
return [[[self toolbarDefaultItemIdentifiers:nil] arrayByAddingObjectsFromArray:standardItems] arrayByAddingObjectsFromArray:moreItems];
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem {
//NSLog(@"-- %@", [theItem label]);
if([theItem tag] == kAlwaysSelected) {
return YES;
} else if ([theItem tag] == kSelectedIfAtLeastOneImageSelected) {
return [[imagesController selectedObjects] count] > 0;
} else if ([theItem tag] == kSelectedIfAtLeastOneGPSImageSelected) {
return [imagesController atLeastOneImageWithGPSSelected];
} else if ([theItem tag] == kSelectedIfGPSOrCanGoBackToImage) {
return [(AppDelegate *)[NSApp delegate] isMap] || [imagesController atLeastOneImageWithGPSSelected];
}
return NO;
}
- (void)toggleFlags:(id)sender {
[imagesController toggleFlags:sender];
}
- (void)remove:(id)sender {
[imagesController remove:sender];
}
- (void)moveToTrash:(id)sender {
[imagesController moveToTrash:sender];
}
- (void)openMap:(id)sender {
[imagesController openMap:sender];
}
@end