diff options
author | Johan Paulsson <gonz@badcode.net> | 2014-03-25 17:30:35 +0000 |
---|---|---|
committer | Johan Paulsson <gonz@badcode.net> | 2014-03-25 17:30:35 +0000 |
commit | 4c3a82c9146aa0e147b49b429b49fefb0e785a17 (patch) | |
tree | 532436ec35f19d6de54579734df22c20a8d67ca5 /tikzit/src | |
parent | 5532f8878b7219720de6145eabbe57efb894957c (diff) |
osx gui: custom nodes preference panel shows tikzit preview and tikz code for selected custom node.
Diffstat (limited to 'tikzit/src')
-rw-r--r-- | tikzit/src/common/TikzShape.h | 3 | ||||
-rw-r--r-- | tikzit/src/common/TikzShape.m | 4 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodeCellView.m | 10 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodeController.h | 6 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodeController.m | 53 |
5 files changed, 29 insertions, 47 deletions
diff --git a/tikzit/src/common/TikzShape.h b/tikzit/src/common/TikzShape.h index 1ccf658..6a91f91 100644 --- a/tikzit/src/common/TikzShape.h +++ b/tikzit/src/common/TikzShape.h @@ -25,8 +25,11 @@ #import "Shape.h" @interface TikzShape : Shape { + NSString *tikzSrc; } +@property (copy) NSString *tikzSrc; + - (id)initWithTikzFile:(NSString*)file; @end diff --git a/tikzit/src/common/TikzShape.m b/tikzit/src/common/TikzShape.m index 9735371..c07c61e 100644 --- a/tikzit/src/common/TikzShape.m +++ b/tikzit/src/common/TikzShape.m @@ -26,6 +26,8 @@ @implementation TikzShape +@synthesize tikzSrc; + - (id)initWithTikzFile:(NSString*)file { self = [super init]; if (self) { @@ -33,6 +35,8 @@ encoding:NSUTF8StringEncoding error:NULL]; if (tikz == nil) return nil; + + tikzSrc = [tikz copy]; Graph *graph = [Graph graphFromTikz:tikz]; if (graph == nil) return nil; diff --git a/tikzit/src/osx/CustomNodeCellView.m b/tikzit/src/osx/CustomNodeCellView.m index 57ef24a..612394b 100644 --- a/tikzit/src/osx/CustomNodeCellView.m +++ b/tikzit/src/osx/CustomNodeCellView.m @@ -31,8 +31,6 @@ } -(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context { - NSLog(@"drawing layer ^^"); - if (nodeLayer!=nil) { if (![[[self layer] sublayers] containsObject:nodeLayer]) { [[self layer] addSublayer:nodeLayer]; @@ -56,17 +54,23 @@ } - (void) setObjectValue:(id)objectValue{ - [[self textField] setStringValue:[(NodeStyle *)objectValue shapeName]]; + if(objectValue == nil) + return; + nodeStyle = (NodeStyle *)objectValue; + [[self textField] setStringValue:[nodeStyle shapeName]]; if (nodeLayer == nil) { nodeLayer = [[NodeLayer alloc] initWithNode:[Node node] transformer:[Transformer defaultTransformer]]; [nodeLayer setRescale:NO]; } + [nodeStyle setName:[nodeStyle shapeName]]; [[nodeLayer node] setStyle:nodeStyle]; [nodeLayer updateFrame]; + + NSLog(@"asd"); } - (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle { diff --git a/tikzit/src/osx/CustomNodeController.h b/tikzit/src/osx/CustomNodeController.h index 56cb74c..5553fcd 100644 --- a/tikzit/src/osx/CustomNodeController.h +++ b/tikzit/src/osx/CustomNodeController.h @@ -18,14 +18,16 @@ @interface CustomNodeController : NSViewController <NSTableViewDelegate>{ NSDictionary* __weak nodeStyles; NSMutableArray* customNodeStyles; - NSMutableArray* __weak onodeStyles; GraphicsView *__weak graphicsView; TikzSourceController *__weak tikzSourceController; + NSTableView *customNodeTable; } @property (weak, readonly) NSDictionary *nodeStyles; -@property (weak, readonly) NSMutableArray* onodeStyles; +@property NSMutableArray* customNodeStyles; + +@property IBOutlet NSTableView *customNodeTable; @property (weak) IBOutlet GraphicsView *graphicsView; @property (weak) IBOutlet TikzSourceController *tikzSourceController; diff --git a/tikzit/src/osx/CustomNodeController.m b/tikzit/src/osx/CustomNodeController.m index ef6b5bd..4f46acc 100644 --- a/tikzit/src/osx/CustomNodeController.m +++ b/tikzit/src/osx/CustomNodeController.m @@ -15,71 +15,40 @@ @implementation CustomNodeController -@synthesize nodeStyles, onodeStyles; +@synthesize nodeStyles, customNodeStyles; @synthesize graphicsView, tikzSourceController; +@synthesize customNodeTable; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { -// [SupportDir createUserSupportDir]; -// NSString *supportDir = [SupportDir userSupportDir]; - -// NSString *ns = [supportDir stringByAppendingPathComponent:@"nodeStyles.plist"]; -// NSString *es = [supportDir stringByAppendingPathComponent:@"edgeStyles.plist"]; -// onodeStyles = (NSMutableArray*)[NSKeyedUnarchiver -// unarchiveObjectWithFile:ns]; - // edgeStyles = (NSMutableArray*)[NSKeyedUnarchiver -// unarchiveObjectWithFile:es]; - - if (onodeStyles == nil) onodeStyles = [NSMutableArray array]; -// if (edgeStyles == nil) edgeStyles = [NSMutableArray array]; - -// [[self window] setLevel:NSNormalWindowLevel]; -// [self showWindow:self]; - - // Initialization code here. - - NSLog(@"Custom Node controller up and running!"); - - nodeStyles= [Shape shapeDictionary]; - + nodeStyles = [Shape shapeDictionary]; customNodeStyles = [NSMutableArray array]; - NSLog(@"Got a shape dictionary?"); - - NSString *meh; - for(id key in nodeStyles) { Shape *value = [nodeStyles objectForKey:key]; if([value isKindOfClass:[TikzShape class]]){ - NSLog(@"Got a custom node shape!"); NodeStyle *newNodeStyle = [[NodeStyle alloc] init]; [newNodeStyle setShapeName:key]; [customNodeStyles addObject:newNodeStyle]; - [onodeStyles addObject:newNodeStyle]; - -// meh = [(TikzShape *) value tikz]; } } - - NSLog(@"Trying to display tikz."); - -// [tikzSourceController setTikz:meh]; -// [tikzSourceController parseTikz:self]; } return self; } --(NSArray *)onodeStyles{ - return onodeStyles; - //return [nodeStyles allValues]; -} - - (void)tableViewSelectionDidChange:(NSNotification *)aNotification{ - NSLog(@"Changed selection!"); + NSInteger selectedRow = [customNodeTable selectedRow]; + + NodeStyle* selectedNodeStyle = [customNodeStyles objectAtIndex:selectedRow]; + TikzShape *tikzshape = (TikzShape *) [nodeStyles objectForKey:[selectedNodeStyle shapeName]]; + + [[tikzSourceController graphicsView] setEnabled:NO]; + [tikzSourceController setTikz:[tikzshape tikzSrc]]; + [tikzSourceController parseTikz:self]; } - (id)valueForUndefinedKey:(NSString *)key{ |