KMLeftSideViewController.swift 246 KB

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