Cleanup the Save As destination feature a bit
This commit is contained in:
5 files changed
+85
-73
No files matched your search
@@ -55,7 +55,8 @@ class GeneralPrefsViewController: NSViewController {
|
||||
}
|
||||
|
||||
if let url = Prefs.saveAsCustomLocation {
|
||||
menu.insertItem(menuItem(url: url), at: 2)
|
||||
menu.insertItem(NSMenuItem.separator(), at: 2)
|
||||
menu.insertItem(menuItem(url: url), at: 3)
|
||||
}
|
||||
|
||||
selectCurrentSaveLocation()
|
||||
|
||||
@@ -91,7 +91,7 @@ extension MP42File {
|
||||
}
|
||||
}
|
||||
|
||||
func preferredFileDirectory() -> URL? {
|
||||
func firstSourceDirectoryURL() -> URL? {
|
||||
return tracks.compactMap { $0.url }.first?.deletingLastPathComponent()
|
||||
}
|
||||
|
||||
|
||||
+35
-24
@@ -26,11 +26,6 @@ struct Stored<T> : Registable {
|
||||
let key: String
|
||||
let defaultValue: T
|
||||
|
||||
init(key: String, defaultValue: T) {
|
||||
self.key = key
|
||||
self.defaultValue = defaultValue
|
||||
}
|
||||
|
||||
var wrappedValue: T {
|
||||
get { ud.object(forKey: key) as? T ?? defaultValue }
|
||||
set { ud.set(newValue, forKey: key) }
|
||||
@@ -41,16 +36,41 @@ struct Stored<T> : Registable {
|
||||
}
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
struct StoredEnum<T: RawRepresentable> : Registable {
|
||||
let key: String
|
||||
let defaultValue: T
|
||||
|
||||
var wrappedValue: T {
|
||||
get { T(rawValue: (ud.object(forKey: key) as? T.RawValue) ?? defaultValue.rawValue) ?? defaultValue }
|
||||
set { ud.set(newValue.rawValue, forKey: key) }
|
||||
}
|
||||
|
||||
func register(in dictionary: inout [String :Any]) {
|
||||
dictionary[key] = defaultValue.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
struct StoredURL : Registable {
|
||||
let key: String
|
||||
let defaultValue: URL?
|
||||
|
||||
var wrappedValue: URL? {
|
||||
get { ud.url(forKey: key) ?? defaultValue }
|
||||
set { ud.set(newValue, forKey: key) }
|
||||
}
|
||||
|
||||
func register(in dictionary: inout [String :Any]) {
|
||||
dictionary[key] = defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
struct StoredCodable<T: Codable> : Registable {
|
||||
let key: String
|
||||
let defaultValue: T
|
||||
|
||||
init(key: String, defaultValue: T) {
|
||||
self.key = key
|
||||
self.defaultValue = defaultValue
|
||||
}
|
||||
|
||||
var wrappedValue: T {
|
||||
get {
|
||||
guard let data = ud.data(forKey: key) else { return defaultValue }
|
||||
@@ -88,7 +108,7 @@ enum Prefs {
|
||||
_audioBitrate, _audioDRC, _audioConvertAC3, _audioKeepAC3, _audioConvertDts,
|
||||
_audioDtsOptions, _subtitleConvertBitmap, _ratingsCountry, _chaptersPreviewPosition,
|
||||
_chaptersPreviewTrack, _mp464bitOffset, _mp464bitTimes, _mp4SaveAsOptimize, _forceHvc1,
|
||||
_logFormat, _saveAsLocationValue])
|
||||
_logFormat, _saveAsLocation])
|
||||
}
|
||||
|
||||
@Stored(key: "NSApplicationCrashOnException", defaultValue: true)
|
||||
@@ -172,21 +192,12 @@ enum Prefs {
|
||||
@Stored(key: "SBLogFormat", defaultValue: 0)
|
||||
static var logFormat: Int // 0 = Time Only, 1 = Date and Time
|
||||
|
||||
@Stored(key: "SBSaveAsLocationMode", defaultValue: 0)
|
||||
private static var saveAsLocationValue: Int
|
||||
|
||||
static var saveAsLocation: SaveAsLocation {
|
||||
get { SaveAsLocation(rawValue: saveAsLocationValue) ?? .lastUsed }
|
||||
set { saveAsLocationValue = newValue.rawValue }
|
||||
}
|
||||
|
||||
private static let saveAsCustomLocationKey = "SBSaveAsCustomLocation"
|
||||
@StoredEnum(key: "SBSaveAsLocationMode", defaultValue: .lastUsed)
|
||||
static var saveAsLocation: SaveAsLocation
|
||||
|
||||
/// The folder used when saveAsLocation is set to custom.
|
||||
static var saveAsCustomLocation: URL? {
|
||||
get { ud.url(forKey: saveAsCustomLocationKey) }
|
||||
set { ud.set(newValue, forKey: saveAsCustomLocationKey) }
|
||||
}
|
||||
@StoredURL(key: "SBSaveAsCustomLocation", defaultValue: nil)
|
||||
static var saveAsCustomLocation: URL?
|
||||
}
|
||||
|
||||
enum MetadataPrefs {
|
||||
|
||||
@@ -62,7 +62,7 @@ final class SaveOptions: NSViewController {
|
||||
case .lastUsed:
|
||||
return nil
|
||||
case .sameAsFile:
|
||||
return doc.fileURL?.deletingLastPathComponent() ?? doc.mp4.preferredFileDirectory()
|
||||
return doc.fileURL?.deletingLastPathComponent() ?? doc.mp4.firstSourceDirectoryURL()
|
||||
case .custom:
|
||||
return Prefs.saveAsCustomLocation
|
||||
}
|
||||
@@ -83,8 +83,8 @@ final class SaveOptions: NSViewController {
|
||||
savePanel?.nameFieldStringValue = filename
|
||||
}
|
||||
|
||||
if let directory = preferredDirectory(for: doc) {
|
||||
savePanel?.directoryURL = directory
|
||||
if let url = preferredDirectory(for: doc) {
|
||||
savePanel?.directoryURL = url
|
||||
}
|
||||
|
||||
setFileType(filenameExtension: fileType)
|
||||
|
||||
Reference in new issue
Block a user