Permalink
Browse files

accessory view for choosing whether to import creation dates from the…

… Import... menu item
  • Loading branch information...
1 parent 4aead30 commit c9f24bec8425c2a72209eee28944c94883012b46 Zachary Schneirov committed Oct 1, 2009
View
@@ -16,13 +16,17 @@ extern NSString *RetrievedPasswordKey;
@class NoteObject;
@interface AlienNoteImporter : NSObject {
+ IBOutlet NSButton *grabCreationDatesButton;
+ IBOutlet NSView *importAccessoryView;
+
SEL importerSelector;
//for URL downloading
id receptionDelegate;
id source;
NSMutableDictionary *documentSettings;
+ BOOL shouldGrabCreationDates;
}
//a directory containing notes, a custom bundle, or custom file format in which more than one note could be expected
@@ -37,6 +41,7 @@ extern NSString *RetrievedPasswordKey;
+ (NSBundle *)PDFKitBundle;
+ (Class)PDFDocClass;
+- (NSView*)accessoryView;
- (NSDictionary*)documentSettings;
- (NSArray*)importedNotes;
View
@@ -20,6 +20,7 @@
NSString *PasswordWasRetrievedFromKeychainKey = @"PasswordRetrievedFromKeychain";
NSString *RetrievedPasswordKey = @"RetrievedPassword";
+NSString *ShouldImportCreationDates = @"ShouldImportCreationDates";
@interface AlienNoteImporter (Private)
- (NSArray*)_importStickies:(NSString*)filename;
@@ -31,7 +32,7 @@ @implementation AlienNoteImporter
- (id)init {
if ([super init]) {
-
+ shouldGrabCreationDates = NO;
documentSettings = [[NSMutableDictionary alloc] init];
}
return self;
@@ -152,12 +153,26 @@ - (NSDictionary*)documentSettings {
return documentSettings;
}
+- (NSView*)accessoryView {
+ if (!importAccessoryView) {
+ if (![NSBundle loadNibNamed:@"ImporterAccessory" owner:self]) {
+ NSLog(@"Failed to load ImporterAccessory.nib");
+ NSBeep();
+ return nil;
+ }
+ }
+ return importAccessoryView;
+}
+
+
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo {
id delegate = (id)contextInfo;
if (delegate && [delegate respondsToSelector:@selector(noteImporter:importedNotes:)]) {
if (returnCode == NSOKButton) {
+ shouldGrabCreationDates = [grabCreationDatesButton state] == NSOnState;
+ [[NSUserDefaults standardUserDefaults] setBool:shouldGrabCreationDates forKey:ShouldImportCreationDates];
NSArray *notes = [self notesWithPaths:[panel filenames]];
if (notes && [notes count])
[delegate noteImporter:self importedNotes:notes];
@@ -181,6 +196,8 @@ - (void)importNotesFromDialogAroundWindow:(NSWindow*)mainWindow receptionDelegat
[openPanel setPrompt:NSLocalizedString(@"Import",@"title of button in import dialog")];
[openPanel setTitle:NSLocalizedString(@"Import Notes",@"title of import dialog")];
[openPanel setMessage:NSLocalizedString(@"Select files and folders from which to import notes.",@"import dialog message")];
+ [openPanel setAccessoryView:[self accessoryView]];
+ [grabCreationDatesButton setState:[[NSUserDefaults standardUserDefaults] boolForKey:ShouldImportCreationDates]];
[self retain];
@@ -321,30 +338,33 @@ - (NoteObject*)noteWithFile:(NSString*)filename {
} else if (fileType == PDF_TYPE_ID || [extension isEqualToString:@"pdf"]) {
//try PDFKit if on 10.4
if (RunningTigerAppKitOrHigher) {
- Class PdfDocClass = [[self class] PDFDocClass];
- if (PdfDocClass != Nil) {
- id doc = [[PdfDocClass alloc] initWithData:[NSData dataWithContentsOfFile:filename]];
- if (doc) {
- id sel = [doc performSelector:@selector(selectionForEntireDocument)];
- if (sel) {
- attributedStringFromData = [[NSMutableAttributedString alloc] initWithAttributedString:[sel attributedString]];
- //maybe we could check pages and boundsForPage: to try to determine where a line was soft-wrapped in the document?
+ @try {
+ Class PdfDocClass = [[self class] PDFDocClass];
+ if (PdfDocClass != Nil) {
+ id doc = [[PdfDocClass alloc] initWithURL:[NSURL fileURLWithPath:filename]];
+ if (doc) {
+ id sel = [doc performSelector:@selector(selectionForEntireDocument)];
+ if (sel) {
+ attributedStringFromData = [[NSMutableAttributedString alloc] initWithAttributedString:[sel attributedString]];
+ //maybe we could check pages and boundsForPage: to try to determine where a line was soft-wrapped in the document?
+ } else {
+ NSLog(@"Couldn't get entire doc selection for PDF");
+ }
+ [doc autorelease];
} else {
- NSLog(@"Couldn't get entire doc selection for PDF");
+ NSLog(@"Couldn't parse data into PDF");
}
- [doc release];
} else {
- NSLog(@"Couldn't parse data into PDF");
+ NSLog(@"No PDFDocument!");
}
- } else {
- NSLog(@"No PDFDocument!");
+ } @catch (NSException *e) {
+ NSLog(@"Error importing PDF %@ (%@, %@)", filename, [e name], [e reason]);
}
}
} else if (fileType == TEXT_TYPE_ID || [extension isEqualToString:@"txt"] || [extension isEqualToString:@"text"]) {
- NSMutableString *stringFromData = nil;
- NSStringEncoding defaultEncoding = [NSString defaultCStringEncoding];
- if ((stringFromData = [NSMutableString newShortLivedStringFromData:[NSMutableData dataWithContentsOfFile:filename] ofGuessedEncoding:&defaultEncoding])) {
+ NSMutableString *stringFromData = [NSMutableString newShortLivedStringFromFile:filename];
+ if (stringFromData) {
attributedStringFromData = [[NSMutableAttributedString alloc] initWithString:stringFromData
attributes:[[GlobalPrefs defaultPrefs] noteBodyAttributes]];
[stringFromData release];
@@ -366,7 +386,9 @@ - (NoteObject*)noteWithFile:(NSString*)filename {
NoteObject *noteObject = [[NoteObject alloc] initWithNoteBody:attributedStringFromData title:[[filename lastPathComponent] stringByDeletingPathExtension]
uniqueFilename:nil format:SingleDatabaseFormat];
if (noteObject) {
- //[noteObject setDateAdded:CFDateGetAbsoluteTime((CFDateRef)[attributes objectForKey:NSFileCreationDate])];
+ if (shouldGrabCreationDates) {
+ [noteObject setDateAdded:CFDateGetAbsoluteTime((CFDateRef)[attributes objectForKey:NSFileCreationDate])];
+ }
[noteObject setDateModified:CFDateGetAbsoluteTime((CFDateRef)[attributes objectForKey:NSFileModificationDate])];
return [noteObject autorelease];
@@ -526,11 +548,8 @@ - (NSArray*)_importBlorNotes:(NSString*)filename {
- (NSArray*)_importTSVFile:(NSString*)filename
{
- NSMutableString *contents = nil;
- NSStringEncoding defaultEncoding = [NSString defaultCStringEncoding];
- if (!(contents = [NSMutableString newShortLivedStringFromData:[NSMutableData dataWithContentsOfFile:filename] ofGuessedEncoding:&defaultEncoding])) {
- return nil;
- }
+ NSMutableString *contents = [NSMutableString newShortLivedStringFromFile:filename];
+ if (!contents) return nil;
// normalize newlines
[contents replaceOccurrencesOfString:@"\r\n" withString:@"\n" options:0 range:NSMakeRange(0, [contents length])];
View
@@ -53,22 +53,34 @@ void MakeLowercase(char *text) {
}
}
+int ContainsUInteger(const NSUInteger *uintArray, size_t count, NSUInteger auint) {
+ size_t i;
+ for (i=0; i<count; i++) {
+ if (uintArray[i] == auint) return 1;
+ }
+ return 0;
+}
+
int ContainsHighAscii(const void *s1, size_t n) {
- register unsigned int *intBuffer = (unsigned int*)s1;
- register unsigned int i, pattern = 0x80808080;
- register unsigned int integerCount = n/sizeof(unsigned int);
+ register NSUInteger *intBuffer = (NSUInteger*)s1;
+ register NSUInteger i, integerCount = n/sizeof(NSUInteger);
+ register NSUInteger pattern =
+#if __LP64__ || NS_BUILD_32_LIKE_64
+ 0x8080808080808080;
+#else
+ 0x80808080;
+#endif
- //could be further parallelized with 64-bit integers and altivec
for (i=0; i<integerCount; i++ ) {
if (pattern & intBuffer[i]) {
return 1;
}
}
unsigned char *charBuffer = (unsigned char*)s1;
- unsigned int leftOverCharCount = n % sizeof(unsigned int);
+ NSUInteger leftOverCharCount = n % sizeof(NSUInteger);
for (i = n - leftOverCharCount; i<n; i++) {
if (charBuffer[i] > 127) {
View
@@ -12,12 +12,13 @@
char *replaceString(char *oldString, const char *newString);
void ResizeBuffer(void ***buffer, unsigned int objCount, unsigned int *bufSize);
int IsZeros(const void *s1, size_t n);
+int ContainsUInteger(const NSUInteger *uintArray, size_t count, NSUInteger auint);
void MakeLowercase(char *text);
int ContainsHighAscii(const void *s1, size_t n);
CFStringRef CFStringFromBase10Integer(int quantity);
unsigned DumbWordCount(const void *s1, size_t len);
-int genericSortContextFirst(int (*context) (void*, void*), void* one, void* two);
-int genericSortContextLast(void* one, void* two, int (*context) (void*, void*));
+NSInteger genericSortContextFirst(int (*context) (void*, void*), void* one, void* two);
+NSInteger genericSortContextLast(void* one, void* two, int (*context) (void*, void*));
void QuickSortBuffer(void **buffer, unsigned int objCount, int (*compar)(const void *, const void *));
CFStringRef CreateRandomizedFileName();
OSStatus FSCreateFileIfNotPresentInDirectory(FSRef *directoryRef, FSRef *childRef, CFStringRef filename, Boolean *created);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit c9f24be

Please sign in to comment.