From f7cab515f4f116eebc18492bddaeb616b692da03 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 30 Jan 2012 00:14:43 +0000 Subject: [PATCH] Sort the Sort menu items on launch, since the main menu is now localized through a strings file. --- macosx/Controller.h | 2 ++ macosx/Controller.m | 25 +++++++++++++++++++++++++ macosx/en.lproj/MainMenu.xib | 10 +++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index 682606f91..273bad030 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -79,6 +79,8 @@ typedef enum IBOutlet NSMenuItem * fNextInfoTabItem, * fPrevInfoTabItem; + IBOutlet NSMenu * fSortMenu; + IBOutlet NSMenu * fActionMenu; IBOutlet NSMenu * fUploadMenu, * fDownloadMenu; diff --git a/macosx/Controller.m b/macosx/Controller.m index 4cb4c27e7..3f86261f5 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -403,6 +403,31 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [fTableView registerForDraggedTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE]]; [fWindow registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, NSURLPboardType, nil]]; + //sort the sort menu items (localization is from strings file) + NSMutableArray * sortMenuItems = [NSMutableArray arrayWithCapacity: 7]; + NSUInteger sortMenuIndex = 0; + BOOL foundSortItem = NO; + for (NSMenuItem * item in [fSortMenu itemArray]) + { + if ([item action] == @selector(setSort:) && [item tag] != SORT_ORDER_TAG) + { + [sortMenuItems addObject: item]; + [fSortMenu removeItemAtIndex: sortMenuIndex]; + foundSortItem = YES; + } + else + { + if (foundSortItem) + break; + ++sortMenuIndex; + } + } + + [sortMenuItems sortUsingDescriptors: [NSArray arrayWithObject: [NSSortDescriptor sortDescriptorWithKey: @"title" ascending: YES selector: @selector(localizedCompare:)]]]; + + for (NSMenuItem * item in sortMenuItems) + [fSortMenu insertItem: item atIndex: sortMenuIndex++]; + //you would think this would be called later in this method from updateUI, but it's not reached in awakeFromNib //this must be called after showStatusBar: [fStatusBar updateWithDownload: 0.0 upload: 0.0]; diff --git a/macosx/en.lproj/MainMenu.xib b/macosx/en.lproj/MainMenu.xib index fc35f199e..3626d713c 100644 --- a/macosx/en.lproj/MainMenu.xib +++ b/macosx/en.lproj/MainMenu.xib @@ -148,7 +148,6 @@ {{118, 5}, {279, 14}} - YES 67239488 @@ -194,7 +193,7 @@ {515, 224} - + YES @@ -667,7 +666,7 @@ AAAAAAAAAAA {{0, 24}, {515, 224}} - + 133648 @@ -5731,6 +5730,7 @@ AAAAAAAAAAA NSMenuItem NSMenuItem NSMenu + NSMenu NSButton TorrentTableView NSTextField @@ -5800,6 +5800,10 @@ AAAAAAAAAAA fRatioStopMenu NSMenu + + fSortMenu + NSMenu + fSpeedLimitButton NSButton -- 2.40.0