diff --git a/baRSS/Preferences/Feeds Tab/ModalFeedEdit.m b/baRSS/Preferences/Feeds Tab/ModalFeedEdit.m index 8465c87..997fe86 100644 --- a/baRSS/Preferences/Feeds Tab/ModalFeedEdit.m +++ b/baRSS/Preferences/Feeds Tab/ModalFeedEdit.m @@ -33,7 +33,7 @@ #pragma mark - ModalEditDialog - -@interface ModalEditDialog() +@interface ModalEditDialog() @property (strong) FeedGroup *feedGroup; @property (strong) ModalSheet *modalSheet; @end @@ -47,8 +47,10 @@ } /// @return New @c ModalSheet with its subclass @c .view property as dialog content. - (ModalSheet *)getModalSheet { - if (!self.modalSheet) + if (!self.modalSheet) { self.modalSheet = [[ModalSheet alloc] initWithView:self.view]; + self.modalSheet.delegate = self; + } return self.modalSheet; } /// This method should be overridden by subclasses. Used to save changes to persistent store. @@ -297,6 +299,15 @@ #pragma mark - NSTextField Delegate +/// Window delegate will be only called on button 'Done'. +- (BOOL)windowShouldClose:(NSWindow *)sender { + if (![self.previousURL isEqualToString:self.url.stringValue]) { + [[NSNotificationCenter defaultCenter] postNotificationName:NSControlTextDidEndEditingNotification object:self.url]; + return NO; + } + return YES; +} + /// Whenever the user finished entering the url (return key or focus change) perform a download request. - (void)controlTextDidEndEditing:(NSNotification *)obj { if (obj.object == self.url) { diff --git a/baRSS/Preferences/ModalSheet.m b/baRSS/Preferences/ModalSheet.m index 6d54cf2..a65b3a5 100644 --- a/baRSS/Preferences/ModalSheet.m +++ b/baRSS/Preferences/ModalSheet.m @@ -24,6 +24,7 @@ @interface ModalSheet() @property (weak) NSButton *btnDone; +@property (assign) BOOL respondToShouldClose; @end @implementation ModalSheet @@ -36,12 +37,20 @@ /// Manually disable 'Done' button if a task is still running. - (void)setDoneEnabled:(BOOL)accept { self.btnDone.enabled = accept; } +- (void)setDelegate:(id)delegate { + [super setDelegate:delegate]; + self.respondToShouldClose = [delegate respondsToSelector:@selector(windowShouldClose:)]; +} + /** Called after user has clicked the 'Done' (Return) or 'Cancel' (Esc) button. Flags controller as being closed @c .closeInitiated @c = @c YES. And removes all subviews (clean up). */ - (void)closeWithResponse:(NSModalResponse)response { + if (response == NSModalResponseOK && self.respondToShouldClose && ![self.delegate windowShouldClose:self]) { + return; + } _didCloseAndSave = (response == NSModalResponseOK); _didCloseAndCancel = (response != NSModalResponseOK); // store modal view width and remove subviews to avoid _NSKeyboardFocusClipView issues