KMLeftSideViewController.swift 193 KB

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