mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-03 15:30:42 +00:00
Allow themes to override only a "base" image like
common_3DArrowRight and have images that map to it (NSMenuArrow) automatically update. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36474 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fa82e4c865
commit
709dcde42d
3 changed files with 90 additions and 5 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2013-04-06 Eric Wasylishen <ewasylishen@gmail.com>
|
||||||
|
|
||||||
|
* Source/GSTheme.m:
|
||||||
|
* Source/NSImage.m: Allow themes to override only a "base" image like
|
||||||
|
common_3DArrowRight and have images that map to it (NSMenuArrow)
|
||||||
|
automatically update.
|
||||||
|
|
||||||
2013-04-03 Fred Kiefer <FredKiefer@gmx.de>
|
2013-04-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Tools/speech/GSSpeechSynthesizer.m: Use object_getClass()
|
* Tools/speech/GSSpeechSynthesizer.m: Use object_getClass()
|
||||||
|
|
|
@ -208,6 +208,7 @@ GSStringFromBorderType(NSBorderType borderType)
|
||||||
|
|
||||||
@interface NSImage (Private)
|
@interface NSImage (Private)
|
||||||
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
|
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
|
||||||
|
+ (NSDictionary *) _nameToPathDictionaryWithMappings: (NSDictionary*)pathForName;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GSTheme (Private)
|
@interface GSTheme (Private)
|
||||||
|
@ -452,6 +453,9 @@ typedef struct {
|
||||||
NSDictionary *infoDict;
|
NSDictionary *infoDict;
|
||||||
NSWindow *window;
|
NSWindow *window;
|
||||||
GSThemeControlState state;
|
GSThemeControlState state;
|
||||||
|
NSMutableDictionary *themeImagePathForName;
|
||||||
|
NSDictionary *themeImagePathForNameWithMappings;
|
||||||
|
NSString *imageName;
|
||||||
|
|
||||||
NSDebugMLLog(@"GSTheme", @"%@ %p", [self name], self);
|
NSDebugMLLog(@"GSTheme", @"%@ %p", [self name], self);
|
||||||
/* Get rid of any cached colors list so that we regenerate it when needed
|
/* Get rid of any cached colors list so that we regenerate it when needed
|
||||||
|
@ -473,6 +477,7 @@ typedef struct {
|
||||||
imagePaths = [_bundle pathsForResourcesOfType: nil
|
imagePaths = [_bundle pathsForResourcesOfType: nil
|
||||||
inDirectory: @"ThemeImages"];
|
inDirectory: @"ThemeImages"];
|
||||||
enumerator = [imagePaths objectEnumerator];
|
enumerator = [imagePaths objectEnumerator];
|
||||||
|
themeImagePathForName = [[NSMutableDictionary alloc] init];
|
||||||
while ((imagePath = [enumerator nextObject]) != nil)
|
while ((imagePath = [enumerator nextObject]) != nil)
|
||||||
{
|
{
|
||||||
NSString *ext = [imagePath pathExtension];
|
NSString *ext = [imagePath pathExtension];
|
||||||
|
@ -483,11 +488,29 @@ typedef struct {
|
||||||
|
|
||||||
imageName = [imagePath lastPathComponent];
|
imageName = [imagePath lastPathComponent];
|
||||||
imageName = [imageName stringByDeletingPathExtension];
|
imageName = [imageName stringByDeletingPathExtension];
|
||||||
[_imageNames addObject: imageName];
|
[themeImagePathForName setObject: imagePath forKey: imageName];
|
||||||
[NSImage _setImagePath: imagePath name: imageName];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "Expand" the themeImagePathForName dictionary by applying the
|
||||||
|
* mappings in nsmappings.strings.
|
||||||
|
*
|
||||||
|
* e.g. if the theme defines
|
||||||
|
* common_3DArrowRight but not NSMenuArrow, this will add an entry
|
||||||
|
* for NSMenuArrow pointing at the common_3DArrowRight path.
|
||||||
|
*/
|
||||||
|
themeImagePathForNameWithMappings = [NSImage _nameToPathDictionaryWithMappings: themeImagePathForName];
|
||||||
|
DESTROY(themeImagePathForName);
|
||||||
|
|
||||||
|
enumerator = [themeImagePathForNameWithMappings keyEnumerator];
|
||||||
|
while ((imageName = [enumerator nextObject]) != nil)
|
||||||
|
{
|
||||||
|
imagePath = [themeImagePathForNameWithMappings objectForKey: imageName];
|
||||||
|
[NSImage _setImagePath: imagePath name: imageName];
|
||||||
|
[_imageNames addObject: imageName];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use the GSThemeDomain key in the info dictionary of the theme to
|
* Use the GSThemeDomain key in the info dictionary of the theme to
|
||||||
* set a defaults domain which will establish user defaults values
|
* set a defaults domain which will establish user defaults values
|
||||||
|
|
|
@ -120,6 +120,7 @@ BOOL NSImageForceCaching = NO; /* use on missmatch */
|
||||||
static NSRecursiveLock *imageLock = nil;
|
static NSRecursiveLock *imageLock = nil;
|
||||||
static NSMutableDictionary *nameDict = nil;
|
static NSMutableDictionary *nameDict = nil;
|
||||||
static NSDictionary *nsmapping = nil;
|
static NSDictionary *nsmapping = nil;
|
||||||
|
static NSMutableDictionary *nsmapping_inverse = nil;
|
||||||
static NSColor *clearColor = nil;
|
static NSColor *clearColor = nil;
|
||||||
static Class cachedClass = 0;
|
static Class cachedClass = 0;
|
||||||
static Class bitmapClass = 0;
|
static Class bitmapClass = 0;
|
||||||
|
@ -154,6 +155,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
||||||
|
|
||||||
@interface NSImage (Private)
|
@interface NSImage (Private)
|
||||||
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
|
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
|
||||||
|
+ (NSDictionary *) _nameToPathDictionaryWithMappings: (NSDictionary*)pathForName;
|
||||||
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
|
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
|
||||||
+ (NSString *) _pathForImageNamed: (NSString *)aName;
|
+ (NSString *) _pathForImageNamed: (NSString *)aName;
|
||||||
- (BOOL) _useFromFile: (NSString *)fileName;
|
- (BOOL) _useFromFile: (NSString *)fileName;
|
||||||
|
@ -184,8 +186,31 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
||||||
ofType: @"strings"
|
ofType: @"strings"
|
||||||
inDirectory: @"Images"];
|
inDirectory: @"Images"];
|
||||||
if (path)
|
if (path)
|
||||||
|
{
|
||||||
|
NSEnumerator *e;
|
||||||
|
NSString *nsName;
|
||||||
|
|
||||||
|
// read NS image name to GS image name mapping
|
||||||
nsmapping = RETAIN([[NSString stringWithContentsOfFile: path]
|
nsmapping = RETAIN([[NSString stringWithContentsOfFile: path]
|
||||||
propertyListFromStringsFileFormat]);
|
propertyListFromStringsFileFormat]);
|
||||||
|
|
||||||
|
// create a GS image name to array of NS image names dict
|
||||||
|
nsmapping_inverse = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
|
e = [nsmapping keyEnumerator];
|
||||||
|
while ((nsName = [e nextObject]) != nil)
|
||||||
|
{
|
||||||
|
NSString *gsName = [nsmapping objectForKey: nsName];
|
||||||
|
|
||||||
|
NSMutableArray *nsNames = [nsmapping_inverse objectForKey: gsName];
|
||||||
|
if (nsNames == nil)
|
||||||
|
{
|
||||||
|
nsNames = [NSMutableArray array];
|
||||||
|
[nsmapping_inverse setObject: nsNames forKey: gsName];
|
||||||
|
}
|
||||||
|
[nsNames addObject: nsName];
|
||||||
|
}
|
||||||
|
}
|
||||||
clearColor = RETAIN([NSColor clearColor]);
|
clearColor = RETAIN([NSColor clearColor]);
|
||||||
cachedClass = [NSCachedImageRep class];
|
cachedClass = [NSCachedImageRep class];
|
||||||
bitmapClass = [NSBitmapImageRep class];
|
bitmapClass = [NSBitmapImageRep class];
|
||||||
|
@ -1908,7 +1933,7 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
|
||||||
}
|
}
|
||||||
[image setName: name];
|
[image setName: name];
|
||||||
}
|
}
|
||||||
else
|
else if (image != nil)
|
||||||
{
|
{
|
||||||
if (nil == path)
|
if (nil == path)
|
||||||
{
|
{
|
||||||
|
@ -1925,6 +1950,36 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
|
||||||
[imageLock unlock];
|
[imageLock unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expands a name->path dictionary by applying all of the nsmappings.strings
|
||||||
|
* mappings.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary *) _nameToPathDictionaryWithMappings: (NSDictionary*)pathForName
|
||||||
|
{
|
||||||
|
NSMutableDictionary *finalDict = [NSMutableDictionary dictionaryWithDictionary: pathForName];
|
||||||
|
NSEnumerator *e;
|
||||||
|
NSString *name;
|
||||||
|
|
||||||
|
e = [pathForName keyEnumerator];
|
||||||
|
while ((name = [e nextObject]) != nil)
|
||||||
|
{
|
||||||
|
NSString *path = [pathForName objectForKey: name];
|
||||||
|
NSEnumerator *namesMappedToNameEnumerator;
|
||||||
|
NSString *mappedName;
|
||||||
|
|
||||||
|
namesMappedToNameEnumerator = [[nsmapping_inverse objectForKey: name] objectEnumerator];
|
||||||
|
while ((mappedName = [namesMappedToNameEnumerator nextObject]) != nil)
|
||||||
|
{
|
||||||
|
if ([pathForName objectForKey: mappedName] == nil)
|
||||||
|
{
|
||||||
|
[finalDict setObject: path forKey: mappedName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalDict;
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSString *) _pathForImageNamed: (NSString *)aName
|
+ (NSString *) _pathForImageNamed: (NSString *)aName
|
||||||
{
|
{
|
||||||
NSString *realName = [nsmapping objectForKey: aName];
|
NSString *realName = [nsmapping objectForKey: aName];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue