@@ -24,16 +24,14 @@ @interface ViewController()<NSTextViewDelegate>
24
24
@property (weak ) IBOutlet NSTextField *firstModuleTxf;
25
25
@property (weak ) IBOutlet NSTextField *firstReplacedTxf;
26
26
27
-
28
27
@property (unsafe_unretained) IBOutlet NSTextView *secondModulePathTxv;
29
28
@property (weak ) IBOutlet NSTextField *secondModuleTxf;
30
29
@property (weak ) IBOutlet NSTextField *secondReplacedTxf;
31
30
32
31
33
-
34
-
35
32
@property (nonatomic ,copy ) NSString *firstFolderPathString;
36
33
@property (nonatomic ,copy ) NSString *secondFolderPathString;
34
+
37
35
@property (nonatomic ,copy ) NSString *moduleClassPrefix;
38
36
@property (nonatomic ,copy ) NSString *targetClassPrefix;
39
37
@@ -45,11 +43,9 @@ @implementation ViewController
45
43
- (void )viewDidLoad {
46
44
[super viewDidLoad ];
47
45
[self initData ];
48
-
49
46
50
47
}
51
48
52
-
53
49
- (void )initData
54
50
{
55
51
self.firstFolderPathString = [UserDefaults objectForKey: firstFolderPath];
@@ -87,7 +83,7 @@ - (IBAction)firstOpenBtnAction:(NSButton *)sender {
87
83
}
88
84
- (IBAction )firstCreateBtnAction : (id )sender {
89
85
90
-
86
+ self. firstFolderPathString = self. firstModulePathTxv . string ;
91
87
if (!self.firstModulePathTxv .string ||[self .firstModulePathTxv.string isEqualToString: @" " ]) {
92
88
93
89
[self showAlertWithMessage: @" Please select first module filePath " ];
@@ -119,6 +115,10 @@ - (IBAction)secondOpenBtnAction:(NSButton *)sender {
119
115
}
120
116
121
117
- (IBAction )secondCreateOpenBtnAction : (id )sender {
118
+
119
+
120
+ self.secondFolderPathString = self.secondModulePathTxv .string ;
121
+
122
122
if (!self.secondModulePathTxv .string ||[self .secondModulePathTxv.string isEqualToString: @" " ]) {
123
123
124
124
[self showAlertWithMessage: @" Please select second module filePath " ];
@@ -183,27 +183,56 @@ - (void)creatFolderAndFileAtModuleFilePath:(NSString *)filePath
183
183
continue ;
184
184
}
185
185
// 文件夹路径;如果是文件夹的话,就创建文件夹
186
- if (![subPath containsString: @" / " ] ) {
186
+ if (!( [subPath containsString: @" .h " ]||[subPath containsString: @" .m " ]) ) {
187
187
188
188
[[FileManager sharedInstance ] createFolderAtPath: newWholePath];
189
189
continue ;
190
190
}
191
191
NSString *str = [[FileManager sharedInstance ] getStringWithContentsOfFilePath: wholePath];
192
192
NSString *replacedStr = [str stringByReplacingOccurrencesOfString: self .moduleClassPrefix withString: self .targetClassPrefix];
193
- [[FileManager sharedInstance ] createFileAtPath: newWholePath content: replacedStr];
193
+ NSString *stringAfterReplaceDate = [self replaceModuleDateWithNowDate: [self getNowDateStr ] nowYear: [self getNowYearStr ] moduleStr: replacedStr];
194
+ [[FileManager sharedInstance ] createFileAtPath: newWholePath content: stringAfterReplaceDate];
194
195
}
195
196
[[NSWorkspace sharedWorkspace ] openFile: filePath];
197
+ }
198
+
196
199
200
+
201
+ #pragma mark - ReplaceDate
202
+ - (NSString *)replaceModuleDateWithNowDate : (NSString *)nowDate nowYear : (NSString *)nowYear moduleStr : (NSString *)moduleStr {
203
+
204
+ NSMutableString *searchText = [NSMutableString stringWithFormat: @" %@ " ,moduleStr];
205
+ NSError *error = NULL ;
206
+ // 匹配17/06/25
207
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: @" [0-9]{1,2}/[0-9]{1,2}/[0-9]{1,2}" options: NSRegularExpressionCaseInsensitive error: &error];
208
+ // 匹配2017年;
209
+ NSRegularExpression *regexT = [NSRegularExpression regularExpressionWithPattern: @" [0-9]{1}[0-9]{1}[0-9]{1}[0-9]{1}[\u4e00 -\u9fa5 ]" options: NSRegularExpressionCaseInsensitive error: &error];
210
+ [regex replaceMatchesInString: searchText options: 0 range: NSMakeRange (0 , searchText.length) withTemplate: nowDate];
211
+ [regexT replaceMatchesInString: searchText options: 0 range: NSMakeRange (0 , searchText.length) withTemplate: nowYear];
212
+ return searchText;
213
+ }
214
+
215
+ - (NSString *)getNowDateStr {
216
+ NSDateFormatter *formatter = [[NSDateFormatter alloc ] init ];
217
+ formatter.dateFormat = @" yy/MM/dd" ;
218
+ return [formatter stringFromDate: [NSDate date ]];
197
219
}
198
220
221
+ - (NSString *)getNowYearStr {
222
+ NSDateFormatter *formatter = [[NSDateFormatter alloc ] init ];
223
+ formatter.dateFormat = @" yyyy" ;
224
+
225
+ NSString *nowYear = [NSString stringWithFormat: @" %@ 年" ,[formatter stringFromDate: [NSDate date ]]];
226
+
227
+ return nowYear;
228
+ }
229
+
230
+
199
231
- (void )showAlertWithMessage : (NSString *)message {
200
232
201
233
NSAlert *alert = [[NSAlert alloc ] init ];
202
234
[alert setMessageText: message];
203
235
[alert runModal ];
204
236
}
205
237
206
- #pragma mark - Getter && Setter
207
-
208
-
209
238
@end
0 commit comments