Introduce (private) NSWorkspace notification to propagate changes of

the application or icon associated with a file type and URL scheme,
respectively.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31794 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
wlux 2010-12-29 12:19:00 +00:00
parent 466d891152
commit 56b66af36f
2 changed files with 96 additions and 42 deletions

View file

@ -1,3 +1,13 @@
2010-12-29 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSWorkspace.m(GSWorkspacePreferencesChanged, -init,
-findApplications, -setBestApp:inRole:forExtension:,
-setBestIcon:forExtension:, -setBestApp:inRole:forScheme:,
_workspacePreferencesChanged:):
Introduce (private) workspace notification to propagate changes of
the application or icon associated with a file type and URL
scheme, respectively.
2010-12-29 Wolfgang Lux <wolfgang.lux@gmail.com> 2010-12-29 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSDocument.m (-runModalSavePanel:withAccessoryView:): * Source/NSDocument.m (-runModalSavePanel:withAccessoryView:):

View file

@ -98,6 +98,8 @@ static NSImage *unknownTool = nil;
static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification"; static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification";
static NSString *GSWorkspacePreferencesChanged =
@"GSWorkspacePreferencesChanged";
/* /*
* Depending on the 'active' flag this returns either the currently * Depending on the 'active' flag this returns either the currently
@ -404,6 +406,7 @@ static id GSLaunched(NSNotification *notification, BOOL active)
- (BOOL) _scheme: (NSString*)scheme - (BOOL) _scheme: (NSString*)scheme
role: (NSString*)role role: (NSString*)role
app: (NSString**)app; app: (NSString**)app;
- (void) _workspacePreferencesChanged: (NSNotification *)aNotification;
// application communication // application communication
- (BOOL) _launchApplication: (NSString*)appName - (BOOL) _launchApplication: (NSString*)appName
@ -679,6 +682,11 @@ static NSString *_rootPath = @"/";
{ {
[self findApplications]; [self findApplications];
} }
[_workspaceCenter
addObserver: self
selector: @selector(_workspacePreferencesChanged:)
name: GSWorkspacePreferencesChanged
object: nil];
/* icon associtation and caching */ /* icon associtation and caching */
folderPathIconDict = [[NSMutableDictionary alloc] initWithCapacity:5]; folderPathIconDict = [[NSMutableDictionary alloc] initWithCapacity:5];
@ -1375,9 +1383,6 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
- (void) findApplications - (void) findApplications
{ {
static NSString *path = nil; static NSString *path = nil;
NSFileManager *mgr = [NSFileManager defaultManager];
NSData *data;
NSDictionary *dict;
NSTask *task; NSTask *task;
/* /*
@ -1393,42 +1398,9 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
{ {
[task waitUntilExit]; [task waitUntilExit];
} }
if ([mgr isReadableFileAtPath: extPrefPath] == YES) [self _workspacePreferencesChanged:
{ [NSNotification notificationWithName: GSWorkspacePreferencesChanged
data = [NSData dataWithContentsOfFile: extPrefPath]; object: self]];
if (data)
{
dict = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
ASSIGN(extPreferences, dict);
}
}
if ([mgr isReadableFileAtPath: urlPrefPath] == YES)
{
data = [NSData dataWithContentsOfFile: urlPrefPath];
if (data)
{
dict = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
ASSIGN(urlPreferences, dict);
}
}
if ([mgr isReadableFileAtPath: appListPath] == YES)
{
data = [NSData dataWithContentsOfFile: appListPath];
if (data)
{
dict = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
ASSIGN(applications, dict);
}
}
/*
* Invalidate the cache of icons for file extensions.
*/
[_iconMap removeAllObjects];
} }
/** /**
@ -2180,7 +2152,15 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
RELEASE(extPreferences); RELEASE(extPreferences);
extPreferences = map; extPreferences = map;
data = [NSSerializer serializePropertyList: extPreferences]; data = [NSSerializer serializePropertyList: extPreferences];
[data writeToFile: extPrefPath atomically: YES]; if ([data writeToFile: extPrefPath atomically: YES])
{
[_workspaceCenter postNotificationName: GSWorkspacePreferencesChanged
object: self];
}
else
{
NSLog(@"Update %@ of failed", extPrefPath);
}
} }
/** /**
@ -2211,7 +2191,15 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
RELEASE(extPreferences); RELEASE(extPreferences);
extPreferences = map; extPreferences = map;
data = [NSSerializer serializePropertyList: extPreferences]; data = [NSSerializer serializePropertyList: extPreferences];
[data writeToFile: extPrefPath atomically: YES]; if ([data writeToFile: extPrefPath atomically: YES])
{
[_workspaceCenter postNotificationName: GSWorkspacePreferencesChanged
object: self];
}
else
{
NSLog(@"Update %@ of failed", extPrefPath);
}
} }
/** /**
@ -2299,7 +2287,15 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
RELEASE(urlPreferences); RELEASE(urlPreferences);
urlPreferences = map; urlPreferences = map;
data = [NSSerializer serializePropertyList: urlPreferences]; data = [NSSerializer serializePropertyList: urlPreferences];
[data writeToFile: urlPrefPath atomically: YES]; if ([data writeToFile: urlPrefPath atomically: YES])
{
[_workspaceCenter postNotificationName: GSWorkspacePreferencesChanged
object: self];
}
else
{
NSLog(@"Update %@ of failed", urlPrefPath);
}
} }
@end @end
@ -2814,6 +2810,54 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
} }
} }
- (void) _workspacePreferencesChanged: (NSNotification *)aNotification
{
// FIXME reload only those preferences that really were changed
// TODO add a user info to aNotification, which includes a bitmask
// denoting the updated preference files.
NSFileManager *mgr = [NSFileManager defaultManager];
NSData *data;
NSDictionary *dict;
if ([mgr isReadableFileAtPath: extPrefPath] == YES)
{
data = [NSData dataWithContentsOfFile: extPrefPath];
if (data)
{
dict = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
ASSIGN(extPreferences, dict);
}
}
if ([mgr isReadableFileAtPath: urlPrefPath] == YES)
{
data = [NSData dataWithContentsOfFile: urlPrefPath];
if (data)
{
dict = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
ASSIGN(urlPreferences, dict);
}
}
if ([mgr isReadableFileAtPath: appListPath] == YES)
{
data = [NSData dataWithContentsOfFile: appListPath];
if (data)
{
dict = [NSDeserializer deserializePropertyListFromData: data
mutableContainers: NO];
ASSIGN(applications, dict);
}
}
/*
* Invalidate the cache of icons for file extensions.
*/
[_iconMap removeAllObjects];
}
/** /**
* Launch an application locally (ie without reference to the workspace * Launch an application locally (ie without reference to the workspace
* manager application). We should only call this method when we want * manager application). We should only call this method when we want