This repository has been archived by the owner on Jan 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeautifyTools.m
89 lines (73 loc) · 2.54 KB
/
BeautifyTools.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// BeautifyTools.m
// BeautifyTools
//
// Created by supudo on 6/17/11.
// Copyright (c) 2011 supudo.net, All Rights Reserved.
//
#import "BeautifyTools.h"
#import "CSSFormatter.h"
@implementation BeautifyTools
#pragma mark -
#pragma mark System specific
- (id) initWithPlugInController:(CodaPlugInsController *)inController bundle:(NSBundle *)yourBundle {
if ((self = [super init]) != nil) {
[NSBundle loadNibNamed:@"About" owner:self];
controller = inController;
[controller registerActionWithTitle:NSLocalizedString(@"CSS Format 1-line-elements", @"CSS Format 1-line-elements") target:self selector:@selector(cssFormat1Line:)];
[controller registerActionWithTitle:NSLocalizedString(@"CSS Format Multiline", @"CSS Format Multiline") target:self selector:@selector(cssFormatMultiline:)];
[controller registerActionWithTitle:NSLocalizedString(@"About", @"About") target:self selector:@selector(showAbout:)];
}
return self;
}
- (NSString *)name {
return @"Beautify Tools";
}
#pragma mark -
#pragma mark Menu actions
- (void)cssFormat1Line:(id)sender {
CodaTextView *tv = [controller focusedTextView:self];
if (tv) {
NSString *cssData = [tv string];
if (![cssData isEqualToString:@""]) {
NSRange wholeRange = NSMakeRange(0, [cssData length]);
CSSFormatter *formatter = [[CSSFormatter alloc] init];
NSString *formatedCSS = [formatter formatCSS1line:cssData];
[formatter release];
[tv replaceCharactersInRange:wholeRange withString:formatedCSS];
}
}
}
- (void)cssFormatMultiline:(id)sender {
CodaTextView *tv = [controller focusedTextView:self];
if (tv) {
NSString *cssData = [tv string];
if (![cssData isEqualToString:@""]) {
NSRange wholeRange = NSMakeRange(0, [cssData length]);
CSSFormatter *formatter = [[CSSFormatter alloc] init];
NSString *formatedCSS = [formatter formatCSSMultiline:cssData];
[formatter release];
[tv replaceCharactersInRange:wholeRange withString:formatedCSS];
}
}
}
#pragma mark -
#pragma mark Dialogs
- (void)showAbout:(id)sender {
CodaTextView *textView = [controller focusedTextView:self];
NSWindow *window = [textView window];
[dialogAbout makeFirstResponder:btnClose];
if (window && ![window attachedSheet])
[NSApp beginSheet:dialogAbout modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
else
NSBeep();
}
#pragma mark -
#pragma mark Actions
- (IBAction)openURL:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://github.com/supudo/CodaBeautifyTools"]];
}
- (IBAction)closeAbout:(id)sender {
[dialogAbout close];
}
@end