Merge remote-tracking branch 'schriftgestalt/master'

* schriftgestalt/master:
  add option to insert NSLocalizedStringFromTableInBundle

Conflicts:
	QuickLocalization/QuickLocalization.m
This commit is contained in:
Zitao Xiong
2015-11-19 02:26:20 -05:00
12 changed files with 686 additions and 58 deletions

View File

@@ -7,6 +7,11 @@
objects = {
/* Begin PBXBuildFile section */
0966970B1B5A20C200D29654 /* AMMenuGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 0966970A1B5A20C200D29654 /* AMMenuGenerator.m */; };
0966970D1B5A20C900D29654 /* MenuItemData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0966970C1B5A20C900D29654 /* MenuItemData.plist */; };
096697101B5A214400D29654 /* AMConstString.m in Sources */ = {isa = PBXBuildFile; fileRef = 0966970F1B5A214400D29654 /* AMConstString.m */; };
099474BA1B5A1F3000E39E3C /* OLSettingController.m in Sources */ = {isa = PBXBuildFile; fileRef = 099474B81B5A1F3000E39E3C /* OLSettingController.m */; };
099474BB1B5A1F3000E39E3C /* OLSettingController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 099474B91B5A1F3000E39E3C /* OLSettingController.xib */; };
09A343C6174068E600A713EE /* RCXcode.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A343C5174068E200A713EE /* RCXcode.m */; };
09EC581817E3B6E1002261C4 /* icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 09EC581717E3B6E1002261C4 /* icon.icns */; };
09F65636174041010000486B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09F65635174041010000486B /* AppKit.framework */; };
@@ -16,6 +21,14 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
096697091B5A20C200D29654 /* AMMenuGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMMenuGenerator.h; sourceTree = "<group>"; };
0966970A1B5A20C200D29654 /* AMMenuGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMMenuGenerator.m; sourceTree = "<group>"; };
0966970C1B5A20C900D29654 /* MenuItemData.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = MenuItemData.plist; sourceTree = "<group>"; };
0966970E1B5A214400D29654 /* AMConstString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMConstString.h; sourceTree = "<group>"; };
0966970F1B5A214400D29654 /* AMConstString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMConstString.m; sourceTree = "<group>"; };
099474B71B5A1F3000E39E3C /* OLSettingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OLSettingController.h; sourceTree = "<group>"; };
099474B81B5A1F3000E39E3C /* OLSettingController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OLSettingController.m; sourceTree = "<group>"; };
099474B91B5A1F3000E39E3C /* OLSettingController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OLSettingController.xib; sourceTree = "<group>"; };
09A343C4174068E200A713EE /* RCXcode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCXcode.h; sourceTree = "<group>"; };
09A343C5174068E200A713EE /* RCXcode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCXcode.m; sourceTree = "<group>"; };
09EC581717E3B6E1002261C4 /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = "<group>"; };
@@ -75,7 +88,15 @@
09F65640174041010000486B /* QuickLocalization.m */,
09A343C4174068E200A713EE /* RCXcode.h */,
09A343C5174068E200A713EE /* RCXcode.m */,
0966970C1B5A20C900D29654 /* MenuItemData.plist */,
0966970E1B5A214400D29654 /* AMConstString.h */,
0966970F1B5A214400D29654 /* AMConstString.m */,
096697091B5A20C200D29654 /* AMMenuGenerator.h */,
0966970A1B5A20C200D29654 /* AMMenuGenerator.m */,
09F6563A174041010000486B /* Supporting Files */,
099474B71B5A1F3000E39E3C /* OLSettingController.h */,
099474B81B5A1F3000E39E3C /* OLSettingController.m */,
099474B91B5A1F3000E39E3C /* OLSettingController.xib */,
);
path = QuickLocalization;
sourceTree = "<group>";
@@ -142,7 +163,9 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
099474BB1B5A1F3000E39E3C /* OLSettingController.xib in Resources */,
09F6563E174041010000486B /* InfoPlist.strings in Resources */,
0966970D1B5A20C900D29654 /* MenuItemData.plist in Resources */,
09EC581817E3B6E1002261C4 /* icon.icns in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -155,6 +178,9 @@
buildActionMask = 2147483647;
files = (
09F65641174041010000486B /* QuickLocalization.m in Sources */,
096697101B5A214400D29654 /* AMConstString.m in Sources */,
099474BA1B5A1F3000E39E3C /* OLSettingController.m in Sources */,
0966970B1B5A20C200D29654 /* AMMenuGenerator.m in Sources */,
09A343C6174068E600A713EE /* RCXcode.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -0,0 +1,32 @@
//
// AMConstString.h
// AMMethod2Implement
//
// Created by JohnnyLiu on 15/4/1.
// Copyright (c) 2015年 Tendencystudio. All rights reserved.
//
#import <Foundation/Foundation.h>
extern NSString * const kDeclareMap;
extern NSString * const kImplementMap;
extern NSString * const kImplementContent;
extern NSString * const kSelectTextType;
extern NSString * const kSelectTextFirstSelectMethod;
extern NSString * const kMenuRootMenuTitle;
extern NSString * const kMenuPluginTitle;
extern NSString * const kMenuSubMenuItems;
extern NSString * const kMenuTitle;
extern NSString * const kMenuSelector;
extern NSString * const kMenuShortcut;
extern NSString * const kMenuKeyMask;
extern NSString * const kMenuKeyEquivalent;
extern NSString * const kMenuActionTitle;
extern NSString * const kQLFormatStringKey;
extern NSString * const kQLFormatStringCommentSameKey;
extern NSString * const kQLFormatStringSwiftSyntax;

View File

@@ -0,0 +1,32 @@
//
// AMConstString.m
// AMMethod2Implement
//
// Created by JohnnyLiu on 15/4/1.
// Copyright (c) 2015 Tendencystudio. All rights reserved.
//
#import "AMConstString.h"
NSString * const kDeclareMap = @"declareMap";
NSString * const kImplementMap = @"implementMap";
NSString * const kImplementContent = @"implementContent";
NSString * const kSelectTextType = @"type";
NSString * const kSelectTextFirstSelectMethod = @"firstSelectMethod";
NSString * const kMenuRootMenuTitle = @"rootMenuTitle";
NSString * const kMenuPluginTitle = @"pluginTitle";
NSString * const kMenuSubMenuItems = @"subMenuItems";
NSString * const kMenuTitle = @"title";
NSString * const kMenuSelector = @"selector";
NSString * const kMenuShortcut = @"shortcut";
NSString * const kMenuKeyMask = @"keyMask";
NSString * const kMenuKeyEquivalent = @"keyEquivalent";
NSString * const kMenuActionTitle = @"Implement Mehod";
NSString * const kQLFormatStringKey = @"KQLFormatStringKey";
NSString * const kQLFormatStringCommentSameKey = @"KQLFormatStringKey";
NSString * const kQLFormatStringSwiftSyntax = @"kQLFormatStringSwiftSyntax";

View File

@@ -0,0 +1,16 @@
//
// AMMenuGenerator.h
// AMMethod2Implement
//
// Created by JohnnyLiu on 15/4/1.
// Copyright (c) 2015年 Tendencystudio. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface AMMenuGenerator : NSObject
+ (void)generateMenuItems:(NSBundle *)bundle version:(NSString *)version target:(id)target;
+ (NSUInteger)getKeyEquivalentModifierMaskWithKey:(NSString *)key;
@end

View File

@@ -0,0 +1,75 @@
//
// AMMenuGenerator.m
// AMMethod2Implement
//
// Created by JohnnyLiu on 15/4/1.
// Copyright (c) 2015 Tendencystudio. All rights reserved.
//
#import "AMMenuGenerator.h"
#import "RCXcode.h"
@implementation AMMenuGenerator
+ (void)generateMenuItems:(NSBundle *)bundle version:(NSString *)version target:(id)target
{
NSString *dataPath = [bundle pathForResource:@"MenuItemData" ofType:@"plist"];
NSDictionary *menuData = [NSDictionary dictionaryWithContentsOfFile:dataPath];
NSMenuItem *menuItem = [[NSApp mainMenu] itemWithTitle:menuData[kMenuRootMenuTitle]];
if (menuItem) {
[[menuItem submenu] addItem:[NSMenuItem separatorItem]];
NSString *title = menuData[kMenuPluginTitle];
NSMenuItem *actionMenuItem = [[NSMenuItem alloc] initWithTitle:title action:nil keyEquivalent:@""];
[[menuItem submenu] addItem:actionMenuItem];
NSMenu* submenu = [[NSMenu alloc] init];
[actionMenuItem setSubmenu:submenu];
for (NSDictionary *item in menuData[kMenuSubMenuItems]) {
NSString *subMenuTitle = item[kMenuTitle];
if ([subMenuTitle rangeOfString:@"%@"].length > 0) {
subMenuTitle = [NSString stringWithFormat:subMenuTitle, version];
}
NSString *selectorString = item[kMenuSelector];
SEL selector = nil;
if (selectorString != nil && selectorString.length > 0) {
selector = NSSelectorFromString(selectorString);
}
NSString *keyEquivalent = @"";
if (item[kMenuShortcut][kMenuKeyEquivalent] != nil) {
keyEquivalent = item[kMenuShortcut][kMenuKeyEquivalent];
}
NSArray *maskArray = item[kMenuShortcut][kMenuKeyMask];
NSDictionary *userMenu = [[NSUserDefaults standardUserDefaults] objectForKey:kMenuActionTitle];
if (userMenu != nil) {
keyEquivalent = userMenu[kMenuKeyEquivalent];
maskArray = userMenu[kMenuShortcut];
}
NSMenuItem *subMenuItem = [[NSMenuItem alloc] initWithTitle:subMenuTitle action:selector keyEquivalent:keyEquivalent];
if (maskArray.count == 1) {
subMenuItem.keyEquivalentModifierMask = [AMMenuGenerator getKeyEquivalentModifierMaskWithKey:maskArray[0]];
}else if(maskArray.count == 2) {
subMenuItem.keyEquivalentModifierMask = [AMMenuGenerator getKeyEquivalentModifierMaskWithKey:maskArray[0]] |
[AMMenuGenerator getKeyEquivalentModifierMaskWithKey:maskArray[1]];
}
subMenuItem.target = target;
[submenu addItem:subMenuItem];
}
}
}
+ (NSUInteger)getKeyEquivalentModifierMaskWithKey:(NSString *)key
{
NSDictionary *keyMaskMap = @{@"ctrl":@(NSControlKeyMask),
@"shift":@(NSShiftKeyMask),
@"command":@(NSCommandKeyMask),
@"alt":@(NSAlternateKeyMask)};
return [keyMaskMap[key] integerValue];
}
@end

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>rootMenuTitle</key>
<string>Edit</string>
<key>pluginTitle</key>
<string>Quick Localization</string>
<key>subMenuItems</key>
<array>
<dict>
<key>title</key>
<string>Quick Localization</string>
<key>selector</key>
<string>quickLocalization:</string>
<key>shortcut</key>
<dict>
<key>keyMask</key>
<array>
<string>ctrl</string>
</array>
<key>keyEquivalent</key>
<string>a</string>
</dict>
</dict>
<dict>
<key>title</key>
<string>Setting</string>
<key>selector</key>
<string>showSettingWindow</string>
</dict>
<dict>
<key>title</key>
<string>Plugin version %@</string>
<key>selector</key>
<string></string>
</dict>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,14 @@
//
// OLSettingController.h
// QuickLocalization
//
// Created by Zitao Xiong on 7/18/15.
// Copyright (c) 2015 nanaimostudio. All rights reserved.
//
#import <Cocoa/Cocoa.h>
extern NSUInteger QL_CountOccurentOfStringWithSubString(NSString *str, NSString *subString);
@interface OLSettingController : NSWindowController
@property (nonatomic, weak) NSBundle *bundle;
@end

View File

@@ -0,0 +1,138 @@
//
// OLSettingController.m
// QuickLocalization
//
// Created by Zitao Xiong on 7/18/15.
// Copyright (c) 2015 nanaimostudio. All rights reserved.
//
#import "OLSettingController.h"
NSUInteger QL_CountOccurentOfStringWithSubString(NSString *str, NSString *subString) {
NSUInteger count = 0, length = [str length];
NSRange range = NSMakeRange(0, length);
while(range.location != NSNotFound)
{
range = [str rangeOfString:subString options:0 range:range];
if(range.location != NSNotFound)
{
range = NSMakeRange(range.location + range.length, length - (range.location + range.length));
count++;
}
}
return count;
}
@interface OLSettingController ()
@property (weak) IBOutlet NSTextField *commentTextField;
@property (weak) IBOutlet NSTextField *tableNameTextField;
@property (weak) IBOutlet NSTextField *bunldeTextField;
@property (weak) IBOutlet NSButton *swiftCheckButton;
@property (weak) IBOutlet NSButton *commentSameAsKeyCheckButton;
@property (weak) IBOutlet NSComboBox *comboBox;
@property (weak) IBOutlet NSTextField *previewLabel;
@property (weak) IBOutlet NSButton *commentAsKeyButton;
@property (weak) IBOutlet NSTextField *valueTextField;
@property (weak) IBOutlet NSButton *swiftLocalizationPreviewButton;
@end
@implementation OLSettingController
- (void)windowDidLoad {
[super windowDidLoad];
[self.comboBox selectItemAtIndex:0];
[self updatePreviewText];
}
- (IBAction)onSaveButton:(id)sender {
}
- (IBAction)commentDidChange:(id)sender {
[self updatePreviewText];
}
- (IBAction)onTableNameChanged:(id)sender {
[self updatePreviewText];
}
- (IBAction)onBunldeNameChanged:(id)sender {
[self updatePreviewText];
}
- (IBAction)onCommentAsKayButton:(id)sender {
if (self.commentAsKeyButton.state == NSOnState) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kQLFormatStringCommentSameKey];
}
else {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kQLFormatStringCommentSameKey];
}
[self updatePreviewText];
}
- (IBAction)onValueTextField:(id)sender {
[self updatePreviewText];
}
- (IBAction)onSwiftLocalizationPreviewChanged:(id)sender {
if (self.swiftLocalizationPreviewButton.state == NSOnState) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kQLFormatStringSwiftSyntax];
}
else {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kQLFormatStringSwiftSyntax];
}
[self updatePreviewText];
}
- (IBAction)onComboBoxChanged:(id)sender {
[self updatePreviewText];
}
- (NSString *)updatePreviewText {
NSString *formatString = [self.comboBox objectValueOfSelectedItem];
NSUInteger placeholderCount = QL_CountOccurentOfStringWithSubString(formatString, @"%@");
NSString *value = @"\"Hello World\"";
if (self.swiftLocalizationPreviewButton.state == NSOffState) {
value = [NSString stringWithFormat:@"@%@", value];
}
NSString *comment;
NSString *savedComment;
if ([self.commentAsKeyButton state] == NSOnState) {
comment = [value copy];
savedComment = @"%@";
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kQLFormatStringCommentSameKey];
}
else {
comment = self.commentTextField.stringValue;
savedComment = comment.copy;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kQLFormatStringCommentSameKey];
}
NSString *savedFormatString;
if (placeholderCount == 2) {
//swift or object-c
[self.previewLabel setStringValue:[NSString stringWithFormat:formatString, value, comment]];
savedFormatString = [NSString stringWithFormat:formatString, @"%@", savedComment];
}
else if (placeholderCount == 4) {
//object-c from bundle
[self.previewLabel setStringValue:[NSString stringWithFormat:formatString, value, comment, self.tableNameTextField.stringValue, self.bunldeTextField.stringValue]];
savedFormatString = [NSString stringWithFormat:formatString, @"%@", savedComment, self.tableNameTextField.stringValue, self.bunldeTextField.stringValue];
}
else if (placeholderCount == 5) {
[self.previewLabel setStringValue:[NSString stringWithFormat:formatString, value, self.tableNameTextField.stringValue, self.bunldeTextField.stringValue, self.valueTextField.stringValue, comment]];
savedFormatString = [NSString stringWithFormat:formatString, @"%@", self.tableNameTextField.stringValue, self.bunldeTextField.stringValue, self.valueTextField.stringValue, savedComment];
}
else {
[self.previewLabel setStringValue:@"%@ must be 2, 4, or 5"];
return @"";
}
[[NSUserDefaults standardUserDefaults] setObject:savedFormatString forKey:kQLFormatStringKey];
return savedFormatString;
}
@end

View File

@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9060"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="OLSettingController">
<connections>
<outlet property="bunldeTextField" destination="w0s-KN-5HC" id="j9M-4o-AEB"/>
<outlet property="comboBox" destination="UqZ-1F-wC0" id="gNt-Mu-ZbN"/>
<outlet property="commentAsKeyButton" destination="UD6-Va-jOJ" id="wye-4f-NMx"/>
<outlet property="commentSameAsKeyCheckButton" destination="UD6-Va-jOJ" id="qc6-Rf-N8s"/>
<outlet property="commentTextField" destination="4be-14-cLw" id="CVS-cB-pvH"/>
<outlet property="previewLabel" destination="HId-I8-xsX" id="Dt8-we-ze4"/>
<outlet property="swiftCheckButton" destination="D9Q-Un-OAv" id="7X3-b0-hCf"/>
<outlet property="swiftLocalizationPreviewButton" destination="D9Q-Un-OAv" id="Yu7-0E-zvJ"/>
<outlet property="tableNameTextField" destination="pTz-WM-a7f" id="v70-tW-mke"/>
<outlet property="valueTextField" destination="UbR-ET-wcK" id="dc0-fh-ELx"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Xcode Quick Localization Settings" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="588" height="312"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1417"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="588" height="312"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4be-14-cLw">
<rect key="frame" x="105" y="277" width="105" height="22"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="&lt;# comment #&gt;" drawsBackground="YES" id="jgI-yo-s4i">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="commentDidChange:" target="-2" id="aSs-Dr-dKQ"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uQF-yY-Cl8">
<rect key="frame" x="21" y="281" width="66" height="17"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="comment:" id="Fe3-3o-hcT">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pTz-WM-a7f">
<rect key="frame" x="105" y="247" width="105" height="22"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="nil" drawsBackground="YES" id="uPN-08-F50">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="onTableNameChanged:" target="-2" id="DN4-id-Bmo"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="AxW-iO-sMY">
<rect key="frame" x="21" y="251" width="75" height="17"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="tableName:" id="q7z-1m-CNi">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UD6-Va-jOJ">
<rect key="frame" x="222" y="280" width="111" height="17"/>
<animations/>
<buttonCell key="cell" type="check" title="Same as Key?" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="cg9-nb-qHQ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="onCommentAsKayButton:" target="-2" id="px9-bv-K5S"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="D9Q-Un-OAv">
<rect key="frame" x="21" y="161" width="60" height="18"/>
<animations/>
<buttonCell key="cell" type="check" title="Swift?" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Cnw-gx-DEo">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="onSwiftLocalizationPreviewChanged:" target="-2" id="Sdr-iP-jop"/>
</connections>
</button>
<comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UqZ-1F-wC0">
<rect key="frame" x="23" y="124" width="548" height="26"/>
<animations/>
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" numberOfVisibleItems="4" id="Lfv-2P-hwd">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<objectValues>
<string>NSLocalizedString(%@, %@)</string>
<string>NSLocalizedStringFromTableInBundle(%@, %@, %@, %@)</string>
<string>NSLocalizedString(%@, comment: %@)</string>
<string>NSLocalizedString(%@, tableName: %@, bundle: %@, value: %@, comment: %@)</string>
</objectValues>
</comboBoxCell>
<connections>
<action selector="onComboBoxChanged:" target="-2" id="96K-Gl-o26"/>
</connections>
</comboBox>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UbR-ET-wcK">
<rect key="frame" x="105" y="191" width="105" height="22"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="&lt;# value #&gt;" drawsBackground="YES" id="pNa-Hi-MsB">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="onValueTextField:" target="-2" id="xCt-gy-sBF"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NMp-3M-z2d">
<rect key="frame" x="21" y="195" width="40" height="17"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="value:" id="QdF-5G-Ouu">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="w0s-KN-5HC">
<rect key="frame" x="105" y="217" width="105" height="22"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="nil" drawsBackground="YES" id="kkj-EX-CmJ">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="onBunldeNameChanged:" target="-2" id="Eh5-it-x5x"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6wB-B8-UK0">
<rect key="frame" x="21" y="221" width="50" height="17"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="bundle:" id="3F0-yl-Ms0">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wkS-OA-33u">
<rect key="frame" x="21" y="103" width="55" height="17"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="preview:" id="srm-6Q-pMN">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HId-I8-xsX">
<rect key="frame" x="20" y="78" width="549" height="17"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="4xj-Fm-hoi">
<font key="font" metaFont="system" size="10"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<animations/>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="423" y="679"/>
</window>
</objects>
</document>

View File

@@ -42,13 +42,22 @@
<string></string>
<key>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>E969541F-E6F9-4D25-8158-72DC3545A6C6</string>
<string>9F75337B-21B4-4ADC-B558-F9CADF7073A7</string>
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
<string>37B30044-3B14-46BA-ABAA-F01000C27B63</string>
<string>A2E4D43F-41F4-4FB9-BB94-7177011C9AED</string>
<string>C4A681B0-4A26-480E-93EC-1218098B9AA0</string>
<string>A16FF353-8441-459E-A50C-B071F53F51B7</string>
<string>AD68E85B-441B-4301-B564-A45E4919A6AD</string>
<string>A2E4D43F-41F4-4FB9-BB94-7177011C9AED</string>
<string>37B30044-3B14-46BA-ABAA-F01000C27B63</string>
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
<string>C4A681B0-4A26-480E-93EC-1218098B9AA0</string>
<string>FEC992CC-CA4A-4CFD-8881-77300FCB848A</string>
<string>992275C1-432A-4CF7-B659-D84ED6D42D3F</string>
<string>A16FF353-8441-459E-A50C-B071F53F51B7</string>
<string>9F75337B-21B4-4ADC-B558-F9CADF7073A7</string>
<string>8DC44374-2B35-4C57-A6FE-2AD66A36AAD9</string>
<string>E969541F-E6F9-4D25-8158-72DC3545A6C6</string>
<string>AABB7188-E14E-4433-AD3B-5CD791EAD9A3</string>
<string>7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90</string>
<string>CC0D0F4F-05B3-431A-8F33-F84AFCB2C651</string>
<string>0420B86A-AA43-4792-9ED0-6FE0F2B16A13</string>
<string>7265231C-39B4-402C-89E1-16167C4CC990</string>
</array>
<key>XC4Compatible</key>
<true/>

View File

@@ -4,4 +4,5 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import "AMConstString.h"
#endif

View File

@@ -8,6 +8,8 @@
#import "QuickLocalization.h"
#import "RCXcode.h"
#import "OLSettingController.h"
#import "AMMenuGenerator.h"
static NSString *localizeRegexs[] = {
@"NSLocalizedString\\s*\\(\\s*@\"(.*)\"\\s*,\\s*(.*)\\s*\\)",
@@ -23,13 +25,16 @@ static NSString *swiftStringRegexs = @"([\"'])(?:(?=(\\\\?))\\2.)*?\\1";
static NSString * const QLShouldUseNilForComment = @"QLShouldUseNilForComment";
static NSString * const QLShouldUseSnippetForComment = @"QLShouldUseSnippetForComment";
static NSString * const QLShouldUseSwiftSyntax = @"QLShouldUseSwiftSyntax";
static NSString * const QLShouldUseNSLocalizedStringFromTableInBundle = @"QLShouldUseNSLocalizedStringFromTableInBundle";
@interface QuickLocalization ()
@property (nonatomic, assign) BOOL shouldUseNilForComment;
@property (nonatomic, assign) BOOL shouldUseSnippetForComment;
@property (nonatomic, assign) BOOL shouldUseSwiftSyntax;
@property (nonatomic, assign) BOOL shouldUseStringFromTableInBundle;
@property (nonatomic, strong) OLSettingController *settingControlelr;
@property (nonatomic, strong) NSBundle *bundle;
@end
@implementation QuickLocalization
@@ -37,50 +42,78 @@ static NSString * const QLShouldUseSwiftSyntax = @"QLShouldUseSwiftSyntax";
static id sharedPlugin = nil;
+ (void)pluginDidLoad:(NSBundle *)plugin {
+ (void)pluginDidLoad:(NSBundle *)plugin
{
static id sharedPlugin = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedPlugin = [[self alloc] init];
});
NSString *currentApplicationName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"];
if ([currentApplicationName isEqual:@"Xcode"]) {
dispatch_once(&onceToken, ^{
sharedPlugin = [[self alloc] initWithBundle:plugin];
});
}
}
- (id)init {
- (id)initWithBundle:(NSBundle *)plugin
{
if (self = [super init]) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSMenuItem *viewMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];
if (viewMenuItem) {
[[viewMenuItem submenu] addItem:[NSMenuItem separatorItem]];
NSMenuItem *localization = [[NSMenuItem alloc] initWithTitle:@"Quick Localization" action:@selector(quickLocalization) keyEquivalent:@"d"];
[localization setKeyEquivalentModifierMask:NSShiftKeyMask | NSAlternateKeyMask];
[localization setTarget:self];
NSMenuItem *nilToggle = [[NSMenuItem alloc] initWithTitle:@"Use nil for NSLocalizedString comment" action:@selector(toggleNilOption) keyEquivalent:@""];
[nilToggle setTarget:self];
NSMenuItem *snippetToggle = [[NSMenuItem alloc] initWithTitle:@"Use <# comments #> for NSLocalizedString comment" action:@selector(toggleSnippetOption) keyEquivalent:@""];
[snippetToggle setTarget:self];
NSMenuItem *swiftSyntax = [[NSMenuItem alloc] initWithTitle:@"Swift Localization" action:@selector(toggleSwiftOption) keyEquivalent:@""];
[swiftSyntax setTarget:self];
NSMenu *groupMenu = [[NSMenu alloc] initWithTitle:@"Quick Localization"];
[groupMenu addItem:localization];
[groupMenu addItem:nilToggle];
[groupMenu addItem:snippetToggle];
[groupMenu addItem:swiftSyntax];
NSMenuItem *groupMenuItem = [[NSMenuItem alloc] initWithTitle:@"Quick Localization" action:NULL keyEquivalent:@""];
[[viewMenuItem submenu] addItem:groupMenuItem];
[[viewMenuItem submenu] setSubmenu:groupMenu forItem:groupMenuItem];
}
}];
// reference to plugin's bundle, for resource acccess
self.bundle = plugin;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidFinishLaunching:)
name:NSApplicationDidFinishLaunchingNotification
object:nil];
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self createMenuItem];
}
- (void)createMenuItem {
[AMMenuGenerator generateMenuItems:self.bundle version:[self getBundleVersion] target:self];
// return;
// [[NSOperationQueue mainQueue] addOperationWithBlock:^{
// NSMenuItem *viewMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];
// if (viewMenuItem) {
// [[viewMenuItem submenu] addItem:[NSMenuItem separatorItem]];
//
// NSMenuItem *localization = [[NSMenuItem alloc] initWithTitle:@"Quick Localization" action:@selector(quickLocalization:) keyEquivalent:@"d"];
// [localization setKeyEquivalentModifierMask:NSShiftKeyMask | NSAlternateKeyMask];
// [localization setTarget:self];
// [localization setTag:0];
//
// NSMenuItem *shouldUseStringFromTableInBundleToggle = [[NSMenuItem alloc] initWithTitle:@"NSLocalizedStringFromTableInBundle" action:@selector(toggleStringFromTableInBundle) keyEquivalent:@""];
// [shouldUseStringFromTableInBundleToggle setTarget:self];
//
// NSMenuItem *nilToggle = [[NSMenuItem alloc] initWithTitle:@"Use nil for NSLocalizedString comment" action:@selector(toggleNilOption) keyEquivalent:@""];
// [nilToggle setTarget:self];
//
// NSMenuItem *snippetToggle = [[NSMenuItem alloc] initWithTitle:@"Use <# comments #> for NSLocalizedString comment" action:@selector(toggleSnippetOption) keyEquivalent:@""];
// [snippetToggle setTarget:self];
//
// NSMenuItem *swiftSyntax = [[NSMenuItem alloc] initWithTitle:@"Swift Localization" action:@selector(toggleSwiftOption) keyEquivalent:@""];
// [swiftSyntax setTarget:self];
//
// NSMenu *groupMenu = [[NSMenu alloc] initWithTitle:@"Quick Localization"];
// [groupMenu addItem:localization];
// [groupMenu addItem:nilToggle];
// [groupMenu addItem:snippetToggle];
// [groupMenu addItem:swiftSyntax];
// [groupMenu addItem:shouldUseStringFromTableInBundleToggle];
//
// NSMenuItem *groupMenuItem = [[NSMenuItem alloc] initWithTitle:@"Quick Localization" action:NULL keyEquivalent:@""];
// [[viewMenuItem submenu] addItem:groupMenuItem];
// [[viewMenuItem submenu] setSubmenu:groupMenu forItem:groupMenuItem];
// }
// }];
}
// Sample Action, for menu item:
- (void)quickLocalization {
- (void)quickLocalization:(id)sender {
IDESourceCodeDocument *document = [RCXcode currentSourceCodeDocument];
NSTextView *textView = [RCXcode currentSourceCodeTextView];
if (!document || !textView) {
@@ -94,6 +127,8 @@ static id sharedPlugin = nil;
NSRange lineRange = [textView.textStorage.string lineRangeForRange:range];
NSString *line = [textView.textStorage.string substringWithRange:lineRange];
NSRegularExpression *localizedRex = [[NSRegularExpression alloc] initWithPattern:localizeRegexs[0] options:NSRegularExpressionCaseInsensitive error:nil];
NSArray *localizedMatches = [localizedRex matchesInString:line options:0 range:NSMakeRange(0, [line length])];
@@ -108,26 +143,22 @@ static id sharedPlugin = nil;
continue;
}
NSString *string = [line substringWithRange:matchedRangeInLine];
// NSLog(@"string index:%d, %@", i, string);
// NSLog(@"string index:%d, %@", i, string);
NSString *outputString;
NSString *swiftAddtion = self.shouldUseSwiftSyntax ? @"comment: " : @"";
if ([self shouldUseNilForComment]) {
if (self.shouldUseSwiftSyntax) {
outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, comment: \"\")", string];
}
else {
outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, nil)", string];
}
NSString *savedFormatString = [[NSUserDefaults standardUserDefaults] objectForKey:kQLFormatStringKey];
NSUInteger placeHolderCount = QL_CountOccurentOfStringWithSubString(savedFormatString, @"%@");
if (placeHolderCount == 2) {
outputString = [NSString stringWithFormat:savedFormatString, string, string];
}
else if ([self shouldUseSnippetForComment]) {
outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, %@<# comments #>)", string, swiftAddtion];
else if (placeHolderCount == 1) {
outputString = [NSString stringWithFormat:savedFormatString, string];
}
else {
outputString = [NSString stringWithFormat:@"NSLocalizedString(%@, %@%@)", string, swiftAddtion ,string];
outputString = [NSString stringWithFormat:@"placeholder incorrect, it is %@", savedFormatString];
}
addedLength = addedLength + outputString.length - string.length;
if ([textView shouldChangeTextInRange:matchedRangeInDocument replacementString:outputString]) {
[textView.textStorage replaceCharactersInRange:matchedRangeInDocument
@@ -143,7 +174,8 @@ static id sharedPlugin = nil;
}
- (NSString *)currentStringRegexs {
if (self.shouldUseSwiftSyntax) {
BOOL isSwiftSyntax = [[NSUserDefaults standardUserDefaults] boolForKey:kQLFormatStringSwiftSyntax];
if (isSwiftSyntax) {
return swiftStringRegexs;
}
else {
@@ -194,7 +226,18 @@ static id sharedPlugin = nil;
return YES;
}
- (void)toggleStringFromTableInBundle {
self.shouldUseStringFromTableInBundle = !self.shouldUseStringFromTableInBundle;
}
#pragma mark Preferences
- (BOOL)shouldUseStringFromTableInBundle {
return [[NSUserDefaults standardUserDefaults] boolForKey:QLShouldUseNSLocalizedStringFromTableInBundle];
}
- (void)setShouldUseStringFromTableInBundle:(BOOL)shouldUseStringFromTableInBundle {
[[NSUserDefaults standardUserDefaults] setBool:shouldUseStringFromTableInBundle forKey:QLShouldUseNSLocalizedStringFromTableInBundle];
}
- (BOOL)shouldUseNilForComment {
return [[NSUserDefaults standardUserDefaults] boolForKey:QLShouldUseNilForComment];
@@ -219,4 +262,21 @@ static id sharedPlugin = nil;
- (void)setShouldUseSwiftSyntax:(BOOL)shouldUseSwiftSyntax {
[[NSUserDefaults standardUserDefaults] setBool:shouldUseSwiftSyntax forKey:QLShouldUseSwiftSyntax];
}
- (NSString *)getBundleVersion
{
NSString *bundleVersion = [[self.bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"];
return bundleVersion;
}
- (void)showSettingWindow
{
if (self.settingControlelr == nil) {
self.settingControlelr = [[OLSettingController alloc] initWithWindowNibName:@"OLSettingController"];
self.settingControlelr.bundle = self.bundle;
}
[self.settingControlelr showWindow:self.settingControlelr];
}
@end