API  1.0.0
CPThemeBlend.j
Go to the documentation of this file.
1 /*
2  * CPThemeBlend.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2009, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 
25 
30 @implementation CPThemeBlend : CPObject
31 {
32  CPBundle _bundle;
33  CPArray _themes;
34  id _loadDelegate;
35 }
36 
37 - (id)initWithContentsOfURL:(CPURL)aURL
38 {
39  self = [super init];
40 
41  if (self)
42  {
43  _bundle = [[CPBundle alloc] initWithPath:aURL];
44  }
45 
46  return self;
47 }
48 
53 - (CPArray)themes
54 {
55  return _themes;
56 }
57 
61 - (CPArray)themeNames
62 {
63  return [_themes arrayByApplyingBlock:function(theme)
64  {
65  return theme.substring(0, theme.indexOf(".keyedtheme"));
66  }];
67 }
68 
69 - (void)loadWithDelegate:(id)aDelegate
70 {
71  _loadDelegate = aDelegate;
72 
73  [_bundle loadWithDelegate:self];
74 }
75 
76 - (void)bundleDidFinishLoading:(CPBundle)aBundle
77 {
78  _themes = [_bundle objectForInfoDictionaryKey:@"CPKeyedThemes"];
79 
80  var count = _themes.length;
81 
82  while (count--)
83  {
84  var path = [aBundle pathForResource:_themes[count]],
85  unarchiver = [[_CPThemeKeyedUnarchiver alloc]
86  initForReadingWithData:[[CPURL URLWithString:path] staticResourceData]
87  bundle:_bundle];
88 
89  [unarchiver decodeObjectForKey:@"root"];
90 
91  [unarchiver finishDecoding];
92  }
93 
94  // CSS Theming
95 
96  for (var i = 0, nb = [_themes count], allThemes = [self themeNames], aThemeName, aTheme; i < nb; i++)
97  {
98  aThemeName = allThemes[i];
99  aTheme = [CPTheme themeNamed:aThemeName];
100 
101  if ([aTheme isCSSBased])
102  [aTheme setCSSResourcesPath:[aBundle resourcePath]];
103  }
104 
105  [_loadDelegate blendDidFinishLoading:self];
106 }
107 
108 @end
109 
111 
115 - (CPBundle)bundle
116 {
117  return _bundle;
118 }
119 
120 @end
CPData staticResourceData()
Definition: CPURL.j:235
CPString pathForResource:(CPString aFilename)
Definition: CPBundle.j:158
CPString resourcePath()
Definition: CPBundle.j:129
id initWithPath:(CPString aPath)
Definition: CPBundle.j:109
id init()
Definition: CPObject.j:145
Definition: CPTheme.h:2
CPTheme themeNamed:(CPString aName)
Definition: CPTheme.j:70
id URLWithString:(CPString URLString)
Definition: CPURL.j:78
Definition: CPURL.h:2
id alloc()
Definition: CPObject.j:130