Permalink
Browse files

Trying to integrate CPTabView into Atlas ... no luck so far!

  • Loading branch information...
1 parent 170ce66 commit 3c8e264f3071045eb80169c29794761822ce9e43 @aldrinmartoq committed Apr 26, 2011
View
@@ -6,7 +6,7 @@
@import <AtlasKit/AtlasKit.j>
@import "GoogleMapsView.j"
-@import "GoogleMapsView.j"
+@import "RutTextField.j"
@implementation AldrinKitPlugin : AKPlugin {
}
@@ -29,6 +29,14 @@
} recursively:YES] forKey:@"CPTableView"];
[_classDescriptions setObject:[CPDictionary dictionaryWithJSObject:{
+ "ClassName" : "CPTabView",
+ "SuperClass" : "CPView",
+ "Outlets" : {
+ "delegate" : "id"
+ }
+ } recursively:YES] forKey:@"CPTableView"];
+
+ [_classDescriptions setObject:[CPDictionary dictionaryWithJSObject:{
"ClassName" : "GoogleMapsView",
"SuperClass" : "CPView",
"Outlets" : {
@@ -5,14 +5,14 @@
// Copyright (C) 2011 Aldrin Martoq.
@import <AtlasKit/AtlasKit.j>
-@import <AppKit/CPButton.j>
@implementation CPControlAttributeInspector : AKInspector {
@outlet CPPopUpButton align;
@outlet CPTextField fontSize;
@outlet CPButton bold;
@outlet CPButton underline;
@outlet CPButton italic;
+ @outlet CPCheckBox border;
}
- (CPString)label {
@@ -47,19 +47,34 @@
}
}
+- (@action)border:(id)sender {
+ var inspectedObjects = [self inspectedObjects];
+ var v = [border state];
+ CPLog.debug("border change: " + v);
+ for (var i=0,len=inspectedObjects.length; i< len; i++) {
+ var o = inspectedObjects[i];
+ if ([o respondsToSelector:@selector(setBordered:)]) {
+ [o setBordered:v];
+ }
+ }
+}
+
- (void)refresh {
var inspectedObjects = [self inspectedObjects];
var oldVal = null;
for (var i=0,len=inspectedObjects.length; i< len; i++) {
- var newVal = [inspectedObjects[i] alignment];
+ var o = inspectedObjects[i];
+ var newVal = [o alignment];
if (oldVal != null && oldVal != newVal) {
- [align selectItem:null];
- return;
+ oldVal = null;
+ break;
}
oldVal = newVal;
}
[align selectItemAtIndex:oldVal];
+
+ [border takeValueFromKeyPath:"bordered" ofObjects:inspectedObjects];
}
@end
View
@@ -0,0 +1,17 @@
+// CPTabView+Integration.j
+// AldrinKit
+//
+// Created by Aldrin Martoq on April 22, 2011.
+// Copyright (C) 2011 Aldrin Martoq.
+
+@import "CPTabViewAttributeInspector.j"
+
+@implementation CPTabView (Integration)
+
+- (void)atlasPopulateAttributeInspectorClasses:(CPMutableArray)classes {
+ [super atlasPopulateAttributeInspectorClasses:classes];
+
+ [classes addObject:[CPTabViewAttributeInspector class]];
+}
+
+@end
@@ -0,0 +1,127 @@
+// CPTabViewAttributeInspector.j
+// AldrinKit
+//
+// Created by Aldrin Martoq on April 22, 2011.
+// Copyright (C) 2011 Aldrin Martoq.
+
+@import <AtlasKit/AtlasKit.j>
+
+@implementation CPTabViewAttributeInspector : AKInspector {
+ @outlet CPTableView viewsTable;
+ CPTableColumn viewsTableTitle;
+ CPTableColumn viewsTableIdentifier;
+ @outlet CPButton viewsAdd;
+ @outlet CPButton viewsRemove;
+ CPTabView tabView;
+}
+
+- (CPString)label {
+ return @"Tab View";
+}
+
+- (CPString)viewCibName {
+ return @"CPTabViewAttributeInspector";
+}
+
+- (void)awakeFromCib {
+ var cols = [viewsTable tableColumns];
+ viewsTableTitle = cols[0];
+ viewsTableIdentifier = cols[1];
+
+ [viewsTable setDelegate:self];
+ [viewsTable setDataSource:self];
+}
+
+- (void)refresh {
+ var inspectedObjects = [self inspectedObjects];
+
+ if ([inspectedObjects count] != 1) {
+ [viewsTable setEnabled:NO];
+ tabView = null;
+ } else {
+ [viewsTable setEnabled:YES];
+ tabView = inspectedObjects[0];
+ }
+
+ [viewsTable reloadData];
+}
+
+- (@action)addView:(id)aSender {
+ var len = [tabView numberOfTabViewItems];
+ var identifier = "" + (len + 1);
+ var name = "Tab " + identifier;
+
+ var v = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth([tabView bounds]), 50.0)];
+
+ var tabViewItem = [[CPTabViewItem alloc] initWithIdentifier:identifier];
+ [tabViewItem setLabel:name];
+ [tabViewItem setView:v];
+
+ [tabView addTabViewItem:tabViewItem];
+ [tabView selectLastTabViewItem:null];
+ [viewsTable reloadData];
+ // var cols = [tableView tableColumns];
+ // var identifier = "" + cols.length;
+ // var name = "Column " + identifier;
+ //
+ // var col = [[CPTableColumn alloc] initWithIdentifier:identifier];
+ // [[col headerView] setStringValue:name];
+ // [[col headerView] sizeToFit];
+ // [tableView addTableColumn:col];
+ //
+ // [tableColumnsTable reloadData];
+ // [tableView display];
+}
+
+- (@action)removeView:(id)aSender {
+ // var rowIndex = [tableColumnsTable selectedRow];
+ // var cols = [tableView tableColumns];
+ //
+ // if (rowIndex < 0) {
+ // return;
+ // }
+ // var tableColumn = cols[rowIndex];
+ //
+ // [tableView removeTableColumn:tableColumn];
+ //
+ // [tableColumnsTable reloadData];
+ // [tableView display];
+}
+
+@end
+
+@implementation CPTabViewAttributeInspector (CPTableView)
+
+- (int)numberOfRowsInTableView:(CPTableView)aTableView {
+ return [tabView numberOfTabViewItems];
+}
+
+- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(int)rowIndex {
+ var viewItems = [tabView tabViewItems];
+
+ if (aTableColumn == viewsTableTitle) {
+ return [viewItems[rowIndex] label];
+ } else if (aTableColumn == viewsTableIdentifier) {
+ return [viewItems[rowIndex] identifier];
+ }
+
+ return '-';
+}
+
+- (void)tableView:(CPTableView)aTableView setObjectValue: (CPControl)anObject forTableColumn:(CPTableColumn)aTableColumn row:(int)rowIndex {
+ var viewItems = [tabView tabViewItems];
+
+ if (aTableColumn == viewsTableTitle) {
+ [viewItems[rowIndex] setLabel:anObject];
+ [tabView _updateItems];
+ } else if (aTableColumn == viewsTableIdentifier) {
+ [viewItems[rowIndex] setIdentifier:anObject];
+ }
+}
+
+- (void)tableViewSelectionDidChange:(CPNotification)aNotification {
+ var rowIndex = [viewsTable selectedRow];
+ [viewsRemove setEnabled:(rowIndex >= 0)];
+}
+
+@end
Oops, something went wrong.

0 comments on commit 3c8e264

Please sign in to comment.