File: HistoryList.m

package info (click to toggle)
wcalc 2.2.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,228 kB
  • ctags: 698
  • sloc: ansic: 6,918; objc: 1,835; sh: 766; yacc: 644; lex: 573; makefile: 78
file content (74 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download
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
#include "historyManager.h"
#include "HistoryList.h"
#ifdef MEMWATCH
#include "memwatch.h"
#endif

@implementation HistoryList

- (int)numberOfRowsInTableView:(NSTableView *)atv
{
	return historyLength();
}

/* returns the correct text for a given column and row */
- (id)tableView:(NSTableView *)atv objectValueForTableColumn:(NSTableColumn*)col row:(int)rowIndex
{
	char * val;

	if ([[col identifier] isEqualToString:@"history"])
		val = historynum(rowIndex,1);
	else
		val = historynum(rowIndex,2);

	if (! val)
		return @"BAD ROW (history manager)";

	return [NSString stringWithUTF8String:val];
}

- (IBAction)rowSelected:(id)sender
{
	int row = [sender selectedRow];
//	printf("selected: %i\n",[sender selectedRow]);
	if (row > -1) {
		[expressionField setStringValue:[NSString stringWithUTF8String:historynum([sender selectedRow],1)]];
	}
	[expressionField selectText:self];
}

- (IBAction)clearHistory:(id)sender
{
    clearHistory();
    [theList reloadData];
}

- (IBAction)copyMe:(id)sender
{
    NSPasteboard* pboard=[NSPasteboard generalPasteboard];
    NSString *theString = @"";
    NSIndexSet* rowEnumerator=[theList selectedRowIndexes];
    unsigned int index=0;

    // Set the pasteboard types you want here.
    [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
    
    index = [rowEnumerator firstIndex];
    do {
	// Here, you'd look up the data in your data source instead, and add data to the pasteboard for one or more of the types.
	theString = [theString stringByAppendingFormat:@"%s\t%s\n", historynum(index,1), historynum(index,2)];
    } while ((index = [rowEnumerator indexGreaterThanIndex:index]) != NSNotFound);
    [pboard setString:theString forType:NSStringPboardType];    
}

// ** Make sure we don't enable the copy menu item unless there is something to copy.
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
{
    if ([menuItem tag]==666)
    {
	return ([theList numberOfSelectedRows]>0);
    }
    return YES;
}

@end