KMLeftSideViewController.swift 208 KB

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