Skip to content

Instantly share code, notes, and snippets.

View jarek-foksa's full-sized avatar

Jarek Foksa jarek-foksa

View GitHub Profile
// @events
// press
// release
var Button = registerElement("x-button", {
// @pragma mark model -----------------------------------------------------------------------
// Leading "&" means that the property is bound to attribute and that it will fire
// <propertyName>ChangedCallback() each time when either attribute or property is changed
// and the callback exists.
import Foundation
class NotificationCenter {
func addObserver(name: String, object: AnyObject, callback: (NSDictionary) -> Void ) -> NSObjectProtocol {
var observer : NSObjectProtocol = NSNotificationCenter.defaultCenter().addObserverForName(name, object: object, queue: nil, usingBlock: {
(notification : NSNotification!) in
callback(notification.userInfo)
})
return observer
import Cocoa
class MainMenuController : NSObject, NSMenuDelegate {
init() {
}
private func forEach(callback: (NSMenuItem)->()) {
func walk(menu: NSMenu) {
for item in menu.itemArray {
callback(item as NSMenuItem)
// @info
// Asynchronously iterate over each item of an array or an array-like object.
// The order in which items are iterated is guaranteed to match array order.
var iterateSeries = function (array, iterator, callback) {
array = Array.prototype.slice.call(array, 0);
if (array.length === 0) {
if (callback) callback();
}
else {
var space = {
id: "editor-1",
label: "Untitled",
type: "editor",
url: "frontend/editor.xhtml",
fileName: null,
loaded: false,
load() { editor.laod(...) }
};
import Foundation
class EventEmitter {
var _events : Dictionary<String, Dictionary<Int, (event: Any)->()>?> = [:]
var _eventsCounter : Int = 0
func addEventListener(eventName: String, listener: (event: Any) -> ()) -> (Int) {
_eventsCounter += 1
var optionalListeners = _events[eventName]
#import "BXWindow.h"
#import "INAppStoreWindow.h"
#import "INWindowButton.h"
#import "NSColor+hex.h"
@implementation BXWindow
-(void)awakeFromNib {
self.titleBarHeight = 24.0;
self.trafficLightButtonsLeftMargin = 8.0;
# http://svg-whiz.com/svg/starPrimative.svg
drawNGon: (cx, cy, r, rCorner, arms, shift = 0) ->
polyPoints = ''
if arms in [1,3,5,7,9]
orient = 'point'
else
orient = 'edge'
for s in [0..arms]
# http://svg-whiz.com/svg/starPrimative.svg
# Smoothing: http://www.codeproject.com/Articles/128705/WPF-rounded-corners-polygon
drawStar: (cx, cy, r1, r2, rCorner, arms, shift = 0) ->
polyPoints = null
segments = []
if arms in [1,3,5,7,9]
orient = 'point'
else
orient = 'edge'
RectShape =
$element: null
width: 100
height: 100
x: 0
y: 0
r1: 0 # top left
r2: 0 # top right
r3: 0 # bottom left