The R Project SVN R-packages

Rev

Rev 5865 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5865 Rev 5868
Line 47... Line 47...
47
{
47
{
48
	NSString *tmp = nil;
48
	NSString *tmp = nil;
49
 
49
 
50
	switch([sender tag]) {
50
	switch([sender tag]) {
51
		case 0:
51
		case 0:
52
		tmp = [self rowsAsTabStringWithHeaders:YES];
52
		tmp = ([self numberOfSelectedRows]) ? [self rowsAsTabStringWithHeaders:YES] : [self columnsAsTabStringWithHeaders:YES];
53
		break;
53
		break;
54
		case 1:
54
		case 1:
55
		tmp = [self rowsAsCsvStringWithHeaders:YES];
55
		tmp = ([self numberOfSelectedRows]) ? [self rowsAsCsvStringWithHeaders:YES] : [self columnsAsCsvStringWithHeaders:YES];
56
		break;
56
		break;
57
		default:
57
		default:
58
		NSBeep();
58
		NSBeep();
59
		return;
59
		return;
60
	}
60
	}
Line 75... Line 75...
75
 
75
 
76
}
76
}
77
 
77
 
78
- (NSUInteger)draggingSourceOperationMaskForLocal:(BOOL)isLocal
78
- (NSUInteger)draggingSourceOperationMaskForLocal:(BOOL)isLocal
79
{
79
{
80
	return NSDragOperationCopy;
80
	return ([[self selectedRowIndexes] count]) ? NSDragOperationCopy : NSDragOperationNone;
81
}
81
}
82
 
82
 
83
- (NSString *)rowsAsTabStringWithHeaders:(BOOL)withHeaders
83
- (NSString *)rowsAsTabStringWithHeaders:(BOOL)withHeaders
84
{
84
{
85
	if (![self numberOfSelectedRows]) return nil;
85
	if (![self numberOfSelectedRows]) return nil;
Line 184... Line 184...
184
	}
184
	}
185
 
185
 
186
	return result;
186
	return result;
187
}
187
}
188
 
188
 
-
 
189
- (NSString *)columnsAsTabStringWithHeaders:(BOOL)withHeaders
-
 
190
{
-
 
191
	if (![self numberOfSelectedColumns]) return nil;
-
 
192
 
-
 
193
	NSIndexSet *selectedCols = [self selectedColumnIndexes];
-
 
194
	NSUInteger colIndex = [selectedCols firstIndex];
-
 
195
 
-
 
196
	NSUInteger i;
-
 
197
	NSMutableString *result = [NSMutableString stringWithCapacity:2000];
-
 
198
 
-
 
199
	// Add the table headers if requested to do so
-
 
200
	if (withHeaders) {
-
 
201
		while ( colIndex != NSNotFound ) {
-
 
202
			if([result length])
-
 
203
				[result appendString:@"\t"];
-
 
204
			[result appendString:[[NSArrayObjectAtIndex([self tableColumns], colIndex) headerCell] title]];
-
 
205
 
-
 
206
			// Select the next column index
-
 
207
			colIndex = [selectedCols indexGreaterThanIndex:colIndex];
-
 
208
		}
-
 
209
		[result appendString:@"\n"];
-
 
210
	}
-
 
211
 
-
 
212
	// Loop through the rows, adding their descriptive contents
-
 
213
	NSArray *ds = [[self delegate] objectData];
-
 
214
	for ( i = 0; i < [NSArrayObjectAtIndex(ds, 0) count]; i++ )
-
 
215
	{
-
 
216
		colIndex = [selectedCols firstIndex];
-
 
217
		while ( colIndex != NSNotFound ) {
-
 
218
			[result appendFormat:@"%@\t", NSArrayObjectAtIndex(NSArrayObjectAtIndex(ds, colIndex), i)];
-
 
219
			// Select the next column index
-
 
220
			colIndex = [selectedCols indexGreaterThanIndex:colIndex];
-
 
221
		}
-
 
222
 
-
 
223
		// Remove the trailing tab and add the linebreak
-
 
224
		if ([result length])
-
 
225
			[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
-
 
226
 
-
 
227
		[result appendString:@"\n"];
-
 
228
	
-
 
229
	}
-
 
230
	
-
 
231
	// Remove the trailing line end
-
 
232
	if ([result length]) {
-
 
233
		[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
-
 
234
	}
-
 
235
 
-
 
236
	return result;
-
 
237
 
-
 
238
}
-
 
239
 
-
 
240
- (NSString *)columnsAsCsvStringWithHeaders:(BOOL)withHeaders
-
 
241
{
-
 
242
	if (![self numberOfSelectedColumns]) return nil;
-
 
243
 
-
 
244
	NSIndexSet *selectedCols = [self selectedColumnIndexes];
-
 
245
	NSUInteger colIndex = [selectedCols firstIndex];
-
 
246
 
-
 
247
	NSUInteger i;
-
 
248
	NSMutableString *result = [NSMutableString stringWithCapacity:2000];
-
 
249
 
-
 
250
	// Add the table headers if requested to do so
-
 
251
	if (withHeaders) {
-
 
252
		while ( colIndex != NSNotFound ) {
-
 
253
			if([result length])
-
 
254
				[result appendString:@","];
-
 
255
 
-
 
256
			[result appendString:[NSString stringWithFormat:@"\"%@\"",[[[NSArrayObjectAtIndex([self tableColumns], colIndex) headerCell] title] stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""]]];
-
 
257
 
-
 
258
			// Select the next column index
-
 
259
			colIndex = [selectedCols indexGreaterThanIndex:colIndex];
-
 
260
		}
-
 
261
		[result appendString:@"\n"];
-
 
262
	}
-
 
263
 
-
 
264
	// Loop through the rows, adding their descriptive contents
-
 
265
	NSArray *ds = [[self delegate] objectData];
-
 
266
	NSArray *columnTypes = [[self delegate] objectColumnTypes];
-
 
267
 
-
 
268
	NSInteger types[[columnTypes count]];
-
 
269
 
-
 
270
	for( i = 0; i < [columnTypes count]; i++ )
-
 
271
		types[i] = [NSArrayObjectAtIndex(columnTypes, i) intValue];
-
 
272
 
-
 
273
	for ( i = 0; i < [NSArrayObjectAtIndex(ds, 0) count]; i++ )
-
 
274
	{
-
 
275
		colIndex = [selectedCols firstIndex];
-
 
276
		while ( colIndex != NSNotFound ) {
-
 
277
 
-
 
278
			if(types[colIndex] == 1)
-
 
279
				[result appendFormat:@"%@,", NSArrayObjectAtIndex(NSArrayObjectAtIndex(ds, colIndex), i)];
-
 
280
			else
-
 
281
				[result appendFormat:@"\"%@\",", [NSArrayObjectAtIndex(NSArrayObjectAtIndex(ds, colIndex), i) stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""]];
-
 
282
 
-
 
283
			// Select the next column index
-
 
284
			colIndex = [selectedCols indexGreaterThanIndex:colIndex];
-
 
285
		}
-
 
286
 
-
 
287
		// Remove the trailing comma and add the linebreak
-
 
288
		if ([result length]){
-
 
289
			[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
-
 
290
		}
-
 
291
		[result appendString:@"\n"];
-
 
292
 
-
 
293
	}
-
 
294
	
-
 
295
	// Remove the trailing line end
-
 
296
	if ([result length]) {
-
 
297
		[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
-
 
298
	}
-
 
299
 
-
 
300
	return result;
-
 
301
 
-
 
302
}
-
 
303
 
189
- (CGFloat)widthForColumn:(NSInteger)columnIndex andHeaderName:(NSString*)colName
304
- (CGFloat)widthForColumn:(NSInteger)columnIndex andHeaderName:(NSString*)colName
190
{
305
{
191
 
306
 
192
	CGFloat        columnBaseWidth;
307
	CGFloat        columnBaseWidth;
193
	NSString       *contentString;
308
	NSString       *contentString;
Line 369... Line 484...
369
}
484
}
370
 
485
 
371
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
486
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
372
{
487
{
373
	if ([menuItem action] == @selector(copy:)) {
488
	if ([menuItem action] == @selector(copy:)) {
374
		return ([self numberOfSelectedRows] > 0);
489
		return ([self numberOfSelectedRows] > 0 || [self numberOfSelectedColumns] > 0);
375
	}
490
	}
376
	if ([menuItem action] == @selector(remSelection:)) {
491
	if ([menuItem action] == @selector(remSelection:)) {
377
		return ([[self selectedColumnIndexes] count] || [[self selectedRowIndexes] count]);
492
		return ([[self selectedColumnIndexes] count] || [[self selectedRowIndexes] count]);
378
	}
493
	}
379
 
494