Skip to content

Commit

Permalink
Converts to modern Objective-C syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
zonble committed May 23, 2015
1 parent 3d80b8f commit e13cd36
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 39 deletions.
Expand Up @@ -26,7 +26,7 @@ - (NSString *)absolutePathFromBaseDirPath:(NSString *)baseDirPath
NSMutableArray *pathComponents2 = [NSMutableArray arrayWithArray:[theBasePath pathComponents]];

while ([pathComponents1 count] > 0) {
NSString *topComponent1 = [pathComponents1 objectAtIndex:0];
NSString *topComponent1 = pathComponents1[0];
[pathComponents1 removeObjectAtIndex:0];

if ([topComponent1 isEqualToString:@".."]) {
Expand Down Expand Up @@ -55,8 +55,8 @@ - (NSString *)relativePathFromBaseDirPath:(NSString *)baseDirPath

// Remove same path components
while ([pathComponents1 count] > 0 && [pathComponents2 count] > 0) {
NSString *topComponent1 = [pathComponents1 objectAtIndex:0];
NSString *topComponent2 = [pathComponents2 objectAtIndex:0];
NSString *topComponent1 = pathComponents1[0];
NSString *topComponent2 = pathComponents2[0];
if (![topComponent1 isEqualToString:topComponent2]) {
break;
}
Expand Down
16 changes: 8 additions & 8 deletions Localizer/JHDocument.m
Expand Up @@ -52,7 +52,7 @@ - (void)dealloc
[super dealloc];
}

- (id)init
- (instancetype)init
{
self = [super init];
if (self) {
Expand Down Expand Up @@ -154,9 +154,9 @@ - (IBAction)addScanFolderAndFiles:(id)sender
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:YES];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setAllowedFileTypes:[NSArray arrayWithObjects:@"h", @"m",@"mm", nil]];
[openPanel setAllowedFileTypes:@[@"h", @"m",@"mm"]];

NSWindow *window = [[[self windowControllers] objectAtIndex:0] window];
NSWindow *window = [[self windowControllers][0] window];
[openPanel beginSheetModalForWindow:window completionHandler:^(NSInteger result) {
if (result == NSOKButton) {
NSMutableArray *pathsToAdd = [NSMutableArray array];
Expand Down Expand Up @@ -195,7 +195,7 @@ - (IBAction)scan:(id)sender
[message appendFormat:@"%d. %@\n\n",count, addedMatchInfo.key];
}
NSAlert *alert = [NSAlert alertWithMessageText:message defaultButton:NSLocalizedString(@"OK", @"") alternateButton:nil otherButton:nil informativeTextWithFormat:@""];
NSWindow *window = [[[self windowControllers] objectAtIndex:0] window];
NSWindow *window = [[self windowControllers][0] window];
[alert beginSheetModalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil];
}
// merge src info set and localizable info set
Expand All @@ -212,7 +212,7 @@ - (IBAction)translate:(id)sender
translatedWindowController.translatedWindowControllerDelegate = self;
[self addWindowController:translatedWindowController];
}
NSWindow *window = [[[self windowControllers] objectAtIndex:0] window];
NSWindow *window = [[self windowControllers][0] window];
[NSApp beginSheet:translatedWindowController.window modalForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:nil];
}

Expand All @@ -226,7 +226,7 @@ - (IBAction)filterWithSearchType:(id)sender
- (IBAction)performFindPanelAction:(id)sender
{
if ([sender tag] == 1) {
NSWindow *window = [[[self windowControllers] objectAtIndex:0] window];
NSWindow *window = [[self windowControllers][0] window];
[window makeFirstResponder:searchField];
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ - (void)windowController:(JHTranslatedWindowController *)inWindowController didM
if ([localizableInfoSet containsObject:obj]) {
NSUInteger index = [result indexOfObject:obj];

JHMatchInfo *matchInfo = [result objectAtIndex:index];
JHMatchInfo *matchInfo = result[index];
obj.filePath = matchInfo.filePath;

if ([obj.key isEqualToString:obj.translateString]) {
Expand All @@ -323,7 +323,7 @@ - (void)windowController:(JHTranslatedWindowController *)inWindowController didM
if ([obj.filePath isEqualToString:@"Not exist"]) {
obj.state = notExist;
}
[result replaceObjectAtIndex:index withObject:obj];
result[index] = obj;
}
else {
obj.state = notExist;
Expand Down
10 changes: 5 additions & 5 deletions Localizer/JHFilePathTableViewController.m
Expand Up @@ -83,7 +83,7 @@ - (void)dealloc
[super dealloc];
}

- (id)init
- (instancetype)init
{
self = [super init];
if (self) {
Expand All @@ -97,7 +97,7 @@ - (id)init
- (void)awakeFromNib
{
// Register to accept filename drag/drop
[self.view registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
[self.view registerForDraggedTypes:@[NSFilenamesPboardType]];
NSTableView *tableView = (NSTableView *)self.view;
NSTableColumn *column = [tableView tableColumnWithIdentifier:@"path"];
[column setEditable:NO];
Expand Down Expand Up @@ -129,7 +129,7 @@ - (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColu

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
return [[filePathArray objectAtIndex:row] path];
return [filePathArray[row] path];
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation
Expand Down Expand Up @@ -172,8 +172,8 @@ - (void)tableView:(NSTableView *)inTableView didDeleteScanFoldersWithIndexes:(NS
- (void)tableView:(NSTableView *)inTableView didOpenScanFoldersWithIndexes:(NSIndexSet *)inIndexes
{
[inIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSDictionary* errors = [NSDictionary dictionary];
NSString *scriptString = [NSString stringWithFormat:@"tell application \"Finder\" \n activate\n open (\"%@\" as POSIX file) \n end tell",[filePathArray objectAtIndex:idx]];
NSDictionary* errors = @{};
NSString *scriptString = [NSString stringWithFormat:@"tell application \"Finder\" \n activate\n open (\"%@\" as POSIX file) \n end tell",filePathArray[idx]];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithSource:scriptString];
[appleScript executeAndReturnError:&errors];
[appleScript release];
Expand Down
4 changes: 2 additions & 2 deletions Localizer/JHLocalizableSettingParser.m
Expand Up @@ -49,7 +49,7 @@ - (void)parse:(NSString *)fileContent scanFolderPathArray:(out NSArray **)outArr
- (NSArray *)scanFolderPathsFromString:(NSString *)inFolderPaths
{
if (![inFolderPaths length]) {
return [NSArray array];
return @[];
}
NSMutableArray *result = [NSMutableArray array];
for (NSString *folderPath in [inFolderPaths componentsSeparatedByString:@","]) {
Expand Down Expand Up @@ -133,7 +133,7 @@ - (NSSet *)makeMatchRecord:(NSString *)belongFilePath bodyString:(NSString *)inB
//matchInfo 是以 key 為比對方式,key 相同就存在,在除了 key 以外的資訊有可能不同,所以採用 replace 的方式置換
if ([result containsObject:matchInfo]) {
NSUInteger index = [result indexOfObject:matchInfo];
[result replaceObjectAtIndex:index withObject:matchInfo];
result[index] = matchInfo;
}
else {
[result addObject:matchInfo];
Expand Down
7 changes: 3 additions & 4 deletions Localizer/JHMatchInfo.h
Expand Up @@ -25,11 +25,11 @@

#import <Foundation/Foundation.h>

typedef enum {
typedef NS_ENUM(unsigned int, MatchInfoRecordState) {
notExist, // not exist
unTranslated, // untranslatedString
translated // translatedString
} MatchInfoRecordState;
};

@interface JHMatchInfo : NSObject<NSCopying, NSCoding, NSPasteboardWriting, NSPasteboardReading>
{
Expand All @@ -45,7 +45,6 @@ typedef enum {
@property (retain, nonatomic) NSString *comment;
@property (retain, nonatomic) NSString *filePath;

- (MatchInfoRecordState)state;
- (void)setState:(MatchInfoRecordState)state;
@property (NS_NONATOMIC_IOSONLY) MatchInfoRecordState state;

@end
2 changes: 1 addition & 1 deletion Localizer/JHMatchInfo.m
Expand Up @@ -136,7 +136,7 @@ - (void)encodeWithCoder:(NSCoder *)coder
[coder encodeObject:self.filePath forKey:@"kFilePath"];
}

- (id)initWithCoder:(NSCoder *)aDecoder
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
Expand Down
6 changes: 3 additions & 3 deletions Localizer/JHMatchInfoRecordColorTransformer.m
Expand Up @@ -58,13 +58,13 @@ - (id)transformedValue:(id)value
- (id)reverseTransformedValue:(id)value
{
if (value == [NSColor blueColor]) {
return [NSNumber numberWithInt:unTranslated];
return @(unTranslated);
}
else if(value == [NSColor redColor]) {
return [NSNumber numberWithInt:notExist];
return @(notExist);
}
else if(value == [NSColor blackColor]) {
return [NSNumber numberWithInt:translated];
return @(translated);
}
return nil;
}
Expand Down
4 changes: 2 additions & 2 deletions Localizer/JHMatchInfoTableView.m
Expand Up @@ -27,7 +27,7 @@ a copy of this software and associated documentation files (the

@implementation JHMatchInfoTableView

- (id)initWithCoder:(NSCoder *)aDecoder
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];

Expand All @@ -43,7 +43,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
[self setAllowsMultipleSelection: YES];

for (int i = 0; i < [self.tableColumns count] ; i++) {
[[self.tableColumns objectAtIndex:i] setHeaderCell:[[[NSTableHeaderCell alloc] initTextCell:[headerNameArray objectAtIndex:i]] autorelease]];
[(self.tableColumns)[i] setHeaderCell:[[[NSTableHeaderCell alloc] initTextCell:headerNameArray[i]] autorelease]];
}
}
return self;
Expand Down
4 changes: 2 additions & 2 deletions Localizer/JHMatchInfoTableViewController.h
Expand Up @@ -42,10 +42,10 @@
- (void)reloadMatchInfoRecords:(NSArray *)inArray;

//利用 match info 的所有資訊生成一個固定格式的字串
- (NSString *)matchInfosString;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *matchInfosString;

//回傳排序好的 match info file path 陣列
- (NSArray *)sortedMatchInfoFilePathArray;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *sortedMatchInfoFilePathArray;

//matchInfo array 要 redo 的時候使用這個介面 restore 資料
- (void)restoreMatchinfoArray:(NSArray *)inArray actionName:(NSString *)inActionName;
Expand Down
6 changes: 3 additions & 3 deletions Localizer/JHMatchInfoTableViewController.m
Expand Up @@ -100,8 +100,8 @@ - (JHMatchInfo *)copiedMatchInfo:(JHMatchInfo *)inMatchInfo
- (void)tableView:(NSTableView *)inTableView didPasteMatchInfosWithIndexes:(NSIndexSet *)inIndexes
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[JHMatchInfo class]];
NSDictionary *options = [NSDictionary dictionary];
NSArray *classArray = @[[JHMatchInfo class]];
NSDictionary *options = @{};

BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
if (ok) {
Expand Down Expand Up @@ -209,7 +209,7 @@ - (void)changeKeyPath:(NSString *)keyPath ofObject:(id)object toValue:(id)newVal

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(JHMatchInfo *)object change:(NSDictionary *)change context:(void *)context
{
id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
id oldValue = change[NSKeyValueChangeOldKey];
[[undoManager prepareWithInvocationTarget:self] changeKeyPath:keyPath ofObject:object toValue:oldValue];
if (!undoManager.isUndoing) {
[undoManager setActionName:NSLocalizedString(@"Edit", @"")];
Expand Down
4 changes: 2 additions & 2 deletions Localizer/JHScanFoldersTableView.m
Expand Up @@ -13,7 +13,7 @@

@implementation JHScanFoldersTableView

- (id)initWithCoder:(NSCoder *)aDecoder
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];

Expand All @@ -23,7 +23,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder
[self setAllowsMultipleSelection: YES];

for (int i = 0; i < [self.tableColumns count] ; i++) {
[[self.tableColumns objectAtIndex:i] setHeaderCell:[[[NSTableHeaderCell alloc] initTextCell:[headerNameArray objectAtIndex:i]] autorelease]];
[(self.tableColumns)[i] setHeaderCell:[[[NSTableHeaderCell alloc] initTextCell:headerNameArray[i]] autorelease]];
}
}
return self;
Expand Down
7 changes: 3 additions & 4 deletions Localizer/JHSourceCodeParser.m
Expand Up @@ -80,7 +80,7 @@ @implementation JHSourceCodeParser
BOOL isDir = NO;
// Because we used GTMUILocalizer, so we must maintain key in xib.
[[NSFileManager defaultManager] fileExistsAtPath:absoluteFilePath isDirectory:&isDir];
if ([[NSArray arrayWithObjects:@"h", @"m", @"mm", @"xib", @"swift", nil] containsObject:[absoluteFilePath pathExtension]] || isDir) {
if ([@[@"h", @"m", @"mm", @"xib", @"swift"] containsObject:[absoluteFilePath pathExtension]] || isDir) {
NSString *fileContent = [NSString stringWithContentsOfFile:absoluteFilePath encoding:NSUTF8StringEncoding error:&e];
if (e) {
if (error != nil) {
Expand All @@ -101,12 +101,11 @@ @implementation JHSourceCodeParser
(.*?) 這是 Reluctant 的做法
, key 和 comment 之間要有一個分隔符號 ,
*/
NSArray *patterns = [NSArray arrayWithObjects:
@"NSLocalizedString\\s*\\(\\s*@\"(.*?)\"\\s*,\\s*@?\"?(.*?)\"?\\s*\\)",
NSArray *patterns = @[@"NSLocalizedString\\s*\\(\\s*@\"(.*?)\"\\s*,\\s*@?\"?(.*?)\"?\\s*\\)",
@"NSLocalizedString\\s*\\(\\s*\"(.*?)\"\\s*,\\s*commemt:\\s*@?\"?(.*?)\"?\\s*\\)",
@"LFLSTR\\s*\\(\\s*@\"(.*?)\"\\s*\\)",
@"LFLSTR\\s*\\(\\s*\"(.*?)\"\\s*\\)",
@"\\^(.*?)<",nil];
@"\\^(.*?)<"];
for (NSString *pattern in patterns) {
[result unionSet:makeMatchInfoSet(pattern, fileContent, extFilePath)];
}
Expand Down

0 comments on commit e13cd36

Please sign in to comment.