PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/BlendKit/objj.platform/BKUtilities.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 145 lines | 118 code | 27 blank | 0 comment | 0 complexity | 9773b21362d1ceef2b1ceb6f2916b220 MD5 | raw file
  1c;4385;
  2
  3
  4{var the_class = objj_allocateClassPair(CPObject, "BKThemeTemplate"),
  5meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_name"), new objj_ivar("_description")]);
  6objj_registerClassPair(the_class);
  7objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  8class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function(self, _cmd, aCoder)
  9{ with(self)
 10{
 11    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
 12
 13    if (self)
 14    {
 15        _name = objj_msgSend(aCoder, "decodeObjectForKey:", "BKThemeTemplateName");
 16        _description = objj_msgSend(aCoder, "decodeObjectForKey:", "BKThemeTemplateDescription");
 17    }
 18
 19    return self;
 20}
 21}), new objj_method(sel_getUid("encodeWithCoder:"), function(self, _cmd, aCoder)
 22{ with(self)
 23{
 24    objj_msgSend(aCoder, "encodeObject:forKey:", _name, "BKThemeTemplateName");
 25    objj_msgSend(aCoder, "encodeObject:forKey:", _description, "BKThemeTemplateDescription");
 26}
 27})]);
 28}
 29
 30{var the_class = objj_allocateClassPair(CPView, "BKThemeObjectTemplate"),
 31meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_label"), new objj_ivar("_themedObject")]);
 32objj_registerClassPair(the_class);
 33objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 34class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function(self, _cmd, aCoder)
 35{ with(self)
 36{
 37    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPView") }, "init");
 38
 39    if (self)
 40    {
 41        _label = objj_msgSend(aCoder, "decodeObjectForKey:", "BKThemeObjectTemplateLabel");
 42        _themedObject = objj_msgSend(aCoder, "decodeObjectForKey:", "BKThemeObjectTemplateThemedObject");
 43    }
 44
 45    return self;
 46}
 47}), new objj_method(sel_getUid("encodeWithCoder:"), function(self, _cmd, aCoder)
 48{ with(self)
 49{
 50    objj_msgSend(aCoder, "encodeObject:forKey:", _label, "BKThemeObjectTemplateLabel");
 51    objj_msgSend(aCoder, "encodeObject:forKey:", _themedObject, "BKThemeObjectTemplateThemedObject");
 52}
 53})]);
 54}
 55
 56BKThemeDescriptorClasses= function()
 57{
 58
 59    var themeDescriptorClasses = [];
 60
 61    for (candidate in window)
 62    {
 63        var theClass = objj_getClass(candidate),
 64            theClassName = class_getName(theClass),
 65            index = theClassName.indexOf("ThemeDescriptor");
 66
 67        if ((index >= 0) && (index === theClassName.length - "ThemeDescriptor".length))
 68            themeDescriptorClasses.push(theClass);
 69    }
 70
 71    return themeDescriptorClasses;
 72}
 73
 74BKThemeObjectTemplatesForClass= function(aClass)
 75{
 76    var templates = [],
 77        methods = class_copyMethodList(aClass.isa),
 78        count = objj_msgSend(methods, "count");
 79
 80    while (count--)
 81    {
 82        var method = methods[count],
 83            selector = method_getName(method);
 84
 85        if (selector.indexOf("themed") === 0)
 86        {
 87            var impl = method_getImplementation(method),
 88                object = impl(aClass, selector);
 89
 90            if (object)
 91            {
 92                var template = objj_msgSend(objj_msgSend(BKThemeObjectTemplate, "alloc"), "init");
 93
 94                objj_msgSend(template, "setValue:forKey:", object, "themedObject");
 95                objj_msgSend(template, "setValue:forKey:", BKLabelFromIdentifier(selector), "label");
 96
 97                objj_msgSend(templates, "addObject:", template);
 98            }
 99        }
100    }
101
102    return templates;
103}
104
105BKLabelFromIdentifier= function(anIdentifier)
106{
107    var string = anIdentifier.substr("themed".length);
108        index = 0,
109        count = string.length,
110        label = "",
111        lastCapital = null,
112        isLeadingCapital = YES;
113
114    for (; index < count; ++index)
115    {
116        var character = string.charAt(index),
117            isCapital = /^[A-Z]/.test(character);
118
119        if (isCapital)
120        {
121            if (!isLeadingCapital)
122            {
123                if (lastCapital === null)
124                    label += ' ' + character.toLowerCase();
125                else
126                    label += character;
127            }
128
129            lastCapital = character;
130        }
131        else
132        {
133            if (isLeadingCapital && lastCapital !== null)
134                label += lastCapital;
135
136            label += character;
137
138            lastCapital = null;
139            isLeadingCapital = NO;
140        }
141    }
142
143    return label;
144}
145