SKPresentationOptionsSheetController.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. //
  2. // SKPresentationOptionsSheetController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2024/1/17.
  6. //
  7. import Cocoa
  8. typealias closePresentationControllerCallBack = (_ vc: SKPresentationOptionsSheetController) -> ()
  9. let RIGHTARROW_CHARACTER: unichar = 0x2192
  10. let PAGE_COLUMNID = "page"
  11. let IMAGE_COLUMNID = "image"
  12. let TRANSITIONSTYLE_KEY = "transitionStyle"
  13. let DURATION_KEY = "duration"
  14. let SHOULDRESTRICT_KEY = "shouldRestrict"
  15. let PROPERTIES_KEY = "properties"
  16. let CONTENTOBJECT_BINDINGNAME = "contentObject"
  17. let MAX_PAGE_COLUMN_WIDTH: CGFloat = 100.0
  18. let TABLE_OFFSET: CGFloat = 8.0
  19. //var SKTransitionPropertiesObservationContext = UnsafeMutableRawPointer(mutating: "SKTransitionPropertiesObservationContext")
  20. var SKPDFViewTransitionsObservationContext: CChar?
  21. class SKPresentationOptionsSheetController: KMBaseWindowController {
  22. @IBOutlet var notesDocumentPopUpButton: NSPopUpButton!
  23. @IBOutlet var tableView: KMBotaTableView!
  24. @IBOutlet var separateCheckButton: NSButton!
  25. @IBOutlet var boxes, transitionLabels, transitionControls, buttons: NSArray!
  26. @IBOutlet var effectPopUpButton: NSPopUpButton!
  27. @IBOutlet var effectLabel: NSTextField!
  28. @IBOutlet var durationLabel: NSTextField!
  29. @IBOutlet var durationSlider: NSSlider!
  30. @IBOutlet var durationTF: NSTextField!
  31. @IBOutlet var extentLabel: NSTextField!
  32. @IBOutlet var screeBtn: NSButtonCell!
  33. @IBOutlet var pageBtn: NSButtonCell!
  34. @IBOutlet var synchoronizBox: NSBox!
  35. @IBOutlet var cancelBtn: NSButton!
  36. @IBOutlet var okBtn: NSButton!
  37. @IBOutlet var pageTransitionBox: NSBox!
  38. var closeCallBack: closePresentationControllerCallBack?
  39. var separate = false
  40. var transition: KMTransitionInfo = KMTransitionInfo()
  41. private var transitions_: NSArray?
  42. var transitions: NSArray? {
  43. get {
  44. return self.transitions_
  45. }
  46. set{
  47. if self.transitions_ != newValue {
  48. self.transitions_ = newValue
  49. if let data = self.transitions as? [KMTransitionInfo] {
  50. stopObservingTransitions(infos: data)
  51. startObservingTransitions(data)
  52. }
  53. }
  54. }
  55. }
  56. var currentTransitions: NSArray? {
  57. get{
  58. return self.separate ? self.transitions : [transition as Any]
  59. }
  60. }
  61. var pageTransitions: NSArray? {
  62. get{
  63. if self.separate && self.transitions?.count ?? 0 > 0 {
  64. return transforArr()//[transitions?.value(forKey: PROPERTIES_KEY) as Any]
  65. }
  66. return nil
  67. }
  68. }
  69. var notesDocument: NSDocument? {
  70. get{
  71. _ = self.window
  72. return self.notesDocumentPopUpButton.selectedItem?.representedObject as? NSDocument
  73. }
  74. }
  75. var isScrolling: Bool {
  76. get{
  77. let scroller = self.tableView?.enclosingScrollView?.verticalScroller as? KMScroller
  78. return scroller?.isScrolling ?? false
  79. }
  80. }
  81. var undoRedoManager = UndoManager()
  82. weak var controller: KMMainViewController?
  83. weak var transitionController: SKTransitionController?
  84. private weak var proxyDelegate_: SKTransitionControllerDelegate?
  85. override var windowNibName: NSNib.Name?{
  86. return "TransitionSheet"
  87. }
  88. override init(window: NSWindow?) {
  89. super.init(window: window)
  90. }
  91. required init?(coder: NSCoder) {
  92. super.init(coder: coder)
  93. }
  94. deinit {
  95. NSLog("===SKPresentationOptionsSheetController==")
  96. }
  97. override func windowDidLoad() {
  98. super.windowDidLoad()
  99. let count: Int = SKTransitionController.transitionNames().count
  100. for i in 0..<count {
  101. self.effectPopUpButton.addItem(withTitle: SKTransitionController.localizedName(for: SKAnimationTransitionStyle(rawValue: UInt(i)) ?? .noTransition))
  102. self.effectPopUpButton.lastItem?.tag = i
  103. }
  104. self.notesDocumentPopUpButton.item(at: 0)?.title = NSLocalizedString("None", comment: "")
  105. let transitionController = self.controller?.listView.transitionController
  106. self.proxyDelegate_ = transitionController?.delegate
  107. transitionController?.delegate = self
  108. self.transitionController = transitionController
  109. self.transition.transitionStyle = transitionController?.transitionStyle ?? .noTransition
  110. self.transition.duration = Float(transitionController?.duration ?? 0)
  111. self.transition.shouldRestrict = transitionController?.shouldRestrict ?? false
  112. self.startObservingTransitions([self.transition])
  113. self.pageTransitionBox.title = KMLocalizedString("Page Transition")
  114. self.effectLabel.stringValue = NSLocalizedString("Effect:", comment: "")
  115. self.durationLabel.stringValue = NSLocalizedString("Duration:", comment: "")
  116. self.extentLabel.stringValue = NSLocalizedString("Extent:", comment: "")
  117. self.screeBtn.title = KMLocalizedString("Screen")
  118. self.pageBtn.title = KMLocalizedString("Page")
  119. separateCheckButton.title = NSLocalizedString("Distinct page transitions", comment: "")
  120. self.separateCheckButton.sizeToFit()
  121. self.synchoronizBox.title = KMLocalizedString("Synchronized Notes Document")
  122. cancelBtn.title = NSLocalizedString("Cancel", comment: "")
  123. okBtn.title = NSLocalizedString("OK", comment: "")
  124. SKAutoSizeButtons(buttons as? [Any], true)
  125. let dw = SKAutoSizeLabelFields(transitionLabels as? [Any], transitionControls as? [Any], false)
  126. if abs(dw) > 0.0 {
  127. SKResizeWindow(self.window, dw)
  128. SKShiftAndResizeViews(self.boxes as? [Any], -dw, dw)
  129. SKShiftAndResizeView(self.separateCheckButton, -dw, 0.0)
  130. }
  131. // collapse the table
  132. self.window?.setFrame(NSInsetRect(window?.frame ?? .zero, 0.5 * (NSWidth(tableView.enclosingScrollView?.frame ?? .zero) + TABLE_OFFSET), 0.0), display: false)
  133. self.tableView.registerForDraggedTypes(KMTransitionInfo.readableTypes(for: NSPasteboard(name: .drag)))
  134. self.tableView.delegate = self
  135. self.tableView.dataSource = self
  136. self.tableView.botaDelegate = self
  137. self.tableView.setTypeSelectHelper(SKTypeSelectHelper(matchOption: .SKFullStringMatch))
  138. self.tableView.hasImageToolTips = true
  139. self.tableView.backgroundColor = NSColor(calibratedRed: 0.839216, green: 0.866667, blue: 0.898039, alpha: 1)
  140. if (transitionController?.pageTransitions != nil && transitionController?.pageTransitions.count ?? 0 > 0) {
  141. self.undoRedoManager.disableUndoRegistration()
  142. self.separate = true
  143. self.undoRedoManager.enableUndoRegistration()
  144. }
  145. // set the current notes document and observe changes for the popup
  146. self.handleDocumentsDidChangeNotification(notification: nil)
  147. let docIndex = self.notesDocumentPopUpButton.indexOfItem(withRepresentedObject: self.controller?.myDocument/*presentationNotesDocument*/)
  148. self.notesDocumentPopUpButton.selectItem(at: docIndex > 0 ? docIndex : 0)
  149. NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentsDidChangeNotification(notification:)), name: NSNotification.Name("SKDocumentDidShowNotification"), object: nil)
  150. NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentsDidChangeNotification(notification:)), name: NSNotification.Name("SKDocumentControllerDidRemoveDocumentNotification"), object: nil)
  151. }
  152. override func initDefaultValue() {
  153. super.initDefaultValue()
  154. self.effectPopUpButton.target = self
  155. self.effectPopUpButton.action = #selector(effectButtonAction)
  156. self.durationTF.delegate = self
  157. self.screeBtn.target = self
  158. self.screeBtn.action = #selector(extentAction)
  159. self.pageBtn.target = self
  160. self.pageBtn.action = #selector(extentAction)
  161. }
  162. func stopObservingTransitions(infos: [KMTransitionInfo]) {
  163. }
  164. func startObservingTransitions(_ infos: [KMTransitionInfo]) {
  165. }
  166. func setValue(_ value: Any?, forKey key: String, ofTransition info: KMTransitionInfo) {
  167. info.setValue(value, forKey: key)
  168. }
  169. // MARK: - Private
  170. private func makeTransitions() {
  171. if transitions != nil {
  172. return
  173. }
  174. let tableColumn = self.tableView?.tableColumn(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: PAGE_COLUMNID))
  175. let cell = tableColumn?.dataCell
  176. var labelWidth: CGFloat = 0.0
  177. var array = [Any]()
  178. let dictionary: NSDictionary? = self.transition.properties
  179. let arr: NSArray? = self.transitionController?.pageTransitions as NSArray?
  180. let ptEnum = arr?.objectEnumerator()
  181. var tn: KMThumbnail? = nil
  182. labelWidth = min(labelWidth, MAX_PAGE_COLUMN_WIDTH)
  183. tableColumn?.minWidth = labelWidth
  184. tableColumn?.maxWidth = labelWidth
  185. tableColumn?.width = labelWidth
  186. var frame: NSRect = self.tableView?.enclosingScrollView?.frame ?? .zero
  187. let wi: CGFloat = 61//tableColumn?.value(forKeyPath: "@sum.width") as! CGFloat
  188. frame.size.width = 19.0 + wi
  189. self.tableView?.enclosingScrollView?.frame = frame
  190. self.transitions = array as NSArray
  191. }
  192. @objc dynamic func changePageTransitionType(sep: Bool) {
  193. self.separate = sep
  194. self.separateCheckButton.state = sep ? .on : .off
  195. let window = self.window
  196. let isVisible = window?.isVisible ?? false
  197. var frame = window?.frame ?? NSRect.zero
  198. let scrollView = tableView?.enclosingScrollView
  199. var extraWidth: CGFloat
  200. let firstResponder = window?.firstResponder
  201. var editor: NSTextView? = nil
  202. if let textView = firstResponder as? NSTextView {
  203. editor = textView
  204. if textView.isFieldEditor {
  205. }
  206. }
  207. if let editor = editor, window?.firstResponder != editor {
  208. window?.makeFirstResponder(firstResponder)
  209. }
  210. if sep {
  211. makeTransitions()
  212. extraWidth = (scrollView?.frame.width ?? 0) + TABLE_OFFSET
  213. frame.size.width += extraWidth
  214. frame.origin.x -= floor(0.5 * extraWidth)
  215. window?.setFrame(frame, display: isVisible, animate: isVisible)
  216. scrollView?.isHidden = false
  217. } else {
  218. scrollView?.isHidden = true
  219. extraWidth = (scrollView?.frame.width ?? 0) + TABLE_OFFSET
  220. frame.size.width -= extraWidth
  221. frame.origin.x += floor(0.5 * extraWidth)
  222. window?.setFrame(frame, display: isVisible, animate: isVisible)
  223. }
  224. (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).changePageTransitionType(sep: sep == false)
  225. }
  226. func selectedInfos() -> [KMTransitionInfo]? {
  227. if self.separate == false {
  228. return [self.transition]
  229. } else {
  230. guard let trans = self.transitions else {
  231. return nil
  232. }
  233. let ris = self.tableView.selectedRowIndexes
  234. var infos: [KMTransitionInfo] = []
  235. for ri in ris {
  236. if ri >= trans.count {
  237. continue
  238. }
  239. if let info = trans.object(at: ri) as? KMTransitionInfo {
  240. infos.append(info)
  241. }
  242. }
  243. return infos
  244. }
  245. }
  246. private func _updateInfo(key: String, value: Any) {
  247. if key == KMTransitionStyleName {
  248. let _value = value as? SKAnimationTransitionStyle ?? .noTransition
  249. if self.separate == false {
  250. self.transition.transitionStyle = _value
  251. } else {
  252. guard let trans = self.transitions else {
  253. return
  254. }
  255. let ris = self.tableView.selectedRowIndexes
  256. for ri in ris {
  257. if ri >= trans.count {
  258. continue
  259. }
  260. let info = trans.object(at: ri) as? KMTransitionInfo
  261. info?.transitionStyle = _value
  262. }
  263. }
  264. } else if key == KMDurationName {
  265. let _value = value as? Float ?? 0
  266. if self.separate == false {
  267. self.transition.duration = _value
  268. } else {
  269. guard let trans = self.transitions else {
  270. return
  271. }
  272. let ris = self.tableView.selectedRowIndexes
  273. for ri in ris {
  274. if ri >= trans.count {
  275. continue
  276. }
  277. let info = trans.object(at: ri) as? KMTransitionInfo
  278. info?.duration = _value
  279. }
  280. }
  281. } else if key == KMShouldRestrictName {
  282. let _value = value as? Bool ?? false
  283. if self.separate == false {
  284. self.transition.shouldRestrict = _value
  285. } else {
  286. guard let trans = self.transitions else {
  287. return
  288. }
  289. let ris = self.tableView.selectedRowIndexes
  290. for ri in ris {
  291. if ri >= trans.count {
  292. continue
  293. }
  294. let info = trans.object(at: ri) as? KMTransitionInfo
  295. info?.shouldRestrict = _value
  296. }
  297. }
  298. }
  299. }
  300. // Actions
  301. @objc func effectButtonAction(sender: NSPopUpButton) {
  302. let index = sender.indexOfSelectedItem
  303. let names = SKTransitionController.transitionNames() as? [String]
  304. let name = names?.safe_element(for: index) as? String ?? ""
  305. let type = SKTransitionController.style(forName: name)
  306. guard let infos = self.selectedInfos(), infos.isEmpty == false else {
  307. NSSound.beep()
  308. return
  309. }
  310. for info in infos {
  311. if info.transitionStyle != type { // undo
  312. self.undo_effectAction(info: info, key: KMTransitionStyleName, value: type, popup: nil)
  313. }
  314. }
  315. }
  316. @objc dynamic func undo_effectAction(info: KMTransitionInfo, key: String, value: Any, popup: NSPopUpButton?) {
  317. if key == KMTransitionStyleName {
  318. let oldValue = info.transitionStyle
  319. (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).undo_effectAction(info: info, key: key, value: oldValue, popup: self.effectPopUpButton)
  320. info.transitionStyle = value as? SKAnimationTransitionStyle ?? .noTransition
  321. popup?.selectItem(at: Int(info.transitionStyle.rawValue))
  322. }
  323. }
  324. @objc func extentAction(sender: NSMatrix) {
  325. let value = sender.selectedTag() == 1 ? true : false
  326. self.undoRedoManager.registerUndo(withTarget: self) { target in
  327. if value {
  328. target.screeBtn.performClick(nil)
  329. } else {
  330. target.pageBtn.performClick(nil)
  331. }
  332. }
  333. self._updateInfo(key: KMShouldRestrictName, value: value)
  334. }
  335. func transforArr() -> NSArray {
  336. let arr = NSMutableArray()
  337. for i in 0..<(transitions?.count ?? 0) {
  338. if let item = transitions?[i] as? KMTransitionInfo {
  339. let dic = NSMutableDictionary.init()
  340. dic.setValue(item.duration, forKey: "duration")
  341. dic.setValue(item.shouldRestrict, forKey: "shouldRestrict")
  342. dic.setValue(item.properties?[SKStyleNameKey], forKey: "styleName")
  343. arr.add(dic)
  344. }
  345. }
  346. return arr
  347. }
  348. @IBAction func pageTransitionAction(_ sender: NSButton) {
  349. self.separate = sender.state == .on
  350. self.changePageTransitionType(sep: self.separate)
  351. Task { @MainActor in
  352. }
  353. }
  354. @IBAction func changeDurationSlider(_ sender: NSSlider) {
  355. guard let infos = self.selectedInfos(), infos.isEmpty == false else {
  356. NSSound.beep()
  357. return
  358. }
  359. for info in infos {
  360. if info.duration != sender.floatValue { // undo
  361. self.undo_sliderAction(info: info, key: KMDurationName, value: sender.floatValue, slider: nil, textF: self.durationTF)
  362. }
  363. }
  364. }
  365. @objc func undo_sliderAction(info: KMTransitionInfo, key: String, value: Any, slider: NSSlider?, textF: NSTextField?) {
  366. if key == KMDurationName {
  367. let oldValue = info.duration
  368. (self.undoRedoManager.prepare(withInvocationTarget: self) as AnyObject).undo_sliderAction(info: info, key: key, value: oldValue, slider: self.durationSlider, textF: self.durationTF)
  369. let duration = value as? Float ?? 0
  370. slider?.floatValue = duration
  371. textF?.floatValue = duration
  372. }
  373. }
  374. @IBAction func cancelAction(_ sender: Any) {
  375. if let handle = self.closeCallBack {
  376. handle(self)
  377. }
  378. }
  379. @IBAction func okAction(_ sender: Any) {
  380. if let handle = self.closeCallBack {
  381. handle(self)
  382. }
  383. if self.undoRedoManager.canUndo {
  384. self.transitionController?.transitionStyle = transition.transitionStyle
  385. self.transitionController?.duration = CGFloat(transition.duration)
  386. self.transitionController?.shouldRestrict = transition.shouldRestrict
  387. self.transitionController?.pageTransitions = pageTransitions as? [Any]
  388. (self.controller?.undoManager)?.setActionName(NSLocalizedString("Change Transitions", comment: "Undo action name"))
  389. }
  390. }
  391. // Noti Actions
  392. @objc private func handleDocumentsDidChangeNotification(notification: Notification?) {
  393. let currentDoc = self.notesDocumentPopUpButton.selectedItem?.representedObject as? NSDocument
  394. while self.notesDocumentPopUpButton.numberOfItems > 1 {
  395. self.notesDocumentPopUpButton.removeItem(at: self.notesDocumentPopUpButton.numberOfItems - 1)
  396. }
  397. let document = self.controller?.myDocument
  398. let documents = NSMutableArray()
  399. let pageCount = self.controller?.document?.pageCount ?? 0
  400. for doc in NSDocumentController.shared.documents {
  401. guard let mainDoc = doc as? KMMainDocument else {
  402. continue
  403. }
  404. if mainDoc.isHome {
  405. continue
  406. }
  407. if mainDoc.isEqual(to: document) {
  408. continue
  409. }
  410. if let pdfDoc = mainDoc.mainViewController?.document {
  411. if pdfDoc.pageCount == pageCount {
  412. documents.add(doc)
  413. }
  414. }
  415. }
  416. let sortDescriptor = NSSortDescriptor(key: "displayName", ascending: true)
  417. documents.sort(using: [sortDescriptor])
  418. for doc in documents {
  419. self.notesDocumentPopUpButton.addItem(withTitle: (doc as AnyObject).displayName)
  420. self.notesDocumentPopUpButton.lastItem?.representedObject = doc
  421. }
  422. let docIndex = self.notesDocumentPopUpButton.indexOfItem(withRepresentedObject: currentDoc)
  423. self.notesDocumentPopUpButton.selectItem(at: docIndex == -1 ? 0 : docIndex)
  424. }
  425. }
  426. // MARK: - NSTextFieldDelegate
  427. extension SKPresentationOptionsSheetController: NSTextFieldDelegate {
  428. func controlTextDidChange(_ obj: Notification) {
  429. if self.durationTF.isEqual(to: obj.object) {
  430. }
  431. }
  432. func controlTextDidEndEditing(_ obj: Notification) {
  433. if self.durationTF.isEqual(to: obj.object) {
  434. if checkString(str: self.durationTF.stringValue) {
  435. self.durationSlider.floatValue = self.durationTF.floatValue
  436. // 更新数据
  437. self._updateInfo(key: KMDurationName, value: self.durationTF.floatValue)
  438. }else{
  439. self.durationTF.stringValue = "1.0"
  440. }
  441. }
  442. }
  443. func checkString(str: String) -> Bool {
  444. let reg = "^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$"
  445. let pre = NSPredicate(format: "SELF MATCHES %@", reg)
  446. if pre.evaluate(with: str) {
  447. return true
  448. }
  449. return false
  450. }
  451. }
  452. // MARK: - NSWindowDelegate
  453. extension SKPresentationOptionsSheetController: NSWindowDelegate {
  454. func windowWillReturnUndoManager(_ window: NSWindow) -> UndoManager? {
  455. return self.undoRedoManager
  456. }
  457. }
  458. // MARK: - SKTransitionControllerDelegate
  459. extension SKPresentationOptionsSheetController: SKTransitionControllerDelegate {
  460. func transitionController(_ controller: SKTransitionController!, valueDidChanged info: [AnyHashable : Any]!) {
  461. // 消息转发
  462. self.proxyDelegate_?.transitionController(controller, valueDidChanged: info)
  463. }
  464. }
  465. // MARK: - NSTableViewDelegate, NSTableViewDataSource
  466. extension SKPresentationOptionsSheetController: NSTableViewDelegate, NSTableViewDataSource {
  467. func numberOfRows(in tableView: NSTableView) -> Int {
  468. return self.transitions?.count ?? 0
  469. }
  470. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  471. let identifier = tableColumn?.identifier
  472. let info = transitions?[row] as? KMTransitionInfo
  473. var cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMPresentTableViewCell"), owner: self)
  474. if cell == nil {
  475. cell = KMPresentTableViewCell(type: .text)
  476. }
  477. let myCellView: KMPresentTableViewCell = cell! as! KMPresentTableViewCell
  478. myCellView.label?.stringValue = info?.label ?? ""
  479. let page = self.controller?.listView.document.page(at: UInt(info?.thumbnail?.pageIndex ?? 0))
  480. let image = page?.thumbnail(of: page?.bounds.size ?? .zero)
  481. myCellView.iv?.image = image
  482. return myCellView;
  483. }
  484. func tableViewSelectionDidChange(_ notification: Notification) {
  485. if self.tableView.isEqual(to: notification.object) == false {
  486. return
  487. }
  488. let ris = self.tableView.selectedRowIndexes
  489. if ris.isEmpty {
  490. return
  491. }
  492. var info: KMTransitionInfo?
  493. if ris.count == 1 {
  494. info = self.transitions?[ris.first ?? 0] as? KMTransitionInfo
  495. self.pageTransitionBox.title = KMLocalizedString("Page Transition") + (info?.label ?? "")
  496. } else {
  497. self.pageTransitionBox.title = KMLocalizedString("Page Transition")
  498. info = self.transition
  499. }
  500. self.effectPopUpButton.selectItem(at: Int(info?.transitionStyle.rawValue ?? 0))
  501. let durationV = info?.duration ?? 0
  502. self.durationSlider.animator().floatValue = durationV
  503. self.durationTF.floatValue = durationV
  504. let shouldRestrict = info?.shouldRestrict ?? false
  505. if shouldRestrict { // 1
  506. self.pageBtn.state = .on
  507. self.screeBtn.state = .off
  508. } else {
  509. self.screeBtn.state = .on
  510. self.pageBtn.state = .off
  511. }
  512. }
  513. func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
  514. if rowIndexes.count == 1 {
  515. if let data = transitions?[rowIndexes.first ?? 0] as? NSPasteboardWriting {
  516. pboard.clearContents()
  517. pboard.writeObjects([data])
  518. }
  519. return true
  520. } else {
  521. return false
  522. }
  523. }
  524. func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
  525. return NSDragOperation(rawValue: 0)
  526. }
  527. func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
  528. return false
  529. }
  530. }
  531. extension SKPresentationOptionsSheetController: KMBotaTableViewDelegate {
  532. func tableView(_ aTableView: NSTableView, imageContextForRow rowIndex: Int) -> AnyObject? {
  533. return controller?.document?.page(at: UInt(rowIndex))
  534. }
  535. func tableView(_ aTableView: NSTableView, copyRowsWithIndexes rowIndexes: IndexSet) {
  536. if let data = transitions?[rowIndexes.first ?? 0] as? NSPasteboardWriting {
  537. let pboard = NSPasteboard.general
  538. pboard.clearContents()
  539. pboard.writeObjects([data])
  540. }
  541. }
  542. func tableView(_ aTableView: NSTableView, canCopyRowsWithIndexes rowIndexes: IndexSet) -> Bool {
  543. return false
  544. }
  545. func tableView(_ aTableView: NSTableView, pasteFromPasteboard pboard: NSPasteboard) {
  546. }
  547. func tableView(_ aTableView: NSTableView, canPasteFromPasteboard pboard: NSPasteboard) -> Bool {
  548. return false
  549. }
  550. func tableView(_ aTableView: NSTableView, typeSelectHelperSelectionStrings aTypeSelectHelper: SKTypeSelectHelper) -> NSArray {
  551. return []
  552. }
  553. }