KMLeftSideViewController.swift 191 KB

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