From d89cd601d19d87691f621016035ba38ce9f1bd5a Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 15 Nov 2010 00:25:18 +0000 Subject: [PATCH] #3742 entering a blocklist URL should register while typing (and support undo) - boo for glue code replacing bindings! --- macosx/PrefsController.h | 3 + macosx/PrefsController.m | 36 ++++++++++-- macosx/en.lproj/PrefsWindow.xib | 99 ++++++--------------------------- 3 files changed, 50 insertions(+), 88 deletions(-) diff --git a/macosx/PrefsController.h b/macosx/PrefsController.h index c90ff74e5..ce20956a2 100644 --- a/macosx/PrefsController.h +++ b/macosx/PrefsController.h @@ -45,6 +45,7 @@ IBOutlet NSTextField * fPeersGlobalField, * fPeersTorrentField, * fBlocklistURLField, * fBlocklistMessageField, * fBlocklistDateField; + IBOutlet NSButton * fBlocklistButton; PortChecker * fPortChecker; IBOutlet NSTextField * fPortField, * fPortStatusField; @@ -90,6 +91,8 @@ - (void) updateBlocklist: (id) sender; - (void) setBlocklistAutoUpdate: (id) sender; - (void) updateBlocklistFields; +- (void) updateBlocklistURLField; +- (void) updateBlocklistButton; - (void) setAutoStartDownloads: (id) sender; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 90cb9df3d..eee30be58 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -215,10 +215,19 @@ tr_session * fHandle; [fStalledField setIntValue: [fDefaults integerForKey: @"StalledMinutes"]]; //set blocklist + NSString * blocklistURL = [fDefaults stringForKey: @"BlocklistURL"]; + if (blocklistURL) + [fBlocklistURLField setStringValue: blocklistURL]; + + [self updateBlocklistButton]; [self updateBlocklistFields]; + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateBlocklistFields) name: @"BlocklistUpdated" object: nil]; + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateBlocklistURLField) + name: NSControlTextDidChangeNotification object: fBlocklistURLField]; + //set rpc port [fRPCPortField setIntValue: [fDefaults integerForKey: @"RPCPort"]]; @@ -480,11 +489,8 @@ tr_session * fHandle; tr_blocklistSetEnabled(fHandle, [fDefaults boolForKey: @"BlocklistNew"]); [[BlocklistScheduler scheduler] updateSchedule]; -} - -- (void) setBlocklistURL: (id) sender -{ - tr_blocklistSetURL(fHandle, [[fDefaults stringForKey: @"BlocklistURL"] UTF8String]); + + [self updateBlocklistButton]; } - (void) updateBlocklist: (id) sender @@ -541,6 +547,24 @@ tr_session * fHandle; NSLocalizedString(@"Last updated", "Prefs -> blocklist -> message"), updatedDateString]]; } +- (void) updateBlocklistURLField +{ + NSString * blocklistString = [fBlocklistURLField stringValue]; + + [fDefaults setObject: blocklistString forKey: @"BlocklistURL"]; + tr_blocklistSetURL(fHandle, [blocklistString UTF8String]); + + [self updateBlocklistButton]; +} + +- (void) updateBlocklistButton +{ + NSString * blocklistString = [fDefaults objectForKey: @"BlocklistURL"]; + const BOOL enable = (blocklistString && ![blocklistString isEqualToString: @""]) + && [fDefaults boolForKey: @"BlocklistNew"]; + [fBlocklistButton setEnabled: enable]; +} + - (void) setAutoStartDownloads: (id) sender { tr_sessionSetPaused(fHandle, ![fDefaults boolForKey: @"AutoStartDownload"]); @@ -1159,6 +1183,8 @@ tr_session * fHandle; //speed limit schedule times and day handled by bindings + [fBlocklistURLField setStringValue: blocklistURL]; + [self updateBlocklistButton]; [self updateBlocklistFields]; //ratio limit enabled handled by bindings diff --git a/macosx/en.lproj/PrefsWindow.xib b/macosx/en.lproj/PrefsWindow.xib index b1028e16a..a135bebaa 100644 --- a/macosx/en.lproj/PrefsWindow.xib +++ b/macosx/en.lproj/PrefsWindow.xib @@ -13,7 +13,6 @@ YES - YES @@ -434,7 +433,7 @@ NSResponder - + 256 YES @@ -1744,7 +1743,6 @@ {542, 331} - NSView NSResponder @@ -3082,7 +3080,7 @@ AAABAAAAAQ YES -1804468671 - 272634880 + 272630784 @@ -4225,6 +4223,7 @@ AAABAAAAAQ {{1, 1}, {291, 76}} + 4 @@ -4251,6 +4250,7 @@ AAABAAAAAQ {{103, 96}, {308, 78}} + 18 @@ -4369,12 +4369,6 @@ AAABAAAAAQ NSResponder - - YES - BlocklistNew - BlocklistNew.length - BlocklistURL - YES @@ -7327,22 +7321,6 @@ AAABAAAAAQ 1989 - - - enabled: values.BlocklistNew - - - - - - enabled: values.BlocklistNew - enabled - values.BlocklistNew - 2 - - - 1990 - enabled: values.BlocklistNew @@ -7400,64 +7378,12 @@ AAABAAAAAQ 1994 - - setBlocklistURL: + + fBlocklistButton - + - 1995 - - - - value: values.BlocklistURL - - - - - - value: values.BlocklistURL - value - values.BlocklistURL - 2 - - - 1996 - - - - enabled2: values.BlocklistURL - - - - - - enabled2: values.BlocklistURL - enabled2 - values.BlocklistURL - - YES - - YES - NSMultipleValuesPlaceholder - NSNoSelectionPlaceholder - NSNotApplicablePlaceholder - NSNullPlaceholder - NSValueTransformerName - - - YES - - - - - NSIsNotNil - - - - 2 - - - 2026 + 2031 @@ -11314,7 +11240,7 @@ AAABAAAAAQ - 2026 + 2031 @@ -11962,6 +11888,7 @@ AAABAAAAAQ YES fAutoSpeedDayTypePopUp fBandwidthView + fBlocklistButton fBlocklistDateField fBlocklistMessageField fBlocklistURLField @@ -11999,6 +11926,7 @@ AAABAAAAAQ YES NSPopUpButton NSView + NSButton NSTextField NSTextField NSTextField @@ -12039,6 +11967,7 @@ AAABAAAAAQ YES fAutoSpeedDayTypePopUp fBandwidthView + fBlocklistButton fBlocklistDateField fBlocklistMessageField fBlocklistURLField @@ -12082,6 +12011,10 @@ AAABAAAAAQ fBandwidthView NSView + + fBlocklistButton + NSButton + fBlocklistDateField NSTextField