diff --git a/Classes/MainViewController.h b/Classes/MainViewController.h index 41b3b5f..9279335 100755 --- a/Classes/MainViewController.h +++ b/Classes/MainViewController.h @@ -21,4 +21,6 @@ - (IBAction)fontChangeClick:(NSSegmentedControl *)sender; - (IBAction)undoClick:(NSSegmentedControl *)sender; + +- (IBAction)supportClick:(id)sender; @end diff --git a/Classes/MainViewController.m b/Classes/MainViewController.m index 9f649c8..9afcfe7 100755 --- a/Classes/MainViewController.m +++ b/Classes/MainViewController.m @@ -106,6 +106,10 @@ - (IBAction)undoClick:(NSSegmentedControl *)sender{ } } +- (IBAction)supportClick:(id)sender +{ + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.tanhao.me"]]; +} #pragma mark - #pragma mark Service diff --git a/Classes/THButton.h b/Classes/THButton.h new file mode 100755 index 0000000..f35acc8 --- /dev/null +++ b/Classes/THButton.h @@ -0,0 +1,13 @@ +// +// THButton.h +// Vdisk +// +// Created by Hao Tan on 12/02/08. +// Copyright (c) 2012年 tanhao. All rights reserved. +// + +#import + +@interface THButton : NSButton + +@end diff --git a/Classes/THButton.m b/Classes/THButton.m new file mode 100755 index 0000000..c529ba2 --- /dev/null +++ b/Classes/THButton.m @@ -0,0 +1,24 @@ +// +// THButton.m +// Vdisk +// +// Created by Hao Tan on 12/02/08. +// Copyright (c) 2012年 tanhao. All rights reserved. +// + +#import "THButton.h" + +@implementation THButton + +- (void)awakeFromNib +{ + [super awakeFromNib]; +} + +- (void)resetCursorRects +{ + [super resetCursorRects]; + [self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]]; +} + +@end diff --git a/Classes/WordsViewController.m b/Classes/WordsViewController.m index cd4083d..ac319ad 100755 --- a/Classes/WordsViewController.m +++ b/Classes/WordsViewController.m @@ -56,7 +56,8 @@ - (IBAction)translateBegin:(NSButton *)sender } //此处利用了异步加载 - NSString *urlstring = [NSString stringWithFormat:@"http://dict.cn/ws.php?q=%@",string]; + //NSString *urlstring = [NSString stringWithFormat:@"http://dict.cn/ws.php?q=%@",string]; + NSString *urlstring = [NSString stringWithFormat:@"http://fanyi.youdao.com/openapi.do?keyfrom=tanhao&key=881024171&type=data&doctype=xml&version=1.1&q=%@",string]; NSString *encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)urlstring, NULL, NULL, kCFStringEncodingUTF8 ); [[MKServiceManager sharedManager] cancelForDelegate:self]; [[MKServiceManager sharedManager] downloadWithURL:[NSURL URLWithString:encodedString] delegate:self context:nil]; @@ -126,11 +127,62 @@ - (void)redoAction #pragma mark - #pragma mark MKServiceManagerDelegate -- (NSString *)readXmlInfo:(NSString *)aString{ +- (NSString *)readXmlInfo:(NSString *)aString +{ + NSMutableString *displayString=[[[NSMutableString alloc] init] autorelease]; + + NSError *error; + //NSStringEncoding encoding=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + NSStringEncoding encoding=NSUTF8StringEncoding; + NSData *data=[aString dataUsingEncoding:encoding]; + GDataXMLDocument* document = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error]; + GDataXMLElement *rootNode = [document rootElement]; + + //自动纠错 + NSArray *sugg=[rootNode nodesForXPath:@"//dict/sugg" error:&error]; + if ([sugg count]>0) { + [displayString appendFormat:@"您要查找的是不是:\n"]; + for(GDataXMLNode* node in sugg){ + [displayString appendFormat:@"%@ ",[node stringValue]]; + } + } + //读音 + NSArray *pron = [rootNode nodesForXPath:@"//basic/phonetic" error:&error]; + if ([pron count]>0) { + [displayString appendFormat:@"读音: %@\n\n",[[pron objectAtIndex:0] stringValue]]; + } + //解释 + NSArray *def = [rootNode nodesForXPath:@"//basic/explains/ex" error:&error]; + if ([def count]>0) + { + [displayString appendFormat:@"释义:\n"]; + for (int i=0; i<[def count]; i++) + { + [displayString appendFormat:@"%@\n",[[def objectAtIndex:i] stringValue]]; + } + } + //例句 + NSArray *orig = [rootNode nodesForXPath:@"//explain/key" error:&error]; + NSArray *trans= [rootNode nodesForXPath:@"//explain/value/ex" error:&error]; + if ([orig count]>0) { + [displayString appendFormat:@"\n例句:\n"]; + for (int i=0; i<[orig count]; i++) + { + [displayString appendFormat:@"%@\n%@\n",[[orig objectAtIndex:i] stringValue],[[trans objectAtIndex:i] stringValue]]; + } + } + + [document release]; + return displayString; +} + + +- (NSString *)readXmlInfoOld:(NSString *)aString{ NSMutableString *displayString=[[[NSMutableString alloc] init] autorelease]; NSError *error; - NSStringEncoding encoding=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + //NSStringEncoding encoding=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + NSStringEncoding encoding=NSUTF8StringEncoding; NSData *data=[aString dataUsingEncoding:encoding]; GDataXMLDocument* document = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error]; GDataXMLElement *rootNode = [document rootElement]; @@ -172,7 +224,8 @@ - (NSString *)readXmlInfo:(NSString *)aString{ - (void)serviceFinish:(MKServiceManager *)webService didReceiveData:(NSData *)data context:(id)context { - NSStringEncoding encoding=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + //NSStringEncoding encoding=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); + NSStringEncoding encoding=NSUTF8StringEncoding; NSString *receiveString = [[NSString alloc] initWithData:data encoding:encoding]; if (receiveString==nil) { @@ -217,7 +270,10 @@ - (void)quickTranslateWithString:(NSString *)str - (void)setFirstResponder { - [searchField becomeFirstResponder]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.view.window makeFirstResponder:searchField]; + }); + //[searchField becomeFirstResponder]; } - (void)changeFont:(NSFont *)aFont diff --git a/MKDic-Info.plist b/MKDic-Info.plist index 171a50e..e1d5727 100755 --- a/MKDic-Info.plist +++ b/MKDic-Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 3.0 + 3.1 CFBundleSignature ???? CFBundleVersion diff --git a/MKDic.xcodeproj/project.pbxproj b/MKDic.xcodeproj/project.pbxproj index 9ebe41a..8371123 100755 --- a/MKDic.xcodeproj/project.pbxproj +++ b/MKDic.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 04BA7F9315788115002D217C /* THButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 04BA7F9215788115002D217C /* THButton.m */; }; 04EAAA6F1497B74F00EEF4E6 /* MKServiceManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04EAAA6B1497B74F00EEF4E6 /* MKServiceManager.m */; }; 04EAAA701497B74F00EEF4E6 /* MKWebService.m in Sources */ = {isa = PBXBuildFile; fileRef = 04EAAA6D1497B74F00EEF4E6 /* MKWebService.m */; }; 04EAAA711497B74F00EEF4E6 /* readme.txt in Resources */ = {isa = PBXBuildFile; fileRef = 04EAAA6E1497B74F00EEF4E6 /* readme.txt */; }; @@ -47,6 +48,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 04BA7F9115788115002D217C /* THButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THButton.h; sourceTree = ""; }; + 04BA7F9215788115002D217C /* THButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THButton.m; sourceTree = ""; }; 04EAAA6A1497B74F00EEF4E6 /* MKServiceManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKServiceManager.h; sourceTree = ""; }; 04EAAA6B1497B74F00EEF4E6 /* MKServiceManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKServiceManager.m; sourceTree = ""; }; 04EAAA6C1497B74F00EEF4E6 /* MKWebService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKWebService.h; sourceTree = ""; }; @@ -216,6 +219,8 @@ children = ( 04EAAA691497B74F00EEF4E6 /* MKWebService_1.1.0 */, 40C823D013B335CE008D0451 /* config.h */, + 04BA7F9115788115002D217C /* THButton.h */, + 04BA7F9215788115002D217C /* THButton.m */, 400AA21113A9BB4D00DFD74F /* MKDicAppDelegate.h */, 400AA21213A9BB4D00DFD74F /* MKDicAppDelegate.m */, 400AA25F13A9C5EA00DFD74F /* GDataXML */, @@ -446,6 +451,7 @@ B89CCC3713AF80920009B69D /* WordNoteDao.m in Sources */, 04EAAA6F1497B74F00EEF4E6 /* MKServiceManager.m in Sources */, 04EAAA701497B74F00EEF4E6 /* MKWebService.m in Sources */, + 04BA7F9315788115002D217C /* THButton.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/xibs/MainViewController.xib b/xibs/MainViewController.xib index f35a3d4..429cc0d 100755 --- a/xibs/MainViewController.xib +++ b/xibs/MainViewController.xib @@ -1,21 +1,21 @@ - 1060 - 11C74 - 1938 - 1138.23 - 567.00 + 1070 + 11E53 + 2182 + 1138.47 + 569.00 com.apple.InterfaceBuilder.CocoaPlugin - 1938 + 2182 YES NSCustomView - NSTextField - NSTextFieldCell NSSegmentedCell + NSButton + NSButtonCell NSCustomObject NSSegmentedControl @@ -43,6 +43,34 @@ 286 YES + + + 268 + {{19, 5}, {341, 32}} + + + + _NS:9 + YES + + 67239424 + 134217728 + Copyright © 1987-2012 TanHao. All Rights Reserved + + LucidaGrande + 13 + 1044 + + _NS:9 + + -939376385 + 129 + + + 200 + 25 + + 301 @@ -57,7 +85,7 @@ LucidaGrande 12 - 4883 + 16 @@ -132,7 +160,7 @@ {{316, 337}, {146, 24}} - + YES 67239424 @@ -160,44 +188,6 @@ 1 - - - 289 - {{17, 9}, {351, 17}} - - - - YES - - 68288064 - 272630784 - Copyright © 1987-2012 TanHao. All Rights Reserved - - LucidaGrande - 13 - 1044 - - - - 6 - System - controlColor - - 3 - MC42NjY2NjY2NjY3AA - - - - 6 - System - controlTextColor - - 3 - MAA - - - - {480, 360} @@ -257,6 +247,14 @@ 33 + + + supportClick: + + + + 36 + @@ -293,26 +291,12 @@ YES - + - - 13 - - - YES - - - - - - 14 - - - 15 @@ -355,6 +339,20 @@ + + 34 + + + YES + + + + + + 35 + + + @@ -365,8 +363,6 @@ -2.IBPluginDependency -3.IBPluginDependency 1.IBPluginDependency - 13.IBPluginDependency - 14.IBPluginDependency 15.IBPluginDependency 16.IBPluginDependency 19.IBPluginDependency @@ -376,8 +372,11 @@ 31.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey 31.IBPluginDependency 31.IBSegmentedControlInspectorSelectedSegmentMetadataKey + 34.CustomClassName + 34.IBPluginDependency + 35.IBPluginDependency - + YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -387,13 +386,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + THButton + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -408,7 +408,7 @@ - 33 + 36 @@ -422,12 +422,14 @@ YES fontChangeClick: segmentClick: + supportClick: undoClick: - + YES NSSegmentedControl NSSegmentedControl + id NSSegmentedControl @@ -437,9 +439,10 @@ YES fontChangeClick: segmentClick: + supportClick: undoClick: - + YES fontChangeClick: @@ -449,6 +452,10 @@ segmentClick: NSSegmentedControl + + supportClick: + id + undoClick: NSSegmentedControl @@ -462,7 +469,7 @@ segmentedControl undoSegmentControl - + YES NSSegmentedControl NSSegmentedControl @@ -475,7 +482,7 @@ segmentedControl undoSegmentControl - + YES segmentedControl @@ -492,14 +499,18 @@ ./Classes/MainViewController.h + + THButton + NSButton + + IBProjectSource + ./Classes/THButton.h + + 0 IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 @@ -515,7 +526,7 @@ big_A small_A - + YES {9, 9} {9, 9}