forked from leehosung/LemonEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LMProjectConvertWC.m
114 lines (92 loc) · 3.69 KB
/
LMProjectConvertWC.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// LMProjectConvertWC.m
// IUEditor
//
// Created by jd on 5/28/14.
// Copyright (c) 2014 JDLab. All rights reserved.
//
#import "LMProjectConvertWC.h"
#import "IUDjangoProject.h"
#import "IUProjectController.h"
@interface LMProjectConvertWC ()
@property (weak) IBOutlet NSView *htmlTabV;
@property (weak) IBOutlet NSView *djangoTabV;
@property (weak) IBOutlet NSView *htmlConvertV;
@property (weak) IBOutlet NSView *htmlRemainV;
@property (weak) IBOutlet NSView *djangoConvertV;
@property (weak) IBOutlet NSView *djangoRemainV;
@property (nonatomic) NSString *targetProjectDirectory;
@property NSString *buildProjectDirectory;
@property NSString *resourceProjectDirectory;
@property (weak) IBOutlet NSTabView *tabView;
@end
@implementation LMProjectConvertWC{
NSString *outputFilePath;
IUProject *_project;
}
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
// Initialization code here.
}
return self;
}
- (void)awakeFromNib{
//cover to django
[_tabView selectTabViewItemAtIndex:1];
}
- (void)setCurrentProject:(IUProject *)currentProject{
_project = currentProject;
//load nib
[self window];
// [self setTargetProjectDirectory:@"/Users/jd/Desktop"];
if ([[currentProject className] isEqualToString:@"IUProject"]) {
[_djangoTabV addSubview:_djangoConvertV];
[_htmlTabV addSubview:_htmlRemainV];
}
else {
[_htmlTabV addSubview:_htmlConvertV];
[_djangoTabV addSubview:_djangoRemainV];
}
}
- (IBAction)convertDjango:(id)sender{
if (_targetProjectDirectory == nil || _buildProjectDirectory == nil || _resourceProjectDirectory == nil) {
[JDLogUtil alert:@"Please fill all fields"];
return;
}
NSString *projectPath = [_targetProjectDirectory stringByAppendingFormat:@"/%@.iu", [_targetProjectDirectory lastPathComponent]];
// if file exist in project path, alert and return
if ([[NSFileManager defaultManager] fileExistsAtPath:projectPath]) {
[JDLogUtil alert:[NSString stringWithFormat:@"File exist in %@", projectPath] title:@"Sorry, File exist in path"];
return;
}
NSDictionary *options = @{ IUProjectKeyGit: @(NO),
IUProjectKeyHeroku: @(NO),
IUProjectKeyAppName : [_targetProjectDirectory lastPathComponent],
IUProjectKeyIUFilePath : projectPath,
IUProjectKeyType:@(IUProjectTypeDjango),
IUProjectKeyResourcePath : _resourceProjectDirectory,
IUProjectKeyBuildPath : _buildProjectDirectory,
IUProjectKeyConversion :
_project
};
[(IUProjectController *)[NSDocumentController sharedDocumentController] newDocument:self withOption:options];
[self.window.sheetParent endSheet:self.window returnCode:NSModalResponseOK];
}
- (IBAction)pressSelectProjectDirectory:(id)sender {
NSURL *url = [[JDFileUtil util] openDirectoryByNSOpenPanel];
self.targetProjectDirectory = [url path];
}
- (void)setTargetProjectDirectory:(NSString *)targetProjectDirectory{
_targetProjectDirectory = targetProjectDirectory;
self.buildProjectDirectory = [_targetProjectDirectory stringByAppendingPathComponent:@"templates"];
self.resourceProjectDirectory = [_targetProjectDirectory stringByAppendingPathComponent:@"templates/resource"];
}
- (IBAction)pressCancelB:(id)sender {
[self.window.sheetParent endSheet:self.window returnCode:NSModalResponseAbort];
}
- (NSString *)outputFilePath{
return outputFilePath;
}
@end