KMLeftSideViewController.swift 215 KB

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