KMLeftSideViewController.swift 216 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315
  1. //
  2. // KMLeftSideViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lxy on 2022/10/10.
  6. //
  7. import Cocoa
  8. @objc protocol KMLeftSideViewControllerDelegate {
  9. @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
  10. @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
  11. @objc optional func searchAction(searchString:String, isCase:Bool)
  12. @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
  13. @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
  14. @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
  15. @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
  16. }
  17. class KMLeftSideViewController: KMSideViewController {
  18. // @IBOutlet weak var leftTableview: NSTableView!
  19. // @IBOutlet weak var leftBox: NSBox!
  20. lazy var annotationViewController : KMAnnotationViewController = {
  21. let annotationViewController = KMAnnotationViewController(nibName: "KMAnnotationViewController", bundle: nil)
  22. return annotationViewController
  23. }()
  24. lazy var bookViewController : KMBookMarkViewController = {
  25. let bookViewController = KMBookMarkViewController()
  26. bookViewController.bookMarkDidChange = { [unowned self] (controller, bookMarks) in
  27. self.delegate?.controller?(controller: self, bookMarkDidChange: bookMarks)
  28. }
  29. return bookViewController
  30. }()
  31. // lazy var signatureViewController : KMSignatureViewController = {
  32. // let signatureViewController = KMSignatureViewController()
  33. // return signatureViewController
  34. // }()
  35. lazy var panelSetViewController : KMPDFViewPanelSetViewController = {
  36. let panelSetViewController = KMPDFViewPanelSetViewController()
  37. // panelSetViewController.delegate = self
  38. return panelSetViewController
  39. }()
  40. var dataSource : [KMLeftMethodMode] = [KMLeftMethodMode]()
  41. var type : KMLeftMethodMode = KMLeftMethodMode()
  42. var isShowPanel : Bool = false
  43. var norImage : [String] = []
  44. var selectImage : [String] = []
  45. var mainVC: KMMainViewController?
  46. var selectPages: [Int]?
  47. open weak var delegate: KMLeftSideViewControllerDelegate?
  48. deinit {
  49. KMPrint("KMLeftSideViewController deinit.")
  50. NotificationCenter.default.removeObserver(self)
  51. }
  52. override var nibName: NSNib.Name? {
  53. return "LeftSideView"
  54. }
  55. convenience init(type : KMLeftMethodMode) {
  56. self.init()
  57. self.type = type
  58. }
  59. override func viewDidAppear() {
  60. super.viewDidAppear()
  61. // self.annotationViewController.view.isHidden = true
  62. }
  63. override func viewDidLoad() {
  64. super.viewDidLoad()
  65. // self.leftBox.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
  66. // self.leftTableview.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
  67. // self.leftTableview.border(NSColor.km_init(hex: "#EDEEF0"),1 , 0)
  68. // self.addMenuTitle()
  69. // self.refreshShowMethod()
  70. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  71. self.annotationViewController.listView = self.listView
  72. self.view.addSubview(self.annotationViewController.view)
  73. self.annotationViewController.reloadData()
  74. // self.annotationViewController.view.isHidden = true
  75. self.annotationViewController.view.frame = NSMakeRect(0, 0, 1, 1)
  76. // self.annotationViewController.annotationOutlineView.outlineView.delegate = nil
  77. // self.annotationViewController.annotationOutlineView.outlineView.dataSource = nil
  78. }
  79. func showPanelView(show: Bool) {
  80. self.isShowPanel = show
  81. if show {
  82. // self.panelSetViewController.listView = self.listView
  83. // self.panelSetViewController.view.frame = self.view.frame
  84. // self.view.addSubview(self.panelSetViewController.view)
  85. // self.panelSetViewController.reloadListViewModel()
  86. // self.panelSetViewController.view.autoresizingMask = [.height]
  87. } else {
  88. // self.contentBox.isHidden = false
  89. // self.panelSetViewController.view.removeFromSuperview()
  90. // if self.type.methodType == .None {
  91. // self.delegate?.controlStateChange?(self, show: false)
  92. // }
  93. }
  94. }
  95. func refreshMethodType(methodType: BotaType) {
  96. if (self.isShowPanel) {
  97. self.showPanelView(show: false)
  98. return
  99. }
  100. let newType = KMLeftMethodMode()
  101. var show = true
  102. if self.type.methodType != methodType {
  103. newType.methodType = methodType
  104. }
  105. if self.type.methodType == methodType {
  106. show = false
  107. }
  108. self.type = newType;
  109. // self.refreshShowMethod()
  110. self.delegate?.controlStateChange?(self,show:show)
  111. }
  112. //
  113. // private func updateViewButtonState() {
  114. // switch self.type.methodType {
  115. // case .None: do {
  116. //// self.contentBox.contentView = NSView()
  117. // self.delegate?.controlStateChange?(self,show:false)
  118. // }
  119. // break
  120. // case .Thumbnail: do {
  121. // self.thumbnailViewController.listView = self.listView
  122. // self.thumbnailViewController.delegate = self
  123. //// self.contentBox.contentView = self.thumbnailViewController.view
  124. //// self.thumbnailViewController.reloadData()
  125. // }
  126. // break
  127. // case .Outline: do {
  128. // }
  129. // break
  130. // case .BookMark: do {
  131. // self.bookViewController.listView = self.listView
  132. //// self.contentBox.contentView = self.bookViewController.view
  133. // self.bookViewController.reloadData()
  134. // }
  135. // break
  136. // case .Annotation: do {
  137. // self.annotationViewController.listView = self.listView
  138. //// self.contentBox.contentView = self.annotationViewController.view
  139. //// self.annotationViewController.reloadData()
  140. // }
  141. // break
  142. // break
  143. // case .Signature: do {
  144. // self.signatureViewController.listView = self.listView
  145. //// self.contentBox.contentView = self.signatureViewController.view
  146. // self.signatureViewController.reloadData()
  147. // }
  148. // break
  149. // }
  150. // }
  151. // func refreshShowMethod() {
  152. // self.dataSource = [KMLeftMethodMode]()
  153. // norImage = []
  154. // selectImage = []
  155. // if KMBOTAManagerClass.shard.getMethodShow(key: thumbnailMethodKey) {
  156. // let mode = KMLeftMethodMode()
  157. // mode.methodName = thumbnailMethodKey
  158. // mode.methodType = .Thumbnail
  159. // self.dataSource.insert(mode, at: self.dataSource.count)
  160. // norImage.append("KMImageNameSidebarThumbailNor")
  161. // selectImage.append("KMImageNameSidebarThumbailSelect")
  162. // }
  163. // if KMBOTAManagerClass.shard.getMethodShow(key: outlineMethodKey) {
  164. // let mode = KMLeftMethodMode()
  165. // mode.methodName = outlineMethodKey
  166. // mode.methodType = .Outline
  167. // self.dataSource.insert(mode, at: self.dataSource.count)
  168. // norImage.append("KMImageNameSidebarOutlineNor")
  169. // selectImage.append("KMImageNameSidebarOutlineSelect")
  170. // }
  171. // if KMBOTAManagerClass.shard.getMethodShow(key: bookMarkMethodKey) {
  172. // let mode = KMLeftMethodMode()
  173. // mode.methodName = bookMarkMethodKey
  174. // mode.methodType = .BookMark
  175. // self.dataSource.insert(mode, at: self.dataSource.count)
  176. // norImage.append("KMImageNameSidebarBookMarkNor")
  177. // selectImage.append("KMImageNameSidebarBookMarkSelect")
  178. // }
  179. // if KMBOTAManagerClass.shard.getMethodShow(key: anntationMethodKey) {
  180. // let mode = KMLeftMethodMode()
  181. // mode.methodName = anntationMethodKey
  182. // mode.methodType = .Annotation
  183. // self.dataSource.insert(mode, at: self.dataSource.count)
  184. // norImage.append("KMImageNameSidebarAnnotationNor")
  185. // selectImage.append("KMImageNameSidebarAnnotationSelect")
  186. // }
  187. // if KMBOTAManagerClass.shard.getMethodShow(key: searchMethodKey) {
  188. // let mode = KMLeftMethodMode()
  189. // mode.methodName = searchMethodKey
  190. // mode.methodType = .Search
  191. // self.dataSource.insert(mode, at: self.dataSource.count)
  192. // norImage.append("KMImageNameSidebarSearchNor")
  193. // selectImage.append("KMImageNameSidebarSearchSelect")
  194. // }
  195. //// if KMBOTAManagerClass.shard.getMethodShow(key: formMethodKey) {
  196. //// let mode = KMLeftMethodMode()
  197. //// mode.methodName = formMethodKey
  198. //// mode.methodType = .From
  199. //// self.dataSource.insert(mode, at: self.dataSource.count)
  200. //// }
  201. //// if KMBOTAManagerClass.shard.getMethodShow(key: signatureMethodKey) {
  202. //// let mode = KMLeftMethodMode()
  203. //// mode.methodName = signatureMethodKey
  204. //// mode.methodType = .Signature
  205. //// self.dataSource.insert(mode, at: self.dataSource.count)
  206. //// }
  207. // var isConstant = false
  208. // for source in dataSource {
  209. // if self.type.methodType == source.methodType {
  210. // isConstant = true
  211. // }
  212. // }
  213. // if(!isConstant) {
  214. // self.type = KMLeftMethodMode()
  215. // }
  216. //// self.leftTableview.reloadData()
  217. // var typeIndex = -1
  218. // for (index,value) in self.dataSource.enumerated() {
  219. // if value.methodType == self.type.methodType {
  220. // typeIndex = index
  221. // }
  222. // }
  223. //
  224. //// self.leftTableview.selectRowIndexes([typeIndex], byExtendingSelection: true)
  225. // if self.dataSource.count > 0 && typeIndex >= 0 {
  226. // self.type = self.dataSource[typeIndex]
  227. // }
  228. // self.updateViewButtonState()
  229. //
  230. // }
  231. //
  232. //MARK: menu
  233. // private func addMenuTitle() {
  234. // let menus : NSMenu = NSMenu(title: "")
  235. //
  236. // let addItem = self.menuItemWithTitle(title: NSLocalizedString("Thumbnails", comment: ""),type:thumbnailMethodKey,action: #selector(renameBookAction),tag: 1)
  237. // let outlineItem = self.menuItemWithTitle(title: NSLocalizedString("Outline", comment: ""),type:outlineMethodKey,action: #selector(renameBookAction),tag: 2)
  238. // let bookItem = self.menuItemWithTitle(title: NSLocalizedString("Bookmarks", comment: ""), type:bookMarkMethodKey,action: #selector(renameBookAction),tag: 3)
  239. // let annationItem = self.menuItemWithTitle(title: NSLocalizedString("Annotations", comment: ""), type:anntationMethodKey,action: #selector(renameBookAction),tag: 4)
  240. // let searchItem = self.menuItemWithTitle(title: NSLocalizedString("Search", comment: ""), type:searchMethodKey,action: #selector(renameBookAction),tag: 5)
  241. //// let formItem = self.menuItemWithTitle(title: NSLocalizedString("域", comment: ""), type:formMethodKey,action: #selector(renameBookAction),tag: 6)
  242. //// let signatureItem = self.menuItemWithTitle(title: NSLocalizedString("签名", comment: ""), type:signatureMethodKey,action: #selector(renameBookAction),tag: 7)
  243. //
  244. // menus.addItem(addItem)
  245. // menus.addItem(outlineItem)
  246. // menus.addItem(bookItem)
  247. // menus.addItem(annationItem)
  248. // menus.addItem(searchItem)
  249. //// menus.addItem(formItem)
  250. //// menus.addItem(signatureItem)
  251. //// self.leftTableview.menu = menus
  252. // }
  253. // func menuItemWithTitle(title:String,type:String,action:Selector?,tag:Int) -> NSMenuItem {
  254. // let menuItem = NSMenuItem.init(title: title as String, action: action, keyEquivalent: "")
  255. // menuItem.target = self
  256. // menuItem.tag = tag
  257. // if KMBOTAManagerClass.shard.getMethodShow(key: type) {
  258. // menuItem.state = NSControl.StateValue.on
  259. // } else {
  260. // menuItem.state = NSControl.StateValue.off
  261. // }
  262. // return menuItem
  263. // }
  264. // @objc func renameBookAction(menuItem:NSMenuItem) {
  265. // var show = true
  266. // if menuItem.state == NSControl.StateValue.on {
  267. // menuItem.state = NSControl.StateValue.off
  268. // show = false
  269. // } else {
  270. // menuItem.state = NSControl.StateValue.on
  271. // show = true
  272. // }
  273. // switch menuItem.tag {
  274. // case 1: do {
  275. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: thumbnailMethodKey)
  276. // }
  277. // case 2: do {
  278. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: outlineMethodKey)
  279. // }
  280. // case 3: do {
  281. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: bookMarkMethodKey)
  282. // }
  283. // case 4: do {
  284. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: anntationMethodKey)
  285. // }
  286. // case 5: do {
  287. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: searchMethodKey)
  288. // }
  289. // case 6: do {
  290. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: formMethodKey)
  291. // }
  292. // case 7: do {
  293. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: signatureMethodKey)
  294. // }
  295. // break
  296. // default:
  297. // break
  298. // }
  299. // self.refreshShowMethod()
  300. // }
  301. // MARK: - New
  302. /*
  303. NSArrayController *thumbnailArrayController;
  304. NSArrayController *findArrayController;
  305. NSArrayController *groupedFindArrayController;
  306. }
  307. - (void)applySearchTableHeader:(NSString *)message;
  308. - (void)displayFindState;
  309. */
  310. // @property (nonatomic, retain) IBOutlet NSArrayController *thumbnailArrayController, *findArrayController, *groupedFindArrayController;
  311. @IBOutlet var segmentedControl: KMSegmentedControl!
  312. @IBOutlet var thumbnailTableView: KMThumbnailTableView!
  313. @IBOutlet var tocOutlineView: KMTocOutlineView!
  314. @IBOutlet var noteOutlineView: KMNoteOutlineView!
  315. @IBOutlet var findTableView: KMBotaTableView!
  316. @IBOutlet var groupedFindTableView: KMBotaTableView!
  317. @IBOutlet var snapshotTableView: KMBotaTableView!
  318. @IBOutlet weak var leftListView: NSView!
  319. @IBOutlet var searchViewController: KMBotaSearchViewController!
  320. @IBOutlet weak var toolButtonBox: NSBox!
  321. @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
  322. @IBOutlet weak var snapshotNormalView: NSView!
  323. @IBOutlet weak var snapshotLabel: NSTextField!
  324. @IBOutlet weak var snapshotNormalMoreButton: NSButton!
  325. @IBOutlet weak var snapshotNormalSearchButton: NSButton!
  326. @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
  327. @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
  328. @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
  329. @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
  330. @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
  331. @IBOutlet weak var snapshotDoneButton: NSButton!
  332. @IBOutlet weak var outlineView: NSView!
  333. @IBOutlet weak var outlineMoreButton: NSButton!
  334. @IBOutlet weak var outlineAddButton: NSButton!
  335. @IBOutlet weak var outlineSearchButton: NSButton!
  336. @IBOutlet weak var outlineLabel: NSTextField!
  337. @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
  338. @IBOutlet weak var outlineDoneButton: NSButton!
  339. @IBOutlet weak var noteView: NSView!
  340. @IBOutlet weak var noteMoreButton: NSButton!
  341. @IBOutlet weak var noteFilterButton: NSButton!
  342. @IBOutlet weak var noteSearchButton: NSButton!
  343. @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
  344. @IBOutlet weak var noteTitleLabel: NSTextField!
  345. @IBOutlet weak var noteHeaderView: NSView!
  346. @IBOutlet weak var sortTypeBox: KMBox!
  347. @IBOutlet weak var sortTypeLabel: NSTextField!
  348. @IBOutlet weak var noteSortButton: NSButton!
  349. @IBOutlet weak var noteDoneButton: NSButton!
  350. @IBOutlet weak var thumbnailView: NSView!
  351. @IBOutlet weak var thumbnailZoomOutButton: NSButton!
  352. @IBOutlet weak var thumbnailZoomInButton: NSButton!
  353. @IBOutlet weak var thumbnailTitleLabel: NSTextField!
  354. @IBOutlet weak var emptySearchBox: NSBox!
  355. @IBOutlet weak var emptySearchLabel: NSTextField!
  356. var filterButtonLayer: NSView?
  357. var moreButtonLayer: KMButtonLayer?
  358. var thumbnails: [KMThumbnail] = []
  359. var isDisplayPageSize = false
  360. var thumbnailCacheSize: CGFloat = 32 * 3
  361. var findState: KMFindState = .content
  362. // var searchResults: [CPDFSelection] = []
  363. var searchResults : [KMSearchMode] = [] {
  364. didSet {
  365. self.updataLeftSideFindView()
  366. }
  367. }
  368. var findPaneState: KMFindPaneState = .singular
  369. var isSearchOutlineMode = false
  370. var outlineIgnoreCaseFlag = false
  371. var noteTypeDict: [String : Any] = [:]
  372. private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
  373. private let LABEL_COLUMNID = "label"
  374. var foldType: KMFoldAllAnnotationType = .none
  375. private let KMLeftSideViewNoteSortTypeKey = "KMLeftSideViewNoteSortTypeKey"
  376. private let KMLeftSideViewAscendSortBoolKey = "KMLeftSideViewAscendSortBoolKey"
  377. var tocType: KMFoldType = .none
  378. var snapshots: [Any] = []
  379. private var _noteSortType: KMNoteSortType = .none
  380. var noteSortType: KMNoteSortType {
  381. get {
  382. return self._noteSortType
  383. }
  384. set {
  385. self._noteSortType = newValue
  386. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
  387. }
  388. }
  389. var isAscendSort = false {
  390. didSet {
  391. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
  392. }
  393. }
  394. lazy var leftSideEmptyVC: KMLeftSideEmptyFileViewController = {
  395. let vc = KMLeftSideEmptyFileViewController(nibName: "KMLeftSideEmptyFileViewController", bundle: nil)
  396. vc.view.wantsLayer = true
  397. return vc
  398. }()
  399. var preThumbnailRow: Int = 0
  400. var leftMargin: CGFloat = 0
  401. lazy var leftView: KMBotaLeftView = {
  402. let view = KMBotaLeftView()
  403. return view
  404. }()
  405. override func loadView() {
  406. super.loadView()
  407. self.view.wantsLayer = true
  408. self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  409. self.view.addSubview(self.leftView)
  410. self.leftView.frame = NSMakeRect(0, 0, 44, NSHeight(self.view.frame))
  411. self.leftView.autoresizingMask = [.height]
  412. self.leftView.wantsLayer = true
  413. self.leftView.layer?.backgroundColor = .white
  414. self.outlineView.wantsLayer = true
  415. self.outlineView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  416. self.noteView.wantsLayer = true
  417. self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  418. self.thumbnailView.wantsLayer = true
  419. self.thumbnailView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  420. self.snapshotNormalView.wantsLayer = true
  421. self.snapshotNormalView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  422. self.tocOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
  423. self.noteOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
  424. self.findTableView.backgroundColor = KMAppearance.Layout.l0Color()
  425. self.groupedFindTableView.backgroundColor = KMAppearance.Layout.l0Color()
  426. self.snapshotTableView.backgroundColor = KMAppearance.Layout.l0Color()
  427. self.thumbnailTableView.backgroundColor = KMAppearance.Layout.l0Color()
  428. self.leftListView.wantsLayer = true
  429. self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  430. self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
  431. self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
  432. self.emptySearchBox.isHidden = true
  433. self.thumbnailTitleLabel.stringValue = KMLocalizedString("Thumbnails", nil)
  434. self.thumbnailTitleLabel.textColor = KMAppearance.Layout.h0Color()
  435. self.thumbnailZoomInButton.action = #selector(thumbnailSizeScaling)
  436. self.thumbnailZoomInButton.target = self
  437. self.thumbnailZoomInButton.tag = 1
  438. self.thumbnailZoomOutButton.action = #selector(thumbnailSizeScaling)
  439. self.thumbnailZoomOutButton.target = self
  440. self.thumbnailZoomOutButton.tag = 0
  441. self.snapshotTableView.delegate = self
  442. self.snapshotTableView.dataSource = self
  443. // [[snapshotTableView menu] setDelegate:mainController];
  444. // [snapshotTableView setDoubleAction:@selector(toggleSelectedSnapshots:)];
  445. // [snapshotTableView setTarget:mainController];
  446. self.snapshotTableView.backgroundColor = .clear
  447. // [snapshotTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
  448. self.snapshotLabel.stringValue = KMLocalizedString("Snapshots", nil)
  449. self.snapshotLabel.textColor = KMAppearance.Layout.h0Color()
  450. self.snapshotNormalZoomInButton.action = #selector(thumbnailSizeScaling)
  451. self.snapshotNormalZoomInButton.target = self
  452. self.snapshotNormalZoomInButton.tag = 2
  453. self.snapshotNormalZoomOutButton.action = #selector(thumbnailSizeScaling)
  454. self.snapshotNormalZoomOutButton.target = self
  455. self.snapshotNormalZoomOutButton.tag = 3
  456. self.snapshotNormalSearchButton.toolTip = KMLocalizedString("Search", nil)
  457. self.snapshotNormalMoreButton.action = #selector(leftSideViewMoreButtonAction)
  458. self.snapshotNormalMoreButton.target = self
  459. self.snapshotNormalMoreButton.tag = 300
  460. self.snapshotSearchZoomInButton.action = #selector(thumbnailSizeScaling)
  461. self.snapshotSearchZoomInButton.target = self
  462. self.snapshotSearchZoomInButton.tag = 2
  463. self.snapshotSearchZoomOutButton.action = #selector(thumbnailSizeScaling)
  464. self.snapshotSearchZoomOutButton.target = self
  465. self.snapshotSearchZoomOutButton.tag = 3
  466. self.snapshotDoneButton.title = KMLocalizedString("Done", nil)
  467. self.snapshotDoneButton.toolTip = KMLocalizedString("Done", nil)
  468. self.snapshotDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  469. self.snapshotDoneButton.wantsLayer = true
  470. self.snapshotDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  471. self.snapshotDoneButton.layer?.cornerRadius = 4.0
  472. self.snapshotDoneButton.action = #selector(leftSideViewDoneButtonAction)
  473. self.snapshotDoneButton.target = self
  474. self.snapshotDoneButton.tag = 312
  475. self.snapshotDoneButton.isHidden = true
  476. // [noteOutlineView setAutoresizesOutlineColumn: NO];
  477. self.noteOutlineView.delegate = self
  478. self.noteOutlineView.dataSource = self
  479. // [[noteOutlineView menu] setDelegate:mainController];
  480. // [noteOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
  481. // [noteOutlineView setIndentationPerLevel:0.0];
  482. // [noteOutlineView registerForDraggedTypes:[NSColor readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]];
  483. self.snapshotSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  484. self.outlineSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  485. self.noteSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  486. self.snapshotSearchField.wantsLayer = true
  487. self.outlineSearchField.wantsLayer = true
  488. self.noteSearchField.wantsLayer = true
  489. self.snapshotSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  490. self.outlineSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  491. self.noteSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  492. self.snapshotSearchField.layer?.borderWidth = 1.0
  493. self.outlineSearchField.layer?.borderWidth = 1.0
  494. self.noteSearchField.layer?.borderWidth = 1.0
  495. self.snapshotSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  496. self.outlineSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  497. self.noteSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  498. // __block typeof(self) blockSelf = self;
  499. // _snapshotSearchField.changeCallBack = ^(NSString *changeContent) {
  500. // NSString *editContent = @"";
  501. // if (changeContent) {
  502. // editContent = changeContent;
  503. // }
  504. // [blockSelf.mainController searchFieldChangeAction:editContent];
  505. // };
  506. self.snapshotSearchField.isHidden = true
  507. self.snapshotSearchZoomOutButton.isHidden = true
  508. self.snapshotSearchZoomInButton.isHidden = true
  509. // _snapshotSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  510. // if (isEndEdit/* && searchViewController.segmentedControl.segmentCount == 3*/) {
  511. // _snapshotSearchField.hidden = YES;
  512. // _snapshotSearchZoomOutButton.hidden = YES;
  513. // _snapshotSearchZoomInButton.hidden = YES;
  514. // _snapshotLabel.hidden = NO;
  515. // _snapshotNormalZoomOutButton.hidden = NO;
  516. // _snapshotNormalZoomInButton.hidden = NO;
  517. // }
  518. // };
  519. self.thumbnailZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  520. self.snapshotNormalZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  521. self.snapshotSearchZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  522. self.thumbnailZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  523. self.snapshotNormalZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  524. self.snapshotSearchZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  525. self.outlineLabel.stringValue = KMLocalizedString("Outline", nil);
  526. self.outlineLabel.textColor = KMAppearance.Layout.h0Color()
  527. self.outlineAddButton.toolTip = KMLocalizedString("Add Item", nil)
  528. self.outlineAddButton.action = #selector(outlineContextMenuItemClicked_AddEntry)
  529. self.outlineAddButton.target = self
  530. self.outlineSearchButton.toolTip = KMLocalizedString("Search", nil)
  531. self.outlineMoreButton.action = #selector(leftSideViewMoreButtonAction)
  532. self.outlineMoreButton.target = self
  533. self.outlineMoreButton.tag = 302
  534. self.outlineDoneButton.title = KMLocalizedString("Done", nil);
  535. self.outlineDoneButton.toolTip = KMLocalizedString("Done", nil);
  536. self.outlineDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  537. self.outlineDoneButton.wantsLayer = true
  538. self.outlineDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  539. self.outlineDoneButton.layer?.cornerRadius = 4.0
  540. self.outlineDoneButton.action = #selector(leftSideViewDoneButtonAction)
  541. self.outlineDoneButton.target = self
  542. self.outlineDoneButton.tag = 310
  543. self.outlineDoneButton.isHidden = true
  544. self.outlineSearchField.isHidden = true
  545. // _outlineSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  546. // if (isEndEdit) {
  547. // _outlineSearchField.hidden = YES;
  548. // _outlineLabel.hidden = NO;
  549. // _outlineSearchButton.hidden = NO;
  550. // }
  551. // };
  552. // NSMenu *menuOutline = [NSMenu menu];
  553. // [menuOutline addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleOutlineCaseInsensitiveSearch:) target:mainController];
  554. // [[_outlineSearchField cell] setSearchMenuTemplate:menuOutline];
  555. (self.outlineSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Outline", nil)
  556. self.outlineSearchField.target = self
  557. let sud = UserDefaults.standard
  558. self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
  559. self.noteTitleLabel.textColor = KMAppearance.Layout.h0Color()
  560. self.noteMoreButton.action = #selector(leftSideViewMoreButtonAction)
  561. self.noteMoreButton.target = self
  562. self.noteMoreButton.tag = 304
  563. self.noteMoreButton.wantsLayer = true
  564. self.moreButtonLayer = KMButtonLayer()
  565. self.noteMoreButton.layer?.addSublayer(self.moreButtonLayer!)
  566. self.moreButtonLayer?.frame = CGRectMake(0, 0, CGRectGetWidth(self.noteMoreButton.bounds), CGRectGetHeight(self.noteMoreButton.bounds))
  567. self.moreButtonLayer?.layerType = .none
  568. self.moreButtonLayer?.isHidden = true
  569. self.noteFilterButton.action = #selector(noteFilterAction)
  570. self.noteFilterButton.target = self
  571. self.noteFilterButton.toolTip = KMLocalizedString("Sort", nil)
  572. self.noteFilterButton.wantsLayer = true
  573. self.filterButtonLayer = NSView()
  574. self.noteFilterButton.addSubview(self.filterButtonLayer!)
  575. self.filterButtonLayer?.frame = CGRectMake(14, 2, 8, 8)
  576. // self.filterButtonLayer?.layerType = KMNoteFilerButtonLayerType_Dot
  577. self.filterButtonLayer?.isHidden = true
  578. self.filterButtonLayer?.wantsLayer = true
  579. self.filterButtonLayer?.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  580. self.filterButtonLayer?.layer?.cornerRadius = 4.0
  581. self.noteDoneButton.title = KMLocalizedString("Done", nil)
  582. self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
  583. self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  584. self.noteDoneButton.wantsLayer = true
  585. self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  586. self.noteDoneButton.layer?.cornerRadius = 4.0
  587. self.noteDoneButton.action = #selector(leftSideViewDoneButtonAction)
  588. self.noteDoneButton.target = self
  589. self.noteDoneButton.tag = 311
  590. self.noteDoneButton.isHidden = true
  591. self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
  592. self.noteSearchField.isHidden = true
  593. self.noteSearchField.endEditCallBack = { [unowned self] isEndEdit in
  594. if (isEndEdit) {
  595. self.noteSearchField.isHidden = true
  596. self.noteSearchButton.isHidden = false
  597. self.noteTitleLabel.isHidden = false
  598. }
  599. };
  600. self.noteHeaderView.wantsLayer = true
  601. self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
  602. self.noteHeaderView.layer?.cornerRadius = 1.0
  603. let sortType = sud.integer(forKey: KMLeftSideViewNoteSortTypeKey)
  604. if (sortType == 1) {
  605. self.noteSortType = KMNoteSortType(rawValue: sortType)!
  606. if (self.noteSortType == .time) {
  607. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  608. self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
  609. } else if (self._noteSortType == .page) {
  610. self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
  611. self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
  612. }
  613. } else {
  614. self.noteSortType = .time
  615. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  616. }
  617. self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
  618. self.isAscendSort = sud.bool(forKey: KMLeftSideViewAscendSortBoolKey)
  619. if (self.isAscendSort) {
  620. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  621. self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  622. } else {
  623. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  624. self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  625. }
  626. self.sortTypeBox.downCallback = { [unowned self] downEntered, mouseBox, _ in
  627. if (downEntered) {
  628. let menu = NSMenu()
  629. let timeItem = menu.addItem(title: KMLocalizedString("Time", nil), action: #selector(sortTypeAction), target: self)
  630. timeItem?.representedObject = self
  631. timeItem?.tag = 0
  632. let pageItem = menu.addItem(title: KMLocalizedString("Page", nil), action: #selector(sortTypeAction), target: self)
  633. pageItem?.representedObject = self
  634. timeItem?.tag = 1
  635. if (self.noteSortType == .time) {
  636. timeItem?.state = .on
  637. pageItem?.state = .off
  638. } else if (self.noteSortType == .page) {
  639. timeItem?.state = .off
  640. pageItem?.state = .on
  641. }
  642. menu.popUp(positioning: nil, at: CGPointMake(-10, 0), in: self.sortTypeBox)
  643. }
  644. }
  645. self.searchViewController.loadView()
  646. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  647. self.searchField = self.searchViewController.searchField
  648. self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
  649. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
  650. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
  651. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
  652. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
  653. self.searchViewController.segmentedControl.isBackgroundHighlighted = true
  654. self.searchViewController.segmentedControl.selectedSegment = 0
  655. self.searchViewController.segmentedControl.block = { [unowned self] segIndex in
  656. if segIndex == 0 {
  657. self.findPaneState = .singular
  658. self.displayFindViewAnimating(false)
  659. } else {
  660. self.findPaneState = .grouped
  661. self.displayGroupedFindViewAnimating(false)
  662. }
  663. }
  664. // [mainController bind:@"findPaneState" toObject:searchViewController.segmentedControl withKeyPath:@"selectedSegment" options:nil];
  665. self.leftView.segmentedControl.block = { [unowned self] segIndex in
  666. self.toolButtonBox.isHidden = false
  667. self.toolButtonBoxLayoutConstraint.constant = 40.0
  668. if (segIndex == 0) {
  669. self.toolButtonBox.contentView = self.thumbnailView
  670. self.displayThumbnailViewAnimating(true)
  671. } else if (segIndex == 1) {
  672. self.toolButtonBox.contentView = self.outlineView
  673. self.displayTocViewAnimating(false)
  674. } else if (segIndex == 2) {
  675. self.toolButtonBox.contentView = self.noteView
  676. self.displayNoteViewAnimating(false)
  677. } else if (segIndex == 3) {
  678. self.toolButtonBox.contentView = self.snapshotNormalView
  679. self.displaySnapshotViewAnimating(false)
  680. self.updataLeftSideSnapView()
  681. } else if (segIndex == 4) {
  682. self.toolButtonBox.isHidden = true
  683. self.toolButtonBoxLayoutConstraint.constant = 0
  684. self.displayFindViewAnimating(false)
  685. }
  686. }
  687. // self.button.setHelp(KMLocalizedString("View Thumbnails", "Tool tip message"), for: KMLeftSidePaneState.thumbnail.rawValue)
  688. // self.button.setHelp(KMLocalizedString("View Outline", "Tool tip message"), for: KMLeftSidePaneState.outline.rawValue)
  689. // self.alternateButton.setHelp(KMLocalizedString("Separate search results", "Tool tip message"), for: KMFindPaneState.singular.rawValue)
  690. // self.alternateButton.setHelp(KMLocalizedString("Group search results by page", "Tool tip message"), for: KMFindPaneState.grouped.rawValue)
  691. // NSMenu *menu = [NSMenu menu];
  692. // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
  693. // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
  694. // [[searchField cell] setSearchMenuTemplate:menu];
  695. // [[searchField cell] setPlaceholderString:NSLocalizedString(@"Search PDF", @"placeholder")];
  696. self.searchField.action = #selector(search)
  697. self.searchField.target = self
  698. self.tocOutlineView.autoresizesOutlineColumn = false
  699. self.tocOutlineView.allowsMultipleSelection = true
  700. self.tocOutlineView.allowsEmptySelection = true
  701. self.tocOutlineView.delegate = self
  702. self.tocOutlineView.dataSource = self
  703. self.thumbnailTableView.delegate = self
  704. self.thumbnailTableView.dataSource = self
  705. self.thumbnailTableView.allowsMultipleSelection = true
  706. self.findTableView.delegate = self
  707. self.findTableView.dataSource = self
  708. self.groupedFindTableView.delegate = self
  709. self.groupedFindTableView.dataSource = self
  710. // [[thumbnailTableView menu] setDelegate:mainController];
  711. // [[findTableView menu] setDelegate:mainController];
  712. // [[groupedFindTableView menu] setDelegate:mainController];
  713. // [tocOutlineView setDoubleAction:@selector(goToSelectedOutlineItem:)];
  714. // [tocOutlineView setTarget:mainController];
  715. // [findTableView setDoubleAction:@selector(goToSelectedFindResults:)];
  716. // [findTableView setTarget:mainController];
  717. // [groupedFindTableView setDoubleAction:@selector(goToSelectedFindResults:)];
  718. // [groupedFindTableView setTarget:mainController];
  719. // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
  720. // //支持拖拽的文字类型
  721. // [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
  722. // [tocOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
  723. // [tocOutlineView registerForDraggedTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType]];
  724. // [[[findTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
  725. // [[[groupedFindTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
  726. // [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] dataCell] setEnabled:NO];
  727. // if (RUNNING_AFTER(10_9)) {
  728. // [thumbnailTableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
  729. // [(SKSourceListTextFieldCell *)[[thumbnailTableView tableColumnWithIdentifier:PAGE_COLUMNID] dataCell] setSimulatesSourceList:YES];
  730. // }
  731. // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
  732. // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
  733. //
  734. // [thumbnailTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
  735. // if (NO == [[NSUserDefaults standardUserDefaults] boolForKey:SKDisableTableToolTipsKey]) {
  736. // [tocOutlineView setHasImageToolTips:YES];
  737. // [findTableView setHasImageToolTips:YES];
  738. // [groupedFindTableView setHasImageToolTips:YES];
  739. // }
  740. // [self updateViewColor];
  741. }
  742. func displayThumbnailViewAnimating(_ animate: Bool) {
  743. self.replaceSideView(self.thumbnailTableView.enclosingScrollView!, animate: animate)
  744. var frame = self.thumbnailTableView.enclosingScrollView?.frame ?? .zero
  745. frame.origin.y = 0
  746. frame.origin.x = self.leftMargin
  747. frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  748. self.thumbnailTableView.enclosingScrollView?.frame = frame
  749. self.resetThumbnails()
  750. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  751. frame.origin.y = 0
  752. frame.origin.x = self.leftMargin
  753. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  754. self.noteOutlineView.enclosingScrollView?.frame = frame
  755. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  756. frame.origin.y = 0
  757. frame.origin.x = self.leftMargin
  758. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  759. self.snapshotTableView.enclosingScrollView?.frame = frame
  760. // [self updateThumbnailSelection];
  761. }
  762. func displayFindViewAnimating(_ animate: Bool) {
  763. self.replaceSideView(self.searchViewController.view, animate: animate)
  764. if (self.findState != .content) {
  765. self.findState = .content
  766. } else {
  767. self.displayFindState()
  768. }
  769. var frame = self.searchViewController.view.frame
  770. frame.origin.y = 0
  771. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
  772. self.searchViewController.view.frame = frame
  773. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  774. frame.origin.y = 0
  775. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  776. self.noteOutlineView.enclosingScrollView?.frame = frame
  777. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  778. frame.origin.y = 0
  779. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  780. self.snapshotTableView.enclosingScrollView?.frame = frame
  781. self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
  782. self.updataLeftSideSnapView()
  783. }
  784. func displayFindState() {
  785. if (self.findState == .content) {
  786. self.displayFind()
  787. } else if (self.findState == .note) {
  788. // [self displayNoteFind];
  789. } else if (self.findState == .snapshot) {
  790. // [self displaySnapshotFind];
  791. }
  792. }
  793. func updataLeftSideSnapView() {
  794. if (snapshots.count < 1) {
  795. self.snapshotNormalSearchButton.isEnabled = false
  796. // leftSideController.snapshotSearchZoomOutButton.enabled = NO;
  797. self.snapshotNormalZoomOutButton.isEnabled = false
  798. // leftSideController.snapshotSearchZoomInButton.enabled = NO;
  799. self.snapshotNormalZoomInButton.isEnabled = false
  800. self.snapshotNormalMoreButton.isEnabled = false
  801. self.leftSideEmptyVC.deleteSnapBtn.isEnabled = false
  802. self.leftSideEmptyVC.exportSnapBtn.isEnabled = false
  803. self.leftSideEmptyVC.printSnapBtn.isEnabled = false
  804. self.snapshotTableView.usesAlternatingRowBackgroundColors = false
  805. let view = self.snapshotTableView.enclosingScrollView!
  806. let emptyVcSize = self.leftSideEmptyVC.emptySnapView.frame.size
  807. self.leftSideEmptyVC.emptySnapView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
  808. self.leftSideEmptyVC.emptySnapView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  809. self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptySnapView)
  810. } else {
  811. self.snapshotNormalSearchButton.isEnabled = true
  812. // leftSideController.snapshotSearchZoomOutButton.enabled = YES;
  813. self.snapshotNormalZoomOutButton.isEnabled = true
  814. // leftSideController.snapshotSearchZoomInButton.enabled = YES;
  815. self.snapshotNormalZoomInButton.isEnabled = true
  816. self.snapshotNormalMoreButton.isEnabled = true
  817. self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
  818. self.leftSideEmptyVC.deleteSnapBtn.isEnabled = true
  819. self.leftSideEmptyVC.exportSnapBtn.isEnabled = true
  820. self.leftSideEmptyVC.printSnapBtn.isEnabled = true
  821. }
  822. }
  823. func updataLeftSideFindView() {
  824. if (self.findState != .content) {
  825. return
  826. }
  827. if (self.searchResults.count > 0) {
  828. self.searchViewController.emptyBox.isHidden = true
  829. self.searchViewController.searchResultsView.isHidden = false
  830. self.searchViewController.searchResultsLabel.stringValue = String(format: KMLocalizedString("%ld Results", "Message in search table header"), self.searchResults.count)
  831. } else {
  832. self.searchViewController.emptyBox.isHidden = false
  833. self.searchViewController.searchResultsView.isHidden = true
  834. }
  835. }
  836. func displayGroupedFindViewAnimating(_ animate: Bool) {
  837. self.replaceSideView(self.searchViewController.view , animate: animate)
  838. if (self.findState != .content) {
  839. self.findState = .content
  840. } else {
  841. self.displayFindState()
  842. }
  843. var frame = self.searchViewController.view.frame
  844. frame.origin.y = 0
  845. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? 0
  846. self.searchViewController.view.frame = frame
  847. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  848. frame.origin.y = 0
  849. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  850. self.noteOutlineView.enclosingScrollView?.frame = frame
  851. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  852. frame.origin.y = 0
  853. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  854. self.snapshotTableView.enclosingScrollView?.frame = frame
  855. self.updataLeftSideSnapView()
  856. }
  857. func displayNoteViewAnimating(_ animate: Bool) {
  858. self.searchViewController.contentView = nil
  859. self.replaceSideView(self.noteOutlineView.enclosingScrollView!, animate: animate)
  860. if (self.findState != .note) {
  861. self.findState = .note
  862. } else {
  863. self.displayFindState()
  864. }
  865. var frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  866. frame.origin.y = 0
  867. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  868. self.noteOutlineView.enclosingScrollView?.frame = frame
  869. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  870. frame.origin.y = 0
  871. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  872. self.noteOutlineView.enclosingScrollView?.frame = frame
  873. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  874. frame.origin.y = 0
  875. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  876. self.snapshotTableView.enclosingScrollView?.frame = frame
  877. let view = self.noteOutlineView.enclosingScrollView!
  878. let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  879. self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  880. DispatchQueue.main.async {
  881. self.noteOutlineView.reloadData()
  882. }
  883. }
  884. func displaySnapshotViewAnimating(_ animate: Bool) {
  885. self.searchViewController.contentView = nil
  886. self.replaceSideView(self.snapshotTableView.enclosingScrollView!, animate: animate)
  887. if (self.findState != .snapshot) {
  888. self.findState = .snapshot;
  889. } else {
  890. self.displayFindState()
  891. }
  892. var frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  893. frame.origin.y = 0
  894. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  895. self.snapshotTableView.enclosingScrollView?.frame = frame
  896. // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  897. // frame.origin.y = 0;
  898. // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  899. // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  900. frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
  901. frame.origin.y = 0
  902. frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  903. self.tocOutlineView.enclosingScrollView?.frame = frame
  904. // [self updateSnapshotsIfNeeded];
  905. }
  906. func displayFind() {
  907. self.searchField = self.searchViewController.searchField
  908. let menu = NSMenu()
  909. // menu.addItem(title: <#T##String#>, action: <#T##Selector?#>, target: <#T##AnyObject?#>)
  910. // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
  911. // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
  912. // [[searchViewController.searchField cell] setSearchMenuTemplate:menu];
  913. (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
  914. // self.searchViewController.searchField.target =
  915. // [searchViewController.searchField setAction:@selector(search:)];
  916. // [searchViewController.searchField setTarget:mainController];
  917. if (self.findPaneState == .singular) {
  918. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  919. self.findTableView.wantsLayer = true
  920. self.findTableView.layer?.backgroundColor = NSColor.red.cgColor
  921. DispatchQueue.main.async {
  922. self.findTableView.reloadData()
  923. }
  924. } else if (self.findPaneState == .grouped) {
  925. self.searchViewController.contentView = self.groupedFindTableView.enclosingScrollView
  926. self.groupedFindTableView.reloadData()
  927. }
  928. }
  929. func displayTocViewAnimating(_ animate: Bool) {
  930. self.replaceSideView(self.tocOutlineView.enclosingScrollView!, animate: animate)
  931. var frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
  932. frame.origin.y = 0
  933. frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  934. self.tocOutlineView.enclosingScrollView?.frame = frame
  935. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  936. frame.origin.y = 0
  937. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  938. self.noteOutlineView.enclosingScrollView?.frame = frame
  939. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  940. frame.origin.y = 0
  941. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  942. self.snapshotTableView.enclosingScrollView?.frame = frame
  943. // [self updateOutlineSelection];
  944. let view = self.tocOutlineView.enclosingScrollView!
  945. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  946. self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
  947. }
  948. /*
  949. @implementation SKLeftSideViewController
  950. @synthesize thumbnailArrayController, findArrayController, groupedFindArrayController;
  951. - (BOOL)requiresAlternateButtonForView:(NSView *)aView {
  952. return NO;
  953. return [findTableView isDescendantOf:aView] || [groupedFindTableView isDescendantOf:aView];
  954. }
  955. - (void)applySearchTableHeader:(NSString *)message {
  956. [[[findTableView tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
  957. [[findTableView headerView] setNeedsDisplay:YES];
  958. [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell] setStringValue:message];
  959. [[groupedFindTableView headerView] setNeedsDisplay:YES];
  960. }
  961. - (void)displayFindState {
  962. if (mainController.findState == SKFindStateContent) {
  963. [self displayFind];
  964. } else if (mainController.findState == SKFindStateNote) {
  965. [self displayNoteFind];
  966. } else if (mainController.findState == SKFindStateSnapshot) {
  967. [self displaySnapshotFind];
  968. }
  969. }
  970. - (void)displayNoteFind {
  971. mainController.rightSideController.searchField = self.noteSearchField;
  972. NSMenu *menu = [NSMenu menu];
  973. [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
  974. [[self.noteSearchField cell] setSearchMenuTemplate:menu];
  975. [[self.noteSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Notes", @"placeholder")];
  976. [self.noteSearchField setAction:@selector(searchNotes:)];
  977. [self.noteSearchField setTarget:mainController];
  978. }
  979. - (void)displaySnapshotFind {
  980. mainController.rightSideController.searchField = self.snapshotSearchField;
  981. NSMenu *menu = [NSMenu menu];
  982. [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
  983. [[self.snapshotSearchField cell] setSearchMenuTemplate:menu];
  984. [[self.snapshotSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Snapshots", @"placeholder")];
  985. [self.snapshotSearchField setAction:@selector(searchNotes:)];
  986. [self.snapshotSearchField setTarget:mainController];
  987. [self.snapshotSearchField setDelegate:mainController];
  988. }
  989. */
  990. @IBAction func search(_ sender: NSSearchField) {
  991. self.delegate?.searchAction?(searchString: sender.stringValue, isCase: false)
  992. }
  993. @IBAction func snapshotNormalSearchButtonAction(_ sender: NSButton) {
  994. self.snapshotSearchField.isHidden = false
  995. // _snapshotSearchZoomOutButton.hidden = YES;
  996. self.snapshotSearchZoomInButton.isHidden = true
  997. self.snapshotNormalSearchButton.isHidden = true
  998. self.snapshotDoneButton.isHidden = false
  999. self.snapshotLabel.isHidden = true
  1000. self.snapshotNormalZoomOutButton.isHidden = true
  1001. self.snapshotNormalZoomInButton.isHidden = true
  1002. self.snapshotSearchField.becomeFirstResponder()
  1003. }
  1004. func resetThumbnails() {
  1005. // [self willChangeValueForKey:THUMBNAILS_KEY];
  1006. // self.thumbnailCacheSize = 160
  1007. self.thumbnails.removeAll()
  1008. let pageLabels = self.listView.document.pageLabels()
  1009. if (pageLabels.isEmpty == false) {
  1010. let isLocked = self.listView.document.isLocked
  1011. let firstPage = self.listView.document.page(at: 0)
  1012. // SKPDFPage
  1013. let emptyPage = CPDFPage()
  1014. let firstFrame = firstPage?.bounds(for: .cropBox) ?? .zero
  1015. let firstFrame2 = firstPage?.bounds(for: .mediaBox) ?? .zero
  1016. emptyPage.setBounds(firstFrame, for: .cropBox)
  1017. emptyPage.setBounds(firstFrame2, for: .mediaBox)
  1018. emptyPage.rotation = firstPage?.rotation ?? 0
  1019. let pageImage = firstPage!.thumbnail(of: NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize))
  1020. // NSImage * = [emptyPage thumbnailWithSize:thumbnailCacheSize forBox:[pdfView displayBox]];
  1021. var rect: NSRect = .zero
  1022. rect.size = pageImage?.size ?? .zero
  1023. let width = 1.2 * fmin(NSWidth(rect), NSHeight(rect))
  1024. rect = NSInsetRect(rect, 0.5 * (NSWidth(rect) - width), 0.5 * (NSHeight(rect) - width));
  1025. pageImage?.lockFocus()
  1026. // NSImage(named: NSImage.applicationIconName)?.draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
  1027. if (isLocked) {
  1028. NSWorkspace.shared.icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kLockedBadgeIcon))).draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
  1029. // [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:0.5];
  1030. }
  1031. pageImage?.unlockFocus()
  1032. // __block typeof(self) blockSelf = self;
  1033. for (i, label) in pageLabels.enumerated() {
  1034. let firstPage = self.listView.document.page(at: UInt(i))
  1035. let size = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
  1036. let pageImage = firstPage!.thumbnail(of: size)
  1037. let thumbnail = KMThumbnail(image: pageImage, label: label, pageIndex: i)
  1038. // thumbnail.delegate = self
  1039. thumbnail.dirty = true
  1040. self.thumbnails.append(thumbnail)
  1041. }
  1042. }
  1043. // [self didChangeValueForKey:THUMBNAILS_KEY];
  1044. // [self allThumbnailsNeedUpdate];
  1045. DispatchQueue.main.async {
  1046. self.thumbnailTableView.reloadData()
  1047. }
  1048. }
  1049. @IBAction @objc func sortTypeAction(_ sender: NSMenuItem) {
  1050. let item = sender
  1051. let tag = item.tag
  1052. if (item.state == .on) {
  1053. item.state = .off
  1054. } else {
  1055. item.state = .on
  1056. }
  1057. if (tag == 0) {
  1058. self.noteSortType = .page
  1059. self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
  1060. self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
  1061. } else if (tag == 1) {
  1062. self.noteSortType = .time
  1063. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  1064. self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
  1065. }
  1066. UserDefaults.standard.set(self.noteSortType.rawValue, forKey: KMLeftSideViewNoteSortTypeKey)
  1067. UserDefaults.standard.synchronize()
  1068. }
  1069. @IBAction func noteSortAction(_ sender: AnyObject?) {
  1070. if (self.isAscendSort) {
  1071. self.isAscendSort = false
  1072. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  1073. self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  1074. } else {
  1075. self.isAscendSort = true
  1076. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  1077. self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  1078. }
  1079. UserDefaults.standard.setValue(self.isAscendSort, forKey: KMLeftSideViewAscendSortBoolKey)
  1080. UserDefaults.standard.synchronize()
  1081. }
  1082. @IBAction func noteSearchAction(_ sender: NSButton) {
  1083. self.noteSearchField.isHidden = false
  1084. self.noteTitleLabel.isHidden = true
  1085. self.noteSearchButton.isHidden = true
  1086. self.noteDoneButton.isHidden = false
  1087. self.noteFilterButton.isHidden = true
  1088. self.noteMoreButton.isHidden = true
  1089. self.noteSearchField.becomeFirstResponder()
  1090. }
  1091. @IBAction func leftSideViewDoneButtonAction(_ sender: AnyObject?) {
  1092. let button = sender as? NSButton
  1093. let tag = button?.tag ?? 0
  1094. if (tag == 310) {
  1095. self.outlineSearchField.isHidden = true
  1096. self.outlineDoneButton.isHidden = true
  1097. self.outlineLabel.isHidden = false
  1098. self.outlineSearchButton.isHidden = false
  1099. self.outlineMoreButton.isHidden = false
  1100. self.outlineAddButton.isHidden = false
  1101. } else if (tag == 311) {
  1102. self.noteSearchField.isHidden = true
  1103. self.noteTitleLabel.isHidden = false
  1104. self.noteSearchButton.isHidden = false
  1105. self.noteDoneButton.isHidden = true
  1106. self.noteFilterButton.isHidden = false
  1107. self.noteMoreButton.isHidden = false
  1108. } else if (tag == 312) {
  1109. self.snapshotSearchField.isHidden = true
  1110. // leftSideController.snapshotSearchZoomOutButton.hidden = YES;
  1111. // leftSideController.snapshotSearchZoomInButton.hidden = YES;
  1112. self.snapshotNormalSearchButton.isHidden = false
  1113. self.snapshotDoneButton.isHidden = true
  1114. self.snapshotLabel.isHidden = false
  1115. self.snapshotNormalZoomOutButton.isHidden = false
  1116. self.snapshotNormalZoomInButton.isHidden = false
  1117. }
  1118. }
  1119. @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
  1120. let button = sender as? NSButton
  1121. let tag = button?.tag ?? 0
  1122. if (tag == 300) {
  1123. // NSInteger selectedRow = 0;
  1124. // if (rightSideController.snapshotTableView.selectedRow >= 0) {
  1125. // selectedRow = rightSideController.snapshotTableView.selectedRow;
  1126. // } else {
  1127. // return;
  1128. // }
  1129. // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:selectedRow];
  1130. // NSMenu *menu = [[[NSMenu alloc] init] autorelease];
  1131. // NSMenuItem *itemExport = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil target:self];
  1132. // NSMenu *subMenu = [NSMenu menu];
  1133. //
  1134. // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(menuItemClick_ExportPNG:) target:self];
  1135. // [t setRepresentedObject:controller];
  1136. //
  1137. // t = [subMenu addItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(menuItemClick_ExportJPG:) target:self];
  1138. // [t setRepresentedObject:controller];
  1139. //
  1140. // t = [subMenu addItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(menuItemClick_ExportPDF:) target:self];
  1141. // [t setRepresentedObject:controller];
  1142. // itemExport.submenu = subMenu;
  1143. //
  1144. // NSMenuItem *itemPrint = [menu addItemWithTitle:NSLocalizedString(@"Print", @"Menu item title") action:@selector(menuItemClick_Print:) target:self];
  1145. // [itemPrint setRepresentedObject:controller];
  1146. // [menu addItem:[NSMenuItem separatorItem]];
  1147. //
  1148. // NSMenuItem *itemSelectAll = [menu addItemWithTitle:NSLocalizedString(@"Select All", @"Menu item title") action:@selector(menuItemClick_SelectAll:) target:self];
  1149. // [itemSelectAll setRepresentedObject:controller];
  1150. // [menu addItem:[NSMenuItem separatorItem]];
  1151. //
  1152. // NSMenuItem *itemDeleteAllSnapshot = [menu addItemWithTitle:NSLocalizedString(@"Delete All Snapshots", @"Menu item title") action:@selector(deleteAllSnapshot:) target:self];
  1153. // [itemDeleteAllSnapshot setRepresentedObject:controller];
  1154. //
  1155. // [NSMenu popUpContextMenu:menu withEvent:[NSApp currentEvent] forView:(NSButton *)sender];
  1156. } else if (tag == 302) {
  1157. let menu = NSMenu()
  1158. // NSMenuItem *addEntryItem = [menu addItemWithTitle:NSLocalizedString(@"Add Item", nil) action:@selector(outlineContextMenuItemClicked_AddEntry:) target:self];
  1159. // [addEntryItem setRepresentedObject:self.leftSideController.tocOutlineView];
  1160. // NSMenuItem *addChildItem = [menu addItemWithTitle:NSLocalizedString(@"Add Sub-Item", nil) action:@selector(outlineContextMenuItemClicked_AddChildEntry:) target:self];
  1161. // [addChildItem setRepresentedObject:self.leftSideController.tocOutlineView];
  1162. // [menu addItem:[NSMenuItem separatorItem]];
  1163. //
  1164. // NSMenuItem *setDestinationItem = [menu addItemWithTitle:NSLocalizedString(@"Change Destination", nil) action:@selector(outlineContextMenuItemClicked_SetDestination:) target:self];
  1165. // [setDestinationItem setRepresentedObject:self.leftSideController.tocOutlineView];
  1166. // [menu addItem:[NSMenuItem separatorItem]];
  1167. let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
  1168. expandAllCommentsItem?.representedObject = self.tocOutlineView
  1169. let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
  1170. expandAllCommentsItem?.representedObject = self.tocOutlineView
  1171. let item = self.listView.document.outlineRoot()
  1172. var num = 0
  1173. for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
  1174. let outline = item?.child(at: UInt(i))
  1175. if self.tocOutlineView.isItemExpanded(outline) {
  1176. num += 1
  1177. }
  1178. }
  1179. if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
  1180. self.tocType = .fold
  1181. } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
  1182. self.tocType = .unfold
  1183. } else {
  1184. self.tocType = .none
  1185. }
  1186. if (self.tocType == .unfold) {
  1187. expandAllCommentsItem?.state = .on
  1188. foldAllCommentsItem?.state = .off
  1189. } else if (self.tocType == .fold) {
  1190. expandAllCommentsItem?.state = .off
  1191. foldAllCommentsItem?.state = .on
  1192. } else {
  1193. expandAllCommentsItem?.state = .off
  1194. foldAllCommentsItem?.state = .off
  1195. }
  1196. let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
  1197. removeEntryItem?.representedObject = self.tocOutlineView
  1198. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
  1199. } else if (tag == 304) {
  1200. let menu = NSMenu()
  1201. let object = KMPopupMenuObject()
  1202. object.menuTag = 1001
  1203. menu.delegate = object
  1204. object.enterControllerCallback = { [weak self] isEnter in
  1205. if (isEnter) {
  1206. self?.moreButtonLayer?.isHidden = false
  1207. } else {
  1208. self?.moreButtonLayer?.isHidden = true
  1209. }
  1210. }
  1211. let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
  1212. expandAllCommentsItem?.representedObject = self.noteOutlineView
  1213. let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
  1214. foldAllCommentsItem?.representedObject = self.noteOutlineView
  1215. if (self.foldType == .unfold) {
  1216. expandAllCommentsItem?.state = .on
  1217. foldAllCommentsItem?.state = .off
  1218. } else if (self.foldType == .fold) {
  1219. expandAllCommentsItem?.state = .off
  1220. foldAllCommentsItem?.state = .on
  1221. } else {
  1222. expandAllCommentsItem?.state = .off
  1223. foldAllCommentsItem?.state = .off
  1224. }
  1225. let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
  1226. let subMenu = NSMenu()
  1227. // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"Type", nil) action:@selector(noteShowNoteAction:) target:self];
  1228. // if ([[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue]) {
  1229. // [t setState:NSControlStateValueOff];
  1230. // } else {
  1231. // [t setState:NSControlStateValueOn];
  1232. // }
  1233. // [t setRepresentedObject:self.rightSideController.noteOutlineView];
  1234. // t.tag = 100;
  1235. var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
  1236. let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
  1237. if pageKey {
  1238. t?.state = .off
  1239. } else {
  1240. t?.state = .on
  1241. }
  1242. t?.representedObject = self.noteOutlineView
  1243. t?.tag = 101
  1244. t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
  1245. let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
  1246. if timeKey {
  1247. t?.state = .off
  1248. } else {
  1249. t?.state = .on
  1250. }
  1251. t?.representedObject = self.noteOutlineView
  1252. t?.tag = 102
  1253. t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
  1254. let authorKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
  1255. if authorKey {
  1256. t?.state = .off
  1257. } else {
  1258. t?.state = .on
  1259. }
  1260. t?.representedObject = self.noteOutlineView
  1261. t?.tag = 103
  1262. showAnnotationItem?.submenu = subMenu
  1263. menu.addItem(.separator())
  1264. let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: ""), action: nil, target: self)
  1265. let subMenu2 = NSMenu()
  1266. var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1267. t2?.representedObject = self.noteOutlineView
  1268. t2?.tag = 0
  1269. t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1270. t2?.representedObject = self.noteOutlineView
  1271. t2?.tag = 1
  1272. t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1273. t2?.representedObject = self.noteOutlineView
  1274. t2?.tag = 2
  1275. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1276. t2?.representedObject = self.noteOutlineView
  1277. t2?.tag = 3
  1278. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1279. t2?.representedObject = self.noteOutlineView
  1280. t2?.tag = 4
  1281. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1282. t2?.representedObject = self.noteOutlineView
  1283. t2?.tag = 5
  1284. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1285. t2?.representedObject = self.noteOutlineView
  1286. t2?.tag = 6
  1287. exportAnnotationsItem?.submenu = subMenu2
  1288. menu.addItem(.separator())
  1289. let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
  1290. removeAllAnnotationsItem?.representedObject = self.noteOutlineView
  1291. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: button!, with: nil)
  1292. }
  1293. }
  1294. @IBAction func note_expandAllComments(_ sender: AnyObject?) {
  1295. if (self.foldType == .unfold) {
  1296. return
  1297. }
  1298. self.foldType = .unfold
  1299. // [self loadUnfoldDate:KMFoldAllAnnotationType_None];
  1300. self.noteOutlineView.reloadData()
  1301. }
  1302. @IBAction func note_foldAllComments(_ sender: AnyObject?) {
  1303. if (self.foldType == .fold) {
  1304. return
  1305. }
  1306. self.foldType = .fold
  1307. // [self loadUnfoldDate:KMFoldAllAnnotationType_None];
  1308. self.noteOutlineView.reloadData()
  1309. }
  1310. @IBAction func noteShowNoteAction(_ sender: AnyObject?) {
  1311. let item = sender as? NSMenuItem
  1312. let tag = item?.tag ?? 0
  1313. if (tag == 100) {
  1314. // BOOL isType = [[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue];
  1315. // [self.noteTypeDict setObject:[NSNumber numberWithBool:!isType] forKey:@"kKMNoteFilterAnnotationTypeKey"];
  1316. } else if (tag == 101) {
  1317. let isPage = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
  1318. self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] = isPage
  1319. } else if (tag == 102) {
  1320. let isTime = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
  1321. self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] = isTime
  1322. } else if (tag == 103) {
  1323. let isAuther = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
  1324. self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] = isAuther
  1325. }
  1326. UserDefaults.standard.set(self.noteTypeDict, forKey: "KMNoteOutlineViewTableColumnKey")
  1327. UserDefaults.standard.synchronize()
  1328. let selectRow = self.noteOutlineView.selectedRow
  1329. self.noteOutlineView.reloadData()
  1330. self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  1331. }
  1332. @objc func exportAnnotationNotes(_ sender: AnyObject?) {
  1333. // [self.document saveDocumentTo:sender];
  1334. self.mainViewController.myDocument?.saveTo(sender)
  1335. }
  1336. @objc func leftSideEmptyAnnotationClick_DeleteAnnotation(_ sender: AnyObject?) {
  1337. // NSAlert* alert = [[NSAlert alloc] init];
  1338. // [alert setAlertStyle:NSAlertStyleCritical];
  1339. // [alert setMessageText:NSLocalizedString(@"This will permanently remove all annotations. Are you sure to continue?", nil)];
  1340. // [alert addButtonWithTitle:NSLocalizedString(@"Yes", nil)];
  1341. // [alert addButtonWithTitle:NSLocalizedString(@"No", nil)];
  1342. //
  1343. // NSModalResponse response = [alert runModal];
  1344. // if (response == NSAlertFirstButtonReturn) {
  1345. // NSMutableArray *annotations = [NSMutableArray array];
  1346. //
  1347. // for (NSUInteger i = 0; i < self.pdfView.document.pageCount; i++) {
  1348. // PDFPage *page = [[self.pdfView document] pageAtIndex:i];
  1349. // for (PDFAnnotation *annotation in [page annotations]) {
  1350. // if ([annotation isKindOfClass:[PDFAnnotationTextWidget class]] ||
  1351. // [annotation isKindOfClass:[PDFAnnotationButtonWidget class]] ||
  1352. // [annotation isKindOfClass:[PDFAnnotationChoiceWidget class]]) {
  1353. // continue;
  1354. // }
  1355. // if (@available(macOS 10.13, *)) {
  1356. // if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  1357. // continue;
  1358. // }
  1359. // }
  1360. // if ([annotation isKindOfClass:[PDFAnnotationLink class]]) {
  1361. // continue;
  1362. // }
  1363. // [annotations addObject:annotation];
  1364. // }
  1365. // }
  1366. //
  1367. // for (PDFAnnotation *annotation in annotations) {
  1368. // [self.pdfView removeAnnotation:annotation];
  1369. // }
  1370. // }
  1371. }
  1372. @IBAction func noteFilterAction(_ sender: AnyObject?) {
  1373. let button = sender as? NSButton
  1374. let menu = NSMenu()
  1375. let filterViewController = KMNoteOutlineFilterViewController()
  1376. // let object = KMPopupMenuObject()
  1377. // menu.delegate = object
  1378. // object.enterControllerCallback = {
  1379. //
  1380. // }
  1381. //
  1382. var notes = NSMutableArray()
  1383. for section in self.annotationViewController.annotations {
  1384. if section.annotations?.count != 0 {
  1385. for item in section.annotations! {
  1386. notes.add(item.annotation!)
  1387. }
  1388. }
  1389. }
  1390. filterViewController.setNotesArray(notes)
  1391. filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
  1392. menu.cancelTracking()
  1393. if (isEmpty) {
  1394. self?.filterButtonLayer?.isHidden = true
  1395. } else {
  1396. self?.filterButtonLayer?.isHidden = false
  1397. }
  1398. //
  1399. // [blockSelf annotationSort:@[typeArr, colorArr, authorArr]];
  1400. }
  1401. filterViewController.cancelCallback = { isCancel in
  1402. if (isCancel) {
  1403. menu.cancelTracking()
  1404. }
  1405. }
  1406. let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
  1407. item.target = self
  1408. item.representedObject = filterViewController
  1409. item.view = filterViewController.view
  1410. menu.popUp(positioning: nil, at: CGPointMake(-130, 30), in: button)
  1411. }
  1412. @IBAction func outlineNormalSearchButtonAction(_ sender: NSButton) {
  1413. self.outlineSearchField.isHidden = false
  1414. self.outlineDoneButton.isHidden = false
  1415. self.outlineLabel.isHidden = true
  1416. self.outlineSearchButton.isHidden = true
  1417. self.outlineMoreButton.isHidden = true
  1418. self.outlineAddButton.isHidden = true
  1419. self.outlineSearchField.becomeFirstResponder()
  1420. }
  1421. @objc func outlineContextMenuItemClicked_AddEntry(_ sender: NSMenuItem) {
  1422. // NSMutableArray *PDFOutlineArray = [[NSMutableArray new] autorelease];
  1423. // NSIndexSet *rowSet = [self selectedRowIndexes] ;
  1424. //
  1425. // [rowSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1426. // [PDFOutlineArray addObject:[leftSideController.tocOutlineView itemAtRow:idx]];
  1427. // }];
  1428. //
  1429. // if (PDFOutlineArray.count == 0) {
  1430. // PDFOutline *lastPDFLine = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.numberOfRows - 1];
  1431. //
  1432. // PDFOutline *rootPDFOutline;
  1433. // if (lastPDFLine) {
  1434. // while (lastPDFLine.parent) {
  1435. // lastPDFLine = lastPDFLine.parent;
  1436. // }
  1437. // rootPDFOutline = lastPDFLine;
  1438. // } else {
  1439. // rootPDFOutline = self.pdfView.document.outlineRoot;
  1440. // if (!rootPDFOutline) {
  1441. // rootPDFOutline = [[[PDFOutline alloc] init] autorelease];
  1442. // [self.pdfView.document setOutlineRoot:rootPDFOutline];
  1443. // }
  1444. // }
  1445. //
  1446. // PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
  1447. // addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
  1448. // addOutLine.destination = self.pdfView.currentDestination;
  1449. // [self addoutlineWithParent:rootPDFOutline addOutline:addOutLine index:rootPDFOutline.numberOfChildren needExpand:NO];
  1450. //
  1451. // } else {
  1452. // PDFOutline *currentPDFline = PDFOutlineArray.lastObject;
  1453. // NSInteger currentIndex = currentPDFline.index;
  1454. // PDFOutline *parent;
  1455. // parent = currentPDFline.parent;
  1456. //
  1457. // PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
  1458. // addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
  1459. // addOutLine.destination = self.pdfView.currentDestination;
  1460. // [self addoutlineWithParent:parent addOutline:addOutLine index:currentIndex + 1 needExpand:NO];
  1461. // [self.leftSideController.tocOutlineView scrollRowToVisible:currentIndex + 1];
  1462. // [self.leftSideController.tocOutlineView deselectRow:currentIndex+1];
  1463. //
  1464. // }
  1465. }
  1466. @IBAction func toc_expandAllComments(_ sender: AnyObject?) {
  1467. if (self.tocType == .unfold) {
  1468. return
  1469. }
  1470. self.tocType = .unfold
  1471. self.tocOutlineView.reloadData()
  1472. self.tocOutlineView.expandItem(nil, expandChildren: true)
  1473. }
  1474. @IBAction func toc_foldAllComments(_ sender: AnyObject?) {
  1475. if (self.tocType == .fold) {
  1476. return
  1477. }
  1478. self.tocType = .fold
  1479. self.tocOutlineView.reloadData()
  1480. self.tocOutlineView.collapseItem(nil, collapseChildren: true)
  1481. }
  1482. @objc func leftSideEmptyAnnotationClick_DeleteOutline(_ sender: AnyObject?) {
  1483. KMPrint("leftSideEmptyAnnotationClick_DeleteOutline")
  1484. // NSAlert *alert = [[NSAlert alloc] init];
  1485. // [alert setAlertStyle:NSAlertStyleCritical];
  1486. // [alert setMessageText:@""];
  1487. // [alert setInformativeText:NSLocalizedString(@"This will permanently remove all outlines. Are you sure to continue?", nil)];
  1488. // [alert addButtonWithTitle:NSLocalizedString(@"Yes", nil)];
  1489. // [alert addButtonWithTitle:NSLocalizedString(@"No", nil)];
  1490. // NSModalResponse response = [alert runModal];
  1491. // if (response == NSAlertFirstButtonReturn) {
  1492. // PDFOutline * item = [[pdfView document] outlineRoot];
  1493. // [self removeAllOutline:item];
  1494. // }
  1495. }
  1496. @IBAction func thumbnailSizeScaling(_ sender: NSButton) {
  1497. let sud = UserDefaults.standard
  1498. let tag = sender.tag
  1499. if (tag == 0 || tag == 1) {
  1500. var scaling = sud.float(forKey: "KMThumbnailSizeScalingKey")
  1501. if (scaling <= 0) {
  1502. scaling = 1
  1503. }
  1504. if (tag == 0) { // thumbnail Zoom In
  1505. scaling += 0.1
  1506. } else if (tag == 1) { // thumbnail Zoom Out
  1507. scaling -= 0.1
  1508. }
  1509. sud.setValue(scaling, forKey: "KMThumbnailSizeScalingKey")
  1510. let selectRow = self.thumbnailTableView.selectedRow
  1511. self.thumbnailTableView.reloadData()
  1512. self.thumbnailTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  1513. } else if (tag == 2 || tag == 3) {
  1514. var scaling = sud.float(forKey: "KMSnapshotSizeScalingKey")
  1515. if (scaling <= 0) {
  1516. scaling = 1
  1517. }
  1518. if (tag == 2) { // snapshot Zoom In
  1519. scaling += 0.1
  1520. } else if (tag == 3) { // snapshot Zoom Out
  1521. scaling -= 0.1
  1522. }
  1523. sud.setValue(scaling, forKey: "KMSnapshotSizeScalingKey")
  1524. let selectRow = self.snapshotTableView.selectedRow
  1525. self.snapshotTableView.reloadData()
  1526. self.snapshotTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  1527. }
  1528. }
  1529. }
  1530. //MARK: NSTableViewDelegate,NSTableViewDataSource
  1531. //extension KMLeftSideViewController: NSTableViewDelegate,NSTableViewDataSource {
  1532. // func numberOfRows(in tableView: NSTableView) -> Int {
  1533. // return self.dataSource.count
  1534. // }
  1535. //
  1536. // func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1537. // let cell : KMLiftSideCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMLiftSideCellView"), owner: self) as! KMLiftSideCellView
  1538. // if row <= selectImage.count-1 {
  1539. // if self.dataSource[row] == self.type {
  1540. // cell.isSelect = true
  1541. // cell.mothedImage.image = NSImage(named: selectImage[row])
  1542. // cell.backgroundColor(NSColor.km_init(hex: "#DFE1E5"))
  1543. // } else {
  1544. // cell.isSelect = false
  1545. // cell.mothedImage.image = NSImage(named: norImage[row])
  1546. // cell.backgroundColor(NSColor.clear)
  1547. // }
  1548. // }
  1549. // cell.index = row
  1550. // cell.buttonClick = { [unowned self] index in
  1551. // if ((index < self.dataSource.count) && (index > -1)) {
  1552. //
  1553. // let isSearch = self.type.methodType == .Search
  1554. //
  1555. // var show = true
  1556. // if( self.type == self.dataSource[index]) {
  1557. // self.type = KMLeftMethodMode()
  1558. // show = false
  1559. // } else {
  1560. // self.type = self.dataSource[index]
  1561. // show = true
  1562. // }
  1563. //
  1564. // self.trackEvent(type: self.type.methodType)
  1565. //
  1566. // self.updateViewButtonState()
  1567. // self.delegate?.controlStateChange?(self,show:show)
  1568. //// self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  1569. //// self.leftTableview.reloadData()
  1570. //
  1571. // UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  1572. // UserDefaults.standard.synchronize()
  1573. //
  1574. // if (isSearch && show == false) {
  1575. // self.view.window?.makeFirstResponder(self)
  1576. // } else if (isSearch && self.type.methodType != .Search) { // 切换
  1577. // self.view.window?.makeFirstResponder(self)
  1578. // }
  1579. // }
  1580. // }
  1581. // return cell
  1582. // }
  1583. //
  1584. // func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1585. // return 48
  1586. // }
  1587. //
  1588. // func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  1589. // let rowView = KMCustomTableRowView()
  1590. // rowView.selectionColor = NSColor(calibratedRed: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1.0)
  1591. // rowView.color = NSColor.km_init(hex: "#F7F8FA")
  1592. // return rowView
  1593. // }
  1594. //
  1595. // func tableViewSelectionDidChange(_ notification: Notification) {
  1596. //
  1597. // }
  1598. //}
  1599. //extension KMLeftSideViewController: KMPDFViewPanelSetViewControllerDelegate {
  1600. // func controller(_ controller: KMPDFViewPanelSetViewController, dispayDidChange dispay: KMPDFDisplayType) {
  1601. // self.delegate?.controller?(self, dispayDidChange: dispay)
  1602. // }
  1603. //
  1604. // func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool) {
  1605. // self.listView?.displaysPageBreaks = pageBreaks
  1606. // self.listView?.layoutDocumentView()
  1607. // }
  1608. //
  1609. // func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType) {
  1610. //// if (rotateType == .clockwise) { /// 顺时针
  1611. //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1612. //// if page.rotation == 0 {
  1613. //// page.rotation = 90
  1614. //// } else if page.rotation == 90 {
  1615. //// page.rotation = 180
  1616. //// } else if page.rotation == 180 {
  1617. //// page.rotation = 270
  1618. //// } else if page.rotation == 270 {
  1619. //// page.rotation = 0
  1620. //// }
  1621. //// self.listView?.layoutDocumentView()
  1622. //// } else if (rotateType == .anticlockwise) { /// 逆时针
  1623. //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1624. //// if page.rotation == 0 {
  1625. //// page.rotation = 270
  1626. //// } else if page.rotation == 90 {
  1627. //// page.rotation = 0
  1628. //// } else if page.rotation == 180 {
  1629. //// page.rotation = 90
  1630. //// } else if page.rotation == 270 {
  1631. //// page.rotation = 180
  1632. //// }
  1633. //// self.listView?.layoutDocumentView()
  1634. //// }
  1635. ////
  1636. // self.delegate?.controller?(controller: self, rotateType: rotateType)
  1637. // }
  1638. //}
  1639. // MARK: -
  1640. // MARK: - 扩展
  1641. extension KMLeftSideViewController {
  1642. public func selectType(_ type: BotaType) {
  1643. // 更新 type
  1644. var show = true
  1645. if (self.type.methodType == .None) {
  1646. show = true
  1647. } else {
  1648. if (self.type.methodType == type) {
  1649. show = false
  1650. } else {
  1651. show = true
  1652. }
  1653. }
  1654. var index: Int = NSNotFound
  1655. switch type {
  1656. case .None:
  1657. index = NSNotFound
  1658. break
  1659. case .Thumbnail:
  1660. index = 0
  1661. break
  1662. case .Outline:
  1663. index = 1
  1664. break
  1665. case .BookMark:
  1666. index = 2
  1667. break
  1668. case .Annotation:
  1669. index = 3
  1670. break
  1671. case .Search:
  1672. index = 4
  1673. break
  1674. case .From:
  1675. index = 5
  1676. break
  1677. case .Signature:
  1678. index = 6
  1679. break
  1680. }
  1681. self.type = self.getMethodMode(show ? type : .None)
  1682. // 更新按钮状态
  1683. // self.updateViewButtonState()
  1684. // 将事件传递出去
  1685. self.delegate?.controlStateChange?(self,show:show)
  1686. if (index != NSNotFound) {
  1687. // self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  1688. // 记录当前选中
  1689. UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  1690. UserDefaults.standard.synchronize()
  1691. }
  1692. // self.leftTableview.reloadData()
  1693. }
  1694. private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
  1695. let mode = KMLeftMethodMode()
  1696. mode.methodType = type
  1697. switch type {
  1698. case .None:
  1699. mode.methodName = ""
  1700. break
  1701. case .Thumbnail:
  1702. mode.methodName = thumbnailMethodKey
  1703. break
  1704. case .Outline:
  1705. mode.methodName = outlineMethodKey
  1706. break
  1707. case .BookMark:
  1708. mode.methodName = bookMarkMethodKey
  1709. break
  1710. case .Annotation:
  1711. mode.methodName = anntationMethodKey
  1712. break
  1713. case .Search:
  1714. mode.methodName = searchMethodKey
  1715. break
  1716. case .From:
  1717. mode.methodName = formMethodKey
  1718. break
  1719. case .Signature:
  1720. mode.methodName = signatureMethodKey
  1721. break
  1722. }
  1723. return mode
  1724. }
  1725. }
  1726. //MARK: Cache
  1727. extension KMLeftSideViewController {
  1728. func clearAnnotationFilterData() {
  1729. if let _key = self.listView?.document?.documentURL?.path {
  1730. let userDefaults = UserDefaults.standard
  1731. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1732. userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + _key)
  1733. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1734. userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + _key)
  1735. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1736. userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + _key)
  1737. userDefaults.synchronize()
  1738. }
  1739. }
  1740. func clearNotification() {
  1741. self.bookViewController.removeNotification()
  1742. self.annotationViewController.removeNotification()
  1743. }
  1744. }
  1745. // MARK: - Analytics (埋点)
  1746. extension KMLeftSideViewController {
  1747. func trackEvent(type: BotaType) -> Void {
  1748. if (type == .Thumbnail) {
  1749. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Thumbnail", parameters: [
  1750. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1751. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1752. } else if (type == .Outline) {
  1753. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Outline", parameters: [
  1754. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1755. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1756. } else if (type == .BookMark) {
  1757. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_BookMark", parameters: [
  1758. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1759. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1760. } else if (type == .Annotation) {
  1761. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Annotation", parameters: [
  1762. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1763. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1764. } else if (type == .Search) {
  1765. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Search", parameters: [
  1766. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1767. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1768. }
  1769. }
  1770. }
  1771. // MARK: - Private Methods
  1772. extension KMLeftSideViewController {
  1773. @objc private func _themeChanged(_ notification: NSNotification) {
  1774. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  1775. self._updateViewColor()
  1776. }
  1777. }
  1778. private func _updateViewColor() {
  1779. if(KMAppearance.isDarkMode()){
  1780. self.leftListView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1781. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1782. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1783. self.noteView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1784. self.outlineView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1785. self.view.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1786. self.thumbnailTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1787. self.groupedFindTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1788. self.tocOutlineView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1789. self.findTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1790. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1791. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1792. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1793. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1794. self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1795. self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1796. self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1797. } else {
  1798. self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1799. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1800. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1801. self.noteView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1802. self.outlineView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1803. self.view.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1804. self.thumbnailTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1805. self.groupedFindTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1806. self.tocOutlineView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1807. self.findTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1808. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1809. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1810. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1811. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1812. self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1813. self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1814. self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1815. }
  1816. }
  1817. private func _hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {
  1818. // if ([outline.label rangeOfString:searchString options:self.outlineIgnoreCaseFlag?NSCaseInsensitiveSearch:0].location != NSNotFound){
  1819. // return YES;
  1820. // } else {
  1821. // BOOL subHas = NO;
  1822. // for (NSUInteger i = 0; i < outline.numberOfChildren; i ++) {
  1823. // PDFOutline *subOutline = [outline childAtIndex:i];
  1824. // subHas = [self hasContainString:searchString rootOutline:subOutline];
  1825. // if (subHas) {
  1826. // break;
  1827. // }
  1828. // }
  1829. // return subHas;
  1830. // }
  1831. return false
  1832. }
  1833. }
  1834. // MARK: - KMThumbnailTableViewDelegate, NSTableViewDataSource
  1835. extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
  1836. func numberOfRows(in tableView: NSTableView) -> Int {
  1837. if tableView.isEqual(to: self.thumbnailTableView) {
  1838. return self.thumbnails.count
  1839. } else if tableView.isEqual(to: self.findTableView) {
  1840. return self.searchResults.count
  1841. } else if tableView.isEqual(to: self.groupedFindTableView) {
  1842. // for result in self.searchResults {
  1843. // }
  1844. KMPrint(self.searchResults)
  1845. }
  1846. return 0
  1847. }
  1848. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1849. if tableView.isEqual(to: self.thumbnailTableView) {
  1850. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMThumbnailTableviewCell"), owner: self) as! KMThumbnailTableviewCell
  1851. let thumbnail = self.thumbnails[row]
  1852. cell.pageNumLabel.stringValue = thumbnail.label
  1853. // cell.thumImage.image = thumbnail.image
  1854. cell.pageView.page = self.listView.document.page(at: UInt(row))
  1855. if let _image = thumbnail.image {
  1856. let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
  1857. let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
  1858. if (_image.size.height > _image.size.width) {
  1859. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  1860. // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
  1861. // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  1862. } else {
  1863. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  1864. // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
  1865. // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  1866. }
  1867. }
  1868. if (self.isDisplayPageSize) {
  1869. cell.sizeLabel.isHidden = false
  1870. //获取Page的真实尺寸
  1871. let page = self.listView.document.page(at: UInt(row))
  1872. let rect = page?.bounds(for: .cropBox) ?? .zero
  1873. let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
  1874. let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
  1875. if let data = page?.rotation, data == 90 || data == 270 {
  1876. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
  1877. } else {
  1878. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
  1879. }
  1880. } else {
  1881. cell.sizeLabel.isHidden = true
  1882. }
  1883. cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
  1884. if(self.thumbnailTableView.selectedRowIndexes.contains(row)) {
  1885. cell.isSelectCell = true
  1886. } else {
  1887. cell.isSelectCell = false
  1888. }
  1889. return cell
  1890. } else if (tableView.isEqual(to: self.findTableView)) {
  1891. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMFindTableviewCell"), owner: self) as! KMFindTableviewCell
  1892. let selection = searchResults[row]
  1893. if let data = tableColumn?.identifier.rawValue, data == "results" {
  1894. cell.resultLabel.attributedStringValue = selection.selection.attributedString()
  1895. cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
  1896. } else if let data = tableColumn?.identifier.rawValue, data == "page" {
  1897. cell.resultLabel.stringValue = selection.selection.pages().first?.label ?? ""
  1898. cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
  1899. }
  1900. return cell
  1901. } else if tableView.isEqual(to: self.snapshotTableView) {
  1902. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMSnapshotTableViewCell"), owner: self) as! KMSnapshotTableViewCell
  1903. // SKSnapshotWindowController *snapshot = snapshots[row];
  1904. // cell.snapshotImage.image = snapshot.thumbnail;
  1905. // cell.snapshotLabel.stringValue = snapshot.pageLabel;
  1906. // if (snapshot.hasWindow) {
  1907. // cell.snapshotImageView.hidden = NO;
  1908. // } else {
  1909. // cell.snapshotImageView.hidden = YES;
  1910. // }
  1911. // if(selectCellList.count > 0 && [selectCellList.firstObject integerValue]< 0 && (NSUInteger)row == self.snapshots.count - 1) {
  1912. // cell.isSelectCell = YES;
  1913. // } else {
  1914. // cell.isSelectCell = NO;
  1915. // }
  1916. // for (NSUInteger i = 0; i < selectCellList.count; i ++) {
  1917. // NSInteger selectCell = [selectCellList[i] integerValue];
  1918. // if (selectCell == row) {
  1919. // cell.isSelectCell = YES;
  1920. // }
  1921. // }
  1922. // if (row == tableView.selectedRow) {
  1923. // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowSel]];
  1924. // } else {
  1925. // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowNor]];
  1926. // }
  1927. return cell
  1928. }
  1929. return nil
  1930. }
  1931. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1932. if tableView.isEqual(to: self.thumbnailTableView) {
  1933. let scaling = UserDefaults.standard.float(forKey: "KMThumbnailSizeScalingKey")
  1934. let thumbnailSize = self.thumbnails[row].size
  1935. let newScaling: CGFloat = scaling.cgFloat + 0.1
  1936. let newThumbnailHeight = thumbnailSize.width * newScaling
  1937. if (newThumbnailHeight > MIN_SIDE_PANE_WIDTH) {
  1938. self.thumbnailZoomOutButton.isEnabled = false
  1939. } else {
  1940. self.thumbnailZoomOutButton.isEnabled = true
  1941. }
  1942. if ((scaling - 0.1) < 0.3) {
  1943. self.thumbnailZoomInButton.isEnabled = false
  1944. } else {
  1945. self.thumbnailZoomInButton.isEnabled = true
  1946. }
  1947. var labelHeight = 0.0
  1948. if (self.isDisplayPageSize) {
  1949. labelHeight = 56.0
  1950. } else {
  1951. labelHeight = 41.5
  1952. }
  1953. let cellHeight = thumbnailSize.height + labelHeight
  1954. var thumbSize: NSSize = .zero
  1955. if (scaling != nil && scaling > 0) {
  1956. thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  1957. } else {
  1958. thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
  1959. }
  1960. return thumbSize.height
  1961. // NSSize cellSize = NSMakeSize([[tv tableColumnWithIdentifier:IMAGE_COLUMNID] width], fmin(thumbSize.height, roundedThumbnailSize));
  1962. // if (thumbSize.height < [tv rowHeight])
  1963. // return [tv rowHeight];
  1964. // else if (thumbSize.width / thumbSize.height < cellSize.width / cellSize.height)
  1965. // return cellSize.height;
  1966. // else
  1967. // return fmax([tv rowHeight], fmin(cellSize.width, thumbSize.width) * thumbSize.height / thumbSize.width);
  1968. } else if tableView.isEqual(to: self.snapshotTableView) {
  1969. let scaling = UserDefaults.standard.float(forKey: "KMSnapshotSizeScalingKey")
  1970. // NSSize snapshotSize = [[[[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row] thumbnail] size];
  1971. let snapshotSize = CGSizeMake(120, 63)
  1972. var newScaling = scaling + 0.1
  1973. let newSnapshotHeight = snapshotSize.width * newScaling.cgFloat;
  1974. if (newSnapshotHeight > MIN_SIDE_PANE_WIDTH) {
  1975. self.snapshotNormalZoomInButton.isEnabled = false
  1976. } else {
  1977. self.snapshotNormalZoomInButton.isEnabled = true
  1978. }
  1979. if ((scaling - 0.1) < 0.3 || (newSnapshotHeight < 150.0)) {
  1980. self.snapshotNormalZoomOutButton.isEnabled = false
  1981. } else {
  1982. self.snapshotNormalZoomOutButton.isEnabled = true
  1983. }
  1984. let cellHeight = snapshotSize.height + 24.0
  1985. var thumbSize: NSSize = .zero
  1986. if (scaling > 0) {
  1987. thumbSize = NSMakeSize(snapshotSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  1988. } else {
  1989. thumbSize = NSMakeSize(snapshotSize.width, cellHeight)
  1990. }
  1991. return thumbSize.height
  1992. } else if (tableView.isEqual(to: self.findTableView)) {
  1993. return 40.0
  1994. }
  1995. return tableView.rowHeight
  1996. }
  1997. func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  1998. if (tableView.isEqual(to: self.findTableView) || tableView.isEqual(to: self.groupedFindTableView)) {
  1999. let rowView = KMCustomTableRowView()
  2000. return rowView
  2001. }
  2002. return nil
  2003. }
  2004. func tableViewSelectionIsChanging(_ notification: Notification) {
  2005. KMPrint(self.thumbnailTableView.selectedRowIndexes)
  2006. }
  2007. func tableViewSelectionDidChange(_ notification: Notification) {
  2008. // if ([[aNotification object] isEqual:leftSideController.findTableView] || [[aNotification object] isEqual:leftSideController.groupedFindTableView]) {
  2009. // [self updateFindResultHighlightsForDirection:NSDirectSelection];
  2010. //
  2011. // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  2012. // [self hideLeftSideWindow];
  2013. // } else
  2014. if self.thumbnailTableView.isEqual(to: notification.object) {
  2015. // if (mwcFlags.updatingThumbnailSelection == 0) {
  2016. let row = self.thumbnailTableView.selectedRow
  2017. let curPage = self.listView.document.index(for: self.listView.currentPage())
  2018. if (row != -1 && row != curPage) {
  2019. // [pdfView goToPage:[[pdfView document] pageAtIndex:row]];
  2020. self.listView.go(toPageIndex: row, animated: true)
  2021. }
  2022. // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  2023. // [self hideLeftSideWindow];
  2024. // thumbnailSelectCount = row;
  2025. // var rowIndexSet = IndexSet()
  2026. // for i in 0 ..< self.thumbnailTableView.numberOfRows {
  2027. // rowIndexSet.insert(i)
  2028. // }
  2029. // self.thumbnailTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: IndexSet(integer: 0))
  2030. // }
  2031. let view = self.thumbnailTableView.view(atColumn: 0, row: self.preThumbnailRow, makeIfNecessary: false) as? KMThumbnailTableviewCell
  2032. view?.isSelectCell = false
  2033. let view2 = self.thumbnailTableView.view(atColumn: 0, row: row, makeIfNecessary: false) as? KMThumbnailTableviewCell
  2034. view2?.isSelectCell = true
  2035. self.preThumbnailRow = row
  2036. }
  2037. // else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
  2038. // NSInteger row = [rightSideController.snapshotTableView selectedRow];
  2039. // [selectCellList removeAllObjects];
  2040. // [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
  2041. // if (row != -1) {
  2042. // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
  2043. // if ([[controller window] isVisible])
  2044. // [[controller window] orderFront:self];
  2045. // }
  2046. // NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2047. // for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
  2048. // [rowIndexSet addIndex:i];
  2049. // }
  2050. // NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2051. // [columnIndexSet addIndex:0];
  2052. // [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
  2053. //
  2054. // }
  2055. }
  2056. /*
  2057. //- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  2058. // return nil;
  2059. //}
  2060. - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
  2061. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2062. NSUInteger idx = [rowIndexes firstIndex];
  2063. if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
  2064. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2065. NSString *fileExt = nil;
  2066. NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  2067. if ([[pdfView document] allowsPrinting]) {
  2068. NSData *pdfData = [page dataRepresentation];
  2069. fileExt = @"pdf";
  2070. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePDF, NSPasteboardTypeTIFF,NSFilenamesPboardType, NSFilesPromisePboardType, KPDFThumbnailLocalForDraggedTypes,KPDFThumbnailDoucumentURLForDraggedTypes,nil] owner:self];
  2071. [pboard setData:pdfData forType:NSPasteboardTypePDF];
  2072. NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
  2073. [pboard setData:zNSIndexSetData forType:KPDFThumbnailLocalForDraggedTypes];
  2074. NSData *documentURL = [NSKeyedArchiver archivedDataWithRootObject:[[pdfView document].documentURL absoluteString]];
  2075. NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
  2076. __block NSMutableString *pagesName = nil;
  2077. if (rowIndexes.count > 1) {
  2078. pagesName = [NSMutableString stringWithString:@" pages"];
  2079. } else {
  2080. pagesName = [NSMutableString stringWithString:@" page"];
  2081. }
  2082. NSString * tFileName = [NSString stringWithFormat:@"%@ %@",pagesName,[self fileNameWithSelectedPages:rowIndexes]];
  2083. PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
  2084. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2085. PDFPage *copyPage = [[pdfView.document pageAtIndex:idx] copy];
  2086. [pdf insertPage:copyPage atIndex:pdf.pageCount];
  2087. [copyPage release];
  2088. }];
  2089. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2090. NSString *cachesDir = [paths objectAtIndex:0];
  2091. docmentName = [NSString stringWithFormat:@"%@%@",docmentName,tFileName];
  2092. if (docmentName.length > 50) {
  2093. [docmentName substringWithRange:NSMakeRange(0, 50)];
  2094. }
  2095. cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
  2096. BOOL success = [pdf writeToFile:cachesDir];
  2097. if (success) {
  2098. [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
  2099. }else{
  2100. [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
  2101. }
  2102. [pboard setData:documentURL forType:KPDFThumbnailDoucumentURLForDraggedTypes];
  2103. } else {
  2104. fileExt = @"tiff";
  2105. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
  2106. }
  2107. [pboard setData:tiffData forType:NSPasteboardTypeTIFF];
  2108. [pboard setPropertyList:[NSArray arrayWithObject:fileExt] forType:NSFilesPromisePboardType];
  2109. return YES;
  2110. }
  2111. } else if ([tv isEqual:rightSideController.snapshotTableView]) {
  2112. NSUInteger idx = [rowIndexes firstIndex];
  2113. if (idx != NSNotFound) {
  2114. SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
  2115. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
  2116. [pboard setData:[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] forType:NSPasteboardTypeTIFF];
  2117. [pboard setPropertyList:[NSArray arrayWithObject:@"tiff"] forType:NSFilesPromisePboardType];
  2118. return YES;
  2119. }
  2120. }
  2121. return NO;
  2122. }
  2123. - (NSArray *)tableView:(NSTableView *)tv namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2124. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2125. __block NSMutableArray *fileURLArray = [NSMutableArray array];
  2126. if (rowIndexes.count > 1) {
  2127. NSString *docmentName = @"";
  2128. NSString * tFileName = [NSString stringWithFormat:@"%@",[self fileNameWithSelectedPages:rowIndexes]];
  2129. PDFDocument *pdf = [[[PDFDocument alloc] init] autorelease];
  2130. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2131. if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
  2132. PDFPage *copyPage = [[[pdfView document] pageAtIndex:idx] copy];
  2133. [pdf insertPage:copyPage atIndex:pdf.pageCount];
  2134. [copyPage release];
  2135. }
  2136. }];
  2137. NSURL *fileURL = [[[dropDestination URLByAppendingPathComponent:tFileName] URLByAppendingPathExtension:@"pdf"] uniqueFileURL];
  2138. docmentName = fileURL.path;
  2139. BOOL success = [pdf writeToFile:docmentName];
  2140. if(success) {
  2141. [fileURLArray addObject:[fileURL lastPathComponent]];
  2142. }
  2143. } else {
  2144. PDFPage *page = [[pdfView document] pageAtIndex:rowIndexes.firstIndex];
  2145. NSURL *fileURL = [dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
  2146. NSString *pathExt = nil;
  2147. NSData *data = nil;
  2148. if ([[pdfView document] allowsPrinting]) {
  2149. pathExt = @"pdf";
  2150. data = [page dataRepresentation];
  2151. } else {
  2152. pathExt = @"tiff";
  2153. data = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  2154. }
  2155. fileURL = [[fileURL URLByAppendingPathExtension:pathExt] uniqueFileURL];
  2156. if ([data writeToURL:fileURL atomically:YES]) {
  2157. [fileURLArray addObject:[fileURL lastPathComponent]];
  2158. }
  2159. }
  2160. return fileURLArray;
  2161. } else if ([tv isEqual:rightSideController.snapshotTableView]) {
  2162. NSUInteger idx = [rowIndexes firstIndex];
  2163. if (idx != NSNotFound) {
  2164. SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
  2165. PDFPage *page = [[pdfView document] pageAtIndex:[snapshot pageIndex]];
  2166. NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]] URLByAppendingPathExtension:@"tiff"];
  2167. fileURL = [fileURL uniqueFileURL];
  2168. if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] writeToURL:fileURL atomically:YES])
  2169. return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
  2170. }
  2171. }
  2172. return [NSArray array];
  2173. }
  2174. - (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors {
  2175. if ([tv isEqual:leftSideController.groupedFindTableView]) {
  2176. [leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
  2177. }
  2178. }
  2179. #pragma mark NSTableView delegate protocol
  2180. - (BOOL)tableView:(NSTableView *)tv commandSelectRow:(NSInteger)row {
  2181. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2182. // NSRect rect = [[[pdfView document] pageAtIndex:row] boundsForBox:kPDFDisplayBoxCropBox];
  2183. //
  2184. // rect.origin.y = NSMidY(rect) - 0.5 * SNAPSHOT_HEIGHT;
  2185. // rect.size.height = SNAPSHOT_HEIGHT;
  2186. // [self showSnapshotAtPageNumber:row forRect:rect scaleFactor:[pdfView scaleFactor] autoFits:NO];
  2187. KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
  2188. thumbailTabCell.isSelectCell = YES;
  2189. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2190. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2191. [rowIndexSet addIndex:idx];
  2192. }];
  2193. [rowIndexSet addIndex:row];
  2194. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  2195. return YES;
  2196. }
  2197. return NO;
  2198. }
  2199. - (BOOL)tableView:(NSTableView *)tv shiftSelectRow:(NSInteger)row {
  2200. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2201. if(leftSideController.thumbnailTableView.selectedRowIndexes.count == 0) {
  2202. KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
  2203. thumbailTabCell.isSelectCell = YES;
  2204. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] initWithIndex:row] autorelease];
  2205. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  2206. return YES;
  2207. } else if (leftSideController.thumbnailTableView.selectedRowIndexes.count == 1 && leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex == (NSUInteger)row) {
  2208. return NO;
  2209. } else {
  2210. __block NSInteger fristIndex = leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex;
  2211. __block NSInteger lastIndex = leftSideController.thumbnailTableView.selectedRowIndexes.lastIndex;
  2212. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2213. if(idx < (NSUInteger)fristIndex) {
  2214. fristIndex = idx;
  2215. }
  2216. if(idx > (NSUInteger)lastIndex) {
  2217. lastIndex = idx;
  2218. }
  2219. }];
  2220. if(row < fristIndex) {
  2221. fristIndex = row;
  2222. } else if (row > lastIndex) {
  2223. lastIndex = row;
  2224. }
  2225. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2226. for (NSInteger i = fristIndex; i<=lastIndex;i++) {
  2227. [rowIndexSet addIndex:i];
  2228. }
  2229. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  2230. return YES;
  2231. }
  2232. }
  2233. return NO;
  2234. }
  2235. - (void)tableViewColumnDidResize:(NSNotification *)aNotification {
  2236. if ([[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:IMAGE_COLUMNID]) {
  2237. if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
  2238. [leftSideController.thumbnailTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [leftSideController.thumbnailTableView numberOfRows])]];
  2239. } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
  2240. [rightSideController.snapshotTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.snapshotTableView numberOfRows])]];
  2241. }
  2242. }
  2243. }
  2244. - (void)tableView:(NSTableView *)tv deleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2245. if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
  2246. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2247. return;
  2248. }
  2249. if ([tv isEqual:rightSideController.snapshotTableView]) {
  2250. NSArray *controllers = [[rightSideController.snapshotArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
  2251. [controllers makeObjectsPerformSelector:@selector(close)];
  2252. } else if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2253. [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2254. if (idx >= [[pdfView document] pageCount]) {
  2255. return;
  2256. }
  2257. for (PDFAnnotation *item in [[[pdfView document] pageAtIndex:idx] notes]){
  2258. [pdfView removeAnnotation:item];
  2259. }
  2260. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2261. [[[[self document] undoManager] prepareWithInvocationTarget:self] insertPage:page pageAtIndex:idx];
  2262. [[pdfView document] removePageAtIndex:idx];
  2263. }];
  2264. [pdfView layoutDocumentView];
  2265. [pageLabels setArray:[[pdfView document] pageLabels]];
  2266. [self resetThumbnails];
  2267. NSUInteger idx = [rowIndexes firstIndex];
  2268. NSInteger index = MIN(idx, [[pdfView document] pageCount]-1);
  2269. [pdfView goToPage:[[pdfView document] pageAtIndex:index]];
  2270. }
  2271. }
  2272. - (void)insertPage:(PDFPage*)page pageAtIndex:(NSInteger)index {
  2273. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  2274. [[pdfView document] insertPage:page atIndex:index];
  2275. [pdfView layoutDocumentView];
  2276. [pageLabels setArray:[[pdfView document] pageLabels]];
  2277. [self resetThumbnails];
  2278. NSInteger pageIndex = MIN((NSUInteger)index, [[pdfView document] pageCount]-1);
  2279. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  2280. }
  2281. - (BOOL)tableView:(NSTableView *)tv canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2282. if ([tv isEqual:rightSideController.snapshotTableView]) {
  2283. return [rowIndexes count] > 0;
  2284. } else if ([tv isEqual:leftSideController.thumbnailTableView]){
  2285. if (self.pdfDocument.pageCount <= 1) {
  2286. return NO;
  2287. }
  2288. return YES;
  2289. }
  2290. return NO;
  2291. }
  2292. - (void)tableView:(NSTableView *)tv copyRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2293. if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  2294. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2295. return;
  2296. }
  2297. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2298. self.copysPages = [NSMutableArray array];
  2299. if ([[pdfView document] isLocked] == NO) {
  2300. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2301. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2302. [self.copysPages addObject:page];
  2303. }];
  2304. // NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  2305. // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  2306. // NSPasteboardItem *pboardItem = [[[NSPasteboardItem alloc] init] autorelease];
  2307. // if ([[pdfView document] allowsPrinting])
  2308. // [pboardItem setData:[page dataRepresentation] forType:NSPasteboardTypePDF];
  2309. // [pboardItem setData:tiffData forType:NSPasteboardTypeTIFF];
  2310. // [pboard clearContents];
  2311. // [pboard writeObjects:[NSArray arrayWithObjects:pboardItem, nil]];
  2312. }
  2313. } else if ([tv isEqual:leftSideController.findTableView]) {
  2314. NSMutableString *string = [NSMutableString string];
  2315. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  2316. PDFSelection *match = [searchResults objectAtIndex:idx];
  2317. [string appendString:@"* "];
  2318. [string appendFormat:NSLocalizedString(@"Page %@", @""), [match firstPageLabel]];
  2319. [string appendFormat:@": %@\n", [[match contextString] string]];
  2320. }];
  2321. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  2322. [pboard clearContents];
  2323. [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
  2324. } else if ([tv isEqual:leftSideController.groupedFindTableView]) {
  2325. NSMutableString *string = [NSMutableString string];
  2326. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  2327. SKGroupedSearchResult *result = [groupedSearchResults objectAtIndex:idx];
  2328. NSArray *matches = [result matches];
  2329. [string appendString:@"* "];
  2330. [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result page] displayLabel]];
  2331. [string appendString:@": "];
  2332. [string appendFormat:NSLocalizedString(@"%ld Results", @""), (long)[matches count]];
  2333. [string appendFormat:@":\n\t%@\n", [[matches valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
  2334. }];
  2335. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  2336. [pboard clearContents];
  2337. [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
  2338. }
  2339. }
  2340. - (BOOL)tableView:(NSTableView *)tv canCopyRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2341. if ([tv isEqual:leftSideController.thumbnailTableView] || [tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView]) {
  2342. return [rowIndexes count] > 0;
  2343. }
  2344. return NO;
  2345. }
  2346. - (void)tableView:(NSTableView *)tv cutRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2347. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2348. self.copysPages = [NSMutableArray array];
  2349. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2350. if (idx != NSNotFound) {
  2351. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2352. [self.copysPages addObject:page];;
  2353. }
  2354. }];
  2355. [self tableView:tv deleteRowsWithIndexes:rowIndexes];
  2356. }
  2357. }
  2358. - (void)tableView:(NSTableView *)tv rotateRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2359. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2360. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2361. if (idx != NSNotFound) {
  2362. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2363. [[[[self document] undoManager] prepareWithInvocationTarget:self] rotatePage:page pageAtIndex:idx];
  2364. if (page.rotation == 0) {
  2365. [page setRotation:90];
  2366. } else if (page.rotation == 90){
  2367. [page setRotation:180];
  2368. } else if (page.rotation == 180){
  2369. [page setRotation:270];
  2370. } else if (page.rotation == 270){
  2371. [page setRotation:0];
  2372. }
  2373. [pdfView layoutDocumentView];
  2374. [self resetThumbnails];
  2375. NSInteger pageIndex = MIN(idx, [[pdfView document] pageCount]-1);
  2376. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  2377. }
  2378. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexes byExtendingSelection:YES];
  2379. }];
  2380. }
  2381. }
  2382. - (void)rotatePage:(PDFPage*)page pageAtIndex:(NSInteger)index {
  2383. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView rotateRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  2384. if (page.rotation == 0) {
  2385. [page setRotation:270];
  2386. } else if (page.rotation == 90){
  2387. [page setRotation:0];
  2388. } else if (page.rotation == 180){
  2389. [page setRotation:90];
  2390. } else if (page.rotation == 270){
  2391. [page setRotation:180];
  2392. }
  2393. [pdfView layoutDocumentView];
  2394. [self resetThumbnails];
  2395. }
  2396. - (void)tableView:(NSTableView *)tv shareRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2397. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2398. NSUInteger idx = [rowIndexes firstIndex];
  2399. if (idx != NSNotFound) {
  2400. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2401. NSString *fileName = [[[pdfView document] documentURL] lastPathComponent];
  2402. NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  2403. NSString *filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Untitled"]];
  2404. filePath = [filePath stringByAppendingPathExtension:[fileName pathExtension]];
  2405. [self fileWithPage:page atPath:filePath];
  2406. if (rint(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
  2407. [KMMailHelper sendFileWithPaths:[NSArray arrayWithObject:filePath]];
  2408. } else {
  2409. NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
  2410. [service performWithItems:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]]];
  2411. }
  2412. }
  2413. }
  2414. }
  2415. - (void)tableView:(NSTableView *)tv extractRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2416. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2417. NSMutableArray *pages = [NSMutableArray array];
  2418. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2419. if (idx < self.pdfView.document.pageCount) {
  2420. [pages addObject:[self.pdfView.document pageAtIndex:idx]];
  2421. }
  2422. }];
  2423. NSString * fileName = [self.pdfView.document getFileNameAccordingSelctPages:pages];
  2424. KMSavePanelAccessoryController *saveAccessCtr = [[KMSavePanelAccessoryController alloc] init];
  2425. NSSavePanel * outputSavePanel = [NSSavePanel savePanel];
  2426. [outputSavePanel setAllowedFileTypes:[NSArray arrayWithObject:@"pdf"]];
  2427. outputSavePanel.accessoryView = saveAccessCtr.view;
  2428. [outputSavePanel setNameFieldStringValue:fileName];
  2429. [outputSavePanel beginSheetModalForWindow:[self window]completionHandler:^(NSInteger result) {
  2430. if (result == NSModalResponseOK) {
  2431. [saveAccessCtr retain];
  2432. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2433. KMProgressWindowController * vc = [[[KMProgressWindowController alloc] init] autorelease];
  2434. // [NSApp beginSheet:[vc window]
  2435. // modalForWindow:self.window
  2436. // modalDelegate:nil
  2437. // didEndSelector:nil
  2438. // contextInfo:NULL];
  2439. [self.window beginSheet:[vc window] completionHandler:^(NSModalResponse returnCode) {
  2440. }];
  2441. NSString *saveFilePath = [[outputSavePanel URL] path];
  2442. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  2443. PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
  2444. BOOL success = [pdf extractAsOneDocumentWithPages:pages savePath:saveFilePath];
  2445. dispatch_async(dispatch_get_main_queue(), ^{
  2446. if (success) {
  2447. if (saveAccessCtr.openAutomaticButton.state == NSControlStateValueOn) {
  2448. [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:[outputSavePanel URL] display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
  2449. }];
  2450. } else {
  2451. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  2452. NSURL *url = [NSURL fileURLWithPath:saveFilePath];
  2453. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  2454. }
  2455. }
  2456. [NSApp endSheet:vc.window];
  2457. [vc close];
  2458. [saveAccessCtr release];
  2459. });
  2460. });
  2461. });
  2462. }
  2463. [saveAccessCtr release];
  2464. }];
  2465. }
  2466. }
  2467. - (void)fileWithPage:(PDFPage *)page atPath:(NSString *)filePath {
  2468. NSData *data = [page dataRepresentation];
  2469. PDFDocument *document = [[PDFDocument alloc] initWithData:data];
  2470. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  2471. BOOL success = [document writeToURL:[NSURL fileURLWithPath:filePath]];
  2472. if (success) {
  2473. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  2474. NSURL *url = [NSURL fileURLWithPath:filePath];
  2475. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  2476. }
  2477. [document release];
  2478. }
  2479. - (BOOL)tableView:(NSTableView *)aTableView canPasteFromPasteboard:(NSPasteboard *)pboard
  2480. {
  2481. if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
  2482. if(self.copysPages.count > 0){
  2483. return YES;
  2484. }
  2485. }
  2486. return NO;
  2487. }
  2488. - (void)tableView:(NSTableView *)aTableView pasteFromPasteboard:(NSPasteboard *)pboard
  2489. {
  2490. if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  2491. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2492. return;
  2493. }
  2494. if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
  2495. if (self.copysPages.count > 0) {
  2496. NSUInteger index = [[pdfView document] indexForPage:[pdfView currentPage]] + 1;
  2497. if (index == NSNotFound) {
  2498. return;
  2499. }
  2500. [self.copysPages enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(PDFPage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2501. PDFPage *page = [obj copy];
  2502. [[pdfView document] insertPage:page atIndex:index];
  2503. [page release];
  2504. [pdfView layoutDocumentView];
  2505. [pageLabels setArray:[[pdfView document] pageLabels]];
  2506. [self resetThumbnails];
  2507. NSInteger pageIndex = MIN(index, [[pdfView document] pageCount]-1);
  2508. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  2509. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  2510. }];
  2511. }
  2512. }
  2513. }
  2514. - (NSUInteger)tableView:(NSTableView *)tv highlightLevelForRow:(NSInteger)row {
  2515. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2516. NSUInteger i, iMax = [lastViewedPages count];
  2517. for (i = 0; i < iMax; i++) {
  2518. if (row == (NSInteger)[lastViewedPages pointerAtIndex:i])
  2519. return i;
  2520. }
  2521. }
  2522. return NSNotFound;
  2523. }
  2524. - (void)tableViewMoveLeft:(NSTableView *)tv {
  2525. if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
  2526. [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
  2527. }
  2528. }
  2529. - (void)tableViewMoveRight:(NSTableView *)tv {
  2530. if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
  2531. [self updateFindResultHighlightsForDirection:NSSelectingNext];
  2532. }
  2533. }
  2534. - (id <SKImageToolTipContext>)tableView:(NSTableView *)tv imageContextForRow:(NSInteger)row {
  2535. if ([tv isEqual:leftSideController.findTableView])
  2536. return [[[leftSideController.findArrayController arrangedObjects] objectAtIndex:row] destination];
  2537. else if ([tv isEqual:leftSideController.groupedFindTableView])
  2538. return [[[[[leftSideController.groupedFindArrayController arrangedObjects] objectAtIndex:row] matches] objectAtIndex:0] destination];
  2539. return nil;
  2540. }
  2541. - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
  2542. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2543. return pageLabels;
  2544. }
  2545. return nil;
  2546. }
  2547. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
  2548. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2549. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  2550. }
  2551. }
  2552. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
  2553. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2554. if (searchString.length > 0)
  2555. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  2556. else
  2557. [self updateLeftStatus];
  2558. }
  2559. }
  2560. #pragma mark dragging
  2561. - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
  2562. {
  2563. if (dropOperation == NSTableViewDropOn || ![tableView isEqual:leftSideController.thumbnailTableView]) {
  2564. return NSDragOperationNone;
  2565. }
  2566. NSPasteboard *pboard = [info draggingPasteboard];
  2567. if ([pboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
  2568. return NSDragOperationMove;
  2569. } else if ([pboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]){
  2570. NSArray *fileNames = [pboard propertyListForType:NSFilenamesPboardType];
  2571. if (fileNames.count == 1) {
  2572. NSString *path = fileNames.firstObject;
  2573. NSString *pathExtension = [path.pathExtension lowercaseString];
  2574. if ([pathExtension isEqualToString:@"pdf"] ||
  2575. [[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
  2576. return NSDragOperationMove;
  2577. }
  2578. } else {
  2579. return NSDragOperationNone;
  2580. }
  2581. }
  2582. return NSDragOperationNone;
  2583. }
  2584. - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {
  2585. __block BOOL result = NO;
  2586. if (![tableView isEqual:leftSideController.thumbnailTableView]) {
  2587. return result;
  2588. }
  2589. NSPasteboard *pasteboard = [info draggingPasteboard];
  2590. if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
  2591. result = YES;
  2592. NSData *rowData = [pasteboard dataForType:KPDFThumbnailLocalForDraggedTypes];
  2593. NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
  2594. NSData *urlData = [pasteboard dataForType:KPDFThumbnailDoucumentURLForDraggedTypes];
  2595. NSString *url = [NSKeyedUnarchiver unarchiveObjectWithData:urlData];
  2596. if(![url isEqualToString:[pdfView document].documentURL.absoluteString] && url) {
  2597. if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
  2598. NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
  2599. if (fileNames.count == 1) {
  2600. NSString *path = fileNames.firstObject;
  2601. NSString *pathExtension = [path.pathExtension lowercaseString];
  2602. if ([pathExtension isEqualToString:@"pdf"]) {
  2603. __block NSInteger index = row;
  2604. __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2605. PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]] autorelease];
  2606. if ([pdf isEncrypted]) {
  2607. KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
  2608. vc.filePath = url;
  2609. [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  2610. if (password) {
  2611. [pdf unlockWithPassword:password];
  2612. for(NSUInteger i=0; i<pdf.pageCount;i++) {
  2613. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2614. [self.pdfView.document insertPage:page atIndex:index];
  2615. [insertIndexSet addIndex:index];
  2616. index++;
  2617. [page release];
  2618. }
  2619. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2620. }
  2621. }];
  2622. [vc release];
  2623. } else {
  2624. for(NSUInteger i=0; i<pdf.pageCount;i++) {
  2625. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2626. [self.pdfView.document insertPage:page atIndex:index];
  2627. [insertIndexSet addIndex:index];
  2628. index++;
  2629. [page release];
  2630. }
  2631. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2632. }
  2633. return YES;
  2634. }
  2635. }
  2636. }
  2637. }
  2638. __block NSInteger pageIndex = 0;
  2639. __block NSMutableArray *pages = [NSMutableArray array];
  2640. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2641. PDFPage *page = [[[pdfView document] pageAtIndex:idx] copy];
  2642. [pages addObject:page];
  2643. [page release];
  2644. }];
  2645. PDFPage *toPage = nil;
  2646. if (row < (NSInteger)pdfView.document.pageCount) {
  2647. toPage = [pdfView.document pageAtIndex:row];
  2648. }
  2649. __block NSInteger toPageIndex = 0;
  2650. if (toPage) {
  2651. toPageIndex = [pdfView.document indexForPage:toPage];
  2652. } else {
  2653. toPageIndex = pdfView.document.pageCount;
  2654. }
  2655. for(NSUInteger i = 0;i<pages.count;i++) {
  2656. PDFPage *page = pages[i];
  2657. [pdfView.document insertPage:page atIndex:toPageIndex+i];
  2658. pageIndex += 1;
  2659. [self.pdfView goToPage:page];
  2660. }
  2661. [self.pdfView layoutDocumentView];
  2662. __block NSMutableArray *deletepages = [NSMutableArray array];
  2663. [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2664. if((NSInteger)idx < toPageIndex) {
  2665. if((idx+pageIndex) < pdfView.document.pageCount) {
  2666. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2667. [deletepages addObject:page];
  2668. [pdfView.document removePageAtIndex:idx];
  2669. }
  2670. } else {
  2671. if((idx+pageIndex) < pdfView.document.pageCount) {
  2672. PDFPage *page = [[pdfView document] pageAtIndex:idx+pageIndex];
  2673. [deletepages addObject:page];
  2674. [pdfView.document removePageAtIndex:idx+pageIndex];
  2675. }
  2676. }
  2677. }];
  2678. [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
  2679. [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
  2680. [self.pdfView layoutDocumentView];
  2681. [self resetThumbnails];
  2682. } else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
  2683. if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
  2684. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2685. return NO;
  2686. }
  2687. NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
  2688. NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2689. __block NSInteger index = row;
  2690. if (fileNames.count == 1) {
  2691. NSString *path = fileNames.firstObject;
  2692. NSString *pathExtension = [path.pathExtension lowercaseString];
  2693. if ([pathExtension isEqualToString:@"pdf"]) {
  2694. PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
  2695. if ([pdf isEncrypted]) {
  2696. KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
  2697. vc.filePath = path;
  2698. [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  2699. if (password) {
  2700. [pdf unlockWithPassword:password];
  2701. for (NSUInteger i = 0; i< pdf.pageCount; i++) {
  2702. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2703. [self.pdfView.document insertPage:page atIndex:index];
  2704. [insertIndexSet addIndex:index];
  2705. index++;
  2706. [page release];
  2707. }
  2708. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2709. }
  2710. }];
  2711. [vc release];
  2712. } else {
  2713. for (NSUInteger i = 0; i < pdf.pageCount; i++) {
  2714. PDFPage * page = [[pdf pageAtIndex:i] copy];
  2715. [self.pdfView.document insertPage:page atIndex:index];
  2716. [insertIndexSet addIndex:index];
  2717. index++;
  2718. [page release];
  2719. }
  2720. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2721. }
  2722. } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
  2723. NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
  2724. PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
  2725. [pdfView.document insertPage:page atIndex:index];
  2726. [insertIndexSet addIndex:index];
  2727. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2728. }
  2729. result = YES;
  2730. } else {
  2731. result = NO;
  2732. }
  2733. }
  2734. return result;
  2735. }
  2736. */
  2737. }
  2738. // MARK: - NSOutlineViewDelegate, NSOutlineViewDataSource
  2739. /*
  2740. func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
  2741. if item is KMBOTAAnnotationSection {
  2742. let section = item as? KMBOTAAnnotationSection
  2743. return section!.annotations?[index] as Any
  2744. } else if item is KMBOTAAnnotationItem {
  2745. return item as Any
  2746. } else {
  2747. var tempArray: [KMBOTAAnnotationSection] = []
  2748. for temp in self.data {
  2749. if temp.annotations?.count != 0 {
  2750. tempArray.append(temp)
  2751. }
  2752. }
  2753. let section = tempArray[index]
  2754. return section as Any
  2755. }
  2756. }
  2757. func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
  2758. if item is KMBOTAAnnotationItem {
  2759. let cell : KMAnnotationOutlineCellView = KMAnnotationOutlineCellView.init()
  2760. cell.delegate = self
  2761. cell.model = item as? KMBOTAAnnotationItem
  2762. return cell
  2763. } else if item is KMBOTAAnnotationSection {
  2764. let section = item as? KMBOTAAnnotationSection
  2765. let cell : KMAnnotationOutlineSectionView = KMAnnotationOutlineSectionView.init()
  2766. cell.model = section
  2767. return cell
  2768. }
  2769. return NSTableCellView()
  2770. }
  2771. func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
  2772. let rowView = KMAnnotationOutlineRowView()
  2773. if item is KMBOTAAnnotationItem {
  2774. rowView.model = (item as? KMBOTAAnnotationItem)
  2775. } else if item is KMBOTAAnnotationSection {
  2776. rowView.section = (item as? KMBOTAAnnotationSection)
  2777. }
  2778. rowView.mouseDownAction = { [unowned self] view, event in
  2779. if rowView.section != nil {
  2780. let expanded = outlineView.isItemExpanded(outlineView.item(atRow: outlineView.selectedRow))
  2781. if expanded {
  2782. outlineView.collapseItem(outlineView.item(atRow: outlineView.selectedRow), collapseChildren: true)
  2783. outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
  2784. } else {
  2785. outlineView.expandItem(outlineView.item(atRow: outlineView.selectedRow), expandChildren: true)
  2786. outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
  2787. }
  2788. } else if rowView.model != nil {
  2789. self.didSelectItem(view: rowView, event: event)
  2790. }
  2791. }
  2792. rowView.rightMouseDownAction = { [unowned self] view, event in
  2793. if rowView.section != nil {
  2794. } else if rowView.model != nil {
  2795. if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
  2796. self.selectItems.count == 1 {
  2797. self.selectItem(item: item as! KMBOTAAnnotationItem)
  2798. }
  2799. DispatchQueue.main.async {
  2800. self.delegate?.annotationOutlineView(self, rightMouseDownDidSelectView: view, evnet: event)
  2801. }
  2802. }
  2803. }
  2804. rowView.hoverCallback = { [unowned self] (mouseEntered, mouseBox) in
  2805. self.outlineView.enumerateAvailableRowViews { view, row in
  2806. if view is KMAnnotationOutlineRowView {
  2807. (view as? KMAnnotationOutlineRowView)?.model?.hover = false
  2808. (view as? KMAnnotationOutlineRowView)?.reloadData()
  2809. }
  2810. }
  2811. if mouseEntered {
  2812. rowView.model?.hover = true
  2813. } else {
  2814. rowView.model?.hover = false
  2815. }
  2816. }
  2817. return rowView
  2818. }
  2819. func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
  2820. if item is KMBOTAAnnotationItem {
  2821. return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: self.maxWidth - 16, height: 1000))
  2822. } else if item is KMBOTAAnnotationSection {
  2823. return 40
  2824. } else {
  2825. return 30
  2826. }
  2827. }
  2828. func outlineViewSelectionDidChange(_ notification: Notification) {
  2829. if self.outlineView.selectedRow == -1 {
  2830. self.cancelSelect()
  2831. }
  2832. }
  2833. func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
  2834. if item is KMBOTAAnnotationItem {
  2835. return false
  2836. } else if item is KMBOTAAnnotationSection {
  2837. let section = item as? KMBOTAAnnotationSection
  2838. return section!.annotations?.count ?? 0 > 0
  2839. }
  2840. return false
  2841. }
  2842. func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
  2843. if let item = item as? KMBOTAAnnotationSection {
  2844. if !item.isItemExpanded {
  2845. item.isItemExpanded = true
  2846. outlineView.animator().expandItem(item, expandChildren: true)
  2847. return false
  2848. }
  2849. }
  2850. return true
  2851. }
  2852. func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool {
  2853. if let item = item as? KMBOTAAnnotationSection {
  2854. if item.isItemExpanded {
  2855. item.isItemExpanded = false
  2856. outlineView.animator().collapseItem(item, collapseChildren: true)
  2857. return false
  2858. }
  2859. }
  2860. return true
  2861. }
  2862. */
  2863. extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSource {
  2864. func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
  2865. if outlineView.isEqual(to: self.tocOutlineView) {
  2866. let isLocked = self.listView.document?.isLocked ?? true
  2867. if item == nil && isLocked == false {
  2868. var item = self.listView.document.outlineRoot()
  2869. if let data = item?.numberOfChildren, data == 0 && !self.isSearchOutlineMode {
  2870. let view = self.tocOutlineView.enclosingScrollView!
  2871. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  2872. //
  2873. self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  2874. self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  2875. self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
  2876. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
  2877. } else {
  2878. self.leftSideEmptyVC.emptyOutlineView.removeFromSuperview()
  2879. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = true
  2880. }
  2881. if let data = item?.numberOfChildren, data > 0 {
  2882. self.outlineSearchButton.isEnabled = true
  2883. } else {
  2884. self.outlineSearchButton.isEnabled = false
  2885. }
  2886. if (self.isSearchOutlineMode) {
  2887. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: item!) {
  2888. // [self showSearchOutlineBlankState:NO];
  2889. } else {
  2890. // [self showSearchOutlineBlankState:YES];
  2891. }
  2892. }
  2893. let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
  2894. // var bookMarks: [KMBookMarkItem] = []
  2895. // for bookMark in array {
  2896. // let item = KMBookMarkItem()
  2897. // item.bookMark = bookMark
  2898. // item.index = UInt(bookMark.pageIndex)
  2899. // item.label = bookMark.label
  2900. // bookMarks.append(item)
  2901. // }
  2902. var bookmarkNum = 0
  2903. if array.isEmpty == false {
  2904. bookmarkNum = 1
  2905. }
  2906. return Int(item?.numberOfChildren ?? 0) + bookmarkNum
  2907. }
  2908. if (self.isSearchOutlineMode) {
  2909. // var num = 0
  2910. // for (NSUInteger i = 0; i < [(PDFOutline *)item numberOfChildren]; i++) {
  2911. // PDFOutline *outline = [(PDFOutline *)item childAtIndex:i];
  2912. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
  2913. // num ++;
  2914. // }
  2915. // }
  2916. // return num;
  2917. } else {
  2918. // return [(PDFOutline *)item numberOfChildren];
  2919. }
  2920. // if item is CPDFBookmark {
  2921. // return 0
  2922. // }
  2923. // return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
  2924. let array = self.listView.document?.bookmarks() ?? [CPDFBookmark]()
  2925. if let data = item as? String, data == "Bookmarks" {
  2926. return array.count
  2927. } else if item is CPDFOutline {
  2928. // return Int(item?.numberOfChildren ?? 0)
  2929. return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
  2930. } else if item is CPDFBookmark {
  2931. return 0
  2932. }
  2933. } else if outlineView.isEqual(to: self.noteOutlineView) {
  2934. var count = 0
  2935. for section in self.annotationViewController.annotations {
  2936. if section.annotations?.count != 0 {
  2937. count += section.annotations!.count
  2938. }
  2939. }
  2940. // if (item == nil){
  2941. // NSInteger count = [[rightSideController.noteArrayController arrangedObjects] count];
  2942. if (count < 1) {
  2943. // if (notes.count < 1) {
  2944. // leftSideController.noteSearchButton.enabled = NO;
  2945. // leftSideController.noteFilterButton.enabled = NO;
  2946. // }
  2947. self.noteOutlineView.usesAlternatingRowBackgroundColors = false
  2948. let view = self.noteOutlineView.enclosingScrollView!
  2949. let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  2950. self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  2951. self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  2952. self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
  2953. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
  2954. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
  2955. //
  2956. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  2957. self.noteHeaderView.isHidden = true
  2958. self.toolButtonBoxLayoutConstraint.constant = 40.0
  2959. }
  2960. } else {
  2961. self.noteSearchButton.isEnabled = true
  2962. self.noteFilterButton.isEnabled = true
  2963. self.noteOutlineView.usesAlternatingRowBackgroundColors = false
  2964. self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
  2965. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
  2966. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
  2967. //
  2968. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  2969. self.noteHeaderView.isHidden = false
  2970. self.toolButtonBoxLayoutConstraint.constant = 64.0
  2971. }
  2972. }
  2973. return count;
  2974. // } else {
  2975. // return [item hasNoteText];
  2976. // }
  2977. }
  2978. return 0
  2979. }
  2980. func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
  2981. if outlineView.isEqual(to: self.tocOutlineView) {
  2982. let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
  2983. var bookmarkNum = 0
  2984. if array.isEmpty == false {
  2985. bookmarkNum = 1
  2986. }
  2987. if item == nil && self.listView.document.isLocked == false {
  2988. if index == 0 && bookmarkNum == 1 {
  2989. return "Bookmarks"
  2990. } else {
  2991. var _index = bookmarkNum == 1 ? index-1 : index
  2992. var _item: CPDFOutline?
  2993. _item = self.listView.document.outlineRoot()
  2994. var obj = _item?.child(at: UInt(_index))
  2995. return obj as Any
  2996. }
  2997. } else {
  2998. if let data = item as? String, data == "Bookmarks" {
  2999. return array[index]
  3000. } else if item is CPDFOutline {
  3001. return (item as! CPDFOutline).child(at: UInt(index))
  3002. } else if item is CPDFBookmark {
  3003. // return nil?
  3004. }
  3005. }
  3006. // var obj = _item?.child(at: UInt(index))
  3007. // if (self.isSearchOutlineMode) {
  3008. // NSMutableArray *array = [NSMutableArray array];
  3009. // for (NSUInteger i = 0; i < [(PDFOutline *)item numberOfChildren]; i ++) {
  3010. // PDFOutline *subOutline = [(PDFOutline *)item childAtIndex:i];
  3011. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:subOutline]) {
  3012. // [array addObject:subOutline];
  3013. // }
  3014. // }
  3015. // return [array objectAtIndex:anIndex];
  3016. // } else {
  3017. // return obj;
  3018. // }
  3019. // return obj as Any
  3020. } else if outlineView.isEqual(to: self.noteOutlineView) {
  3021. // if (item == nil)
  3022. // {
  3023. // return [[rightSideController.noteArrayController arrangedObjects] objectAtIndex:anIndex];
  3024. // // return [self.notes objectAtIndex:anIndex];
  3025. // }
  3026. // else
  3027. // return [item noteText];
  3028. var tempArray: [KMBOTAAnnotationItem] = []
  3029. for secion in self.annotationViewController.annotations {
  3030. if secion.annotations?.count != 0 {
  3031. for _item in secion.annotations! {
  3032. tempArray.append(_item)
  3033. }
  3034. }
  3035. }
  3036. return tempArray[index] as Any
  3037. }
  3038. return item
  3039. }
  3040. func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
  3041. if outlineView.isEqual(to: self.tocOutlineView) {
  3042. // let tcID = tableColumn?.identifier.rawValue ?? ""
  3043. // var ol = item as? CPDFOutline
  3044. // if(tcID == LABEL_COLUMNID) {
  3045. // if (self.isSearchOutlineMode) {
  3046. //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
  3047. //// NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
  3048. //// NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
  3049. //// for (NSUInteger i = 0; i <arr.count ; i++) {
  3050. //// NSValue * rangeValue = arr[i];
  3051. //// NSRange range = rangeValue.rangeValue;
  3052. //// range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
  3053. //// [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
  3054. //// }
  3055. //// [attributeString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:NSMakeRange(0, roughString.length)];
  3056. //// return attributeString;
  3057. // } else {
  3058. // var attributedString = NSMutableAttributedString()
  3059. //// attributedString
  3060. // attributedString.append(.init(string: ol?.label ?? "", attributes: [.foregroundColor : KMAppearance.Layout.h0Color()]))
  3061. //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
  3062. //// NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3063. //// NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
  3064. //// [attributedString appendAttributedString:attr1];
  3065. //
  3066. // return attributedString
  3067. // }
  3068. //
  3069. // }
  3070. // else if([tcID isEqualToString:PAGE_COLUMNID]) {
  3071. // NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  3072. // NSString *roughString = [ol pageLabel]? : @"";
  3073. // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3074. // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
  3075. // [attributedString appendAttributedString:attr1];
  3076. //
  3077. // return attributedString;
  3078. // }
  3079. }
  3080. // else if ([ov isEqual:rightSideController.noteOutlineView]) {
  3081. // NSString *tcID = [tableColumn identifier];
  3082. // PDFAnnotation *note = item;
  3083. // if (tableColumn == nil || [tcID isEqualToString:NOTE_COLUMNID])
  3084. // return [note objectValue];
  3085. // else if([tcID isEqualToString:TYPE_COLUMNID]){
  3086. // NSString *noteType = [note type];
  3087. // if ([note isKindOfClass:[PDFAnnotationButtonWidget class]]) {
  3088. // PDFAnnotationButtonWidget *buttonWidget = (PDFAnnotationButtonWidget *)note;
  3089. // if (buttonWidget.controlType == kPDFWidgetRadioButtonControl) {
  3090. // noteType = SKAnnotationFormRadioButtonKey;
  3091. // } else if (buttonWidget.controlType == kPDFWidgetCheckBoxControl){
  3092. // noteType = SKAnnotationFormCheckBoxKey;
  3093. // } else if (buttonWidget.controlType == kPDFWidgetPushButtonControl){
  3094. // noteType = SKAnnotationFormActionButtonKey;
  3095. // }
  3096. // } else if ([note isKindOfClass:[PDFAnnotationTextWidget class]]){
  3097. // noteType = SKAnnotationFormTextFieldKey;
  3098. // } else if ([note isKindOfClass:[PDFAnnotationChoiceWidget class]]){
  3099. // PDFAnnotationChoiceWidget *choiceWidget = (PDFAnnotationChoiceWidget *)note;
  3100. // if (choiceWidget.isListChoice) {
  3101. // noteType = SKAnnotationFormListMenuKey;
  3102. // } else {
  3103. // noteType = SKAnnotationFormComboBoxKey;
  3104. // }
  3105. //
  3106. // }
  3107. // return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:note == [pdfView activeAnnotation]], SKAnnotationTypeImageCellActiveKey, noteType, SKAnnotationTypeImageCellTypeKey,[note color],SKAnnotationTypeImageCellColorKey, nil];
  3108. // }
  3109. // else if([tcID isEqualToString:COLOR_COLUMNID])
  3110. // return [note type] ? [note color] : nil;
  3111. // else if([tcID isEqualToString:PAGE_COLUMNID])
  3112. // return [[note page] displayLabel];
  3113. // else if([tcID isEqualToString:AUTHOR_COLUMNID])
  3114. // return [note type] ? [note userName] : nil;
  3115. // else if([tcID isEqualToString:DATE_COLUMNID])
  3116. // return [note type] ? [note modificationDate] : nil;
  3117. // }
  3118. return nil
  3119. }
  3120. func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
  3121. if outlineView.isEqual(to: self.tocOutlineView) {
  3122. let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMTocTableCellView"), owner: self) as! KMTocTableCellView
  3123. let tcID = tableColumn?.identifier.rawValue
  3124. var title = ""
  3125. if let data = item as? String, data == "Bookmarks" {
  3126. title = NSLocalizedString("Bookmarks", comment: "")
  3127. } else if item is CPDFOutline {
  3128. title = (item as! CPDFOutline).label
  3129. } else if item is CPDFBookmark {
  3130. title = (item as! CPDFBookmark).label
  3131. }
  3132. if tcID == LABEL_COLUMNID {
  3133. if (self.isSearchOutlineMode) {
  3134. // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
  3135. // NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
  3136. // NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
  3137. //
  3138. // for (NSUInteger i = 0; i <arr.count ; i++) {
  3139. // NSValue * rangeValue = arr[i];
  3140. // NSRange range = rangeValue.rangeValue;
  3141. // range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
  3142. // [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
  3143. // }
  3144. // cell.tocLabel.attributedStringValue = attributeString;
  3145. } else {
  3146. cell.tocLabel.stringValue = title
  3147. }
  3148. // TODO: 不确定是哪个字段
  3149. cell.pageLabel.stringValue = ""
  3150. }
  3151. // else if([tcID isEqualToString:PAGE_COLUMNID]) {
  3152. // cell.pageLabel.stringValue = [ol pageLabel];
  3153. // }
  3154. return cell
  3155. } else if outlineView.isEqual(to: self.noteOutlineView) {
  3156. let note = (item as! KMBOTAAnnotationItem).annotation!
  3157. let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteTableViewCell"), owner: self) as! KMNoteTableViewCell
  3158. cell.cellNote = note
  3159. let noteColor = note.color
  3160. var noteType = note.type ?? ""
  3161. var noteString = note.string() ?? ""
  3162. // NSString *pageString = [[note page] displayLabel] ? : @"";
  3163. var pageString = note.page.label ?? ""
  3164. let date = note.modificationDate()
  3165. var authorString = note.userName() ?? ""
  3166. // NSString *noteTextString = [note noteText].string ? : @"";
  3167. var noteTextString = note.string() ?? ""
  3168. //
  3169. // if([noteType isEqualToString:@"Redact"]) {
  3170. // noteString = @"Redact";
  3171. // }
  3172. //
  3173. let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool
  3174. if timeKey == nil || timeKey == false {
  3175. if (date != nil) {
  3176. cell.timeLabel.stringValue = CPDFAnnotationModel.timeString(withTime: date)
  3177. } else {
  3178. cell.timeLabel.stringValue = ""
  3179. }
  3180. cell.timeLabel.isHidden = false
  3181. } else {
  3182. cell.timeLabel.isHidden = true
  3183. }
  3184. let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool
  3185. if pageKey == nil || pageKey == false {
  3186. let labelsize = cell.pageLabel.stringValue.boundingRect(with: CGSizeMake(CGFloat(MAXFLOAT),CGRectGetHeight(cell.pageLabel.bounds)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font : NSFont.systemFont(ofSize: 12)])
  3187. cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5
  3188. cell.pageLabel.stringValue = pageString
  3189. cell.pageLabel.isHidden = false
  3190. } else {
  3191. cell.pageLabel.isHidden = true
  3192. }
  3193. let autherKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool
  3194. if pageKey == nil || pageKey == false {
  3195. cell.autherLabel.stringValue = authorString
  3196. cell.autherLabel.isHidden = false
  3197. } else {
  3198. cell.autherLabel.isHidden = true
  3199. }
  3200. let imageView = KMNoteTypeImageView()
  3201. if note.isKind(of: CPDFStampAnnotation.self) {
  3202. let annotation_stamp = note as! CPDFStampAnnotation
  3203. if (annotation_stamp.stampImage() != nil) {
  3204. noteType = SKNStampString
  3205. }
  3206. } else if note.isKind(of: CPDFLineAnnotation.self) {
  3207. let annotation_line = note as! CPDFLineAnnotation
  3208. if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .none {
  3209. noteType = SKNLine_NoneString
  3210. } else if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .openArrow {
  3211. noteType = SKNLine_OpenArrowString
  3212. } else {
  3213. noteType = SKNLine_NoneString
  3214. }
  3215. } else if note.isKind(of: CPDFButtonWidgetAnnotation.self) {
  3216. let buttonWidget = note as! CPDFButtonWidgetAnnotation
  3217. if buttonWidget.controlType() == .radioButtonControl {
  3218. noteType = KMAnnotationFormRadioButtonKey
  3219. } else if buttonWidget.controlType() == .checkBoxControl {
  3220. noteType = KMAnnotationFormCheckBoxKey
  3221. } else if buttonWidget.controlType() == .pushButtonControl {
  3222. noteType = KMAnnotationFormActionButtonKey
  3223. }
  3224. } else if note.isKind(of: CPDFTextWidgetAnnotation.self) {
  3225. noteType = KMAnnotationFormTextFieldKey
  3226. } else if note.isKind(of: CPDFChoiceWidgetAnnotation.self) {
  3227. let choiceWidget = note as! CPDFChoiceWidgetAnnotation
  3228. if choiceWidget.isListChoice {
  3229. noteType = KMAnnotationFormListMenuKey
  3230. } else {
  3231. noteType = KMAnnotationFormComboBoxKey
  3232. }
  3233. } else if note.isKind(of: KMTableAnnotation.self) {
  3234. noteType = "Ink_Table"
  3235. } else if note.isKind(of: KMSelfSignAnnotation.self) {
  3236. let selfSignNote = note as! KMSelfSignAnnotation
  3237. if selfSignNote.annotationType == .signFalse {
  3238. noteType = "KMSelfSignTypeFalseActionButtonKey"
  3239. } else if (selfSignNote.annotationType == .signature) {
  3240. noteType = "KMSelfSignTypeTureActionButtonKey"
  3241. } else if (selfSignNote.annotationType == .signCircle) {
  3242. noteType = "KMSelfSignTypeCircleActionButtonKey"
  3243. } else if (selfSignNote.annotationType == .signLine) {
  3244. noteType = "KMSelfSignTypeLineActionButtonKey"
  3245. } else if (selfSignNote.annotationType == .signDot) {
  3246. noteType = "KMSelfSignTypeDotActionButtonKey"
  3247. } else if (selfSignNote.annotationType == .signText) {
  3248. noteType = "KMSelfSignTypeTextActionButtonKey"
  3249. }
  3250. } else if note.isKind(of: CPDFSquareAnnotation.self) {
  3251. noteType = SKNSquareString
  3252. } else if note.isKind(of: CPDFTextAnnotation.self) {
  3253. noteType = SKNNoteString
  3254. }
  3255. cell.typeImageView.image = imageView.noteTypeImage(withType: noteType, color: noteColor ?? .red)
  3256. cell.typeImageView.isHidden = false
  3257. if note.isKind(of: CPDFMarkupAnnotation.self) {
  3258. cell.isFold = true
  3259. }
  3260. cell.noteContentBox.isHidden = true
  3261. cell.noteImageView.isHidden = true
  3262. cell.foldButton.isHidden = true
  3263. cell.annotationContentLabel.isHidden = false
  3264. cell.noteContentLabel.stringValue = noteString
  3265. cell.contentView.isHidden = false
  3266. cell.contentViewHidden(false)
  3267. if note.isKind(of: CPDFMarkupAnnotation.self) {
  3268. let markup = note as! CPDFMarkupAnnotation
  3269. if(noteTextString.isEmpty == false) {
  3270. cell.foldButton.isHidden = false
  3271. }
  3272. var attributeStr = NSMutableAttributedString(string: noteTextString)
  3273. if (markup.markupType() == .highlight) {
  3274. attributeStr.addAttribute(.backgroundColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
  3275. } else if (markup.markupType() == .strikeOut) {
  3276. attributeStr.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
  3277. attributeStr.addAttribute(.strikethroughColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
  3278. } else if (markup.markupType() == .underline) {
  3279. attributeStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
  3280. attributeStr.addAttribute(.underlineColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
  3281. }
  3282. cell.annotationContentLabel.attributedStringValue = attributeStr
  3283. if (self.foldType == .unfold) {
  3284. cell.isFold = false
  3285. } else if (self.foldType == .fold) {
  3286. cell.isFold = true
  3287. } else {
  3288. // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
  3289. // cell.isFold = NO;
  3290. // } else {
  3291. // cell.isFold = YES;
  3292. // }
  3293. }
  3294. if (noteString.isEmpty == false && noteTextString.isEmpty == false) {
  3295. cell.contentViewHidden(false)
  3296. } else {
  3297. cell.contentViewHidden(true)
  3298. }
  3299. } else if note.isKind(of: CPDFLineAnnotation.self) || noteType == SKNSquareString || noteType == SKNCircleString || noteType == SKNInkString {
  3300. cell.annotationContentLabel.stringValue = noteString
  3301. if (noteString.isEmpty == false) {
  3302. cell.contentViewHidden(false)
  3303. } else {
  3304. cell.contentViewHidden(true)
  3305. }
  3306. } else if note.isKind(of: CPDFStampAnnotation.self) {
  3307. if note.isKind(of: KMSelfSignAnnotation.self) {
  3308. let newAnnotation = note as! KMSelfSignAnnotation
  3309. let type = newAnnotation.annotationType
  3310. var returnString = ""
  3311. if (type == .signFalse) {
  3312. returnString = KMLocalizedString("X", nil)
  3313. } else if (type == .signature) {
  3314. returnString = KMLocalizedString("Check mark", nil)
  3315. } else if (type == .signCircle) {
  3316. returnString = KMLocalizedString("Circle", nil)
  3317. } else if (type == .signLine) {
  3318. returnString = KMLocalizedString("Line", nil)
  3319. } else if (type == .signDot) {
  3320. returnString = KMLocalizedString("Dot", nil)
  3321. } else if (type == .signText) {
  3322. returnString = KMLocalizedString("Text", nil)
  3323. }
  3324. cell.annotationContentLabel.stringValue = returnString
  3325. } else {
  3326. cell.annotationContentLabel.isHidden = true
  3327. cell.noteImageView.isHidden = false
  3328. // PDFAnnotation *annotation = note;
  3329. // NSImage *stampImage = [self stampCreateImage:annotation];
  3330. // if (stampImage) {
  3331. // cell.noteImageView.image = [self stampCreateImage:annotation];
  3332. // } else {
  3333. // cell.noteImageView.hidden = YES;
  3334. // [cell contentViewHidden:YES];
  3335. // }
  3336. }
  3337. }
  3338. // else if ([note isKindOfClass:[SKNPDFAnnotationNote class]]) {
  3339. // cell.foldButton.hidden = NO;
  3340. // if (!noteString || noteString.length < 1){
  3341. // cell.annotationContentLabel.stringValue = noteTextString;
  3342. // }else{
  3343. // cell.annotationContentLabel.stringValue = noteString;
  3344. // cell.noteContentLabel.stringValue = noteTextString;
  3345. // }
  3346. //
  3347. // if (self.foldType == KMFoldAllAnnotationType_Unfold) {
  3348. // cell.isFold = NO;
  3349. // } else if (self.foldType == KMFoldAllAnnotationType_Fold) {
  3350. // cell.isFold = YES;
  3351. // } else {
  3352. // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
  3353. // cell.isFold = NO;
  3354. // } else {
  3355. // cell.isFold = YES;
  3356. // }
  3357. // }
  3358. // if (noteString.length > 0 || noteTextString.length > 0) {
  3359. // cell.contentView.hidden = NO;
  3360. // } else {
  3361. // cell.contentView.hidden = YES;
  3362. // [cell contentViewHidden:YES];
  3363. // }
  3364. // if (noteString.length > 0 && noteTextString.length > 0) {
  3365. // cell.foldButton.hidden = NO;
  3366. // }else{
  3367. // cell.foldButton.hidden = YES;
  3368. // }
  3369. //
  3370. // }
  3371. else {
  3372. cell.annotationContentLabel.stringValue = noteString
  3373. cell.imageViewHeightConstraint.constant = cell.contentView.frame.size.height
  3374. if (noteString.isEmpty == false) {
  3375. cell.contentViewHidden(false)
  3376. } else {
  3377. cell.contentViewHidden(true)
  3378. }
  3379. }
  3380. //
  3381. cell.autherLayoutConstraint.constant = cell.autherLabel.isHidden ? -(cell.autherLabel.bounds.size.width) + 10.0 : 10.0
  3382. cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.isHidden ? -(cell.typeImageView.bounds.size.width) : 0.0
  3383. cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.isHidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0
  3384. if note.isKind(of: CPDFStampAnnotation.self) && note.isKind(of: KMSelfSignAnnotation.self) == false {
  3385. //
  3386. } else {
  3387. if note.isKind(of: CPDFMarkupAnnotation.self) {
  3388. if (!cell.isFold) {
  3389. // [rightSideController.allFoldNotes addObject:note];
  3390. } else {
  3391. cell.imageViewHeightConstraint.constant = 18.0 + 8
  3392. }
  3393. } else {
  3394. cell.imageViewHeightConstraint.constant = 18.0 + 8
  3395. }
  3396. }
  3397. // cell.isUnFoldNote = ^(PDFAnnotation *cellNote, BOOL isUnfold) {
  3398. // if (isUnfold) {
  3399. // if ([rightSideController.allFoldNotes containsObject:note]) {
  3400. // [rightSideController.allFoldNotes removeObject:note];
  3401. // }
  3402. //
  3403. // if (rightSideController.allFoldNotes.count == 0) {
  3404. // self.foldType = KMFoldAllAnnotationType_Fold;
  3405. // } else {
  3406. // self.foldType = KMFoldAllAnnotationType_None;
  3407. // }
  3408. // } else {
  3409. // if (![rightSideController.allFoldNotes containsObject:note]) {
  3410. // [rightSideController.allFoldNotes addObject:note];
  3411. // }
  3412. //
  3413. // if (rightSideController.allFoldNotes.count == rightSideController.canFoldNotes.count) {
  3414. // self.foldType = KMFoldAllAnnotationType_Unfold;
  3415. // } else {
  3416. // self.foldType = KMFoldAllAnnotationType_None;
  3417. // }
  3418. // }
  3419. // };
  3420. return cell
  3421. }
  3422. return nil
  3423. }
  3424. func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
  3425. if outlineView.isEqual(self.noteOutlineView) {
  3426. if item is KMBOTAAnnotationItem {
  3427. return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: 260+40 - 16, height: 1000))
  3428. }
  3429. return 30
  3430. } else if outlineView.isEqual(self.tocOutlineView) {
  3431. if item is CPDFOutline {
  3432. let tempItem = item as! CPDFOutline
  3433. let string: NSString = tempItem.label as NSString
  3434. let paragraphStyle = NSMutableParagraphStyle()
  3435. paragraphStyle.lineHeightMultiple = 1.32
  3436. paragraphStyle.alignment = .left
  3437. let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle,
  3438. NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0)]
  3439. let size = string.boundingRect(with: CGSizeMake(outlineView.frame.size.width - 30, 200), options: NSString.DrawingOptions(rawValue: 3), attributes: attributes)
  3440. return max(40, size.height + 16)
  3441. }
  3442. return 40
  3443. }
  3444. return outlineView.rowHeight
  3445. }
  3446. func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
  3447. if outlineView.isEqual(self.tocOutlineView) {
  3448. // var _item: CPDFOutline?
  3449. // if item == nil && self.listView.document.isLocked == false {
  3450. // _item = self.listView.document.outlineRoot()
  3451. // }
  3452. if let data = item as? String, data == "Bookmarks" {
  3453. return true
  3454. } else if item is CPDFOutline {
  3455. return ((item as! CPDFOutline).numberOfChildren ?? 0) != 0
  3456. } else if item is CPDFBookmark {
  3457. return false
  3458. }
  3459. if (self.isSearchOutlineMode) {
  3460. // return [self subOutLineContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:(PDFOutline *)item];
  3461. } else {
  3462. // return ((_item?.numberOfChildren ?? 0) != 0)
  3463. }
  3464. } else if outlineView.isEqual(to: self.noteOutlineView) {
  3465. // return [item hasNoteText];
  3466. return false
  3467. }
  3468. return false
  3469. }
  3470. func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
  3471. if outlineView.isEqual(self.tocOutlineView) {
  3472. let itemView = KMCustomTableRowView()
  3473. return itemView
  3474. } else if outlineView.isEqual(self.noteOutlineView) {
  3475. let itemView = KMCustomTableRowView()
  3476. return itemView;
  3477. }
  3478. return nil
  3479. }
  3480. /*
  3481. #pragma mark NSOutlineView datasource protocol
  3482. - (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item{
  3483. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3484. PDFAnnotation *note = item;
  3485. if ([note type]) {
  3486. if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
  3487. if ([(object ?: @"") isEqualToString:([note string] ?: @"")] == NO)
  3488. [note setString:object];
  3489. } else if ([[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
  3490. if ([(object ?: @"") isEqualToString:([note userName] ?: @"")] == NO)
  3491. [note setUserName:object];
  3492. }
  3493. }
  3494. }
  3495. }
  3496. #pragma mark Drag
  3497. - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard{
  3498. if ([outlineView isEqual:leftSideController.tocOutlineView]) {
  3499. if (leftSideController.tocOutlineView.selectedRowIndexes.count > 1) {
  3500. return NO;
  3501. }
  3502. NSIndexSet *tIndex = [[[NSIndexSet alloc] initWithIndex:leftSideController.tocOutlineView.clickedRow] autorelease];
  3503. [leftSideController.tocOutlineView deselectRow:tIndex.firstIndex];
  3504. self.dragPDFOutline = items.firstObject;
  3505. NSIndexSet *set = [NSIndexSet indexSetWithIndex:0];
  3506. NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:set];
  3507. [pasteboard declareTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType] owner:self];
  3508. [pasteboard setData:zNSIndexSetData forType:kKMPDFViewOutlineDragDataType];
  3509. return YES;
  3510. }
  3511. return NO;
  3512. }
  3513. - (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)anIndex {
  3514. NSDragOperation dragOp = NSDragOperationNone;
  3515. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3516. NSPasteboard *pboard = [info draggingPasteboard];
  3517. if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
  3518. anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
  3519. dragOp = NSDragOperationEvery;
  3520. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3521. if (anIndex == -1) {
  3522. dragOp = NSDragOperationNone;
  3523. } else {
  3524. dragOp = NSDragOperationMove;
  3525. }
  3526. }
  3527. return dragOp;
  3528. }
  3529. - (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)anIndex {
  3530. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3531. NSPasteboard *pboard = [info draggingPasteboard];
  3532. if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]]) {
  3533. BOOL isShift = ([NSEvent standardModifierFlags] & NSEventModifierFlagShift) != 0;
  3534. BOOL isAlt = ([NSEvent standardModifierFlags] & NSEventModifierFlagOption) != 0;
  3535. [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
  3536. return YES;
  3537. }
  3538. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3539. if (anIndex < 0) {
  3540. return NO;
  3541. }
  3542. PDFOutline *outline = item;
  3543. //root,drag item to root
  3544. if (!outline.parent) {
  3545. //fetch root
  3546. PDFOutline *root = self.dragPDFOutline;
  3547. while (root.parent) {
  3548. root = root.parent;
  3549. }
  3550. if ([self.dragPDFOutline.parent isEqual:root]) {
  3551. if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
  3552. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
  3553. } else {
  3554. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:root];
  3555. }
  3556. } else {
  3557. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
  3558. }
  3559. } else {
  3560. //在同一个层级内移动
  3561. if ([self.dragPDFOutline.parent isEqual:item]) {
  3562. if (self.dragPDFOutline.index) {
  3563. if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
  3564. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
  3565. }else{
  3566. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:outline];
  3567. }
  3568. } else {
  3569. return NO;
  3570. }
  3571. } else {
  3572. PDFOutline *tOutlline = outline;
  3573. BOOL isContains = NO;
  3574. while (tOutlline) {
  3575. if ([tOutlline isEqual:self.dragPDFOutline]) {
  3576. isContains = YES;
  3577. break;
  3578. }
  3579. tOutlline = tOutlline.parent;
  3580. }
  3581. if (!isContains) {
  3582. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
  3583. }
  3584. }
  3585. }
  3586. return YES;
  3587. }
  3588. return NO;
  3589. }
  3590. #pragma mark NSOutlineView delegate protocol
  3591. - (NSCell *)outlineView:(NSOutlineView *)ov dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
  3592. if ([ov isEqual:rightSideController.noteOutlineView] && tableColumn == nil && [(PDFAnnotation *)item type] == nil) {
  3593. return [[ov tableColumnWithIdentifier:NOTE_COLUMNID] dataCellForRow:[ov rowForItem:item]];
  3594. }
  3595. return [tableColumn dataCellForRow:[ov rowForItem:item]];
  3596. }
  3597. - (void)outlineView:(NSOutlineView *)ov willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
  3598. if ([ov isEqual:leftSideController.tocOutlineView] &&
  3599. [ov selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular &&
  3600. [ov isRowSelected:[ov rowForItem:item]]) {
  3601. [cell setBackgroundStyle:NSBackgroundStyleLowered];
  3602. }
  3603. }
  3604. - (BOOL)outlineView:(NSOutlineView *)ov shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item{
  3605. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3606. if (tableColumn == nil) {
  3607. if ([pdfView hideNotes] == NO && [[(SKNoteText *)item note] isNote]) {
  3608. PDFAnnotation *annotation = [(SKNoteText *)item note];
  3609. [pdfView scrollAnnotationToVisible:annotation];
  3610. [pdfView setActiveAnnotation:annotation];
  3611. [self showNote:annotation];
  3612. SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
  3613. [[noteController window] makeFirstResponder:[noteController textView]];
  3614. [[noteController textView] selectAll:nil];
  3615. }
  3616. return NO;
  3617. } else if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID] || [[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
  3618. return YES;
  3619. }
  3620. }
  3621. return NO;
  3622. }
  3623. - (void)outlineView:(NSOutlineView *)ov didClickTableColumn:(NSTableColumn *)tableColumn {
  3624. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3625. NSTableColumn *oldTableColumn = [ov highlightedTableColumn];
  3626. NSTableColumn *newTableColumn = ([NSEvent modifierFlags] & NSEventModifierFlagCommand) ? nil : tableColumn;
  3627. NSMutableArray *sortDescriptors = nil;
  3628. BOOL ascending = YES;
  3629. if ([oldTableColumn isEqual:newTableColumn]) {
  3630. sortDescriptors = [[[rightSideController.noteArrayController sortDescriptors] mutableCopy] autorelease];
  3631. [sortDescriptors replaceObjectAtIndex:0 withObject:[[sortDescriptors firstObject] reversedSortDescriptor]];
  3632. ascending = [[sortDescriptors firstObject] ascending];
  3633. } else {
  3634. NSString *tcID = [newTableColumn identifier];
  3635. NSSortDescriptor *pageIndexSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationPageIndexKey ascending:ascending] autorelease];
  3636. NSSortDescriptor *boundsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKPDFAnnotationBoundsOrderKey ascending:ascending selector:@selector(compare:)] autorelease];
  3637. sortDescriptors = [NSMutableArray arrayWithObjects:pageIndexSortDescriptor, boundsSortDescriptor, nil];
  3638. if ([tcID isEqualToString:TYPE_COLUMNID]) {
  3639. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationTypeKey ascending:YES selector:@selector(noteTypeCompare:)] autorelease] atIndex:0];
  3640. } else if ([tcID isEqualToString:COLOR_COLUMNID]) {
  3641. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationColorKey ascending:YES selector:@selector(colorCompare:)] autorelease] atIndex:0];
  3642. } else if ([tcID isEqualToString:NOTE_COLUMNID]) {
  3643. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationStringKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
  3644. } else if ([tcID isEqualToString:AUTHOR_COLUMNID]) {
  3645. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationUserNameKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
  3646. } else if ([tcID isEqualToString:DATE_COLUMNID]) {
  3647. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationModificationDateKey ascending:YES] autorelease] atIndex:0];
  3648. }
  3649. if (oldTableColumn)
  3650. [ov setIndicatorImage:nil inTableColumn:oldTableColumn];
  3651. [ov setHighlightedTableColumn:newTableColumn];
  3652. }
  3653. [rightSideController.noteArrayController setSortDescriptors:sortDescriptors];
  3654. if (newTableColumn)
  3655. [ov setIndicatorImage:[NSImage imageNamed:ascending ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
  3656. inTableColumn:newTableColumn];
  3657. [ov reloadData];
  3658. }
  3659. }
  3660. - (void)outlineViewSelectionDidChange:(NSNotification *)notification{
  3661. // Get the destination associated with the search result list. Tell the PDFView to go there.
  3662. if ([[notification object] isEqual:leftSideController.tocOutlineView] && (mwcFlags.updatingOutlineSelection == 0)){
  3663. mwcFlags.updatingOutlineSelection = 1;
  3664. [self goToSelectedOutlineItem:nil];
  3665. mwcFlags.updatingOutlineSelection = 0;
  3666. if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  3667. [self hideLeftSideWindow];
  3668. }
  3669. }
  3670. - (NSString *)outlineView:(NSOutlineView *)ov toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn item:(id)item mouseLocation:(NSPoint)mouseLocation {
  3671. if ([ov isEqual:rightSideController.noteOutlineView] &&
  3672. (tableColumn == nil || [[tableColumn identifier] isEqualToString:NOTE_COLUMNID])) {
  3673. return [item string];
  3674. }
  3675. return @"";
  3676. }
  3677. - (void)outlineViewItemDidExpand:(NSNotification *)notification{
  3678. if ([[notification object] isEqual:leftSideController.tocOutlineView]) {
  3679. [self updateOutlineSelection];
  3680. }
  3681. }
  3682. - (void)outlineViewItemDidCollapse:(NSNotification *)notification{
  3683. if ([[notification object] isEqual:leftSideController.tocOutlineView]) {
  3684. [self updateOutlineSelection];
  3685. }
  3686. }
  3687. - (void)outlineViewColumnDidResize:(NSNotification *)notification{
  3688. if (mwcFlags.autoResizeNoteRows &&
  3689. [[notification object] isEqual:rightSideController.noteOutlineView] &&
  3690. [[[[notification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:NOTE_COLUMNID] &&
  3691. [(SKScrollView *)[[notification object] enclosingScrollView] isResizingSubviews] == NO) {
  3692. [rowHeights removeAllFloats];
  3693. [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
  3694. }
  3695. }
  3696. - (void)outlineView:(NSOutlineView *)ov didChangeHiddenOfTableColumn:(NSTableColumn *)tableColumn {
  3697. if (mwcFlags.autoResizeNoteRows &&
  3698. [ov isEqual:rightSideController.noteOutlineView] &&
  3699. [[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
  3700. [rowHeights removeAllFloats];
  3701. [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
  3702. }
  3703. }
  3704. - (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item {
  3705. }
  3706. - (void)updateSelectRowHeight{
  3707. CGFloat rowHeight = 0;
  3708. PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.selectedRow];
  3709. if (!outline){
  3710. return;
  3711. }
  3712. NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  3713. NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3714. NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
  3715. [attributedString appendAttributedString:attr1];
  3716. NSInteger *row = [leftSideController.tocOutlineView selectedRow];
  3717. NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:row makeIfNecessary:YES];
  3718. NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
  3719. // id cell = [tableColumn dataCell];
  3720. id cell = [tableColumn dataCellForRow:row];
  3721. [cell setObjectValue:attributedString];
  3722. CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
  3723. NSInteger num = [self getNum:outline];
  3724. CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
  3725. rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
  3726. rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
  3727. [rowHeights setFloat:rowHeight forKey:outline];
  3728. if (@available(macOS 10.13, *)) {
  3729. } else {
  3730. rowHeight = 40.0;
  3731. }
  3732. CGRect fram = viewS.frame;
  3733. viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
  3734. [leftSideController.tocOutlineView reloadData];
  3735. }
  3736. - (NSInteger)getNum:(PDFOutline *)ol{
  3737. NSInteger num = 0;
  3738. PDFOutline *outLine = [ol parent];
  3739. do {
  3740. outLine = [outLine parent];
  3741. if (outLine){
  3742. num ++;
  3743. }
  3744. } while (outLine);
  3745. return num;
  3746. }
  3747. - (void)sizeOutlineViewToContents:(NSOutlineView*) outlineView;
  3748. {
  3749. NSInteger rowCount = [outlineView numberOfRows];
  3750. for (NSInteger i = 0; i < rowCount; i++){
  3751. CGFloat rowHeight = 0;
  3752. PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:i];
  3753. if (!outline){
  3754. continue;
  3755. }
  3756. NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  3757. NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3758. NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
  3759. [attributedString appendAttributedString:attr1];
  3760. // NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:i makeIfNecessary:YES];
  3761. NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
  3762. // id cell = [tableColumn dataCell];
  3763. id cell = [tableColumn dataCellForRow:i];
  3764. [cell setObjectValue:attributedString];
  3765. CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
  3766. NSInteger num = [self getNum:outline];
  3767. CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
  3768. rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
  3769. rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
  3770. [rowHeights setFloat:rowHeight forKey:outline];
  3771. if (@available(macOS 10.13, *)) {
  3772. } else {
  3773. rowHeight = 40.0;
  3774. }
  3775. // CGRect fram = viewS.frame;
  3776. // viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
  3777. }
  3778. [leftSideController.tocOutlineView reloadData];
  3779. }
  3780. - (BOOL)outlineView:(NSOutlineView *)ov canResizeRowByItem:(id)item {
  3781. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3782. return YES;
  3783. }
  3784. return NO;
  3785. }
  3786. - (void)outlineView:(NSOutlineView *)ov setHeight:(CGFloat)newHeight ofRowByItem:(id)item {
  3787. [rowHeights setFloat:newHeight forKey:item];
  3788. }
  3789. - (NSArray *)noteItems:(NSArray *)items {
  3790. NSMutableArray *noteItems = [NSMutableArray array];
  3791. for (PDFAnnotation *item in items) {
  3792. if ([item type] == nil) {
  3793. item = [(SKNoteText *)item note];
  3794. }
  3795. if ([noteItems containsObject:item] == NO)
  3796. [noteItems addObject:item];
  3797. }
  3798. return noteItems;
  3799. }
  3800. - (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items {
  3801. if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
  3802. for (PDFAnnotation *item in [self noteItems:items])
  3803. [pdfView removeAnnotation:item];
  3804. [[[self document] undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
  3805. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3806. [self outlineContextMenuItemClicked_RemoveEntry:nil];
  3807. }
  3808. }
  3809. - (BOOL)outlineView:(NSOutlineView *)ov canDeleteItems:(NSArray *)items {
  3810. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3811. return [[self pdfDocument] allowsNotes] && [items count] > 0;
  3812. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3813. return [items count] > 0;
  3814. }
  3815. return NO;
  3816. }
  3817. - (void)outlineView:(NSOutlineView *)ov copyItems:(NSArray *)items {
  3818. if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
  3819. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  3820. NSMutableArray *copiedItems = [NSMutableArray array];
  3821. NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] init] autorelease];
  3822. BOOL isAttributed = NO;
  3823. id item;
  3824. for (item in [self noteItems:items]) {
  3825. if ([item isMovable])
  3826. [copiedItems addObject:item];
  3827. }
  3828. for (item in items) {
  3829. if ([attrString length])
  3830. [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:@"\n\n"];
  3831. if ([(PDFAnnotation *)item type] == nil && [[(SKNoteText *)item note] isNote]) {
  3832. [attrString appendAttributedString:[(SKNoteText *)item text]];
  3833. isAttributed = YES;
  3834. } else {
  3835. [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:[item string] ?: @""];
  3836. }
  3837. }
  3838. [pboard clearContents];
  3839. if (isAttributed)
  3840. [pboard writeObjects:[NSArray arrayWithObjects:attrString, nil]];
  3841. else
  3842. [pboard writeObjects:[NSArray arrayWithObjects:[attrString string], nil]];
  3843. if ([copiedItems count] > 0)
  3844. [pboard writeObjects:copiedItems];
  3845. }
  3846. }
  3847. - (BOOL)outlineView:(NSOutlineView *)ov canCopyItems:(NSArray *)items {
  3848. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3849. if ([items count] == 1) {
  3850. PDFAnnotation *annotation = [[self noteItems:items] lastObject];
  3851. if ([annotation isKindOfClass:[PDFAnnotationStamp class]] ||
  3852. [annotation isKindOfClass:[PDFAnnotationLink class]]) {
  3853. return NO;
  3854. }
  3855. }
  3856. return [items count] > 0;
  3857. }
  3858. return NO;
  3859. }
  3860. - (NSUInteger)outlineView:(NSOutlineView *)ov highlightLevelForRow:(NSInteger)row {
  3861. if ([ov isEqual:leftSideController.tocOutlineView]) {
  3862. NSInteger numRows = [ov numberOfRows];
  3863. NSUInteger firstPage = [[[ov itemAtRow:row] page] pageIndex];
  3864. NSUInteger lastPage = row + 1 < numRows ? [[[ov itemAtRow:row + 1] page] pageIndex] : [[self pdfDocument] pageCount];
  3865. NSRange range = NSMakeRange(firstPage, MAX(1LU, lastPage - firstPage));
  3866. NSUInteger i, iMax = [lastViewedPages count];
  3867. for (i = 0; i < iMax; i++) {
  3868. if (NSLocationInRange((NSUInteger)[lastViewedPages pointerAtIndex:i], range))
  3869. return i;
  3870. }
  3871. }
  3872. return NSNotFound;
  3873. }
  3874. - (id <SKImageToolTipContext>)outlineView:(NSOutlineView *)ov imageContextForItem:(id)item {
  3875. if ([ov isEqual:leftSideController.tocOutlineView])
  3876. return [item destination];
  3877. return nil;
  3878. }
  3879. - (void)outlineViewCommandKeyPressedDuringNavigation:(NSOutlineView *)ov {
  3880. PDFAnnotation *annotation = [[self selectedNotes] lastObject];
  3881. if (annotation) {
  3882. [pdfView scrollAnnotationToVisible:annotation];
  3883. [pdfView setActiveAnnotation:annotation];
  3884. }
  3885. }
  3886. - (NSArray *)outlineView:(NSOutlineView *)ov typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
  3887. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3888. NSInteger i, count = [rightSideController.noteOutlineView numberOfRows];
  3889. NSMutableArray *texts = [NSMutableArray arrayWithCapacity:count];
  3890. for (i = 0; i < count; i++) {
  3891. id item = [rightSideController.noteOutlineView itemAtRow:i];
  3892. NSString *string = [item string];
  3893. [texts addObject:string ?: @""];
  3894. }
  3895. return texts;
  3896. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3897. NSInteger i, count = [leftSideController.tocOutlineView numberOfRows];
  3898. NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
  3899. for (i = 0; i < count; i++)
  3900. [array addObject:[[(PDFOutline *)[leftSideController.tocOutlineView itemAtRow:i] label] lossyStringUsingEncoding:NSASCIIStringEncoding]];
  3901. return array;
  3902. }
  3903. return nil;
  3904. }
  3905. - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
  3906. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3907. [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  3908. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3909. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  3910. }
  3911. }
  3912. - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
  3913. if ([typeSelectHelper isEqual:[leftSideController.thumbnailTableView typeSelectHelper]] || [typeSelectHelper isEqual:[pdfView typeSelectHelper]]) {
  3914. if (searchString)
  3915. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  3916. else
  3917. [self updateLeftStatus];
  3918. } else if ([typeSelectHelper isEqual:[rightSideController.noteOutlineView typeSelectHelper]]) {
  3919. if (searchString)
  3920. [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding note: \"%@\"", @"Status message"), searchString]];
  3921. else
  3922. [self updateRightStatus];
  3923. } else if ([typeSelectHelper isEqual:[leftSideController.tocOutlineView typeSelectHelper]]) {
  3924. if (searchString)
  3925. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding: \"%@\"", @"Status message"), searchString]];
  3926. else
  3927. [self updateLeftStatus];
  3928. }
  3929. }
  3930. */
  3931. }