Skip to content

Commit

Permalink
Fix up issues with Add to Blocklist: remove duplicates and refresh do…
Browse files Browse the repository at this point in the history
…main list
  • Loading branch information
cstigler committed Apr 26, 2021
1 parent d6d13d5 commit 512bdf8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ - (void)handleConfigurationChangedNotification {
// let the domain list know!
if (domainListWindowController_ != nil) {
domainListWindowController_.readOnly = [SCUIUtilities blockIsRunning];
[domainListWindowController_ refreshDomainList];
}

// let the timer window know!
Expand Down Expand Up @@ -431,8 +432,11 @@ - (void)addToBlockList:(NSString*)host lock:(NSLock*)lock {
if (cleanedEntries.count == 0) return;

for (NSUInteger i = 0; i < cleanedEntries.count; i++) {
NSString* entry = cleanedEntries[i];
[list addObject: entry];
NSString* entry = cleanedEntries[i];
// don't add duplicate entries
if (![list containsObject: entry]) {
[list addObject: entry];
}
}

[defaults_ setValue: list forKey: @"Blocklist"];
Expand Down
2 changes: 2 additions & 0 deletions DomainListWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

@property (getter=isReadOnly) BOOL readOnly;

- (void)refreshDomainList;

// Called when the add button is clicked. Adds a new empty string to the domain
// list, reloads the table view, and highlights and opens that cell for editing.
- (IBAction)addDomain:(id)sender;
Expand Down
5 changes: 5 additions & 0 deletions DomainListWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ - (void)awakeFromNib {
[self updateWindowTitle];
}

- (void)refreshDomainList {
domainList_ = [[defaults_ arrayForKey: @"Blocklist"] mutableCopy];
[domainListTableView_ reloadData];
}

- (void)showWindow:(id)sender {
[[self window] makeKeyAndOrderFront: self];

Expand Down
1 change: 1 addition & 0 deletions TimerWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ - (IBAction) closeExtendSheet:(id)sender {
- (IBAction) performAddSite:(id)sender {
NSString* addToBlockTextFieldContents = [addToBlockTextField_ stringValue];
[self.appController addToBlockList: addToBlockTextFieldContents lock: modifyBlockLock];
addToBlockTextField_.stringValue = @""; // clear text field for next time
[NSApp endSheet: addSheet_];
}

Expand Down

0 comments on commit 512bdf8

Please sign in to comment.