KMMainViewController+UI.swift 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978
  1. //
  2. // KMMainViewController+UI.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/12/15.
  6. //
  7. import Foundation
  8. extension KMMainViewController {
  9. // MARK: - 退出全屏
  10. @IBAction func exitFullScreen(_ sender: Any) {
  11. if (self.view.window == nil) {
  12. return
  13. }
  14. if (KMTools.isFullScreen(self.view.window!)) {
  15. self.view.window?.toggleFullScreen(nil)
  16. }
  17. }
  18. @IBAction func startSpeaking(_ sender: Any) {
  19. self.showTTSWindow()
  20. let ttsView = KMTTSWindowController.share
  21. ttsView.buttonItemClick_Play(ttsView.playButton)
  22. }
  23. @IBAction func stopSpeaking(_ sender: Any) {
  24. let ttsWindowC = KMTTSWindowController.share
  25. if ttsWindowC.pdfView?.document?.documentURL.path == self.listView.document.documentURL.path {
  26. if let data = ttsWindowC.window?.isVisible, data {
  27. ttsWindowC.stopSpeaking()
  28. ttsWindowC.close()
  29. }
  30. }
  31. }
  32. }
  33. extension KMMainViewController {
  34. //通知
  35. func preferenceDidChangeNotification(notification:Notification) {
  36. let info : [AnyHashable : Any] = notification.userInfo ?? [:]
  37. if info.keys.contains(KMPreference.viewZoomScaleTypeKey) {
  38. self.selectZoom(KMPreferenceManager.shared.viewZoomScaleType)
  39. }
  40. if notification.name.rawValue == "pdfViewDocumentDidLoaded" || info.keys.contains(KMPreference.viewPageDisplayTypeKey) {
  41. self.selectDisplay(display: KMPreferenceManager.shared.viewPageDisplayType)
  42. }
  43. if info.keys.contains(KMPreference.displayBackgroundNormalColorKey) || notification.name.rawValue == "pdfViewDocumentDidLoaded" {
  44. self.listView.backgroundColor = KMPreferenceManager.shared.displayBackgroundNormalColor
  45. self.listView.layoutDocumentView()
  46. }
  47. self.updatePageIndicatoreType()
  48. if (info.keys.contains(KMPreference.generalAuthorNameKey)) { // 作者名称
  49. CPDFKitConfig.sharedInstance().setAnnotationAuthor((info[KMPreference.generalAuthorNameKey] as! String))
  50. }
  51. if (info.keys.contains(KMPreference.highlightLinksKey)) {
  52. let hlLink = info[KMPreference.highlightLinksKey] as? Bool
  53. CPDFKitConfig.sharedInstance().setEnableLinkFieldHighlight(hlLink == nil ? false : hlLink!)
  54. self.listView.setNeedsDisplayForVisiblePages()
  55. }
  56. if info.keys.contains(KMPreference.thumbPageSizeKey) {
  57. self.leftSideViewController.refreshUIOfThumbnailIfNeed(preference: true)
  58. }
  59. if info.keys.contains(KMPreference.thumbSnapshotSizeKey) {
  60. self.leftSideViewController.refreshUIOfSnapshotIfNeed(preference: true)
  61. }
  62. if info.keys.contains(KMPreference.outlineFontSizeKey) {
  63. self.leftSideViewController.updateTableFont()
  64. }
  65. if info.keys.contains(KMPreference.greekThresholdKey) {
  66. let value = KMPreference.shared.greekThreshold.cgFloat
  67. self.listView.setGreekingThreshold(value)
  68. self.secondaryPdfView?.setGreekingThreshold(value)
  69. }
  70. if info.keys.contains(KMPreference.antiAliasTextKey) {
  71. self.listView.setShouldAntiAlias(KMPreference.shared.antiAliasText)
  72. self.listView.applyDefaultInterpolationQuality()
  73. self.secondaryPdfView?.setShouldAntiAlias(KMPreference.shared.antiAliasText)
  74. self.secondaryPdfView?.applyDefaultInterpolationQuality()
  75. }
  76. if info.keys.contains(KMPreference.markupColorHighlightKey) {
  77. if let item = self.toolbarController.findItem(KMToolbarHighlightAnnotationItemIdentifier) {
  78. if item.isSelected {
  79. let color = KMPreference.shared.markupHighlightColor
  80. let imageV = KMNoteTypeImageView()
  81. item.image = imageV.noteTypeImage(withType: SKNHighlightString, color: color)
  82. }
  83. }
  84. }
  85. if info.keys.contains(KMPreference.markupColorUnderlineKey) {
  86. if let item = self.toolbarController.findItem(KMToolbarUnderlineAnnotationItemIdentifier) {
  87. if item.isSelected {
  88. let color = KMPreference.shared.markupUnderlineColor
  89. let imageV = KMNoteTypeImageView()
  90. item.image = imageV.noteTypeImage(withType: SKNUnderlineString, color: color)
  91. }
  92. }
  93. }
  94. if info.keys.contains(KMPreference.markupColorStrikthroughKey) {
  95. if let item = self.toolbarController.findItem(KMToolbarStrikeOutAnnotationItemIdentifier) {
  96. if item.isSelected {
  97. let color = KMPreference.shared.markupStrikthroughColor
  98. let imageV = KMNoteTypeImageView()
  99. item.image = imageV.noteTypeImage(withType: SKNStrikeOutString, color: color)
  100. }
  101. }
  102. }
  103. if info.keys.contains(KMPreference.markupColorPenKey) {
  104. if let item = self.toolbarController.findItem(KMToolbarInkAnnotationItemIdentifier) {
  105. if item.isSelected {
  106. let color = KMPreference.shared.markupPenColor
  107. let imageV = KMNoteTypeImageView()
  108. item.image = imageV.noteTypeImage(withType: SKNInkString, color: color)
  109. }
  110. }
  111. }
  112. }
  113. //刷新页面显示器
  114. func updatePageIndicatoreType () {
  115. if self.isReadMode {
  116. self.pageNumberDisplayView.outView()
  117. } else {
  118. if self.listView.document != nil {
  119. self.pageNumberDisplayView.totalPagesCount = Int(self.listView.document.pageCount)
  120. }
  121. self.pageNumberDisplayView.currentPageIndex = self.listView.currentPageIndex
  122. self.pageNumberDisplayView.displayType = KMPreferenceManager.shared.pageIndicatorType
  123. self.readContentView.addSubview(self.tipCurrentPageBox, positioned: .above, relativeTo: self.readContentView)
  124. }
  125. }
  126. func showConvertNotesProgress() {
  127. guard let pdfDocument = self.document else {
  128. return
  129. }
  130. guard let _ = self.listView?.document else {
  131. return
  132. }
  133. guard let _ = self.view.window else {
  134. return
  135. }
  136. let isNewCreated = (self.myDocument as? KMMainDocument)?.isNewCreated ?? false
  137. if isNewCreated {
  138. return
  139. }
  140. self.model.needConvertNotes = false
  141. Task { @MainActor in
  142. self.convertNotesUsingPDFDocument(pdfDocument)
  143. }
  144. }
  145. func convertNotesUsingPDFDocument(_ pdfDocument: CPDFDocument) {
  146. guard let doc = self.listView?.document else {
  147. return
  148. }
  149. DispatchQueue.main.async {
  150. self.beginProgressSheet(withMessage: NSLocalizedString("Converting notes", comment: "Message for progress sheet").appending("..."), maxValue: 0)
  151. let count = pdfDocument.pageCount
  152. DispatchQueue.global().async {
  153. // var addAnnotations = [CPDFAnnotation]()
  154. // var removeAnnotations = [CPDFAnnotation]()
  155. self.model.addAnnotations.removeAll()
  156. self.model.removeAnnotations.removeAll()
  157. for i in 0..<count {
  158. let page = pdfDocument.page(at: i)
  159. // var addAnnotations = [CPDFAnnotation]()
  160. // var removeAnnotations = [CPDFAnnotation]()
  161. for annotation in page?.annotations ?? [] {
  162. var newAnnotation: CPDFAnnotation?
  163. if let inkAnnotation = annotation as? CPDFInkAnnotation, inkAnnotation.contents.hasPrefix("<?xml version=\"1.0\" encoding=\"utf-8\"?>") {
  164. let table = KMTableAnnotation(KMNoteBounds: inkAnnotation.bounds, document: doc)
  165. table.border = inkAnnotation.border
  166. table.color = inkAnnotation.color
  167. table.createForm(withList: inkAnnotation.contents, andPaths: inkAnnotation.bezierPaths())
  168. table.updateAppearanceInk(withIsAdd: false)
  169. table.contents = annotation.contents
  170. newAnnotation = table
  171. }
  172. if let newAnnotation = newAnnotation {
  173. self.model.addAnnotations.append(newAnnotation)
  174. self.model.removeAnnotations.append(annotation)
  175. }
  176. }
  177. // for i in 0..<addAnnotations.count {
  178. // let newAnnotation = addAnnotations[i]
  179. // let annotation = removeAnnotations[i]
  180. //
  181. // // this is only to make sure markup annotations generate the lineRects, for thread safety
  182. // pdfView?.addAnnotation(with: newAnnotation, to: page)
  183. // pdfView?.remove(annotation)
  184. // if newAnnotation.contents != nil {
  185. // if newAnnotation.contents.count == 0 {
  186. // newAnnotation.autoUpdateString()
  187. // }
  188. // }
  189. // }
  190. }
  191. DispatchQueue.main.async {
  192. for i in 0..<self.model.addAnnotations.count {
  193. let newAnnotation = self.model.addAnnotations[i]
  194. let annotation = self.model.removeAnnotations[i]
  195. let page = annotation.page
  196. // this is only to make sure markup annotations generate the lineRects, for thread safety
  197. self.listView?.addAnnotation(with: newAnnotation, to: page)
  198. self.listView?.remove(annotation)
  199. if newAnnotation.contents != nil {
  200. if newAnnotation.contents.count == 0 {
  201. newAnnotation.autoUpdateString()
  202. }
  203. }
  204. }
  205. self.dismissProgressSheet()
  206. self.listView?.undoManager?.removeAllActions()
  207. self.undoManager?.removeAllActions()
  208. // 清空数据
  209. self.model.addAnnotations.removeAll()
  210. self.model.removeAnnotations.removeAll()
  211. }
  212. }
  213. }
  214. }
  215. // MARK: - KMInterfaceThemeChangedProtocol
  216. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  217. super.interfaceThemeDidChanged(appearance)
  218. self.toolbarController.interfaceThemeDidChanged(appearance)
  219. self.leftSideViewController.interfaceThemeDidChanged(appearance)
  220. self.rightSideViewController.interfaceThemeDidChanged(appearance)
  221. self.pdfEditController?.interfaceThemeDidChanged(appearance)
  222. self.mianSplitView.superview?.wantsLayer = true
  223. // let sView = self.listView.documentView()
  224. if KMAppearance.isDarkMode() {
  225. self.mianSplitView.superview?.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  226. // sView?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  227. } else {
  228. self.mianSplitView.superview?.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  229. // sView?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1)
  230. }
  231. }
  232. }
  233. // MARK: - KMToolbarControllerDelegate
  234. extension KMMainViewController: KMToolbarControllerDelegate {
  235. func toolbarController(_ viewController: KMToolbarController, heightOffsetChange heightOffset: Float, animated: Bool) {
  236. let heightConst = (animated ? self.heightOffset.animator() : self.heightOffset)
  237. if self.isReadMode {
  238. if self.toolbarController.toolbarType == .Annatiton {
  239. heightConst?.constant = CGFloat(heightOffset)
  240. } else {
  241. heightConst?.constant = CGFloat(0)
  242. }
  243. } else {
  244. heightConst?.constant = CGFloat(heightOffset)
  245. }
  246. self.refreshListViewToolMode()
  247. self.trackEvent(toolMode: self.listView.toolMode)
  248. if self.listView.annotationType == .editTextImage ||
  249. self.listView.annotationType == .addText ||
  250. self.listView.annotationType == .addImage {
  251. self.closeRightPane()
  252. }
  253. self.listView.annotationType = .unkown
  254. }
  255. func changeAnnotationModeAction(item: KMToolbarClickButton) {
  256. if self.listView.toolMode == .formToolMode {
  257. if !IAPProductsManager.default().isAvailableAllFunction(){
  258. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  259. return
  260. }
  261. }
  262. if (self.model.rightMouseEventing) {
  263. self.model.rightMouseEventing = false
  264. }
  265. if (self.toolbarController.ignoreCurrentAnnotationTypeChange) {
  266. self.toolbarController.ignoreCurrentAnnotationTypeChange = false
  267. }
  268. var currentType = self.listView.annotationType
  269. if (currentType == .eraser) {
  270. currentType = .ink
  271. }
  272. let isSelected = (currentType == CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown) && ((self.listView.toolMode == .noteToolMode) || (self.listView.toolMode == .selfSignMode) || (self.listView.toolMode == .formToolMode))
  273. var editSelectd = false
  274. if self.listView.annotationType == CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown && self.listView.toolMode == .editPDFToolMode {
  275. editSelectd = true
  276. }
  277. if isSelected {
  278. if self.listView.toolMode == .formToolMode {
  279. } else {
  280. self.listView.toolMode = .textToolMode
  281. }
  282. self.listView.annotationType = .unkown
  283. self.closeRightPane()
  284. } else {
  285. let type = CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown
  286. self.trackEvent(annotationType: type)
  287. self.listView.annotationType = type
  288. if self.listView.currentSelection != nil {
  289. let annotation = self.listView.addAnnotation(with: CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown, selection: self.listView.currentSelection, page: self.listView.currentSelection.page, bounds: self.listView.currentSelection.bounds)
  290. if((annotation != nil) &&
  291. !self.listView.activeAnnotations.contains(annotation ?? self.listView.activeAnnotation)) {
  292. var newAnnonations : [CPDFAnnotation] = []
  293. newAnnonations.append(annotation!)
  294. self.listView.updateActiveAnnotations(newAnnonations)
  295. self.listView.setNeedsDisplayAnnotationViewFor(annotation?.page)
  296. }
  297. }
  298. if self.listView.toolMode == .formToolMode {
  299. } else {
  300. self.refreshListViewToolMode()
  301. }
  302. }
  303. if self.listView.toolMode != .editPDFToolMode && self.listView.annotationType != .unkown {
  304. self.rightSideViewController.isHidden = false
  305. self.rightSideViewController.subViewType = .AnnotationProperts
  306. if !self.isReadMode {
  307. self.openRightPane()
  308. }
  309. } else if self.listView.toolMode == .editPDFToolMode {
  310. if editSelectd {
  311. self.rightSideViewController.isHidden = true
  312. self.listView.setShouAddEdit([])
  313. self.listView.change([.text, .image])
  314. self.listView.annotationType = .editTextImage
  315. self.closeRightPane()
  316. } else if self.listView.annotationType == .addText {
  317. self.rightSideViewController.isHidden = false
  318. if !self.isReadMode {
  319. self.openRightPane()
  320. }
  321. self.rightSideViewController.subViewType = .EditPDFAddText
  322. FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_EditPDF", withProperties: ["SubTbr_Btn" : "Btn_SubTbr_EditPDF_AddText"])
  323. self.listView.setShouAddEdit(.text)
  324. self.listView.change(.text)
  325. } else if self.listView.annotationType == .addImage {
  326. self.rightSideViewController.isHidden = false
  327. if !self.isReadMode {
  328. self.openRightPane()
  329. }
  330. FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_EditPDF", withProperties: ["SubTbr_Btn" : "Btn_SubTbr_EditPDF_AddImage"])
  331. // self.closeRightPane()
  332. self.rightSideViewController.subViewType = .EditPDFAddImage
  333. self.listView.setShouAddEdit(.image)
  334. self.listView.change(.image)
  335. self.rightSideViewController.eidtPDFImageProperty.reloadData()
  336. }
  337. } else {
  338. self.rightSideViewController.isHidden = true
  339. self.closeRightPane()
  340. }
  341. }
  342. func refreshListViewToolMode () {
  343. if self.toolbarController.toolbarType == .Annatiton {
  344. self.listView.toolMode = .noteToolMode
  345. } else if self.toolbarController.toolbarType == .Move {
  346. self.listView.toolMode = .moveToolMode
  347. } else if self.toolbarController.toolbarType == .Magnify {
  348. self.listView.toolMode = .magnifyToolMode
  349. } else if self.toolbarController.toolbarType == .Select {
  350. self.listView.toolMode = .selectToolMode
  351. } else if self.toolbarController.toolbarType == .SelectZoom {
  352. self.listView.toolMode = .selectZoomToolMode
  353. } else if self.toolbarController.toolbarType == .Page {
  354. } else if self.toolbarController.toolbarType == .Form {
  355. self.listView.toolMode = .formToolMode
  356. self.rightSideViewController.subViewType = .AnnotationProperts
  357. } else if self.toolbarController.toolbarType == .FillSign {
  358. self.listView.toolMode = .selfSignMode
  359. self.rightSideViewController.subViewType = .AnnotationProperts
  360. } else if self.toolbarController.toolbarType == .editPDF {
  361. self.listView.toolMode = .editPDFToolMode
  362. // self.listView.editingConfig().isShowEditingAreaHover = true
  363. // self.listView.editingConfig().editingBorderWidth = 1
  364. // self.listView.editingConfig().editingCenterRadius = 5
  365. // self.listView.editingConfig().editAreaMargin = 2
  366. // self.listView.editingConfig().editingHoverBorderColor = NSColor.init(red: 0, green: 136.0/255.0, blue: 1.0, alpha: 0.5)
  367. // self.listView.editingConfig().editingBorderColor = NSColor.init(red: 0, green: 0, blue: 0, alpha: 0.4)
  368. // self.listView.editingConfig().addEditAreaColor = NSColor.init(red: 23.0/255.0, green: 112.0/255.0, blue: 244.0/255.0, alpha: 0.5)
  369. // self.listView.editingConfig().editAreaMoveFillColor = NSColor.init(red: 23.0/255.0, green: 112.0/255.0, blue: 244.0/255.0, alpha: 0.1)
  370. self.listView.setShouAddEdit([])
  371. }else if self.toolbarController.toolbarType == .LeftPanel {
  372. self.toggleLeftPane()
  373. self.leftSideViewController.showPanelView(show: true)
  374. }else {
  375. self.listView.toolMode = .textToolMode
  376. }
  377. }
  378. func showPDFLayoutModeAction(show: Bool) {
  379. self.listView.annotationType = .unkown
  380. self.showOrHideNotes()
  381. }
  382. }
  383. // MARK: - NSSplitViewDelegate
  384. extension KMMainViewController : NSSplitViewDelegate {
  385. func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
  386. if splitView == self.mianSplitView {
  387. // return (subview == self.listView) == false
  388. } else if splitView == self.newPDFSplitView {
  389. return subview.isEqual(to: self.secondaryPdfContentView)
  390. }
  391. return false
  392. }
  393. func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int) -> Bool {
  394. if splitView == self.newPDFSplitView {
  395. if subview.isEqual(to: self.secondaryPdfContentView) {
  396. var position = self.newPDFSplitView.maxPossiblePositionOfDivider(at: dividerIndex)
  397. if self.newPDFSplitView.isSubviewCollapsed(subview) {
  398. if self.lastSplitPDFHeight <= 0.0 {
  399. let DEFAULT_SPLIT_PANE_HEIGHT: Float = 200.0
  400. self.lastSplitPDFHeight = DEFAULT_SPLIT_PANE_HEIGHT
  401. }
  402. if self.lastSplitPDFHeight.cgFloat > NSHeight(self.pdfContentView.frame) {
  403. self.lastSplitPDFHeight = floorf(0.5 * Float(NSHeight(self.pdfContentView.frame)))
  404. }
  405. position += self.lastSplitPDFHeight.cgFloat
  406. } else {
  407. self.lastSplitPDFHeight = Float(NSHeight(subview.frame))
  408. }
  409. self.pdfSplitView.setPosition(position, ofDividerAt: dividerIndex, animate: true)
  410. }
  411. return false
  412. }
  413. return false
  414. }
  415. func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
  416. if splitView == self.mianSplitView {
  417. return splitView == self.mianSplitView
  418. } else if splitView == self.newPDFSplitView {
  419. return false
  420. }
  421. return false
  422. }
  423. func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  424. if splitView == mianSplitView {
  425. let splitViewWidth = splitView.frame.width
  426. let dividerIndexX0 = self.model.panelWidth + functionWidth
  427. if dividerIndex == 0 {
  428. if self.model.leftPanelOpen {
  429. return CGFloat(dividerIndexX0 * 1.5)
  430. } else {
  431. return functionWidth
  432. }
  433. } else if dividerIndex == 1 {
  434. return splitViewWidth
  435. }
  436. } else if splitView == self.newPDFSplitView {
  437. if dividerIndex == 0 {
  438. let MIN_SIDE_PANE_WIDTH = 270
  439. return proposedMaximumPosition + MIN_SIDE_PANE_WIDTH.cgFloat
  440. }
  441. }
  442. return proposedMaximumPosition
  443. }
  444. func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  445. if splitView == mianSplitView {
  446. let splitViewWidth = splitView.frame.width
  447. let dividerIndexX1 = splitViewWidth - self.model.defaultRightWidth
  448. if dividerIndex == 0 {
  449. return functionWidth
  450. } else if dividerIndex == 1 {
  451. return dividerIndexX1
  452. }
  453. } else if splitView == self.newPDFSplitView {
  454. }
  455. return proposedMinimumPosition
  456. }
  457. func splitView(_ splitView: NSSplitView, resizeSubviewsWithOldSize oldSize: NSSize) {
  458. if splitView.isEqual(to: mianSplitView) {
  459. let leftView = splitView.subviews[0]
  460. let centerView = splitView.subviews[1]
  461. let rightView = splitView.subviews[2]
  462. // let centerView = self.pdfSplitView ?? splitView.subviews[1]
  463. // let rightView = self.rightView ?? splitView.subviews[2]
  464. // 左边是否收起
  465. let leftCollapsed = splitView.isSubviewCollapsed(leftView)
  466. // 右边是否收起
  467. let rightCollapsed = splitView.isSubviewCollapsed(rightView)
  468. var leftSize = leftView.frame.size
  469. var mainSize = centerView.frame.size
  470. var rightSize = rightView.frame.size
  471. var contentWidth = splitView.frame.width
  472. if leftCollapsed {
  473. leftSize.width = 0.0
  474. } else {
  475. contentWidth = contentWidth - splitView.dividerThickness
  476. }
  477. if rightCollapsed {
  478. rightSize.width = 0.0
  479. } else {
  480. contentWidth = contentWidth - splitView.dividerThickness
  481. }
  482. if contentWidth < leftSize.width + rightSize.width {
  483. var oldContentWidth = oldSize.width
  484. if leftCollapsed == false {
  485. oldContentWidth = oldContentWidth - splitView.dividerThickness
  486. }
  487. if rightCollapsed == false {
  488. oldContentWidth = oldContentWidth - splitView.dividerThickness
  489. }
  490. let resizeFactor = contentWidth / oldContentWidth
  491. leftSize.width = floor(resizeFactor*leftSize.width)
  492. rightSize.width = floor(resizeFactor*rightSize.width)
  493. }
  494. mainSize.width = contentWidth - leftSize.width - rightSize.width
  495. leftSize.height = splitView.frame.height
  496. rightSize.height = splitView.frame.height
  497. mainSize.height = splitView.frame.height
  498. if leftCollapsed == false {
  499. leftView.setFrameSize(leftSize)
  500. }
  501. if rightCollapsed == false {
  502. rightView.setFrameSize(rightSize)
  503. }
  504. centerView.setFrameSize(mainSize)
  505. } else if splitView == self.newPDFSplitView {
  506. // let firstV = splitView.subviews.first
  507. // let lastV = splitView.subviews.last
  508. // if firstV == lastV{
  509. // splitView.adjustSubviews()
  510. // return
  511. // }
  512. // if self.newPDFSplitView.isVertical { // 横向
  513. // // 左边是否收起
  514. // let leftCollapsed = splitView.isSubviewCollapsed(firstV!)
  515. // // 右边是否收起
  516. // let rightCollapsed = splitView.isSubviewCollapsed(lastV!)
  517. //
  518. // var contentSize = splitView.frame.size
  519. // firstV?.setFrameSize(NSMakeSize(contentSize.width * 0.5, contentSize.height))
  520. // lastV?.setFrameSize(NSMakeSize(contentSize.width * 0.5, contentSize.height))
  521. // } else { // 纵向
  522. // // 左边是否收起
  523. // let leftCollapsed = splitView.isSubviewCollapsed(firstV!)
  524. // // 右边是否收起
  525. // let rightCollapsed = splitView.isSubviewCollapsed(lastV!)
  526. //
  527. // var contentSize = splitView.frame.size
  528. // firstV?.setFrameSize(NSMakeSize(contentSize.width, contentSize.height * 0.5))
  529. // lastV?.setFrameSize(NSMakeSize(contentSize.width, contentSize.height * 0.5))
  530. // }
  531. }
  532. splitView.adjustSubviews()
  533. }
  534. func splitViewWillResizeSubviews(_ notification: Notification) {
  535. let defaultView = KMSplitView()
  536. let sender : NSSplitView = notification.object as? NSSplitView ?? defaultView
  537. if (sender == self.mianSplitView || sender == defaultView) && self.view.window?.frameAutosaveName != nil{
  538. // let leftWidth = self.mianSplitView.isSubviewCollapsed(self.leftView) ? 0.0 : leftSideViewController.view.frame.width
  539. // if leftPanelOpen {
  540. // if leftWidth < 100 && lastLeftPanWidth > functionWidth{
  541. // self.closeLeftPane()
  542. // }
  543. // }
  544. } else {
  545. if sender == self.pdfSplitView {
  546. KMPrint("")
  547. }
  548. }
  549. }
  550. func splitViewDidResizeSubviews(_ notification: Notification) {
  551. self.locationPageView.frame = CGRect(x: 0, y: self.listView.frame.maxY-32, width: self.listView.frame.width, height: 32)
  552. let defaultView = KMSplitView()
  553. let sender : NSSplitView = notification.object as? NSSplitView ?? defaultView
  554. if (sender == self.mianSplitView || sender == defaultView) && self.view.window?.frameAutosaveName != nil{
  555. let leftWidth = self.mianSplitView.isSubviewCollapsed(self.leftView) ? 0.0 : leftSideViewController.view.frame.width
  556. let rightWidth = self.mianSplitView.isSubviewCollapsed(self.rightView) ? 0.0 : rightSideViewController.view.frame.width
  557. UserDefaults.standard.set(leftWidth, forKey: CPDFOfficeLeftSidePaneWidthKey)
  558. UserDefaults.standard.set(rightWidth, forKey: CPDFOfficeRightSidePaneWidthKey)
  559. } else {
  560. if sender == self.pdfSplitView {
  561. KMPrint("")
  562. }
  563. }
  564. }
  565. func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
  566. if splitView == self.mianSplitView {
  567. if dividerIndex == 0 {
  568. if self.model.leftPanelOpen {
  569. //当左边栏开启式,拖拽时不改变宽度,当宽度达到原宽度的一半时关闭窗口
  570. //如果 isShowPanel 为 true 那么将不会收缩
  571. if (proposedPosition < functionWidth + self.model.panelWidth * 0.5) && !self.leftSideViewController.isShowPanel {
  572. self.closeLeftPane()
  573. self.leftSideViewController.refreshMethodType(methodType: .None)
  574. return functionWidth
  575. } else if proposedPosition > self.model.panelWidth + functionWidth {
  576. return proposedPosition
  577. } else {
  578. return self.model.panelWidth + functionWidth
  579. }
  580. } else {
  581. return functionWidth
  582. }
  583. }
  584. } else if splitView == self.newPDFSplitView {
  585. }
  586. return proposedPosition
  587. }
  588. }
  589. // MARK: - KMLeftSideViewControllerDelegate
  590. extension KMMainViewController: KMLeftSideViewControllerDelegate {
  591. func controlStateChange(_ obj: KMLeftSideViewController, show: Bool) {
  592. if show {
  593. self.openLeftPane()
  594. } else {
  595. self.closeLeftPane()
  596. }
  597. }
  598. func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int]) {
  599. let item : KMToolbarItemView = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentPageToolbarItemIdentifier))!
  600. self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Page, toolbar: item, pages)
  601. }
  602. func searchAction(searchString: String,isCase:Bool) {
  603. self.search(searchString: searchString,isCase: isCase)
  604. }
  605. func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType) {
  606. self.selectDisplay(display: dispay, viewSettingIsReload: false)
  607. }
  608. func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?) {
  609. if (itemKey == .print) { // 打印
  610. if params is NSImage {
  611. KMPrintWindowController.cpdf_printImage(image: params as! NSImage)
  612. return
  613. }
  614. var pageRange: KMPrintPageRange = KMPrintPageRange(type: .allPage, selectPages: [], reversePrintOrder: false)
  615. if (params != nil) {
  616. pageRange.type = .custom
  617. pageRange.selectPages = params as! [Int]
  618. }
  619. self.showPrintWindow(pageRange: pageRange)
  620. } else if (itemKey == .cut || itemKey == .paste || itemKey == .delete || itemKey == .leftRotate || itemKey == .rightRotate) {
  621. self.recordIsPDFDocumentEdited(type: itemKey.toSubscribeWaterMarkType())
  622. } else if itemKey == .pageEdit {
  623. self.toolbarController.clickItem(KMDocumentPageToolbarItemIdentifier)
  624. } else if itemKey == .demote { // 大纲降级
  625. guard let currentOutline: CPDFOutline = controller.tocOutlineView.km.clickedItem() else {
  626. return
  627. }
  628. self.listView?.demote(outline: currentOutline)
  629. } else if itemKey == .promote { // 大纲升级
  630. guard let currentOutline: CPDFOutline = controller.tocOutlineView.km.clickedItem() else {
  631. return
  632. }
  633. self.listView?.promote(outline: currentOutline)
  634. }
  635. }
  636. func controller(controller: KMLeftSideViewController, rotateType: KMRotateType) {
  637. if rotateType == .clockwise {
  638. self.menuItemAction_rotateRight((Any).self)
  639. } else if rotateType == .anticlockwise {
  640. self.menuItemAction_rotateLeft((Any).self)
  641. }
  642. }
  643. func controller(controller: KMLeftSideViewController, listViewSelectionDidChange object: Any?, info: [String : Any]?) {
  644. if controller.thumbnailTableView.isEqual(to: object) {
  645. let row = controller.thumbnailTableView.selectedRow
  646. let curIndex = self.listView.currentPageIndex
  647. if (row != -1 && row != curIndex) {
  648. self.listView?.go(toPageIndex: row, animated: true)
  649. }
  650. }
  651. }
  652. }
  653. //MARK: - ReadModel
  654. extension KMMainViewController {
  655. @objc func openReadModel() {
  656. //保存进入阅读模式之前的状态
  657. readLeftMethodType = self.leftSideViewController.type.methodType
  658. readLeftPanelOpen = self.model.leftPanelOpen
  659. readLastLeftPanWidth = self.model.lastLeftPanWidth
  660. readLeftViewShowPanel = self.leftSideViewController.isShowPanel
  661. readRightPanelOpen = self.model.rightPanelIsOpen
  662. readToolbarType = self.toolbarController.toolbarType
  663. readToolMode = self.listView.toolMode
  664. readAnnotationType = self.listView.annotationType
  665. readSubViewType = self.rightSideViewController.subViewType ?? .None
  666. if self.toolbarController.lastItemBox.isSelected {
  667. readToolbarItemIdentifier = self.toolbarController.lastItemBox.itemIdentifier ?? ""
  668. } else {
  669. readToolbarItemIdentifier = ""
  670. }
  671. //设置阅读模式
  672. self.isReadMode = true
  673. self.readModelView.isHidden = false
  674. //
  675. //顶部菜单栏状态清空
  676. self.toolbarController.toolbarType = .None
  677. // self.toolbarController.view.isHidden = true
  678. self.toolbarController.cancelSelected(KMLeftControlToolbarItemIdentifier)
  679. self.toolbarController.cancelSelected(KMRightControlToolbarItemIdentifier)
  680. self.toolbarController.lastItemBox.isSelected = false
  681. //左侧菜单栏情况
  682. self.model.leftPanelOpen = false
  683. self.model.lastLeftPanWidth = 0
  684. self.leftSideViewController.refreshMethodType(methodType: .None)
  685. //阅读界面初始化
  686. self.readModelView.isHidden = false
  687. self.readModelView.currentPageIndex = self.listView.currentPageIndex
  688. self.readModelView.totalPagesCount = Int(self.listView.document.pageCount)
  689. self.readModelView.beginTimer()
  690. // self.listView.autoScales = true
  691. // self.readModelView.scaleType = .autoSize
  692. self.readModelView.zoomButton.stringValue = (NSString(format: "%.0f", self.listView.scaleFactor * 100) as String) + "%"
  693. //关闭左侧右侧菜单栏
  694. self.closeLeftPane()
  695. self.closeRightPane()
  696. self.leftSideViewController.showPanelView(show: false)
  697. self.leftView.isHidden = true
  698. //弹出提示框
  699. if readAlertView != nil {
  700. readAlertView?.removeFromSuperview()
  701. }
  702. readAlertView = CustomAlertView.alertView(message: NSLocalizedString("Read Mode On", comment: ""), fromView: self.view, withStyle: .blue, backgroundColor: NSColor.km_init(hex: "#36383B"))
  703. UserDefaults.standard.set(isReadMode, forKey: "kKMPDFViewIsReadMode")
  704. UserDefaults.standard.synchronize()
  705. self.updatePageIndicatoreType()
  706. }
  707. @objc func closeReadModel() {
  708. if self.isReadMode {
  709. self.model.isShowBOTA = false
  710. self.readModelView.isHidden = true
  711. self.isReadMode = false
  712. self.readModelView.isHidden = true
  713. self.leftSideViewController.refreshMethodType(methodType: readLeftMethodType)
  714. self.model.leftPanelOpen = readLeftPanelOpen
  715. self.model.rightPanelIsOpen = readRightPanelOpen
  716. self.model.lastLeftPanWidth = readLastLeftPanWidth
  717. if self.model.leftPanelOpen {
  718. self.openLeftPane()
  719. }
  720. self.closeRightPane()
  721. self.toolbarController.toolbarType = .None
  722. self.toolbarController.cancelSelected(KMDocumentViewDisplayToolbarItemIdentifier)
  723. // if self.rightPanelIsOpen {
  724. // self.rightPanelIsOpen = false
  725. //// self.toolbarController.selectItem(KMRightControlToolbarItemIdentifier)
  726. // self.openRightPane()
  727. // }
  728. //
  729. // if readToolbarItemIdentifier.count == 0 {
  730. // self.toolbarController.toolbarType = .None
  731. // } else {
  732. // self.toolbarController.selectItem(readToolbarItemIdentifier)
  733. // }
  734. // self.toolbarController.selectItem(KMDocumentViewDisplayToolbarItemIdentifier)
  735. self.leftSideViewController.showPanelView(show: readLeftViewShowPanel)
  736. if readLeftViewShowPanel {
  737. self.toolbarController.selectItem(KMLeftControlToolbarItemIdentifier)
  738. }
  739. self.toolbarController.view.isHidden = false
  740. self.listView.toolMode = readToolMode
  741. self.listView.annotationType = readAnnotationType
  742. // self.toolbarController.toolbarType = .viewSetting
  743. } else {
  744. self.toolbarController.toolbarType = .None
  745. }
  746. if readAlertView != nil {
  747. readAlertView?.removeFromSuperview()
  748. }
  749. readAlertView = CustomAlertView.alertView(message: NSLocalizedString("Read Mode Off", comment: ""), fromView: self.view, withStyle: .blue, backgroundColor: NSColor.km_init(hex: "#36383B"))
  750. UserDefaults.standard.set(isReadMode, forKey: "kKMPDFViewIsReadMode")
  751. UserDefaults.standard.synchronize()
  752. }
  753. @objc func addOutLineItemAction() {
  754. let labelString = "\(KMLocalizedString("Page", nil)) \((self.listView?.currentPageIndex ?? 0) + 1)"
  755. let label = self.listView?.currentSelection?.string() ?? labelString
  756. let dest = self.listView?.currentDestination
  757. if let row = self.leftSideViewController.selectedRowIndexes().last {
  758. if let ol = self.leftSideViewController.tocOutlineView.item(atRow: row) as? CPDFOutline {
  759. _ = self.listView.addOutline(for: ol.parent, label: label, dest: dest, at: ol.index+1)
  760. } else {
  761. let idx = self.listView?.document?.outlineRoot()?.numberOfChildren ?? 0
  762. _ = self.listView.addOutlineForRoot(label: label, dest:dest, at: idx)
  763. }
  764. } else {
  765. let idx = self.listView?.document?.outlineRoot()?.numberOfChildren ?? 0
  766. _ = self.listView.addOutlineForRoot(label: label, dest:dest, at: idx)
  767. }
  768. }
  769. @objc func showTTSView() {
  770. self.showTTSWindow()
  771. }
  772. @objc func showShareAction() {
  773. }
  774. @objc func lookUpAction() {
  775. let label = self.listView?.currentSelection?.string() ?? ""
  776. self.toolbarController.showFindBar()
  777. self.toolbarController.findSearchView.searchString(label)
  778. // self.toolbarController.findSearchView.find(Any.self)
  779. }
  780. @objc func searchBaiduAction() {
  781. let label = self.listView?.currentSelection?.string() ?? ""
  782. let query = label.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
  783. if let url = URL(string: "https://www.baidu.com/s?wd=\(query)") {
  784. NSWorkspace.shared.open(url)
  785. }
  786. }
  787. @objc func showInfoInFinder() {
  788. }
  789. @objc func NextPageAction() {
  790. }
  791. @objc func PreviousPageAction() {
  792. }
  793. @objc func TranslateItemAction() {
  794. // 获取选中的文本
  795. if let selection = self.listView?.currentSelection?.string() {
  796. // 进行翻译
  797. let escapedText = selection.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
  798. let urlStr = "https://translate.google.com/?sl=auto&amp;tl=zh-CN&amp;text=\(escapedText)"
  799. if let url = URL(string: urlStr) {
  800. NSWorkspace.shared.open(url)
  801. }
  802. } else {
  803. print("No text selected.")
  804. }
  805. }
  806. @objc func AutoScrollItemAction() {
  807. //增加判断,如果是正在滚动,就停止,否则就开始滚动
  808. self.listView.autoFlow()
  809. }
  810. @objc func shareFromService(sender: NSMenuItem) {
  811. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  812. return
  813. }
  814. var string = ""
  815. if let freeTextAnnotation = listView.activeAnnotation as? CPDFFreeTextAnnotation {
  816. string = freeTextAnnotation.contents ?? ""
  817. } else if let markupAnnotation = listView.activeAnnotation as? CPDFMarkupAnnotation {
  818. if let page = markupAnnotation.page {
  819. if let selection = page.selection(for: markupAnnotation.bounds) {
  820. string = selection.string() ?? ""
  821. }
  822. }
  823. } else {
  824. string = listView.currentSelection?.string() ?? ""
  825. }
  826. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  827. let model = windowControler.browser?.tabStripModel
  828. if let cnt = model?.count(), cnt <= 0 {
  829. return
  830. }
  831. if let data = model?.activeTabContents().isHome, data {
  832. return
  833. }
  834. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  835. if string.count > 0 {
  836. let represent : NSSharingService = sender.representedObject as! NSSharingService
  837. represent.perform(withItems: [string])
  838. return
  839. }
  840. let represent = sender.representedObject as? NSSharingService
  841. represent?.perform(withItems: [string])
  842. }
  843. @objc func cutAction(sender: NSMenuItem) {
  844. }
  845. @objc func deleteAction(sender: NSMenuItem) {
  846. }
  847. @objc func ColorsItemAction(sender: NSMenuItem) {
  848. }
  849. @objc func LinesItemAction(sender: NSMenuItem) {
  850. }
  851. @objc func EditNoteItemAction(sender: NSMenuItem) {
  852. }
  853. @objc func AITranslateItemAction(sender: NSMenuItem) {
  854. self.showAITypeChooseView(aiConfigType: .translate)
  855. }
  856. @objc func AIProofreadItemAction(sender: NSMenuItem) {
  857. self.showAITypeChooseView(aiConfigType: .proofreading)
  858. }
  859. @objc func AIRewriteItemAction(sender: NSMenuItem) {
  860. self.showAITypeChooseView(aiConfigType: .reWriting)
  861. }
  862. // @objc func highlightLinks() {
  863. // let highlightLinks = KMPreferenceManager.shared.highlightLinks
  864. // KMPreferenceManager.shared.highlightLinks = !highlightLinks
  865. // }
  866. }
  867. // MARK: - KMEditImagePropertyViewControllerDelegate
  868. extension KMMainViewController: KMEditImagePropertyViewControllerDelegate {
  869. func editImagePropertyViewControllerDidChanged(controller: KMEditImagePropertyViewController, type: KMEditImagePropertyViewControllerChangeType) {
  870. self.model.isPDFTextImageEdited = true
  871. }
  872. }
  873. // MARK: - KMSnapshotWindowControllerDelegate
  874. extension KMMainViewController: KMSnapshotWindowControllerDelegate {
  875. func snapshotControllerWillClose(_ controller: KMSnapshotWindowController) {
  876. self.leftSideViewController.snapshotControllerWillClose(controller)
  877. }
  878. func snapshotController(_ controller: KMSnapshotWindowController, miniaturizedRect isMiniaturize: Bool) -> NSRect {
  879. if isMiniaturize && self.interactionMode != .presentation {
  880. if self.interactionMode != .legacyFullScreen && self.model.leftPanelOpen == false {
  881. self.toggleLeftPane()
  882. } else if self.interactionMode == .legacyFullScreen {
  883. // else if ([self interactionMode] == SKLegacyFullScreenMode && ([rightSideWindow state] == NSDrawerClosedState || [rightSideWindow state] == NSDrawerClosingState)) {
  884. // [rightSideWindow expand];
  885. // [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(hideRightSideWindow:) userInfo:NULL repeats:NO];
  886. }
  887. var row = NSNotFound
  888. for (i,sp) in self.leftSideViewController.snapshots.enumerated() {
  889. if controller.isEqual(sp.windowC) {
  890. row = i
  891. }
  892. }
  893. if (row != NSNotFound) {
  894. if self.leftSideViewController.type.methodType != .snapshot {
  895. self.leftSideViewController.leftView.segmentedControl.selectedSegment = 3
  896. } else {
  897. self.leftSideViewController.refreshUIOfSnapshotIfNeed()
  898. }
  899. self.leftSideViewController.snapshotTableView.scrollRowToVisible(row)
  900. }
  901. }
  902. return self.leftSideViewController.snapshotController(controller, miniaturizedRect: isMiniaturize)
  903. }
  904. func snapshotControllerDidFinishSetup(_ controller: KMSnapshotWindowController) {
  905. self.leftSideViewController.snapshotControllerDidFinishSetup(controller)
  906. }
  907. }
  908. // MARK: - CPDFDocumentDelegate
  909. extension KMMainViewController: CPDFDocumentDelegate {
  910. func documentDidBeginDocumentFind(_ document: CPDFDocument!) {
  911. self.leftSideViewController.documentDidBeginFind()
  912. // [statusBar setProgressIndicatorStyle:SKProgressIndicatorBarStyle];
  913. // [[statusBar progressIndicator] setMaxValue:[[note object] pageCount]];
  914. // [[statusBar progressIndicator] setDoubleValue:0.0];
  915. // [statusBar startAnimation:self];
  916. // [self willChangeValueForKey:SEARCHRESULTS_KEY];
  917. // [self willChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
  918. }
  919. func documentDidEndDocumentFind(_ document: CPDFDocument!) {
  920. self.leftSideViewController.documentDidEndFind()
  921. // [self didChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
  922. // [self didChangeValueForKey:SEARCHRESULTS_KEY];
  923. // [statusBar stopAnimation:self];
  924. // [statusBar setProgressIndicatorStyle:SKProgressIndicatorNone];
  925. // NSArray *highlights = [[NSArray alloc] initWithArray:searchResults copyItems:YES];
  926. // [highlights setValue:[NSColor yellowColor] forKey:@"color"];
  927. // [self.pdfView setHighlightedSelections:highlights];
  928. // [highlights release];
  929. }
  930. }
  931. // MAKR: - CPDFViewDelegate,CPDFListViewDelegate
  932. extension KMMainViewController: CPDFViewDelegate,CPDFListViewDelegate {
  933. func pdfViewDocumentDidLoaded(_ pdfView: CPDFView!) {
  934. self.dealDocumentDidLoaded()
  935. let notification = Notification(name: Notification.Name(rawValue: "pdfViewDocumentDidLoaded"))
  936. self.preferenceDidChangeNotification(notification:notification)
  937. let leftWidthNumber = UserDefaults.standard.object(forKey: CPDFOfficeLeftSidePaneWidthKey) as? NSNumber ?? NSNumber(value: self.model.panelWidth + functionWidth)
  938. let rightWidthNumber = UserDefaults.standard.object(forKey: CPDFOfficeRightSidePaneWidthKey) as? NSNumber ?? NSNumber(value: self.model.defaultRightWidth)
  939. applyLeftSideWidth(leftWidthNumber.doubleValue, rightSideWidth: rightWidthNumber.doubleValue)
  940. self.updatePageIndicatoreType()
  941. }
  942. func pdfViewCurrentPageDidChanged(_ pdfView: CPDFView!) {
  943. self.updatePageIndicatoreType()
  944. NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "KMPDFViewCurrentPageDidChanged"), object: self.document)
  945. // KMPrint("KMPDFViewCurrentPageDidChanged")
  946. }
  947. func pdfViewScaleDidChanged(_ pdfView: CPDFView!) {
  948. self.toolbarController.mainToolBarView?.zoomTextField.stringValue = "\(Int(self.listView.scaleFactor * 100))%"
  949. }
  950. func pdfViewDidClick(onLink pdfView: CPDFView!, withURL url: String!) {
  951. if let urlString = url, urlString == kKMPurchaseProductURLString {
  952. //跳转订阅比较表
  953. let _ = KMComparativeTableViewController.show(window: NSApp.mainWindow ?? NSWindow())
  954. return
  955. }
  956. KMTools.openURL(urlString: url)
  957. }
  958. func pdfViewPerformURL(_ pdfView: CPDFView!, withContent content: String!) {
  959. KMPrint("pdfViewPerformURL")
  960. if content != nil {
  961. NSWorkspace.shared.open(URL(string: content)!)
  962. } else {
  963. let alert = NSAlert()
  964. alert.alertStyle = .critical
  965. alert.informativeText = NSLocalizedString("The hyperlink is invalid.", comment: "")
  966. alert.messageText = ""
  967. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  968. alert.runModal()
  969. return
  970. }
  971. }
  972. func pdfViewPerformPrint(_ pdfView: CPDFView!) {
  973. KMPrint("pdfViewPerformPrint")
  974. self.showPrintWindow()
  975. }
  976. func pdfViewPerformGo(toPage pdfView: CPDFView!) {
  977. KMPrint("pdfViewPerformGo")
  978. }
  979. func pdfViewOpenPDF(_ pdfView: CPDFView!, forRemoteGoTo action: CPDFAction!) {
  980. KMPrint("pdfViewOpenPDF")
  981. }
  982. func pdfViewPerformReset(_ pdfView: CPDFView!) {
  983. KMPrint("pdfViewPerformReset")
  984. // self.listView.resetFormAnnotation()
  985. pdfView.document.resetForm()
  986. }
  987. func pdfViewEditingBlockDidChanged(_ pdfView: CPDFView!) {
  988. KMPrint("pdfViewEditingBlockDidChanged")
  989. }
  990. func pdfViewAsBookBookmark() -> NSImage! {
  991. return NSImage(named: "KMImageNameUXIconPDFViewBookMark")!
  992. }
  993. func pdfViewEditingSelectionDidChanged(_ pdfView: CPDFView!) {
  994. if self.rightSideViewController != nil && self.rightSideViewController.subViewType == .EditPDFAddText {
  995. self.rightSideViewController.eidtPDFTextProperty.reloadData()
  996. self.rightSideViewController.eidtPDFTextProperty.updateTextTextPresuppositionState()
  997. }
  998. }
  999. func pdfViewEditingAreaDidChanged(_ pdfView: CPDFView!) {
  1000. let areas = self.listView.editingAreas()
  1001. if areas == nil || areas?.count ?? 0 == 0 {
  1002. if self.listView.toolMode == .editPDFToolMode {
  1003. if self.listView.annotationType == .addImage || self.listView.annotationType == .addText {
  1004. if self.listView.isEditImage {
  1005. self.menuItemEditingClick_CropImage(sender: NSMenuItem())
  1006. } else {
  1007. // if self.listView.annotationType == .addImage {
  1008. // self.closeRightPane()
  1009. // }
  1010. if self.listView.annotationType == .addImage {
  1011. if self.rightSideViewController.eidtPDFImageProperty != nil {
  1012. self.rightSideViewController.eidtPDFImageProperty.reloadData()
  1013. }
  1014. }
  1015. // self.openRightPane()
  1016. }
  1017. } else {
  1018. self.closeRightPane()
  1019. }
  1020. } else {
  1021. self.rightSideViewController.isHidden = true
  1022. self.closeRightPane()
  1023. if self.rightSideViewController != nil && self.rightSideViewController.subViewType == .EditPDFAddText && self.listView.annotationType == .addText {
  1024. self.rightSideViewController.eidtPDFTextProperty.initData()
  1025. }
  1026. }
  1027. if self.listView.isEdited() {
  1028. self.recordIsPDFDocumentEdited(type: .editText)
  1029. }
  1030. if self.listView.annotationType != .addText {
  1031. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kPDFViewEditingAreaDidChanged"), object: self.listView.document)
  1032. }
  1033. return
  1034. }
  1035. self.model.isPDFTextImageEdited = true
  1036. if (self.listView.annotationType == .addImage) && areas!.count > 0 {
  1037. var isImageArea = false
  1038. for i in 0 ... areas!.count-1 {
  1039. if areas![i] is CPDFEditImageArea {
  1040. isImageArea = true
  1041. }
  1042. }
  1043. if isImageArea {
  1044. // self.rightSideViewController.view.isHidden = false
  1045. self.rightSideViewController.isHidden = false
  1046. if self.rightSideViewController != nil && self.rightSideViewController.subViewType == .EditPDFAddImage {
  1047. self.rightSideViewController.subViewType = .EditPDFAddImage
  1048. self.rightSideViewController.eidtPDFImageProperty.reloadData()
  1049. }
  1050. self.openRightPane()
  1051. } else {
  1052. // self.rightSideViewController.view.isHidden = true
  1053. self.rightSideViewController.isHidden = true
  1054. self.closeRightPane()
  1055. }
  1056. } else if self.rightSideViewController != nil && self.rightSideViewController.subViewType == .EditPDFAddText && self.listView.annotationType == .addText {
  1057. // self.rightSideViewController.view.isHidden = false
  1058. self.rightSideViewController.isHidden = false
  1059. if self.listView.editingSelectionString().count != 0 {
  1060. self.rightSideViewController.eidtPDFTextProperty.reloadData()
  1061. } else {
  1062. self.rightSideViewController.eidtPDFTextProperty.refreshSelectAreaProperty(needDefaultData: true)
  1063. }
  1064. self.openRightPane()
  1065. } else {
  1066. var textsAreas : [CPDFEditTextArea] = []
  1067. var imagesAreas : [CPDFEditImageArea] = []
  1068. if self.listView.editingAreas()?.count ?? 0 < 1 {
  1069. return
  1070. }
  1071. for i in 0 ... areas!.count-1 {
  1072. if areas![i] is CPDFEditTextArea {
  1073. textsAreas.append(areas![i] as! CPDFEditTextArea)
  1074. }
  1075. if areas![i] is CPDFEditImageArea {
  1076. imagesAreas.append(areas![i] as! CPDFEditImageArea)
  1077. }
  1078. }
  1079. if textsAreas.count > 0 && textsAreas.count == areas!.count {
  1080. // self.rightSideViewController.view.isHidden = false
  1081. self.rightSideViewController.isHidden = false
  1082. self.rightSideViewController.subViewType = .EditPDFAddText
  1083. self.rightSideViewController.eidtPDFTextProperty?.reloadData()
  1084. self.openRightPane()
  1085. } else if imagesAreas.count > 0 {
  1086. // self.rightSideViewController.view.isHidden = false
  1087. self.rightSideViewController.isHidden = false
  1088. self.rightSideViewController.subViewType = .EditPDFAddImage
  1089. self.rightSideViewController.eidtPDFImageProperty?.reloadData()
  1090. self.openRightPane()
  1091. }
  1092. }
  1093. if self.listView.isEdited() {
  1094. self.recordIsPDFDocumentEdited(type: .editText)
  1095. if self.listView.annotationType != .addText {
  1096. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kPDFViewEditingAreaDidChanged"), object: self.listView.document)
  1097. }
  1098. }
  1099. }
  1100. func pdfViewEditingCropBoundsDidChanged(_ pdfView: CPDFView!, editing editArea: CPDFEditArea!) {
  1101. if editArea != nil && (editArea is CPDFEditImageArea){
  1102. self.listView.cropAreas = editArea as? CPDFEditImageArea
  1103. }
  1104. }
  1105. //编辑PDF 创建图片区域回调
  1106. func pdfViewEditingAddImageArea(_ pdfView: CPDFView!, add page: CPDFPage!, add rect: CGRect) {
  1107. if self.listView.isEditImage {
  1108. self.menuItemEditingClick_CropImage(sender: NSMenuItem())
  1109. } else {
  1110. let panel = NSOpenPanel()
  1111. panel.allowsMultipleSelection = false
  1112. panel.allowedFileTypes = ["png","jpg"]
  1113. panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  1114. if response == .OK {
  1115. var filePath = panel.url?.path
  1116. var image = NSImage.init(contentsOf: panel.url!)
  1117. //图片自适应范围
  1118. if image != nil {
  1119. var imageRect = rect
  1120. let imageSize = image!.size
  1121. var previewSize = rect.size
  1122. var isChangeSize = false
  1123. if previewSize.width == 0 && previewSize.height == 0 {
  1124. previewSize = CGSize(width: 500, height: 500)
  1125. isChangeSize = true
  1126. }
  1127. let scale = min(previewSize.width / imageSize.width, previewSize.height / imageSize.height)
  1128. let newSize = CGSize(width: imageSize.width * scale, height: imageSize.height * scale)
  1129. if isChangeSize {
  1130. imageRect.origin.x = imageRect.origin.x - newSize.width / 2
  1131. imageRect.origin.y = imageRect.origin.y - newSize.height / 2
  1132. } else {
  1133. imageRect.origin.x = imageRect.origin.x + imageRect.width / 2 - newSize.width / 2
  1134. imageRect.origin.y = imageRect.origin.y + imageRect.height / 2 - newSize.height / 2
  1135. }
  1136. imageRect.size = newSize
  1137. let limitWidth = 1920.0
  1138. if imageSize.width > limitWidth || imageSize.height > limitWidth {
  1139. filePath = KMImageOptimization.needCompressImageLosslessly(image: image!,
  1140. targetSize: CGSize(width: limitWidth, height: limitWidth),
  1141. maxSizeInBytes: 1024 * 1024 * 5,
  1142. targetCompression: 1.0)
  1143. }
  1144. //自适应page
  1145. let pageRect = self.listView.currentPage().bounds
  1146. if imageRect.width > pageRect.width ||
  1147. imageRect.height > pageRect.height {
  1148. let pageScale = min(pageRect.width / imageSize.width, pageRect.height / imageSize.height)
  1149. imageRect = CGRect(x: imageRect.origin.x,
  1150. y: imageRect.origin.y,
  1151. width: imageRect.width * pageScale,
  1152. height: imageRect.height * pageScale)
  1153. }
  1154. if imageRect.origin.x < 0 {
  1155. imageRect.origin.x = 5
  1156. }
  1157. if imageRect.origin.y < 0 {
  1158. imageRect.origin.y = 5
  1159. }
  1160. if imageRect.origin.x + imageRect.width > pageRect.width ||
  1161. imageRect.origin.y + imageRect.height > pageRect.height {
  1162. let offsetX = imageRect.origin.x + imageRect.width - pageRect.width
  1163. let offsetY = imageRect.origin.y + imageRect.height - pageRect.height
  1164. imageRect.origin.x = imageRect.origin.x - offsetX - 5
  1165. imageRect.origin.y = imageRect.origin.y - offsetY - 5
  1166. }
  1167. DispatchQueue.main.async {
  1168. self.listView.createImagePath(filePath, rect: imageRect, page: pdfView.currentPage())
  1169. self.model.isPDFTextImageEdited = true
  1170. self.recordIsPDFDocumentEdited(type: .editImage)
  1171. // self.asyncSaveDocument { params in
  1172. //
  1173. // }
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. }
  1180. func pdfViewEditingAddTextArea(_ pdfView: CPDFView!, add page: CPDFPage!, add rect: CGRect) {
  1181. // print(rect)
  1182. var newrect = CGRect(x: rect.origin.x, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
  1183. if __CGSizeEqualToSize(rect.size, CGSize.zero) {
  1184. newrect = CGRect(x: rect.origin.x, y: rect.origin.y - 12, width: 20, height: 12)
  1185. } else {
  1186. newrect = CGRect(x: rect.origin.x, y: rect.origin.y + rect.size.height - 12, width: rect.size.width, height: 12)
  1187. }
  1188. let model = KMEditPDFTextManager.manager.fetchUserDefaultData(type: .commonly)
  1189. let fontName = KMEditPDFTextManager.manager.fetchFontName(fontName: model.fontName)
  1190. let fontSize = model.fontSize
  1191. let fontColor = model.color
  1192. let fontAlign = model.alignment
  1193. let fontStyle = KMEditPDFTextManager.manager.fetchFontStyle(fontName: model.fontName)
  1194. NSColorPanel.shared.color = fontColor
  1195. let font = KMEditPDFTextManager.manager.fetchFont(fontName: fontName, style: fontStyle, size: fontSize)
  1196. let style = NSMutableParagraphStyle()
  1197. style.alignment = fontAlign
  1198. let attributes = [NSAttributedString.Key.font:font, NSAttributedString.Key.foregroundColor:fontColor,NSAttributedString.Key.paragraphStyle:style] as [NSAttributedString.Key : Any]
  1199. self.listView.createEmptyStringBounds(newrect,withAttributes: attributes as [NSAttributedString.Key : Any], page: page)
  1200. if self.rightSideViewController != nil && self.rightSideViewController.subViewType == .EditPDFAddText && self.listView.annotationType == .addText {
  1201. self.rightSideViewController.eidtPDFTextProperty.refreshSelectAreaProperty(needDefaultData: true)
  1202. }
  1203. // self.asyncSaveDocument { params in
  1204. //
  1205. // }
  1206. }
  1207. func pdfListViewKeyDownIsContinue(_ pdfListView: CPDFListView!, theEvent: NSEvent!) -> Bool {
  1208. let command = theEvent.modifierFlags.contains(.command)
  1209. let control = theEvent.modifierFlags.contains(.control)
  1210. KMPrint(theEvent.keyCode)
  1211. if (theEvent.keyCode == 11 && command) { // command + B [添加书签]
  1212. self.menuItemBookMarkClick_add(sender: NSMenuItem())
  1213. return false
  1214. } else if (command && control && theEvent.keyCode == 14) { // command + control + E [注释 橡皮擦]
  1215. return false
  1216. } else if (theEvent.keyCode == 123) { // 向左
  1217. if(self.listView.isEditing() && !self.listView.isSelecteditAreaNotEdit()) {
  1218. return false
  1219. } else {
  1220. if (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage()) {
  1221. self.listView.goToPreviousPage(nil)
  1222. return false
  1223. }
  1224. }
  1225. } else if (theEvent.keyCode == 126) { // 向上
  1226. if(self.listView.isEditing() && !self.listView.isSelecteditAreaNotEdit()) {
  1227. return false
  1228. } else {
  1229. if (self.listView.isContinousScroll()) {
  1230. return true
  1231. }
  1232. if (self.pdfViewCanVerticalScroll() == false && self.listView.canGoToPreviousPage()) {
  1233. self.listView.goToPreviousPage(nil)
  1234. return false
  1235. }
  1236. }
  1237. } else if (theEvent.keyCode == 124) { // 向右
  1238. if(self.listView.isEditing() && !self.listView.isSelecteditAreaNotEdit()) {
  1239. return false
  1240. } else {
  1241. if (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage()) {
  1242. self.listView.goToNextPage(nil)
  1243. return false
  1244. }
  1245. }
  1246. } else if (theEvent.keyCode == 125) { // 向下
  1247. if(self.listView.isEditing() && !self.listView.isSelecteditAreaNotEdit()) {
  1248. return false
  1249. } else {
  1250. if (self.listView.isContinousScroll()) {
  1251. return true
  1252. }
  1253. if (self.pdfViewCanVerticalScroll() == false && self.listView.canGoToNextPage()) {
  1254. self.listView.goToNextPage(nil)
  1255. return false
  1256. }
  1257. }
  1258. } else if (theEvent.keyCode == 36) {
  1259. if self.listView.annotationType == .addImage || self.listView.annotationType == .addText {
  1260. if self.listView.isEditImage {
  1261. self.menuItemEditingClick_CropImage(sender: NSMenuItem())
  1262. }
  1263. }
  1264. }
  1265. if theEvent.keyCode == 53 {
  1266. self.exitFullScreen(Any.self)
  1267. if self.isReadMode {
  1268. self.closeReadModel()
  1269. }
  1270. self.leftSideViewCancelSelect()
  1271. if (self.toolbarController.toolbarType.isToolMode()) {
  1272. self.toolbarController.selectItem(self.toolbarController.toolbarType.itemIdentifier())
  1273. }
  1274. }
  1275. return true
  1276. }
  1277. func pdfListViewMenuValidate(_ pdfListView: CPDFListView!, menuItem: NSMenuItem!, isTakesEffect: UnsafeMutablePointer<ObjCBool>!) -> Bool {
  1278. guard let action = menuItem.action else {
  1279. isTakesEffect.pointee = false
  1280. return false
  1281. }
  1282. if (KMSystemMenu.isEditSelector(sel: action)) {
  1283. if (KMSystemMenu.Edit.deleteSelector == action) {
  1284. isTakesEffect.pointee = true
  1285. return self.listView.activeAnnotations.count > 0
  1286. } else if (KMSystemMenu.Edit.copySelector == action) {
  1287. isTakesEffect.pointee = true
  1288. return true//self.listView.canCopy()
  1289. } else if (KMSystemMenu.Edit.cutSelector == action) {
  1290. isTakesEffect.pointee = true
  1291. return self.listView.canCopy()
  1292. } else if (KMSystemMenu.Edit.pasteSelector == action) {
  1293. isTakesEffect.pointee = true
  1294. return self.listView.canPaste()
  1295. }
  1296. }
  1297. isTakesEffect.pointee = false
  1298. return false
  1299. }
  1300. //MARK: -CPDFListViewDelegate
  1301. func cPDFListView(_ pdfListView: CPDFListView, didDelete annotation: CPDFAnnotation, in pdfPage: CPDFPage) {
  1302. self.leftSideViewController.updateThumbnail(at: Int(pdfPage.pageIndex()))
  1303. }
  1304. func pdfListViewChangeatioActiveAnnotations(_ pdfListView: CPDFListView!, forActiveAnnotations annotations: [CPDFAnnotation]!, isRightMenu: Bool) {
  1305. self.view.window?.makeFirstResponder(self.listView)
  1306. if isRightMenu {
  1307. } else if annotations.count > 0 {
  1308. if annotations.count > 1 {
  1309. let fristAnnotation = annotations.first
  1310. var isSameAnnotation = true
  1311. let className = NSStringFromClass(fristAnnotation!.classForCoder)
  1312. for annotation in annotations {
  1313. let cunrrentClassName = NSStringFromClass(annotation.classForCoder)
  1314. if (className == "CPDFSquareAnnotation") ||
  1315. (className == "CPDFCircleAnnotation") ||
  1316. (className == "CPDFLineAnnotation") {
  1317. if (cunrrentClassName != "CPDFSquareAnnotation") &&
  1318. (cunrrentClassName != "CPDFCircleAnnotation") &&
  1319. (cunrrentClassName != "CPDFLineAnnotation") {
  1320. isSameAnnotation = false
  1321. }
  1322. } else {
  1323. if className != cunrrentClassName {
  1324. isSameAnnotation = false
  1325. }
  1326. }
  1327. }
  1328. if isSameAnnotation == false {
  1329. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: false)
  1330. // self.closeRightPane()
  1331. } else {
  1332. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: true)
  1333. self.openRightPane()
  1334. }
  1335. } else {
  1336. let fristAnnotation = annotations.first
  1337. let className = NSStringFromClass(fristAnnotation!.classForCoder)
  1338. if self.isReadMode {
  1339. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: false)
  1340. self.closeRightPane()
  1341. } else {
  1342. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: true)
  1343. if className != "CPDFStampAnnotation" &&
  1344. className != "CPDFSignatureAnnotation" &&
  1345. className != "CPDFListStampAnnotation" {
  1346. self.openRightPane()
  1347. }
  1348. }
  1349. }
  1350. } else if (annotations.count == 0){
  1351. if pdfListView.annotationType == .unkown {
  1352. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: false)
  1353. self.closeRightPane()
  1354. } else {
  1355. if self.isReadMode {
  1356. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: false)
  1357. self.closeRightPane()
  1358. } else {
  1359. self.rightSideViewController?.reloadDataWithPDFView(pdfView: pdfListView, isShow: true)
  1360. self.openRightPane()
  1361. }
  1362. }
  1363. }
  1364. }
  1365. func pdfListViewChangedAnnotationType(_ pdfListView: CPDFListView!, for annotationType: CAnnotationType) {
  1366. if(annotationType == .unkown) {
  1367. // self.rightSideViewController.view.isHidden = true
  1368. self.rightSideViewController.isHidden = true
  1369. self.closeRightPane()
  1370. }
  1371. let aType = annotationType
  1372. if aType.isMarkup() || aType == .anchored || aType == .freeText || aType.isSquare() || aType == .link {
  1373. KMDataManager.ud_set(annotationType.rawValue, forKey: SKLastAnnotationModeKey)
  1374. }
  1375. }
  1376. ///开始定位链接注释
  1377. func pdfListViewLinkDestinationStart(_ pdfListView: CPDFListView!, withActiveAnnotation annotation: CPDFAnnotation!) {
  1378. if self.locationPageView.superview == nil {
  1379. self.locationPageView.frame = CGRect(x: 0, y: pdfListView.frame.maxY-32, width: pdfListView.frame.width, height: 32)
  1380. pdfListView.addSubview(self.locationPageView)
  1381. }
  1382. }
  1383. ///刷新链接注释
  1384. func pdfListViewLinkDestinationEnd(_ pdfListView: CPDFListView!, withActiveAnnotation annotation: CPDFAnnotation!) {
  1385. if self.locationPageView.superview != nil {
  1386. self.locationPageView.removeFromSuperview()
  1387. }
  1388. if self.rightSideViewController.subViewType == .AnnotationProperts && pdfListView.annotationType == .link {
  1389. self.rightSideViewController.reloadDataWithPDFView(pdfView: pdfListView, isShow: true)
  1390. }
  1391. }
  1392. func pdfListViewMenuItemsEditing(at point: CGPoint, for page: CPDFPage!, menuItems: [NSMenuItem]!) -> [NSMenuItem]! {
  1393. if (listView.toolMode != CToolMode.editPDFToolMode) {
  1394. return menuItems
  1395. }
  1396. var tMenuItems = menuItems;
  1397. if(listView.isSelectEditCharRange() ||
  1398. listView.isSelecteditArea(with: point)) {
  1399. tMenuItems?.append(NSMenuItem.separator())
  1400. // tMenuItems?.append(self.fontColorMenuItem())
  1401. // tMenuItems?.append(self.fontSizeMenuItem())
  1402. }
  1403. let areas = self.listView.editingAreas() ?? []
  1404. if areas.count == 1 {
  1405. let fristAreas = areas.first
  1406. if fristAreas is CPDFEditImageArea {
  1407. self.listView.selectImageAreas = fristAreas as? CPDFEditImageArea
  1408. if self.listView.isEditImage {
  1409. tMenuItems?.removeAll()
  1410. tMenuItems?.append(self.corpImageMenuItem())
  1411. tMenuItems?.append(self.cancelCorpImageMenuItem())
  1412. tMenuItems?.append(self.restoreCorpImageMenuItem())
  1413. } else {
  1414. tMenuItems?.append(NSMenuItem.separator())
  1415. tMenuItems?.append(self.cutImageArea())
  1416. tMenuItems?.append(self.replaceImageArea())
  1417. tMenuItems?.append(self.exportImageArea())
  1418. }
  1419. } else {
  1420. if tMenuItems?.count != 1 {
  1421. tMenuItems?.swapAt(0, 1)
  1422. }
  1423. }
  1424. } else if areas.count == 0 {
  1425. tMenuItems?.append(NSMenuItem.separator())
  1426. tMenuItems?.append(self.addText())
  1427. tMenuItems?.append(self.addImage())
  1428. }
  1429. return tMenuItems
  1430. }
  1431. func tableMenu(_ menu: NSMenu, withTable table: KMTableAnnotation, point: CGPoint) -> NSMenu {
  1432. if table.currentCell.row >= 0 && table.currentCell.column >= 0 {
  1433. let itemTitles = ["Edit", "", "Add Row Above", "Add Row Below", "", "Add Column Before", "Add Column After", "", "Delete Row", "Delete Column", "Delete Table", "Cut", "Copy", "Paste", "Paste and Match Style", "Delete Cell Contents", "Clear All"]
  1434. let actions = ["formAnnotTextEdit:", "", "addRowAbove:", "addRowBelow:", "", "addColumnBefore:", "addColumnAfter:", "", "deleteRow:", "deleteColumn:", "deleteTabel", "cutCell:", "copyCell:", "pasteCell:", "pasteAndMatchStyle:", "deleteCellContents:", "clearAll:"]
  1435. for i in 0..<itemTitles.count {
  1436. var item: NSMenuItem? = nil
  1437. if itemTitles[i] == "" {
  1438. item = NSMenuItem.separator()
  1439. menu.insertItem(item!, at: i)
  1440. } else {
  1441. item = NSMenuItem(title: itemTitles[i], action: nil, keyEquivalent: "")
  1442. item!.target = self
  1443. item!.action = NSSelectorFromString(actions[i])
  1444. if itemTitles[i] == "Paste" /*&& !_copyCellData*/ {
  1445. item!.action = nil
  1446. } else if itemTitles[i] == "Paste and Match Style" /*&& !_copyCellData */{
  1447. item!.action = nil
  1448. } else if itemTitles[i] == "Add Row Above" {
  1449. let path1 = table.crossLines[table.rowNumber - table.currentCell.row]
  1450. let path2 = table.crossLines[table.rowNumber - table.currentCell.row - 1]
  1451. if (path1 as AnyObject).lineJoinStyle == NSBezierPath.LineJoinStyle.round && table.headerCount() >= 5 {
  1452. item!.action = nil
  1453. } else if (path2 as AnyObject).lineJoinStyle == NSBezierPath.LineJoinStyle.bevel && table.footerCount() >= 5 {
  1454. item!.action = nil
  1455. }
  1456. }
  1457. item!.title = NSLocalizedString(item!.title, comment: "")
  1458. item!.representedObject = NSValue(point: point)
  1459. menu.insertItem(item!, at: i)
  1460. }
  1461. }
  1462. } else {
  1463. let itemTitles = ["Cut", "Copy", "Paste", "Delete"]
  1464. let actions = ["cut:", "copy:", "paste:", "delete:"]
  1465. for i in 0..<itemTitles.count {
  1466. let item = NSMenuItem(title: itemTitles[i], action: nil, keyEquivalent: "")
  1467. item.target = self
  1468. item.action = NSSelectorFromString(actions[i])
  1469. item.title = NSLocalizedString(item.title, comment: "")
  1470. menu.insertItem(item, at: i)
  1471. item.representedObject = NSValue(point: point)
  1472. }
  1473. }
  1474. return menu
  1475. }
  1476. func pdfListViewMenu(forEvent pdfListView: CPDFListView!, for theEvent: NSEvent!, click menu: AutoreleasingUnsafeMutablePointer<NSMenu?>!, isMoveSelectAnno: Bool) {
  1477. self.mouseRightMenuEvent = theEvent
  1478. var currentMenu : NSMenu = menu.pointee!
  1479. if let activeAnno = listView.activeAnnotation as? KMTableAnnotation {//Table
  1480. var pagePoint = NSPoint()
  1481. _ = self.listView.pageAndPoint(&pagePoint, for: theEvent, nearest: true)
  1482. currentMenu.removeAllItems()
  1483. let annotation = activeAnno
  1484. annotation.completeEditCellText()
  1485. if !(NSIsEmptyRect(annotation.drawRect)) {
  1486. annotation.drawLine(pagePoint)
  1487. NotificationCenter.default.post(name: NSNotification.Name.KMPDFViewTableAnnotationDidChange, object: self, userInfo: ["point": NSValue(point: pagePoint)])
  1488. }
  1489. if (annotation.rowNumber - annotation.currentCell.row - 1) < 0 {
  1490. return
  1491. }
  1492. currentMenu = tableMenu(currentMenu, withTable: listView.activeAnnotation as! KMTableAnnotation, point: pagePoint)
  1493. listView.needsDisplay = true
  1494. return
  1495. }
  1496. if (listView.toolMode == .selectToolMode){
  1497. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1498. currentMenu.insertItem(self.printingMenu(), at: 3)
  1499. currentMenu.insertItem(self.setTTSStype(), at: 3)
  1500. currentMenu.insertItem(self.setCropStype(), at: 3)
  1501. currentMenu.insertItem(self.setSnapshotStype(), at: 3)
  1502. let export = NSMenuItem(title: NSLocalizedString("Export", comment: ""), action: nil, target: self)
  1503. export.submenu = self.exportMenu()
  1504. currentMenu.insertItem(export, at: 3)
  1505. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1506. if listView.activeAnnotation == nil{
  1507. currentMenu.insertItem(self.setAnnotationToolStype(), at: 3)
  1508. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1509. }
  1510. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 3)
  1511. currentMenu.insertItem(self.addReadModelStype(), at: currentMenu.items.count - 3)
  1512. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1513. currentMenu.insertItem(self.setAITranslateStype(), at: 0)
  1514. currentMenu.insertItem(self.setAIProofreadStype(), at: 0)
  1515. currentMenu.insertItem(self.setAIRewriteStype(), at: 0)
  1516. return
  1517. }
  1518. if (listView.toolMode == .moveToolMode || listView.toolMode == .magnifyToolMode){
  1519. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1520. currentMenu.insertItem(self.setTTSStype(), at: 0)
  1521. currentMenu.insertItem(self.setCropStype(), at: 0)
  1522. currentMenu.insertItem(self.setSnapshotStype(), at: 0)
  1523. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1524. currentMenu.insertItem(self.addOutlineStype(), at: 0)
  1525. currentMenu.insertItem(self.addBookmarkMenu(), at: 0)
  1526. if listView.activeAnnotation == nil{
  1527. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1528. currentMenu.insertItem(self.setAnnotationToolStype(), at: 0)
  1529. }
  1530. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1531. currentMenu.insertItem(self.setAITranslateStype(), at: 0)
  1532. currentMenu.insertItem(self.setAIProofreadStype(), at: 0)
  1533. currentMenu.insertItem(self.setAIRewriteStype(), at: 0)
  1534. return
  1535. }
  1536. if currentMenu.items.count > 3 {
  1537. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 3)
  1538. currentMenu.insertItem(self.addReadModelStype(), at: currentMenu.items.count - 3)
  1539. }
  1540. if listView.currentSelection != nil && listView.activeAnnotations.count < 1{
  1541. if listView.currentSelection.selectionType() == .text {
  1542. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1543. currentMenu.insertItem(self.setSearchBaiduStype(), at: 3)
  1544. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1545. currentMenu.insertItem(self.setLookUpStype(), at: 3)
  1546. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1547. currentMenu.insertItem(self.addOutlineStype(), at: 3)
  1548. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1549. // if listView.activeAnnotation == nil{
  1550. currentMenu.insertItem(self.setAnnotationToolStype(), at: 3)
  1551. // }
  1552. currentMenu.insertItem(self.setTTSStype(), at: 3)
  1553. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1554. currentMenu.insertItem(self.setShareStype(), at: 3)
  1555. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1556. }
  1557. currentMenu.insertItem(self.enterAnnotationStype(), at: 3)
  1558. currentMenu.insertItem(NSMenuItem.separator(), at: 3)
  1559. if listView.currentSelection.selectionType() == .image{
  1560. //
  1561. // currentMenu.insertItem(self.setCutStype(), at: 1)
  1562. // }
  1563. // if listView.activeAnnotations.count > 0 {
  1564. // currentMenu.insertItem(self.setDeleteStype(), at: 3)
  1565. currentMenu.insertItem(NSMenuItem.separator(), at: 6)
  1566. currentMenu.insertItem(self.addOutlineStype(), at: 6)
  1567. currentMenu.insertItem(NSMenuItem.separator(), at: 6)
  1568. currentMenu.insertItem(self.setAnnotationToolStype(), at: 6)
  1569. // currentMenu.insertItem(self.setEditNoteStype(), at: 6)
  1570. // currentMenu.insertItem(self.setRotateStype(), at: 6)
  1571. // currentMenu.insertItem(self.setLinesStype(), at: 6)
  1572. // currentMenu.insertItem(self.setColorsStype(), at: 6)
  1573. // }
  1574. }
  1575. if listView.currentSelection.selectionType() == .text {
  1576. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count)
  1577. currentMenu.insertItem(self.setTranslateStype(), at: currentMenu.items.count)
  1578. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count)
  1579. // currentMenu.insertItem(self.setServicesStype(), at: currentMenu.items.count)
  1580. }
  1581. }
  1582. if listView.activeAnnotation != nil || isMoveSelectAnno {
  1583. if let data = self.listView?.activeAnnotation?.type?.lowercased(), data == "stamp"{
  1584. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1585. currentMenu.insertItem(self.enterAnnotationStype(), at: currentMenu.items.count - 15)
  1586. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1587. }else{
  1588. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1589. currentMenu.insertItem(self.enterAnnotationStype(), at: currentMenu.items.count - 15)
  1590. // currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1591. // currentMenu.insertItem(self.setAnnotationToolStype(), at: currentMenu.items.count - 15)
  1592. // currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1593. // currentMenu.insertItem(self.addBookmarkMenu(), at: currentMenu.items.count - 15)
  1594. // currentMenu.insertItem(self.addOutlineStype(), at: currentMenu.items.count - 15)
  1595. // currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1596. // currentMenu.insertItem(self.setSnapshotStype(), at: currentMenu.items.count - 15)
  1597. // currentMenu.insertItem(self.setCropStype(), at: currentMenu.items.count - 15)
  1598. // currentMenu.insertItem(self.setTTSStype(), at: currentMenu.items.count - 15)
  1599. if let anno = self.listView.activeAnnotation, anno.isKind(of: CPDFStampAnnotation.self) {
  1600. // currentMenu.insertItem(self.setRotateStype(), at: currentMenu.items.count - 15)
  1601. } else {
  1602. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1603. currentMenu.insertItem(self.setShareStype(), at: currentMenu.items.count - 15)
  1604. }
  1605. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
  1606. }
  1607. }
  1608. if listView.activeAnnotation == nil && listView.currentSelection == nil{
  1609. currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count)
  1610. if(listView.toolMode == .selectToolMode) {
  1611. if NSIsEmptyRect(listView.currentSelectionRect()) {
  1612. currentMenu.insertItem(self.zoomSelectionMenuItem(), at: 0)
  1613. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1614. }
  1615. currentMenu.insertItem(self.printingMenu(), at: 0)
  1616. currentMenu.insertItem(self.setTTSStype(), at: 0)
  1617. currentMenu.insertItem(self.setCropStype(), at: 0)
  1618. currentMenu.insertItem(self.setSnapshotStype(), at: 0)
  1619. let export = NSMenuItem(title: NSLocalizedString("Export", comment: ""), action: nil, target: self)
  1620. export.submenu = self.exportMenu()
  1621. currentMenu.insertItem(export, at: currentMenu.items.count)
  1622. }else{
  1623. currentMenu.insertItem(NSMenuItem.separator(), at: 2)
  1624. currentMenu.insertItem(self.setTTSStype(), at: 2)
  1625. currentMenu.insertItem(self.setCropStype(), at: 2)
  1626. currentMenu.insertItem(self.setSnapshotStype(), at: 2)
  1627. currentMenu.insertItem(NSMenuItem.separator(), at: 2)
  1628. currentMenu.insertItem(self.addOutlineStype(), at: 2)
  1629. currentMenu.insertItem(NSMenuItem.separator(), at: 2)
  1630. currentMenu.insertItem(self.enterAnnotationStype(), at: 2)
  1631. currentMenu.insertItem(NSMenuItem.separator(), at: 2)
  1632. if(currentMenu.items.count > 4) {
  1633. currentMenu.insertItem(NSMenuItem.separator(), at: 5)
  1634. }
  1635. if(currentMenu.items.count > 5) {
  1636. currentMenu.insertItem(self.addBookmarkMenu(), at: 6)
  1637. }
  1638. // if (currentMenu.items.count > 6 && self.isReadMode) {
  1639. // currentMenu.removeItem(currentMenu.item(withTitle: "Zoom")!)
  1640. // }
  1641. // currentMenu.insertItem(self.findStringMenu(), at: currentMenu.items.count)
  1642. currentMenu.insertItem(self.setAutoScrollStype(), at: currentMenu.items.count)
  1643. }
  1644. currentMenu.insertItem(self.setAnnotationToolStype(), at: 5)
  1645. }
  1646. currentMenu.insertItem(NSMenuItem.separator(), at: 0)
  1647. currentMenu.insertItem(self.setAITranslateStype(), at: 0)
  1648. currentMenu.insertItem(self.setAIProofreadStype(), at: 0)
  1649. currentMenu.insertItem(self.setAIRewriteStype(), at: 0)
  1650. for item in currentMenu.items {
  1651. if (item.action == NSSelectorFromString("menuItemClick_HidenorShowNote:")) {
  1652. // 显示与隐藏注释 item action 截取
  1653. item.action = #selector(menuItemClick_HidenorShowNote)
  1654. item.target = self
  1655. break
  1656. }
  1657. }
  1658. }
  1659. func pdfListViewAddAnnotations(_ pdfListView: CPDFListView!, forAdd annotations: [CPDFAnnotation]!, in pdfPage: CPDFPage!) {
  1660. var addRedact = false
  1661. for anno in annotations {
  1662. if (anno.isKind(of: CPDFRedactAnnotation.self)) {
  1663. addRedact = true
  1664. } else if anno is CPDFSquareAnnotation || anno is CPDFCircleAnnotation {
  1665. anno.contents = pdfPage?.string(for: anno.bounds) ?? ""
  1666. }
  1667. }
  1668. self.model.hasAddRedact = addRedact
  1669. if /*self.isReadMode || */self.listView.toolMode == .moveToolMode {
  1670. self.listView.toolMode = .textToolMode
  1671. self.listView.annotationType = .unkown
  1672. self.toolbarController.toolbarType = .Annatiton
  1673. }
  1674. if (self.model.rightMouseEventing) {
  1675. self.model.rightMouseEventing = false
  1676. if (self.toolbarController.ignoreCurrentAnnotationTypeChange && self.listView.annotationType == .ink) {
  1677. self.listView.toolMode = .textToolMode
  1678. self.listView.annotationType = .unkown
  1679. }
  1680. }
  1681. self.toolbarController.ignoreCurrentAnnotationTypeChange = false
  1682. self.leftSideViewController.refreshUIForAddAnnotation(annos: annotations, page: pdfPage)
  1683. }
  1684. func pdfListViewRemoveAnnotations(_ pdfListView: CPDFListView!, forRemove annotations: [CPDFAnnotation]!, in pdfPage: CPDFPage!) {
  1685. self.leftSideViewController.annoList_refreshUIForDeleteAnnotations(annos: annotations, page: pdfPage)
  1686. }
  1687. func pdfListViewDidSelectionEnd(_ pdfListView: CPDFListView!) {
  1688. if (!self.listView.isEqual(to: pdfListView)) {
  1689. return
  1690. }
  1691. if (self.listView.toolMode != .selectToolMode) {
  1692. return
  1693. }
  1694. if (self.topTipBox.isHidden || self.topTipBox.contentView?.subviews.count == 0) {
  1695. return
  1696. }
  1697. let tipView = self.topTipBox.contentView?.subviews.first
  1698. if (tipView?.isKind(of: KMCropTipView.self) == false) {
  1699. return
  1700. }
  1701. (tipView as! KMCropTipView).setString(string: "请按 Enter 键确定裁剪区域")
  1702. }
  1703. func pdfListViewKeyDowClosePanel(_ speedy: CPDFViewSidebarSpeedMode, event theEvent: NSEvent!) {
  1704. if(speedy == .right) {
  1705. self.toggleRightPane()
  1706. } else if (speedy == .left) {
  1707. self.menuItemAction_hiddenLeftSide(speedy)
  1708. }
  1709. }
  1710. func pdfListViewEventMarkupColor(with annotation: CPDFAnnotation!) -> [NSColor]! {
  1711. if (annotation.isKind(of: CPDFMarkupAnnotation.self)) {
  1712. if (annotation as! CPDFMarkupAnnotation).markupType() == .highlight {
  1713. return KMAnnotationPropertiesColorManager.manager.markHighlightColors
  1714. } else {
  1715. return KMAnnotationPropertiesColorManager.manager.markOtherColors
  1716. }
  1717. } else {
  1718. return KMAnnotationPropertiesColorManager.manager.markOtherColors
  1719. }
  1720. }
  1721. func pdfListViewHaveDocumentAttribute() -> Bool {
  1722. if(!self.listView.document.allowsCopying) {
  1723. self.removeOwnerPassword()
  1724. return false
  1725. }
  1726. return true
  1727. }
  1728. func pdfListView(_ sender: CPDFListView!, showSnapshotAtPageNumber pageNum: Int, for rect: NSRect, scaleFactor: CGFloat, autoFits: Bool) {
  1729. let swc = KMSnapshotWindowController(windowNibName: "SnapshotWindow")
  1730. swc.delegate = self
  1731. swc.setPdfDocument(self.listView.document, goToPageNumber: pageNum, rect: rect, scaleFactor: scaleFactor, autoFits: autoFits)
  1732. swc.forceOnTop = self.interactionMode != .normal
  1733. self.myDocument?.addWindowController(swc)
  1734. }
  1735. func pdfListView(_ pdfView: CPDFListView!, documentDataDidChanged docData: Any!, withInfo info: [AnyHashable : Any]!) {
  1736. if let data = info?[CPDFListView.outlineKey] as? Bool, data { // 大纲改变
  1737. guard let ol = docData as? CPDFOutline else {
  1738. return
  1739. }
  1740. let add = info?[CPDFListView.outlineAddKey] as? Bool ?? false
  1741. let remove = info?[CPDFListView.outlineRemoveKey] as? Bool ?? false
  1742. if add {
  1743. self.leftSideViewController.addOutlineAfter(ol)
  1744. }
  1745. if remove {
  1746. self.leftSideViewController.removeOutlineAfter(ol)
  1747. }
  1748. let demote = info?[CPDFListView.outlineDemoteKey] as? Bool ?? false
  1749. let promote = info?[CPDFListView.outlinePromoteKey] as? Bool ?? false
  1750. if demote {
  1751. self.leftSideViewController.demoteOutlineAfter(ol)
  1752. }
  1753. if promote {
  1754. self.leftSideViewController.promoteOutlineAfter(ol)
  1755. }
  1756. }
  1757. }
  1758. //TextEdit
  1759. func pdfListViewDidTextFontChanged(_ pdfListView: CPDFListView!) {
  1760. self.rightSideViewController.eidtPDFTextProperty.reloadData()
  1761. }
  1762. func pdfListViewDidTextColorChanged(_ pdfListView: CPDFListView!, with color: NSColor!) {
  1763. self.rightSideViewController.eidtPDFTextProperty.fontColorChangeAction()
  1764. }
  1765. }