KMLeftSideViewController.swift 237 KB

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