From 401b8214d9de69d04cc0b8af8f2fc0aa31451f25 Mon Sep 17 00:00:00 2001 From: EnjoySR Date: Mon, 14 Aug 2017 11:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DXcode=209?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/ESJsonFormat.xcscheme | 8 +++++++- ESJsonFormat/Controller/ESDialogController.xib | 8 ++++---- ESJsonFormat/ESJsonFormat.m | 17 ++++++++++++++++- ESJsonFormat/ESJsonFormatManager.m | 4 ++-- ESJsonFormat/Info.plist | 3 +++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ESJsonFormat.xcodeproj/xcshareddata/xcschemes/ESJsonFormat.xcscheme b/ESJsonFormat.xcodeproj/xcshareddata/xcschemes/ESJsonFormat.xcscheme index 752f4b3..6e46ec8 100755 --- a/ESJsonFormat.xcodeproj/xcshareddata/xcschemes/ESJsonFormat.xcscheme +++ b/ESJsonFormat.xcodeproj/xcshareddata/xcschemes/ESJsonFormat.xcscheme @@ -40,6 +40,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" shouldUseLaunchSchemeArgsEnv = "YES"> @@ -47,9 +48,10 @@ + + - + - + @@ -46,7 +46,7 @@ - + - + diff --git a/ESJsonFormat/ESJsonFormat.m b/ESJsonFormat/ESJsonFormat.m index 13ecf20..9eb4170 100755 --- a/ESJsonFormat/ESJsonFormat.m +++ b/ESJsonFormat/ESJsonFormat.m @@ -50,6 +50,8 @@ - (id)initWithBundle:(NSBundle *)plugin [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLog:) name:NSTextViewDidChangeSelectionNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLog:) name:@"IDEEditorDocumentDidChangeNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLog:) name:@"PBXProjectDidOpenNotification" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLog:) name:@"SourceEditorSelectedSourceRangeChangedNotification" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationLog:) name:@"IDEWorkspaceDocumentWillWriteStateDataNotification" object:nil]; } instance = self; return self; @@ -57,9 +59,10 @@ - (id)initWithBundle:(NSBundle *)plugin - (void)notificationLog:(NSNotification *)notify { + if (!self.notiTag) return; if ([notify.name isEqualToString:NSTextViewDidChangeSelectionNotification]) { - if ([notify.object isKindOfClass:[NSTextView class]]) { + if ([notify.object isKindOfClass:NSClassFromString(@"DVTSourceTextView")]) { NSTextView *text = (NSTextView *)notify.object; self.currentTextView = text; } @@ -79,7 +82,19 @@ - (void)notificationLog:(NSNotification *)notify }else if ([notify.name isEqualToString:@"PBXProjectDidOpenNotification"]){ self.currentProjectPath = [notify.object valueForKey:@"path"]; [[ESPbxprojInfo shareInstance] setParamsWithPath:[self.currentProjectPath stringByAppendingPathComponent:@"project.pbxproj"]]; + }else if ([notify.name isEqualToString:@"SourceEditorSelectedSourceRangeChangedNotification"]) { + // 适配 Xcode 9,在Xcode 9 中代码编辑区域的 View 类型如下,继承于 NSView,但使用方式与 NSTextView 类似 + if ([notify.object isKindOfClass:NSClassFromString(@"IDEPegasusSourceEditor.SourceCodeEditorView")]) { + self.currentTextView = notify.object; + } + }else if ([notify.name isEqualToString:@"IDEWorkspaceDocumentWillWriteStateDataNotification"]) { + NSArray *recentEditorDocumentURLs = [notify.object valueForKey:@"_recentEditorDocumentURLs"]; + NSString *path = [recentEditorDocumentURLs.firstObject absoluteString]; + if ([path hasPrefix:@"file"]) { + self.currentFilePath = path; + } } + } -(void)outputResult:(NSNotification*)noti{ diff --git a/ESJsonFormat/ESJsonFormatManager.m b/ESJsonFormat/ESJsonFormatManager.m index 27c50ff..c4085d5 100644 --- a/ESJsonFormat/ESJsonFormatManager.m +++ b/ESJsonFormat/ESJsonFormatManager.m @@ -116,13 +116,13 @@ + (NSString *)formatObjcWithKey:(NSString *)key value:(NSObject *)value classInf * @return */ + (NSString *)formatSwiftWithKey:(NSString *)key value:(NSObject *)value classInfo:(ESClassInfo *)classInfo{ - NSString *typeStr = @"String?"; + NSString *typeStr = @"String"; //判断大小写 if ([ESUppercaseKeyWords containsObject:key] && [ESJsonFormatSetting defaultSetting].uppercaseKeyWordForId) { key = [key uppercaseString]; } if ([value isKindOfClass:[NSString class]]) { - return [NSString stringWithFormat:@" var %@: %@",key,typeStr]; + return [NSString stringWithFormat:@" var %@: %@ = \"\"",key,typeStr]; }else if([value isKindOfClass:[@(YES) class]]){ typeStr = @"Bool"; return [NSString stringWithFormat:@" var %@: %@ = false",key,typeStr]; diff --git a/ESJsonFormat/Info.plist b/ESJsonFormat/Info.plist index 0dfeb8a..792e11d 100644 --- a/ESJsonFormat/Info.plist +++ b/ESJsonFormat/Info.plist @@ -25,6 +25,7 @@ DVTPlugInCompatibilityUUIDs AABB7188-E14E-4433-AD3B-5CD791EAD9A3 + 1637F4D5-0B27-416B-A78D-498965D64877 F41BD31E-2683-44B8-AE7F-5F09E919790E 992275C1-432A-4CF7-B659-D84ED6D42D3F 7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90 @@ -36,6 +37,8 @@ 0420B86A-AA43-4792-9ED0-6FE0F2B16A13 7265231C-39B4-402C-89E1-16167C4CC990 ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C + DFFB3951-EB0A-4C09-9DAC-5F2D28CC839C + CA351AD8-3176-41CB-875C-42A05C7CDEC7 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET)