mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
* Source/GSTheme.m:
* Source/NSImage.m: Revert previous commit and write a much cleaner implementation that fixes the same bug. I removed the step in theme activation where we call +[NSImage _setImagePath:name:] on each image in the theme, and instead modified +[NSImage _pathForImageNamed:] to also search the theme images directory. When a GSTheme activates now, it only calls +[NSImage _reloadCachedImages] which checks all NSImage cached by name and reloads any whose path has changed. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36482 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
23d47ca882
commit
67daa51afa
3 changed files with 59 additions and 62 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2013-04-06 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/GSTheme.m:
|
||||
* Source/NSImage.m: Revert previous commit and write a much cleaner
|
||||
implementation that fixes the same bug.
|
||||
|
||||
I removed the step in theme activation where we call
|
||||
+[NSImage _setImagePath:name:] on each image in the theme, and instead
|
||||
modified +[NSImage _pathForImageNamed:] to also search the theme images
|
||||
directory.
|
||||
|
||||
When a GSTheme activates now, it only calls +[NSImage _reloadCachedImages]
|
||||
which checks all NSImage cached by name and reloads any whose path has
|
||||
changed.
|
||||
|
||||
2013-04-06 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/GSTheme.m:
|
||||
|
|
|
@ -208,6 +208,7 @@ GSStringFromBorderType(NSBorderType borderType)
|
|||
|
||||
@interface NSImage (Private)
|
||||
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
|
||||
+ (void) _reloadCachedImages;
|
||||
@end
|
||||
|
||||
@interface GSTheme (Private)
|
||||
|
@ -446,9 +447,6 @@ typedef struct {
|
|||
NSUserDefaults *defs;
|
||||
NSMutableArray *searchList;
|
||||
NSEnumerator *enumerator;
|
||||
NSArray *imagePaths;
|
||||
NSString *imagePath;
|
||||
NSArray *imageTypes;
|
||||
NSDictionary *infoDict;
|
||||
NSWindow *window;
|
||||
GSThemeControlState state;
|
||||
|
@ -465,28 +463,9 @@ typedef struct {
|
|||
}
|
||||
|
||||
/*
|
||||
* We step through all the bundle image resources and load them in
|
||||
* to memory, setting their names so that they are visible to
|
||||
* [NSImage+imageNamed:] and storing them in our local array.
|
||||
* Reload NSImage's cache of image by name
|
||||
*/
|
||||
imageTypes = [_imageClass imageFileTypes];
|
||||
imagePaths = [_bundle pathsForResourcesOfType: nil
|
||||
inDirectory: @"ThemeImages"];
|
||||
enumerator = [imagePaths objectEnumerator];
|
||||
while ((imagePath = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSString *ext = [imagePath pathExtension];
|
||||
|
||||
if (ext != nil && [imageTypes containsObject: ext] == YES)
|
||||
{
|
||||
NSString *imageName;
|
||||
|
||||
imageName = [imagePath lastPathComponent];
|
||||
imageName = [imageName stringByDeletingPathExtension];
|
||||
[_imageNames addObject: imageName];
|
||||
[NSImage _setImagePath: imagePath name: imageName];
|
||||
}
|
||||
}
|
||||
[NSImage _reloadCachedImages];
|
||||
|
||||
/*
|
||||
* Use the GSThemeDomain key in the info dictionary of the theme to
|
||||
|
@ -707,9 +686,6 @@ typedef struct {
|
|||
|
||||
- (void) deactivate
|
||||
{
|
||||
NSEnumerator *enumerator;
|
||||
NSString *imageName;
|
||||
|
||||
NSDebugMLLog(@"GSTheme", @"%@ %p", [self name], self);
|
||||
|
||||
/* Tell everything that we will become inactive.
|
||||
|
@ -732,15 +708,6 @@ typedef struct {
|
|||
}
|
||||
}
|
||||
|
||||
/* Unload all images created by this theme.
|
||||
*/
|
||||
enumerator = [_imageNames objectEnumerator];
|
||||
while ((imageName = [enumerator nextObject]) != nil)
|
||||
{
|
||||
[NSImage _setImagePath: nil name: imageName];
|
||||
}
|
||||
[_imageNames removeAllObjects];
|
||||
|
||||
[self _revokeOwnerships];
|
||||
|
||||
/* Tell everything that we have become inactive.
|
||||
|
|
|
@ -154,8 +154,8 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
|||
|
||||
@interface NSImage (Private)
|
||||
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
|
||||
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
|
||||
+ (NSString *) _pathForImageNamed: (NSString *)aName;
|
||||
+ (void) _reloadCachedImages;
|
||||
- (BOOL) _useFromFile: (NSString *)fileName;
|
||||
- (BOOL) _loadFromData: (NSData *)data;
|
||||
- (BOOL) _loadFromFile: (NSString *)fileName;
|
||||
|
@ -1887,40 +1887,29 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
|
|||
DESTROY(imagePasteboardTypes);
|
||||
}
|
||||
|
||||
+ (void) _setImagePath: (NSString*)path name: (NSString*)name
|
||||
/**
|
||||
* For all NSImage instances cached in nameDict, recompute the
|
||||
* path using +_pathForImageNamed: and if it has changed,
|
||||
* reload the image contents using the new path.
|
||||
*/
|
||||
+ (void) _reloadCachedImages
|
||||
{
|
||||
NSImage *image;
|
||||
NSString *name;
|
||||
NSEnumerator *e;
|
||||
|
||||
[imageLock lock];
|
||||
image = (NSImage*)[nameDict objectForKey: name];
|
||||
if (nil == image && nil != path)
|
||||
e = [nameDict keyEnumerator];
|
||||
while ((name = [e nextObject]) != nil)
|
||||
{
|
||||
/* There was no existing image with the given name ...
|
||||
* create a new one.
|
||||
*/
|
||||
image = [[[[GSTheme theme] imageClass] alloc]
|
||||
initByReferencingFile: path];
|
||||
if (image != nil)
|
||||
{
|
||||
[image setName: name];
|
||||
image->_flags.archiveByName = YES;
|
||||
AUTORELEASE(image);
|
||||
}
|
||||
[image setName: name];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nil == path)
|
||||
{
|
||||
path = [self _pathForImageNamed: name];
|
||||
}
|
||||
if (path != nil && ![path isEqual: image->_fileName])
|
||||
NSImage *image = [nameDict objectForKey: name];
|
||||
NSString *path = [self _pathForImageNamed: name];
|
||||
if (![path isEqual: image->_fileName])
|
||||
{
|
||||
/* Reset the existing image to use the contents of
|
||||
* the specified file.
|
||||
*/
|
||||
[image _resetAndUseFromFile: path];
|
||||
}
|
||||
}
|
||||
}
|
||||
[imageLock unlock];
|
||||
}
|
||||
|
@ -1979,6 +1968,32 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If not found then search in the theme */
|
||||
if (!path)
|
||||
{
|
||||
NSBundle *themeBundle = [[GSTheme theme] bundle];
|
||||
if (ext)
|
||||
{
|
||||
path = [themeBundle pathForResource: realName
|
||||
ofType: ext
|
||||
inDirectory: @"ThemeImages"];
|
||||
}
|
||||
else
|
||||
{
|
||||
id o, e;
|
||||
|
||||
e = [array objectEnumerator];
|
||||
while ((o = [e nextObject]))
|
||||
{
|
||||
path = [themeBundle pathForResource: realName
|
||||
ofType: o
|
||||
inDirectory: @"ThemeImages"];
|
||||
if (path != nil && [path length] != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If not found then search in system */
|
||||
if (!path)
|
||||
|
|
Loading…
Reference in a new issue