Add completion callback to installBundle:

This commit is contained in:
Allan Odgaard
2013-04-23 18:51:16 +07:00
parent 93a1c37e47
commit cdb75619ca
4 changed files with 13 additions and 5 deletions

View File

@@ -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;

View File

@@ -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_db::bundle_ptr> 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<bundles_db::bundle_ptr> 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

View File

@@ -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" }];

View File

@@ -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];
}
}