From ce5930b13b15a98e0c365003ef56cedc1c9cb6b3 Mon Sep 17 00:00:00 2001 From: Johan Paulsson Date: Tue, 26 Feb 2013 19:18:54 +0000 Subject: osx gui underlines the offending line on a parser error in document message --- tikzit/English.lproj/TikzDocument.xib | 19 ++++++++----------- tikzit/TikZiT.xcodeproj/project.pbxproj | 20 ++++++++++++++------ tikzit/src/common/TikzGraphAssembler.m | 16 ++++++++++++++-- tikzit/src/osx/TikzSourceController.m | 31 ++++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 22 deletions(-) (limited to 'tikzit') diff --git a/tikzit/English.lproj/TikzDocument.xib b/tikzit/English.lproj/TikzDocument.xib index 446cb7e..53963d6 100644 --- a/tikzit/English.lproj/TikzDocument.xib +++ b/tikzit/English.lproj/TikzDocument.xib @@ -1,7 +1,7 @@ - 1070 + 1080 12C60 2843 1187.34 @@ -69,10 +69,10 @@ 265 - {{422, 18}, {17, 19}} + {{425, 21}, {17, 19}} - + YES _NS:1574 YES @@ -111,7 +111,7 @@ YES 68157504 - 272630784 + 1077941248 LucidaGrande @@ -206,7 +206,7 @@ {{0, -14}, {445, 14}} - + @@ -343,7 +343,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA {447, 0} - + 133202 @@ -371,6 +371,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA {{305, -184}, {128, 14}} + YES 68157504 @@ -395,7 +396,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA - {{0, 0}, {1600, 1178}} + {{0, 0}, {1600, 1200}} {94, 108} {10000000000000, 10000000000000} YES @@ -849,10 +850,6 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA 0 IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 diff --git a/tikzit/TikZiT.xcodeproj/project.pbxproj b/tikzit/TikZiT.xcodeproj/project.pbxproj index 3780cc6..bf8e930 100644 --- a/tikzit/TikZiT.xcodeproj/project.pbxproj +++ b/tikzit/TikZiT.xcodeproj/project.pbxproj @@ -130,6 +130,7 @@ 7F6E2C8A16B0096000BFE20D /* SupportDir.m in Sources */ = {isa = PBXBuildFile; fileRef = 55652DF813E1F2030023F4C6 /* SupportDir.m */; }; 7F6E2C8C16B00ABA00BFE20D /* SFBInspectors.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 55CA98D412EF8FCE008F0368 /* SFBInspectors.framework */; }; 7F781C1A16B5DE1400239826 /* ParseErrorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F781C1916B5DE1400239826 /* ParseErrorView.m */; }; + 7F90E88616DD29600069EBCD /* NSString+Tikz.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F90E88516DD29600069EBCD /* NSString+Tikz.m */; }; 7FB9BFEE16B57C2E00773146 /* TikzFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FB9BFED16B57C2E00773146 /* TikzFormatter.m */; }; 7FEED45716B1A7C500B056CB /* StyleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FEED45616B1A7C500B056CB /* StyleManager.m */; }; 8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; }; @@ -343,6 +344,8 @@ 7F6E2C8716B0091300BFE20D /* maths.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = maths.m; path = src/common/test/maths.m; sourceTree = ""; }; 7F781C1816B5DE1400239826 /* ParseErrorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParseErrorView.h; path = src/osx/ParseErrorView.h; sourceTree = ""; }; 7F781C1916B5DE1400239826 /* ParseErrorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ParseErrorView.m; path = src/osx/ParseErrorView.m; sourceTree = ""; }; + 7F90E88416DD29600069EBCD /* NSString+Tikz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+Tikz.h"; path = "src/common/NSString+Tikz.h"; sourceTree = ""; }; + 7F90E88516DD29600069EBCD /* NSString+Tikz.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+Tikz.m"; path = "src/common/NSString+Tikz.m"; 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 = ""; }; 7FEED45516B1A7C400B056CB /* StyleManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleManager.h; path = src/common/StyleManager.h; sourceTree = ""; }; @@ -607,6 +610,8 @@ 558F18C0117B031C009863B2 /* GraphElementData.m */, 558F18C1117B031C009863B2 /* Node.h */, 558F18C2117B031C009863B2 /* Node.m */, + 7F90E88416DD29600069EBCD /* NSString+Tikz.h */, + 7F90E88516DD29600069EBCD /* NSString+Tikz.m */, 558F18C3117B031C009863B2 /* NodeStyle.h */, 558F18C4117B031C009863B2 /* NodeStyle.m */, 5585E5C0117F681800124513 /* NodeStyle+Coder.h */, @@ -901,6 +906,7 @@ 7FEED45716B1A7C500B056CB /* StyleManager.m in Sources */, 7FB9BFEE16B57C2E00773146 /* TikzFormatter.m in Sources */, 7F781C1A16B5DE1400239826 /* ParseErrorView.m in Sources */, + 7F90E88616DD29600069EBCD /* NSString+Tikz.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1004,7 +1010,7 @@ AppKit, ); PRODUCT_NAME = tests; - SDKROOT = macosx10.7; + SDKROOT = macosx; }; name = Debug; }; @@ -1029,7 +1035,7 @@ AppKit, ); PRODUCT_NAME = tests; - SDKROOT = macosx10.7; + SDKROOT = macosx; ZERO_LINK = NO; }; name = Release; @@ -1038,6 +1044,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1054,7 +1061,7 @@ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.7; PRODUCT_NAME = TikZiT; - SDKROOT = macosx10.7; + SDKROOT = macosx; }; name = Debug; }; @@ -1062,6 +1069,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1076,7 +1084,7 @@ LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.7; PRODUCT_NAME = TikZiT; - SDKROOT = macosx10.7; + SDKROOT = macosx; }; name = Release; }; @@ -1093,7 +1101,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.5; ONLY_ACTIVE_ARCH = YES; PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO; - SDKROOT = macosx10.5; + SDKROOT = macosx; SYMROOT = xbuild; USER_HEADER_SEARCH_PATHS = "src/osx src/common"; VALID_ARCHS = "i386 x86_64"; @@ -1112,7 +1120,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.5; ONLY_ACTIVE_ARCH = NO; PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO; - SDKROOT = macosx10.5; + SDKROOT = macosx; SYMROOT = xbuild; USER_HEADER_SEARCH_PATHS = "src/osx src/common"; VALID_ARCHS = "i386 x86_64"; diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index b07ee58..1dc997a 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -46,8 +46,20 @@ void yyerror(const char *str) { NSLog(@"Parse error on line %i: %s\n%s\n%@\n", lineno, str, linebuff, [[@"" stringByPaddingToLength:(tokenpos-yyleng) withString: @" " startingAtIndex:0] stringByAppendingString:[@"" stringByPaddingToLength:yyleng withString: @"^" startingAtIndex:0]]); if (currentAssembler != nil) { NSError *error = [NSError errorWithDomain:@"net.sourceforge.tikzit" - code:TZ_ERR_PARSE - userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithCString:str] forKey: NSLocalizedDescriptionKey]]; + code:TZ_ERR_PARSE + userInfo:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithCString:str encoding:NSUTF8StringEncoding], + [NSNumber numberWithInt:lineno], + [NSString stringWithCString:linebuff encoding:NSUTF8StringEncoding], + [NSNumber numberWithInt:tokenpos], + [NSNumber numberWithInt:yyleng], + nil] + forKeys: [NSArray arrayWithObjects:NSLocalizedDescriptionKey, + @"lineNumber", + @"syntaxString", + @"tokenStart", + @"tokenLength", + nil]]]; + [currentAssembler invalidateWithError:error]; } } diff --git a/tikzit/src/osx/TikzSourceController.m b/tikzit/src/osx/TikzSourceController.m index 428c6ba..6daff0f 100644 --- a/tikzit/src/osx/TikzSourceController.m +++ b/tikzit/src/osx/TikzSourceController.m @@ -180,12 +180,37 @@ [status setStringValue:@"parse error"]; [status setTextColor:failedColor]; + NSDictionary *d = [[assembler lastError] userInfo]; - NSLog(@"Parse error: %@",[assembler lastError]); + NSString *ts = [NSString stringWithFormat: @"Parse error on line %@: %@\n", [d valueForKey:@"lineNumber"], [d valueForKey:NSLocalizedDescriptionKey]]; + NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat: @"Parse error on line %@: %@\n%@\n", [d valueForKey:@"lineNumber"], [d valueForKey:NSLocalizedDescriptionKey], [[d valueForKey:@"syntaxString"] stringByReplacingOccurrencesOfString:@"\t" withString:@""]]]; - NSError *e = [assembler lastError]; + NSInteger tokenLength = [[d valueForKey:@"tokenLength"] integerValue]; + // Bit of a mess, offset around to find correct position and correct for 4 characters for every one character of \t + NSInteger addedTokenStart = [[d valueForKey:@"tokenStart"] integerValue] + [ts length] - ([[[d valueForKey:@"syntaxString"] componentsSeparatedByString:@"\t"] count]-1)*4 - tokenLength; - [errorMessage setStringValue:[[[assembler lastError] userInfo] valueForKey:NSLocalizedDescriptionKey]]; + // Can't see if the error is a start paranthesis as only that will be underlined, underline the entire paranthesis instead + if(tokenLength == 1 && [[as string] characterAtIndex:addedTokenStart] == '('){ + tokenLength += [[[as string] substringFromIndex:addedTokenStart+1] rangeOfString:@")"].location + 1; + } + + // Same if unexpected endparanthesis + if(tokenLength == 1 && [[as string] characterAtIndex:addedTokenStart] == ')'){ + NSInteger d = addedTokenStart - [[[as string] substringToIndex:addedTokenStart] rangeOfString:@"(" options:NSBackwardsSearch].location; + + tokenLength += d; + addedTokenStart -= d; + } + + [as beginEditing]; + [as addAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt:NSUnderlineStyleSingle | NSUnderlinePatternDot], NSUnderlineStyleAttributeName, + [NSColor redColor], NSUnderlineColorAttributeName, + nil] + range:NSMakeRange(addedTokenStart, tokenLength)]; + [as endEditing]; + + [errorMessage setAttributedStringValue:as]; [errorNotification setHidden:FALSE]; } } -- cgit v1.2.3