Rewrite some class in swift.

This commit is contained in:
Damiano Galassi committed 2017-11-12 14:42:45 +01:00
1 parent eb5f700700
commit fd6473478d
21 files changed
+500 -508

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
//
// ComboBoxCell.swift
// Subler
//
// Created by Damiano Galassi on 20/10/2017.
//
import Cocoa
class ComboBoxCell : NSComboBoxCell {
private var originalBackgroundStyle: NSView.BackgroundStyle = NSView.BackgroundStyle.light
override var backgroundStyle: NSView.BackgroundStyle {
get {
return super.backgroundStyle
}
set (newBackgroundStyle) {
super.backgroundStyle = newBackgroundStyle
if newBackgroundStyle == NSView.BackgroundStyle.dark {
textColor = NSColor.controlHighlightColor
} else {
textColor = NSColor.controlTextColor
}
}
}
override func setUpFieldEditorAttributes(_ textObj: NSText) -> NSText {
originalBackgroundStyle = backgroundStyle
backgroundStyle = NSView.BackgroundStyle.light
drawsBackground = true
return super.setUpFieldEditorAttributes(textObj)
}
override func endEditing(_ textObj: NSText) {
super.endEditing(textObj)
drawsBackground = false
backgroundStyle = originalBackgroundStyle
}
}
+71
View File
@@ -0,0 +1,71 @@
//
// ImageBrowserView.swift
// Subler
//
// Created by Damiano Galassi on 11/11/2017.
//
import Cocoa
import Quartz
@objc(SBImageBrowserViewDelegate) protocol ImageBrowserViewDelegate : NSObjectProtocol {
@objc(pasteToImageBrowserView:) optional func paste(to imagebrowserview: ImageBrowserView)
}
@objc(SBImageBrowserView) class ImageBrowserView : IKImageBrowserView {
@objc var pasteboardTypes: [NSPasteboard.PasteboardType]
var pasteboardHasSupportedType: Bool {
get {
// has the pasteboard got a type we support?
let pb = NSPasteboard.general
let bestType = pb.availableType(from: pasteboardTypes)
return bestType != nil
}
}
private var expandedDelegate: ImageBrowserViewDelegate? {
get {
return delegate as? ImageBrowserViewDelegate
}
}
override init(frame frameRect: NSRect) {
pasteboardTypes = Array()
super.init(frame: frameRect)
}
required init?(coder: NSCoder) {
pasteboardTypes = Array()
super.init(coder: coder)
}
private func implements(selector: Selector) -> Bool {
if let implemented = expandedDelegate?.responds(to: selector),
implemented == true {
return true
}
return false
}
override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
if let action = menuItem.action {
switch action {
case #selector(paste(_:)):
if pasteboardHasSupportedType == false || implements(selector: #selector(ExpandedTableViewDelegate.paste(to:))) == false {
return false
}
default:
break
}
}
return true
}
@IBAction func paste(_ sender: Any?) {
if implements(selector: #selector(ImageBrowserViewDelegate.paste(to:))) {
expandedDelegate?.paste!(to: self)
}
}
}
+69
View File
@@ -0,0 +1,69 @@
//
// ItemViewController.swift
// Subler
//
// Created by Damiano Galassi on 11/11/2017.
//
import Cocoa
@objc(SBItemViewDelegate) protocol ItemViewDelegate: AnyObject {
@objc(editItem:) func edit(item: SBQueueItem)
}
@objc(SBItemViewController) class ItemViewController : NSViewController {
@objc let item: SBQueueItem
var delegate: ItemViewDelegate
var statusObserver: NSKeyValueObservation?
var actionsObserver: NSKeyValueObservation?
@IBOutlet var editButton: NSButton!
@IBOutlet var spinner: NSProgressIndicator!
@IBOutlet var tableHeight: NSLayoutConstraint!
override var nibName: NSNib.Name? {
return NSNib.Name(rawValue: "QueueItem")
}
@objc init(item: SBQueueItem, delegate: ItemViewDelegate) {
self.item = item
self.delegate = delegate
super.init(nibName: self.nibName, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func loadView() {
super.loadView()
// Observe the item status
statusObserver = self.observe(\.item.status, options: [.initial, .new]) { [weak self] observed, change in
guard let s = self, let status = change.newValue else { return }
DispatchQueue.main.async {
if status != SBQueueItemStatus.ready && status != SBQueueItemStatus.editing {
s.editButton.isEnabled = false
} else {
s.editButton.isEnabled = true
}
}
}
// Observe the item actions
actionsObserver = self.observe(\.item.actions, options: [.initial, .new]) { [weak self] observed, change in
guard let s = self, let newCount = change.newValue?.count, let oldCount = change.oldValue?.count else { return }
let count = newCount - oldCount
let height = 16.0 * CGFloat(count >= 0 ? count : 1)
s.tableHeight.constant = height
}
}
@IBAction func edit(_ sender: Any) {
spinner.isHidden = false
delegate.edit(item: item)
}
}
+30
View File
@@ -0,0 +1,30 @@
//
// LanguageTransformer.swift
// Subler
//
// Created by Damiano Galassi on 11/11/2017.
//
import Foundation
@objc(SBLanguageTransformer) class LanguageTransformer : ValueTransformer {
private let langManager = MP42Languages.defaultManager
override class func transformedValueClass() -> Swift.AnyClass {
return NSString.self
}
override class func allowsReverseTransformation() -> Bool {
return true
}
override func transformedValue(_ value: Any?) -> Any? {
return langManager.localizedLang(forExtendedTag: value as! String)
}
override func reverseTransformedValue(_ value: Any?) -> Any? {
return langManager.extendedTag(forLocalizedLang: value as! String)
}
}
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13528" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13770" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13528"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13770"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SBChapterViewController">
<customObject id="-2" userLabel="File's Owner" customClass="ChapterSearchController" customModule="Subler" customModuleProvider="target">
<connections>
<outlet property="chapterTableView" destination="22" id="49"/>
<outlet property="removeChapter" destination="31" id="47"/>
<outlet property="removeChapter" destination="31" id="faJ-CI-g36"/>
<outlet property="tableView" destination="22" id="7Za-v5-yKx"/>
<outlet property="view" destination="1" id="2"/>
</connections>
</customObject>
@@ -35,7 +35,7 @@
<rect key="frame" x="1" y="0.0" width="446" height="194"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="14" headerView="23" id="22" customClass="ExpandedTableView" customModule="Subler" customModuleProvider="target">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="14" headerView="23" viewBased="YES" id="22" customClass="ExpandedTableView" customModule="Subler" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="446" height="177"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
@@ -302,6 +302,29 @@
</allowedInputSourceLocales>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="lUr-1t-Gov">
<rect key="frame" x="1" y="1" width="96" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" misplaced="YES" id="sbg-eG-N9u">
<rect key="frame" x="0.0" y="3" width="96" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="right" title="Table View Cell" id="fIl-II-Tfv">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="setChapterTimeStamp:" target="-2" id="SNb-Yy-l6Q"/>
</connections>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="sbg-eG-N9u" id="rpX-jo-DcW"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn identifier="title" width="344" minWidth="40" maxWidth="2000" id="25">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Title">
@@ -315,6 +338,29 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="SuA-T8-hMx">
<rect key="frame" x="100" y="1" width="344" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" misplaced="YES" id="KkS-kR-z72">
<rect key="frame" x="0.0" y="3" width="344" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="Ktq-AC-XnR">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="setChapterTitle:" target="-2" id="6Jm-gc-jcn"/>
</connections>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="KkS-kR-z72" id="Psh-7t-gco"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
<accessibility description="Chapters"/>
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13528" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13770" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13528"/>
<plugIn identifier="com.apple.imagekit.ibplugin" version="13528"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13770"/>
<plugIn identifier="com.apple.imagekit.ibplugin" version="13770"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -255,7 +255,7 @@
<comboBox verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="YES" preferredMaxLayoutWidth="1000" translatesAutoresizingMaskIntoConstraints="NO" id="LbC-r6-Pau">
<rect key="frame" x="3" y="0.0" width="319" height="19"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<comboBoxCell key="cell" controlSize="small" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="left" title="Do not localize" usesSingleLineMode="YES" buttonBordered="NO" numberOfVisibleItems="5" id="jkg-xz-Hbn" customClass="ComboBoxCell" customModule="Subler" customModuleProvider="target">
<comboBoxCell key="cell" controlSize="small" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" alignment="left" title="Do not localize" usesSingleLineMode="YES" buttonBordered="NO" numberOfVisibleItems="5" id="jkg-xz-Hbn">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -0,0 +1,136 @@
//
// ChapterViewController.swift
// Subler
//
// Created by Damiano Galassi on 11/11/2017.
//
import Cocoa
@objc(SBChapterViewController) class ChapterViewController : NSViewController, NSTableViewDataSource, NSTableViewDelegate {
var track: MP42ChapterTrack {
didSet {
tableView.reloadData()
}
}
@IBOutlet var tableView: ExpandedTableView!
@IBOutlet var removeChapter: NSButton!
override var nibName: NSNib.Name? {
return NSNib.Name(rawValue: "ChapterView")
}
@objc init(track: MP42ChapterTrack) {
self.track = track
super.init(nibName: self.nibName, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func loadView() {
super.loadView()
tableView.defaultEditingColumn = 1
tableView.doubleAction = #selector(doubleClickAction(_:))
}
// MARK: Table View
func numberOfRows(in tableView: NSTableView) -> Int {
return Int(track.chapterCount())
}
let trackTimeColumn = NSUserInterfaceItemIdentifier(rawValue: "time")
let trackTitleColumn = NSUserInterfaceItemIdentifier(rawValue: "title")
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let chapter = track.chapter(at: UInt(row))
switch tableColumn?.identifier {
case trackTimeColumn?:
let cell = tableView.makeView(withIdentifier: trackTimeColumn, owner:self) as? NSTableCellView
cell?.textField?.attributedStringValue = StringFromTime(Int64(chapter.timestamp), 1000).boldMonospacedAttributedString()
return cell
case trackTitleColumn?:
let cell = tableView.makeView(withIdentifier: trackTitleColumn, owner:self) as? NSTableCellView
cell?.textField?.stringValue = chapter.title
return cell
default:
return nil
}
}
func tableViewSelectionDidChange(_ notification: Notification) {
removeChapter.isEnabled = tableView.selectedRow != -1 ? true : false
}
@IBAction func setChapterTitle(_ sender: NSTextField) {
let row = tableView.row(for: sender)
if row > -1 {
let chapter = track.chapter(at: UInt(row))
track.setTitle(sender.stringValue, forChapter: chapter)
tableView.reloadData(forRowIndexes: IndexSet(integer: row), columnIndexes: IndexSet(integer: 1))
updateChangeCount()
}
}
@IBAction func setChapterTimeStamp(_ sender: NSTextField) {
let row = tableView.row(for: sender)
if row > -1 {
let chapter = track.chapter(at: UInt(row))
let timestamp = TimeFromString(sender.stringValue, 1000)
track.setTimestamp(timestamp, forChapter: chapter)
tableView.reloadData()
updateChangeCount()
}
}
@IBAction func doubleClickAction(_ sender: NSTableView) {
if sender.clickedRow > -1 && sender.clickedColumn > -1 {
sender.editColumn(sender.clickedColumn, row: sender.clickedRow, with: nil, select: true)
}
}
// MARK: Actions
private func updateChangeCount() {
view.window?.windowController?.document?.updateChangeCount(NSDocument.ChangeType.changeDone)
}
@IBAction func removeChapter(_ sender: Any) {
let currentIndex = tableView.selectedRow
if currentIndex < track.chapterCount() {
track.removeChapter(at: UInt(currentIndex))
let indexes = IndexSet(integer: currentIndex)
tableView.removeRows(at: indexes, withAnimation: NSTableView.AnimationOptions.slideUp)
tableView.selectRowIndexes(indexes, byExtendingSelection: false)
updateChangeCount()
}
}
@IBAction func addChapter(_ sender: Any) {
track.addChapter("Chapter", duration: 0)
tableView.reloadData()
updateChangeCount()
}
@IBAction func renameChapters(_ sender: Any) {
for (index, chapter) in track.chapters.enumerated() {
let title = "Chapter \(index + 1)"
track.setTitle(title, forChapter: chapter)
}
tableView.reloadData()
updateChangeCount()
}
}
@@ -1,25 +0,0 @@
//
// ChapterViewController.h
// Subler
//
// Created by Damiano Galassi on 06/02/09.
// Copyright 2009 Damiano Galassi. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <MP42Foundation/MP42File.h>
#import <MP42Foundation/MP42ChapterTrack.h>
NS_ASSUME_NONNULL_BEGIN
@interface SBChapterViewController : NSViewController
@property (nonatomic, readwrite, nullable) MP42ChapterTrack *track;
- (IBAction)addChapter:(id)sender;
- (IBAction)removeChapter:(id)sender;
- (IBAction)renameChapters:(id)sender;
@end
NS_ASSUME_NONNULL_END
@@ -1,152 +0,0 @@
//
// ChapterViewController.m
// Subler
//
// Created by Damiano Galassi on 06/02/09.
// Copyright 2009 Damiano Galassi. All rights reserved.
//
#import "SBChapterViewController.h"
#import "Subler-Swift.h"
#import <MP42Foundation/MP42Utilities.h>
@implementation SBChapterViewController
{
NSDictionary *detailBoldAttr;
IBOutlet ExpandedTableView *chapterTableView;
IBOutlet NSButton *removeChapter;
}
- (void)loadView
{
[super loadView];
NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
ps.headIndent = -10.0;
ps.alignment = NSTextAlignmentRight;
if ([[NSFont class] respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]) {
detailBoldAttr = @{ NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightBold],
NSParagraphStyleAttributeName: ps,
NSForegroundColorAttributeName: [NSColor grayColor] };
}
else {
detailBoldAttr = @{ NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]],
NSParagraphStyleAttributeName: ps,
NSForegroundColorAttributeName: [NSColor grayColor] };
}
chapterTableView.defaultEditingColumn = 1;
}
- (NSAttributedString *)boldString:(NSString *)string
{
return [[NSAttributedString alloc] initWithString:string attributes:detailBoldAttr];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)t
{
return [self.track chapterCount];
}
- (id) tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)rowIndex
{
MP42TextSample *chapter = [self.track chapterAtIndex:rowIndex];
if ([tableColumn.identifier isEqualToString:@"time"]) {
return [self boldString:StringFromTime(chapter.timestamp, 1000)];
}
if ([tableColumn.identifier isEqualToString:@"title"]) {
return chapter.title;
}
return nil;
}
- (void)tableView:(NSTableView *)tableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)rowIndex
{
MP42TextSample *chapter = [self.track chapterAtIndex:rowIndex];
if ([tableColumn.identifier isEqualToString:@"title"]) {
if (![chapter.title isEqualToString:anObject]) {
[self.track setTitle:anObject forChapter:chapter];
[self.view.window.windowController.document updateChangeCount:NSChangeDone];
}
}
else if ([tableColumn.identifier isEqualToString:@"time"]) {
MP42Duration timestamp = TimeFromString(anObject, 1000);
if (!(chapter.timestamp == timestamp)) {
[self.track setTimestamp:timestamp forChapter:chapter];
[chapterTableView reloadData];
[self.view.window.windowController.document updateChangeCount:NSChangeDone];
}
}
}
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
if (chapterTableView.selectedRow != -1) {
[removeChapter setEnabled:YES];
}
else {
[removeChapter setEnabled:NO];
}
}
- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
if ([tableColumn.identifier isEqualToString:@"time"]) {
if ([tableView.selectedRowIndexes containsIndex:rowIndex]) {
// Without this, the color won't change because
// we are using a attributed string.
NSMutableAttributedString *highlightedString = [[NSMutableAttributedString alloc] initWithAttributedString:[cell attributedStringValue]];
[highlightedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, highlightedString.length)];
[cell setAttributedStringValue:highlightedString];
[cell setTextColor:[NSColor blackColor]];
}
else {
[cell setTextColor:[NSColor grayColor]];
}
}
}
- (IBAction)removeChapter:(id)sender {
NSInteger current_index = chapterTableView.selectedRow;
if (current_index < [self.track chapterCount]) {
[self.track removeChapterAtIndex:current_index];
[chapterTableView reloadData];
[self.view.window.windowController.document updateChangeCount:NSChangeDone];
}
}
- (IBAction)addChapter:(id)sender {
[self.track addChapter:@"Chapter" duration:0];
[chapterTableView reloadData];
[self.view.window.windowController.document updateChangeCount:NSChangeDone];
}
- (IBAction)renameChapters:(id)sender {
[self.track.chapters enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *title = [NSString stringWithFormat:@"Chapter %lu", (unsigned long) idx + 1];
[self.track setTitle:title forChapter:(MP42TextSample *)obj];
}];
[chapterTableView reloadData];
[self.view.window.windowController.document updateChangeCount:NSChangeDone];
}
@end
+1 -2
View File
@@ -10,7 +10,6 @@ NSString *SublerMetadataPBoardType = @"SublerMetadataPBoardTypeV2";
NSString *SublerCoverArtPBoardType = @"SublerCoverArtPBoardType";
#import "SBMovieViewController.h"
#import "SBImageBrowserView.h"
#import <MP42Foundation/MP42Ratings.h>
#import <MP42Foundation/MP42Image.h>
@@ -982,7 +981,7 @@ static NSArray<NSArray *> *_mediaKinds;
return itemIndexes.count;
}
- (void)_pasteToImageBrowserView:(IKImageBrowserView *)ImageBrowserView
- (void)pasteToImageBrowserView:(SBImageBrowserView *)imagebrowserview
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *items = nil;
@@ -0,0 +1,114 @@
//
// SoundViewController.swift
// Subler
//
// Created by Damiano Galassi on 11/11/2017.
//
import Cocoa
class SoundViewController : NSViewController {
var track: MP42AudioTrack {
didSet {
}
}
let fallbacks: [MP42AudioTrack]
let follows: [MP42SubtitleTrack]
let mediaTagsController: SBMediaTagsController
@IBOutlet var mediaTagsView: NSView!
@IBOutlet var volume: NSSlider!
@IBOutlet var alternateGroup: NSPopUpButton!
@IBOutlet var fallback: NSPopUpButton!
@IBOutlet var follow: NSPopUpButton!
override var nibName: NSNib.Name? {
return NSNib.Name(rawValue: "SoundView")
}
init(mp4: MP42File, track: MP42AudioTrack) {
self.track = track
self.fallbacks = Array()
self.follows = Array()
self.mediaTagsController = SBMediaTagsController(track: track)
super.init(nibName: self.nibName, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func loadView() {
super.loadView()
// Media Tags controls
mediaTagsController.view.frame = mediaTagsView.bounds
mediaTagsController.view.autoresizingMask = [.width, .height]
mediaTagsView.addSubview(mediaTagsController.view)
// Standard audio controls
alternateGroup.selectItem(at: Int(track.alternateGroup))
}
// MARK: Actions
private func updateChangeCount() {
view.window?.windowController?.document?.updateChangeCount(NSDocument.ChangeType.changeDone)
}
@IBAction func setTrackVolume(_ sender: NSSlider) {
let value = sender.floatValue / 100
if value != track.volume {
track.volume = value
updateChangeCount()
}
}
@IBAction func seTracktFallback(_ sender: NSPopUpButton) {
let index = sender.tag
if index > -1 {
let newFallbackTrack = fallbacks[index]
if newFallbackTrack != track.fallbackTrack {
track.fallbackTrack = newFallbackTrack
updateChangeCount()
}
}
else {
track.fallbackTrack = nil
updateChangeCount()
}
}
@IBAction func setTrackFollows(_ sender: NSPopUpButton) {
let index = sender.tag
if index > -1 {
let newFollowskTrack = follows[index]
if newFollowskTrack != track.followsTrack {
track.followsTrack = newFollowskTrack
updateChangeCount()
}
}
else {
track.followsTrack = nil
updateChangeCount()
}
}
@IBAction func setTrackAlternateGroup(_ sender: NSPopUpButton) {
if let group = sender.selectedItem?.tag {
if track.alternateGroup != group {
track.alternateGroup = UInt64(group)
updateChangeCount()
}
}
}
}
+1 -3
View File
@@ -13,7 +13,6 @@
#import "SBMovieViewController.h"
#import "SBVideoViewController.h"
#import "SBSoundViewController.h"
#import "SBChapterViewController.h"
#import <MP42Foundation/MP42File.h>
#import <MP42Foundation/MP42FileImporter.h>
@@ -720,8 +719,7 @@ static NSDictionary *_detailMonospacedAttr;
controller = [[SBMovieViewController alloc] initWithNibName:@"MovieView" bundle:nil];
[(SBMovieViewController *)controller setMetadata:self.mp4.metadata];
} else if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
controller = [[SBChapterViewController alloc] initWithNibName:@"ChapterView" bundle:nil];
[controller setTrack:track];
controller = [[SBChapterViewController alloc] initWithTrack:track];
} else if ([track isKindOfClass:[MP42VideoTrack class]]) {
controller = [[SBVideoViewController alloc] initWithNibName:@"VideoView" bundle:nil];
[controller setTrack:track];
-26
View File
@@ -1,26 +0,0 @@
//
// SBImageBrowserView.h
// Subler
//
// Created by Damiano Galassi on 02/09/13.
//
//
#import <Quartz/Quartz.h>
NS_ASSUME_NONNULL_BEGIN
@protocol SBImageBrowserViewDelegate
@optional
- (void)_pasteToImageBrowserView:(IKImageBrowserView *)ImageBrowserView;
@end
@interface SBImageBrowserView : IKImageBrowserView
@property(nonatomic, readwrite, strong) NSArray<NSString *> *pasteboardTypes;
@end
NS_ASSUME_NONNULL_END
-60
View File
@@ -1,60 +0,0 @@
//
// SBImageBrowserView.m
// Subler
//
// Created by Damiano Galassi on 02/09/13.
//
//
#import "SBImageBrowserView.h"
@implementation SBImageBrowserView
- (instancetype)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_pasteboardTypes = @[];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
_pasteboardTypes = @[];
}
return self;
}
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
id delegate = [self delegate];
SEL action = item.action;
if (action == @selector(paste:)) {
if (![self pasteboardHasSupportedType] || ![delegate respondsToSelector:@selector(_pasteToImageBrowserView:)]) {
return NO;
} else {
return YES;
}
} else {
return [super validateMenuItem:item];
}
}
- (IBAction)paste:(id)sender
{
if ([[self delegate] respondsToSelector:@selector(_pasteToImageBrowserView:)])
[(id <SBImageBrowserViewDelegate>)[self delegate] _pasteToImageBrowserView:self];
}
- (BOOL)pasteboardHasSupportedType {
// has the pasteboard got a type we support?
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSString *bestType = [pb availableTypeFromArray:self.pasteboardTypes];
return (bestType != nil);
}
@end
-31
View File
@@ -1,31 +0,0 @@
//
// SBItemViewController.h
// Subler
//
// Created by Damiano Galassi on 19/03/14.
//
//
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@class SBQueueItem;
@protocol SBItemViewDelegate <NSObject>
- (void)setPopoverSize:(NSSize)size;
- (void)editItem:(SBQueueItem *)item;
@end
@interface SBItemViewController : NSViewController
@property (nonatomic, readonly) SBQueueItem *item;
@property (nonatomic, unsafe_unretained, readwrite) id<SBItemViewDelegate> delegate;
- (instancetype)initWithItem:(SBQueueItem *)item;
@end
NS_ASSUME_NONNULL_END
-106
View File
@@ -1,106 +0,0 @@
//
// SBItemViewController.m
// Subler
//
// Created by Damiano Galassi on 19/03/14.
//
//
#import "SBItemViewController.h"
#import "SBQueueItem.h"
static void *SBItemViewContex = &SBItemViewContex;
#define TABLE_ROW_HEIGHT 16
@interface SBItemViewController ()
{
id<SBItemViewDelegate> __unsafe_unretained _delegate;
}
@property (nonatomic) SBQueueItem *item;
@property (nonatomic, weak) IBOutlet NSButton *editButton;
@property (nonatomic, weak) IBOutlet NSProgressIndicator *spinner;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *tableHeight;
@end
@implementation SBItemViewController
@synthesize item = _item;
@synthesize delegate = _delegate;
@synthesize editButton = _editButton;
@synthesize spinner = _spinner;
- (instancetype)initWithItem:(SBQueueItem *)item {
self = [self init];
if (self) {
_item = item;
}
return self;
}
- (instancetype)init {
self = [super initWithNibName:@"QueueItem" bundle:nil];
return self;
}
- (void)loadView {
[super loadView];
// Observe the item status
[self addObserver:self
forKeyPath:@"item.status"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:SBItemViewContex];
// Observe the item actions
[self addObserver:self
forKeyPath:@"item.actions"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:SBItemViewContex];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == SBItemViewContex) {
// Disable the edit button if the item status
// is different from ready
if ([keyPath isEqualToString:@"item.status"]) {
SBQueueItemStatus newStatus = [[change valueForKey:NSKeyValueChangeNewKey] integerValue];
dispatch_async(dispatch_get_main_queue(), ^{
if (newStatus != SBQueueItemStatusReady && newStatus != SBQueueItemStatusEditing) {
[self.editButton setEnabled:NO];
} else {
[self.editButton setEnabled:YES];
}
});
} else if ([keyPath isEqualToString:@"item.actions"]) {
NSInteger count = [change[NSKeyValueChangeNewKey] count] - [change[NSKeyValueChangeOldKey] count];
CGFloat height = TABLE_ROW_HEIGHT * (count >= 0 ? count : 1);
[self.tableHeight setConstant:height];
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (IBAction)edit:(id)sender {
[self.spinner setHidden:NO];
if ([self.delegate respondsToSelector:@selector(editItem:)]) {
[self.delegate editItem:self.item];
}
}
- (void)dealloc {
@try {
[self removeObserver:self forKeyPath:@"item.status"];
[self removeObserver:self forKeyPath:@"item.actions"];
} @catch (NSException * __unused exception) {}
}
@end
-13
View File
@@ -1,13 +0,0 @@
//
// SBLanguageTransformer.h
// Subler
//
// Created by Damiano Galassi on 30/11/16.
//
//
#import <Foundation/Foundation.h>
@interface SBLanguageTransformer : NSValueTransformer
@end
-49
View File
@@ -1,49 +0,0 @@
//
// SBLanguageTransformer.m
// Subler
//
// Created by Damiano Galassi on 30/11/16.
//
//
#import "SBLanguageTransformer.h"
#import <MP42Foundation/MP42Languages.h>
@interface SBLanguageTransformer ()
@property (nonatomic, readonly) MP42Languages *langManager;
@end
@implementation SBLanguageTransformer
- (instancetype)init
{
self = [super init];
if (self) {
_langManager = MP42Languages.defaultManager;
}
return self;
}
+ (Class)transformedValueClass
{
return [NSString class];
}
- (id)transformedValue:(id)value
{
return [self.langManager localizedLangForExtendedTag:value];
}
+ (BOOL)allowsReverseTransformation
{
return YES;
}
- (id)reverseTransformedValue:(id)value
{
return [self.langManager extendedTagForLocalizedLang:value];
}
@end
+1 -3
View File
@@ -11,7 +11,6 @@
#import "SBQueuePreferences.h"
#import "SBOptionsViewController.h"
#import "SBItemViewController.h"
#import "SBDocument.h"
@@ -419,8 +418,7 @@ static void *SBQueueContex = &SBQueueContex;
// the popover retains us and we retain the popover,
// we drop the popover whenever it is closed to avoid a cycle
SBItemViewController *view = [[SBItemViewController alloc] initWithItem:item];
view.delegate = self;
SBItemViewController *view = [[SBItemViewController alloc] initWithItem:item delegate:self];
self.itemPopover.contentViewController = view;
self.itemPopover.animates = YES;