From f3706b04a1098e4abca5dae7d451c586c36fcc34 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Sun, 22 Aug 2010 19:19:37 -0400 Subject: [PATCH] Proposed method of excluding themed objects from the theme showcase. - Also added class_respondsToSelector, it was a no-brainer. - Cleaned up trailing whitespace in CPThemeBlend.j. Woo-hoo! --- AppKit/CPThemeBlend.j | 6 +- AppKit/Themes/Aristo/ThemeDescriptors.j | 9 +++ AppKit/Themes/BlendKit/BKShowcaseController.j | 10 ++-- AppKit/Themes/BlendKit/BKThemeDescriptor.j | 55 +++++++++++++++---- Objective-J/Runtime.js | 7 +++ 5 files changed, 67 insertions(+), 20 deletions(-) diff --git a/AppKit/CPThemeBlend.j b/AppKit/CPThemeBlend.j index cf523037a..d0f0baf23 100644 --- a/AppKit/CPThemeBlend.j +++ b/AppKit/CPThemeBlend.j @@ -40,19 +40,19 @@ - (id)initWithContentsOfURL:(CPURL)aURL { self = [super init]; - + if (self) { _bundle = [[CPBundle alloc] initWithPath:aURL]; } - + return self; } - (void)loadWithDelegate:(id)aDelegate { _loadDelegate = aDelegate; - + [_bundle loadWithDelegate:self]; } diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index ec24fd503..b78624bb0 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -298,6 +298,10 @@ var themedButtonValues = nil, return @"Aristo"; } ++ (CPArray)themeShowcaseExcludes +{ + return ["alert", "cornerview", "tableView", "tableDataView"]; +} + (CPButton)makeButton { @@ -1346,6 +1350,11 @@ var themedButtonValues = nil, return @"Aristo-HUD"; } ++ (CPArray)themeShowcaseExcludes +{ + return ["alert"]; +} + + (CPColor)defaultShowcaseBackgroundColor { return [CPColor blackColor]; diff --git a/AppKit/Themes/BlendKit/BKShowcaseController.j b/AppKit/Themes/BlendKit/BKShowcaseController.j index 71975723d..78bf30c78 100644 --- a/AppKit/Themes/BlendKit/BKShowcaseController.j +++ b/AppKit/Themes/BlendKit/BKShowcaseController.j @@ -137,7 +137,7 @@ var BKLearnMoreToolbarItemIdentifier = @"BKLearnMoreToolbarItemId [_themedObjectsCollectionView setMinItemSize:itemSize]; [_themedObjectsCollectionView setMaxItemSize:itemSize]; - [_themedObjectsCollectionView setContent:[themeDescriptorClass themedObjectTemplates]]; + [_themedObjectsCollectionView setContent:[themeDescriptorClass themedShowcaseObjectTemplates]]; [BKShowcaseCell setBackgroundColor:[themeDescriptorClass showcaseBackgroundColor]]; } @@ -249,12 +249,12 @@ var BKLearnMoreToolbarItemIdentifier = @"BKLearnMoreToolbarItemId - (void)changeState:(id)aSender { - var themedObjectTemplates = [[self selectedThemeDescriptor] themedObjectTemplates], - count = [themedObjectTemplates count]; + var themedShowcaseObjectTemplates = [[self selectedThemeDescriptor] themedShowcaseObjectTemplates], + count = [themedShowcaseObjectTemplates count]; while (count--) { - var themedObject = [themedObjectTemplates[count] valueForKey:@"themedObject"]; + var themedObject = [themedShowcaseObjectTemplates[count] valueForKey:@"themedObject"]; if ([themedObject respondsToSelector:@selector(setEnabled:)]) [themedObject setEnabled:[aSender title] === @"Enabled" ? YES : NO]; @@ -324,7 +324,7 @@ var SelectionColor = nil; [self addSubview:_label]; } - [_label setStringValue:[aThemeDescriptor themeName] + " (" + [[aThemeDescriptor themedObjectTemplates] count] + ")"]; + [_label setStringValue:[aThemeDescriptor themeName] + " (" + [[aThemeDescriptor themedShowcaseObjectTemplates] count] + ")"]; } - (void)setSelected:(BOOL)isSelected diff --git a/AppKit/Themes/BlendKit/BKThemeDescriptor.j b/AppKit/Themes/BlendKit/BKThemeDescriptor.j index 4841fb21e..9ec637754 100644 --- a/AppKit/Themes/BlendKit/BKThemeDescriptor.j +++ b/AppKit/Themes/BlendKit/BKThemeDescriptor.j @@ -25,6 +25,7 @@ var ItemSizes = { }, ThemedObjects = { }, + ThemedShowcaseObjects = { }, BackgroundColors = { }, LightCheckersColor = nil, @@ -120,15 +121,38 @@ var ItemSizes = { }, return ThemedObjects[className]; } ++ (CPArray)themedShowcaseObjectTemplates +{ + var className = [self className]; + + if (!ThemedShowcaseObjects[className]) + [self calculateThemedObjectTemplates]; + + return ThemedShowcaseObjects[className]; +} + + (void)calculateThemedObjectTemplates { var templates = [], + showcaseTemplates = [], itemSize = CGSizeMake(0.0, 0.0), methods = class_copyMethodList([self class].isa), index = 0, - count = [methods count]; + count = [methods count], + excludes = []; - for (; index < count; ++index) + if (class_respondsToSelector(self, @selector(themeShowcaseExcludes))) + excludes = [self themeShowcaseExcludes]; + + for (; index < excludes.length; ++index) + { + var name = excludes[index]; + + if (name && name.indexOf("themed") !== 0) + excludes[index] = "themed" + name.charAt(0).toUpperCase() + name.substr(1); + } + + for (index = 0; index < count; ++index) { var method = methods[index], selector = method_getName(method); @@ -142,26 +166,32 @@ var ItemSizes = { }, if (!object) continue; - var template = [[BKThemedObjectTemplate alloc] init]; + var template = [[BKThemedObjectTemplate alloc] init], + excluded = [excludes containsObject:selector]; [template setValue:object forKey:@"themedObject"]; [template setValue:BKLabelFromIdentifier(selector) forKey:@"label"]; [templates addObject:template]; - if ([object isKindOfClass:[CPView class]]) + if (!excluded) { - var size = [object frame].size, - labelWidth = [[template valueForKey:@"label"] sizeWithFont:[CPFont boldSystemFontOfSize:12.0]].width + 20.0; + if ([object isKindOfClass:[CPView class]]) + { + var size = [object frame].size, + labelWidth = [[template valueForKey:@"label"] sizeWithFont:[CPFont boldSystemFontOfSize:12.0]].width + 20.0; - if (size.width > itemSize.width) - itemSize.width = size.width; + if (size.width > itemSize.width) + itemSize.width = size.width; - if (labelWidth > itemSize.width) - itemSize.width = labelWidth; + if (labelWidth > itemSize.width) + itemSize.width = labelWidth; - if (size.height > itemSize.height) - itemSize.height = size.height; + if (size.height > itemSize.height) + itemSize.height = size.height; + } + + [showcaseTemplates addObject:template]; } } @@ -169,6 +199,7 @@ var ItemSizes = { }, ItemSizes[className] = itemSize; ThemedObjects[className] = templates; + ThemedShowcaseObjects[className] = showcaseTemplates; } + (int)compare:(BKThemeDescriptor)aThemeDescriptor diff --git a/Objective-J/Runtime.js b/Objective-J/Runtime.js index 551113132..c003bd9ab 100644 --- a/Objective-J/Runtime.js +++ b/Objective-J/Runtime.js @@ -256,6 +256,13 @@ GLOBAL(class_getClassMethod) = function(/*Class*/ aClass, /*SEL*/ aSelector) DISPLAY_NAME(class_getClassMethod); +GLOBAL(class_respondsToSelector) = function(/*Class*/ aClass, /*SEL*/ aSelector) +{ + return class_getClassMethod(aClass, aSelector) != NULL; +} + +DISPLAY_NAME(class_respondsToSelector); + GLOBAL(class_copyMethodList) = function(/*Class*/ aClass) { return aClass.method_list.slice(0);