Skip to content

Commit

Permalink
playing with interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cescofry committed Jun 26, 2013
1 parent 107fb61 commit 344a12a
Show file tree
Hide file tree
Showing 21 changed files with 1,937 additions and 1,496 deletions.
20 changes: 20 additions & 0 deletions HiperStrings/Controllers/ZFFileDetailController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// ZFFileDetailController.h
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZFLangFile.h"

@interface ZFFileDetailController : NSObject <NSTableViewDataSource, NSTableViewDelegate>

@property (nonatomic, strong) IBOutlet NSSegmentedControl *segmentedControl;
@property (nonatomic, strong) IBOutlet NSTableView *tableView;
@property (nonatomic, strong) ZFLangFile *langFile;

- (IBAction)didSwithSegmentedControl:(NSSegmentedControl *)sender;

@end
72 changes: 72 additions & 0 deletions HiperStrings/Controllers/ZFFileDetailController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// ZFFileDetailController.m
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import "ZFFileDetailController.h"

#define KEY_KEY @"Keys"

@interface ZFFileDetailController ()

@property (nonatomic, strong) NSArray *keys;
@property (nonatomic, strong) NSDictionary *rows;
@property (nonatomic, strong) NSArray *columns;

@end

@implementation ZFFileDetailController

- (void)setLangFile:(ZFLangFile *)langFile {
_langFile = langFile;

[self didSwithSegmentedControl:self.segmentedControl];

}

#pragma mark - Segmented Controller

- (IBAction)didSwithSegmentedControl:(NSSegmentedControl *)sender {
self.rows = (self.segmentedControl.selectedSegment == 0)? [self.langFile iOStranslations] : [self.langFile androidTranslations];

self.columns = [[NSArray arrayWithObject:KEY_KEY] arrayByAddingObjectsFromArray:[self.rows allKeys]];
self.keys = (self.columns.count > 1)? [[self.rows objectForKey:[self.columns objectAtIndex:1]] allKeys] : [NSArray array];

NSMutableArray *addCol = [self.columns mutableCopy];

[self.tableView beginUpdates];

NSArray *columns = [self.tableView.tableColumns copy];
[columns enumerateObjectsUsingBlock:^(NSTableColumn *column, NSUInteger idx, BOOL *stop) {
if ([self.columns containsObject:column.identifier]) {
[addCol removeObject:column.identifier];
return;
}

[self.tableView removeTableColumn:column];
}];
[addCol enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:obj];
[column setHeaderCell:[[NSCell alloc] initTextCell:obj]];
[self.tableView addTableColumn:column];
}];

[self.tableView reloadData];
[self.tableView endUpdates];
}

#pragma mark - TableView

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [self.rows count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
if ([tableColumn.identifier isEqualToString:KEY_KEY]) return [self.keys objectAtIndex:row];
else return [[self.rows objectForKey:tableColumn.identifier] objectForKey:[self.keys objectAtIndex:row]];
}

@end
18 changes: 18 additions & 0 deletions HiperStrings/Controllers/ZFFilesController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ZFFilesController.h
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZFFileDetailController.h"

@interface ZFFilesController : NSObject <NSTableViewDataSource, NSTableViewDelegate>

@property (nonatomic, strong) IBOutlet ZFFileDetailController *fileDetailController;
@property (nonatomic, strong) IBOutlet NSTableView *filesTable;
@property (assign) IBOutlet NSWindow *window;

@end
91 changes: 91 additions & 0 deletions HiperStrings/Controllers/ZFFilesController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// ZFFilesController.m
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import "ZFFilesController.h"
#import "ZFFileViewCell.h"
#import "ZFStringScanner.h"
#import "ZFLangFile.h"

@interface ZFFilesController ()

@property (nonatomic, strong) NSURL *sourceURL;
@property (nonatomic, strong) ZFStringScanner *scanner;

@end

@implementation ZFFilesController

#pragma mark - tableview

- (id)init
{
self = [super init];
if (self) {
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self load];
});
}
return self;
}

- (void)load {
[self setURLFromDialog:^(BOOL success) {
if (!self.sourceURL || !success) return;
self.scanner = [[ZFStringScanner alloc] init];
[self.scanner startScanAtURL:self.sourceURL];
[self.filesTable reloadData];
/*
[scanner.files enumerateObjectsUsingBlock:^(ZFLangFile *obj, NSUInteger idx, BOOL *stop) {
NSLog(@"file\n %@[%@]\n %@[%@]", obj.iOSName, [obj.iOStranslations.allKeys componentsJoinedByString:@"|"], obj.androidName, [obj.androidTranslations.allKeys componentsJoinedByString:@"|"]);
}];
*/

}];
}


- (void)setURLFromDialog:(void (^)(BOOL success)) completed {
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:NO];
[openDlg setAllowsMultipleSelection:NO];
[openDlg setCanChooseDirectories:YES];


void (^completitionBlock)(NSInteger) = ^(NSInteger result) {
if (result != NSOKButton) {
if (completed) completed(NO);
return;
}

self.sourceURL = openDlg.URL;
if (completed) completed(YES);
};

if (!self.window) [openDlg beginWithCompletionHandler:completitionBlock];
else [openDlg beginSheetModalForWindow:self.window completionHandler:completitionBlock];
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [self.scanner.files count];
}

- (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
ZFFileViewCell *cell = [tableView makeViewWithIdentifier:@"langCell" owner:self];
[cell setLangFile:[self.scanner.files objectAtIndex:row]];

return cell;
}

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row {
if (self.fileDetailController) [self.fileDetailController setLangFile:[self.scanner.files objectAtIndex:row]];
return YES;
}

@end
1 change: 1 addition & 0 deletions HiperStrings/HiperStrings-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import "ZFUtils.h"
#endif
16 changes: 16 additions & 0 deletions HiperStrings/Views/ZFFileViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ZFFileViewCell.h
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "ZFLangFile.h"

@interface ZFFileViewCell : NSTableCellView

@property (nonatomic, strong) ZFLangFile *langFile;

@end
50 changes: 50 additions & 0 deletions HiperStrings/Views/ZFFileViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// ZFFileViewCell.m
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import "ZFFileViewCell.h"

@interface ZFFileViewCell ()

@property (nonatomic, strong) NSTextView *titleLbl;
@property (nonatomic, strong) NSTextView *detailLbl;

@end

@implementation ZFFileViewCell

- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
frame = self.bounds;
frame.size.height = ceil(frame.size.height /2);
self.titleLbl = [[NSTextView alloc] initWithFrame:frame];
[self addSubview:self.titleLbl];

frame.origin.y += frame.size.height;
self.detailLbl = [[NSTextView alloc] initWithFrame:frame];
[self addSubview:self.detailLbl];
}

return self;
}

- (void)setLangFile:(ZFLangFile *)langFile {
_langFile = langFile;
if (_langFile.iOSName.length > 0) [self.textField setStringValue:_langFile.iOSName];

if (_langFile.androidName.length > 0) [self.textField setStringValue:_langFile.androidName];
}

- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
}

@end
15 changes: 15 additions & 0 deletions HiperStrings/Views/ZFTranslationView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ZFTranslationCollectionItem.h
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface ZFTranslationView : NSView

@property (nonatomic, strong) IBOutlet NSTextView *label;

@end
17 changes: 17 additions & 0 deletions HiperStrings/Views/ZFTranslationView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ZFTranslationCollectionItem.m
// Strings
//
// Created by Francesco on 26/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import "ZFTranslationView.h"

@interface ZFTranslationView ()

@end

@implementation ZFTranslationView

@end
30 changes: 1 addition & 29 deletions HiperStrings/ZFAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ZFAppDelegate.h"
#import "ZFStringScanner.h"
#import "ZFLangFile.h"

@interface ZFAppDelegate ()

Expand All @@ -19,35 +20,6 @@ @implementation ZFAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[self setURLFromDialog:^(BOOL success) {
if (!self.sourceURL || !success) return;
ZFStringScanner *scanner = [[ZFStringScanner alloc] init];
[scanner scanStringsAtURL:self.sourceURL];
}];
}


- (void)setURLFromDialog:(void (^)(BOOL success)) completed {
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:NO];
[openDlg setAllowsMultipleSelection:NO];
[openDlg setCanChooseDirectories:YES];


void (^completitionBlock)(NSInteger) = ^(NSInteger result) {
if (result != NSOKButton) {
if (completed) completed(NO);
return;
}

self.sourceURL = openDlg.URL;
if (completed) completed(YES);
};

if (!self.window) [openDlg beginWithCompletionHandler:completitionBlock];
else [openDlg beginSheetModalForWindow:self.window completionHandler:completitionBlock];
}


@end
Loading

0 comments on commit 344a12a

Please sign in to comment.