Skip to content

Commit 94517dc

Browse files
committed
add a search field to the rom window.
1 parent 2efdcc2 commit 94517dc

2 files changed

Lines changed: 66 additions & 7 deletions

File tree

Ample/Base.lproj/DownloadWindow.xib

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<outlet property="downloadField" destination="sJz-So-jbA" id="WjK-48-FcE"/>
1414
<outlet property="formatButton" destination="2Rg-eX-DUq" id="oYo-MG-Sc6"/>
1515
<outlet property="missingFilterButton" destination="6c7-tU-3F3" id="89Y-wQ-9pB"/>
16+
<outlet property="searchFilter" destination="EuH-NO-RLR" id="ZtY-CC-pgz"/>
1617
<outlet property="tableView" destination="FLX-Wt-y53" id="a4O-pk-EAt"/>
1718
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
1819
</connections>
@@ -251,7 +252,6 @@
251252
<toolbar key="toolbar" implicitIdentifier="B60021E6-BFBC-44E6-97DC-120AA9FD3269" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconOnly" sizeMode="regular" id="kpz-W4-xgh">
252253
<allowedToolbarItems>
253254
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="tbY-ts-Irb"/>
254-
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="3Kc-zG-IdN"/>
255255
<toolbarItem implicitItemIdentifier="BD743A15-0B61-48FF-9EED-FD8D57EF8459" label="All" paletteLabel="All" tag="1" sizingBehavior="auto" id="Jj0-n8-I5a">
256256
<nil key="toolTip"/>
257257
<button key="view" verticalHuggingPriority="750" tag="1" id="Kgj-LP-FsF">
@@ -280,10 +280,28 @@
280280
</connections>
281281
</button>
282282
</toolbarItem>
283+
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="3Kc-zG-IdN"/>
284+
<toolbarItem implicitItemIdentifier="5FAD9453-A303-4057-A122-37BF870A4D81" label="Search" paletteLabel="Search" tag="3" sizingBehavior="auto" id="kT0-k4-f7d">
285+
<nil key="toolTip"/>
286+
<searchField key="view" wantsLayer="YES" verticalHuggingPriority="750" tag="3" textCompletion="NO" id="EuH-NO-RLR">
287+
<rect key="frame" x="0.0" y="14" width="96" height="22"/>
288+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
289+
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="6vV-pw-9Ej">
290+
<font key="font" metaFont="system"/>
291+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
292+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
293+
</searchFieldCell>
294+
<connections>
295+
<action selector="search:" target="-2" id="JsE-wh-qQV"/>
296+
</connections>
297+
</searchField>
298+
</toolbarItem>
283299
</allowedToolbarItems>
284300
<defaultToolbarItems>
285301
<toolbarItem reference="Jj0-n8-I5a"/>
286302
<toolbarItem reference="GV4-aX-5Ox"/>
303+
<toolbarItem reference="3Kc-zG-IdN"/>
304+
<toolbarItem reference="kT0-k4-f7d"/>
287305
</defaultToolbarItems>
288306
</toolbar>
289307
<connections>

Ample/DownloadWindowController.m

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ @interface DownloadWindowController ()
133133
/* filter buttons */
134134
@property (weak) IBOutlet NSButton *allFilterButton;
135135
@property (weak) IBOutlet NSButton *missingFilterButton;
136+
@property (weak) IBOutlet NSSearchField *searchFilter;
136137

137138
@property (strong) IBOutlet NSArrayController *arrayController;
138139

@@ -152,6 +153,11 @@ @implementation DownloadWindowController {
152153
NSUserDefaults *_defaults;
153154

154155
NSArray<NSButton *> *_filterButtons;
156+
157+
NSPredicate *_missingPredicate;
158+
NSPredicate *_searchPredicate;
159+
160+
155161
}
156162

157163
+(instancetype)sharedInstance {
@@ -519,30 +525,65 @@ - (IBAction)downloadExtensionChanged:(id)sender {
519525
}
520526

521527

528+
-(void)updatePredicate {
529+
if (!_missingPredicate && !_searchPredicate) {
530+
[_arrayController setFilterPredicate: nil];
531+
return;
532+
}
533+
if (_missingPredicate && !_searchPredicate) {
534+
[_arrayController setFilterPredicate: _missingPredicate];
535+
return;
536+
}
537+
if (_searchPredicate && !_missingPredicate) {
538+
[_arrayController setFilterPredicate: _searchPredicate];
539+
return;
540+
}
541+
NSCompoundPredicate *p = [NSCompoundPredicate andPredicateWithSubpredicates: @[ _missingPredicate, _searchPredicate]];
542+
[_arrayController setFilterPredicate: p];
543+
}
544+
522545
- (IBAction)filterButton:(id)sender {
523546

524-
NSPredicate *p = nil;
525547
NSUInteger tag = [sender tag];
526548
[sender setState: NSControlStateValueOn];
527549

528-
529550
for (NSButton *b in _filterButtons) {
530551
if (b != sender) [b setState: NSControlStateValueOff];
531552
}
532553
switch (tag) {
533554
case 1: // all
534555
default:
535-
[_arrayController setFilterPredicate: nil];
556+
_missingPredicate = nil;
536557
break;
537558
case 2: // missing.
538-
p = [NSPredicate predicateWithBlock: ^BOOL(DownloadItem *item, NSDictionary *bindings){
559+
_missingPredicate = [NSPredicate predicateWithBlock: ^BOOL(DownloadItem *item, NSDictionary *bindings){
539560
NSURL *localURL = [item localURL];
540561
return localURL == nil;
541562
}];
542563

543-
[_arrayController setFilterPredicate: p];
544-
break;
545564
}
565+
566+
[self updatePredicate];
567+
}
568+
- (IBAction)search:(id)sender {
569+
NSString *text = [sender stringValue];
570+
if (![text length]) {
571+
_searchPredicate = nil;
572+
} else {
573+
574+
text = [text lowercaseString];
575+
NSPredicate *p = [NSPredicate predicateWithBlock: ^(DownloadItem *item, NSDictionary *bindings){
576+
577+
NSString *value = [[item value] lowercaseString];
578+
NSString *name = [[item name] lowercaseString];
579+
580+
BOOL ok = [name containsString: text] || [value containsString: text];
581+
return ok;
582+
}];
583+
_searchPredicate = p;
584+
585+
}
586+
[self updatePredicate];
546587
}
547588

548589

0 commit comments

Comments
 (0)