diff --git a/Medianno/MAAppController.h b/Medianno/MAAppController.h index a0a484e..367bb5f 100644 --- a/Medianno/MAAppController.h +++ b/Medianno/MAAppController.h @@ -7,6 +7,7 @@ // #import +#import "MAMovieWindow.h" typedef void (^MASheetBlock)(NSInteger returnCode); @@ -16,6 +17,9 @@ typedef void (^MASheetBlock)(NSInteger returnCode); @end -@interface MAAppController : NSObject +@interface MAAppController : NSObject { +} + +@property (assign) IBOutlet MAMovieWindow * moviePanel; @end diff --git a/Medianno/MAAppController.mm b/Medianno/MAAppController.mm index 66839c3..3141814 100644 --- a/Medianno/MAAppController.mm +++ b/Medianno/MAAppController.mm @@ -8,6 +8,16 @@ #import "MAAppController.h" +@implementation MAAppController + +@synthesize moviePanel; + +- (void)applicationDidFinishLaunching:(NSNotification *)notification +{ + [[NSDocumentController sharedDocumentController] setAutosavingDelay:30.0]; +} + +@end @implementation NSApplication (SheetAdditions) @@ -28,12 +38,3 @@ } @end - -@implementation MAAppController - -- (void)applicationDidFinishLaunching:(NSNotification *)notification -{ - [[NSDocumentController sharedDocumentController] setAutosavingDelay:30.0]; -} - -@end diff --git a/Medianno/MADocWindow.h b/Medianno/MADocWindow.h index 64562f4..82fbe16 100644 --- a/Medianno/MADocWindow.h +++ b/Medianno/MADocWindow.h @@ -35,8 +35,9 @@ - (IBAction)mediaSkipBackward:(id)sender; - (IBAction)mediaSkipForward:(id)sender; - (IBAction)toggleMediaPlay:(id)sender; -- (IBAction)toggleMoviePanel:(id)sender; - (QTTime)currentMovieTime; +- (void)moviePanelDidAppear; +- (void)moviePanelDidClose; @end diff --git a/Medianno/MADocWindow.mm b/Medianno/MADocWindow.mm index e7859c9..6b598d8 100644 --- a/Medianno/MADocWindow.mm +++ b/Medianno/MADocWindow.mm @@ -16,6 +16,7 @@ #import "MATag.h" #import "MATagDescription.h" #import "MAMovieWindow.h" +#import "MAAppController.h" static const char * kMADocWindowObserver = "MADocWindowObserver"; @@ -39,7 +40,34 @@ static const char * kMADocWindowObserver = "MADocWindowObserver"; [annotationController setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"location" ascending:YES]]]; [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateMovieTime:) userInfo:nil repeats:YES]; [mediaController addObserver:self forKeyPath:@"selection.media" options:0 context:&kMADocWindowObserver]; - [moviePanel addObserver:self forKeyPath:@"showMovieInPanel" options:0 context:&kMADocWindowObserver]; +} + +- (MAMovieWindow *)moviePanel +{ + return [[NSApp delegate] moviePanel]; +} + +- (void)moviePanelDidAppear +{ + [movieView setMovie:nil]; + if (![[self moviePanel] shouldDisplayMovie:currentMovie]) + [movieView setMovie:currentMovie]; +} + +- (void)windowDidBecomeMain:(NSNotification *)notification +{ + [self moviePanelDidAppear]; +} + +- (void)moviePanelDidClose +{ + [[self moviePanel] shouldDisplayMovie:nil]; + [movieView setMovie:currentMovie]; +} + +- (void)windowDidResignMain:(NSNotification *)notification +{ + [self moviePanelDidClose]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -52,20 +80,10 @@ static const char * kMADocWindowObserver = "MADocWindowObserver"; MAMedia * currentMedia = [mediaController selection]; currentMovie = [[QTMovie alloc] initWithFile:[currentMedia valueForKey:@"media"] error:nil]; } - [moviePanel setMovie:currentMovie]; + [self moviePanelDidAppear]; } } -- (void)windowDidBecomeMain:(NSNotification *)notification -{ - [moviePanel setMainWindowIsFront:YES]; -} - -- (void)windowDidResignMain:(NSNotification *)notification -{ - [moviePanel setMainWindowIsFront:NO]; -} - #pragma mark Media management - (QTTime)currentMovieTime @@ -223,11 +241,6 @@ static const char * kMADocWindowObserver = "MADocWindowObserver"; [currentMovie play]; } -- (IBAction)toggleMoviePanel:(id)sender -{ - [moviePanel setMoviePanelEnabled:![moviePanel moviePanelEnabled]]; -} - - (BOOL)validateUserInterfaceItem:(id )item { if ([item action] == @selector(addMediaFiles:) @@ -237,11 +250,6 @@ static const char * kMADocWindowObserver = "MADocWindowObserver"; return YES; NSMenuItem * menuItem = (NSMenuItem *)item; - if ([item action] == @selector(toggleMoviePanel:)) { - [menuItem setState:[moviePanel moviePanelEnabled]]; - - return YES; - } if ([item action] == @selector(toggleMediaPlay:)) { if ([currentMovie rate] > 0.0f) [menuItem setTitle:NSLocalizedString(@"Pause", @"Pause playback")]; @@ -337,7 +345,7 @@ static NSTimeInterval sLastSkip = 0.0; - (IBAction)addAnnotation:(id)sender { - [movieView pause:sender]; + [currentMovie stop]; QTTime location = [self currentMovieTime]; MAAnno * anno = [[self document] addAnnotationForMedia:[[mediaController selectedObjects] objectAtIndex:0] location:location]; [annotationController setSelectedObjects:[NSArray arrayWithObject:anno]]; diff --git a/Medianno/MAMovieWindow.h b/Medianno/MAMovieWindow.h index f53d1f7..d2c088d 100644 --- a/Medianno/MAMovieWindow.h +++ b/Medianno/MAMovieWindow.h @@ -9,17 +9,12 @@ #import #import -@interface MAMovieWindow : NSWindowController { - IBOutlet NSWindow * mainWindow; - IBOutlet QTMovieView * mainMovieView; - IBOutlet QTMovieView * panelMovieView; +@interface MAMovieWindow : NSWindowController { + IBOutlet QTMovieView * panelMovieView; } -@property BOOL mainWindowIsFront, moviePanelEnabled; - -- (BOOL)showMovieInPanel; -+ (NSSet *)keyPathsForValuesAffectingShowMovieInPanel; -- (void)setMovie:(QTMovie *)movie; +- (BOOL)shouldDisplayMovie:(QTMovie *)movie; +- (IBAction)toggleWindow:(id)sender; @end diff --git a/Medianno/MAMovieWindow.m b/Medianno/MAMovieWindow.m index 202451b..abd7dae 100644 --- a/Medianno/MAMovieWindow.m +++ b/Medianno/MAMovieWindow.m @@ -7,11 +7,10 @@ // #import "MAMovieWindow.h" +#import "MADocWindow.h" @implementation MAMovieWindow -@synthesize moviePanelEnabled, mainWindowIsFront; - - (id)init { self = [super initWithWindowNibName:@"MAMovie"]; @@ -24,39 +23,32 @@ [super windowDidLoad]; } -- (void)setMoviePanelEnabled:(BOOL)enabled +- (BOOL)shouldDisplayMovie:(QTMovie *)movie { - if ((self->moviePanelEnabled = enabled)) - [self loadWindow]; - - [self setMainWindowIsFront:[mainWindow isMainWindow]]; -} - -- (BOOL)showMovieInPanel -{ - return moviePanelEnabled && mainWindowIsFront; -} - -- (void)setShowMovieInPanel:(BOOL)showIt -{ - moviePanelEnabled = showIt; -} - -+ (NSSet *)keyPathsForValuesAffectingShowMovieInPanel -{ - return [NSSet setWithObjects:@"moviePanelEnabled", @"mainWindowIsFront", nil]; -} - -- (void)setMovie:(QTMovie *)movie -{ - if ([self showMovieInPanel]) { + if ([self isWindowLoaded] && [[self window] isVisible]) { [panelMovieView setMovie:movie]; - [mainMovieView setMovie:nil]; + return YES; } else { - [mainMovieView setMovie:movie]; [panelMovieView setMovie:nil]; + return NO; } } + +- (IBAction)toggleWindow:(id)sender +{ + if ([self isWindowLoaded] && [[self window] isVisible]) { + [self close]; + } else { + [[self window] orderFront:sender]; + [[[NSApp mainWindow] windowController] moviePanelDidAppear]; + } +} + +- (void)windowWillClose:(NSNotification *)notification +{ + [[[NSApp mainWindow] windowController] moviePanelDidClose]; +} + @end @implementation MAMovieWin diff --git a/Medianno/en.lproj/MADocument.xib b/Medianno/en.lproj/MADocument.xib index e5db017..0a9d73d 100644 --- a/Medianno/en.lproj/MADocument.xib +++ b/Medianno/en.lproj/MADocument.xib @@ -99,7 +99,7 @@ {1279, 183} - + _NS:1197 YES @@ -339,7 +339,7 @@ {1281, 201} - + _NS:1193 133682 @@ -401,7 +401,7 @@ {1278, 565} - + _NS:1197 YES @@ -548,7 +548,6 @@ {{1, 566}, {1279, 15}} - _NS:1216 1 @@ -574,7 +573,7 @@ {1280, 583} - + _NS:1193 133682 @@ -787,9 +786,6 @@ 0 NO - - MAMovieWindow - @@ -1335,38 +1331,6 @@ 100248 - - - moviePanel - - - - 100250 - - - - mainWindow - - - - 100252 - - - - mediaController - - - - 100255 - - - - mainMovieView - - - - 100260 - @@ -1755,12 +1719,6 @@ - - 100249 - - - Movie Panel - @@ -1825,7 +1783,6 @@ 100237.IBPluginDependency 100238.IBPluginDependency 100239.IBPluginDependency - 100249.IBPluginDependency 5.IBNSWindowAutoPositionCentersHorizontal 5.IBNSWindowAutoPositionCentersVertical 5.IBPluginDependency @@ -1901,7 +1858,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2094,42 +2050,14 @@ MAMovieWindow NSWindowController - YES - - YES - mainMovieView - mainWindow - panelMovieView - - - YES - QTMovieView - NSWindow - QTMovieView - + panelMovieView + QTMovieView - YES - - YES - mainMovieView - mainWindow - panelMovieView - - - YES - - mainMovieView - QTMovieView - - - mainWindow - NSWindow - - - panelMovieView - QTMovieView - + panelMovieView + + panelMovieView + QTMovieView diff --git a/Medianno/en.lproj/MAMovie.xib b/Medianno/en.lproj/MAMovie.xib index cae23af..641713b 100644 --- a/Medianno/en.lproj/MAMovie.xib +++ b/Medianno/en.lproj/MAMovie.xib @@ -99,6 +99,7 @@ {{0, 0}, {2560, 1418}} {10000000000000, 10000000000000} + MAMoviePanel YES @@ -113,22 +114,6 @@ 5 - - - visible: showMovieInPanel - - - - - - visible: showMovieInPanel - visible - showMovieInPanel - 2 - - - 9 - panelMovieView @@ -137,6 +122,14 @@ 12 + + + delegate + + + + 13 + @@ -226,7 +219,7 @@ - 12 + 13 @@ -242,43 +235,26 @@ MAMovieWindow NSWindowController - - YES - - YES - mainMovieView - mainWindow - panelMovieView - - - YES - QTMovieView - NSWindow - QTMovieView + + toggleWindow: + id + + + toggleWindow: + + toggleWindow: + id + + panelMovieView + QTMovieView + - YES - - YES - mainMovieView - mainWindow - panelMovieView - - - YES - - mainMovieView - QTMovieView - - - mainWindow - NSWindow - - - panelMovieView - QTMovieView - + panelMovieView + + panelMovieView + QTMovieView diff --git a/Medianno/en.lproj/MainMenu.xib b/Medianno/en.lproj/MainMenu.xib index 767816e..2dec51c 100644 --- a/Medianno/en.lproj/MainMenu.xib +++ b/Medianno/en.lproj/MainMenu.xib @@ -30,7 +30,7 @@ YES - NSApplication + MAAppController FirstResponder @@ -945,6 +945,9 @@ MAAppController + + MAMovieWindow + @@ -981,14 +984,6 @@ 127 - - - orderFrontStandardAboutPanel: - - - - 142 - performClose: @@ -1373,14 +1368,6 @@ 582 - - - delegate - - - - 584 - exportMedia: @@ -1405,13 +1392,37 @@ 598 + + + moviePanel + + + + 607 + - toggleMoviePanel: - + orderFrontStandardAboutPanel: + + + + 608 + + + + delegate + + + + 609 + + + + toggleWindow: + - 601 + 610 @@ -2135,6 +2146,12 @@ + + 602 + + + Movie Panel + @@ -2235,6 +2252,7 @@ 593.IBPluginDependency 596.IBPluginDependency 600.IBPluginDependency + 602.IBPluginDependency 72.IBPluginDependency 73.IBPluginDependency 74.IBPluginDependency @@ -2354,6 +2372,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -2368,7 +2387,7 @@ - 601 + 610 @@ -2394,6 +2413,17 @@ MAAppController NSObject + + moviePanel + MAMovieWindow + + + moviePanel + + moviePanel + MAMovieWindow + + IBProjectSource ./Classes/MAAppController.h @@ -2558,14 +2588,25 @@ MAMovieWindow NSWindowController + + toggleWindow: + id + + + toggleWindow: + + toggleWindow: + id + + - mainMovieView + panelMovieView QTMovieView - mainMovieView + panelMovieView - mainMovieView + panelMovieView QTMovieView