From cdb75619cab8879da567cc801ebda0aefa8b4eb0 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Tue, 23 Apr 2013 18:51:16 +0700 Subject: [PATCH] Add completion callback to installBundle: --- Frameworks/BundlesManager/src/BundlesManager.h | 2 +- Frameworks/BundlesManager/src/BundlesManager.mm | 12 ++++++++++-- Frameworks/DocumentWindow/src/FileTypeDialog.mm | 2 +- Frameworks/Preferences/src/BundlesPreferences.mm | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Frameworks/BundlesManager/src/BundlesManager.h b/Frameworks/BundlesManager/src/BundlesManager.h index d2b38c5b..f355af6b 100644 --- a/Frameworks/BundlesManager/src/BundlesManager.h +++ b/Frameworks/BundlesManager/src/BundlesManager.h @@ -18,7 +18,7 @@ PUBLIC @interface BundlesManager : NSObject - (bundles_db::bundle_ptr const&)bundleAtIndex:(NSUInteger)anIndex; - (NSCellStateValue)installStateForBundle:(bundles_db::bundle_ptr const&)aBundle; -- (void)installBundle:(bundles_db::bundle_ptr const&)aBundle; +- (void)installBundle:(bundles_db::bundle_ptr const&)aBundle completionHandler:(void(^)(BOOL))callback; - (void)uninstallBundle:(bundles_db::bundle_ptr const&)aBundle; + (BundlesManager*)sharedInstance; diff --git a/Frameworks/BundlesManager/src/BundlesManager.mm b/Frameworks/BundlesManager/src/BundlesManager.mm index 0f330eea..183d2681 100644 --- a/Frameworks/BundlesManager/src/BundlesManager.mm +++ b/Frameworks/BundlesManager/src/BundlesManager.mm @@ -266,7 +266,7 @@ static double const kPollInterval = 3*60*60; }); } -- (void)installBundle:(bundles_db::bundle_ptr const&)aBundle +- (void)installBundle:(bundles_db::bundle_ptr const&)aBundle completionHandler:(void(^)(BOOL))callback { std::vector bundles; for(auto bundle : bundles_db::dependencies(bundlesIndex, aBundle, true, false)) @@ -284,6 +284,11 @@ static double const kPollInterval = 3*60*60; [self installBundles:bundles completionHandler:^(std::vector failedBundles){ self.activityText = [NSString stringWithFormat:@"Installed ‘%@’.", bundleName]; self.isBusy = NO; + if(callback) + { + [self createBundlesIndex:self]; + callback(failedBundles.empty()); + } }]; } @@ -321,7 +326,9 @@ static double const kPollInterval = 3*60*60; - (void)createBundlesIndex:(id)sender { - D(DBF_BundlesManager, bug("\n");); + D(DBF_BundlesManager, bug("%s\n", BSTR(_needsCreateBundlesIndex));); + if(_needsCreateBundlesIndex == NO) + return; auto pair = create_bundle_index(bundlesPaths, cache); bundles::set_index(pair.first, pair.second); @@ -465,6 +472,7 @@ namespace bundlesPaths.push_back(path::join(path, "Bundles")); bundlesIndexPath = path::join(path::home(), "Library/Caches/com.macromates.TextMate/BundlesIndex.plist"); cache.load(bundlesIndexPath, &prune_dictionary); + _needsCreateBundlesIndex = YES; [self createBundlesIndex:self]; } @end diff --git a/Frameworks/DocumentWindow/src/FileTypeDialog.mm b/Frameworks/DocumentWindow/src/FileTypeDialog.mm index 8a84a2c6..cd21ce78 100644 --- a/Frameworks/DocumentWindow/src/FileTypeDialog.mm +++ b/Frameworks/DocumentWindow/src/FileTypeDialog.mm @@ -206,7 +206,7 @@ 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]; + [[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" }]; diff --git a/Frameworks/Preferences/src/BundlesPreferences.mm b/Frameworks/Preferences/src/BundlesPreferences.mm index 94e01614..5f8869cf 100644 --- a/Frameworks/Preferences/src/BundlesPreferences.mm +++ b/Frameworks/Preferences/src/BundlesPreferences.mm @@ -199,7 +199,7 @@ static std::string textify (std::string str) { bundles_db::bundle_ptr bundle = bundles[rowIndex]; if([anObject boolValue]) - [_bundlesManager installBundle:bundle]; + [_bundlesManager installBundle:bundle completionHandler:nil]; else [_bundlesManager uninstallBundle:bundle]; } }