KMLeftSideViewController.swift 253 KB

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