summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2020-01-27 12:34:02 +0100
committerDamiano Galassi <[email protected]>2020-01-27 12:34:02 +0100
commit198ff63d6e0fcf8473c4d03085311c954d9a5cec (patch)
tree6180942476e56ae88bd5b2e186a55c83745d6f4d
parent81f919fadfb0eec4f243f75dca7287c7e95b9f25 (diff)
MacGui: ask the user only for the destination folder when exporting multiple presets.
-rw-r--r--macosx/HBController.m3
-rw-r--r--macosx/HBPresetsViewController.m67
2 files changed, 58 insertions, 12 deletions
diff --git a/macosx/HBController.m b/macosx/HBController.m
index cbbe99302..6703a492a 100644
--- a/macosx/HBController.m
+++ b/macosx/HBController.m
@@ -1425,6 +1425,7 @@ static void *HBControllerLogLevelContext = &HBControllerLogLevelContext;
- (IBAction)exportPreset:(id)sender
{
+ fPresetsView.selectedPreset = self.selectedPreset;
[fPresetsView exportPreset:sender];
}
@@ -1470,7 +1471,7 @@ static void *HBControllerLogLevelContext = &HBControllerLogLevelContext;
- (IBAction)deletePreset:(id)sender
{
- fPresetsView.selectedPreset = presetManager.defaultPreset;
+ fPresetsView.selectedPreset = self.selectedPreset;
[fPresetsView deletePreset:self];
}
diff --git a/macosx/HBPresetsViewController.m b/macosx/HBPresetsViewController.m
index 4b4fcd66f..360b20e85 100644
--- a/macosx/HBPresetsViewController.m
+++ b/macosx/HBPresetsViewController.m
@@ -121,7 +121,8 @@ static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
{
SEL action = anItem.action;
- if (action == @selector(exportPreset:))
+ if (action == @selector(exportPreset:) ||
+ action == @selector(deletePreset:))
{
if (!self.treeController.selectedObjects.firstObject)
{
@@ -147,19 +148,50 @@ static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
return [name stringByAppendingPathExtension:@"json"];
}
-- (IBAction)exportPreset:(id)sender
+- (nonnull NSURL *)lastPresetExportDirectoryURL
{
- // Find the current selection, it can be a category too.
- HBPreset *selectedPreset = [self.treeController.selectedObjects.firstObject copy];
+ NSURL *defaultExportDirectory = [[NSURL fileURLWithPath:NSHomeDirectory()] URLByAppendingPathComponent:@"Desktop" isDirectory:YES];
+ NSURL *lastPresetExportDirectoryURL = [NSUserDefaults.standardUserDefaults URLForKey:@"LastPresetExportDirectoryURL"];
+ return lastPresetExportDirectoryURL ? lastPresetExportDirectoryURL : defaultExportDirectory;
+}
- // Open a panel to let the user choose where and how to save the export file
- NSSavePanel *panel = [NSSavePanel savePanel];
+- (void)doExportPresets:(NSArray<HBPreset *> *)presets
+{
+ NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.title = NSLocalizedString(@"Export presets", @"Export presets save panel title");
+ panel.directoryURL = self.lastPresetExportDirectoryURL;
+ panel.canChooseFiles = NO;
+ panel.canChooseDirectories = YES;
+ panel.allowsMultipleSelection = NO;
+ panel.prompt = NSLocalizedString(@"Save", @"Export presets panel prompt");
- // We get the current file name and path from the destination field here
- NSURL *defaultExportDirectory = [[NSURL fileURLWithPath:NSHomeDirectory()] URLByAppendingPathComponent:@"Desktop" isDirectory:YES];
- panel.directoryURL = defaultExportDirectory;
- panel.nameFieldStringValue = [self fileNameForPreset:selectedPreset];
+ [panel beginWithCompletionHandler:^(NSInteger result)
+ {
+ if (result == NSModalResponseOK)
+ {
+ [NSUserDefaults.standardUserDefaults setURL:panel.URL forKey:@"LastPresetExportDirectoryURL"];
+
+ for (HBPreset *preset in presets)
+ {
+ NSError *error = NULL;
+ NSString *fileName = [self fileNameForPreset:preset];
+ NSURL *url = [panel.URL URLByAppendingPathComponent:fileName];
+ BOOL success = [preset writeToURL:url atomically:YES removeRoot:NO error:&error];
+ if (success == NO)
+ {
+ [self presentError:error];
+ }
+ }
+ }
+ }];
+}
+
+- (void)doExportPreset:(HBPreset *)preset
+{
+ NSSavePanel *panel = [NSSavePanel savePanel];
+ panel.title = NSLocalizedString(@"Export preset", @"Export presets save panel title");
+ panel.directoryURL = self.lastPresetExportDirectoryURL;
+ panel.nameFieldStringValue = [self fileNameForPreset:preset];
[panel beginWithCompletionHandler:^(NSInteger result)
{
@@ -169,7 +201,7 @@ static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
[NSUserDefaults.standardUserDefaults setURL:presetExportDirectory forKey:@"LastPresetExportDirectoryURL"];
NSError *error = NULL;
- BOOL success = [selectedPreset writeToURL:panel.URL atomically:YES removeRoot:NO error:&error];
+ BOOL success = [preset writeToURL:panel.URL atomically:YES removeRoot:NO error:&error];
if (success == NO)
{
[self presentError:error];
@@ -178,6 +210,19 @@ static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
}];
}
+- (IBAction)exportPreset:(id)sender
+{
+ NSArray<HBPreset *> *selectedPresets = self.treeController.selectedObjects;
+ if (selectedPresets.count == 1)
+ {
+ [self doExportPreset:selectedPresets.firstObject];
+ }
+ else if (selectedPresets.count > 1)
+ {
+ [self doExportPresets:selectedPresets];
+ }
+}
+
- (void)doImportPreset:(NSArray<NSURL *> *)URLs atIndexPath:(nullable NSIndexPath *)indexPath
{
if (indexPath == nil)