Skip to content

Commit f2350ac

Browse files
committed
Release of CINDEX as open source
This commit marks the transition of CINDEX from proprietary to open source.
1 parent 7c5071b commit f2350ac

File tree

2,073 files changed

+309310
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,073 files changed

+309310
-2
lines changed

.DS_Store

30 KB
Binary file not shown.

AAP Tagged Text.cstg

320 Bytes
Binary file not shown.

AbbreviationController.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// AbbreviationController.h
3+
// Cindex
4+
//
5+
// Created by PL on 3/26/05.
6+
// Copyright 2005 Indexing Research. All rights reserved.
7+
//
8+
9+
@interface AbbreviationController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate,NSControlTextEditingDelegate>{
10+
IBOutlet NSTableView * table;
11+
IBOutlet NSButton * enter;
12+
IBOutlet NSSegmentedControl * segs;
13+
}
14+
15+
- (IBAction)newAbbreviations:(id)sender;
16+
- (IBAction)openAbbreviations:(id)sender;
17+
- (IBAction)closeAbbreviations:(id)sender;
18+
- (IBAction)manageAbbreviation:(id)sender;
19+
20+
+ (void)showWithExpansion:(NSAttributedString *)text;
21+
@end

AbbreviationController.m

+327
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
//
2+
// AbbreviationController.m
3+
// Cindex
4+
//
5+
// Created by PL on 3/26/05.
6+
// Copyright 2005 Indexing Research. All rights reserved.
7+
//
8+
9+
#import "IRIndexDocumentController.h"
10+
#import "IRIndexDocument.h"
11+
#import "AbbreviationController.h"
12+
#import "cindexmenuitems.h"
13+
#import "AttributedStringCategories.h"
14+
#import "IRTableHeaderView.h"
15+
#import "strings_c.h"
16+
#import "commandutils.h"
17+
18+
NSString * IRWindowAbbreviation = @"AbbreviationWindow";
19+
20+
enum {
21+
TAG_ABBREV = 0,
22+
TAG_EXPANSION
23+
};
24+
25+
@interface AbbreviationController () {
26+
NSMutableDictionary * _dictionary; // working copy
27+
}
28+
@property(retain)id activeText;
29+
@property(retain)NSString * dicpath;
30+
@property(retain)NSMutableArray * sortedArray;
31+
32+
- (BOOL)_saveAbbreviations;
33+
- (void)_setDictionary:(NSMutableDictionary *)dic forPath:(NSString *)path;
34+
- (void)_setNewFile;
35+
- (void)_startNewAbbreviation:(id)stringObject;
36+
@end
37+
38+
@implementation AbbreviationController
39+
40+
+ (void)showWithExpansion:(NSAttributedString *)text {
41+
AbbreviationController * abc = [[AbbreviationController alloc] initWithWindowNibName:@"AbbreviationController"];
42+
abc.activeText = text;
43+
[NSApp runModalForWindow:[abc window]];
44+
}
45+
- (id)init {
46+
self = [super initWithWindowNibName:@"AbbreviationController"];
47+
return self;
48+
}
49+
-(void)dealloc {
50+
self.sortedArray = nil;
51+
self.dicpath = nil;
52+
}
53+
- (void)awakeFromNib {
54+
[super awakeFromNib];
55+
NSTextFieldCell * tcell = [[table tableColumnWithIdentifier:@"_expansion"] dataCell];
56+
57+
[tcell setAllowsEditingTextAttributes:YES];
58+
[self setShouldCascadeWindows:NO];
59+
[[self window] setExcludedFromWindowsMenu:YES];
60+
[[self window] setFrameAutosaveName:IRWindowAbbreviation];
61+
[[self window] makeKeyAndOrderFront:nil]; // needed to ensure that autosaved position is used
62+
[self _setDictionary:[NSMutableDictionary dictionaryWithDictionary:[IRdc abbreviations]] forPath:[[NSUserDefaults standardUserDefaults] objectForKey:CIAbbreviations]];
63+
if (_activeText) // if opened from an expansion entry
64+
[self manageAbbreviation:_activeText]; // set attributed string
65+
}
66+
- (IBAction)showHelp:(id)sender {
67+
[[NSHelpManager sharedHelpManager] openHelpAnchor:@"abbrev0_Anchor-14210" inBook:@"Cindex 4.2.5 Help"];
68+
}
69+
- (void)windowDidUpdate:(NSNotification *)aNotification {
70+
[segs setEnabled:_dictionary ? YES : NO forSegment:0];
71+
[segs setEnabled:[table selectedRow] >= 0 forSegment:1];
72+
}
73+
- (IBAction)printDocument:(id)sender {
74+
NSPrintOperation *printop = [NSPrintOperation printOperationWithView:table];
75+
NSPrintInfo * pinfo = [printop printInfo];
76+
[pinfo setVerticallyCentered:NO];
77+
78+
[printop runOperation];
79+
}
80+
- (BOOL)validateMenuItem:(NSMenuItem *)mitem {
81+
NSInteger itemid = [mitem tag];
82+
83+
// NSLog([mitem title]);
84+
if (itemid == MI_DELETE)
85+
return [table selectedRow] >= 0;
86+
return YES;
87+
}
88+
- (void)newAbbreviation:(id)sender {
89+
[self _startNewAbbreviation:@""];
90+
}
91+
- (IBAction)delete:(id)sender {
92+
NSIndexSet * iset = [table selectedRowIndexes];
93+
NSInteger index = [iset firstIndex];
94+
95+
[[self window] makeFirstResponder:table]; // force close of editor
96+
while (index != NSNotFound) {
97+
[_dictionary removeObjectForKey:[_sortedArray objectAtIndex:index]];
98+
index = [iset indexGreaterThanIndex:index];
99+
}
100+
[self sortAndReload];
101+
}
102+
- (IBAction)newAbbreviations:(id)sender {
103+
[self closeAbbreviations:nil];
104+
[self _setNewFile];
105+
}
106+
- (IBAction)closeAbbreviations:(id)sender {
107+
if ([[self window] makeFirstResponder:table]) { // if good close
108+
[self _saveAbbreviations];
109+
[self _setDictionary:[NSMutableDictionary dictionaryWithCapacity:1] forPath:nil];
110+
}
111+
}
112+
- (IBAction)closePanel:(id)sender {
113+
if ([sender tag] == OKTAG) {
114+
if (![[self window] makeFirstResponder:table] || ![self _saveAbbreviations]) // if have dirty abbreviation
115+
return;
116+
}
117+
[self close];
118+
[NSApp stopModal];
119+
}
120+
- (IBAction)openAbbreviations:(id)sender {
121+
NSArray *fileTypes = [NSArray arrayWithObjects:CINAbbrevExtension/*, NSFileTypeForHFSTypeCode(CINAbbrevType) */,nil]; // !! might add old abbrev type
122+
NSOpenPanel *openpanel = [NSOpenPanel openPanel];
123+
NSString * defaultDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:CIIndexFolder];
124+
125+
if (defaultDirectory)
126+
[openpanel setDirectoryURL:[NSURL fileURLWithPath:defaultDirectory isDirectory:YES]];
127+
[openpanel setAllowedFileTypes:fileTypes];
128+
[openpanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) {
129+
if (result == NSFileHandlingPanelOKButton) {
130+
NSMutableDictionary * newset = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfURL:[openpanel URL]]];
131+
132+
[self _setDictionary:newset forPath:[[openpanel URL] path]];
133+
}
134+
[[NSUserDefaults standardUserDefaults] setObject:[[openpanel directoryURL] path] forKey:CIBackupFolder];
135+
}];
136+
}
137+
- (IBAction)manageAbbreviation:(id)sender {
138+
if ([sender isKindOfClass:[NSAttributedString class]] || [sender selectedSegment] == 0) { // adding
139+
id stringobject;
140+
141+
if ([sender isKindOfClass:[NSAttributedString class]]) // if opened from expansion text
142+
stringobject = [sender normalizeAttributesWithMap:NULL]; // set attributed string
143+
else {
144+
if ([[self window] makeFirstResponder:table]) // forces completion of any item currently being edited
145+
stringobject = @"";
146+
}
147+
[self _startNewAbbreviation:stringobject];
148+
}
149+
else if ([sender selectedSegment] == 1) // deleting
150+
[self delete:nil];
151+
}
152+
- (void)_startNewAbbreviation:(id)stringObject {
153+
[table setSortDescriptors:[NSArray arrayWithObject:[[table tableColumnWithIdentifier:@"_abbreviation"] sortDescriptorPrototype]]];
154+
[_dictionary setObject:stringObject forKey:@""];
155+
[self sortAndReload];
156+
[table editColumn:0 row:0 withEvent:nil select:YES];
157+
((IRTableHeaderView *)[table headerView]).enabled = NO;
158+
}
159+
- (void)_setNewFile {
160+
NSSavePanel *savepanel = [NSSavePanel savePanel];
161+
162+
[savepanel setCanSelectHiddenExtension:YES];
163+
[savepanel setAllowedFileTypes:[NSArray arrayWithObject:CINAbbrevExtension]];
164+
[savepanel setNameFieldLabel:@"Create As:"];
165+
[savepanel setPrompt:@"Create"];
166+
[savepanel setMessage:@"Create a new set of abbreviations"];
167+
[savepanel setNameFieldStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:CIAbbreviations] ? @"New Abbreviations" : @"Default Abbreviations"];
168+
[savepanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) {
169+
if (result == NSFileHandlingPanelOKButton) {
170+
NSDictionary * dic = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:[savepanel isExtensionHidden]] forKey:NSFileExtensionHidden];
171+
172+
self.dicpath = [[savepanel URL] path];
173+
[self _saveAbbreviations];
174+
[[NSFileManager defaultManager] setAttributes:dic ofItemAtPath:self->_dicpath error:nil];
175+
[[self window] setTitleWithRepresentedFilename:self->_dicpath];
176+
}
177+
[[NSUserDefaults standardUserDefaults] setObject:[[savepanel directoryURL] path] forKey:CIIndexFolder];
178+
}];
179+
}
180+
- (BOOL)_saveAbbreviations {
181+
for (id key in [_dictionary allKeys]) { // for all keys
182+
if (![key length] || ![[_dictionary objectForKey:key] length]) // if empty key or expansion
183+
[_dictionary removeObjectForKey:key];
184+
}
185+
if ([_dictionary count] && !_dicpath) // if have defined some abbrev and have no save path
186+
[self _setNewFile]; // abort this save to get file name
187+
else {
188+
BOOL result = TRUE;
189+
if (_dicpath) {
190+
NSData * ddata = [NSKeyedArchiver archivedDataWithRootObject:_dictionary];
191+
result = [ddata writeToFile:_dicpath atomically:NO];
192+
}
193+
if (result) { // if ok
194+
[[NSUserDefaults standardUserDefaults] setObject:_dicpath forKey:CIAbbreviations]; // ensure it's current set
195+
[IRdc setAbbreviations:_dictionary];
196+
return YES;
197+
}
198+
}
199+
return NO;
200+
}
201+
- (void)_setDictionary:(NSMutableDictionary *)dic forPath:(NSString *)path{
202+
_dictionary = dic;
203+
self.dicpath = path;
204+
if (path)
205+
[[self window] setTitleWithRepresentedFilename:path];
206+
else
207+
[[self window] setTitle:@"Abbreviations"];
208+
[table setSortDescriptors:[NSArray arrayWithObject:[[table tableColumnWithIdentifier:@"_abbreviation"] sortDescriptorPrototype]]];
209+
}
210+
- (void)sortAndReload {
211+
NSSortDescriptor * sd = [[table sortDescriptors] objectAtIndex:0];
212+
NSArray *sortedarray;
213+
214+
if ([[sd key] isEqualToString:@"_abbreviation"]) // sort by abbrev
215+
sortedarray = [[_dictionary allKeys] sortedArrayUsingSelector:[sd selector]];
216+
else
217+
sortedarray = [_dictionary keysSortedByValueUsingSelector:[sd selector]];
218+
if (![sd ascending]) // if wanted inverse order
219+
sortedarray = [sortedarray sortedArrayDescending];
220+
self.sortedArray = [NSMutableArray arrayWithArray: sortedarray];
221+
[table reloadData];
222+
}
223+
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor {
224+
if (control == table)
225+
self.activeText = control.objectValue;
226+
return YES;
227+
}
228+
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command {
229+
((IRTableHeaderView *)[table headerView]).enabled = NO;
230+
if (command == @selector(cancelOperation:) || command == @selector(insertNewline:)) {
231+
if (command == @selector(cancelOperation:) && _activeText)
232+
control.objectValue = _activeText;
233+
[[self window] makeFirstResponder:table]; // force close of editor
234+
return YES;
235+
}
236+
if (![[control stringValue] length]) // if leaving empty field
237+
return YES;
238+
if (control == table && (command == @selector(insertTab:) || command == @selector(insertBacktab:))) {
239+
NSInteger editedColumn = [table editedColumn];
240+
NSInteger editedRow = [table editedRow];
241+
if (command == @selector(insertBacktab:)) {
242+
if (editedColumn == TAG_ABBREV) {
243+
editedColumn = TAG_EXPANSION;
244+
// editedRow--;
245+
}
246+
else {
247+
editedColumn--;
248+
}
249+
}
250+
else if (command == @selector(insertTab:)) {
251+
if (editedColumn == TAG_EXPANSION) {
252+
editedColumn = TAG_ABBREV;
253+
// editedRow++;
254+
}
255+
else {
256+
editedColumn++;
257+
}
258+
}
259+
if (editedRow >= table.numberOfRows)
260+
editedRow = 0;
261+
else if (editedRow < 0)
262+
editedRow = table.numberOfRows-1;
263+
if (editedColumn >= table.numberOfColumns)
264+
editedColumn = 0;
265+
[table editColumn:editedColumn row:editedRow withEvent:nil select:YES];
266+
((IRTableHeaderView *)[table headerView]).enabled = NO;
267+
return YES;
268+
}
269+
return NO;
270+
}
271+
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)editor {
272+
if (control == table) {
273+
NSString * abbText = [control stringValue];
274+
NSInteger length = [abbText length];
275+
if (!length || length >= MAXREC)
276+
return NO;
277+
if ([control selectedTag] == TAG_ABBREV) { // check permissible chars in abbrev cell
278+
unichar buff[MAXREC];
279+
[abbText getCharacters:buff];
280+
*(buff+length) = 0;
281+
if (u_strpbrk(buff,abbrev_prefix) || u_strpbrk(buff,abbrev_suffix)) // if ab contains forbidden char
282+
return NO;
283+
if (![abbText isEqualToString:_activeText] && [_dictionary objectForKey:abbText]) // if name not same as current && abbreviation already exists
284+
return NO;
285+
}
286+
}
287+
return YES; // don't check expansion text
288+
}
289+
- (void)controlTextDidEndEditing:(NSNotification *)aNotification {
290+
((IRTableHeaderView *)[table headerView]).enabled = YES;
291+
self.activeText = nil;
292+
}
293+
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
294+
// NSLog(@"selectionchanged");
295+
}
296+
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
297+
[table deselectAll:nil];
298+
return YES;
299+
}
300+
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
301+
return [_dictionary count];
302+
}
303+
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
304+
if ([[tableColumn identifier] isEqualToString:@"_abbreviation"])
305+
return [_sortedArray objectAtIndex:row]; // return key
306+
else // abbrev text
307+
return [_dictionary objectForKey:[_sortedArray objectAtIndex:row]];
308+
}
309+
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
310+
if ([(NSString *)object length]) { // some other checks (e.g., abbrev is single word)
311+
NSString * currentkey = [_sortedArray objectAtIndex:row];
312+
313+
if ([[tableColumn identifier] isEqualToString:@"_abbreviation"]) {
314+
if (![currentkey isEqualToString:object]) { // if changed key
315+
[_dictionary setObject:[_dictionary objectForKey:currentkey] forKey:object];
316+
[_dictionary removeObjectForKey:currentkey];
317+
[_sortedArray replaceObjectAtIndex:row withObject:object];
318+
}
319+
}
320+
else
321+
[_dictionary setObject:[object normalizeAttributesWithMap:NULL] forKey:currentkey];
322+
}
323+
}
324+
- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors {
325+
[self sortAndReload];
326+
}
327+
@end

AlterRefsController.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// AlterRefsController.h
3+
// Cindex
4+
//
5+
// Created by PL on 1/9/05.
6+
// Copyright 2005 Indexing Research. All rights reserved.
7+
//
8+
9+
//#import "IRIndexDocument.h"
10+
#import "indexdocument.h"
11+
12+
@interface AlterRefsController : NSWindowController {
13+
IBOutlet NSMatrix * scope;
14+
IBOutlet NSTextField * rangestart;
15+
IBOutlet NSTextField * rangeend;
16+
17+
IBOutlet NSTextField * match;
18+
19+
IBOutlet NSMatrix * action;
20+
IBOutlet NSButton * holdvalues;
21+
IBOutlet NSTextField * adjustment;
22+
23+
INDEX * FF;
24+
}
25+
- (IBAction)removeAction:(id)sender;
26+
@end

0 commit comments

Comments
 (0)