forked from scribendi/cindex-mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupsController.m
140 lines (130 loc) · 5.06 KB
/
GroupsController.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
//
// GroupsController.m
// Cindex
//
// Created by PL on 1/9/05.
// Copyright 2005 Indexing Research. All rights reserved.
//
#import "GroupsController.h"
#import "commandutils.h"
#import "IRIndexDocument.h"
#import "group.h"
#import "cindexmenuitems.h"
enum { /* action types */
G_REVISE,
G_DELETE,
G_LINK
};
static char *fname[] = {"All","All Text","Last Text"};
//char * makestylestring(unsigned char style, unsigned char font);
@implementation GroupsController
- (void)awakeFromNib {
[super awakeFromNib];
FF = [[self document] iIndex];
[group setMenu:[[self document] groupMenu:YES]];
if (FF->viewtype == VIEW_GROUP) // if there's active group
[group selectItemWithTitle:[NSString stringWithCString:FF->curfile->gname encoding:NSUTF8StringEncoding]]; // select it
if (FF->head.sortpars.fieldorder[0] == PAGEINDEX) // if page sort
[[action cellWithTag:2] setEnabled:NO]; // no linking
}
- (IBAction)showHelp:(id)sender {
[[NSHelpManager sharedHelpManager] openHelpAnchor:@"group2_Anchor-14210" inBook:@"Cindex 4.2.5 Help"];
}
- (IBAction)showInformation:(id)sender {
NSString * gname = [group titleOfSelectedItem];
GROUPHANDLE gh = grp_open(FF, (char *)[gname UTF8String]);
if (gh) { // if can open group
GROUP * gp = gh;
char tstring[256], *tptr;
[[ginfo cellWithTag:0] setStringValue:gname]; // name
[[ginfo cellWithTag:1] setIntValue:gp->rectot]; // records
#if 0
strftime(tstring, 100, "%b %d %Y %H:%M", localtime(&gp->tstamp));
[[ginfo cellWithTag:2] setStringValue:[NSString stringWithUTF8String:tstring]]; // time stamp
#else
[[ginfo cellWithTag:2] setStringValue:[NSString stringFromCinTime:gp->tstamp]];
#endif
if (gp->gflags&GF_SEARCH) { // if built from search
NSString * rstring = @"";
if (strlen(gp->lg.range0) || strlen(gp->lg.range1)) // if had range
rstring = [NSString stringWithFormat:@" in range [%s] [%s]",gp->lg.range0,gp->lg.range1];
[contextbox setHidden: NO];
[[ginfo cellWithTag:3] setStringValue:[NSString stringWithFormat:@"Search%@",rstring]]; // method
[notstring setStringValue:gp->lg.lsarray[0].notflag ? @"Not" : @""];
[searchstring setStringValue:[NSString stringWithUTF8String:gp->lg.lsarray[0].string]];
if (gp->lg.size > 1) // if have more than one search criterion
[andstring setStringValue:gp->lg.lsarray[0].andflag ? @"and…" : @"or…"];
else
[andstring setStringValue:@""];
LIST * lp = &gp->lg.lsarray[0];
[attribstring setStringValue:attribdescriptor(lp->style,lp->font,lp->forbiddenstyle,lp->forbiddenfont)];
if (gp->lg.lsarray[0].field < 0)
tptr = fname[gp->lg.lsarray[0].field+(-ALLFIELDS)];
else {
if (gp->lg.lsarray[0].field == PAGEINDEX)
tptr = FF->head.indexpars.field[PAGEINDEX].name;
else
tptr = FF->head.indexpars.field[gp->lg.lsarray[0].field].name;
}
[fieldstring setStringValue:[NSString stringWithUTF8String:tptr]];
[[gcontext cellWithTag:0] setState:gp->lg.lsarray[0].evalrefflag];
[[gcontext cellWithTag:1] setState:gp->lg.lsarray[0].wordflag];
[[gcontext cellWithTag:2] setState:gp->lg.lsarray[0].caseflag];
[[gcontext cellWithTag:3] setState:gp->lg.lsarray[0].patflag];
}
else {
[contextbox setHidden: YES];
[[ginfo cellWithTag:3] setStringValue:@"From selection"]; // method
}
*tstring = '\0';
if (gp->gflags&GF_REVISED)
strcpy(tstring, "Revised ");
if (gp->gflags&GF_COMBINE)
strcat(tstring, "Combined ");
if (gp->gflags&GF_LINKED)
strcat(tstring,"Linked");
[[ginfo cellWithTag:4] setStringValue:[NSString stringWithUTF8String:tstring]]; // name
grp_dispose(gh);
centerwindow([self window],infopanel);
[NSApp runModalForWindow:infopanel];
}
}
- (IBAction)closePanel:(id)sender {
[infopanel close];
[NSApp stopModal];
}
- (IBAction)closeSheet:(id)sender {
if ([sender tag] == OKTAG) {
int firstgroup, lastgroup;
if ([[groupmode selectedCell] tag]) { // if doing selected group
firstgroup = [group indexOfSelectedItem];
lastgroup = firstgroup+1;
}
else { // all groups
firstgroup = 0;
lastgroup = [group numberOfItems];
}
while (firstgroup < lastgroup) { // for all groups we want
char * gname = (char *)[[group itemTitleAtIndex:firstgroup] UTF8String];
GROUPHANDLE gh = grp_open(FF, gname);
if (gh) { // if can open group
int gaction = [[action selectedCell] tag];
if (gaction == G_REVISE) /* revise */
grp_revise(FF,&gh); /* if ok */
else if (gaction == G_DELETE) /* delete */
grp_delete(FF,gname);
else if (!grp_link(FF,&gh)) /* if can link */
grp_make(FF,gh,gname,TRUE);
grp_dispose(gh); /* dispose of it after finishing */
// things to do if action was on current group
if (FF->viewtype == VIEW_GROUP && !strcmp(FF->curfile->gname,gname)) // if viewing this group
[[self document] setViewType:VIEW_GROUP name:[group itemTitleAtIndex:firstgroup]]; // redisplay (or view_all if group gone)
}
firstgroup++;
}
[[self document] setGroupMenu:[[self document] groupMenu:NO]]; // rebuild menu
[[self document] installGroupMenu]; // install it
}
[self.window.sheetParent endSheet:self.window returnCode:[sender tag]];
}
@end