Remember recent destinations in queue options.
This commit is contained in:
12 files changed
+321
-397
No files matched your search
@@ -7,40 +7,6 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Wrapper for Objc compatibility
|
||||
@objc public class SBMetadataImporter : NSObject {
|
||||
|
||||
@objc public static var movieProviders: [String] {
|
||||
return MetadataSearch.movieProviders
|
||||
}
|
||||
|
||||
@objc public static var tvProviders: [String] {
|
||||
return MetadataSearch.tvProviders
|
||||
}
|
||||
|
||||
@objc public static func defaultLanguage(provider: String) -> String {
|
||||
return MetadataSearch.service(name: provider).defaultLanguage
|
||||
}
|
||||
|
||||
@objc public static func importer(provider: String) -> SBMetadataImporter {
|
||||
return SBMetadataImporter(provider: provider)
|
||||
}
|
||||
|
||||
private let service: MetadataService
|
||||
|
||||
@objc init(provider: String) {
|
||||
service = MetadataSearch.service(name: provider)
|
||||
}
|
||||
|
||||
@objc public var languageType: LanguageType {
|
||||
return service.languageType
|
||||
}
|
||||
|
||||
@objc public var languages: [String] {
|
||||
return service.languages
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Filename
|
||||
|
||||
public enum MetadataSearchTerms {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc(SBMetadataImporterLanguageType) public enum LanguageType: Int {
|
||||
public enum LanguageType {
|
||||
case ISO
|
||||
case custom
|
||||
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
//
|
||||
// OptionsViewController.swift
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 16/03/2018.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
@objc(SBOptionsViewController) class OptionsViewController: NSViewController {
|
||||
|
||||
@IBOutlet var destButton: NSPopUpButton!
|
||||
|
||||
private static var observerContext = 0
|
||||
|
||||
@objc private dynamic let options: NSMutableDictionary
|
||||
|
||||
@objc private dynamic var sets: [MetadataPreset]
|
||||
private var presetsObserver: Any?
|
||||
|
||||
@objc private dynamic let moviesProviders: [String]
|
||||
@objc private dynamic let tvShowsProviders: [String]
|
||||
|
||||
private let moviesProvidersKeyPath: String
|
||||
private let tvShowsProvidersKeyPath: String
|
||||
|
||||
@objc private dynamic var movieLanguages: [String]
|
||||
@objc private dynamic var tvShowLanguages: [String]
|
||||
|
||||
@objc private dynamic let languages: [String]
|
||||
private let langManager: MP42Languages
|
||||
|
||||
private var recentDestinations: [URL]
|
||||
|
||||
override var nibName: NSNib.Name? {
|
||||
return NSNib.Name(rawValue: "QueueOptions")
|
||||
}
|
||||
|
||||
@objc init(options: NSMutableDictionary) {
|
||||
self.options = options
|
||||
|
||||
self.sets = []
|
||||
|
||||
self.moviesProviders = MetadataSearch.movieProviders
|
||||
self.tvShowsProviders = MetadataSearch.tvProviders
|
||||
self.moviesProvidersKeyPath = "options.SBQueueMovieProvider"
|
||||
self.tvShowsProvidersKeyPath = "options.SBQueueTVShowProvider"
|
||||
self.movieLanguages = []
|
||||
self.tvShowLanguages = []
|
||||
|
||||
self.langManager = MP42Languages.defaultManager
|
||||
self.languages = self.langManager.localizedExtendedLanguages
|
||||
|
||||
self.recentDestinations = []
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
deinit {
|
||||
removeObserver(self, forKeyPath: moviesProvidersKeyPath, context: &OptionsViewController.observerContext)
|
||||
removeObserver(self, forKeyPath: tvShowsProvidersKeyPath, context: &OptionsViewController.observerContext)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Hack to fix crappy anti-aliasing on Yosemite
|
||||
// unfortunately it fixes the checkboxes anti-aliasing,
|
||||
// but break the popup buttons one…
|
||||
view.wantsLayer = true
|
||||
|
||||
for subview in view.subviews {
|
||||
if let button = subview as? NSButton {
|
||||
button.attributedTitle = NSAttributedString(string: button.title,
|
||||
attributes: [NSAttributedStringKey.foregroundColor: NSColor.labelColor,
|
||||
NSAttributedStringKey.font: NSFont.labelFont(ofSize: 11)])
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Observe the providers changes
|
||||
// to update the specific provider languages popup
|
||||
addObserver(self, forKeyPath: moviesProvidersKeyPath, options: [.initial, .new], context: &OptionsViewController.observerContext)
|
||||
addObserver(self, forKeyPath: tvShowsProvidersKeyPath, options: [.initial, .new], context: &OptionsViewController.observerContext)
|
||||
|
||||
prepareDestinationPopUp()
|
||||
preparePresetsPopUp()
|
||||
}
|
||||
|
||||
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
||||
guard context == &OptionsViewController.observerContext, let changeDict = change else {
|
||||
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
|
||||
return
|
||||
}
|
||||
|
||||
if keyPath == moviesProvidersKeyPath {
|
||||
let newProvider = changeDict[.newKey] as? String ?? MetadataSearch.movieProviders.first
|
||||
let oldLanguage = options[SBQueueMovieProviderLanguage] as? String ?? "und"
|
||||
let service = MetadataSearch.service(name: newProvider)
|
||||
|
||||
movieLanguages = localizedLanguages(service: service)
|
||||
|
||||
if service.languages.contains(oldLanguage) == false {
|
||||
options[SBQueueMovieProviderLanguage] = service.defaultLanguage
|
||||
}
|
||||
} else if keyPath == tvShowsProvidersKeyPath {
|
||||
let newProvider = changeDict[.newKey] as? String ?? MetadataSearch.tvProviders.first
|
||||
let oldLanguage = options[SBQueueTVShowProviderLanguage] as? String ?? "und"
|
||||
let service = MetadataSearch.service(name: newProvider)
|
||||
|
||||
tvShowLanguages = localizedLanguages(service: service)
|
||||
|
||||
if service.languages.contains(oldLanguage) == false {
|
||||
options[SBQueueTVShowProviderLanguage] = service.defaultLanguage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
||||
switch menuItem.action {
|
||||
case #selector(chooseDestination(_:)),
|
||||
#selector(destination(_:)):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private func localizedLanguages(service: MetadataService) -> [String] {
|
||||
let type = service.languageType
|
||||
return service.languages.map { (lang: String) -> String in
|
||||
if type == LanguageType.ISO {
|
||||
return langManager.localizedLang(forExtendedTag: lang)
|
||||
} else {
|
||||
return lang
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Destination popUp
|
||||
|
||||
private func menuItem(url: URL) -> NSMenuItem {
|
||||
let icon = NSWorkspace.shared.icon(forFile: url.path)
|
||||
icon.size = NSSize(width: 16, height: 16)
|
||||
let item = NSMenuItem(title: url.lastPathComponent, action: #selector(destination(_:)), keyEquivalent: "")
|
||||
item.image = icon
|
||||
item.target = self
|
||||
item.representedObject = url
|
||||
return item
|
||||
}
|
||||
|
||||
private func moviesFolderURL() -> URL? {
|
||||
let fileManager = FileManager.default
|
||||
return fileManager.urls(for: .moviesDirectory, in: .userDomainMask).first
|
||||
}
|
||||
|
||||
private func insertDestinationItem(_ item: NSMenuItem) {
|
||||
destButton.menu?.insertItem(item, at: 0)
|
||||
}
|
||||
|
||||
private func insertAndSelect(_ url: URL) {
|
||||
if let item = (destButton.menu?.items.filter { $0.representedObject as? URL == url })?.first {
|
||||
destButton.menu?.removeItem(item)
|
||||
insertDestinationItem(item)
|
||||
destButton.select(item)
|
||||
} else {
|
||||
let item = menuItem(url: url)
|
||||
insertDestinationItem(item)
|
||||
destButton.select(item)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectCurrentDestination() {
|
||||
if let url = self.options[SBQueueDestination] as? URL, let item = (destButton.menu?.items.filter { $0.representedObject as? URL == url })?.first {
|
||||
destButton.select(item)
|
||||
} else {
|
||||
destButton.selectItem(withTag: sameAsFileTag)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func saveRecentDestinations() {
|
||||
let destinationsPath = recentDestinations.map { $0.path }
|
||||
UserDefaults.standard.set(destinationsPath, forKey: "SBQueueRecentDestinations")
|
||||
// TODO: Sandbox
|
||||
}
|
||||
|
||||
private func loadRecentDestinations() {
|
||||
if let loadedDestinations = UserDefaults.standard.array(forKey: "SBQueueRecentDestinations") as? [String] {
|
||||
recentDestinations = loadedDestinations.compactMap { URL(fileURLWithPath: $0) }
|
||||
if recentDestinations.count > 6 {
|
||||
recentDestinations = Array(recentDestinations[0..<6])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let sameAsFileTag = 10
|
||||
|
||||
private func prepareDestinationPopUp() {
|
||||
loadRecentDestinations()
|
||||
|
||||
if let moviesURL = moviesFolderURL(), recentDestinations.contains(moviesURL) == false {
|
||||
recentDestinations.append(moviesURL)
|
||||
}
|
||||
|
||||
if let currentURL = self.options[SBQueueDestination] as? URL, recentDestinations.contains(currentURL) == false {
|
||||
recentDestinations.insert(currentURL, at: 0)
|
||||
}
|
||||
|
||||
for url in recentDestinations {
|
||||
let item = menuItem(url: url)
|
||||
insertDestinationItem(item)
|
||||
}
|
||||
|
||||
selectCurrentDestination()
|
||||
}
|
||||
|
||||
@IBAction func chooseDestination(_ sender: Any) {
|
||||
let panel = NSOpenPanel()
|
||||
panel.allowsMultipleSelection = false
|
||||
panel.canChooseFiles = false
|
||||
panel.canChooseDirectories = true
|
||||
panel.canCreateDirectories = true
|
||||
|
||||
panel.begin(completionHandler: { (response) in
|
||||
if response == NSApplication.ModalResponse.OK, let url = panel.url {
|
||||
self.options[SBQueueDestination] = url
|
||||
self.insertAndSelect(url)
|
||||
self.recentDestinations.insert(url, at: 0)
|
||||
self.saveRecentDestinations()
|
||||
} else {
|
||||
self.selectCurrentDestination()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@IBAction func destination(_ sender: NSMenuItem) {
|
||||
if let url = sender.representedObject as? URL {
|
||||
options[SBQueueDestination] = url
|
||||
} else {
|
||||
options[SBQueueDestination] = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Presets popUp
|
||||
|
||||
private func preparePresetsPopUp() {
|
||||
let update: (Notification) -> Void = { [weak self] notification in
|
||||
guard let s = self else { return }
|
||||
s.sets = PresetManager.shared.metadataPresets
|
||||
if let set = s.options[SBQueueSet] as? MetadataPreset, s.sets.contains(set) == false {
|
||||
s.options[SBQueueSet] = nil
|
||||
}
|
||||
}
|
||||
|
||||
update(Notification(name: Notification.Name(rawValue: "")))
|
||||
|
||||
presetsObserver = NotificationCenter.default.addObserver(forName: PresetManager.shared.updateNotification,
|
||||
object: nil,
|
||||
queue: OperationQueue.main,
|
||||
using: update)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// QueueScriptCommand.swift
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 16/03/2018.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc(SBQueueScriptCommand) class QueueScriptCommand: NSScriptCommand {
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let args = directParameter as? [URL] else { return nil }
|
||||
SBQueueController.sharedManager.addItems(from: args, at: 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc(SBQueueStartScriptCommand) class QueueStartScriptCommand: NSScriptCommand {
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
SBQueueController.sharedManager.start(self)
|
||||
self.suspendExecution()
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc(SBQueueStopScriptCommand) class QueueStopScriptCommand: NSScriptCommand {
|
||||
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
SBQueueController.sharedManager.stop(self)
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// QueueOptionsController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 16/03/14.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SBOptionsViewController : NSViewController
|
||||
|
||||
- (instancetype)initWithOptions:(NSMutableDictionary *)options;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,262 +0,0 @@
|
||||
//
|
||||
// QueueOptionsController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 16/03/14.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBOptionsViewController.h"
|
||||
#import "SBQueuePreferences.h"
|
||||
|
||||
#import <MP42Foundation/MP42Metadata.h>
|
||||
#import <MP42Foundation/MP42Languages.h>
|
||||
|
||||
#import "Subler-Swift.h"
|
||||
|
||||
static void *SBOptionsViewContex = &SBOptionsViewContex;
|
||||
|
||||
@interface SBOptionsViewController ()
|
||||
|
||||
@property (nonatomic, weak) IBOutlet NSPopUpButton *destButton;
|
||||
|
||||
@property (nonatomic) NSMutableDictionary *options;
|
||||
@property (nonatomic, strong) NSMutableArray *sets;
|
||||
|
||||
@property (nonatomic, strong) NSArray *moviesProviders;
|
||||
@property (nonatomic, strong) NSArray *tvShowsProviders;
|
||||
@property (nonatomic, strong) NSArray *movieLanguages;
|
||||
@property (nonatomic, strong) NSArray *tvShowLanguages;
|
||||
|
||||
@property (nonatomic, strong) NSArray *languages;
|
||||
@property (nonatomic, strong) MP42Languages *langManager;
|
||||
|
||||
- (IBAction)chooseDestination:(id)sender;
|
||||
- (IBAction)destination:(id)sender;
|
||||
|
||||
@property (nonatomic, strong) NSURL *destination;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBOptionsViewController
|
||||
|
||||
- (instancetype)initWithOptions:(NSMutableDictionary *)options {
|
||||
self = [self init];
|
||||
if (self) {
|
||||
_options = options;
|
||||
_sets = [[NSMutableArray alloc] init];
|
||||
_moviesProviders = [SBMetadataImporter movieProviders];
|
||||
_tvShowsProviders = [SBMetadataImporter tvProviders];
|
||||
_languages = [[MP42Languages defaultManager] localizedExtendedLanguages];
|
||||
_langManager = MP42Languages.defaultManager;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super initWithNibName:@"QueueOptions" bundle:nil];
|
||||
if (self) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
// Hack to fix crappy anti-aliasing on Yosemite
|
||||
// unfortunately it fixes the checkboxes anti-aliasing,
|
||||
// but break the popup buttons one…
|
||||
self.view.wantsLayer = YES;
|
||||
|
||||
for (NSButton *subview in self.view.subviews) {
|
||||
if ([subview isKindOfClass:[NSButton class]]) {
|
||||
NSAttributedString *string = [[NSAttributedString alloc] initWithString:subview.title
|
||||
attributes:@{NSForegroundColorAttributeName:[NSColor labelColor],
|
||||
NSFontAttributeName:[NSFont labelFontOfSize:11]}];
|
||||
subview.attributedTitle = string;
|
||||
}
|
||||
}
|
||||
|
||||
// Observe the providers changes
|
||||
// to update the specific provider languages popup
|
||||
[self addObserver:self
|
||||
forKeyPath:@"options.SBQueueMovieProvider"
|
||||
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
|
||||
context:SBOptionsViewContex];
|
||||
|
||||
[self addObserver:self
|
||||
forKeyPath:@"options.SBQueueTVShowProvider"
|
||||
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
|
||||
context:SBOptionsViewContex];
|
||||
|
||||
[self prepareDestPopup];
|
||||
[self prepareSetsPopup];
|
||||
}
|
||||
|
||||
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem {
|
||||
SEL action = anItem.action;
|
||||
|
||||
if (action == @selector(chooseDestination:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(destination:))
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||
if (context == SBOptionsViewContex) {
|
||||
// Update the languages popup
|
||||
if ([keyPath isEqualToString:@"options.SBQueueMovieProvider"]){
|
||||
NSString *newProvider = [change valueForKey:NSKeyValueChangeNewKey];
|
||||
NSString *oldLanguage = self.options[SBQueueMovieProviderLanguage];
|
||||
|
||||
SBMetadataImporter *importer = [SBMetadataImporter importerWithProvider:newProvider];
|
||||
self.movieLanguages = [self localizedLanguagesForImporter:importer];
|
||||
|
||||
if (![importer.languages containsObject:oldLanguage]) {
|
||||
self.options[SBQueueMovieProviderLanguage] = [SBMetadataImporter defaultLanguageWithProvider:newProvider];
|
||||
}
|
||||
} else if ([keyPath isEqualToString:@"options.SBQueueTVShowProvider"]) {
|
||||
NSString *newProvider = [change valueForKey:NSKeyValueChangeNewKey];
|
||||
NSString *oldLanguage = self.options[SBQueueTVShowProviderLanguage];
|
||||
|
||||
SBMetadataImporter *importer = [SBMetadataImporter importerWithProvider:newProvider];
|
||||
self.tvShowLanguages = [self localizedLanguagesForImporter:importer];
|
||||
|
||||
if (![importer.languages containsObject:oldLanguage]) {
|
||||
self.options[SBQueueTVShowProviderLanguage] = [SBMetadataImporter defaultLanguageWithProvider:newProvider];
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)localizedLanguagesForImporter:(SBMetadataImporter *)importer
|
||||
{
|
||||
NSMutableArray *languages = [NSMutableArray array];
|
||||
SBMetadataImporterLanguageType type = importer.languageType;
|
||||
|
||||
for (NSString *lang in importer.languages) {
|
||||
if (type == SBMetadataImporterLanguageTypeISO) {
|
||||
[languages addObject:[_langManager localizedLangForExtendedTag:lang]];
|
||||
}
|
||||
else {
|
||||
[languages addObject:lang];
|
||||
}
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
|
||||
#pragma mark Destination PopUp
|
||||
|
||||
- (void)prepareDestPopup {
|
||||
NSMenuItem *folderItem = nil;
|
||||
|
||||
if (self.options[SBQueueDestination]) {
|
||||
self.destination = self.options[SBQueueDestination];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:self.destination.path isDirectory:nil]) {
|
||||
self.destination = nil;
|
||||
}
|
||||
}
|
||||
|
||||
if (!self.destination) {
|
||||
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSMoviesDirectory,
|
||||
NSUserDomainMask,
|
||||
YES);
|
||||
if (allPaths.count) {
|
||||
self.destination = [NSURL fileURLWithPath:allPaths.lastObject];
|
||||
}
|
||||
}
|
||||
|
||||
if (self.destination) {
|
||||
folderItem = [self prepareDestPopupItem:self.destination];
|
||||
|
||||
[_destButton.menu insertItem:[NSMenuItem separatorItem] atIndex:0];
|
||||
[_destButton.menu insertItem:folderItem atIndex:0];
|
||||
|
||||
if (self.options[SBQueueDestination]) {
|
||||
[_destButton selectItem:folderItem];
|
||||
}
|
||||
else {
|
||||
[_destButton selectItemWithTag:10];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)chooseDestination:(id)sender {
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
panel.allowsMultipleSelection = NO;
|
||||
panel.canChooseFiles = NO;
|
||||
panel.canChooseDirectories = YES;
|
||||
panel.canCreateDirectories = YES;
|
||||
|
||||
panel.prompt = NSLocalizedString(@"Select", @"Select queue destination.");
|
||||
[panel beginWithCompletionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSMenuItem *folderItem = [self prepareDestPopupItem:panel.URL];
|
||||
|
||||
[self->_destButton.menu removeItemAtIndex:0];
|
||||
[self->_destButton.menu insertItem:folderItem atIndex:0];
|
||||
|
||||
[self->_destButton selectItem:folderItem];
|
||||
|
||||
self.options[SBQueueDestination] = panel.URL;
|
||||
self.destination = panel.URL;
|
||||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SBQueueDestinationSelected"];
|
||||
} else {
|
||||
[self->_destButton selectItemAtIndex:2];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)prepareDestPopupItem:(nonnull NSURL *)dest {
|
||||
NSMenuItem *folderItem = [[NSMenuItem alloc] initWithTitle:dest.lastPathComponent action:@selector(destination:) keyEquivalent:@""];
|
||||
|
||||
NSImage *menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:dest.path];
|
||||
menuItemIcon.size = NSMakeSize(16, 16);
|
||||
|
||||
folderItem.image = menuItemIcon;
|
||||
folderItem.action = @selector(destination:);
|
||||
folderItem.target = self;
|
||||
|
||||
return folderItem;
|
||||
}
|
||||
|
||||
- (IBAction)destination:(id)sender {
|
||||
if ([sender tag] == 10) {
|
||||
[self.options removeObjectForKey:SBQueueDestination];
|
||||
} else {
|
||||
self.options[SBQueueDestination] = self.destination;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Sets PopUp
|
||||
|
||||
- (void)prepareSetsPopup {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateSetsMenu:)
|
||||
name:@"SBPresetManagerUpdatedNotification" object:nil];
|
||||
[self updateSetsMenu:self];
|
||||
}
|
||||
|
||||
- (void)updateSetsMenu:(id)sender {
|
||||
self.sets = [SBPresetManager.shared.metadataPresets mutableCopy];
|
||||
if (![self.sets containsObject:self.options[SBQueueSet]]) {
|
||||
[self.options removeObjectForKey:SBQueueSet];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
@try {
|
||||
[self removeObserver:self forKeyPath:@"options.SBQueueMovieProvider"];
|
||||
[self removeObserver:self forKeyPath:@"options.SBQueueTVShowProvider"];
|
||||
} @catch (NSException * __unused exception) {}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -10,8 +10,6 @@
|
||||
#import "SBQueueItem.h"
|
||||
#import "SBQueuePreferences.h"
|
||||
|
||||
#import "SBOptionsViewController.h"
|
||||
|
||||
#import <MP42Foundation/MP42FileImporter.h>
|
||||
|
||||
#import "Subler-Swift.h"
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// SBQueueScriptCommand.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/02/17.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SBQueueScriptCommand : NSScriptCommand
|
||||
@end
|
||||
|
||||
@interface SBQueueStartScriptCommand : NSScriptCommand
|
||||
@end
|
||||
|
||||
@interface SBQueueStopScriptCommand : NSScriptCommand
|
||||
@end
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// SBQueueScriptCommand.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 02/02/17.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBQueueScriptCommand.h"
|
||||
#import "SBQueueController.h"
|
||||
|
||||
@implementation SBQueueScriptCommand
|
||||
|
||||
- (id)performDefaultImplementation
|
||||
{
|
||||
NSArray<NSURL *> *args = [self directParameter];
|
||||
|
||||
[SBQueueController.sharedManager addItemsFromURLs:args atIndex:0];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBQueueStartScriptCommand
|
||||
|
||||
- (id)performDefaultImplementation
|
||||
{
|
||||
[SBQueueController.sharedManager start:self];
|
||||
[self suspendExecution];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBQueueStopScriptCommand
|
||||
|
||||
- (id)performDefaultImplementation
|
||||
{
|
||||
[SBQueueController.sharedManager stop:self];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user