/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

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