Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix exporting Bundles not working (#2261)
  • Loading branch information
dmoagx committed Oct 2, 2015
1 parent b72ee56 commit cbb4494
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions Source/SPBundleEditorController.m
Expand Up @@ -36,8 +36,6 @@
#import "SPSplitView.h"
#import "SPAppController.h"

static NSString *SPSaveBundleAction = @"SPSaveBundle";

#define kBundleNameKey @"bundleName"
#define kChildrenKey @"_children_"
#define kInputFieldScopeArrayIndex 0
Expand Down Expand Up @@ -722,9 +720,47 @@ - (IBAction)saveBundle:(id)sender

[panel setNameFieldStringValue:[[self _currentSelectedObject] objectForKey:kBundleNameKey]];

[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger returnCode)
{
[self sheetDidEnd:panel returnCode:returnCode contextInfo:SPSaveBundleAction];
[panel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger returnCode) {
if (returnCode != NSOKButton) return;

// Panel is still on screen. Hide it first. (This is Apple's recommended way)
[panel orderOut:nil];

id aBundle = [self _currentSelectedObject];

NSString *bundleFileName = [aBundle objectForKey:kBundleNameKey];
NSString *possibleExisitingBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleFileName, SPUserBundleFileExtension];
NSAssert(possibleExisitingBundleFilePath != nil, @"source bundle path must be non-nil!");

NSString *savePath = [[panel URL] path];
NSAssert(savePath != nil, @"destination bundle path must be non-nil! (URL=%@)",[panel URL]);

BOOL isDir;
BOOL copyingWasSuccessful = YES;
NSError *err = nil;

// Copy possible existing bundle with content
if([[NSFileManager defaultManager] fileExistsAtPath:possibleExisitingBundleFilePath isDirectory:&isDir] && isDir) {
//FIXME This will fail if savePath exists, but the user already consented overwriting in the save panel. We should use trashItemAtURL:... once we are 10.8+
if(![[NSFileManager defaultManager] copyItemAtPath:possibleExisitingBundleFilePath toPath:savePath error:&err]) {
//if we have an NSError that will provide the nicest error message.
if(err) {
[[NSAlert alertWithError:err] runModal];
return;
}
NSLog(@"copy(%@ -> %@) failed!",possibleExisitingBundleFilePath,savePath);
copyingWasSuccessful = NO;
}
}

if(!copyingWasSuccessful || ![self saveBundle:aBundle atPath:savePath]) {
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:NSLocalizedString(@"Error while saving the Bundle.", @"Bundle Editor : Save-Bundle-Error : error dialog title")];
[alert addButtonWithTitle:NSLocalizedString(@"OK", @"Bundle Editor : Save-Bundle-Error : OK button")];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal]; //blocks
[alert release];
}
}];
}

Expand Down Expand Up @@ -1005,37 +1041,6 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt

}
}
else if([contextInfo isEqualToString:@"saveBundle"]) {
if (returnCode == NSOKButton) {

id aBundle = [self _currentSelectedObject];

NSString *bundleFileName = [aBundle objectForKey:kBundleNameKey];
NSString *possibleExisitingBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleFileName, SPUserBundleFileExtension];

NSString *savePath = [[sheet URL] path];

BOOL isDir;
BOOL copyingWasSuccessful = YES;

// Copy possible existing bundle with content
if([[NSFileManager defaultManager] fileExistsAtPath:possibleExisitingBundleFilePath isDirectory:&isDir] && isDir) {
if(![[NSFileManager defaultManager] copyItemAtPath:possibleExisitingBundleFilePath toPath:savePath error:nil])
copyingWasSuccessful = NO;
}

if(!copyingWasSuccessful || ![self saveBundle:aBundle atPath:savePath]) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while saving the Bundle.", @"Bundle Editor : Save-Bundle-Error : error dialog title")
defaultButton:NSLocalizedString(@"OK", @"Bundle Editor : Save-Bundle-Error : OK button")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@""];

[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
}
}
}
else if([contextInfo isEqualToString:@"undeleteSelectedDefaultBundles"]) {
if(returnCode == 1) {

Expand All @@ -1058,6 +1063,10 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt

}
}
else {
NSBeep();
NSLog(@"%s: unhandled case! (contextInfo=%p)",__func__,contextInfo);
}

}

Expand Down

0 comments on commit cbb4494

Please sign in to comment.