123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784 |
- //
- // SKPresentationOptionsSheetController.swift
- // PDF Reader Pro
- //
- // Created by liujiajie on 2024/1/17.
- //
- import Cocoa
- typealias closePresentationControllerCallBack = (_ vc: SKPresentationOptionsSheetController) -> ()
- let RIGHTARROW_CHARACTER: unichar = 0x2192
- let PAGE_COLUMNID = "page"
- let IMAGE_COLUMNID = "image"
- let TRANSITIONSTYLE_KEY = "transitionStyle"
- let DURATION_KEY = "duration"
- let SHOULDRESTRICT_KEY = "shouldRestrict"
- let PROPERTIES_KEY = "properties"
- let CONTENTOBJECT_BINDINGNAME = "contentObject"
- let MAX_PAGE_COLUMN_WIDTH: CGFloat = 100.0
- let TABLE_OFFSET: CGFloat = 8.0
- //var SKTransitionPropertiesObservationContext = UnsafeMutableRawPointer(mutating: "SKTransitionPropertiesObservationContext")
- var SKPDFViewTransitionsObservationContext: CChar?
- class SKPresentationOptionsSheetController: KMBaseWindowController {
- @IBOutlet var notesDocumentPopUpButton: NSPopUpButton!
- @IBOutlet var tableView: KMBotaTableView!
- @IBOutlet var separateCheckButton: NSButton!
- @IBOutlet var boxes, transitionLabels, transitionControls, buttons: NSArray!
- @IBOutlet var effectPopUpButton: NSPopUpButton!
- @IBOutlet var effectLabel: NSTextField!
- @IBOutlet var durationLabel: NSTextField!
- @IBOutlet var durationSlider: NSSlider!
- @IBOutlet var durationTF: NSTextField!
- @IBOutlet var extentLabel: NSTextField!
- @IBOutlet var screeBtn: NSButtonCell!
- @IBOutlet var pageBtn: NSButtonCell!
- @IBOutlet var synchoronizBox: NSBox!
- @IBOutlet var cancelBtn: NSButton!
- @IBOutlet var okBtn: NSButton!
- @IBOutlet var pageTransitionBox: NSBox!
-
- var closeCallBack: closePresentationControllerCallBack?
- var separate = false
- var transition: KMTransitionInfo = KMTransitionInfo()
- private var transitions_: NSArray?
- var transitions: NSArray? {
- get {
- return self.transitions_
- }
- set{
- if self.transitions_ != newValue {
- // (undoRedoManager?.prepare(withInvocationTarget: self) as AnyObject).transitions = transitions
- self.transitions_ = newValue
- if let data = self.transitions as? [KMTransitionInfo] {
- stopObservingTransitions(infos: data)
- startObservingTransitions(data)
- }
- }
- }
- }
- var currentTransitions: NSArray? {
- get{
- return self.separate ? self.transitions : [transition as Any]
- }
- }
- var pageTransitions: NSArray? {
- get{
- if self.separate && self.transitions?.count ?? 0 > 0 {
- return transforArr()//[transitions?.value(forKey: PROPERTIES_KEY) as Any]
- }
- return nil
- }
- }
- var notesDocument: NSDocument? {
- get{
- _ = self.window
- return self.notesDocumentPopUpButton.selectedItem?.representedObject as? NSDocument
- }
- }
- var isScrolling: Bool {
- get{
- let scroller = self.tableView?.enclosingScrollView?.verticalScroller as? KMScroller
- return scroller?.isScrolling ?? false
- }
- }
- var undoRedoManager = UndoManager()
- weak var controller: KMMainViewController?
- weak var transitionController: SKTransitionController?
-
- private weak var proxyDelegate_: SKTransitionControllerDelegate?
-
- // class func keyPathsForValuesAffectingCurrentTransitions() -> Set<String> {
- // return Set<String>(["separate", "transitions", "transition"])
- // }
-
- override var windowNibName: NSNib.Name?{
- return "TransitionSheet"
- }
-
- override init(window: NSWindow?) {
- super.init(window: window)
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- }
- deinit {
- NSLog("===SKPresentationOptionsSheetController==")
- }
- override func windowDidLoad() {
- super.windowDidLoad()
-
- let count: Int = SKTransitionController.transitionNames().count
- for i in 0..<count {
- self.effectPopUpButton.addItem(withTitle: SKTransitionController.localizedName(for: SKAnimationTransitionStyle(rawValue: UInt(i)) ?? .noTransition))
- self.effectPopUpButton.lastItem?.tag = i
- }
- self.notesDocumentPopUpButton.item(at: 0)?.title = NSLocalizedString("None", comment: "")
- // creatTransitionController()
- let transitionController = self.controller?.listView.transitionController
- self.proxyDelegate_ = transitionController?.delegate
- transitionController?.delegate = self
- self.transitionController = transitionController
- self.transition.transitionStyle = transitionController?.transitionStyle ?? .noTransition
- self.transition.duration = Float(transitionController?.duration ?? 0)
- self.transition.shouldRestrict = transitionController?.shouldRestrict ?? false
- self.startObservingTransitions([self.transition])
- self.pageTransitionBox.title = KMLocalizedString("Page Transition")
- self.effectLabel.stringValue = NSLocalizedString("Effect:", comment: "")
- self.durationLabel.stringValue = NSLocalizedString("Duration:", comment: "")
- self.extentLabel.stringValue = NSLocalizedString("Extent:", comment: "")
- self.screeBtn.title = KMLocalizedString("Screen")
- self.pageBtn.title = KMLocalizedString("Page")
- separateCheckButton.title = NSLocalizedString("Distinct page transitions", comment: "")
- self.separateCheckButton.sizeToFit()
- self.synchoronizBox.title = KMLocalizedString("Synchronized Notes Document")
- cancelBtn.title = NSLocalizedString("Cancel", comment: "")
- okBtn.title = NSLocalizedString("OK", comment: "")
-
- SKAutoSizeButtons(buttons as? [Any], true)
- let dw = SKAutoSizeLabelFields(transitionLabels as? [Any], transitionControls as? [Any], false)
- if abs(dw) > 0.0 {
- SKResizeWindow(self.window, dw)
- SKShiftAndResizeViews(self.boxes as? [Any], -dw, dw)
- SKShiftAndResizeView(self.separateCheckButton, -dw, 0.0)
- }
- // collapse the table
- self.window?.setFrame(NSInsetRect(window?.frame ?? .zero, 0.5 * (NSWidth(tableView.enclosingScrollView?.frame ?? .zero) + TABLE_OFFSET), 0.0), display: false)
- // self.tableView.registerForDraggedTypes(KMTransitionInfo.readableTypesForPasteboard(pasteboard: NSPasteboard(name: NSPasteboard.Name.drag)) as! [NSPasteboard.PasteboardType])
- self.tableView.registerForDraggedTypes(KMTransitionInfo.readableTypes(for: NSPasteboard(name: .drag)))
- self.tableView.delegate = self
- self.tableView.dataSource = self
- self.tableView.botaDelegate = self
- self.tableView.setTypeSelectHelper(SKTypeSelectHelper(matchOption: .SKFullStringMatch))
- self.tableView.hasImageToolTips = true
- self.tableView.backgroundColor = NSColor.mainSourceListBackgroundColor()
- if (transitionController?.pageTransitions != nil && transitionController?.pageTransitions.count ?? 0 > 0) {
- self.undoRedoManager.disableUndoRegistration()
- self.separate = true
- self.undoRedoManager.enableUndoRegistration()
- }
- // set the current notes document and observe changes for the popup
- self.handleDocumentsDidChangeNotification(notification: nil)
- let docIndex = self.notesDocumentPopUpButton.indexOfItem(withRepresentedObject: self.controller?.myDocument/*presentationNotesDocument*/)
- self.notesDocumentPopUpButton.selectItem(at: docIndex > 0 ? docIndex : 0)
-
- NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentsDidChangeNotification(notification:)), name: NSNotification.Name("SKDocumentDidShowNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentsDidChangeNotification(notification:)), name: NSNotification.Name("SKDocumentControllerDidRemoveDocumentNotification"), object: nil)
- }
-
- override func initDefaultValue() {
- super.initDefaultValue()
-
- self.effectPopUpButton.target = self
- self.effectPopUpButton.action = #selector(effectButtonAction)
-
- self.durationTF.formatter = NumberFormatter()
- self.durationTF.delegate = self
-
- self.screeBtn.target = self
- self.screeBtn.action = #selector(extentAction)
- self.pageBtn.target = self
- self.pageBtn.action = #selector(extentAction)
- }
-
- func stopObservingTransitions(infos: [KMTransitionInfo]) {
- // for info in infos {
- // info.removeObserver(self, forKeyPath: TRANSITIONSTYLE_KEY)
- // info.removeObserver(self, forKeyPath: DURATION_KEY)
- // info.removeObserver(self, forKeyPath: SHOULDRESTRICT_KEY)
- // }
- }
-
- // func creatTransitionController() {
- // transitionController = SKTransitionController(for: controller?.listView)//controller?.mainViewController.listView.transitionController
- // let options: NSKeyValueObservingOptions = [.new, .old]
- // transitionController?.addObserver(self, forKeyPath: "transitionStyle", options: options, context: &SKPDFViewTransitionsObservationContext)
- // transitionController?.addObserver(self, forKeyPath: "duration", options: options, context: &SKPDFViewTransitionsObservationContext)
- // transitionController?.addObserver(self, forKeyPath: "shouldRestrict", options: options, context: &SKPDFViewTransitionsObservationContext)
- // transitionController?.addObserver(self, forKeyPath: "pageTransitions", options: options, context: &SKPDFViewTransitionsObservationContext)
- // }
-
- func startObservingTransitions(_ infos: [KMTransitionInfo]) {
- // for info in infos {
- // info.addObserver(self, forKeyPath: TRANSITIONSTYLE_KEY, options: [.new, .old], context: &SKTransitionPropertiesObservationContext)
- // info.addObserver(self, forKeyPath: DURATION_KEY, options: [.new, .old], context: &SKTransitionPropertiesObservationContext)
- // info.addObserver(self, forKeyPath: SHOULDRESTRICT_KEY, options: [.new, .old], context: &SKTransitionPropertiesObservationContext)
- // }
- }
-
- func setValue(_ value: Any?, forKey key: String, ofTransition info: KMTransitionInfo) {
- info.setValue(value, forKey: key)
- }
- // override class func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
- // if context == &SKTransitionPropertiesObservationContext {
- // guard let info = object as? KMTransitionInfo else {
- // super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
- // return
- // }
- // let newValue = change?[.newKey]
- // let oldValue = change?[.oldKey]
- //
- // let newNonNullValue = newValue as? NSNull == nil ? newValue : nil
- // let oldNonNullValue = oldValue as? NSNull == nil ? oldValue : nil
- //
- //// if (newNonNullValue != nil || oldNonNullValue != nil) && newNonNullValue != oldNonNullValue {
- //// (undoManager?.prepare(withInvocationTarget: self) as AnyObject).setValue(oldNonNullValue, forKey: keyPath, ofTransition: info)
- //// }
- // if (newNonNullValue != nil || oldNonNullValue != nil){
- //
- // }
- // } else {
- // super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
- // }
- // }
-
- // MARK: - Private
-
- private func makeTransitions() {
- if transitions != nil {
- return
- }
-
- let tableColumn = self.tableView?.tableColumn(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: PAGE_COLUMNID))
- let cell = tableColumn?.dataCell
- var labelWidth: CGFloat = 0.0
-
- var array = [Any]()
- let dictionary: NSDictionary? = self.transition.properties
- let arr: NSArray? = self.transitionController?.pageTransitions as NSArray?
- let ptEnum = arr?.objectEnumerator()
- var tn: KMThumbnail? = nil
-
- for next in (controller?.leftSideViewController.thumbnails) ?? [] {
- if tn != nil {
- let info = KMTransitionInfo()
- info.thumbnail = tn
- info.label = "\(tn?.label ?? "")"+"→"+"\(next.label)"
- info.properties = ((ptEnum?.nextObject()) != nil) ? ptEnum?.nextObject() as? NSDictionary : dictionary
- array.append(info)
- // (cell as AnyObject).setStringValue(info.label)
- // labelWidth = max(labelWidth, ceil(((cell as AnyObject).cellSize?.width) ?? 0))
- }
- tn = next
- }
-
- labelWidth = min(labelWidth, MAX_PAGE_COLUMN_WIDTH)
- tableColumn?.minWidth = labelWidth
- tableColumn?.maxWidth = labelWidth
- tableColumn?.width = labelWidth
-
- var frame: NSRect = self.tableView?.enclosingScrollView?.frame ?? .zero
- let wi: CGFloat = 61//tableColumn?.value(forKeyPath: "@sum.width") as! CGFloat
- frame.size.width = 19.0 + wi
- self.tableView?.enclosingScrollView?.frame = frame
-
- self.transitions = array as NSArray
- }
-
- @objc dynamic func changePageTransitionType(sep: Bool) {
- // SKImageToolTipWindow.sharedToolTipWindow().orderOut(nil)
- self.separate = sep
- self.separateCheckButton.state = sep ? .on : .off
-
- let window = self.window
- let isVisible = window?.isVisible ?? false
- var frame = window?.frame ?? NSRect.zero
- let scrollView = tableView?.enclosingScrollView
- var extraWidth: CGFloat
- let firstResponder = window?.firstResponder
- var editor: NSTextView? = nil
-
- if let textView = firstResponder as? NSTextView {
- editor = textView
- if textView.isFieldEditor {
- // firstResponder = textView.delegate
- }
- }
-
- if let editor = editor, window?.firstResponder != editor {
- window?.makeFirstResponder(firstResponder)
- }
-
- if sep {
- makeTransitions()
-
- extraWidth = (scrollView?.frame.width ?? 0) + TABLE_OFFSET
- frame.size.width += extraWidth
- frame.origin.x -= floor(0.5 * extraWidth)
- window?.setFrame(frame, display: isVisible, animate: isVisible)
- scrollView?.isHidden = false
- } else {
- scrollView?.isHidden = true
- extraWidth = (scrollView?.frame.width ?? 0) + TABLE_OFFSET
- frame.size.width -= extraWidth
- frame.origin.x += floor(0.5 * extraWidth)
- window?.setFrame(frame, display: isVisible, animate: isVisible)
- }
-
- (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).changePageTransitionType(sep: sep == false)
- }
-
- func selectedInfos() -> [KMTransitionInfo]? {
- if self.separate == false {
- return [self.transition]
- } else {
- guard let trans = self.transitions else {
- return nil
- }
- let ris = self.tableView.selectedRowIndexes
- var infos: [KMTransitionInfo] = []
- for ri in ris {
- if ri >= trans.count {
- continue
- }
- if let info = trans.object(at: ri) as? KMTransitionInfo {
- infos.append(info)
- }
- }
- return infos
- }
- }
-
- private func _updateInfo(key: String, value: Any) {
- if key == KMTransitionStyleName {
- let _value = value as? SKAnimationTransitionStyle ?? .noTransition
- if self.separate == false {
- self.transition.transitionStyle = _value
- } else {
- guard let trans = self.transitions else {
- return
- }
- let ris = self.tableView.selectedRowIndexes
- for ri in ris {
- if ri >= trans.count {
- continue
- }
- let info = trans.object(at: ri) as? KMTransitionInfo
- info?.transitionStyle = _value
- }
- }
- } else if key == KMDurationName {
- let _value = value as? Float ?? 0
- if self.separate == false {
- self.transition.duration = _value
- } else {
- guard let trans = self.transitions else {
- return
- }
- let ris = self.tableView.selectedRowIndexes
- for ri in ris {
- if ri >= trans.count {
- continue
- }
- let info = trans.object(at: ri) as? KMTransitionInfo
- info?.duration = _value
- }
- }
- } else if key == KMShouldRestrictName {
- let _value = value as? Bool ?? false
- if self.separate == false {
- self.transition.shouldRestrict = _value
- } else {
- guard let trans = self.transitions else {
- return
- }
- let ris = self.tableView.selectedRowIndexes
- for ri in ris {
- if ri >= trans.count {
- continue
- }
- let info = trans.object(at: ri) as? KMTransitionInfo
- info?.shouldRestrict = _value
- }
- }
- }
- }
-
- // Actions
-
- @objc func effectButtonAction(sender: NSPopUpButton) {
- let index = sender.indexOfSelectedItem
- let names = SKTransitionController.transitionNames() as? [String]
- let name = names?.safe_element(for: index) as? String ?? ""
- let type = SKTransitionController.style(forName: name)
-
- guard let infos = self.selectedInfos(), infos.isEmpty == false else {
- NSSound.beep()
- return
- }
-
- for info in infos {
- if info.transitionStyle != type { // undo
- // let oldValue = info.transitionStyle
- self.undo_effectAction(info: info, key: KMTransitionStyleName, value: type, popup: nil)
- }
- }
-
- // self._updateInfo(key: KMTransitionStyleName, value: type)
- }
-
- @objc dynamic func undo_effectAction(info: KMTransitionInfo, key: String, value: Any, popup: NSPopUpButton?) {
- if key == KMTransitionStyleName {
- let oldValue = info.transitionStyle
- (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).undo_effectAction(info: info, key: key, value: oldValue, popup: self.effectPopUpButton)
-
- info.transitionStyle = value as? SKAnimationTransitionStyle ?? .noTransition
- popup?.selectItem(at: Int(info.transitionStyle.rawValue))
- }
- }
-
- @objc func extentAction(sender: NSMatrix) {
- // let isScreen = sender.isEqual(to: self.screeBtn)
- // self.screeBtn.state = isScreen ? .on : .off
- // self.pageBtn.state = isScreen ? .off : .on
- // let value = self.pageBtn. == .on
- let value = sender.selectedTag() == 1 ? true : false
-
- // (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).extentAction(sender: sender)
- self.undoRedoManager.registerUndo(withTarget: self) { target in
- if value {
- target.screeBtn.performClick(nil)
- } else {
- target.pageBtn.performClick(nil)
- }
- }
-
- self._updateInfo(key: KMShouldRestrictName, value: value)
- }
- func transforArr() -> NSArray {
- let arr = NSMutableArray()
- for i in 0..<(transitions?.count ?? 0) {
- if let item = transitions?[i] as? KMTransitionInfo {
- let dic = NSMutableDictionary.init()
- dic.setValue(item.duration, forKey: "duration")
- dic.setValue(item.shouldRestrict, forKey: "shouldRestrict")
- dic.setValue(item.properties?[SKStyleNameKey], forKey: "styleName")
- arr.add(dic)
- }
- }
- return arr
- }
-
- @IBAction func pageTransitionAction(_ sender: NSButton) {
- self.separate = sender.state == .on
-
- self.changePageTransitionType(sep: self.separate)
- Task { @MainActor in
- self.tableView.reloadData()
- }
- }
-
- @IBAction func changeDurationSlider(_ sender: NSSlider) {
- // self.durationTF.stringValue = sender.stringValue
-
- guard let infos = self.selectedInfos(), infos.isEmpty == false else {
- NSSound.beep()
- return
- }
-
- for info in infos {
- if info.duration != sender.floatValue { // undo
- self.undo_sliderAction(info: info, key: KMDurationName, value: sender.floatValue, slider: nil, textF: self.durationTF)
- }
- }
-
- // 更新数据
- // self._updateInfo(key: KMDurationName, value: sender.floatValue)
- }
-
- @objc func undo_sliderAction(info: KMTransitionInfo, key: String, value: Any, slider: NSSlider?, textF: NSTextField?) {
- if key == KMDurationName {
- let oldValue = info.duration
- (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).undo_sliderAction(info: info, key: key, value: oldValue, slider: self.durationSlider, textF: self.durationTF)
-
- let duration = value as? Float ?? 0
- slider?.floatValue = duration
- textF?.floatValue = duration
- }
- }
-
- @IBAction func cancelAction(_ sender: Any) {
- if let handle = self.closeCallBack {
- handle(self)
- }
- }
-
- @IBAction func okAction(_ sender: Any) {
- if let handle = self.closeCallBack {
- handle(self)
- }
-
- if self.undoRedoManager.canUndo {
- self.transitionController?.transitionStyle = transition.transitionStyle
- self.transitionController?.duration = CGFloat(transition.duration)
- self.transitionController?.shouldRestrict = transition.shouldRestrict
- self.transitionController?.pageTransitions = pageTransitions as? [Any]
- (self.controller?.undoManager)?.setActionName(NSLocalizedString("Change Transitions", comment: "Undo action name"))
- }
- // self.controller?.myDocument/*presentationNotesDocument*/ = notesDocument
- }
-
- // Noti Actions
-
- @objc private func handleDocumentsDidChangeNotification(notification: Notification?) {
- let currentDoc = self.notesDocumentPopUpButton.selectedItem?.representedObject as? NSDocument
- while self.notesDocumentPopUpButton.numberOfItems > 1 {
- self.notesDocumentPopUpButton.removeItem(at: self.notesDocumentPopUpButton.numberOfItems - 1)
- }
- // var doc: NSDocument?
- let document = self.controller?.myDocument
-
- let documents = NSMutableArray()
- let pageCount = self.controller?.document?.pageCount ?? 0
- for doc in NSDocumentController.shared.documents {
- guard let mainDoc = doc as? KMMainDocument else {
- continue
- }
- if mainDoc.isHome {
- continue
- }
- if mainDoc.isEqual(to: document) {
- continue
- }
- if let pdfDoc = mainDoc.mainViewController?.document {
- if pdfDoc.pageCount == pageCount {
- documents.add(doc)
- }
- }
- }
- let sortDescriptor = NSSortDescriptor(key: "displayName", ascending: true)
- documents.sort(using: [sortDescriptor])
- for doc in documents {
- self.notesDocumentPopUpButton.addItem(withTitle: (doc as AnyObject).displayName)
- self.notesDocumentPopUpButton.lastItem?.representedObject = doc
- }
- let docIndex = self.notesDocumentPopUpButton.indexOfItem(withRepresentedObject: currentDoc)
- self.notesDocumentPopUpButton.selectItem(at: docIndex == -1 ? 0 : docIndex)
- }
- }
- // MARK: - NSTextFieldDelegate
- extension SKPresentationOptionsSheetController: NSTextFieldDelegate {
- func controlTextDidChange(_ obj: Notification) {
- if self.durationTF.isEqual(to: obj.object) {
- self.durationSlider.floatValue = self.durationTF.floatValue
- // 更新数据
- self._updateInfo(key: KMDurationName, value: self.durationTF.floatValue)
- }
- }
- }
- // MARK: - NSWindowDelegate
- extension SKPresentationOptionsSheetController: NSWindowDelegate {
- func windowWillReturnUndoManager(_ window: NSWindow) -> UndoManager? {
- return self.undoRedoManager
- }
- }
- // MARK: - SKTransitionControllerDelegate
- extension SKPresentationOptionsSheetController: SKTransitionControllerDelegate {
- func transitionController(_ controller: SKTransitionController!, valueDidChanged info: [AnyHashable : Any]!) {
- // 消息转发
- self.proxyDelegate_?.transitionController(controller, valueDidChanged: info)
- }
- }
- // MARK: - NSTableViewDelegate, NSTableViewDataSource
- extension SKPresentationOptionsSheetController: NSTableViewDelegate, NSTableViewDataSource {
- func numberOfRows(in tableView: NSTableView) -> Int {
- return self.transitions?.count ?? 0
- }
-
- // func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
- // let identifier = tableColumn?.identifier
- // let info = transitions?[row] as? KMTransitionInfo
- //
- // if let id = identifier?.rawValue, id == PAGE_COLUMNID {
- // let cell = tableColumn?.dataCell as? NSTextFieldCell
- // cell?.stringValue = info?.label ?? ""
- // return info?.label ?? ""
- // } else if let id = identifier?.rawValue, id == IMAGE_COLUMNID {
- // let cell = tableColumn?.dataCell as? NSImageCell
- // let page = self.controller?.listView.document.page(at: UInt(info?.thumbnail?.pageIndex ?? 0))
- // let image = page?.thumbnail(of: page?.bounds.size ?? .zero)
- //
- //// cell?.image = image
- // return image
- //// if let data = page?.PDFListViewTIFFData(for: page?.bounds ?? .zero) {
- //// let image = NSImage(data: data)
- //// cell?.image = image
- //// return image
- //// }
- // }
- // return nil
- // }
- //
- func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- let identifier = tableColumn?.identifier
- let info = transitions?[row] as? KMTransitionInfo
-
- var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMPresentTableViewCell"), owner: self)
- if cell == nil {
- cell = KMPresentTableViewCell(type: .text)
- }
- let myCellView: KMPresentTableViewCell = cell! as! KMPresentTableViewCell
- // if let id = identifier?.rawValue, id == PAGE_COLUMNID {
- // let cellView = KMPresentTableViewCell(type: .text)
- myCellView.label?.stringValue = info?.label ?? ""
- // return cellView
- // } else if let id = identifier?.rawValue, id == IMAGE_COLUMNID {
- // let cellView = KMPresentTableViewCell(type: .img)
- let page = self.controller?.listView.document.page(at: UInt(info?.thumbnail?.pageIndex ?? 0))
- let image = page?.thumbnail(of: page?.bounds.size ?? .zero)
- myCellView.iv?.image = image
- // return cellView
- // }
- return myCellView;
- }
-
- func tableViewSelectionDidChange(_ notification: Notification) {
- if self.tableView.isEqual(to: notification.object) == false {
- return
- }
- let ris = self.tableView.selectedRowIndexes
- if ris.isEmpty {
- return
- }
- var info: KMTransitionInfo?
- if ris.count == 1 {
- info = self.transitions?[ris.first ?? 0] as? KMTransitionInfo
- self.pageTransitionBox.title = KMLocalizedString("Page Transition") + (info?.label ?? "")
- // self.effectPopUpButton.selectItem(at: Int(info?.transitionStyle.rawValue ?? 0))
- // let durationV = info?.duration ?? 0
- // self.durationSlider.animator().floatValue = durationV
- // self.durationTF.floatValue = durationV
- // let shouldRestrict = info?.shouldRestrict ?? false
- // if shouldRestrict { // 1
- // self.pageBtn.state = .on
- // self.screeBtn.state = .off
- // } else {
- // self.screeBtn.state = .on
- // self.pageBtn.state = .off
- // }
- } else {
- self.pageTransitionBox.title = KMLocalizedString("Page Transition")
- info = self.transition
- }
-
- self.effectPopUpButton.selectItem(at: Int(info?.transitionStyle.rawValue ?? 0))
- let durationV = info?.duration ?? 0
- self.durationSlider.animator().floatValue = durationV
- self.durationTF.floatValue = durationV
- let shouldRestrict = info?.shouldRestrict ?? false
- if shouldRestrict { // 1
- self.pageBtn.state = .on
- self.screeBtn.state = .off
- } else {
- self.screeBtn.state = .on
- self.pageBtn.state = .off
- }
- }
-
- // func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
- // if rowIndexes.count == 1 {
- // pboard.clearContents()
- // let info = KMTransitionInfo.readableTypesForPasteboard(pasteboard: NSPasteboard(name: NSPasteboard.Name.drag))
- // let ind: Int = rowIndexes.first ?? 0
- // let arr = NSArray(objects: transitions![ind])
- // pboard.writeObjects(arr as! [NSPasteboardWriting])
- // return true
- // } else {
- // return false
- // }
- // }
-
- func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
- if rowIndexes.count == 1 {
- if let data = transitions?[rowIndexes.first ?? 0] as? NSPasteboardWriting {
- pboard.clearContents()
- pboard.writeObjects([data])
- }
- return true
- } else {
- return false
- }
- }
-
- func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
- // if info.draggingPasteboard.canReadObject(forClasses: [KMTransitionInfo.self], options: [:]) {
- // if dropOperation == .above {
- // tableView.setDropRow(-1, dropOperation: .on)
- // }
- // return .every
- // }
- return NSDragOperation(rawValue: 0)
- }
-
- func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
- // let pboard = info.draggingPasteboard
- // if dropOperation == .on {
- // guard let infos = pboard.readObjects(forClasses: [KMTransitionInfo.self], options: [:]) as? [KMTransitionInfo], infos.count > 0 else {
- // return false
- // }
- // let propertie: NSDictionary? = infos[0].properties
- //
- // if row == -1 {
- // transitions?.setValue(propertie, forKey: PROPERTIES_KEY)
- // } else {
- // let transit: KMTransitionInfo = transitions?[row] as! KMTransitionInfo
- // transit.properties = propertie
- // }
- // return true
- // }
- return false
- }
- }
- extension SKPresentationOptionsSheetController: KMBotaTableViewDelegate {
- func tableView(_ aTableView: NSTableView, imageContextForRow rowIndex: Int) -> AnyObject? {
- return controller?.document?.page(at: UInt(rowIndex))
- }
-
- func tableView(_ aTableView: NSTableView, copyRowsWithIndexes rowIndexes: IndexSet) {
- if let data = transitions?[rowIndexes.first ?? 0] as? NSPasteboardWriting {
- let pboard = NSPasteboard.general
- pboard.clearContents()
- pboard.writeObjects([data])
- }
- }
- func tableView(_ aTableView: NSTableView, canCopyRowsWithIndexes rowIndexes: IndexSet) -> Bool {
- return false
- }
- func tableView(_ aTableView: NSTableView, pasteFromPasteboard pboard: NSPasteboard) {
- // guard let infos = pboard.readObjects(forClasses: [KMTransitionInfo.self], options: [:]) as? [KMTransitionInfo], infos.count > 0 else { return }
- // let arr = transitions?.objects(at: tableView.selectedRowIndexes) as? NSArray
- // arr?.setValue(infos[0].properties, forKey: PROPERTIES_KEY)
- }
- func tableView(_ aTableView: NSTableView, canPasteFromPasteboard pboard: NSPasteboard) -> Bool {
- // return (tableView.selectedRow != -1 && pboard.canReadObject(forClasses: [KMTransitionInfo.self], options: [:]))
- return false
- }
- func tableView(_ aTableView: NSTableView, typeSelectHelperSelectionStrings aTypeSelectHelper: SKTypeSelectHelper) -> NSArray {
- // return transitions?.value(forKeyPath: "thumbnail.label") as! NSArray
- return []
- }
- }
|