/[gnustep]/gnustep/usr-apps/gworkspace/GWLib/GWLib.m
ViewVC logotype

Diff of /gnustep/usr-apps/gworkspace/GWLib/GWLib.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by esersale, Mon Sep 29 18:13:47 2003 UTC revision 1.6 by esersale, Tue Sep 30 15:38:04 2003 UTC
# Line 35  Line 35 
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
# Line 58  if (gwapp == nil) return x Line 48  if (gwapp == nil) return x
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    
# Line 142  static NSString *gwName = @"GWorkspace"; Line 130  static NSString *gwName = @"GWorkspace";
130    
131  - (NSArray *)imageExtensions;  - (NSArray *)imageExtensions;
132    
133    - (id)workspaceApp;
134    
135  @end  @end
136    
137  @implementation GWLib (PrivateMethods)  @implementation GWLib (PrivateMethods)
# Line 175  static NSString *gwName = @"GWorkspace"; Line 165  static NSString *gwName = @"GWorkspace";
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];
# Line 189  static NSString *gwName = @"GWorkspace"; Line 179  static NSString *gwName = @"GWorkspace";
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);
# Line 215  static NSString *gwName = @"GWorkspace"; Line 204  static NSString *gwName = @"GWorkspace";
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;
# Line 226  static NSString *gwName = @"GWorkspace"; Line 217  static NSString *gwName = @"GWorkspace";
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];
# Line 841  static NSString *gwName = @"GWorkspace"; Line 831  static NSString *gwName = @"GWorkspace";
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    
# Line 961  static NSString *gwName = @"GWorkspace"; Line 986  static NSString *gwName = @"GWorkspace";
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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26