KMLeftSideViewController.swift 190 KB

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