From d1a3d95ee19797180a88e3013015c9f1696a6429 Mon Sep 17 00:00:00 2001 From: Rodeo314 Date: Fri, 2 Feb 2018 04:57:52 -0500 Subject: MacGUI: Add Rename Preset dialog. @BradleyS thanks @Rodeo314 for his help with this. --- macosx/English.lproj/HBRenamePresetController.xib | 92 +++++++++++++++++++++++ macosx/English.lproj/MainMenu.xib | 8 ++ macosx/HBController.h | 2 + macosx/HBController.m | 41 +++++++++- macosx/HBRenamePresetController.h | 22 ++++++ macosx/HBRenamePresetController.m | 85 +++++++++++++++++++++ macosx/HandBrake.xcodeproj/project.pbxproj | 18 +++++ 7 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 macosx/English.lproj/HBRenamePresetController.xib create mode 100644 macosx/HBRenamePresetController.h create mode 100644 macosx/HBRenamePresetController.m (limited to 'macosx') diff --git a/macosx/English.lproj/HBRenamePresetController.xib b/macosx/English.lproj/HBRenamePresetController.xib new file mode 100644 index 000000000..fed39b46d --- /dev/null +++ b/macosx/English.lproj/HBRenamePresetController.xib @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index be6b5f151..75274b917 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -345,6 +345,14 @@ + + + + + + + + diff --git a/macosx/HBController.h b/macosx/HBController.h index b93fefb24..f650a5bf0 100644 --- a/macosx/HBController.h +++ b/macosx/HBController.h @@ -38,8 +38,10 @@ // Manage User presets - (IBAction)showAddPresetPanel:(id)sender; +- (IBAction)showRenamePresetPanel:(id)sender; - (IBAction)selectDefaultPreset:(id)sender; +- (IBAction)renamePreset:(id)sender; - (IBAction)deletePreset:(id)sender; - (IBAction)reloadPreset:(id)sender; diff --git a/macosx/HBController.m b/macosx/HBController.m index b48115efa..70ec14bad 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -30,6 +30,7 @@ #import "HBPresetsViewController.h" #import "HBAddPresetController.h" +#import "HBRenamePresetController.h" @import HandBrakeKit; @@ -549,7 +550,18 @@ } if (action == @selector(exportPreset:)) { - return [fPresetsView validateUserInterfaceItem:menuItem]; + return [fPresetsView validateUserInterfaceItem:menuItem] && self.job != nil; + } + if (action == @selector(selectDefaultPreset:) || + action == @selector(insertCategory:)) + { + return self.job != nil; + } + if (action == @selector(renamePreset:) || + action == @selector(deletePreset:) || + action == @selector(setDefaultPreset:)) + { + return self.job != nil && self.edited == NO;//fixme } return YES; @@ -1502,6 +1514,27 @@ return [preset copy]; } +- (IBAction)showRenamePresetPanel:(id)sender +{ + [self.window HB_endEditing]; + + HBRenamePresetController *renamePresetController = [[HBRenamePresetController alloc] initWithPreset:self.currentPreset + presetManager:presetManager]; + + [NSApp beginSheet:renamePresetController.window modalForWindow:self.window modalDelegate:self didEndSelector:@selector(renamePresetSheetDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain(renamePresetController)]; +} + +- (void)renamePresetSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo +{ + __unused HBRenamePresetController *renamePresetController = (HBRenamePresetController *)CFBridgingRelease(contextInfo); + + if (returnCode != NSModalResponseCancel) + { + [self applyPreset:fPresetsView.selectedPreset]; + [[NSNotificationCenter defaultCenter] postNotificationName:HBPresetsChangedNotification object:nil]; + } +} + #pragma mark - #pragma mark Import Export Preset(s) @@ -1530,6 +1563,12 @@ [fPresetsView setDefault:sender]; } +- (IBAction)renamePreset:(id)sender +{ + fPresetsView.selectedPreset = _currentPreset; + [self showRenamePresetPanel:sender]; +} + - (IBAction)deletePreset:(id)sender { HBPreset *preset = [sender representedObject]; diff --git a/macosx/HBRenamePresetController.h b/macosx/HBRenamePresetController.h new file mode 100644 index 000000000..35b2b914d --- /dev/null +++ b/macosx/HBRenamePresetController.h @@ -0,0 +1,22 @@ +/* HBRenamePresetController.h + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class HBPreset; +@class HBPresetsManager; + +@interface HBRenamePresetController : NSWindowController + +- (instancetype)initWithPreset:(HBPreset *)preset presetManager:(HBPresetsManager *)manager; + +@property (nonatomic, readonly) HBPreset *preset; + +@end + +NS_ASSUME_NONNULL_END diff --git a/macosx/HBRenamePresetController.m b/macosx/HBRenamePresetController.m new file mode 100644 index 000000000..be87fe002 --- /dev/null +++ b/macosx/HBRenamePresetController.m @@ -0,0 +1,85 @@ +/* HBRenamePresetController.m + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import "HBRenamePresetController.h" + +#import "HBPresetsManager.h" +#import "HBPreset.h" + +@import HandBrakeKit; + +@interface HBRenamePresetController () + +@property (nonatomic, strong) IBOutlet NSTextField *name; +@property (nonatomic, strong) IBOutlet NSButton *renameButton; + +@property (nonatomic, strong) HBPreset *preset; + +@property (nonatomic, strong) HBPresetsManager *manager; + +@end + +@implementation HBRenamePresetController + +- (instancetype)initWithPreset:(HBPreset *)preset presetManager:(HBPresetsManager *)manager +{ + self = [super initWithWindowNibName:@"HBRenamePresetController"]; + if (self) + { + NSParameterAssert(preset); + NSParameterAssert(manager); + _preset = preset; + _manager = manager; + } + return self; +} + +- (void)windowDidLoad +{ + [super windowDidLoad]; + + self.name.stringValue = self.name.placeholderString = self.preset.name; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(controlTextDidChange:) + name:NSControlTextDidChangeNotification object:nil]; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSControlTextDidChangeNotification object:nil]; +} + +- (void)controlTextDidChange:(NSNotification *)obj { + self.renameButton.enabled = self.name.stringValue.length > 0 ? YES : NO; +} + +- (IBAction)dismiss:(id)sender +{ + [self.window orderOut:nil]; + [NSApp endSheet:self.window returnCode:NSModalResponseCancel]; +} + +- (IBAction)rename:(id)sender +{ + if (self.name.stringValue.length == 0) + { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:NSLocalizedString(@"The preset name cannot be empty.", @"")]; + [alert setInformativeText:NSLocalizedString(@"Please enter a name.", @"")]; + [alert runModal]; + } + else + { + [self.preset setName:self.name.stringValue]; + + [self.window orderOut:nil]; + [NSApp endSheet:self.window returnCode:NSModalResponseContinue]; + } +} + + +@end diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index 17b667e8d..4dab5ac9f 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 1C6D76551CD7733300F5B943 /* libharfbuzz.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C15C82B1CD7722500368223 /* libharfbuzz.a */; }; 1C6D76561CD7733400F5B943 /* libharfbuzz.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C15C82B1CD7722500368223 /* libharfbuzz.a */; }; + 1C7776A2202300DD001C31EB /* HBRenamePresetController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C7776A0202300DC001C31EB /* HBRenamePresetController.m */; }; + 1C7776A5202301D5001C31EB /* HBRenamePresetController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1C7776A3202301D5001C31EB /* HBRenamePresetController.xib */; }; 226268E11572CC7300477B4E /* libavresample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 226268DF1572CC7300477B4E /* libavresample.a */; }; 22DD2C4B177B95DA00EF50D3 /* libvpx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 22DD2C49177B94DB00EF50D3 /* libvpx.a */; }; 273F202314ADB8650021BE6D /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273F202214ADB8650021BE6D /* IOKit.framework */; }; @@ -316,6 +318,9 @@ /* Begin PBXFileReference section */ 1C15C82B1CD7722500368223 /* libharfbuzz.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libharfbuzz.a; path = external/contrib/lib/libharfbuzz.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 1C7776A0202300DC001C31EB /* HBRenamePresetController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HBRenamePresetController.m; sourceTree = ""; }; + 1C7776A1202300DC001C31EB /* HBRenamePresetController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HBRenamePresetController.h; sourceTree = ""; }; + 1C7776A4202301D5001C31EB /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/HBRenamePresetController.xib; sourceTree = ""; }; 226268DF1572CC7300477B4E /* libavresample.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libavresample.a; path = external/contrib/lib/libavresample.a; sourceTree = BUILT_PRODUCTS_DIR; }; 22CC9E74191EBEA500C69D81 /* libx265.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libx265.a; path = external/contrib/lib/libx265.a; sourceTree = BUILT_PRODUCTS_DIR; }; 22DD2C49177B94DB00EF50D3 /* libvpx.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvpx.a; path = external/contrib/lib/libvpx.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1198,6 +1203,9 @@ 273F20A014ADBE670021BE6D /* HBPreferencesController.m */, A939DD891FC8826A00135F2A /* HBPresetsMenuBuilder.h */, A939DD8A1FC8826A00135F2A /* HBPresetsMenuBuilder.m */, + 1C7776A1202300DC001C31EB /* HBRenamePresetController.h */, + 1C7776A0202300DC001C31EB /* HBRenamePresetController.m */, + 1C7776A3202301D5001C31EB /* HBRenamePresetController.xib */, ); name = Controllers; sourceTree = ""; @@ -1486,6 +1494,7 @@ A9F2EB6F196F12C800066546 /* Audio.xib in Resources */, A9CF25F11990D62C0023F727 /* Presets.xib in Resources */, A9C1839D1A716BCC00C897C2 /* HBTitleSelection.xib in Resources */, + 1C7776A5202301D5001C31EB /* HBRenamePresetController.xib in Resources */, 273F218A14ADDDA10021BE6D /* AdvancedView.xib in Resources */, 273F218B14ADDDA10021BE6D /* InfoPlist.strings in Resources */, A932E26C1988334B0047D13E /* AudioDefaults.xib in Resources */, @@ -1574,6 +1583,7 @@ A99F40CF1B624E7E00750170 /* HBPictureViewController.m in Sources */, 273F20AF14ADBE670021BE6D /* HBAudioController.m in Sources */, A9DC6C52196F04F6002AE6B4 /* HBSubtitlesController.m in Sources */, + 1C7776A2202300DD001C31EB /* HBRenamePresetController.m in Sources */, A9F472891976B7F30009EC65 /* HBSubtitlesDefaultsController.m in Sources */, 273F20AD14ADBE670021BE6D /* HBAdvancedController.m in Sources */, A9906B2C1A710920001D82D5 /* HBQueueController.m in Sources */, @@ -1691,6 +1701,14 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 1C7776A3202301D5001C31EB /* HBRenamePresetController.xib */ = { + isa = PBXVariantGroup; + children = ( + 1C7776A4202301D5001C31EB /* English */, + ); + name = HBRenamePresetController.xib; + sourceTree = ""; + }; 273F217A14ADDDA10021BE6D /* AdvancedView.xib */ = { isa = PBXVariantGroup; children = ( -- cgit v1.2.3