Skip to content

Commit

Permalink
clean up edit-menu-insertion; use string-encoding detection method fo…
Browse files Browse the repository at this point in the history
…r importing TSV files
  • Loading branch information
Zachary Schneirov committed Sep 28, 2009
1 parent 50a0c9c commit ca807ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
38 changes: 17 additions & 21 deletions AlienNoteImporter.m
Expand Up @@ -413,13 +413,9 @@ - (NSArray*)notesInFile:(NSString*)filename {
return [self _importBlorNotes:filename];
} else if ([[filename lastPathComponent] isEqualToString:@"StickiesDatabase"]) {
return [self _importStickies:filename];
} else if ([extension isEqualToString:@"tsv"]) {
return [self _importTSVFile:filename];
} else {
//but check other special cases, too, like mbox!!

NSArray *a = [self _importTSVFile:filename];
if ([a count] > 0)
return (a);

NoteObject *note = [self noteWithFile:filename];
if (note)
return [NSArray arrayWithObject:note];
Expand Down Expand Up @@ -531,14 +527,11 @@ - (NSArray*)_importBlorNotes:(NSString*)filename {

- (NSArray*)_importTSVFile:(NSString*)filename
{
NSMutableString *contents = [NSMutableString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:nil] ;
if (!contents)
contents = [NSMutableString stringWithContentsOfFile:filename encoding:NSASCIIStringEncoding error:nil];
if (!contents)
contents = [NSMutableString stringWithContentsOfFile:filename encoding:NSMacOSRomanStringEncoding error:nil];

if (!contents)
return ([NSArray array]);
NSMutableString *contents = nil;
NSStringEncoding defaultEncoding = [NSString defaultCStringEncoding];
if (!(contents = [NSMutableString getShortLivedStringFromData:[NSMutableData dataWithContentsOfFile:filename] ofGuessedEncoding:&defaultEncoding])) {
return nil;
}

// normalize newlines
[contents replaceOccurrencesOfString:@"\r\n" withString:@"\n" options:0 range:NSMakeRange(0, [contents length])];
Expand All @@ -565,15 +558,18 @@ - (NSArray*)_importTSVFile:(NSString*)filename
continue;

NSString *title = [fields objectAtIndex:0];
NSAttributedString *body = [[[NSAttributedString alloc] initWithString:s] autorelease];
NoteObject *note = [[NoteObject alloc] initWithNoteBody:body title:title uniqueFilename:nil format:SingleDatabaseFormat];
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
[note setDateAdded:now];
[note setDateModified:now];
[notes addObject:note];
[note release];
NSAttributedString *attributedBody = [[[NSMutableAttributedString alloc] initWithString:s attributes:[[GlobalPrefs defaultPrefs] noteBodyAttributes]] autorelease];

NoteObject *note = [[[NoteObject alloc] initWithNoteBody:attributedBody title:title uniqueFilename:nil format:SingleDatabaseFormat] autorelease];
if (note) {
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
[note setDateAdded:now];
[note setDateModified:now];
[notes addObject:note];
}
}
}
[contents release];

return (notes);
}
Expand Down
9 changes: 3 additions & 6 deletions LinkingEditor.m
Expand Up @@ -93,12 +93,9 @@ - (void)awakeFromNib {

if (passwordSetup) {
passwordSetup = NO;

theMenu = [NSApp mainMenu];
// Hackish way to get the Edit menu, but it doesn't have a tag and I don't want to fiddle with MainMenu.nib to get it to open IB 3.2.
theMenuItem = [theMenu itemAtIndex:[theMenu indexOfItem:[theMenu itemWithTag:NOTES_MENU_ID]]+1];
NSMenu *editMenu = [theMenuItem submenu];
[editMenu addItem:[NSMenuItem separatorItem]];

NSMenu *editMenu = [[[NSApp mainMenu] itemWithTitle:@"Edit"] submenu];
[editMenu addItem:[NSMenuItem separatorItem]];

theMenuItem = [[NSMenuItem alloc]
initWithTitle:[NSString stringWithFormat:@"%@%C", NSLocalizedString(@"New Password", ""), 0x2026 /*ellipses*/]
Expand Down

0 comments on commit ca807ca

Please sign in to comment.