KMLeftSideViewController.swift 185 KB

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