-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickSnippetsWindowController.m
57 lines (44 loc) · 1.68 KB
/
QuickSnippetsWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// QuickSnippetsWindowController.m
//
// Created by Taichiro Yoshida on 09/11/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "QuickSnippetsWindowController.h"
#import <Vermilion/Vermilion.h>
@implementation QuickSnippetsWindowController
- (void)awakeFromNib {
[NSApp activateIgnoringOtherApps:YES];
NSWindow *theKeyWindow = [NSApp keyWindow];
NSInteger keyLevel = [theKeyWindow level];
[[self window] setLevel:keyLevel + 1];
[[self window] makeKeyAndOrderFront:self];
[[self window] center];
}
- (IBAction)regist:(id)sender {
@try {
id<HGSDelegate> delegate = [[HGSPluginLoader sharedPluginLoader] delegate];
NSString *path = [[delegate userApplicationSupportFolderForApp]
stringByAppendingPathComponent:kQuickSnippetsPlist];
NSString *key = [_keyTextView stringValue];
NSString *value = [_valueTextView stringValue];
unichar LSC = NSLineSeparatorCharacter;
NSString *lineSepearator = [NSString stringWithCharacters:&LSC length: 1];
value = [value stringByReplacingOccurrencesOfString:lineSepearator withString:@"\n"];
NSMutableArray *snippets = [NSMutableArray arrayWithContentsOfFile:path];
if([snippets count] == 0) {
snippets = [NSMutableArray array];
}
NSArray *snippet = [NSArray arrayWithObjects:key, value, nil];
[snippets addObject:snippet];
[snippets writeToFile:path atomically:YES];
[_label setStringValue:@"Registration is completed."];
}
@catch (NSException * e) {
HGSLog(@"%@", [e description]);
}
[_keyTextView setStringValue:@""];
[_valueTextView setStringValue:@""];
[[self window] makeFirstResponder:_keyTextView];
}
@end