Fix file extension in the save panel
This commit is contained in:
3 files changed
+41
-45
No files matched your search
@@ -206,6 +206,8 @@ final class Document: NSDocument {
|
|||||||
|
|
||||||
override var shouldRunSavePanelWithAccessoryView: Bool { return false }
|
override var shouldRunSavePanelWithAccessoryView: Bool { return false }
|
||||||
|
|
||||||
|
override var savePanelShowsFileFormatsControl: Bool { return false }
|
||||||
|
|
||||||
override func prepareSavePanel(_ savePanel: NSSavePanel) -> Bool {
|
override func prepareSavePanel(_ savePanel: NSSavePanel) -> Bool {
|
||||||
self.accessoryViewController = SaveOptions(doc: self, savePanel: savePanel)
|
self.accessoryViewController = SaveOptions(doc: self, savePanel: savePanel)
|
||||||
|
|
||||||
|
|||||||
+4
-7
@@ -73,8 +73,8 @@ struct StoredCodable<T: Codable> : Registable {
|
|||||||
enum Prefs {
|
enum Prefs {
|
||||||
|
|
||||||
static func register() {
|
static func register() {
|
||||||
ud.register(defaults: [_crashOnException, _showOpenPanelAtLaunch, _suppressDonationAlert, _saveFormat, _organizeAlternateGroups,
|
ud.register(defaults: [_crashOnException, _showOpenPanelAtLaunch, _suppressDonationAlert, _fileType, _organizeAlternateGroups,
|
||||||
_defaultSaveFormat, _organizeAlternateGroups, _inferMediaCharacteristics, _audioMixdown,
|
_organizeAlternateGroups, _inferMediaCharacteristics, _audioMixdown,
|
||||||
_audioBitrate, _audioDRC, _audioConvertAC3, _audioKeepAC3, _audioConvertDts,
|
_audioBitrate, _audioDRC, _audioConvertAC3, _audioKeepAC3, _audioConvertDts,
|
||||||
_audioDtsOptions, _subtitleConvertBitmap, _ratingsCountry, _chaptersPreviewPosition,
|
_audioDtsOptions, _subtitleConvertBitmap, _ratingsCountry, _chaptersPreviewPosition,
|
||||||
_chaptersPreviewTrack, _mp464bitOffset, _mp464bitTimes, _mp4SaveAsOptimize, _forceHvc1,
|
_chaptersPreviewTrack, _mp464bitOffset, _mp464bitTimes, _mp4SaveAsOptimize, _forceHvc1,
|
||||||
@@ -96,11 +96,8 @@ enum Prefs {
|
|||||||
@Stored(key: "rememberWindowSize", defaultValue: false)
|
@Stored(key: "rememberWindowSize", defaultValue: false)
|
||||||
static var rememberDocumentWindowSize: Bool
|
static var rememberDocumentWindowSize: Bool
|
||||||
|
|
||||||
@Stored(key: "SBSaveFormat", defaultValue: "m4v")
|
@Stored(key: "SBSaveFormat", defaultValue: "mp4")
|
||||||
static var saveFormat: String
|
static var fileType: String
|
||||||
|
|
||||||
@Stored(key: "defaultSaveFormat", defaultValue: 0)
|
|
||||||
static var defaultSaveFormat: Int
|
|
||||||
|
|
||||||
@Stored(key: "SBOrganizeAlternateGroups", defaultValue: true)
|
@Stored(key: "SBOrganizeAlternateGroups", defaultValue: true)
|
||||||
static var organizeAlternateGroups: Bool
|
static var organizeAlternateGroups: Bool
|
||||||
|
|||||||
+35
-38
@@ -20,6 +20,8 @@ final class SaveOptions: NSViewController {
|
|||||||
private weak var doc: Document?
|
private weak var doc: Document?
|
||||||
private weak var savePanel: NSSavePanel?
|
private weak var savePanel: NSSavePanel?
|
||||||
|
|
||||||
|
private static let fileTypes = [MP42FileTypeM4V, MP42FileTypeMP4, MP42FileTypeM4A, MP42FileTypeM4B, MP42FileTypeM4R]
|
||||||
|
|
||||||
init(doc: Document, savePanel: NSSavePanel) {
|
init(doc: Document, savePanel: NSSavePanel) {
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
self.savePanel = savePanel
|
self.savePanel = savePanel
|
||||||
@@ -34,34 +36,36 @@ final class SaveOptions: NSViewController {
|
|||||||
return "SaveOptions"
|
return "SaveOptions"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setUpFileFormats()
|
||||||
|
{
|
||||||
|
guard let doc = doc else { return }
|
||||||
|
|
||||||
|
let types = doc.writableTypes(for: .saveAsOperation)
|
||||||
|
|
||||||
|
fileFormat.removeAllItems()
|
||||||
|
|
||||||
|
for type in types {
|
||||||
|
let name = UTTypeCopyDescription(type as CFString)?.takeRetainedValue() as String? ?? type
|
||||||
|
fileFormat.addItem(withTitle: name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
setUpFileFormats()
|
||||||
|
|
||||||
guard let doc = doc else { return }
|
guard let doc = doc else { return }
|
||||||
|
|
||||||
let formats = doc.writableTypes(for: .saveAsOperation)
|
let fileType = Prefs.fileType
|
||||||
fileFormat.removeAllItems()
|
let index = SaveOptions.fileTypes.firstIndex(of: fileType) ?? 1
|
||||||
|
fileFormat.selectItem(at: index)
|
||||||
for format in formats {
|
|
||||||
let name = UTTypeCopyDescription(format as CFString)?.takeRetainedValue() as String? ?? format
|
|
||||||
fileFormat.addItem(withTitle: name)
|
|
||||||
}
|
|
||||||
|
|
||||||
let idx = Prefs.defaultSaveFormat > -1 && Prefs.defaultSaveFormat < formats.count ? Prefs.defaultSaveFormat : 1
|
|
||||||
let format = formats[idx]
|
|
||||||
|
|
||||||
fileFormat.selectItem(at: idx)
|
|
||||||
|
|
||||||
if let filename = doc.mp4.preferredFileName() {
|
if let filename = doc.mp4.preferredFileName() {
|
||||||
savePanel?.nameFieldStringValue = filename
|
savePanel?.nameFieldStringValue = filename
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(macOS 15.0, *) {
|
setFileType(filenameExtension: fileType)
|
||||||
let type = UTType(format) ?? .mpeg4Movie
|
|
||||||
savePanel?.currentContentType = type
|
|
||||||
} else {
|
|
||||||
savePanel?.allowedFileTypes = [Prefs.saveFormat]
|
|
||||||
}
|
|
||||||
|
|
||||||
_64bit_data.state = Prefs.mp464bitOffset ? .on : .off
|
_64bit_data.state = Prefs.mp464bitOffset ? .on : .off
|
||||||
_64bit_time.state = Prefs.mp464bitTimes ? .on : .off
|
_64bit_time.state = Prefs.mp464bitTimes ? .on : .off
|
||||||
@@ -73,7 +77,7 @@ final class SaveOptions: NSViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveUserDefaults() {
|
func saveUserDefaults() {
|
||||||
Prefs.defaultSaveFormat = fileFormat.indexOfSelectedItem
|
Prefs.fileType = SaveOptions.fileTypes[fileFormat.indexOfSelectedItem]
|
||||||
Prefs.mp464bitOffset = _64bit_data.state == .on
|
Prefs.mp464bitOffset = _64bit_data.state == .on
|
||||||
Prefs.mp464bitTimes = _64bit_time.state == .on
|
Prefs.mp464bitTimes = _64bit_time.state == .on
|
||||||
Prefs.mp4SaveAsOptimize = optimize.state == .on
|
Prefs.mp4SaveAsOptimize = optimize.state == .on
|
||||||
@@ -84,28 +88,21 @@ final class SaveOptions: NSViewController {
|
|||||||
saveUserDefaults()
|
saveUserDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func setSaveFormat(_ sender: NSPopUpButton) {
|
func setFileType(filenameExtension: String)
|
||||||
var requiredFileType = MP42FileTypeM4V
|
{
|
||||||
switch sender.indexOfSelectedItem {
|
|
||||||
case 0:
|
|
||||||
requiredFileType = MP42FileTypeM4V
|
|
||||||
case 1:
|
|
||||||
requiredFileType = MP42FileTypeMP4
|
|
||||||
case 2:
|
|
||||||
requiredFileType = MP42FileTypeM4A
|
|
||||||
case 3:
|
|
||||||
requiredFileType = MP42FileTypeM4B
|
|
||||||
case 4:
|
|
||||||
requiredFileType = MP42FileTypeM4R
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if #available(macOS 15.0, *) {
|
if #available(macOS 15.0, *) {
|
||||||
let type = UTType(filenameExtension: requiredFileType) ?? .mpeg4Movie
|
let type = UTType(filenameExtension: filenameExtension) ?? .mpeg4Movie
|
||||||
savePanel?.currentContentType = type
|
savePanel?.currentContentType = type
|
||||||
} else {
|
} else {
|
||||||
savePanel?.allowedFileTypes = [requiredFileType]
|
savePanel?.allowedFileTypes = [filenameExtension]
|
||||||
}
|
}
|
||||||
Prefs.saveFormat = requiredFileType
|
}
|
||||||
|
|
||||||
|
@IBAction func setSaveFormat(_ sender: NSPopUpButton) {
|
||||||
|
let index = sender.indexOfSelectedItem
|
||||||
|
let selectedFileType = SaveOptions.fileTypes.indices.contains(index) ?
|
||||||
|
SaveOptions.fileTypes[index] : MP42FileTypeMP4
|
||||||
|
|
||||||
|
setFileType(filenameExtension: selectedFileType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user