Searchbar should work better with wrong selections

This commit is contained in:
michael starke
2014-09-01 19:06:36 +02:00
parent 16ae9739f2
commit 8ab4d9f787
4 changed files with 28 additions and 29 deletions

View File

@@ -103,7 +103,7 @@
</connections>
</button>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aPQ-t2-bgz">
<rect key="frame" x="493" y="5" width="63" height="19"/>
<rect key="frame" x="491" y="5" width="65" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="recessed" title="Item 1" bezelStyle="recessed" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="LRm-iZ-XrA" id="faz-pC-uGX">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>

View File

@@ -82,6 +82,7 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
[specialMenu addItemWithTitle:NSLocalizedString(@"SELECT_FILTER_WITH_DOTS", "") action:NULL keyEquivalent:@""];
[[specialMenu itemAtIndex:0] setEnabled:NO];
[[specialMenu itemAtIndex:0] setTag:MPEntrySearchNone];
[[specialMenu itemAtIndex:0] setAction:@selector(toggleSearchFlags:)];
for(NSInteger iIndex = 0; iIndex < [titles count]; iIndex++) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:titles[iIndex] action:@selector(toggleSearchFlags:) keyEquivalent:@""];
[item setTag:specialTags[iIndex]];

View File

@@ -70,7 +70,6 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
}
- (void)toggleSearchFlags:(id)sender {
static MPEntrySearchFlags oldFlags;
if(![sender respondsToSelector:@selector(tag)]) {
return; // We need to read the button tag
}
@@ -79,23 +78,21 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
}
MPEntrySearchFlags toggleFlag = [sender tag];
MPEntrySearchFlags newFlags = MPEntrySearchNone;
BOOL isDoublePasswordFlag = (toggleFlag == MPEntrySearchDoublePasswords);
BOOL isExpiredFlag = (toggleFlag == MPEntrySearchExpiredEntries);
BOOL isSingleFlag = toggleFlag & MPEntrySearchSingleFlags;
NSButton *button = sender;
switch([button state]) {
case NSOffState:
toggleFlag ^= MPEntrySearchAllFlags;
newFlags = isDoublePasswordFlag ? oldFlags : (self.searchContext.searchFlags & toggleFlag);
toggleFlag ^= MPEntrySearchAllCombineableFlags;
newFlags = isSingleFlag ? MPEntrySearchNone : (self.searchContext.searchFlags & toggleFlag);
break;
case NSOnState:
if(isDoublePasswordFlag || isExpiredFlag ) {
oldFlags = self.searchContext.searchFlags;
newFlags = toggleFlag;//MPEntrySearchDoublePasswords;
if(isSingleFlag ) {
newFlags = toggleFlag; // This has to be either expired or double passwords
}
else {
/* always mask the double passwords in case another button was pressed */
self.searchContext.searchFlags &= ((MPEntrySearchDoublePasswords | MPEntrySearchExpiredEntries) ^ MPEntrySearchAllFlags);
newFlags = self.searchContext.searchFlags | toggleFlag;
newFlags &= (MPEntrySearchSingleFlags ^ MPEntrySearchAllFlags);
}
break;
default:

View File

@@ -20,18 +20,19 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
They are not intented to be used in conjunktion with any other flag */
MPEntrySearchDoublePasswords = (1<<6),
MPEntrySearchExpiredEntries = (1<<7),
/* All search flags that are combineable combined */
MPEntrySearchAllFlags = (MPEntrySearchDoublePasswords |
/* All combinebale search flags combined */
MPEntrySearchAllCombineableFlags = (MPEntrySearchDoublePasswords |
MPEntrySearchExpiredEntries |
MPEntrySearchNotes |
MPEntrySearchPasswords |
MPEntrySearchTitles |
MPEntrySearchUrls |
MPEntrySearchUsernames |
MPEntrySearchAllAttributes )
MPEntrySearchAllAttributes),
MPEntrySearchSingleFlags = (MPEntrySearchDoublePasswords | MPEntrySearchExpiredEntries),
MPEntrySearchAllFlags = (MPEntrySearchAllCombineableFlags | MPEntrySearchSingleFlags )
};
/* Wrap serach criteria to be able to store them */
@interface MPEntrySearchContext : NSObject <NSSecureCoding,NSCopying>