diff --git a/ChangeLog b/ChangeLog index d1f95867a..20f1033d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2012-06-29 Fred Kiefer + + * Source/NSWorkspace.m (-_openUnknown:): New method that starts an + operation system specific application for files or URL that could + not be handled by GNUstep applications. Based on patch by Julian + Mayer . + * Source/NSWorkspace.m (-openFile:withApplication:andDeactivate:, + -openTempFile:, -openURL:): Use this new method. + * Documentation/GuiUser/DefaultsSummary.gsdoc: Document the new + setting GSUnknownFileTool that allows to define a default application. + 2012-06-23 Fred Kiefer * Source/NSFontDescriptor.m: Small consistency updates. diff --git a/Documentation/GuiUser/DefaultsSummary.gsdoc b/Documentation/GuiUser/DefaultsSummary.gsdoc index a44cbe8d5..5439809de 100644 --- a/Documentation/GuiUser/DefaultsSummary.gsdoc +++ b/Documentation/GuiUser/DefaultsSummary.gsdoc @@ -178,6 +178,15 @@ is meant to make things friendlier for slow computers.

+ GSUnknownFileTool + +

+ A string value that defines a program that should be launched + when no GNUstep application has been defined for a specific + file extension or if an URL could not be opened by a service. + This program gets the file name or URL as parameter. +

+
GSUseFreedesktopThumbnails

diff --git a/Source/NSWorkspace.m b/Source/NSWorkspace.m index aa1adc853..9511578dd 100644 --- a/Source/NSWorkspace.m +++ b/Source/NSWorkspace.m @@ -765,6 +765,43 @@ static NSString *_rootPath = @"/"; /* * Opening Files */ +- (BOOL) _openUnknown: (NSString*)fullPath +{ + NSString *tool = [[NSUserDefaults standardUserDefaults] objectForKey: @"GSUnknownFileTool"]; + NSString *launchPath; + + if ((tool == nil) || (launchPath = [NSTask launchPathForTool: tool]) == nil) + { +#ifdef __MINGW32__ + // Maybe we should rather use "Explorer.exe /e, " as the tool name + unichar *buffer = (unichar *)calloc(1, ([fullPath length] + 1) * sizeof(unichar)); + [fullPath getCharacters: buffer range: NSMakeRange(0, [fullPath length])]; + buffer[[fullPath length]] = 0; + BOOL success = (ShellExecuteW(GetDesktopWindow(), L"open", buffer, NULL, + NULL, SW_SHOWNORMAL) > 32); + free(buffer); + return success; +#else + // Fall back to xdg-open + launchPath = [NSTask launchPathForTool: @"xdg-open"]; +#endif + } + + if (launchPath) + { + NSTask * task = [NSTask launchedTaskWithLaunchPath: launchPath + arguments: [NSArray arrayWithObject: fullPath]]; + if (task != nil) + { + [task waitUntilExit]; + if ([task terminationStatus] == 0) + return YES; + } + } + + return NO; +} + - (BOOL) openFile: (NSString*)fullPath { return [self openFile: fullPath withApplication: nil]; @@ -820,8 +857,15 @@ static NSString *_rootPath = @"/"; if ([self _extension: ext role: nil app: &appName] == NO) { - NSWarnLog(@"No known applications for file extension '%@'", ext); - return NO; + if ([self _openUnknown: fullPath]) + { + return YES; + } + else + { + NSWarnLog(@"No known applications for file extension '%@'", ext); + return NO; + } } } @@ -883,8 +927,15 @@ static NSString *_rootPath = @"/"; ext = [fullPath pathExtension]; if ([self _extension: ext role: nil app: &appName] == NO) { - NSWarnLog(@"No known applications for file extension '%@'", ext); - return NO; + if ([self _openUnknown: fullPath]) + { + return YES; + } + else + { + NSWarnLog(@"No known applications for file extension '%@'", ext); + return NO; + } } app = [self _connectApplication: appName]; @@ -928,7 +979,7 @@ static NSString *_rootPath = @"/"; appName = [self getBestAppInRole: nil forScheme: [url scheme]]; if (appName != nil) { - id app; + id app; /* Now try to get the application to open the URL. */ @@ -956,7 +1007,14 @@ static NSString *_rootPath = @"/"; [pb declareTypes: [NSArray arrayWithObject: NSURLPboardType] owner: nil]; [url writeToPasteboard: pb]; - return NSPerformService(@"OpenURL", pb); + if (NSPerformService(@"OpenURL", pb)) + { + return YES; + } + else + { + return [self _openUnknown: [url absoluteString]]; + } } }