KMLeftSideViewController.swift 191 KB

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