From 9083ca82064be42791191801ac748b170f7cccff Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Tue, 23 Apr 2013 18:57:25 +0700 Subject: [PATCH] Close bundle install sheet on error Previously incase of error the sheet would keep showing effectively locking up the document window. This is related to issue #85 although the reason why installing bundles fails for some users is still unanswered. --- .../DocumentWindow/src/FileTypeDialog.mm | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/Frameworks/DocumentWindow/src/FileTypeDialog.mm b/Frameworks/DocumentWindow/src/FileTypeDialog.mm index cd21ce78..a1398633 100644 --- a/Frameworks/DocumentWindow/src/FileTypeDialog.mm +++ b/Frameworks/DocumentWindow/src/FileTypeDialog.mm @@ -205,15 +205,22 @@ static bool is_installed (oak::uuid_t const& uuid) { if(bundleUUID == (*bundle)->uuid()) { - [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkIfBundleIsInstalled:) userInfo:[grammar objectForKey:@"uuid"] repeats:YES]; - [[BundlesManager sharedInstance] installBundle:*bundle completionHandler:nil]; [installingBundleActivityTextField bind:NSValueBinding toObject:[BundlesManager sharedInstance] withKeyPath:@"activityText" options:nil]; [installingBundleProgressIndicator bind:NSValueBinding toObject:[BundlesManager sharedInstance] withKeyPath:@"progress" options:nil]; [installingBundleProgressIndicator bind:NSIsIndeterminateBinding toObject:[BundlesManager sharedInstance] withKeyPath:@"determinateProgress" options:@{ NSValueTransformerNameBindingOption: @"NSNegateBoolean" }]; [installingBundleProgressIndicator startAnimation:self]; - OakShowSheetForWindow(installingBundleWindow, aWindow, ^(NSInteger returnCode){ - aCompletionHandler(self.fileType); - }); + + OakShowSheetForWindow(installingBundleWindow, aWindow, ^(NSInteger returnCode){ }); + + [[BundlesManager sharedInstance] installBundle:*bundle completionHandler:^(BOOL success){ + [installingBundleProgressIndicator stopAnimation:self]; + [installingBundleProgressIndicator unbind:NSValueBinding]; + [installingBundleActivityTextField unbind:NSValueBinding]; + [NSApp endSheet:installingBundleWindow]; + [installingBundleWindow orderOut:self]; + + aCompletionHandler(is_installed(uuid) ? self.fileType : @"text.plain"); + }]; return; } } @@ -222,21 +229,6 @@ static bool is_installed (oak::uuid_t const& uuid) }); } -- (void)checkIfBundleIsInstalled:(NSTimer*)aTimer -{ - NSString* uuid = [aTimer userInfo]; - if(is_installed(to_s(uuid))) - { - [aTimer invalidate]; - - [installingBundleProgressIndicator stopAnimation:self]; - [installingBundleProgressIndicator unbind:NSValueBinding]; - [installingBundleActivityTextField unbind:NSValueBinding]; - [NSApp endSheet:installingBundleWindow]; - [installingBundleWindow orderOut:self]; - } -} - - (IBAction)performOpenDocument:(id)sender { [self.window orderOut:self];