forked from scribendi/cindex-mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportOptionsController.m
240 lines (234 loc) · 9.6 KB
/
ExportOptionsController.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//
// ExportOptionsController.m
// Cindex
//
// Created by PL on 1/26/05.
// Copyright 2005 Indexing Research. All rights reserved.
//
#define MINTAG 10
#define MAXTAG 25
#import "ExportOptionsController.h"
#import "commandutils.h"
#import "sort.h"
#import "formattedexport.h"
@interface ExportOptionsController () {
NSDictionary * styleDic;
NSMutableArray * styleArray;
EXPORTPARAMS * _exportParams;
INDEX * FF;
BOOL useExplicitNames;
}
@end
@implementation ExportOptionsController
- (id)init {
self = [super initWithWindowNibName:@"ExportOptionsController"];
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
_exportParams = [[self document] exportParameters];
FF = [[self document] iIndex];
if (_exportParams->type == E_ARCHIVE || _exportParams->type == E_XMLRECORDS) {
[tab selectTabViewItemWithIdentifier:@"Archive"];
[archivenumberorder setState:_exportParams->sorted ? NO : YES];
}
else if (_exportParams->type == E_TAB) {
[tab selectTabViewItemWithIdentifier:@"PlainText"];
[plainencoding selectCellWithTag:_exportParams->encoding];
}
else if (_exportParams->type == E_DOS)
[tab selectTabViewItemWithIdentifier:@"Delimited"];
else if (_exportParams->type == E_XMLTAGGED || _exportParams->type == E_TAGGED)
[tab selectTabViewItemWithIdentifier:@"Tagged"];
else {
[tab selectTabViewItemWithIdentifier:@"Formatted"];
#if 1
if (_exportParams->type == E_TEXTNOBREAK) // plain text formatted export
paragraphStyles.hidden = YES;
else
paragraphStyles.action = @selector(doStyles:);
#endif
if (g_prefs.gen.indentdef == '\t')
[formattedindent selectCellWithTag:1];
else if (g_prefs.gen.indentdef != '\0'){
[formattedindent selectCellWithTag:2];
[formattedotherindent setStringValue:[NSString stringWithFormat:@"%c",g_prefs.gen.indentdef]];
}
}
// set up stylenames from saved config;
styleDic = [[NSUserDefaults standardUserDefaults] dictionaryForKey:[NSString stringWithFormat:@"exportStyles%d",_exportParams->type]];
styleArray = [styleDic objectForKey:kStyleStyleNames];
[mode selectCellWithTag:[[styleDic objectForKey:kStyleUseExplicitNames] boolValue]];
[self setStyleMode:nil];
centerwindow([NSApp keyWindow], [self window]);
}
- (void)doStyles:(id)sender {
centerwindow([NSApp keyWindow], stylePanel);
[NSApp runModalForWindow:stylePanel];
}
- (IBAction)setStyleMode:(id)sender {
if (useExplicitNames) // if currently set for explicit names
[self recoverStyleFields]; // recover current ones
useExplicitNames = mode.selectedCell.tag; // set new mode
if (useExplicitNames) {
[self loadStyleFields];
[self enableStyleFields:YES];
}
else {
[self enableStyleFields:NO];
for (int fcount = MINTAG; fcount < MAXTAG ; fcount++) {
if (fcount-MINTAG < FF->head.indexpars.maxfields-1) // if have a field name
((NSTextField *)[stylePanel.contentView viewWithTag:fcount]).stringValue = [NSString stringWithUTF8String:FF->head.indexpars.field[fcount-MINTAG].name];
else // no field name
((NSTextField *)[stylePanel.contentView viewWithTag:fcount]).stringValue = @"";
}
((NSTextField *)[stylePanel.contentView viewWithTag:MAXTAG]).stringValue = _exportParams->type == E_RTF ? @"ahead" : @"Ahead";
}
}
- (IBAction)showHelp:(id)sender {
NSInteger index = [tab indexOfTabViewItem:[tab selectedTabViewItem]];
NSString * anchor;
if (index == 0)
anchor = _exportParams->type == E_ARCHIVE ? @"exopt0_Anchor-11481" : @"exopt0a_Anchor-11481";
else if (index == 1) // plain text
anchor = @"exopt1_Anchor-11481";
else if (index == 2) // DOS text
anchor = @"exopt1_Anchor-11481";
else if (index == 3)
anchor = @"exopt2_Anchor-11481";
else
anchor = @"exopt3_Anchor-11481";
[[NSHelpManager sharedHelpManager] openHelpAnchor:anchor inBook:@"Cindex 4.2.5 Help"];
}
- (IBAction)closePanel:(id)sender {
// NSLog([[tab selectedTabViewItem] identifier]);
if ([sender tag] == OKTAG) {
if (![[self window] makeFirstResponder:[self window]])
return;
if ([sender window] == stylePanel) { // if closing set
if (useExplicitNames) // if want table contents
[self recoverStyleFields]; // recover current explicit settings
NSDictionary * sdic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:useExplicitNames], kStyleUseExplicitNames, styleArray, kStyleStyleNames,nil];
[[NSUserDefaults standardUserDefaults] setObject:sdic forKey:[NSString stringWithFormat:@"exportStyles%d",_exportParams->type]];
}
else {
NSTextField * trstart, *trend, *tpstart, *tpend;
int scope = 0, tsort, err;
char tdel;
if ([[[tab selectedTabViewItem] identifier] isEqualToString:@"Archive"]) {
_exportParams->sorted = [archivenumberorder state] ? NO : YES;
_exportParams->includedeleted = [archiveincludedeleted state];
trstart = archiverangefrom;
trend = archiverangeto;
scope = (int)[[archivescope selectedCell] tag];
}
else if ([[[tab selectedTabViewItem] identifier] isEqualToString:@"PlainText"]) {
_exportParams->sorted = [plainnumberorder state] ? NO : YES;
_exportParams->encoding = (int)[[plainencoding selectedCell] tag];
_exportParams->minfields = [plainminfields intValue];
trstart = plainrangefrom;
trend = plainrangeto;
scope = (int)[[plainscope selectedCell] tag];
}
else if ([[[tab selectedTabViewItem] identifier] isEqualToString:@"Delimited"]) {
_exportParams->sorted = [delimitednumberorder state] ? NO : YES;
_exportParams->appendflag = [delimitedappend state];
_exportParams->includedeleted = [delimitedincludedeleted state];
_exportParams->minfields = [delimitedminfields intValue];
trstart = delimitedrangefrom;
trend = delimitedrangeto;
scope = (int)[[delimitedscope selectedCell] tag];
}
else if ([[[tab selectedTabViewItem] identifier] isEqualToString:@"Formatted"]) {
int tabtype = (int)[formattedindent selectedColumn];
if (tabtype == 1)
_exportParams->usetabs = '\t';
else if (tabtype == 2)
_exportParams->usetabs = *[[formattedotherindent stringValue] UTF8String];
_exportParams->newlinetype = (int)[formattednewline selectedColumn];
trstart = formattedrangefrom;
trend = formattedrangeto;
tpstart = formattedpagerangefrom;
tpend = formattedpagerangeto;
scope = (int)[[formattedscope selectedCell] tag];
}
else if ([[[tab selectedTabViewItem] identifier] isEqualToString:@"Tagged"]) {
_exportParams->newlinetype = (int)[taggednewline selectedColumn];
trstart = taggedrangefrom;
trend = taggedrangeto;
tpstart = taggedpagerangefrom;
tpend = taggedpagerangeto;
scope = (int)[[taggedscope selectedCell] tag];
}
tsort = FF->head.sortpars.ison;
FF->head.sortpars.ison = _exportParams->sorted;
tdel = FF->head.privpars.hidedelete;
FF->head.privpars.hidedelete = !_exportParams->includedeleted;
// sort_setfilter(FF,_exportParams->includedeleted ? SF_OFF : SF_HIDEDELETEONLY);
err = com_getrecrange(FF,scope, trstart, trend,&_exportParams->first, &_exportParams->last);
FF->head.sortpars.ison = tsort;
FF->head.privpars.hidedelete = tdel;
// sort_setfilter(FF,SF_VIEWDEFAULT);
if (err) {
[[self window] makeFirstResponder: err < 0 ? trstart : trend];
return;
}
if (scope == COMR_PAGE) { // if page range
_exportParams->firstpage = [tpstart intValue];
_exportParams->lastpage = [tpend intValue];
}
}
}
[[sender window] close];
[NSApp stopModal];
}
- (void)controlTextDidChange:(NSNotification *)note {
NSControl * control = [note object];
if (control == archiverangefrom || control == archiverangefrom) // if record range
[archivescope selectCellWithTag:COMR_RANGE];
else if (control == plainrangefrom || control == plainrangeto) // if record range
[plainscope selectCellWithTag:COMR_RANGE];
else if (control == delimitedrangefrom || control == delimitedrangeto) // if record range
[delimitedscope selectCellWithTag:COMR_RANGE];
else if (control == formattedrangefrom || control == formattedrangeto) // if record range
[formattedscope selectCellWithTag:COMR_RANGE];
else if (control == taggedrangefrom || control == taggedrangeto) // if record range
[taggedscope selectCellWithTag:COMR_RANGE];
else if (control == formattedpagerangefrom || control == formattedpagerangeto) // if page range
[formattedscope selectCellWithTag:COMR_PAGE];
else if (control == taggedpagerangefrom || control == taggedpagerangeto) // if page range
[taggedscope selectCellWithTag:COMR_PAGE];
else if (control == formattedotherindent) {
// NSString * ustring = [control stringValue];
// if ([ustring length] > 1)
// [control setStringValue:[ustring substringToIndex:1]];
checktextfield(control,2);
}
}
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)editor {
if (control.tag >= MINTAG && control.tag <= MAXTAG) {
const char * style = [control.stringValue UTF8String];
return strlen(style) < FNAMELEN /* && !strchr(style,SPACE) */;
}
return YES;
}
- (void)enableStyleFields:(BOOL)state {
for (int tcount = MINTAG; tcount <= MAXTAG; tcount++)
((NSTextField *)[stylePanel.contentView viewWithTag:tcount]).enabled = state;
}
- (void)clearStyleFields {
for (int tcount = MINTAG; tcount <= MAXTAG; tcount++)
((NSTextField *)[stylePanel.contentView viewWithTag:tcount]).stringValue = @"";
}
- (void)recoverStyleFields {
styleArray = [NSMutableArray arrayWithCapacity:MAXTAG-MINTAG+1];
for (int tcount = MINTAG; tcount <= MAXTAG; tcount++)
[styleArray addObject:((NSTextField *)[stylePanel.contentView viewWithTag:tcount]).stringValue];
}
- (void)loadStyleFields {
if (styleArray && styleArray.count) {
for (int tcount = MINTAG; tcount <= MAXTAG; tcount++)
((NSTextField *)[stylePanel.contentView viewWithTag:tcount]).stringValue = [styleArray objectAtIndex:tcount-MINTAG];
}
}
@end