Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /bathyscaphe/trunk/application/source/CMRAppDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 965 - (show annotations) (download)
Sun Nov 30 15:54:53 2008 UTC (15 years, 6 months ago) by tsawada2
File size: 9736 byte(s)
v345 matomete commit

1 //
2 // CMRAppDelegate.m
3 // BathyScaphe
4 //
5 // Updated by Tsutomu Sawada on 07/12/19.
6 // Copyright 2005-2008 BathyScaphe Project. All rights reserved.
7 // encoding="UTF-8"
8 //
9
10 #import "CMRAppDelegate_p.h"
11 #import "BoardWarrior.h"
12 #import "CMRBrowser.h"
13 #import "BoardListItem.h"
14 #import "CMRThreadDocument.h"
15 #import "TS2SoftwareUpdate.h"
16 #import "CMRDocumentController.h"
17 #import "BSDateFormatter.h"
18 #import "DatabaseManager.h"
19
20 static NSString *const kOnlineItemKey = @"On Line";
21 static NSString *const kOfflineItemKey = @"Off Line";
22 static NSString *const kOnlineItemImageName = @"online";
23 static NSString *const kOfflineItemImageName = @"offline";
24
25 static NSString *const kSWCheckURLKey = @"System - Software Update Check URL";
26 static NSString *const kSWDownloadURLKey = @"System - Software Update Download Page URL";
27
28 @implementation CMRAppDelegate
29 - (void)awakeFromNib
30 {
31 [self setupMenu];
32 }
33
34 - (NSString *)threadPath
35 {
36 return m_threadPath;
37 }
38
39 - (void)setThreadPath:(NSString *)aString
40 {
41 [aString retain];
42 [m_threadPath release];
43 m_threadPath = aString;
44 }
45
46 - (void)dealloc
47 {
48 [self setThreadPath:nil];
49 [super dealloc];
50 }
51
52 #pragma mark IBAction
53 - (IBAction)checkForUpdate:(id)sender
54 {
55 [[TS2SoftwareUpdate sharedInstance] startUpdateCheck:sender];
56 }
57
58 - (IBAction)showPreferencesPane:(id)sender
59 {
60 [NSApp sendAction:@selector(showWindow:) to:[CMRPref sharedPreferencesPane] from:sender];
61 }
62
63 - (IBAction)toggleOnlineMode:(id)sender
64 {
65 [CMRPref setIsOnlineMode:(![CMRPref isOnlineMode])];
66 }
67
68 - (IBAction)resetApplication:(id)sender
69 {
70 CMRApplicationReset(self);
71 }
72
73 - (IBAction)customizeTextTemplates:(id)sender
74 {
75 [[CMRPref sharedPreferencesPane] showPreferencesPaneWithIdentifier:PPReplyDefaultIdentifier];
76 }
77
78 - (IBAction)togglePreviewPanel:(id)sender
79 {
80 [NSApp sendAction:@selector(togglePreviewPanel:) to:[CMRPref sharedImagePreviewer] from:sender];
81 }
82
83 - (IBAction)showTaskInfoPanel:(id)sender
84 {
85 [[CMRTaskManager defaultManager] showWindow:sender];
86 }
87
88 // For Help Menu
89 - (IBAction)openURL:(id)sender
90 {
91 NSURL *url;
92
93 UTILAssertRespondsTo(sender, @selector(representedObject));
94 if (url = [sender representedObject]) {
95 UTILAssertKindOfClass(url, NSURL);
96 [[NSWorkspace sharedWorkspace] openURL:url];
97 }
98 }
99
100 - (IBAction)showAcknowledgment:(id)sender
101 {
102 NSBundle *mainBundle;
103 NSString *fileName;
104 NSString *appName;
105 NSWorkspace *ws = [NSWorkspace sharedWorkspace];
106
107 mainBundle = [NSBundle mainBundle];
108 fileName = [mainBundle pathForResource:@"Acknowledgments" ofType:@"rtf"];
109 appName = [ws absolutePathForAppBundleWithIdentifier:@"com.apple.TextEdit"];
110
111 [ws openFile:fileName withApplication:appName];
112 }
113
114 - (IBAction)openURLPanel:(id)sender
115 {
116 if (![NSApp isActive]) [NSApp activateIgnoringOtherApps:YES];
117 [[CMROpenURLManager defaultManager] askUserURL];
118 }
119
120 - (IBAction)closeAll:(id)sender
121 {
122 NSArray *allWindows = [NSApp windows];
123 if (!allWindows) return;
124 NSEnumerator *iter = [allWindows objectEnumerator];
125 NSWindow *window;
126 while (window = [iter nextObject]) {
127 if ([window isVisible] && ![window isSheet]) {
128 [window performClose:sender];
129 }
130 }
131 }
132
133 - (IBAction)clearHistory:(id)sender
134 {
135 [[CMRHistoryManager defaultManager] removeAllItems];
136 }
137
138 - (IBAction)showThreadFromHistoryMenu:(id)sender
139 {
140 UTILAssertRespondsTo(sender, @selector(representedObject));
141 [CMRThreadDocument showDocumentWithHistoryItem:[sender representedObject]];
142 }
143
144 - (IBAction)showBoardFromHistoryMenu:(id)sender
145 {
146 UTILAssertRespondsTo(sender, @selector(representedObject));
147
148 BoardListItem *boardListItem = [sender representedObject];
149 if (boardListItem && [boardListItem respondsToSelector: @selector(representName)]) {
150 [self showThreadsListForBoard:[boardListItem representName] selectThread:nil addToListIfNeeded:YES];
151 }
152 }
153
154 - (IBAction)startHEADCheckDirectly:(id)sender
155 {
156 BOOL hasBeenOnline = [CMRPref isOnlineMode];
157
158 // ���������������������������������������������������������������
159 if (hasBeenOnline) [self toggleOnlineMode:sender];
160
161 [self showThreadsListForBoard:CMXFavoritesDirectoryName selectThread:nil addToListIfNeeded:NO];
162 [CMRMainBrowser reloadThreadsList:sender];
163
164 // ������������������������������������
165 if (hasBeenOnline) [self toggleOnlineMode:sender];
166 }
167
168 - (IBAction)runBoardWarrior:(id)sender
169 {
170 [[BoardWarrior warrior] syncBoardLists];
171 }
172
173 - (IBAction)openAEDictionary:(id)sender
174 {
175 NSString *selfPath = [[NSBundle mainBundle] bundlePath];
176 NSString *toysPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.ScriptEditor2"];
177 if (selfPath && toysPath) {
178 [[NSWorkspace sharedWorkspace] openFile:selfPath withApplication:toysPath];
179 }
180 }
181
182 // Application Reset Alert's help button delegate
183 - (BOOL)alertShowHelp:(NSAlert *)alert
184 {
185 [[NSHelpManager sharedHelpManager] openHelpAnchor:[alert helpAnchor] inBook:[NSBundle applicationHelpBookName]];
186 return YES;
187 }
188
189 - (void)mainBrowserDidFinishShowThList:(NSNotification *)aNotification
190 {
191 UTILAssertNotificationName(
192 aNotification,
193 CMRBrowserThListUpdateDelegateTaskDidFinishNotification);
194
195 [CMRMainBrowser selectRowWithThreadPath:[self threadPath]
196 byExtendingSelection:NO
197 scrollToVisible:YES];
198
199 [[NSNotificationCenter defaultCenter] removeObserver:self
200 name:CMRBrowserThListUpdateDelegateTaskDidFinishNotification
201 object:CMRMainBrowser];
202 }
203
204 - (void)showThreadsListForBoard:(NSString *)boardName selectThread:(NSString *)path addToListIfNeeded:(BOOL)addToList
205 {
206 if (CMRMainBrowser) {
207 [CMRMainBrowser showWindow:self];
208 } else {
209 [[CMRDocumentController sharedDocumentController] newDocument:self];
210 }
211
212 if (path) {
213 [self setThreadPath:path];
214 [[NSNotificationCenter defaultCenter] addObserver:self
215 selector:@selector(mainBrowserDidFinishShowThList:)
216 name:CMRBrowserThListUpdateDelegateTaskDidFinishNotification
217 object:CMRMainBrowser];
218 }
219 // addBrdToUsrListIfNeeded ��������������������������������������������� YES ������������
220 [CMRMainBrowser selectRowOfName:boardName forceReload:NO]; // ��������������������� outlineView ��� selectionDidChange: ������������������
221 // ��������������������������������������� showThreadsListForBoardName: ���������������������
222 }
223
224 - (IBAction)openWebSiteForUpdate:(id)sender
225 {
226 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:SGTemplateResource(kSWDownloadURLKey)]];
227 }
228
229 - (IBAction) changeUpdateSettings:(id)sender
230 {
231 [[CMRPref sharedPreferencesPane] showPreferencesPaneWithIdentifier:PPGeneralPreferencesIdentifier];
232 }
233
234 #pragma mark Validation
235 - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
236 {
237 SEL action_ = [theItem action];
238
239 if (action_ == @selector(toggleOnlineMode:)) {
240 BOOL isOnline = [CMRPref isOnlineMode];
241 NSString *title_;
242 NSImage *image_;
243
244 title_ = isOnline ? [self localizedString:kOnlineItemKey] : [self localizedString:kOfflineItemKey];
245 image_ = isOnline ? [NSImage imageAppNamed:kOnlineItemImageName] : [NSImage imageAppNamed:kOfflineItemImageName];
246
247 [theItem setImage:image_];
248 [theItem setLabel:title_];
249 return YES;
250 }
251
252 return YES;
253 }
254
255 - (BOOL)validateMenuItem:(NSMenuItem *)theItem
256 {
257 SEL action_ = [theItem action];
258
259 if (action_ == @selector(closeAll:)) {
260 return ([NSApp makeWindowsPerform:@selector(isVisible) inOrder:YES] != nil);
261 } else if (action_ == @selector(togglePreviewPanel:)) {
262 id tmp_ = [CMRPref sharedImagePreviewer];
263 return [tmp_ respondsToSelector:@selector(togglePreviewPanel:)];
264 } else if (action_ == @selector(startHEADCheckDirectly:)) {
265 return [CMRPref canHEADCheck];
266 } else if (action_ == @selector(toggleOnlineMode:)) {
267 [theItem setState:[CMRPref isOnlineMode] ? NSOnState : NSOffState];
268 return YES;
269 }
270 return YES;
271 }
272
273 #pragma mark NSApplication Delegates
274 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
275 {
276 BSStringFromDateTransformer *transformer;
277 NSAppleEventManager *aeMgr = [NSAppleEventManager sharedAppleEventManager];
278
279 [aeMgr setEventHandler:[CMROpenURLManager defaultManager]
280 andSelector:@selector(handleGetURLEvent:withReplyEvent:)
281 forEventClass:'GURL'
282 andEventID:'GURL'];
283
284 TS2SoftwareUpdate *checker = [TS2SoftwareUpdate sharedInstance];
285 [checker setUpdateInfoURL:[NSURL URLWithString:SGTemplateResource(kSWCheckURLKey)]];
286 [checker setOpenPrefsSelector:@selector(changeUpdateSettings:)];
287 [checker setUpdateNowSelector:@selector(openWebSiteForUpdate:)];
288
289 transformer = [[[BSStringFromDateTransformer alloc] init] autorelease];
290 [NSValueTransformer setValueTransformer:transformer forName:@"BSStringFromDateTransformer"];
291 }
292
293 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
294 {
295 AppDefaults *defaults_ = CMRPref;
296
297 /* Service menu */
298 [NSApp setServicesProvider:[CMROpenURLManager defaultManager]];
299
300 /* Remove 'Quick Look' menu */
301 [[CMRMainMenuManager defaultManager] removeQuickLookMenuItemIfNeeded];
302
303 /* BoardWarrior Task */
304 if ([defaults_ isOnlineMode] && [defaults_ autoSyncBoardList]) {
305 NSDate *lastDate = [defaults_ lastSyncDate];
306 if (!lastDate || [[NSDate date] timeIntervalSinceDate: lastDate] > [defaults_ timeIntervalForAutoSyncPrefs]) {
307 [self runBoardWarrior:nil];
308 }
309 }
310
311 if ([defaults_ isOnlineMode]) [[TS2SoftwareUpdate sharedInstance] startUpdateCheck:nil];
312 }
313
314 - (void)applicationWillTerminate:(NSNotification *)aNotification
315 {
316 KeyMap m;
317 long lm;
318 GetKeys(m);
319 #if TARGET_RT_LITTLE_ENDIAN
320 lm = EndianU32_LtoB(m[1].bigEndianValue);
321 #else
322 lm = m[1];
323 #endif
324 if((lm & 0x4) != 0x4/*option key*/) return;
325
326 [[DatabaseManager defaultManager] doVacuum];
327 }
328 @end
329
330
331 @implementation CMRAppDelegate(CMRLocalizableStringsOwner)
332 + (NSString *)localizableStringsTableName
333 {
334 return APP_MAINMENU_LOCALIZABLE_FILE_NAME;
335 }
336 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26