Added MAAddMediaSheet

This commit is contained in:
Matthias Neeracher 2011-08-12 02:00:37 +02:00
parent 269388a545
commit 33a9854b0c
9 changed files with 1270 additions and 20 deletions

View File

@ -23,6 +23,9 @@
950BB6A013F2C6B400D8E669 /* MAMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB69F13F2C6B400D8E669 /* MAMedia.mm */; };
950BB6A313F2C6B400D8E669 /* MATagDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB6A213F2C6B400D8E669 /* MATagDescription.mm */; };
950BB78613F2D95500D8E669 /* MADocWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB78513F2D95500D8E669 /* MADocWindow.mm */; };
950BB7A713F467A400D8E669 /* MAAddMedia.xib in Resources */ = {isa = PBXBuildFile; fileRef = 950BB7A513F467A400D8E669 /* MAAddMedia.xib */; };
950BB7AA13F46BAF00D8E669 /* MAAddMediaSheet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB7A913F46BAF00D8E669 /* MAAddMediaSheet.mm */; };
950BB7AD13F46ECF00D8E669 /* MAAppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950BB7AC13F46ECF00D8E669 /* MAAppController.mm */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -52,6 +55,11 @@
950BB6A213F2C6B400D8E669 /* MATagDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MATagDescription.mm; sourceTree = "<group>"; };
950BB78413F2D95500D8E669 /* MADocWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MADocWindow.h; sourceTree = "<group>"; };
950BB78513F2D95500D8E669 /* MADocWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MADocWindow.mm; sourceTree = "<group>"; };
950BB7A613F467A400D8E669 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MAAddMedia.xib; sourceTree = "<group>"; };
950BB7A813F46BAF00D8E669 /* MAAddMediaSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MAAddMediaSheet.h; sourceTree = "<group>"; };
950BB7A913F46BAF00D8E669 /* MAAddMediaSheet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MAAddMediaSheet.mm; sourceTree = "<group>"; };
950BB7AB13F46ECF00D8E669 /* MAAppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MAAppController.h; sourceTree = "<group>"; };
950BB7AC13F46ECF00D8E669 /* MAAppController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MAAppController.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -98,23 +106,9 @@
950BB67013F1F26200D8E669 /* Medianno */ = {
isa = PBXGroup;
children = (
950BB67C13F1F26200D8E669 /* MADocument.h */,
950BB67D13F1F26200D8E669 /* MADocument.mm */,
950BB6A113F2C6B400D8E669 /* MATagDescription.h */,
950BB6A213F2C6B400D8E669 /* MATagDescription.mm */,
950BB69E13F2C6B400D8E669 /* MAMedia.h */,
950BB69F13F2C6B400D8E669 /* MAMedia.mm */,
950BB69B13F2C6B400D8E669 /* MAAnno.h */,
950BB69C13F2C6B400D8E669 /* MAAnno.mm */,
950BB69813F2C6B400D8E669 /* MATag.h */,
950BB69913F2C6B400D8E669 /* MATag.mm */,
950BB69513F2C6B300D8E669 /* MAFolder.h */,
950BB69613F2C6B300D8E669 /* MAFolder.mm */,
950BB67F13F1F26200D8E669 /* MADocument.xib */,
950BB78413F2D95500D8E669 /* MADocWindow.h */,
950BB78513F2D95500D8E669 /* MADocWindow.mm */,
950BB68213F1F26200D8E669 /* MainMenu.xib */,
950BB68513F1F26200D8E669 /* MADocument.xcdatamodeld */,
950BB7B013F4803500D8E669 /* Classes */,
950BB7AF13F4801A00D8E669 /* Data Model */,
950BB7AE13F47FCA00D8E669 /* Resources */,
950BB67113F1F26200D8E669 /* Supporting Files */,
);
path = Medianno;
@ -132,6 +126,50 @@
name = "Supporting Files";
sourceTree = "<group>";
};
950BB7AE13F47FCA00D8E669 /* Resources */ = {
isa = PBXGroup;
children = (
950BB67F13F1F26200D8E669 /* MADocument.xib */,
950BB7A513F467A400D8E669 /* MAAddMedia.xib */,
950BB68213F1F26200D8E669 /* MainMenu.xib */,
);
name = Resources;
path = ..;
sourceTree = "<group>";
};
950BB7AF13F4801A00D8E669 /* Data Model */ = {
isa = PBXGroup;
children = (
950BB68513F1F26200D8E669 /* MADocument.xcdatamodeld */,
);
name = "Data Model";
sourceTree = "<group>";
};
950BB7B013F4803500D8E669 /* Classes */ = {
isa = PBXGroup;
children = (
950BB67C13F1F26200D8E669 /* MADocument.h */,
950BB67D13F1F26200D8E669 /* MADocument.mm */,
950BB6A113F2C6B400D8E669 /* MATagDescription.h */,
950BB6A213F2C6B400D8E669 /* MATagDescription.mm */,
950BB69E13F2C6B400D8E669 /* MAMedia.h */,
950BB69F13F2C6B400D8E669 /* MAMedia.mm */,
950BB69B13F2C6B400D8E669 /* MAAnno.h */,
950BB69C13F2C6B400D8E669 /* MAAnno.mm */,
950BB69813F2C6B400D8E669 /* MATag.h */,
950BB69913F2C6B400D8E669 /* MATag.mm */,
950BB7A813F46BAF00D8E669 /* MAAddMediaSheet.h */,
950BB7A913F46BAF00D8E669 /* MAAddMediaSheet.mm */,
950BB7AB13F46ECF00D8E669 /* MAAppController.h */,
950BB7AC13F46ECF00D8E669 /* MAAppController.mm */,
950BB69513F2C6B300D8E669 /* MAFolder.h */,
950BB69613F2C6B300D8E669 /* MAFolder.mm */,
950BB78413F2D95500D8E669 /* MADocWindow.h */,
950BB78513F2D95500D8E669 /* MADocWindow.mm */,
);
name = Classes;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -186,6 +224,7 @@
950BB67B13F1F26200D8E669 /* Credits.rtf in Resources */,
950BB68113F1F26200D8E669 /* MADocument.xib in Resources */,
950BB68413F1F26200D8E669 /* MainMenu.xib in Resources */,
950BB7A713F467A400D8E669 /* MAAddMedia.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -205,6 +244,8 @@
950BB6A013F2C6B400D8E669 /* MAMedia.mm in Sources */,
950BB6A313F2C6B400D8E669 /* MATagDescription.mm in Sources */,
950BB78613F2D95500D8E669 /* MADocWindow.mm in Sources */,
950BB7AA13F46BAF00D8E669 /* MAAddMediaSheet.mm in Sources */,
950BB7AD13F46ECF00D8E669 /* MAAppController.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -233,6 +274,7 @@
950BB68013F1F26200D8E669 /* en */,
);
name = MADocument.xib;
path = Medianno;
sourceTree = "<group>";
};
950BB68213F1F26200D8E669 /* MainMenu.xib */ = {
@ -241,6 +283,16 @@
950BB68313F1F26200D8E669 /* en */,
);
name = MainMenu.xib;
path = Medianno;
sourceTree = "<group>";
};
950BB7A513F467A400D8E669 /* MAAddMedia.xib */ = {
isa = PBXVariantGroup;
children = (
950BB7A613F467A400D8E669 /* en */,
);
name = MAAddMedia.xib;
path = Medianno;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

View File

@ -0,0 +1,24 @@
//
// MAAddMediaSheet.h
// Medianno
//
// Created by Matthias Neeracher on 8/11/11.
// Copyright 2011 Apple Computer. All rights reserved.
//
#import <Cocoa/Cocoa.h>
typedef void (^MAAddMediaBlock)(NSURL * url, NSDate * date);
@interface MAAddMediaSheet : NSWindowController {
}
@property (readonly) NSArray * urls;
@property (readonly) NSArray * dates;
@property BOOL copyMedia;
- (void)runWithParentWindow:(NSWindow *)win media:(NSArray *)urls addMedia:(MAAddMediaBlock)block;
- (IBAction)useModificationDates:(id)sender;
@end

View File

@ -0,0 +1,63 @@
//
// MAAddMediaSheet.mm
// Medianno
//
// Created by Matthias Neeracher on 8/11/11.
// Copyright 2011 Apple Computer. All rights reserved.
//
#import "MAAddMediaSheet.h"
#import "MAAppController.h"
@implementation MAAddMediaSheet
@synthesize urls, dates, copyMedia;
- (id)init
{
self = [super initWithWindowNibName:@"MAAddMedia"];
copyMedia = YES;
return self;
}
- (void)runWithParentWindow:(NSWindow *)win media:(NSArray *)mediaUrls addMedia:(MAAddMediaBlock)block
{
urls = [mediaUrls retain];
[self useModificationDates:self];
[NSApp beginSheet:[self window] modalForWindow:win didEndBlock:^(NSInteger returnCode) {
if (returnCode == NSAlertFirstButtonReturn) {
[urls enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
block(obj, [dates objectAtIndex:idx]);
}];
}
[[self window] orderOut:self];
[self autorelease];
}];
}
- (void)dealloc
{
[urls release];
[dates release];
}
- (IBAction)useModificationDates:(id)sender
{
NSMutableArray * newDates = [[NSMutableArray alloc] initWithCapacity:[urls count]];
for (NSURL * url in urls) {
NSDate * modificationDate;
[url getResourceValue:&modificationDate forKey:NSURLContentModificationDateKey error:nil];
[newDates addObject:(modificationDate ? modificationDate : [NSDate date])];
}
[dates release];
dates = newDates;
}
- (IBAction)endSheet:(id)sender
{
[NSApp endSheet:[self window] returnCode:[sender tag]];
}
@end

View File

@ -0,0 +1,21 @@
//
// MAAppController.h
// Medianno
//
// Created by Matthias Neeracher on 8/11/11.
// Copyright 2011 Apple Computer. All rights reserved.
//
#import <Cocoa/Cocoa.h>
typedef void (^MASheetBlock)(NSInteger returnCode);
@interface NSApplication (SheetAdditions)
- (void)beginSheet: (NSWindow *)sheet modalForWindow:(NSWindow *)docWindow didEndBlock: (MASheetBlock)block;
@end
@interface MAAppController : NSObject
@end

View File

@ -0,0 +1,44 @@
//
// MAAppController.mm
// Medianno
//
// Created by Matthias Neeracher on 8/11/11.
// Copyright 2011 Apple Computer. All rights reserved.
//
#import "MAAppController.h"
@implementation NSApplication (SheetAdditions)
- (void)beginSheet: (NSWindow *)sheet modalForWindow:(NSWindow *)docWindow didEndBlock: (MASheetBlock)block
{
[self beginSheet: sheet
modalForWindow: docWindow
modalDelegate: self
didEndSelector: @selector(my_blockSheetDidEnd:returnCode:contextInfo:)
contextInfo: [block copy]];
}
- (void)my_blockSheetDidEnd: (NSWindow *)sheet returnCode: (NSInteger)returnCode contextInfo: (void *)contextInfo
{
MASheetBlock block = (MASheetBlock)contextInfo;
block(returnCode);
[block release];
}
@end
@implementation MAAppController
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
@end

View File

@ -6,9 +6,12 @@
// Copyright 2011 Apple Computer. All rights reserved.
//
#import "MADocWindow.h"
#import <QTKit/QTKit.h>
#import "MADocWindow.h"
#import "MAAddMediaSheet.h"
#import "MADocument.h"
@implementation MADocWindow
- (id)initWithWindow:(NSWindow *)window
@ -37,6 +40,7 @@
[openPanel setAllowsMultipleSelection:YES];
[openPanel setCanChooseDirectories:YES];
[openPanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) {
[openPanel orderOut:self];
if (result == NSFileHandlingPanelOKButton)
[self addMedia:[openPanel URLs]];
}];
@ -76,7 +80,10 @@
}
[expandedURLs addObject:url];
}
NSLog(@"Adding %@\n", expandedURLs);
MADocument * doc = [self document];
[[[MAAddMediaSheet alloc] init] runWithParentWindow:[self window] media:expandedURLs addMedia:^(NSURL *url,NSDate *date) {
[doc addMediaURL:url date:date];
}];
}
@end

View File

@ -12,4 +12,6 @@
}
- (void)addMediaURL:(NSURL *)url date:(NSDate *)date;
@end

View File

@ -9,6 +9,7 @@
#import "MADocument.h"
#import "MADocWindow.h"
#import "MAFolder.h"
#import "MAMedia.h"
#pragma mark NSPersistentDocument file URL hook
@ -160,7 +161,7 @@ static NSString *StoreFileName = @"MediannoDB.sql";
NSString *filePath = [inAbsoluteURL path];
// Depending on the type of save operation:
if (inSaveOperation == NSSaveAsOperation) {
if (inSaveOperation == NSSaveAsOperation || inSaveOperation == NSAutosaveElsewhereOperation) {
// Nothing exists at the URL: set up the directory and migrate the Core Data store.
filewrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil];
@ -223,5 +224,16 @@ static NSString *StoreFileName = @"MediannoDB.sql";
return [super revertToContentsOfURL:inAbsoluteURL ofType:inTypeName error:outError];
}
#pragma mark -
#pragma mark Media management
- (void)addMediaURL:(NSURL *)url date:(NSDate *)date
{
NSManagedObjectContext *moc = [self managedObjectContext];
MAMedia * media = [NSEntityDescription insertNewObjectForEntityForName:@"MAMedia" inManagedObjectContext:moc];
media.media = [url path];
media.date = [date timeIntervalSince1970];
[moc processPendingChanges];
}
@end

File diff suppressed because it is too large Load Diff