From 4c107644b4376b5d1f4a59eb73fcde014f9870c7 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 5 Feb 2014 21:16:37 +0100 Subject: [PATCH] Work in progress on drop-down filter selection --- MacPass/ContextBar.xib | 7 +++++-- MacPass/MPContextBarViewController.m | 26 +++++++++++++++++++++++--- MacPass/en.lproj/Localizable.strings | Bin 8000 -> 8094 bytes 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/MacPass/ContextBar.xib b/MacPass/ContextBar.xib index 78855d74..90f4d2d1 100644 --- a/MacPass/ContextBar.xib +++ b/MacPass/ContextBar.xib @@ -70,8 +70,8 @@ - - + + @@ -86,7 +86,10 @@ + + + diff --git a/MacPass/MPContextBarViewController.m b/MacPass/MPContextBarViewController.m index f8120032..fb5253ba 100644 --- a/MacPass/MPContextBarViewController.m +++ b/MacPass/MPContextBarViewController.m @@ -13,12 +13,15 @@ #import "NSButton+HNHTextColor.h" +NSUInteger const MPContextBarViewControllerActiveFilterMenuItemTag = 1000; + typedef NS_ENUM(NSUInteger, MPContextTab) { MPContextTabFilter, MPContextTabTrash, MPContextTabHistory }; + @interface MPContextBarViewController () { @private BOOL _delegateRespondsToDidChangeFilter; @@ -232,6 +235,11 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { - (NSMenu *)_allocFilterMenu { NSMenu *searchMenu = [[NSMenu alloc] init]; + + NSMenuItem *activeFilterItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SEARCH_IN", "") action:NULL keyEquivalent:@""]; + [activeFilterItem setTag:MPContextBarViewControllerActiveFilterMenuItemTag]; + [searchMenu addItem:activeFilterItem]; + [searchMenu addItem:[NSMenuItem separatorItem]]; NSArray *titles = @[NSLocalizedString(@"TITLE", ""), NSLocalizedString(@"PASSWORD", ""), @@ -251,7 +259,7 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { } [searchMenu addItem:[NSMenuItem separatorItem]]; /* Special Search */ - NSMenuItem *doublePasswordsItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"", "") action:NULL keyEquivalent:@""]; + NSMenuItem *doublePasswordsItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DUPLICTE_PASSWORDS", "") action:NULL keyEquivalent:@""]; [doublePasswordsItem setTag:MPFilterDoublePasswords]; [searchMenu addItem:doublePasswordsItem]; @@ -264,9 +272,21 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { NSArray *allItems = [menu itemArray]; NSArray *enabledItems = [self _filterItemsForMode:self.filterMode]; for(NSMenuItem *item in allItems) { - BOOL isEnabeld = [enabledItems containsObject:item]; - [item setEnabled:isEnabeld]; + BOOL isSelected = [enabledItems containsObject:item]; + [item setState:(isSelected ? NSOnState : NSOffState)]; } + NSMenuItem *activeFilterItem = [menu itemWithTag:MPContextBarViewControllerActiveFilterMenuItemTag]; + __block NSMutableString *activeFilterTitle; + [enabledItems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + if(activeFilterTitle == nil) { + activeFilterTitle = [[NSMutableString alloc] initWithString:[obj title]]; + } + else { + [activeFilterTitle appendFormat:@", %@", [obj title]]; + } + }]; + [activeFilterItem setTitle:activeFilterTitle]; + [self.filterTypePopupButton selectItem:activeFilterItem]; } - (NSArray *)_filterItemsForMode:(MPFilterMode)mode { diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index 76b1f7ef38b1dfd798c67b159e91c941d7ef6e80..0b198700b4576d8a699731d5274d7c7f8ea55976 100644 GIT binary patch delta 70 zcmX?LH_v{95uczEg9}3_LjZ#hgC~PCLkNTGWJL~P*