forked from erkyrath/Inform7-IDE-Mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFNewProjectFile.m
111 lines (94 loc) · 2.55 KB
/
IFNewProjectFile.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
//
// IFNewProjectFile.m
// Inform
//
// Created by Andrew Hunter on Tue Jun 01 2004.
// Copyright (c) 2004 Andrew Hunter. All rights reserved.
//
#import "IFNewProjectFile.h"
#import "IFProject.h"
#import "IFCompilerSettings.h"
enum {
inform6FileTag = 0,
niFileTag = 1,
textFileTag = 2,
richTextFileTag = 3
};
@implementation IFNewProjectFile
- (id) initWithProjectController: (IFProjectController*) control {
self = [super initWithWindowNibName: @"NewFile"];
if (self) {
projectController = control;
newFilename = nil;
}
return self;
}
- (void) dealloc {
if (newFilename) [newFilename release];
[super dealloc];
}
// = Actions =
- (NSString*) getNewFilename {
if ([[[projectController document] settings] usingNaturalInform]) {
// Default is to create a 'ni' file
[fileType selectItem: [[fileType menu] itemWithTag: niFileTag]];
} else {
// Default is to create a '.h' file
// '.h' files are '.i6' files when natural inform is being used
[fileType selectItem: [[fileType menu] itemWithTag: inform6FileTag]];
}
// Set the new filename to nothing
if (newFilename) [newFilename release];
newFilename = nil;
// Run the sheet
[NSApp beginSheet: [self window]
modalForWindow: [projectController window]
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
[NSApp runModalForWindow: [self window]];
[NSApp endSheet: [self window]];
[[self window] orderOut: self];
return newFilename;
}
- (IBAction) cancel: (id) sender {
// Am assuming we're a sheet. Which we should always be
[NSApp stopModal];
}
- (IBAction) addFile: (id) sender {
// Am assuming we're a sheet. Which we should always be
[NSApp stopModal];
// Work out the extension to use
NSString* extension = nil;
switch ([[fileType selectedItem] tag]) {
case inform6FileTag:
if ([[[projectController document] settings] usingNaturalInform]) {
// With Natural Inform, the extension is '.i6'
extension = @"i6";
} else {
// With standard Inform 6, the extension is '.h'
extension = @"h";
}
break;
case niFileTag:
if ([[projectController document] editingExtension])
extension = nil;
else
extension = @"ni";
break;
case textFileTag:
extension = @"txt";
break;
case richTextFileTag:
extension = @"rtf";
break;
}
// ... now the whole filename
NSString* file = [[fileName stringValue] lastPathComponent];
if (extension && file && [file length] > 0) {
newFilename = [[file stringByAppendingPathExtension: extension] retain];
} else if (file && [file length] > 0) {
newFilename = [file copy];
}
}
@end