Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OODockTilePlugIn Class Reference

#include <OODockTilePlugIn.h>

+ Inheritance diagram for OODockTilePlugIn:
+ Collaboration diagram for OODockTilePlugIn:

Instance Methods

(IBAction) - showScreenShots:
 
(IBAction) - showExpansionPacks:
 
(IBAction) - showLatestLog:
 
(IBAction) - showLogFolder:
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(BOOL) - isDirectoryAtPath: [implementation]
 
(BOOL) - addOnsExistAtPath: [implementation]
 
(void) - openPath: [implementation]
 
(BOOL) - validateMenuItem: [implementation]
 
(NSURL *) - snapshotsURLCreatingIfNeeded: [implementation]
 
(NSString *) - latestLogPath [implementation]
 
(NSString *) - logFolderPath [implementation]
 

Class Methods

(static id) + GetPreference [implementation]
 
(static void) + SetPreference [implementation]
 
(static void) + RemovePreference [implementation]
 
(static NSString *) + DESC [implementation]
 

Properties

NSDockTile * dockTile
 
IBOutlet NSMenu * dockMenu
 

Private Attributes

NSDockTile * _dockTile
 
NSMenu * _dockMenu
 

Detailed Description

Definition at line 32 of file OODockTilePlugIn.h.

Method Documentation

◆ addOnsExistAtPath:

- (BOOL) addOnsExistAtPath: (NSString *) path
implementation

Definition at line 342 of file OODockTilePlugIn.m.

115 :(NSString *)path
116{
117 if (![self isDirectoryAtPath:path]) return NO;
118
119 NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
120 for (NSString *subPath in [NSFileManager.defaultManager enumeratorAtPath:path]) {
121 subPath = [path stringByAppendingPathComponent:subPath];
122 NSString *type = [workspace typeOfFile:subPath error:NULL];
123 if ([workspace type:type conformsToType:@"org.aegidian.oolite.expansion"]) return YES;
124 }
125
126 return NO;
127}

◆ dealloc

- (void) dealloc
implementation

Definition at line 342 of file OODockTilePlugIn.m.

65{
66 self.dockTile = nil;
67 self.dockMenu = nil;
68
69 [super dealloc];
70}
return nil

◆ DESC

+ (static NSString *) DESC (NSString *) key
implementation

Definition at line 188 of file OODockTilePlugIn.m.

189{
190 static NSDictionary *descs = nil;
191 if (descs == nil)
192 {
193 // Get default description.plist from Oolite.
194 NSURL *url = [[NSBundle bundleForClass:[OODockTilePlugIn class]] bundleURL];
195 url = [NSURL URLWithString:@"../../Resources/Config/descriptions.plist" relativeToURL:url];
196
197 descs = [NSDictionary dictionaryWithContentsOfURL:url];
198 if (descs == nil) descs = [NSDictionary dictionary];
199 [descs retain];
200 }
201
202 NSString *result = [descs objectForKey:key];
203 if (![result isKindOfClass:[NSString class]]) result = key; // We don't need to deal with arrays.
204 return result;
205}

References nil.

◆ GetPreference

+ (static id) GetPreference (NSString *) key
(Class) expectedClass 
implementation

Definition at line 165 of file OODockTilePlugIn.m.

166{
167 // Use CFPreferences instead of NSDefaults so we can specify the app ID.
168 CFPropertyListRef value = CFPreferencesCopyAppValue((CFStringRef)key, CFSTR("org.aegidian.oolite"));
169 id result = [NSMakeCollectable(value) autorelease];
170 if (expectedClass != Nil && ![result isKindOfClass:expectedClass]) result = nil;
171
172 return result;
173}

References nil.

◆ init

- (id) init
implementation

Definition at line 342 of file OODockTilePlugIn.m.

54{
55 if ((self = [super init]))
56 {
57 [NSBundle loadNibNamed:@"OODockTilePlugIn" owner:self];
58 }
59
60 return self;
61}

◆ isDirectoryAtPath:

- (BOOL) isDirectoryAtPath: (NSString *) path
implementation

Definition at line 342 of file OODockTilePlugIn.m.

108 :(NSString *)path
109{
110 BOOL isDirectory;
111 return [NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
112}

◆ latestLogPath

- (NSString *) latestLogPath
implementation

Definition at line 188 of file OODockTilePlugIn.m.

291{
292 return [[self logFolderPath] stringByAppendingPathComponent:@"Latest.log"];
293}

◆ logFolderPath

- (NSString *) logFolderPath
implementation

Definition at line 188 of file OODockTilePlugIn.m.

297{
299}
NSString * OOLogHandlerGetLogBasePath(void)

◆ openPath:

- (void) openPath: (NSString *) path
implementation

Definition at line 342 of file OODockTilePlugIn.m.

130 :(NSString *)path
131{
132 [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:path]];
133}

◆ RemovePreference

+ (static void) RemovePreference (NSString *) key
implementation

Definition at line 182 of file OODockTilePlugIn.m.

183{
184 SetPreference(key, nil);
185}
static void SetPreference(NSString *key, id value)

References nil, and SetPreference.

+ Here is the call graph for this function:

◆ SetPreference

+ (static void) SetPreference (NSString *) key
(id) value 
implementation

Definition at line 176 of file OODockTilePlugIn.m.

177{
178 CFPreferencesSetAppValue((CFStringRef)key, value, CFSTR("org.aegidian.oolite"));
179}

Referenced by RemovePreference.

+ Here is the caller graph for this function:

◆ showExpansionPacks:

- (IBAction) showExpansionPacks: (id) sender

Definition at line 342 of file OODockTilePlugIn.m.

79 :sender
80{
81 NSArray *paths = ResourceManagerRootPaths();
82
83 // Look for an AddOns directory that actually contains some AddOns.
84 for (NSString *path in paths) {
85 if ([self addOnsExistAtPath:path]) {
86 [self openPath:path];
87 return;
88 }
89 }
90
91 // If that failed, look for an AddOns directory that actually exists.
92 for (NSString *path in paths) {
93 if ([self isDirectoryAtPath:path]) {
94 [self openPath:path];
95 return;
96 }
97 }
98
99 // None found, create the default path.
100 [NSFileManager.defaultManager createDirectoryAtPath:paths[0]
101 withIntermediateDirectories:YES
102 attributes:nil
103 error:NULL];
104 [self openPath:paths[0]];
105}
static NSArray * ResourceManagerRootPaths(void)

◆ showLatestLog:

- (IBAction) showLatestLog: (id) sender

Definition at line 342 of file OODockTilePlugIn.m.

136 :(id)sender
137{
138 [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[self latestLogPath]]];
139}

◆ showLogFolder:

- (IBAction) showLogFolder: (id) sender

Definition at line 342 of file OODockTilePlugIn.m.

142 :(id)sender
143{
144 [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[self logFolderPath]]];
145}

◆ showScreenShots:

- (IBAction) showScreenShots: (id) sender

Definition at line 342 of file OODockTilePlugIn.m.

73 :(id)sender
74{
75 [[NSWorkspace sharedWorkspace] openURL:[self snapshotsURLCreatingIfNeeded:NO]];
76}

◆ snapshotsURLCreatingIfNeeded:

- (NSURL *) snapshotsURLCreatingIfNeeded: (BOOL) create
implementation

Definition at line 188 of file OODockTilePlugIn.m.

211 :(BOOL)create
212{
213 BOOL stale = NO;
214 NSDictionary *snapshotDirDict = GetPreference(kSnapshotsDirRefKey, [NSDictionary class]);
215 NSURL *url = nil;
216 NSString *name = DESC(@"snapshots-directory-name-mac");
217
218 if (snapshotDirDict != nil)
219 {
221 if (url != nil)
222 {
223 NSString *existingName = [[url path] lastPathComponent];
224 if ([existingName compare:name options:NSCaseInsensitiveSearch] != 0)
225 {
226 // Check name from previous access, because we might have changed localizations.
227 NSString *originalOldName = GetPreference(kSnapshotsDirNameKey, [NSString class]);
228 if (originalOldName == nil || [existingName compare:originalOldName options:NSCaseInsensitiveSearch] != 0)
229 {
230 url = nil;
231 }
232 }
233
234 // did we put the old directory in the trash?
235 Boolean inTrash = false;
236 const UInt8* utfPath = (UInt8*)[[url path] UTF8String];
237
238 OSStatus err = DetermineIfPathIsEnclosedByFolder(kOnAppropriateDisk, kTrashFolderType, utfPath, false, &inTrash);
239 // if so, create a new directory.
240 if (err == noErr && inTrash == true) url = nil;
241 }
242 }
243
244 if (url == nil)
245 {
246 NSString *path = nil;
247 NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
248 if ([searchPaths count] > 0)
249 {
250 path = [[searchPaths objectAtIndex:0] stringByAppendingPathComponent:name];
251 }
252 url = [NSURL fileURLWithPath:path];
253
254 if (url != nil)
255 {
256 stale = YES;
257 if (create)
258 {
259 NSFileManager *fmgr = [NSFileManager defaultManager];
260 if (![fmgr fileExistsAtPath:path])
261 {
262#if OOLITE_LEOPARD
263 [fmgr createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL];
264#else
265 [fmgr createDirectoryAtPath:path attributes:nil];
266#endif
267 }
268 }
269 }
270 }
271
272 if (stale)
273 {
274 snapshotDirDict = JAPersistentFileReferenceFromURL(url);
275 if (snapshotDirDict != nil)
276 {
277 SetPreference(kSnapshotsDirRefKey, snapshotDirDict);
278 SetPreference(kSnapshotsDirNameKey, [[url path] lastPathComponent]);
279 }
280 else
281 {
283 }
284 }
285
286 return url;
287}
#define kSnapshotsDirNameKey
#define kSnapshotsDirRefKey
@ kJAPersistentFileReferenceWithoutUI
@ kJAPersistentFileReferenceWithoutMounting
NSURL * JAURLFromPersistentFileReference(NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
NSDictionary * JAPersistentFileReferenceFromURL(NSURL *url)
unsigned count
#define DESC(key)
Definition Universe.h:846
static id GetPreference(NSString *key, Class expectedClass)
static void RemovePreference(NSString *key)

◆ validateMenuItem:

- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
implementation

Definition at line 342 of file OODockTilePlugIn.m.

148 :(NSMenuItem *)menuItem
149{
150 SEL action = [menuItem action];
151
152 if (action == @selector(showScreenShots:))
153 {
154 return [[NSFileManager defaultManager] fileExistsAtPath:[[self snapshotsURLCreatingIfNeeded:NO] path]];
155 }
156 else if (action == @selector(showLatestLog:))
157 {
158 return [[NSFileManager defaultManager] fileExistsAtPath:[self latestLogPath]];
159 }
160
161 return YES;
162}

Member Data Documentation

◆ _dockMenu

- (NSMenu*) _dockMenu
private

Definition at line 39 of file OODockTilePlugIn.h.

◆ _dockTile

- (NSDockTile*) _dockTile
private

Definition at line 38 of file OODockTilePlugIn.h.

Property Documentation

◆ dockMenu

- (IBOutlet NSMenu*) dockMenu
readwriteatomicassign

Definition at line 44 of file OODockTilePlugIn.h.

◆ dockTile

- (NSDockTile*) dockTile
readwriteatomicretain

Definition at line 43 of file OODockTilePlugIn.h.


The documentation for this class was generated from the following files: