Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dataich committed Aug 6, 2013
2 parents 2647616 + 3bb40db commit 2cdee0d
Show file tree
Hide file tree
Showing 13 changed files with 2,451 additions and 26 deletions.
18 changes: 18 additions & 0 deletions LiveDiag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
0A41C46817A6B885008F9FEA /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A41C46717A6B885008F9FEA /* WebKit.framework */; };
0A4A5F3517A7A54800BE1CF9 /* NSString+Count.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A4A5F3417A7A54800BE1CF9 /* NSString+Count.m */; };
0A675C5617A88BBC00EDEB47 /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0A675C5517A88BBC00EDEB47 /* Icon.icns */; };
0A8087DA17ABF742007CA399 /* LDPreferencesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0A8087D917ABF742007CA399 /* LDPreferencesViewController.m */; };
0AA098F817AFEB4D0011E472 /* LDAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AA098F717AFEB4D0011E472 /* LDAppDelegate.m */; };
0AA098FB17AFF6A20011E472 /* LDUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AA098FA17AFF6A20011E472 /* LDUtils.m */; };
0AEF9BD917A743B600A2A3B1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BD617A743B600A2A3B1 /* Localizable.strings */; };
0AEF9BDA17A743CB00A2A3B1 /* jquery-2.0.3.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */; };
0AEF9BE017A751D000A2A3B1 /* application.css in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BDF17A751D000A2A3B1 /* application.css */; };
Expand All @@ -43,6 +46,12 @@
0A4A5F3317A7A54800BE1CF9 /* NSString+Count.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Count.h"; sourceTree = "<group>"; };
0A4A5F3417A7A54800BE1CF9 /* NSString+Count.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Count.m"; sourceTree = "<group>"; };
0A675C5517A88BBC00EDEB47 /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
0A8087D817ABF742007CA399 /* LDPreferencesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LDPreferencesViewController.h; sourceTree = "<group>"; };
0A8087D917ABF742007CA399 /* LDPreferencesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LDPreferencesViewController.m; sourceTree = "<group>"; };
0AA098F617AFEB4D0011E472 /* LDAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LDAppDelegate.h; sourceTree = "<group>"; };
0AA098F717AFEB4D0011E472 /* LDAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LDAppDelegate.m; sourceTree = "<group>"; };
0AA098F917AFF6A20011E472 /* LDUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LDUtils.h; sourceTree = "<group>"; };
0AA098FA17AFF6A20011E472 /* LDUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LDUtils.m; sourceTree = "<group>"; };
0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "jquery-2.0.3.min.js"; sourceTree = "<group>"; };
0AEF9BD617A743B600A2A3B1 /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
0AEF9BDF17A751D000A2A3B1 /* application.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = application.css; sourceTree = "<group>"; };
Expand Down Expand Up @@ -107,8 +116,12 @@
0A11A98117A6B50800E94748 /* LiveDiag */ = {
isa = PBXGroup;
children = (
0AA098F617AFEB4D0011E472 /* LDAppDelegate.h */,
0AA098F717AFEB4D0011E472 /* LDAppDelegate.m */,
0A11A98D17A6B50800E94748 /* LDDocument.h */,
0A11A98E17A6B50800E94748 /* LDDocument.m */,
0A8087D817ABF742007CA399 /* LDPreferencesViewController.h */,
0A8087D917ABF742007CA399 /* LDPreferencesViewController.m */,
0A11A99017A6B50800E94748 /* LDDocument.xib */,
0A11A99317A6B50800E94748 /* MainMenu.xib */,
0A4A5F3217A7A54800BE1CF9 /* Library */,
Expand Down Expand Up @@ -139,6 +152,8 @@
children = (
0A4A5F3317A7A54800BE1CF9 /* NSString+Count.h */,
0A4A5F3417A7A54800BE1CF9 /* NSString+Count.m */,
0AA098F917AFF6A20011E472 /* LDUtils.h */,
0AA098FA17AFF6A20011E472 /* LDUtils.m */,
);
path = Library;
sourceTree = "<group>";
Expand Down Expand Up @@ -252,6 +267,9 @@
0A11A98817A6B50800E94748 /* main.m in Sources */,
0A11A98F17A6B50800E94748 /* LDDocument.m in Sources */,
0A4A5F3517A7A54800BE1CF9 /* NSString+Count.m in Sources */,
0A8087DA17ABF742007CA399 /* LDPreferencesViewController.m in Sources */,
0AA098F817AFEB4D0011E472 /* LDAppDelegate.m in Sources */,
0AA098FB17AFF6A20011E472 /* LDUtils.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 18 additions & 0 deletions LiveDiag/LDAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// LDAppDelegate.h
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/08/05.
// Copyright (c) 2013年 dataich.com. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface LDAppDelegate : NSObject <NSApplicationDelegate>

@property (unsafe_unretained) IBOutlet NSWindow *windowPreferences;

- (IBAction)showPreferences:(id)sender;
- (void)showPreferences;

@end
36 changes: 36 additions & 0 deletions LiveDiag/LDAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// LDAppDelegate.m
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/08/05.
// Copyright (c) 2013年 dataich.com. All rights reserved.
//

#import "LDAppDelegate.h"
#import "LDUtils.h"

@implementation LDAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//check path settings, any commands
if([LDUtils pathTo:@"blockdiag"] == nil || [LDUtils pathTo:@"seqdiag"] == nil || [LDUtils pathTo:@"actdiag"] == nil || [LDUtils pathTo:@"nwdiag"] == nil || [LDUtils pathTo:@"rackdiag"] == nil) {
NSAlert *alert = [NSAlert alertWithMessageText:@"Path Setting" defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"Please specify a path to blockdiag and the other."];
if ([alert runModal] == NSAlertDefaultReturn) {
LDAppDelegate *delegate = (LDAppDelegate *)[[NSApplication sharedApplication] delegate];
[delegate showPreferences];
}
}
}

- (IBAction)showPreferences:(id)sender {
[self showPreferences];
}

- (void)showPreferences {
[NSApp runModalForWindow:self.windowPreferences];
[self.windowPreferences orderOut:self];
// [self.windowPreferences makeKeyAndOrderFront:self];
}

@end
2 changes: 2 additions & 0 deletions LiveDiag/LDDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#import "LDPreferencesViewController.h"

@interface LDDocument : NSDocument <NSTextViewDelegate>
@property (unsafe_unretained) IBOutlet NSTextView *textView;
@property (weak) IBOutlet WebView *webView;
@property (strong) LDPreferencesViewController *preferencesController;

@end
15 changes: 9 additions & 6 deletions LiveDiag/LDDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import "LDDocument.h"
#import "LDAppDelegate.h"
#import "LDUtils.h"
#import "NSString+Count.h"
#import <GHMarkdownParser/GHMarkdownParser.h>

Expand All @@ -29,7 +31,7 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
self.textView.font = [NSFont userFixedPitchFontOfSize:12];

NSURL *fileURL = [self fileURL];
if (!fileURL) {
return;
Expand Down Expand Up @@ -83,7 +85,7 @@ -(void)textViewContentToWebView
if([markDown countOfString:@"{"] == [markDown countOfString:@"}"]) {
//loop for parts of diag
NSError *error;
NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:@"^(blockdiag|seqdiag|actdiag|nwdiag|)(\\s|)\\{.*?^\\}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:@"^(blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
NSArray *matches;
while ([matches = [re matchesInString:markDown options:0 range:NSMakeRange(0, markDown.length)] count] > 0) {
NSTextCheckingResult *match = matches[0];
Expand All @@ -100,6 +102,7 @@ -(void)textViewContentToWebView
if(!command || [command isEqualToString:@""]) {
command = @"blockdiag";
}
command = [LDUtils pathTo:command];

//don't want to use image cache, so create filename by arc4random
NSString *outPath = [NSString stringWithFormat:@"%@%u.png", NSTemporaryDirectory(), arc4random()];
Expand All @@ -118,10 +121,10 @@ -(void)textViewContentToWebView
// after task terminated, add 'src' attribute to <img> from 'prapareSrc' attribute using jQuery
// to pinpoint a <img>, use process identifier
echo.terminationHandler = ^(NSTask *task) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *script = [NSString stringWithFormat:@"$('#%d').attr('src', $('#%d').attr('prepareSrc'));", pid, pid];
[weakSelf.webView stringByEvaluatingJavaScriptFromString:script];
});
dispatch_async(dispatch_get_main_queue(), ^{
NSString *script = [NSString stringWithFormat:@"$('#%d').attr('src', $('#%d').attr('prepareSrc'));", pid, pid];
[weakSelf.webView stringByEvaluatingJavaScriptFromString:script];
});
};
};
}
Expand Down
24 changes: 24 additions & 0 deletions LiveDiag/LDPreferencesViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// LDPreferencesViewController.h
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/08/02.
// Copyright (c) 2013 dataich.com. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface LDPreferencesViewController : NSViewController

@property (weak) IBOutlet NSTextField *textBlockdiag;
@property (weak) IBOutlet NSTextField *textSeqdiag;
@property (weak) IBOutlet NSTextField *textActdiag;
@property (weak) IBOutlet NSTextField *textNwdiag;
@property (weak) IBOutlet NSTextField *textRackdiag;
@property (weak) IBOutlet NSUserDefaultsController *defaultsController;
@property (unsafe_unretained) IBOutlet NSWindow *windowPreferences;

- (IBAction)browse:(NSButton *)sender;
- (IBAction)save:(id)sender;

@end
68 changes: 68 additions & 0 deletions LiveDiag/LDPreferencesViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// LDPreferencesViewController.m
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/08/02.
// Copyright (c) 2013 dataich.com. All rights reserved.
//

#import "LDPreferencesViewController.h"

@interface LDPreferencesViewController ()

@end

@implementation LDPreferencesViewController

/**
* save user preferences to NSUserDefaultsController
* I bind NSTextField to NSUserDefaultsController on xib, but it's saved only when the field loses focus...
* Provisionally I create 'save' action which sent from 'OK' button.
*/
- (IBAction)save:(id)sender {
[self setValueToDefauls:self.textBlockdiag.stringValue forKeyPath:@"values.path_blockdiag"];
[self setValueToDefauls:self.textSeqdiag.stringValue forKeyPath:@"values.path_seqdiag"];
[self setValueToDefauls:self.textActdiag.stringValue forKeyPath:@"values.path_actdiag"];
[self setValueToDefauls:self.textNwdiag.stringValue forKeyPath:@"values.path_nwdiag"];
[self setValueToDefauls:self.textRackdiag.stringValue forKeyPath:@"values.path_rackdiag"];

[NSApp stopModalWithCode:0];
}

- (void)setValueToDefauls:(NSString *)value forKeyPath:(NSString *)forKeyPath{
if(value == nil || [value isEqualToString:@""]) {
[self.defaultsController setValue:nil forKeyPath:forKeyPath];
} else {
[self.defaultsController setValue:value forKeyPath:forKeyPath];
}
}

- (IBAction)browse:(NSButton *)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result) {
if(result == NSFileHandlingPanelOKButton) {
NSString *path = [[panel URL] path];
switch (sender.tag) {
case 0:
self.textBlockdiag.stringValue = path;
break;
case 1:
self.textSeqdiag.stringValue = path;
break;
case 2:
self.textActdiag.stringValue = path;
break;
case 3:
self.textNwdiag.stringValue = path;
break;
case 4:
self.textRackdiag.stringValue = path;
break;
default:
break;
}
}
}];
}

@end
15 changes: 15 additions & 0 deletions LiveDiag/Library/LDUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// LDUtils.h
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/08/06.
// Copyright (c) 2013 dataich.com. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface LDUtils : NSObject

+ (NSString *)pathTo:(NSString *)command;

@end
18 changes: 18 additions & 0 deletions LiveDiag/Library/LDUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// LDUtils.m
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/08/06.
// Copyright (c) 2013 dataich.com. All rights reserved.
//

#import "LDUtils.h"

@implementation LDUtils

+ (NSString *)pathTo:(NSString *)command {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
return [userDefaults stringForKey:[NSString stringWithFormat:@"path_%@", command]];
}

@end
2 changes: 1 addition & 1 deletion LiveDiag/LiveDiag-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Loading

0 comments on commit 2cdee0d

Please sign in to comment.