mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 05:01:11 +00:00
Allow loading from an absolute path
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/themes@23667 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1a87c5ff11
commit
19a0eab892
1 changed files with 36 additions and 18 deletions
|
@ -162,6 +162,7 @@ typedef enum {
|
||||||
@implementation GSTheme
|
@implementation GSTheme
|
||||||
|
|
||||||
static GSTheme *defaultTheme = nil;
|
static GSTheme *defaultTheme = nil;
|
||||||
|
static NSString *defaultThemeName = nil;
|
||||||
static GSTheme *theTheme = nil;
|
static GSTheme *theTheme = nil;
|
||||||
static NSString *theThemeName = nil;
|
static NSString *theThemeName = nil;
|
||||||
static NSMutableDictionary *themes = nil;
|
static NSMutableDictionary *themes = nil;
|
||||||
|
@ -174,8 +175,9 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
defs = [NSUserDefaults standardUserDefaults];
|
defs = [NSUserDefaults standardUserDefaults];
|
||||||
name = [defs stringForKey: @"GSTheme"];
|
name = [defs stringForKey: @"GSTheme"];
|
||||||
if (name != theThemeName && [name isEqual: theThemeName] == NO)
|
if (name != defaultThemeName && [name isEqual: defaultThemeName] == NO)
|
||||||
{
|
{
|
||||||
|
ASSIGN(defaultThemeName, name); // Don't try to load again.
|
||||||
[self loadThemeNamed: name];
|
[self loadThemeNamed: name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +187,6 @@ static NSNull *null = nil;
|
||||||
if (themes == nil)
|
if (themes == nil)
|
||||||
{
|
{
|
||||||
themes = [NSMutableDictionary new];
|
themes = [NSMutableDictionary new];
|
||||||
[self theme]; // Initialise/create the default theme
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
addObserver: self
|
addObserver: self
|
||||||
selector: @selector(defaultsDidChange:)
|
selector: @selector(defaultsDidChange:)
|
||||||
|
@ -203,6 +204,9 @@ static NSNull *null = nil;
|
||||||
defaultTheme = [[self alloc] initWithBundle: aBundle];
|
defaultTheme = [[self alloc] initWithBundle: aBundle];
|
||||||
ASSIGN(theTheme, defaultTheme);
|
ASSIGN(theTheme, defaultTheme);
|
||||||
}
|
}
|
||||||
|
/* Establish the theme specified by the user defaults (if any);
|
||||||
|
*/
|
||||||
|
[self defaultsDidChange: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL) loadThemeNamed: (NSString*)aName
|
+ (BOOL) loadThemeNamed: (NSString*)aName
|
||||||
|
@ -214,15 +218,14 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
if ([aName length] == 0)
|
if ([aName length] == 0)
|
||||||
{
|
{
|
||||||
|
DESTROY(theThemeName);
|
||||||
[self setTheme: nil];
|
[self setTheme: nil];
|
||||||
[self theme];
|
[self theme];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure that the theme name does not contain path components
|
/* Ensure that the theme name has the 'theme' extension.
|
||||||
* and has the 'theme' extension.
|
|
||||||
*/
|
*/
|
||||||
aName = [aName lastPathComponent];
|
|
||||||
if ([[aName pathExtension] isEqualToString: @"theme"] == YES)
|
if ([[aName pathExtension] isEqualToString: @"theme"] == YES)
|
||||||
{
|
{
|
||||||
theme = aName;
|
theme = aName;
|
||||||
|
@ -236,15 +239,28 @@ static NSNull *null = nil;
|
||||||
if (bundle == nil)
|
if (bundle == nil)
|
||||||
{
|
{
|
||||||
NSString *path;
|
NSString *path;
|
||||||
NSEnumerator *enumerator;
|
|
||||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||||
|
BOOL isDir;
|
||||||
|
|
||||||
|
/* A theme may be either an absolute path or a filename to be located
|
||||||
|
* in the Themes subdirectory of one of the standard Library directories.
|
||||||
|
*/
|
||||||
|
if ([theme isAbsolutePath] == YES)
|
||||||
|
{
|
||||||
|
if ([mgr fileExistsAtPath: theme isDirectory: &isDir] == YES
|
||||||
|
&& isDir == YES)
|
||||||
|
{
|
||||||
|
path = theme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSEnumerator *enumerator;
|
||||||
|
|
||||||
enumerator = [NSSearchPathForDirectoriesInDomains
|
enumerator = [NSSearchPathForDirectoriesInDomains
|
||||||
(NSAllLibrariesDirectory, NSAllDomainsMask, YES) objectEnumerator];
|
(NSAllLibrariesDirectory, NSAllDomainsMask, YES) objectEnumerator];
|
||||||
while ((path = [enumerator nextObject]) != nil)
|
while ((path = [enumerator nextObject]) != nil)
|
||||||
{
|
{
|
||||||
BOOL isDir;
|
|
||||||
|
|
||||||
path = [path stringByAppendingPathComponent: @"Themes"];
|
path = [path stringByAppendingPathComponent: @"Themes"];
|
||||||
path = [path stringByAppendingPathComponent: theme];
|
path = [path stringByAppendingPathComponent: theme];
|
||||||
if ([mgr fileExistsAtPath: path isDirectory: &isDir])
|
if ([mgr fileExistsAtPath: path isDirectory: &isDir])
|
||||||
|
@ -252,6 +268,7 @@ static NSNull *null = nil;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (path == nil)
|
if (path == nil)
|
||||||
{
|
{
|
||||||
|
@ -271,6 +288,7 @@ static NSNull *null = nil;
|
||||||
{
|
{
|
||||||
cls = self;
|
cls = self;
|
||||||
}
|
}
|
||||||
|
ASSIGN(theThemeName, theme);
|
||||||
instance = [[cls alloc] initWithBundle: bundle];
|
instance = [[cls alloc] initWithBundle: bundle];
|
||||||
[self setTheme: instance];
|
[self setTheme: instance];
|
||||||
RELEASE(instance);
|
RELEASE(instance);
|
||||||
|
|
Loading…
Reference in a new issue