[vlc-commits] macosx: fix and slightly optimize (on 10.6+) the open recent menu ( fixes #5538)

Felix Paul Kühne git at videolan.org
Tue Dec 20 00:33:20 CET 2011


vlc/vlc-1.2 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Tue Dec 20 00:24:36 2011 +0100| [f4aba3c9f79ee49f9ba2cda27d516e49cb5a5eae] | committer: Jean-Baptiste Kempf

macosx: fix and slightly optimize (on 10.6+) the open recent menu (fixes #5538)
(cherry picked from commit e316b5a5c135120dcebf9f7e2cff2d8d5b1308ca)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.2.git/?a=commit;h=f4aba3c9f79ee49f9ba2cda27d516e49cb5a5eae
---

 .../macosx/Resources/English.lproj/MainMenu.xib    |   13 ++++++++--
 modules/gui/macosx/CompatibilityFixes.h            |    4 +++
 modules/gui/macosx/MainMenu.h                      |    2 +-
 modules/gui/macosx/MainMenu.m                      |   24 +++++++++++++------
 4 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.xib b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
index e2aed54..2cb0da1 100644
--- a/extras/package/macosx/Resources/English.lproj/MainMenu.xib
+++ b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
@@ -26,7 +26,7 @@
       <integer value="2730"/>
       <integer value="915"/>
       <integer value="1617"/>
-      <integer value="235"/>
+      <integer value="569"/>
       <integer value="4596"/>
       <integer value="21"/>
     </object>
@@ -11439,7 +11439,7 @@ LCAuLi4</string>
           <boolean value="YES"/>
           <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
           <boolean value="YES"/>
-          <string>{{1004, 603}, {143, 23}}</string>
+          <string>{{684, 529}, {143, 23}}</string>
           <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
           <boolean value="YES"/>
           <string>{{385, 503}, {267, 233}}</string>
@@ -11455,7 +11455,7 @@ LCAuLi4</string>
           <boolean value="YES"/>
           <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
           <boolean value="YES"/>
-          <string>{{388, 425}, {297, 243}}</string>
+          <string>{{387, 419}, {297, 243}}</string>
           <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
           <boolean value="YES"/>
           <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -14787,6 +14787,7 @@ LCAuLi4</string>
               <string>openDonate:</string>
               <string>openForum:</string>
               <string>openReadMe:</string>
+              <string>openRecentItem:</string>
               <string>openWebsite:</string>
               <string>resizeVideoWindow:</string>
               <string>setPlaybackRate:</string>
@@ -14836,6 +14837,7 @@ LCAuLi4</string>
               <string>id</string>
               <string>id</string>
               <string>id</string>
+              <string>id</string>
             </object>
           </object>
           <object class="NSMutableDictionary" key="actionInfosByName">
@@ -14854,6 +14856,7 @@ LCAuLi4</string>
               <string>openDonate:</string>
               <string>openForum:</string>
               <string>openReadMe:</string>
+              <string>openRecentItem:</string>
               <string>openWebsite:</string>
               <string>resizeVideoWindow:</string>
               <string>setPlaybackRate:</string>
@@ -14923,6 +14926,10 @@ LCAuLi4</string>
                 <string key="candidateClassName">id</string>
               </object>
               <object class="IBActionInfo">
+                <string key="name">openRecentItem:</string>
+                <string key="candidateClassName">id</string>
+              </object>
+              <object class="IBActionInfo">
                 <string key="name">openWebsite:</string>
                 <string key="candidateClassName">id</string>
               </object>
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index 980978d..0ddd517 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -61,6 +61,10 @@ enum {
 extern OSErr UpdateSystemActivity(UInt8 activity);
 #define UsrActivity 1
 #endif
+
+ at interface NSMenu (IntroducedInSnowLeopard)
+- (void)removeAllItems;
+ at end
 #endif
 
 #pragma mark -
diff --git a/modules/gui/macosx/MainMenu.h b/modules/gui/macosx/MainMenu.h
index 3f1f4f5..fc6771e 100644
--- a/modules/gui/macosx/MainMenu.h
+++ b/modules/gui/macosx/MainMenu.h
@@ -199,7 +199,7 @@
 - (void)setRateControlsEnabled:(BOOL)b_enabled;
 
 - (IBAction)clearRecentItems:(id)sender;
-- (void)openRecentItem:(id)item;
+- (IBAction)openRecentItem:(id)item;
 
 - (IBAction)intfOpenFile:(id)sender;
 - (IBAction)intfOpenFileGeneric:(id)sender;
diff --git a/modules/gui/macosx/MainMenu.m b/modules/gui/macosx/MainMenu.m
index 4cddd14..2ef270e 100644
--- a/modules/gui/macosx/MainMenu.m
+++ b/modules/gui/macosx/MainMenu.m
@@ -538,15 +538,14 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 #pragma mark -
 #pragma mark Recent Items
-- (void)openRecentItem:(id)item
+- (IBAction)openRecentItem:(id)item
 {
     [[VLCMain sharedInstance] application: nil openFile: [item title]];
 }
 
 - (IBAction)clearRecentItems:(id)sender
 {
-    [[NSDocumentController sharedDocumentController]
-     clearRecentDocuments: nil];
+    [[NSDocumentController sharedDocumentController] clearRecentDocuments: nil];
 }
 
 #pragma mark -
@@ -1107,15 +1106,22 @@ static VLCMainMenu *_o_sharedInstance = nil;
     {
         NSMenu * o_menu = [o_mi_open_recent submenu];
         int i_nb_items = [o_menu numberOfItems];
-        NSArray * o_docs = [[NSDocumentController sharedDocumentController]
-                            recentDocumentURLs];
+        NSArray * o_docs = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
         UInt32 i_nb_docs = [o_docs count];
 
         if( i_nb_items > 1 )
         {
-            while( --i_nb_items )
+            if (OSX_LEOPARD)
             {
-                [o_menu removeItemAtIndex: 0];
+                while( --i_nb_items )
+                {
+                    [o_menu removeItemAtIndex: 0];
+                }
+            }
+            else
+            {
+                // this is more efficient than removing the items one by one
+                [o_menu removeAllItems];
             }
         }
 
@@ -1123,6 +1129,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
         {
             NSURL * o_url;
             NSString * o_doc;
+            NSMenuItem *o_menuitem;
 
             [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
 
@@ -1137,9 +1144,10 @@ static VLCMainMenu *_o_sharedInstance = nil;
                 else
                     o_doc = [o_url absoluteString];
 
-                [o_menu insertItemWithTitle: o_doc
+                o_menuitem = [o_menu insertItemWithTitle: o_doc
                                      action: @selector(openRecentItem:)
                               keyEquivalent: @"" atIndex: 0];
+                [o_menuitem setTarget: self];
 
                 if( i_nb_docs == 0 )
                     break;



More information about the vlc-commits mailing list