-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAppController.j
172 lines (129 loc) · 5.57 KB
/
AppController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* AppController.j
* TNKit-Example
*
* Created by You on October 29, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import <TNKit/TNKit.j>
@implementation AppController : CPObject
{
@outlet CPWindow theWindow;
@outlet CPWindow windowTooltip;
@outlet CPButton buttonShowQuickEditView;
@outlet CPButton buttonToolTip;
@outlet CPTextField title;
@outlet CPTextField fieldUserDefault;
@outlet TNTextFieldStepper stepper;
@outlet CPScrollView scrollViewTable;
@outlet CPSearchField filterField;
TNTableViewDataSource _datasource;
CPTableView _tableView;
BOOL _stepperImplemented;
}
- (void)awakeFromCib
{
if (typeof(CPStepper) == "undefined")
{
var message = @"If you want to see CPStepper you need to have a version of Cappuccino that implement it. "
+ "you can find one at http://github.com/primalmotion/cappuccino on branch 'integ'";
[TNAlert showAlertWithTitle:@"CPStepper" message:message];
_stepperImplemented = NO;
}
else
_stepperImplemented = YES;
[title setFont:[CPFont boldSystemFontOfSize:32]];
[title sizeToFit];
// TNUserDefault
var defaults = [TNUserDefaults standardUserDefaults];
[defaults setStorageType:TNUserDefaultStorageTypeHTML5];
[defaults registerDefaults:[CPDictionary dictionaryWithObjectsAndKeys:
@"Default", @"TNKitDefaultFieldValue"
]];
[fieldUserDefault setStringValue:[defaults objectForKey:@"TNKitDefaultFieldValue"]];
// TNTableViewDataSource
_datasource = [[TNTableViewDataSource alloc] init];
_tableView = [[CPTableView alloc] initWithFrame:[scrollViewTable bounds]];
[scrollViewTable setDocumentView:_tableView];
[scrollViewTable setAutohidesScrollers:YES];
var colA = [[CPTableColumn alloc] initWithIdentifier:@"name"],
colB = [[CPTableColumn alloc] initWithIdentifier:@"surname"];
[[colA headerView] setStringValue:@"Name"];
[[colB headerView] setStringValue:@"Surname"];
[_tableView addTableColumn:colA];
[_tableView addTableColumn:colB];
[_datasource setSearchableKeyPaths:[@"name", @"surname"]];
[_datasource setTable:_tableView];
[_tableView setDataSource:_datasource];
var content= [
[CPDictionary dictionaryWithObjectsAndKeys:@"Antoine", @"name", @"Mercadal", @"surname"],
[CPDictionary dictionaryWithObjectsAndKeys:@"Foo", @"name", @"Bar", @"surname"],
[CPDictionary dictionaryWithObjectsAndKeys:@"Spam", @"name", @"Egg", @"surname"]
];
[_datasource setContent:content];
[_tableView reloadData];
[filterField setTarget:_datasource];
[filterField setAction:@selector(filterObjects:)];
// TNToolbar
var toolbar = [[TNToolbar alloc] init],
bundle = [CPBundle mainBundle];
[toolbar addItemWithIdentifier:@"id1" label:@"Archipel" icon:[bundle pathForResource:@"item1.png"] target:self action:@selector(didToolbarItemClick:)];
[toolbar addItemWithIdentifier:@"id2" label:@"Logout" icon:[bundle pathForResource:@"item2.png"] target:self action:@selector(didToolbarItemClick:)];
[toolbar setPosition:1 forToolbarItemIdentifier:@"id1"];
[toolbar setPosition:2 forToolbarItemIdentifier:@"id2"];
[toolbar reloadToolbarItems];
[theWindow setToolbar:toolbar];
//TNToolTip
[buttonToolTip setToolTip:@"Hello world! I'm a tooltip!"];
[windowTooltip orderFront:nil];
}
- (IBAction)showQuickEditViewWhite:(id)sender
{
var quickEditView = [[TNAttachedWindow alloc] initWithContentRect:CPRectMake(0.0, 0.0, 200.0, 150.0)],
label = [CPTextField labelWithTitle:@"Hello World"];
[label sizeToFit];
[label setCenter:[[quickEditView contentView] center]];
[[quickEditView contentView] addSubview:label];
[quickEditView attachToView:sender];
}
- (IBAction)showQuickEditViewDark:(id)sender
{
var quickEditView = [[TNAttachedWindow alloc] initWithContentRect:CPRectMake(0.0, 0.0, 200.0, 150.0) themeColor:TNAttachedWindowThemeBlack],
label = [CPTextField labelWithTitle:@"Hello World"];
[label sizeToFit];
[label setTextColor:[CPColor whiteColor]];
[label setCenter:[[quickEditView contentView] center]];
[[quickEditView contentView] addSubview:label];
[quickEditView attachToView:sender];
}
- (IBAction)saveDefault:(id)sender
{
var defaults = [TNUserDefaults standardUserDefaults];
[defaults setObject:[fieldUserDefault stringValue] forKey:@"TNKitDefaultFieldValue"];
}
- (IBAction)clearDefault:(id)sender
{
// TNAlert example
var alert = [TNAlert alertWithTitle:@"Clear defaults ?"
message:@"You will erase all data in defaults. Are you sure man ?"
target:self
actions:[["Yes", @selector(performClearDefault:)], ["No", @selector(performLooser:)]]];
[alert runModal];
}
- (void)performClearDefault:(id)someUserInfo
{
var defaults = [TNUserDefaults standardUserDefaults];
[defaults clear];
[fieldUserDefault setStringValue:[defaults objectForKey:@"TNKitDefaultFieldValue"]];
}
- (void)performLooser:(id)someUserInfo
{
[TNAlert showAlertWithTitle:@"Hehe" message:@"Be a man!"];
}
- (IBAction)didToolbarItemClick:(id)sender
{
[[sender toolbar] selectToolbarItem:sender];
}
@end