From 4c3a82c9146aa0e147b49b429b49fefb0e785a17 Mon Sep 17 00:00:00 2001 From: Johan Paulsson Date: Tue, 25 Mar 2014 17:30:35 +0000 Subject: osx gui: custom nodes preference panel shows tikzit preview and tikz code for selected custom node. --- tikzit/English.lproj/CustomNodes.xib | 256 ++++++++++++++++++++++++++++++++ tikzit/TikZiT.xcodeproj/project.pbxproj | 26 +++- tikzit/src/common/TikzShape.h | 3 + tikzit/src/common/TikzShape.m | 4 + tikzit/src/osx/CustomNodeCellView.m | 10 +- tikzit/src/osx/CustomNodeController.h | 6 +- tikzit/src/osx/CustomNodeController.m | 53 ++----- 7 files changed, 307 insertions(+), 51 deletions(-) create mode 100644 tikzit/English.lproj/CustomNodes.xib diff --git a/tikzit/English.lproj/CustomNodes.xib b/tikzit/English.lproj/CustomNodes.xib new file mode 100644 index 0000000..33f6e3a --- /dev/null +++ b/tikzit/English.lproj/CustomNodes.xib @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + name + strokeThickness + strokeColor + fillColor + strokeColorIsKnown + fillColorIsKnown + representedObject.name + shapeName + scale + @distinctUnionOfObjects.category + category + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \begin{tikzpicture} + +\end{tikzpicture} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tikzit/TikZiT.xcodeproj/project.pbxproj b/tikzit/TikZiT.xcodeproj/project.pbxproj index 692181b..8e3e7c9 100644 --- a/tikzit/TikZiT.xcodeproj/project.pbxproj +++ b/tikzit/TikZiT.xcodeproj/project.pbxproj @@ -143,6 +143,8 @@ 7F938530184D178B00FAED38 /* engine.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F93852F184D178B00FAED38 /* engine.png */; }; 7F938532184D184700FAED38 /* preamble.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F938531184D184700FAED38 /* preamble.png */; }; 7FB9BFEE16B57C2E00773146 /* TikzFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FB9BFED16B57C2E00773146 /* TikzFormatter.m */; }; + 7FD5D44B18E1CB5300E2A930 /* CustomNodes.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7FD5D44918E1CB5300E2A930 /* CustomNodes.xib */; }; + 7FD5D44D18E1CC0B00E2A930 /* customshape.png in Resources */ = {isa = PBXBuildFile; fileRef = 7FD5D44C18E1CC0B00E2A930 /* customshape.png */; }; 7FEED45716B1A7C500B056CB /* StyleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FEED45616B1A7C500B056CB /* StyleManager.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; }; 8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; }; @@ -379,6 +381,8 @@ 7F938531184D184700FAED38 /* preamble.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = preamble.png; sourceTree = ""; }; 7FB9BFEC16B57C2E00773146 /* TikzFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TikzFormatter.h; path = src/osx/TikzFormatter.h; sourceTree = ""; }; 7FB9BFED16B57C2E00773146 /* TikzFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TikzFormatter.m; path = src/osx/TikzFormatter.m; sourceTree = ""; }; + 7FD5D44A18E1CB5300E2A930 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/CustomNodes.xib; sourceTree = ""; }; + 7FD5D44C18E1CC0B00E2A930 /* customshape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = customshape.png; sourceTree = ""; }; 7FEED45516B1A7C400B056CB /* StyleManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleManager.h; path = src/common/StyleManager.h; sourceTree = ""; }; 7FEED45616B1A7C500B056CB /* StyleManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StyleManager.m; path = src/common/StyleManager.m; sourceTree = ""; }; 8D15AC360486D014006FF6A4 /* TikZiT-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "TikZiT-Info.plist"; sourceTree = ""; }; @@ -511,6 +515,7 @@ 55D945701165904F0044178C /* tikzitdoc.icns */, 55D945711165904F0044178C /* tikzit.icns */, 7F90E88C16DD47540069EBCD /* Preferences.xib */, + 7FD5D44918E1CB5300E2A930 /* CustomNodes.xib */, 7F18A322184C599100BC3081 /* UpdatePreferencePanel.xib */, 55391AF713D3250F007DBE71 /* Preamble.xib */, 55391AF513D324FE007DBE71 /* Preview.xib */, @@ -768,6 +773,7 @@ children = ( 7F93852F184D178B00FAED38 /* engine.png */, 7F938531184D184700FAED38 /* preamble.png */, + 7FD5D44C18E1CC0B00E2A930 /* customshape.png */, 7F93852D184D176E00FAED38 /* updates.png */, ); name = Icons; @@ -865,6 +871,7 @@ 1DDD582C0DA1D0D100B32029 /* TikzDocument.xib in Resources */, 7F938530184D178B00FAED38 /* engine.png in Resources */, 1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */, + 7FD5D44D18E1CC0B00E2A930 /* customshape.png in Resources */, 55D945721165904F0044178C /* tikzitdoc.icns in Resources */, 55D945731165904F0044178C /* tikzit.icns in Resources */, 556979431168747B007E5703 /* StylePalette.xib in Resources */, @@ -888,6 +895,7 @@ 55397C8A1449AB91006942FB /* AH_none.png in Resources */, 55397C8B1449AB91006942FB /* AH_plain_tail.png in Resources */, 55397C8D1449ABFC006942FB /* AH_latex_tail.png in Resources */, + 7FD5D44B18E1CB5300E2A930 /* CustomNodes.xib in Resources */, 55397C901449AC7C006942FB /* AH_latex_head.png in Resources */, 55397C911449AC7C006942FB /* AH_plain_head.png in Resources */, 7F18A323184C599100BC3081 /* UpdatePreferencePanel.xib in Resources */, @@ -909,11 +917,12 @@ ); name = "Run Flex"; outputPaths = ( - "$(SRCROOT)/src/common/tikzlexer.m", + "$(DERIVED_SOURCES_DIR)/tikzlexer.m", + "$(DERIVED_SOURCES_DIR)/tikzlexer.h", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cd ${SRCROOT}/src/\nINPUT_FILE_BASE=`basename \"${SCRIPT_INPUT_FILE_0}\" .lm`\nflex -o common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.lm\nmv common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.h ${DERIVED_SOURCES_DIR}\n"; + shellScript = "cd ${SRCROOT}/src/\nexport INPUT_FILE_BASE=`basename \"${SCRIPT_INPUT_FILE_0}\" .lm`\nflex -o common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.lm\nmv common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.h ${DERIVED_SOURCES_DIR}\n"; }; 7F7B6DE118DE0A6E004F6CA8 /* Run Bison */ = { isa = PBXShellScriptBuildPhase; @@ -925,11 +934,12 @@ ); name = "Run Bison"; outputPaths = ( - "$(SRCROOT)/src/common/tikzparser.m", + "$(DERIVED_SOURCES_DIR)/tikzparser.m", + "$(DERIVED_SOURCES_DIR)/tikzparser.h", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cd ${SRCROOT}/src/\nINPUT_FILE_BASE=`basename \"${SCRIPT_INPUT_FILE_0}\" .ym`\nflex -o common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.lm\nbison --defines=common/${INPUT_FILE_BASE}.h --output=common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.ym\nmv common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.h ${DERIVED_SOURCES_DIR}"; + shellScript = "cd ${SRCROOT}/src/\nexport INPUT_FILE_BASE=`basename \"${SCRIPT_INPUT_FILE_0}\" .ym`\nbison --defines=common/${INPUT_FILE_BASE}.h --output=common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.ym\nmv common/${INPUT_FILE_BASE}.m common/${INPUT_FILE_BASE}.h ${DERIVED_SOURCES_DIR}"; }; /* End PBXShellScriptBuildPhase section */ @@ -1124,6 +1134,14 @@ name = UserDefaults.plist; sourceTree = ""; }; + 7FD5D44918E1CB5300E2A930 /* CustomNodes.xib */ = { + isa = PBXVariantGroup; + children = ( + 7FD5D44A18E1CB5300E2A930 /* English */, + ); + name = CustomNodes.xib; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ 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 { 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{ -- cgit v1.2.3