KMLeftSideViewController.swift 246 KB

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