35 |
#include "OSXCompatibility.h" |
#include "OSXCompatibility.h" |
36 |
#endif |
#endif |
37 |
|
|
|
#define CHECKGW \ |
|
|
if (gwapp == nil) \ |
|
|
gwapp = (id <GWProtocol>)[[GWLib class] gworkspaceApplication]; \ |
|
|
if (gwapp == nil) return |
|
|
|
|
|
#define CHECKGW_RET(x) \ |
|
|
if (gwapp == nil) \ |
|
|
gwapp = (id <GWProtocol>)[[GWLib class] gworkspaceApplication]; \ |
|
|
if (gwapp == nil) return x |
|
|
|
|
38 |
#ifndef CACHED_MAX |
#ifndef CACHED_MAX |
39 |
#define CACHED_MAX 20 |
#define CACHED_MAX 20 |
40 |
#endif |
#endif |
48 |
#endif |
#endif |
49 |
|
|
50 |
id instance = nil; |
id instance = nil; |
|
static id gwapp = nil; |
|
|
static NSString *gwName = @"GWorkspace"; |
|
51 |
|
|
52 |
@interface GWLib (PrivateMethods) |
@interface GWLib (PrivateMethods) |
53 |
|
|
130 |
|
|
131 |
- (NSArray *)imageExtensions; |
- (NSArray *)imageExtensions; |
132 |
|
|
133 |
|
- (id)workspaceApp; |
134 |
|
|
135 |
@end |
@end |
136 |
|
|
137 |
@implementation GWLib (PrivateMethods) |
@implementation GWLib (PrivateMethods) |
165 |
self = [super init]; |
self = [super init]; |
166 |
|
|
167 |
if (self) { |
if (self) { |
168 |
BOOL isdir; |
BOOL isdir; |
169 |
|
|
170 |
fm = [NSFileManager defaultManager]; |
fm = [NSFileManager defaultManager]; |
171 |
ws = [NSWorkspace sharedWorkspace]; |
ws = [NSWorkspace sharedWorkspace]; |
179 |
watchers = [NSMutableArray new]; |
watchers = [NSMutableArray new]; |
180 |
watchTimers = [NSMutableArray new]; |
watchTimers = [NSMutableArray new]; |
181 |
watchedPaths = [NSMutableArray new]; |
watchedPaths = [NSMutableArray new]; |
|
|
|
182 |
lockedPaths = [NSMutableArray new]; |
lockedPaths = [NSMutableArray new]; |
|
|
|
183 |
tumbsCache = [NSMutableDictionary new]; |
tumbsCache = [NSMutableDictionary new]; |
184 |
|
|
185 |
thumbnailDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; |
thumbnailDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; |
186 |
thumbnailDir = [thumbnailDir stringByAppendingPathComponent: @"Thumbnails"]; |
thumbnailDir = [thumbnailDir stringByAppendingPathComponent: @"Thumbnails"]; |
187 |
RETAIN (thumbnailDir); |
RETAIN (thumbnailDir); |
204 |
selector: @selector(thumbnailsDidChange:) |
selector: @selector(thumbnailsDidChange:) |
205 |
name: GWThumbnailsDidChangeNotification |
name: GWThumbnailsDidChangeNotification |
206 |
object: nil]; |
object: nil]; |
207 |
|
|
208 |
|
workspaceApp = [self workspaceApp]; |
209 |
} |
} |
210 |
|
|
211 |
return self; |
return self; |
217 |
|
|
218 |
if (contentsDict) { |
if (contentsDict) { |
219 |
return [contentsDict objectForKey: @"files"]; |
return [contentsDict objectForKey: @"files"]; |
|
|
|
220 |
} else { |
} else { |
221 |
NSArray *files = [fm directoryContentsAtPath: path]; |
NSArray *files = [fm directoryContentsAtPath: path]; |
222 |
int stype = [self sortTypeForDirectoryAtPath: path]; |
int stype = [self sortTypeForDirectoryAtPath: path]; |
831 |
@"xpm", nil]; |
@"xpm", nil]; |
832 |
} |
} |
833 |
|
|
834 |
|
- (id)workspaceApp |
835 |
|
{ |
836 |
|
if (workspaceApp == nil) { |
837 |
|
NSUserDefaults *defaults; |
838 |
|
NSString *appName; |
839 |
|
NSString *selName; |
840 |
|
Class wkspclass; |
841 |
|
SEL sel; |
842 |
|
|
843 |
|
defaults = [NSUserDefaults standardUserDefaults]; |
844 |
|
|
845 |
|
appName = [defaults stringForKey: @"GSWorkspaceApplication"]; |
846 |
|
if (appName == nil) { |
847 |
|
appName = @"GWorkspace"; |
848 |
|
} |
849 |
|
|
850 |
|
selName = [defaults stringForKey: @"GSWorkspaceSelName"]; |
851 |
|
if (selName == nil) { |
852 |
|
selName = @"gworkspace"; |
853 |
|
} |
854 |
|
|
855 |
|
#ifdef GNUSTEP |
856 |
|
wkspclass = [[NSBundle mainBundle] principalClass]; |
857 |
|
#else |
858 |
|
wkspclass = [[NSBundle mainBundle] classNamed: appName]; |
859 |
|
#endif |
860 |
|
|
861 |
|
sel = NSSelectorFromString(selName); |
862 |
|
|
863 |
|
workspaceApp = [wkspclass performSelector: sel]; |
864 |
|
} |
865 |
|
|
866 |
|
return workspaceApp; |
867 |
|
} |
868 |
|
|
869 |
@end |
@end |
870 |
|
|
871 |
|
|
986 |
return [[self instance] imageExtensions]; |
return [[self instance] imageExtensions]; |
987 |
} |
} |
988 |
|
|
989 |
|
+ (id)workspaceApp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ (id)gworkspaceApplication |
|
990 |
{ |
{ |
991 |
if (gwapp == nil) { |
return [[self instance] workspaceApp]; |
|
NSString *host; |
|
|
NSString *port; |
|
|
NSDate *when = nil; |
|
|
BOOL done = NO; |
|
|
|
|
|
while (done == NO) { |
|
|
host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"]; |
|
|
|
|
|
if (host == nil) { |
|
|
host = @""; |
|
|
} else { |
|
|
NSHost *h = [NSHost hostWithName: host]; |
|
|
|
|
|
if ([h isEqual: [NSHost currentHost]]) { |
|
|
host = @""; |
|
|
} |
|
|
} |
|
|
|
|
|
port = gwName; |
|
|
|
|
|
NS_DURING |
|
|
{ |
|
|
gwapp = (id <GWProtocol>)[NSConnection rootProxyForConnectionWithRegisteredName: port host: host]; |
|
|
RETAIN (gwapp); |
|
|
} |
|
|
NS_HANDLER |
|
|
{ |
|
|
gwapp = nil; |
|
|
} |
|
|
NS_ENDHANDLER |
|
|
|
|
|
if (gwapp) { |
|
|
done = YES; |
|
|
} |
|
|
|
|
|
if (gwapp == nil) { |
|
|
[[NSWorkspace sharedWorkspace] launchApplication: gwName]; |
|
|
|
|
|
if (when == nil) { |
|
|
when = [[NSDate alloc] init]; |
|
|
done = NO; |
|
|
} else if ([when timeIntervalSinceNow] > 5.0) { |
|
|
int result; |
|
|
|
|
|
DESTROY (when); |
|
|
result = NSRunAlertPanel(gwName, |
|
|
@"Application seems to have hung", |
|
|
@"Continue", @"Terminate", @"Wait"); |
|
|
|
|
|
if (result == NSAlertDefaultReturn) { |
|
|
done = YES; |
|
|
} else if (result == NSAlertOtherReturn) { |
|
|
done = NO; |
|
|
} else { |
|
|
done = YES; |
|
|
} |
|
|
} |
|
|
|
|
|
if (done == NO) { |
|
|
NSDate *limit = [[NSDate alloc] initWithTimeIntervalSinceNow: 0.5]; |
|
|
[[NSRunLoop currentRunLoop] runUntilDate: limit]; |
|
|
RELEASE(limit); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
TEST_RELEASE (when); |
|
|
} |
|
|
|
|
|
return gwapp; |
|
|
} |
|
|
|
|
|
+ (BOOL)selectFile:(NSString *)fullPath |
|
|
inFileViewerRootedAtPath:(NSString *)rootFullpath |
|
|
{ |
|
|
CHECKGW_RET(NO); |
|
|
return [gwapp selectFile: fullPath inFileViewerRootedAtPath: rootFullpath]; |
|
|
return NO; |
|
|
} |
|
|
|
|
|
+ (oneway void)rootViewerSelectFiles:(NSArray *)paths |
|
|
{ |
|
|
CHECKGW; |
|
|
[gwapp rootViewerSelectFiles: paths]; |
|
|
} |
|
|
|
|
|
+ (oneway void)openSelectedPaths:(NSArray *)paths |
|
|
{ |
|
|
CHECKGW; |
|
|
[gwapp openSelectedPaths: paths]; |
|
|
} |
|
|
|
|
|
+ (oneway void)performFileOperationWithDictionary:(NSDictionary *)dict |
|
|
{ |
|
|
CHECKGW; |
|
|
[gwapp performFileOperationWithDictionary: dict]; |
|
|
} |
|
|
|
|
|
+ (oneway void)performServiceWithName:(NSString *)sname |
|
|
pasteboard:(NSPasteboard *)pboard |
|
|
{ |
|
|
NSPerformService(sname, pboard); |
|
|
} |
|
|
|
|
|
+ (NSString *)trashPath |
|
|
{ |
|
|
CHECKGW_RET(nil); |
|
|
return [gwapp trashPath]; |
|
|
return nil; |
|
992 |
} |
} |
993 |
|
|
994 |
@end |
@end |