mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-07 09:28:02 +00:00
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!
This commit is contained in:
1 parent
58bf7bd832
commit
f3706b04a1
5 files changed
+67
-20
No files matched your search
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user