Permalink
Browse files

there were some issues with asking the user on a dirty document to sa…

…ve it

most of the time it wasn't asking until you quit the app

this change now asks the user on closing a dirty tab if he wants to save, discard changes and close anyway or leave the tab open and handles the response properly.
  • Loading branch information...
1 parent af00f25 commit d1b1e5611a52b5e103cec7ca298bf9107df330b2 @schubter committed May 23, 2011
Showing with 21 additions and 10 deletions.
  1. +21 −10 src/KBrowser.mm
View
@@ -52,15 +52,7 @@ - (CTTabContents*)addTabContents:(CTTabContents*)tab
// Overriding CTBrowser's -closeTab in order to check if the document is
// dirty or not before closing.
- (void)closeTab {
- KDocument *doc = (KDocument *)[self tabContentsAtIndex:[self selectedTabIndex]];
-
- if ([doc isDirty]) {
- [doc canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(document:shouldClose:contextInfo:) contextInfo:nil];
- } else {
- shouldCloseTab = YES;
- [super closeTab];
- }
-
+ shouldCloseTab = NO;
}
@@ -69,7 +61,10 @@ - (void)document:(NSDocument *)tab
shouldClose:(BOOL)shouldClose
contextInfo:(void*)contextInfo {
shouldCloseTab = shouldClose;
- [super closeTab];
+
+ if ( shouldClose ) {
+ [super closeTab];
+ }
}
@@ -78,6 +73,22 @@ - (BOOL)canCloseTab {
return shouldCloseTab;
}
+- (BOOL)canCloseContentsAt:(int)index {
+ if ( shouldCloseTab == YES ) {
+ return shouldCloseTab;
+ }
+
+ KDocument *doc = (KDocument *)[self tabContentsAtIndex:index];
+
+ if ([doc isDirty]) {
+ [doc canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(document:shouldClose:contextInfo:) contextInfo:nil];
+ } else {
+ shouldCloseTab = YES;
+ }
+
+ return shouldCloseTab;
+}
+
/*-(void)updateTabStateForContent:(CTTabContents*)contents {
DLOG("updateTabStateForContent:%@", contents);

0 comments on commit d1b1e56

Please sign in to comment.