macosx: Use enum to distinguish different events for playlist / main window states
authorDavid Fuhrmann <david.fuhrmann@googlemail.com>
Sat, 23 Nov 2013 12:47:56 +0000 (13:47 +0100)
committerDavid Fuhrmann <david.fuhrmann@googlemail.com>
Sat, 23 Nov 2013 13:13:42 +0000 (14:13 +0100)
No functional change.

extras/package/macosx/Resources/English.lproj/MainWindow.xib
modules/gui/macosx/ControlsBar.h
modules/gui/macosx/ControlsBar.m
modules/gui/macosx/MainMenu.m
modules/gui/macosx/MainWindow.h
modules/gui/macosx/MainWindow.m
modules/gui/macosx/intf.m

index 90544a9..dfff966 100644 (file)
     </object>
     <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
       <bool key="EncodedWithXMLCoder">YES</bool>
+      <integer value="4756"/>
+      <integer value="4722"/>
       <integer value="4850"/>
       <integer value="5260"/>
-      <integer value="21"/>
-      <integer value="4722"/>
     </object>
     <object class="NSArray" key="IBDocument.PluginDependencies">
       <bool key="EncodedWithXMLCoder">YES</bool>
           </object>
           <int key="connectionID">4666</int>
         </object>
-        <object class="IBConnectionRecord">
-          <object class="IBActionConnection" key="connection">
-            <string key="label">togglePlaylist:</string>
-            <reference key="source" ref="498338108"/>
-            <reference key="destination" ref="955174811"/>
-          </object>
-          <int key="connectionID">4674</int>
-        </object>
         <object class="IBConnectionRecord">
           <object class="IBOutletConnection" key="connection">
             <string key="label">o_split_view</string>
           </object>
           <int key="connectionID">5603</int>
         </object>
+        <object class="IBConnectionRecord">
+          <object class="IBActionConnection" key="connection">
+            <string key="label">togglePlaylist:</string>
+            <reference key="source" ref="878580547"/>
+            <reference key="destination" ref="955174811"/>
+          </object>
+          <int key="connectionID">5604</int>
+        </object>
       </object>
       <object class="IBMutableOrderedSet" key="objectRecords">
         <object class="NSArray" key="orderedObjects">
         </object>
       </object>
       <nil key="sourceID"/>
-      <int key="maxID">5603</int>
+      <int key="maxID">5604</int>
     </object>
     <object class="IBClassDescriber" key="IBDocument.Classes">
       <object class="NSMutableArray" key="referencedPartialClassDescriptions">
               <string>dropzoneButtonAction:</string>
               <string>removePodcast:</string>
               <string>removePodcastWindowAction:</string>
-              <string>togglePlaylist:</string>
             </object>
             <object class="NSMutableArray" key="dict.values">
               <bool key="EncodedWithXMLCoder">YES</bool>
               <string>id</string>
               <string>id</string>
               <string>id</string>
-              <string>id</string>
             </object>
           </object>
           <object class="NSMutableDictionary" key="actionInfosByName">
               <string>dropzoneButtonAction:</string>
               <string>removePodcast:</string>
               <string>removePodcastWindowAction:</string>
-              <string>togglePlaylist:</string>
             </object>
             <object class="NSMutableArray" key="dict.values">
               <bool key="EncodedWithXMLCoder">YES</bool>
                 <string key="name">removePodcastWindowAction:</string>
                 <string key="candidateClassName">id</string>
               </object>
-              <object class="IBActionInfo">
-                <string key="name">togglePlaylist:</string>
-                <string key="candidateClassName">id</string>
-              </object>
             </object>
           </object>
           <object class="NSMutableDictionary" key="outlets">
               <string>repeat:</string>
               <string>shuffle:</string>
               <string>stop:</string>
+              <string>togglePlaylist:</string>
               <string>volumeAction:</string>
             </object>
             <object class="NSMutableArray" key="dict.values">
               <string>id</string>
               <string>id</string>
               <string>id</string>
+              <string>id</string>
             </object>
           </object>
           <object class="NSMutableDictionary" key="actionInfosByName">
               <string>repeat:</string>
               <string>shuffle:</string>
               <string>stop:</string>
+              <string>togglePlaylist:</string>
               <string>volumeAction:</string>
             </object>
             <object class="NSMutableArray" key="dict.values">
                 <string key="name">stop:</string>
                 <string key="candidateClassName">id</string>
               </object>
+              <object class="IBActionInfo">
+                <string key="name">togglePlaylist:</string>
+                <string key="candidateClassName">id</string>
+              </object>
               <object class="IBActionInfo">
                 <string key="name">volumeAction:</string>
                 <string key="candidateClassName">id</string>
index c0fd5a1..cf938bc 100644 (file)
 - (void)setShuffle;
 - (IBAction)shuffle:(id)sender;
 
+- (IBAction)togglePlaylist:(id)sender;
+
 - (void)toggleEffectsButton;
 - (void)toggleJumpButtons;
 - (void)togglePlaymodeButtons;
index 7750623..d595589 100644 (file)
@@ -1062,6 +1062,11 @@ else \
     [self setShuffle];
 }
 
+- (IBAction)togglePlaylist:(id)sender
+{
+    [[[VLCMain sharedInstance] mainWindow] changePlaylistState: psUserEvent];
+}
+
 - (IBAction)volumeAction:(id)sender
 {
     if (sender == o_volume_sld)
index 5ed377f..89042c9 100644 (file)
@@ -1128,7 +1128,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (IBAction)showPlaylist:(id)sender
 {
-    [[VLCMainWindow sharedInstance] togglePlaylist:sender];
+    [[VLCMainWindow sharedInstance] changePlaylistState: psUserMenuEvent];
 }
 
 #pragma mark -
index dedb580..d6d3bd0 100644 (file)
 @class VLCMainWindowControlsBar;
 @class VLCVoutView;
 
+typedef enum {
+    psUserEvent,
+    psUserMenuEvent,
+    psVideoStartedOrStoppedEvent,
+    psPlaylistItemChangedEvent
+} VLCPlaylistStateEvent;
+
 @interface VLCMainWindow : VLCVideoWindowCommon <PXSourceListDataSource, PXSourceListDelegate, NSWindowDelegate, NSAnimationDelegate, NSSplitViewDelegate> {
 
     IBOutlet id o_search_fld;
 
 - (VLCMainWindowControlsBar *)controlsBar;
 
-- (IBAction)togglePlaylist:(id)sender;
+- (void)changePlaylistState:(VLCPlaylistStateEvent)event;
 
 - (IBAction)dropzoneButtonAction:(id)sender;
 
index 5f8b3ac..ef8dd55 100644 (file)
@@ -476,55 +476,48 @@ static VLCMainWindow *_o_sharedInstance = nil;
         [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
 }
 
-// only exception for an controls bar button action
-- (IBAction)togglePlaylist:(id)sender
+
+- (void)changePlaylistState:(VLCPlaylistStateEvent)event
 {
     // Beware, this code is really ugly
 
-    /*
-     * sender can be:
-     * - nil if video playback is started or stopped
-     * - NSNumber with 1 if playlist item changes --> show video view
-     * - sender object if triggered through menu item or button
-     */
-    BOOL b_unhide_videoview = NO;
-    if([sender isKindOfClass: [NSNumber class]] && [sender intValue] == 1) {
-        b_unhide_videoview = YES;
-        sender = nil;
-    }
-
-    msg_Dbg(VLCIntf, "toggle playlist from state: removed splitview %i, minimized view %i. Sender is %p, unhide video view %i", b_splitview_removed, b_minimized_view, sender, b_unhide_videoview);
-    if (![self isVisible] && sender != nil) {
-        [self makeKeyAndOrderFront: sender];
+    msg_Dbg(VLCIntf, "toggle playlist from state: removed splitview %i, minimized view %i. Event %i", b_splitview_removed, b_minimized_view, event);
+    if (![self isVisible] && event == psUserMenuEvent) {
+        [self makeKeyAndOrderFront: nil];
         return;
     }
 
     BOOL b_activeVideo = [[VLCMain sharedInstance] activeVideoPlayback];
     BOOL b_restored = NO;
 
+    // ignore alt if triggered through main menu shortcut
     BOOL b_have_alt_key = ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0;
-    if (sender && [sender isKindOfClass: [NSMenuItem class]])
+    if (event == psUserMenuEvent)
         b_have_alt_key = NO;
 
+    // eUserMenuEvent is now handled same as eUserEvent
+    if(event == psUserMenuEvent)
+        event = psUserEvent;
+
     if (b_dropzone_active && b_have_alt_key) {
         [self hideDropZone];
         return;
     }
 
     if (!(b_nativeFullscreenMode && b_fullscreen) && !b_splitview_removed && ((b_have_alt_key && b_activeVideo)
-                                                                              || (b_nonembedded && sender != nil)
-                                                                              || (!b_activeVideo && sender != nil)
-                                                                              || (b_minimized_view && sender == nil && b_unhide_videoview == NO))) {
+                                                                              || (b_nonembedded && event == psUserEvent)
+                                                                              || (!b_activeVideo && event == psUserEvent)
+                                                                              || (b_minimized_view && event == psVideoStartedOrStoppedEvent))) {
         // for starting playback, window is resized through resized events
         // for stopping playback, resize through reset to previous frame
-        [self hideSplitView: sender != nil];
+        [self hideSplitView: event != psVideoStartedOrStoppedEvent];
         b_minimized_view = NO;
     } else {
         if (b_splitview_removed) {
-            if (!b_nonembedded || (sender != nil && b_nonembedded))
-                [self showSplitView: sender != nil || b_unhide_videoview];
+            if (!b_nonembedded || (event == psUserEvent && b_nonembedded))
+                [self showSplitView: event != psVideoStartedOrStoppedEvent];
 
-            if (sender == nil)
+            if (event != psUserEvent)
                 b_minimized_view = YES;
             else
                 b_minimized_view = NO;
@@ -534,7 +527,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
         }
 
         if (!b_nonembedded) {
-            if (([o_video_view isHidden] && b_activeVideo) || b_restored || (b_activeVideo && sender == nil))
+            if (([o_video_view isHidden] && b_activeVideo) || b_restored || (b_activeVideo && event != psUserEvent))
                 [self makeSplitViewHidden];
             else
                 [self makeSplitViewVisible];
@@ -815,6 +808,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
             [o_fspanel setNonActive: nil];
         }
     }
+
+    [self changePlaylistState: psVideoStartedOrStoppedEvent];
 }
 
 #pragma mark -
index 96655ee..4a5f732 100644 (file)
@@ -1268,7 +1268,7 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 #pragma mark -
 #pragma mark Interface updaters
-
+// This must be called on main thread
 - (void)PlaylistItemChanged
 {
     if (p_current_input && (p_current_input->b_dead || !vlc_object_alive(p_current_input))) {
@@ -1287,7 +1287,7 @@ static VLCMain *_o_sharedMainInstance = nil;
             [o_mainmenu setRateControlsEnabled: YES];
 
             if ([self activeVideoPlayback] && [[o_mainwindow videoView] isHidden]) {
-                [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject: [NSNumber numberWithInt:1] waitUntilDone:NO];
+                [o_mainwindow changePlaylistState: psPlaylistItemChangedEvent];
             }
 
             p_input_changed = vlc_object_hold(p_current_input);
@@ -1538,7 +1538,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     b_active_videoplayback = b_value;
     if (o_mainwindow) {
         [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
-        [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
     }
 
     // update sleep blockers