This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
ORSCanaryPreferencesController.m
175 lines (154 loc) · 5.39 KB
/
ORSCanaryPreferencesController.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
//
// ORSCanaryPreferencesController.m
// Canary
//
// Created by Nicholas Toumpelis on 12/04/2009.
// Copyright 2009 Ocean Road Software. All rights reserved.
//
// Version 0.7
#import "ORSCanaryPreferencesController.h"
@implementation ORSCanaryPreferencesController
@synthesize filters;
static ORSCanaryPreferencesController *sharedPreferencesController = nil;
+ (ORSCanaryPreferencesController *)sharedPreferencesController {
@synchronized(self) {
if (sharedPreferencesController == nil) {
[[self alloc] initWithWindowNibName:@"Preferences"];
}
}
return sharedPreferencesController;
}
+ (id) allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (sharedPreferencesController == nil) {
sharedPreferencesController = [super allocWithZone:zone];
return sharedPreferencesController;
}
}
return nil;
}
- (id) copyWithZone:(NSZone *)zone {
return self;
}
- (id) initWithWindow:(NSWindow *)window {
if (self = [super initWithWindow:window]) {
filters = [[NSArray alloc] init];
}
return self;
}
- (void) windowWillClose:(NSNotification *)notification {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setFloat:self.window.frame.origin.x
forKey:@"CanaryPreferencesWindowX"];
[defaults setFloat:self.window.frame.origin.y
forKey:@"CanaryPreferencesWindowY"];
[defaults setFloat:self.window.frame.size.width
forKey:@"CanaryPreferencesWindowWidth"];
[defaults setFloat:self.window.frame.size.height
forKey:@"CanaryPreferencesWindowHeight"];
}
- (void) awakeFromNib {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[self urlShortenerSelected:self];
if ([defaults floatForKey:@"CanaryPreferencesWindowX"]) {
NSRect newFrame = NSMakeRect(
[defaults floatForKey:@"CanaryPreferencesWindowX"],
[defaults floatForKey:@"CanaryPreferencesWindowY"],
[defaults floatForKey:@"CanaryPreferencesWindowWidth"],
[defaults floatForKey:@"CanaryPreferencesWindowHeight"]);
[[self window] setFrame:newFrame display:YES];
} else {
[self.window center];
}
}
- (IBAction) timelineRefreshRateSelected:sender {
[[ORSCanaryController sharedController] updateTimer];
}
- (IBAction) maxShownUpdatesSelected:sender {
[[ORSCanaryController sharedController] updateMaxNoOfShownUpdates];
}
- (IBAction) urlShortenerSelected:sender {
[[ORSCanaryController sharedController] updateSelectedURLShortener];
if ([selectedShortenerPopUp.selectedItem.title isEqualToString:@"Adjix"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:0];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"Bit.ly"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:1];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"Cli.gs"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:2];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"Is.gd"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:3];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"SnipURL"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:4];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"TinyURL"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:5];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"tr.im"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:6];
} else if ([selectedShortenerPopUp.selectedItem.title
isEqualToString:@"urlBorg"]) {
[shortenerSettingsTabView selectTabViewItemAtIndex:7];
}
}
- (IBAction) addFilter:sender {
ORSFilter *newFilter = [[ORSFilter alloc] init];
newFilter.filterName = @"New Filter";
newFilter.active = YES;
newFilter.predicate = [NSPredicate
predicateWithFormat:@"(text contains \"Adam\") AND \
(text contains \"Eve\")"];
[filterArrayController insertObject:newFilter
atArrangedObjectIndex:0];
[filterArrayController setSelectionIndex:0];
[NSApp beginSheet:filterEditor
modalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(didEndNewFilterSheet:returnCode:contextInfo:)
contextInfo:nil];
}
- (IBAction) editFilter:sender {
tempFilter = [[[filterArrayController selectedObjects]
objectAtIndex:0] copy];
[NSApp beginSheet:filterEditor
modalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(didEndEditFilterSheet:returnCode:contextInfo:)
contextInfo:nil];
}
- (IBAction) duplicateFilter:sender {
ORSFilter *duplicateFilter = [[[filterArrayController selectedObjects]
objectAtIndex:0] copy];
[filterArrayController addObject:duplicateFilter];
}
- (IBAction) cancelFilterChanges:sender {
[filterArrayController discardEditing];
[filterEditor orderOut:sender];
[NSApp endSheet:filterEditor returnCode:0];
}
- (IBAction) keepFilterChanges:sender {
[filterArrayController commitEditing];
[filterEditor orderOut:sender];
[NSApp endSheet:filterEditor returnCode:1];
}
- (void) didEndNewFilterSheet:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
if (returnCode == 0) {
[filterArrayController remove:nil];
}
}
- (void) didEndEditFilterSheet:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
int selIndex = filterArrayController.selectionIndex;
if (returnCode == 0) {
[filterArrayController remove:nil];
[filterArrayController insertObject:tempFilter
atArrangedObjectIndex:selIndex];
}
}
@end