KMLeftSideViewController.swift 243 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736
  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.frame = NSMakeRect(0, 0, 1, 1)
  75. }
  76. func showPanelView(show: Bool) {
  77. self.isShowPanel = show
  78. if show {
  79. // self.panelSetViewController.listView = self.listView
  80. // self.panelSetViewController.view.frame = self.view.frame
  81. // self.view.addSubview(self.panelSetViewController.view)
  82. // self.panelSetViewController.reloadListViewModel()
  83. // self.panelSetViewController.view.autoresizingMask = [.height]
  84. self.leftView.segmentedControl.selectedSegment = 0
  85. } else {
  86. // self.contentBox.isHidden = false
  87. // self.panelSetViewController.view.removeFromSuperview()
  88. // if self.type.methodType == .None {
  89. self.leftView.segmentedControl.selectedSegment = UInt8.max
  90. self.delegate?.controlStateChange?(self, show: false)
  91. // }
  92. }
  93. }
  94. func refreshMethodType(methodType: BotaType) {
  95. // if (self.isShowPanel) {
  96. // self.showPanelView(show: false)
  97. // return
  98. // }
  99. let newType = KMLeftMethodMode()
  100. var show = true
  101. if self.type.methodType != methodType {
  102. newType.methodType = methodType
  103. }
  104. if self.type.methodType == methodType {
  105. show = false
  106. } else if methodType == .None {
  107. show = false
  108. }
  109. self.type = newType;
  110. // self.refreshShowMethod()
  111. self.delegate?.controlStateChange?(self,show:show)
  112. }
  113. //
  114. // private func updateViewButtonState() {
  115. // switch self.type.methodType {
  116. // case .None: do {
  117. //// self.contentBox.contentView = NSView()
  118. // self.delegate?.controlStateChange?(self,show:false)
  119. // }
  120. // break
  121. // case .Thumbnail: do {
  122. // self.thumbnailViewController.listView = self.listView
  123. // self.thumbnailViewController.delegate = self
  124. //// self.contentBox.contentView = self.thumbnailViewController.view
  125. //// self.thumbnailViewController.reloadData()
  126. // }
  127. // break
  128. // case .Outline: do {
  129. // }
  130. // break
  131. // case .BookMark: do {
  132. // self.bookViewController.listView = self.listView
  133. //// self.contentBox.contentView = self.bookViewController.view
  134. // self.bookViewController.reloadData()
  135. // }
  136. // break
  137. // case .Annotation: do {
  138. // self.annotationViewController.listView = self.listView
  139. //// self.contentBox.contentView = self.annotationViewController.view
  140. //// self.annotationViewController.reloadData()
  141. // }
  142. // break
  143. // break
  144. // case .Signature: do {
  145. // self.signatureViewController.listView = self.listView
  146. //// self.contentBox.contentView = self.signatureViewController.view
  147. // self.signatureViewController.reloadData()
  148. // }
  149. // break
  150. // }
  151. // }
  152. // func refreshShowMethod() {
  153. // self.dataSource = [KMLeftMethodMode]()
  154. // norImage = []
  155. // selectImage = []
  156. // if KMBOTAManagerClass.shard.getMethodShow(key: thumbnailMethodKey) {
  157. // let mode = KMLeftMethodMode()
  158. // mode.methodName = thumbnailMethodKey
  159. // mode.methodType = .Thumbnail
  160. // self.dataSource.insert(mode, at: self.dataSource.count)
  161. // norImage.append("KMImageNameSidebarThumbailNor")
  162. // selectImage.append("KMImageNameSidebarThumbailSelect")
  163. // }
  164. // if KMBOTAManagerClass.shard.getMethodShow(key: outlineMethodKey) {
  165. // let mode = KMLeftMethodMode()
  166. // mode.methodName = outlineMethodKey
  167. // mode.methodType = .Outline
  168. // self.dataSource.insert(mode, at: self.dataSource.count)
  169. // norImage.append("KMImageNameSidebarOutlineNor")
  170. // selectImage.append("KMImageNameSidebarOutlineSelect")
  171. // }
  172. // if KMBOTAManagerClass.shard.getMethodShow(key: bookMarkMethodKey) {
  173. // let mode = KMLeftMethodMode()
  174. // mode.methodName = bookMarkMethodKey
  175. // mode.methodType = .BookMark
  176. // self.dataSource.insert(mode, at: self.dataSource.count)
  177. // norImage.append("KMImageNameSidebarBookMarkNor")
  178. // selectImage.append("KMImageNameSidebarBookMarkSelect")
  179. // }
  180. // if KMBOTAManagerClass.shard.getMethodShow(key: anntationMethodKey) {
  181. // let mode = KMLeftMethodMode()
  182. // mode.methodName = anntationMethodKey
  183. // mode.methodType = .Annotation
  184. // self.dataSource.insert(mode, at: self.dataSource.count)
  185. // norImage.append("KMImageNameSidebarAnnotationNor")
  186. // selectImage.append("KMImageNameSidebarAnnotationSelect")
  187. // }
  188. // if KMBOTAManagerClass.shard.getMethodShow(key: searchMethodKey) {
  189. // let mode = KMLeftMethodMode()
  190. // mode.methodName = searchMethodKey
  191. // mode.methodType = .Search
  192. // self.dataSource.insert(mode, at: self.dataSource.count)
  193. // norImage.append("KMImageNameSidebarSearchNor")
  194. // selectImage.append("KMImageNameSidebarSearchSelect")
  195. // }
  196. //// if KMBOTAManagerClass.shard.getMethodShow(key: formMethodKey) {
  197. //// let mode = KMLeftMethodMode()
  198. //// mode.methodName = formMethodKey
  199. //// mode.methodType = .From
  200. //// self.dataSource.insert(mode, at: self.dataSource.count)
  201. //// }
  202. //// if KMBOTAManagerClass.shard.getMethodShow(key: signatureMethodKey) {
  203. //// let mode = KMLeftMethodMode()
  204. //// mode.methodName = signatureMethodKey
  205. //// mode.methodType = .Signature
  206. //// self.dataSource.insert(mode, at: self.dataSource.count)
  207. //// }
  208. // var isConstant = false
  209. // for source in dataSource {
  210. // if self.type.methodType == source.methodType {
  211. // isConstant = true
  212. // }
  213. // }
  214. // if(!isConstant) {
  215. // self.type = KMLeftMethodMode()
  216. // }
  217. //// self.leftTableview.reloadData()
  218. // var typeIndex = -1
  219. // for (index,value) in self.dataSource.enumerated() {
  220. // if value.methodType == self.type.methodType {
  221. // typeIndex = index
  222. // }
  223. // }
  224. //
  225. //// self.leftTableview.selectRowIndexes([typeIndex], byExtendingSelection: true)
  226. // if self.dataSource.count > 0 && typeIndex >= 0 {
  227. // self.type = self.dataSource[typeIndex]
  228. // }
  229. // self.updateViewButtonState()
  230. //
  231. // }
  232. //
  233. //MARK: menu
  234. // private func addMenuTitle() {
  235. // let menus : NSMenu = NSMenu(title: "")
  236. //
  237. // let addItem = self.menuItemWithTitle(title: NSLocalizedString("Thumbnails", comment: ""),type:thumbnailMethodKey,action: #selector(renameBookAction),tag: 1)
  238. // let outlineItem = self.menuItemWithTitle(title: NSLocalizedString("Outline", comment: ""),type:outlineMethodKey,action: #selector(renameBookAction),tag: 2)
  239. // let bookItem = self.menuItemWithTitle(title: NSLocalizedString("Bookmarks", comment: ""), type:bookMarkMethodKey,action: #selector(renameBookAction),tag: 3)
  240. // let annationItem = self.menuItemWithTitle(title: NSLocalizedString("Annotations", comment: ""), type:anntationMethodKey,action: #selector(renameBookAction),tag: 4)
  241. // let searchItem = self.menuItemWithTitle(title: NSLocalizedString("Search", comment: ""), type:searchMethodKey,action: #selector(renameBookAction),tag: 5)
  242. //// let formItem = self.menuItemWithTitle(title: NSLocalizedString("域", comment: ""), type:formMethodKey,action: #selector(renameBookAction),tag: 6)
  243. //// let signatureItem = self.menuItemWithTitle(title: NSLocalizedString("签名", comment: ""), type:signatureMethodKey,action: #selector(renameBookAction),tag: 7)
  244. //
  245. // menus.addItem(addItem)
  246. // menus.addItem(outlineItem)
  247. // menus.addItem(bookItem)
  248. // menus.addItem(annationItem)
  249. // menus.addItem(searchItem)
  250. //// menus.addItem(formItem)
  251. //// menus.addItem(signatureItem)
  252. //// self.leftTableview.menu = menus
  253. // }
  254. // func menuItemWithTitle(title:String,type:String,action:Selector?,tag:Int) -> NSMenuItem {
  255. // let menuItem = NSMenuItem.init(title: title as String, action: action, keyEquivalent: "")
  256. // menuItem.target = self
  257. // menuItem.tag = tag
  258. // if KMBOTAManagerClass.shard.getMethodShow(key: type) {
  259. // menuItem.state = NSControl.StateValue.on
  260. // } else {
  261. // menuItem.state = NSControl.StateValue.off
  262. // }
  263. // return menuItem
  264. // }
  265. // @objc func renameBookAction(menuItem:NSMenuItem) {
  266. // var show = true
  267. // if menuItem.state == NSControl.StateValue.on {
  268. // menuItem.state = NSControl.StateValue.off
  269. // show = false
  270. // } else {
  271. // menuItem.state = NSControl.StateValue.on
  272. // show = true
  273. // }
  274. // switch menuItem.tag {
  275. // case 1: do {
  276. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: thumbnailMethodKey)
  277. // }
  278. // case 2: do {
  279. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: outlineMethodKey)
  280. // }
  281. // case 3: do {
  282. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: bookMarkMethodKey)
  283. // }
  284. // case 4: do {
  285. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: anntationMethodKey)
  286. // }
  287. // case 5: do {
  288. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: searchMethodKey)
  289. // }
  290. // case 6: do {
  291. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: formMethodKey)
  292. // }
  293. // case 7: do {
  294. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: signatureMethodKey)
  295. // }
  296. // break
  297. // default:
  298. // break
  299. // }
  300. // self.refreshShowMethod()
  301. // }
  302. // MARK: - New
  303. /*
  304. NSArrayController *thumbnailArrayController;
  305. NSArrayController *findArrayController;
  306. NSArrayController *groupedFindArrayController;
  307. }
  308. - (void)applySearchTableHeader:(NSString *)message;
  309. - (void)displayFindState;
  310. */
  311. // @property (nonatomic, retain) IBOutlet NSArrayController *thumbnailArrayController, *findArrayController, *groupedFindArrayController;
  312. @IBOutlet var segmentedControl: KMSegmentedControl!
  313. @IBOutlet var thumbnailTableView: KMThumbnailTableView!
  314. @IBOutlet var tocOutlineView: KMTocOutlineView!
  315. @IBOutlet var noteOutlineView: KMNoteOutlineView!
  316. @IBOutlet var findTableView: KMBotaTableView!
  317. @IBOutlet var groupedFindTableView: KMBotaTableView!
  318. @IBOutlet var snapshotTableView: KMBotaTableView!
  319. @IBOutlet weak var leftListView: NSView!
  320. @IBOutlet var searchViewController: KMBotaSearchViewController!
  321. @IBOutlet weak var toolButtonBox: NSBox!
  322. @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
  323. @IBOutlet weak var snapshotNormalView: NSView!
  324. @IBOutlet weak var snapshotLabel: NSTextField!
  325. @IBOutlet weak var snapshotNormalMoreButton: NSButton!
  326. @IBOutlet weak var snapshotNormalSearchButton: NSButton!
  327. @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
  328. @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
  329. @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
  330. @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
  331. @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
  332. @IBOutlet weak var snapshotDoneButton: NSButton!
  333. @IBOutlet weak var outlineView: NSView!
  334. @IBOutlet weak var outlineMoreButton: NSButton!
  335. @IBOutlet weak var outlineAddButton: NSButton!
  336. @IBOutlet weak var outlineSearchButton: NSButton!
  337. @IBOutlet weak var outlineLabel: NSTextField!
  338. @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
  339. @IBOutlet weak var outlineDoneButton: NSButton!
  340. @IBOutlet weak var noteView: NSView!
  341. @IBOutlet weak var noteMoreButton: NSButton!
  342. @IBOutlet weak var noteFilterButton: NSButton!
  343. @IBOutlet weak var noteSearchButton: NSButton!
  344. @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
  345. @IBOutlet weak var noteTitleLabel: NSTextField!
  346. @IBOutlet weak var noteHeaderView: NSView!
  347. @IBOutlet weak var sortTypeBox: KMBox!
  348. @IBOutlet weak var sortTypeLabel: NSTextField!
  349. @IBOutlet weak var noteSortButton: NSButton!
  350. @IBOutlet weak var noteDoneButton: NSButton!
  351. @IBOutlet weak var thumbnailView: NSView!
  352. @IBOutlet weak var thumbnailZoomOutButton: NSButton!
  353. @IBOutlet weak var thumbnailZoomInButton: NSButton!
  354. @IBOutlet weak var thumbnailTitleLabel: NSTextField!
  355. @IBOutlet weak var emptySearchBox: NSBox!
  356. @IBOutlet weak var emptySearchLabel: NSTextField!
  357. var filterButtonLayer: NSView?
  358. var moreButtonLayer: KMButtonLayer?
  359. var thumbnails: [KMThumbnail] = []
  360. var isDisplayPageSize = false
  361. var thumbnailCacheSize: CGFloat = 32 * 3
  362. var findState: KMFindState = .content
  363. // var searchResults: [CPDFSelection] = []
  364. var searchResults : [KMSearchMode] = [] {
  365. didSet {
  366. self.updataLeftSideFindView()
  367. }
  368. }
  369. var findPaneState: KMFindPaneState = .singular
  370. var isSearchOutlineMode = false
  371. var outlineIgnoreCaseFlag = false
  372. var noteTypeDict: [String : Any] = [:]
  373. private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
  374. private let LABEL_COLUMNID = "label"
  375. var foldType: KMFoldAllAnnotationType = .none
  376. private let KMLeftSideViewNoteSortTypeKey = "KMLeftSideViewNoteSortTypeKey"
  377. private let KMLeftSideViewAscendSortBoolKey = "KMLeftSideViewAscendSortBoolKey"
  378. var tocType: KMFoldType = .none
  379. var snapshots: [Any] = []
  380. private var _noteSortType: KMNoteSortType = .none
  381. var noteSortType: KMNoteSortType {
  382. get {
  383. return self._noteSortType
  384. }
  385. set {
  386. self._noteSortType = newValue
  387. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
  388. }
  389. }
  390. var isAscendSort = false {
  391. didSet {
  392. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
  393. }
  394. }
  395. lazy var leftSideEmptyVC: KMLeftSideEmptyFileViewController = {
  396. let vc = KMLeftSideEmptyFileViewController(nibName: "KMLeftSideEmptyFileViewController", bundle: nil)
  397. vc.view.wantsLayer = true
  398. return vc
  399. }()
  400. var preThumbnailRow: Int = 0
  401. var leftMargin: CGFloat = 0
  402. lazy var leftView: KMBotaLeftView = {
  403. let view = KMBotaLeftView()
  404. return view
  405. }()
  406. private var _copysPages: [CPDFPage] = []
  407. override func loadView() {
  408. super.loadView()
  409. self.view.wantsLayer = true
  410. self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  411. self.view.addSubview(self.leftView)
  412. self.leftView.frame = NSMakeRect(0, 0, 44, NSHeight(self.view.frame))
  413. self.leftView.autoresizingMask = [.height]
  414. self.leftView.wantsLayer = true
  415. self.leftView.layer?.backgroundColor = .white
  416. self.outlineView.wantsLayer = true
  417. self.outlineView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  418. self.noteView.wantsLayer = true
  419. self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  420. self.thumbnailView.wantsLayer = true
  421. self.thumbnailView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  422. self.snapshotNormalView.wantsLayer = true
  423. self.snapshotNormalView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  424. self.tocOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
  425. self.noteOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
  426. self.findTableView.backgroundColor = KMAppearance.Layout.l0Color()
  427. self.groupedFindTableView.backgroundColor = KMAppearance.Layout.l0Color()
  428. self.snapshotTableView.backgroundColor = KMAppearance.Layout.l0Color()
  429. self.thumbnailTableView.backgroundColor = KMAppearance.Layout.l0Color()
  430. self.leftListView.wantsLayer = true
  431. self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  432. self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
  433. self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
  434. self.emptySearchBox.isHidden = true
  435. self.thumbnailTitleLabel.stringValue = KMLocalizedString("Thumbnails", nil)
  436. self.thumbnailTitleLabel.textColor = KMAppearance.Layout.h0Color()
  437. self.thumbnailZoomInButton.action = #selector(thumbnailSizeScaling)
  438. self.thumbnailZoomInButton.target = self
  439. self.thumbnailZoomInButton.tag = 1
  440. self.thumbnailZoomOutButton.action = #selector(thumbnailSizeScaling)
  441. self.thumbnailZoomOutButton.target = self
  442. self.thumbnailZoomOutButton.tag = 0
  443. self.snapshotTableView.delegate = self
  444. self.snapshotTableView.dataSource = self
  445. // [[snapshotTableView menu] setDelegate:mainController];
  446. // [snapshotTableView setDoubleAction:@selector(toggleSelectedSnapshots:)];
  447. // [snapshotTableView setTarget:mainController];
  448. self.snapshotTableView.backgroundColor = .clear
  449. // [snapshotTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
  450. self.snapshotLabel.stringValue = KMLocalizedString("Snapshots", nil)
  451. self.snapshotLabel.textColor = KMAppearance.Layout.h0Color()
  452. self.snapshotNormalZoomInButton.action = #selector(thumbnailSizeScaling)
  453. self.snapshotNormalZoomInButton.target = self
  454. self.snapshotNormalZoomInButton.tag = 2
  455. self.snapshotNormalZoomOutButton.action = #selector(thumbnailSizeScaling)
  456. self.snapshotNormalZoomOutButton.target = self
  457. self.snapshotNormalZoomOutButton.tag = 3
  458. self.snapshotNormalSearchButton.toolTip = KMLocalizedString("Search", nil)
  459. self.snapshotNormalMoreButton.action = #selector(leftSideViewMoreButtonAction)
  460. self.snapshotNormalMoreButton.target = self
  461. self.snapshotNormalMoreButton.tag = 300
  462. self.snapshotSearchZoomInButton.action = #selector(thumbnailSizeScaling)
  463. self.snapshotSearchZoomInButton.target = self
  464. self.snapshotSearchZoomInButton.tag = 2
  465. self.snapshotSearchZoomOutButton.action = #selector(thumbnailSizeScaling)
  466. self.snapshotSearchZoomOutButton.target = self
  467. self.snapshotSearchZoomOutButton.tag = 3
  468. self.snapshotDoneButton.title = KMLocalizedString("Done", nil)
  469. self.snapshotDoneButton.toolTip = KMLocalizedString("Done", nil)
  470. self.snapshotDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  471. self.snapshotDoneButton.wantsLayer = true
  472. self.snapshotDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  473. self.snapshotDoneButton.layer?.cornerRadius = 4.0
  474. self.snapshotDoneButton.action = #selector(leftSideViewDoneButtonAction)
  475. self.snapshotDoneButton.target = self
  476. self.snapshotDoneButton.tag = 312
  477. self.snapshotDoneButton.isHidden = true
  478. // [noteOutlineView setAutoresizesOutlineColumn: NO];
  479. self.noteOutlineView.delegate = self
  480. self.noteOutlineView.dataSource = self
  481. // [[noteOutlineView menu] setDelegate:mainController];
  482. // [noteOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
  483. // [noteOutlineView setIndentationPerLevel:0.0];
  484. // [noteOutlineView registerForDraggedTypes:[NSColor readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]];
  485. self.snapshotSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  486. self.outlineSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  487. self.noteSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  488. self.snapshotSearchField.wantsLayer = true
  489. self.outlineSearchField.wantsLayer = true
  490. self.noteSearchField.wantsLayer = true
  491. self.snapshotSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  492. self.outlineSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  493. self.noteSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  494. self.snapshotSearchField.layer?.borderWidth = 1.0
  495. self.outlineSearchField.layer?.borderWidth = 1.0
  496. self.noteSearchField.layer?.borderWidth = 1.0
  497. self.snapshotSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  498. self.outlineSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  499. self.noteSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  500. // __block typeof(self) blockSelf = self;
  501. // _snapshotSearchField.changeCallBack = ^(NSString *changeContent) {
  502. // NSString *editContent = @"";
  503. // if (changeContent) {
  504. // editContent = changeContent;
  505. // }
  506. // [blockSelf.mainController searchFieldChangeAction:editContent];
  507. // };
  508. self.snapshotSearchField.isHidden = true
  509. self.snapshotSearchZoomOutButton.isHidden = true
  510. self.snapshotSearchZoomInButton.isHidden = true
  511. // _snapshotSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  512. // if (isEndEdit/* && searchViewController.segmentedControl.segmentCount == 3*/) {
  513. // _snapshotSearchField.hidden = YES;
  514. // _snapshotSearchZoomOutButton.hidden = YES;
  515. // _snapshotSearchZoomInButton.hidden = YES;
  516. // _snapshotLabel.hidden = NO;
  517. // _snapshotNormalZoomOutButton.hidden = NO;
  518. // _snapshotNormalZoomInButton.hidden = NO;
  519. // }
  520. // };
  521. self.thumbnailZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  522. self.snapshotNormalZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  523. self.snapshotSearchZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  524. self.thumbnailZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  525. self.snapshotNormalZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  526. self.snapshotSearchZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  527. self.outlineLabel.stringValue = KMLocalizedString("Outline", nil);
  528. self.outlineLabel.textColor = KMAppearance.Layout.h0Color()
  529. self.outlineAddButton.toolTip = KMLocalizedString("Add Item", nil)
  530. self.outlineAddButton.action = #selector(outlineContextMenuItemClicked_AddEntry)
  531. self.outlineAddButton.target = self
  532. self.outlineSearchButton.toolTip = KMLocalizedString("Search", nil)
  533. self.outlineMoreButton.action = #selector(leftSideViewMoreButtonAction)
  534. self.outlineMoreButton.target = self
  535. self.outlineMoreButton.tag = 302
  536. self.outlineDoneButton.title = KMLocalizedString("Done", nil);
  537. self.outlineDoneButton.toolTip = KMLocalizedString("Done", nil);
  538. self.outlineDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  539. self.outlineDoneButton.wantsLayer = true
  540. self.outlineDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  541. self.outlineDoneButton.layer?.cornerRadius = 4.0
  542. self.outlineDoneButton.action = #selector(leftSideViewDoneButtonAction)
  543. self.outlineDoneButton.target = self
  544. self.outlineDoneButton.tag = 310
  545. self.outlineDoneButton.isHidden = true
  546. self.outlineSearchField.isHidden = true
  547. // _outlineSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  548. // if (isEndEdit) {
  549. // _outlineSearchField.hidden = YES;
  550. // _outlineLabel.hidden = NO;
  551. // _outlineSearchButton.hidden = NO;
  552. // }
  553. // };
  554. // NSMenu *menuOutline = [NSMenu menu];
  555. // [menuOutline addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleOutlineCaseInsensitiveSearch:) target:mainController];
  556. // [[_outlineSearchField cell] setSearchMenuTemplate:menuOutline];
  557. (self.outlineSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Outline", nil)
  558. self.outlineSearchField.target = self
  559. let sud = UserDefaults.standard
  560. self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
  561. self.noteTitleLabel.textColor = KMAppearance.Layout.h0Color()
  562. self.noteMoreButton.action = #selector(leftSideViewMoreButtonAction)
  563. self.noteMoreButton.target = self
  564. self.noteMoreButton.tag = 304
  565. self.noteMoreButton.wantsLayer = true
  566. self.moreButtonLayer = KMButtonLayer()
  567. self.noteMoreButton.layer?.addSublayer(self.moreButtonLayer!)
  568. self.moreButtonLayer?.frame = CGRectMake(0, 0, CGRectGetWidth(self.noteMoreButton.bounds), CGRectGetHeight(self.noteMoreButton.bounds))
  569. self.moreButtonLayer?.layerType = .none
  570. self.moreButtonLayer?.isHidden = true
  571. self.noteFilterButton.action = #selector(noteFilterAction)
  572. self.noteFilterButton.target = self
  573. self.noteFilterButton.toolTip = KMLocalizedString("Sort", nil)
  574. self.noteFilterButton.wantsLayer = true
  575. self.filterButtonLayer = NSView()
  576. self.noteFilterButton.addSubview(self.filterButtonLayer!)
  577. self.filterButtonLayer?.frame = CGRectMake(14, 2, 8, 8)
  578. // self.filterButtonLayer?.layerType = KMNoteFilerButtonLayerType_Dot
  579. self.filterButtonLayer?.isHidden = true
  580. self.filterButtonLayer?.wantsLayer = true
  581. self.filterButtonLayer?.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  582. self.filterButtonLayer?.layer?.cornerRadius = 4.0
  583. self.noteDoneButton.title = KMLocalizedString("Done", nil)
  584. self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
  585. self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  586. self.noteDoneButton.wantsLayer = true
  587. self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  588. self.noteDoneButton.layer?.cornerRadius = 4.0
  589. self.noteDoneButton.action = #selector(leftSideViewDoneButtonAction)
  590. self.noteDoneButton.target = self
  591. self.noteDoneButton.tag = 311
  592. self.noteDoneButton.isHidden = true
  593. self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
  594. self.noteSearchField.isHidden = true
  595. self.noteSearchField.endEditCallBack = { [unowned self] isEndEdit in
  596. if (isEndEdit) {
  597. self.noteSearchField.isHidden = true
  598. self.noteSearchButton.isHidden = false
  599. self.noteTitleLabel.isHidden = false
  600. }
  601. };
  602. self.noteHeaderView.wantsLayer = true
  603. self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
  604. self.noteHeaderView.layer?.cornerRadius = 1.0
  605. let sortType = sud.integer(forKey: KMLeftSideViewNoteSortTypeKey)
  606. if (sortType == 1) {
  607. self.noteSortType = KMNoteSortType(rawValue: sortType)!
  608. if (self.noteSortType == .time) {
  609. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  610. self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
  611. } else if (self._noteSortType == .page) {
  612. self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
  613. self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
  614. }
  615. } else {
  616. self.noteSortType = .time
  617. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  618. }
  619. self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
  620. self.isAscendSort = sud.bool(forKey: KMLeftSideViewAscendSortBoolKey)
  621. if (self.isAscendSort) {
  622. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  623. self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  624. } else {
  625. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  626. self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  627. }
  628. self.sortTypeBox.downCallback = { [unowned self] downEntered, mouseBox, _ in
  629. if (downEntered) {
  630. let menu = NSMenu()
  631. let timeItem = menu.addItem(title: KMLocalizedString("Time", nil), action: #selector(sortTypeAction), target: self)
  632. timeItem?.representedObject = self
  633. timeItem?.tag = 0
  634. let pageItem = menu.addItem(title: KMLocalizedString("Page", nil), action: #selector(sortTypeAction), target: self)
  635. pageItem?.representedObject = self
  636. timeItem?.tag = 1
  637. if (self.noteSortType == .time) {
  638. timeItem?.state = .on
  639. pageItem?.state = .off
  640. } else if (self.noteSortType == .page) {
  641. timeItem?.state = .off
  642. pageItem?.state = .on
  643. }
  644. menu.popUp(positioning: nil, at: CGPointMake(-10, 0), in: self.sortTypeBox)
  645. }
  646. }
  647. self.searchViewController.loadView()
  648. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  649. self.searchField = self.searchViewController.searchField
  650. self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
  651. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
  652. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
  653. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
  654. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
  655. self.searchViewController.segmentedControl.isBackgroundHighlighted = true
  656. self.searchViewController.segmentedControl.selectedSegment = 0
  657. self.searchViewController.segmentedControl.block = { [unowned self] segIndex in
  658. if segIndex == 0 {
  659. self.findPaneState = .singular
  660. self.displayFindViewAnimating(false)
  661. } else {
  662. self.findPaneState = .grouped
  663. self.displayGroupedFindViewAnimating(false)
  664. }
  665. }
  666. // [mainController bind:@"findPaneState" toObject:searchViewController.segmentedControl withKeyPath:@"selectedSegment" options:nil];
  667. self.leftView.segmentedControl.block = { [unowned self] segIndex in
  668. self.toolButtonBox.isHidden = false
  669. self.toolButtonBoxLayoutConstraint.constant = 40.0
  670. if (segIndex == 0) {
  671. if self.type.methodType == .Thumbnail {
  672. self.leftView.segmentedControl.selectedSegment = UInt8.max
  673. self.refreshMethodType(methodType: .None)
  674. return
  675. }
  676. self.refreshMethodType(methodType: .Thumbnail)
  677. DispatchQueue.main.async {
  678. self.toolButtonBox.contentView = self.thumbnailView
  679. self.displayThumbnailViewAnimating(true)
  680. }
  681. } else if (segIndex == 1) {
  682. if self.type.methodType == .Outline {
  683. self.leftView.segmentedControl.selectedSegment = UInt8.max
  684. self.refreshMethodType(methodType: .None)
  685. return
  686. }
  687. self.refreshMethodType(methodType: .Outline)
  688. DispatchQueue.main.async {
  689. self.toolButtonBox.contentView = self.outlineView
  690. self.displayTocViewAnimating(false)
  691. }
  692. } else if (segIndex == 2) {
  693. if self.type.methodType == .Annotation {
  694. self.leftView.segmentedControl.selectedSegment = UInt8.max
  695. self.refreshMethodType(methodType: .None)
  696. return
  697. }
  698. self.refreshMethodType(methodType: .Annotation)
  699. DispatchQueue.main.async {
  700. self.toolButtonBox.contentView = self.noteView
  701. self.displayNoteViewAnimating(false)
  702. }
  703. } else if (segIndex == 3) {
  704. self.toolButtonBox.contentView = self.snapshotNormalView
  705. self.displaySnapshotViewAnimating(false)
  706. self.updataLeftSideSnapView()
  707. } else if (segIndex == 4) {
  708. if self.type.methodType == .Search {
  709. self.leftView.segmentedControl.selectedSegment = UInt8.max
  710. self.refreshMethodType(methodType: .None)
  711. return
  712. }
  713. self.refreshMethodType(methodType: .Search)
  714. DispatchQueue.main.async {
  715. self.toolButtonBox.isHidden = true
  716. self.toolButtonBoxLayoutConstraint.constant = 0
  717. self.displayFindViewAnimating(false)
  718. }
  719. }
  720. }
  721. // self.button.setHelp(KMLocalizedString("View Thumbnails", "Tool tip message"), for: KMLeftSidePaneState.thumbnail.rawValue)
  722. // self.button.setHelp(KMLocalizedString("View Outline", "Tool tip message"), for: KMLeftSidePaneState.outline.rawValue)
  723. // self.alternateButton.setHelp(KMLocalizedString("Separate search results", "Tool tip message"), for: KMFindPaneState.singular.rawValue)
  724. // self.alternateButton.setHelp(KMLocalizedString("Group search results by page", "Tool tip message"), for: KMFindPaneState.grouped.rawValue)
  725. // NSMenu *menu = [NSMenu menu];
  726. // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
  727. // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
  728. // [[searchField cell] setSearchMenuTemplate:menu];
  729. // [[searchField cell] setPlaceholderString:NSLocalizedString(@"Search PDF", @"placeholder")];
  730. self.searchField.action = #selector(search)
  731. self.searchField.target = self
  732. self.tocOutlineView.autoresizesOutlineColumn = false
  733. self.tocOutlineView.allowsMultipleSelection = true
  734. self.tocOutlineView.allowsEmptySelection = true
  735. self.tocOutlineView.delegate = self
  736. self.tocOutlineView.dataSource = self
  737. self.thumbnailTableView.delegate = self
  738. self.thumbnailTableView.dataSource = self
  739. self.thumbnailTableView.allowsMultipleSelection = true
  740. self.findTableView.delegate = self
  741. self.findTableView.dataSource = self
  742. self.groupedFindTableView.delegate = self
  743. self.groupedFindTableView.dataSource = self
  744. self.thumbnailTableView.menu?.delegate = self
  745. // [[thumbnailTableView menu] setDelegate:mainController];
  746. // [[findTableView menu] setDelegate:mainController];
  747. // [[groupedFindTableView menu] setDelegate:mainController];
  748. // [tocOutlineView setDoubleAction:@selector(goToSelectedOutlineItem:)];
  749. // [tocOutlineView setTarget:mainController];
  750. // [findTableView setDoubleAction:@selector(goToSelectedFindResults:)];
  751. // [findTableView setTarget:mainController];
  752. // [groupedFindTableView setDoubleAction:@selector(goToSelectedFindResults:)];
  753. // [groupedFindTableView setTarget:mainController];
  754. // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
  755. // //支持拖拽的文字类型
  756. // [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
  757. // [tocOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
  758. // [tocOutlineView registerForDraggedTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType]];
  759. // [[[findTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
  760. // [[[groupedFindTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
  761. // [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] dataCell] setEnabled:NO];
  762. // if (RUNNING_AFTER(10_9)) {
  763. // [thumbnailTableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
  764. // [(SKSourceListTextFieldCell *)[[thumbnailTableView tableColumnWithIdentifier:PAGE_COLUMNID] dataCell] setSimulatesSourceList:YES];
  765. // }
  766. // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
  767. // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
  768. //
  769. // [thumbnailTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
  770. // if (NO == [[NSUserDefaults standardUserDefaults] boolForKey:SKDisableTableToolTipsKey]) {
  771. // [tocOutlineView setHasImageToolTips:YES];
  772. // [findTableView setHasImageToolTips:YES];
  773. // [groupedFindTableView setHasImageToolTips:YES];
  774. // }
  775. // [self updateViewColor];
  776. }
  777. func displayThumbnailViewAnimating(_ animate: Bool) {
  778. self.replaceSideView(self.thumbnailTableView.enclosingScrollView!, animate: animate)
  779. var frame = self.thumbnailTableView.enclosingScrollView?.frame ?? .zero
  780. frame.origin.y = 0
  781. frame.origin.x = self.leftMargin
  782. frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  783. self.thumbnailTableView.enclosingScrollView?.frame = frame
  784. self.resetThumbnails()
  785. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  786. frame.origin.y = 0
  787. frame.origin.x = self.leftMargin
  788. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  789. self.noteOutlineView.enclosingScrollView?.frame = frame
  790. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  791. frame.origin.y = 0
  792. frame.origin.x = self.leftMargin
  793. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  794. self.snapshotTableView.enclosingScrollView?.frame = frame
  795. // [self updateThumbnailSelection];
  796. }
  797. func displayFindViewAnimating(_ animate: Bool) {
  798. self.replaceSideView(self.searchViewController.view, animate: animate)
  799. if (self.findState != .content) {
  800. self.findState = .content
  801. } else {
  802. self.displayFindState()
  803. }
  804. var frame = self.searchViewController.view.frame
  805. frame.origin.y = 0
  806. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
  807. self.searchViewController.view.frame = frame
  808. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  809. frame.origin.y = 0
  810. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  811. self.noteOutlineView.enclosingScrollView?.frame = frame
  812. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  813. frame.origin.y = 0
  814. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  815. self.snapshotTableView.enclosingScrollView?.frame = frame
  816. self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
  817. self.updataLeftSideSnapView()
  818. }
  819. func displayFindState() {
  820. if (self.findState == .content) {
  821. self.displayFind()
  822. } else if (self.findState == .note) {
  823. // [self displayNoteFind];
  824. } else if (self.findState == .snapshot) {
  825. // [self displaySnapshotFind];
  826. }
  827. }
  828. func updataLeftSideSnapView() {
  829. if (snapshots.count < 1) {
  830. self.snapshotNormalSearchButton.isEnabled = false
  831. // leftSideController.snapshotSearchZoomOutButton.enabled = NO;
  832. self.snapshotNormalZoomOutButton.isEnabled = false
  833. // leftSideController.snapshotSearchZoomInButton.enabled = NO;
  834. self.snapshotNormalZoomInButton.isEnabled = false
  835. self.snapshotNormalMoreButton.isEnabled = false
  836. self.leftSideEmptyVC.deleteSnapBtn.isEnabled = false
  837. self.leftSideEmptyVC.exportSnapBtn.isEnabled = false
  838. self.leftSideEmptyVC.printSnapBtn.isEnabled = false
  839. self.snapshotTableView.usesAlternatingRowBackgroundColors = false
  840. let view = self.snapshotTableView.enclosingScrollView!
  841. let emptyVcSize = self.leftSideEmptyVC.emptySnapView.frame.size
  842. self.leftSideEmptyVC.emptySnapView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
  843. self.leftSideEmptyVC.emptySnapView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  844. self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptySnapView)
  845. } else {
  846. self.snapshotNormalSearchButton.isEnabled = true
  847. // leftSideController.snapshotSearchZoomOutButton.enabled = YES;
  848. self.snapshotNormalZoomOutButton.isEnabled = true
  849. // leftSideController.snapshotSearchZoomInButton.enabled = YES;
  850. self.snapshotNormalZoomInButton.isEnabled = true
  851. self.snapshotNormalMoreButton.isEnabled = true
  852. self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
  853. self.leftSideEmptyVC.deleteSnapBtn.isEnabled = true
  854. self.leftSideEmptyVC.exportSnapBtn.isEnabled = true
  855. self.leftSideEmptyVC.printSnapBtn.isEnabled = true
  856. }
  857. }
  858. func updataLeftSideFindView() {
  859. if (self.findState != .content) {
  860. return
  861. }
  862. if (self.searchResults.count > 0) {
  863. self.searchViewController.emptyBox.isHidden = true
  864. self.searchViewController.searchResultsView.isHidden = false
  865. self.searchViewController.searchResultsLabel.stringValue = String(format: KMLocalizedString("%ld Results", "Message in search table header"), self.searchResults.count)
  866. } else {
  867. self.searchViewController.emptyBox.isHidden = false
  868. self.searchViewController.searchResultsView.isHidden = true
  869. }
  870. }
  871. func displayGroupedFindViewAnimating(_ animate: Bool) {
  872. self.replaceSideView(self.searchViewController.view , animate: animate)
  873. if (self.findState != .content) {
  874. self.findState = .content
  875. } else {
  876. self.displayFindState()
  877. }
  878. var frame = self.searchViewController.view.frame
  879. frame.origin.y = 0
  880. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? 0
  881. self.searchViewController.view.frame = frame
  882. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  883. frame.origin.y = 0
  884. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  885. self.noteOutlineView.enclosingScrollView?.frame = frame
  886. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  887. frame.origin.y = 0
  888. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  889. self.snapshotTableView.enclosingScrollView?.frame = frame
  890. self.updataLeftSideSnapView()
  891. }
  892. func displayNoteViewAnimating(_ animate: Bool) {
  893. self.searchViewController.contentView = nil
  894. self.replaceSideView(self.noteOutlineView.enclosingScrollView!, animate: animate)
  895. if (self.findState != .note) {
  896. self.findState = .note
  897. } else {
  898. self.displayFindState()
  899. }
  900. var frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  901. frame.origin.y = 0
  902. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  903. self.noteOutlineView.enclosingScrollView?.frame = frame
  904. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  905. frame.origin.y = 0
  906. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  907. self.noteOutlineView.enclosingScrollView?.frame = frame
  908. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  909. frame.origin.y = 0
  910. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  911. self.snapshotTableView.enclosingScrollView?.frame = frame
  912. let view = self.noteOutlineView.enclosingScrollView!
  913. let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  914. 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)
  915. DispatchQueue.main.async {
  916. self.noteOutlineView.reloadData()
  917. }
  918. }
  919. func displaySnapshotViewAnimating(_ animate: Bool) {
  920. self.searchViewController.contentView = nil
  921. self.replaceSideView(self.snapshotTableView.enclosingScrollView!, animate: animate)
  922. if (self.findState != .snapshot) {
  923. self.findState = .snapshot;
  924. } else {
  925. self.displayFindState()
  926. }
  927. var frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  928. frame.origin.y = 0
  929. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  930. self.snapshotTableView.enclosingScrollView?.frame = frame
  931. // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  932. // frame.origin.y = 0;
  933. // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  934. // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  935. frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
  936. frame.origin.y = 0
  937. frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  938. self.tocOutlineView.enclosingScrollView?.frame = frame
  939. // [self updateSnapshotsIfNeeded];
  940. }
  941. func displayFind() {
  942. self.searchField = self.searchViewController.searchField
  943. let menu = NSMenu()
  944. // menu.addItem(title: <#T##String#>, action: <#T##Selector?#>, target: <#T##AnyObject?#>)
  945. // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
  946. // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
  947. // [[searchViewController.searchField cell] setSearchMenuTemplate:menu];
  948. (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
  949. // self.searchViewController.searchField.target =
  950. // [searchViewController.searchField setAction:@selector(search:)];
  951. // [searchViewController.searchField setTarget:mainController];
  952. if (self.findPaneState == .singular) {
  953. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  954. self.findTableView.wantsLayer = true
  955. self.findTableView.layer?.backgroundColor = NSColor.red.cgColor
  956. DispatchQueue.main.async {
  957. self.findTableView.reloadData()
  958. }
  959. } else if (self.findPaneState == .grouped) {
  960. self.searchViewController.contentView = self.groupedFindTableView.enclosingScrollView
  961. self.groupedFindTableView.reloadData()
  962. }
  963. }
  964. func displayTocViewAnimating(_ animate: Bool) {
  965. self.replaceSideView(self.tocOutlineView.enclosingScrollView!, animate: animate)
  966. var frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
  967. frame.origin.y = 0
  968. frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  969. self.tocOutlineView.enclosingScrollView?.frame = frame
  970. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  971. frame.origin.y = 0
  972. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  973. self.noteOutlineView.enclosingScrollView?.frame = frame
  974. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  975. frame.origin.y = 0
  976. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  977. self.snapshotTableView.enclosingScrollView?.frame = frame
  978. // [self updateOutlineSelection];
  979. let view = self.tocOutlineView.enclosingScrollView!
  980. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  981. 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);
  982. }
  983. /*
  984. @implementation SKLeftSideViewController
  985. @synthesize thumbnailArrayController, findArrayController, groupedFindArrayController;
  986. - (BOOL)requiresAlternateButtonForView:(NSView *)aView {
  987. return NO;
  988. return [findTableView isDescendantOf:aView] || [groupedFindTableView isDescendantOf:aView];
  989. }
  990. - (void)applySearchTableHeader:(NSString *)message {
  991. [[[findTableView tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
  992. [[findTableView headerView] setNeedsDisplay:YES];
  993. [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell] setStringValue:message];
  994. [[groupedFindTableView headerView] setNeedsDisplay:YES];
  995. }
  996. - (void)displayFindState {
  997. if (mainController.findState == SKFindStateContent) {
  998. [self displayFind];
  999. } else if (mainController.findState == SKFindStateNote) {
  1000. [self displayNoteFind];
  1001. } else if (mainController.findState == SKFindStateSnapshot) {
  1002. [self displaySnapshotFind];
  1003. }
  1004. }
  1005. - (void)displayNoteFind {
  1006. mainController.rightSideController.searchField = self.noteSearchField;
  1007. NSMenu *menu = [NSMenu menu];
  1008. [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
  1009. [[self.noteSearchField cell] setSearchMenuTemplate:menu];
  1010. [[self.noteSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Notes", @"placeholder")];
  1011. [self.noteSearchField setAction:@selector(searchNotes:)];
  1012. [self.noteSearchField setTarget:mainController];
  1013. }
  1014. - (void)displaySnapshotFind {
  1015. mainController.rightSideController.searchField = self.snapshotSearchField;
  1016. NSMenu *menu = [NSMenu menu];
  1017. [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
  1018. [[self.snapshotSearchField cell] setSearchMenuTemplate:menu];
  1019. [[self.snapshotSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Snapshots", @"placeholder")];
  1020. [self.snapshotSearchField setAction:@selector(searchNotes:)];
  1021. [self.snapshotSearchField setTarget:mainController];
  1022. [self.snapshotSearchField setDelegate:mainController];
  1023. }
  1024. */
  1025. @IBAction func search(_ sender: NSSearchField) {
  1026. self.delegate?.searchAction?(searchString: sender.stringValue, isCase: false)
  1027. }
  1028. @IBAction func snapshotNormalSearchButtonAction(_ sender: NSButton) {
  1029. self.snapshotSearchField.isHidden = false
  1030. // _snapshotSearchZoomOutButton.hidden = YES;
  1031. self.snapshotSearchZoomInButton.isHidden = true
  1032. self.snapshotNormalSearchButton.isHidden = true
  1033. self.snapshotDoneButton.isHidden = false
  1034. self.snapshotLabel.isHidden = true
  1035. self.snapshotNormalZoomOutButton.isHidden = true
  1036. self.snapshotNormalZoomInButton.isHidden = true
  1037. self.snapshotSearchField.becomeFirstResponder()
  1038. }
  1039. func resetThumbnails() {
  1040. // [self willChangeValueForKey:THUMBNAILS_KEY];
  1041. // self.thumbnailCacheSize = 160
  1042. self.thumbnails.removeAll()
  1043. let pageLabels = self.listView.document.pageLabels()
  1044. if (pageLabels.isEmpty == false) {
  1045. let isLocked = self.listView.document.isLocked
  1046. let firstPage = self.listView.document.page(at: 0)
  1047. // SKPDFPage
  1048. let emptyPage = CPDFPage()
  1049. let firstFrame = firstPage?.bounds(for: .cropBox) ?? .zero
  1050. let firstFrame2 = firstPage?.bounds(for: .mediaBox) ?? .zero
  1051. emptyPage.setBounds(firstFrame, for: .cropBox)
  1052. emptyPage.setBounds(firstFrame2, for: .mediaBox)
  1053. emptyPage.rotation = firstPage?.rotation ?? 0
  1054. let pageImage = firstPage!.thumbnail(of: NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize))
  1055. // NSImage * = [emptyPage thumbnailWithSize:thumbnailCacheSize forBox:[pdfView displayBox]];
  1056. var rect: NSRect = .zero
  1057. rect.size = pageImage?.size ?? .zero
  1058. let width = 1.2 * fmin(NSWidth(rect), NSHeight(rect))
  1059. rect = NSInsetRect(rect, 0.5 * (NSWidth(rect) - width), 0.5 * (NSHeight(rect) - width));
  1060. pageImage?.lockFocus()
  1061. // NSImage(named: NSImage.applicationIconName)?.draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
  1062. if (isLocked) {
  1063. NSWorkspace.shared.icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kLockedBadgeIcon))).draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
  1064. // [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:0.5];
  1065. }
  1066. pageImage?.unlockFocus()
  1067. // __block typeof(self) blockSelf = self;
  1068. for (i, label) in pageLabels.enumerated() {
  1069. let firstPage = self.listView.document.page(at: UInt(i))
  1070. let size = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
  1071. let pageImage = firstPage!.thumbnail(of: size)
  1072. let thumbnail = KMThumbnail(image: pageImage, label: label, pageIndex: i)
  1073. // thumbnail.delegate = self
  1074. thumbnail.dirty = true
  1075. self.thumbnails.append(thumbnail)
  1076. }
  1077. }
  1078. // [self didChangeValueForKey:THUMBNAILS_KEY];
  1079. // [self allThumbnailsNeedUpdate];
  1080. DispatchQueue.main.async {
  1081. self.thumbnailTableView.reloadData()
  1082. }
  1083. }
  1084. @IBAction @objc func sortTypeAction(_ sender: NSMenuItem) {
  1085. let item = sender
  1086. let tag = item.tag
  1087. if (item.state == .on) {
  1088. item.state = .off
  1089. } else {
  1090. item.state = .on
  1091. }
  1092. if (tag == 0) {
  1093. self.noteSortType = .page
  1094. self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
  1095. self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
  1096. } else if (tag == 1) {
  1097. self.noteSortType = .time
  1098. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  1099. self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
  1100. }
  1101. UserDefaults.standard.set(self.noteSortType.rawValue, forKey: KMLeftSideViewNoteSortTypeKey)
  1102. UserDefaults.standard.synchronize()
  1103. }
  1104. @IBAction func noteSortAction(_ sender: AnyObject?) {
  1105. if (self.isAscendSort) {
  1106. self.isAscendSort = false
  1107. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  1108. self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  1109. } else {
  1110. self.isAscendSort = true
  1111. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  1112. self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  1113. }
  1114. UserDefaults.standard.setValue(self.isAscendSort, forKey: KMLeftSideViewAscendSortBoolKey)
  1115. UserDefaults.standard.synchronize()
  1116. }
  1117. @IBAction func noteSearchAction(_ sender: NSButton) {
  1118. self.noteSearchField.isHidden = false
  1119. self.noteTitleLabel.isHidden = true
  1120. self.noteSearchButton.isHidden = true
  1121. self.noteDoneButton.isHidden = false
  1122. self.noteFilterButton.isHidden = true
  1123. self.noteMoreButton.isHidden = true
  1124. self.noteSearchField.becomeFirstResponder()
  1125. }
  1126. @IBAction func leftSideViewDoneButtonAction(_ sender: AnyObject?) {
  1127. let button = sender as? NSButton
  1128. let tag = button?.tag ?? 0
  1129. if (tag == 310) {
  1130. self.outlineSearchField.isHidden = true
  1131. self.outlineDoneButton.isHidden = true
  1132. self.outlineLabel.isHidden = false
  1133. self.outlineSearchButton.isHidden = false
  1134. self.outlineMoreButton.isHidden = false
  1135. self.outlineAddButton.isHidden = false
  1136. } else if (tag == 311) {
  1137. self.noteSearchField.isHidden = true
  1138. self.noteTitleLabel.isHidden = false
  1139. self.noteSearchButton.isHidden = false
  1140. self.noteDoneButton.isHidden = true
  1141. self.noteFilterButton.isHidden = false
  1142. self.noteMoreButton.isHidden = false
  1143. } else if (tag == 312) {
  1144. self.snapshotSearchField.isHidden = true
  1145. // leftSideController.snapshotSearchZoomOutButton.hidden = YES;
  1146. // leftSideController.snapshotSearchZoomInButton.hidden = YES;
  1147. self.snapshotNormalSearchButton.isHidden = false
  1148. self.snapshotDoneButton.isHidden = true
  1149. self.snapshotLabel.isHidden = false
  1150. self.snapshotNormalZoomOutButton.isHidden = false
  1151. self.snapshotNormalZoomInButton.isHidden = false
  1152. }
  1153. }
  1154. @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
  1155. let button = sender as? NSButton
  1156. let tag = button?.tag ?? 0
  1157. if (tag == 300) {
  1158. // NSInteger selectedRow = 0;
  1159. // if (rightSideController.snapshotTableView.selectedRow >= 0) {
  1160. // selectedRow = rightSideController.snapshotTableView.selectedRow;
  1161. // } else {
  1162. // return;
  1163. // }
  1164. // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:selectedRow];
  1165. // NSMenu *menu = [[[NSMenu alloc] init] autorelease];
  1166. // NSMenuItem *itemExport = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil target:self];
  1167. // NSMenu *subMenu = [NSMenu menu];
  1168. //
  1169. // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(menuItemClick_ExportPNG:) target:self];
  1170. // [t setRepresentedObject:controller];
  1171. //
  1172. // t = [subMenu addItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(menuItemClick_ExportJPG:) target:self];
  1173. // [t setRepresentedObject:controller];
  1174. //
  1175. // t = [subMenu addItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(menuItemClick_ExportPDF:) target:self];
  1176. // [t setRepresentedObject:controller];
  1177. // itemExport.submenu = subMenu;
  1178. //
  1179. // NSMenuItem *itemPrint = [menu addItemWithTitle:NSLocalizedString(@"Print", @"Menu item title") action:@selector(menuItemClick_Print:) target:self];
  1180. // [itemPrint setRepresentedObject:controller];
  1181. // [menu addItem:[NSMenuItem separatorItem]];
  1182. //
  1183. // NSMenuItem *itemSelectAll = [menu addItemWithTitle:NSLocalizedString(@"Select All", @"Menu item title") action:@selector(menuItemClick_SelectAll:) target:self];
  1184. // [itemSelectAll setRepresentedObject:controller];
  1185. // [menu addItem:[NSMenuItem separatorItem]];
  1186. //
  1187. // NSMenuItem *itemDeleteAllSnapshot = [menu addItemWithTitle:NSLocalizedString(@"Delete All Snapshots", @"Menu item title") action:@selector(deleteAllSnapshot:) target:self];
  1188. // [itemDeleteAllSnapshot setRepresentedObject:controller];
  1189. //
  1190. // [NSMenu popUpContextMenu:menu withEvent:[NSApp currentEvent] forView:(NSButton *)sender];
  1191. } else if (tag == 302) {
  1192. let menu = NSMenu()
  1193. // NSMenuItem *addEntryItem = [menu addItemWithTitle:NSLocalizedString(@"Add Item", nil) action:@selector(outlineContextMenuItemClicked_AddEntry:) target:self];
  1194. // [addEntryItem setRepresentedObject:self.leftSideController.tocOutlineView];
  1195. // NSMenuItem *addChildItem = [menu addItemWithTitle:NSLocalizedString(@"Add Sub-Item", nil) action:@selector(outlineContextMenuItemClicked_AddChildEntry:) target:self];
  1196. // [addChildItem setRepresentedObject:self.leftSideController.tocOutlineView];
  1197. // [menu addItem:[NSMenuItem separatorItem]];
  1198. //
  1199. // NSMenuItem *setDestinationItem = [menu addItemWithTitle:NSLocalizedString(@"Change Destination", nil) action:@selector(outlineContextMenuItemClicked_SetDestination:) target:self];
  1200. // [setDestinationItem setRepresentedObject:self.leftSideController.tocOutlineView];
  1201. // [menu addItem:[NSMenuItem separatorItem]];
  1202. let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
  1203. expandAllCommentsItem?.representedObject = self.tocOutlineView
  1204. let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
  1205. expandAllCommentsItem?.representedObject = self.tocOutlineView
  1206. let item = self.listView.document.outlineRoot()
  1207. var num = 0
  1208. for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
  1209. let outline = item?.child(at: UInt(i))
  1210. if self.tocOutlineView.isItemExpanded(outline) {
  1211. num += 1
  1212. }
  1213. }
  1214. if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
  1215. self.tocType = .fold
  1216. } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
  1217. self.tocType = .unfold
  1218. } else {
  1219. self.tocType = .none
  1220. }
  1221. if (self.tocType == .unfold) {
  1222. expandAllCommentsItem?.state = .on
  1223. foldAllCommentsItem?.state = .off
  1224. } else if (self.tocType == .fold) {
  1225. expandAllCommentsItem?.state = .off
  1226. foldAllCommentsItem?.state = .on
  1227. } else {
  1228. expandAllCommentsItem?.state = .off
  1229. foldAllCommentsItem?.state = .off
  1230. }
  1231. let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
  1232. removeEntryItem?.representedObject = self.tocOutlineView
  1233. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
  1234. } else if (tag == 304) {
  1235. let menu = NSMenu()
  1236. let object = KMPopupMenuObject()
  1237. object.menuTag = 1001
  1238. menu.delegate = object
  1239. object.enterControllerCallback = { [weak self] isEnter in
  1240. if (isEnter) {
  1241. self?.moreButtonLayer?.isHidden = false
  1242. } else {
  1243. self?.moreButtonLayer?.isHidden = true
  1244. }
  1245. }
  1246. let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
  1247. expandAllCommentsItem?.representedObject = self.noteOutlineView
  1248. let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
  1249. foldAllCommentsItem?.representedObject = self.noteOutlineView
  1250. if (self.foldType == .unfold) {
  1251. expandAllCommentsItem?.state = .on
  1252. foldAllCommentsItem?.state = .off
  1253. } else if (self.foldType == .fold) {
  1254. expandAllCommentsItem?.state = .off
  1255. foldAllCommentsItem?.state = .on
  1256. } else {
  1257. expandAllCommentsItem?.state = .off
  1258. foldAllCommentsItem?.state = .off
  1259. }
  1260. let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
  1261. let subMenu = NSMenu()
  1262. // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"Type", nil) action:@selector(noteShowNoteAction:) target:self];
  1263. // if ([[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue]) {
  1264. // [t setState:NSControlStateValueOff];
  1265. // } else {
  1266. // [t setState:NSControlStateValueOn];
  1267. // }
  1268. // [t setRepresentedObject:self.rightSideController.noteOutlineView];
  1269. // t.tag = 100;
  1270. var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
  1271. let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
  1272. if pageKey {
  1273. t?.state = .off
  1274. } else {
  1275. t?.state = .on
  1276. }
  1277. t?.representedObject = self.noteOutlineView
  1278. t?.tag = 101
  1279. t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
  1280. let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
  1281. if timeKey {
  1282. t?.state = .off
  1283. } else {
  1284. t?.state = .on
  1285. }
  1286. t?.representedObject = self.noteOutlineView
  1287. t?.tag = 102
  1288. t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
  1289. let authorKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
  1290. if authorKey {
  1291. t?.state = .off
  1292. } else {
  1293. t?.state = .on
  1294. }
  1295. t?.representedObject = self.noteOutlineView
  1296. t?.tag = 103
  1297. showAnnotationItem?.submenu = subMenu
  1298. menu.addItem(.separator())
  1299. let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: ""), action: nil, target: self)
  1300. let subMenu2 = NSMenu()
  1301. var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1302. t2?.representedObject = self.noteOutlineView
  1303. t2?.tag = 0
  1304. t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1305. t2?.representedObject = self.noteOutlineView
  1306. t2?.tag = 1
  1307. t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1308. t2?.representedObject = self.noteOutlineView
  1309. t2?.tag = 2
  1310. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1311. t2?.representedObject = self.noteOutlineView
  1312. t2?.tag = 3
  1313. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1314. t2?.representedObject = self.noteOutlineView
  1315. t2?.tag = 4
  1316. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1317. t2?.representedObject = self.noteOutlineView
  1318. t2?.tag = 5
  1319. t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
  1320. t2?.representedObject = self.noteOutlineView
  1321. t2?.tag = 6
  1322. exportAnnotationsItem?.submenu = subMenu2
  1323. menu.addItem(.separator())
  1324. let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
  1325. removeAllAnnotationsItem?.representedObject = self.noteOutlineView
  1326. NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: button!, with: nil)
  1327. }
  1328. }
  1329. @IBAction func note_expandAllComments(_ sender: AnyObject?) {
  1330. if (self.foldType == .unfold) {
  1331. return
  1332. }
  1333. self.foldType = .unfold
  1334. // [self loadUnfoldDate:KMFoldAllAnnotationType_None];
  1335. self.noteOutlineView.reloadData()
  1336. }
  1337. @IBAction func note_foldAllComments(_ sender: AnyObject?) {
  1338. if (self.foldType == .fold) {
  1339. return
  1340. }
  1341. self.foldType = .fold
  1342. // [self loadUnfoldDate:KMFoldAllAnnotationType_None];
  1343. self.noteOutlineView.reloadData()
  1344. }
  1345. @IBAction func noteShowNoteAction(_ sender: AnyObject?) {
  1346. let item = sender as? NSMenuItem
  1347. let tag = item?.tag ?? 0
  1348. if (tag == 100) {
  1349. // BOOL isType = [[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue];
  1350. // [self.noteTypeDict setObject:[NSNumber numberWithBool:!isType] forKey:@"kKMNoteFilterAnnotationTypeKey"];
  1351. } else if (tag == 101) {
  1352. let isPage = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
  1353. self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] = isPage
  1354. } else if (tag == 102) {
  1355. let isTime = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
  1356. self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] = isTime
  1357. } else if (tag == 103) {
  1358. let isAuther = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
  1359. self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] = isAuther
  1360. }
  1361. UserDefaults.standard.set(self.noteTypeDict, forKey: "KMNoteOutlineViewTableColumnKey")
  1362. UserDefaults.standard.synchronize()
  1363. let selectRow = self.noteOutlineView.selectedRow
  1364. self.noteOutlineView.reloadData()
  1365. self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  1366. }
  1367. @objc func exportAnnotationNotes(_ sender: AnyObject?) {
  1368. // [self.document saveDocumentTo:sender];
  1369. self.mainViewController.myDocument?.saveTo(sender)
  1370. }
  1371. @objc func leftSideEmptyAnnotationClick_DeleteAnnotation(_ sender: AnyObject?) {
  1372. // NSAlert* alert = [[NSAlert alloc] init];
  1373. // [alert setAlertStyle:NSAlertStyleCritical];
  1374. // [alert setMessageText:NSLocalizedString(@"This will permanently remove all annotations. Are you sure to continue?", nil)];
  1375. // [alert addButtonWithTitle:NSLocalizedString(@"Yes", nil)];
  1376. // [alert addButtonWithTitle:NSLocalizedString(@"No", nil)];
  1377. //
  1378. // NSModalResponse response = [alert runModal];
  1379. // if (response == NSAlertFirstButtonReturn) {
  1380. // NSMutableArray *annotations = [NSMutableArray array];
  1381. //
  1382. // for (NSUInteger i = 0; i < self.pdfView.document.pageCount; i++) {
  1383. // PDFPage *page = [[self.pdfView document] pageAtIndex:i];
  1384. // for (PDFAnnotation *annotation in [page annotations]) {
  1385. // if ([annotation isKindOfClass:[PDFAnnotationTextWidget class]] ||
  1386. // [annotation isKindOfClass:[PDFAnnotationButtonWidget class]] ||
  1387. // [annotation isKindOfClass:[PDFAnnotationChoiceWidget class]]) {
  1388. // continue;
  1389. // }
  1390. // if (@available(macOS 10.13, *)) {
  1391. // if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  1392. // continue;
  1393. // }
  1394. // }
  1395. // if ([annotation isKindOfClass:[PDFAnnotationLink class]]) {
  1396. // continue;
  1397. // }
  1398. // [annotations addObject:annotation];
  1399. // }
  1400. // }
  1401. //
  1402. // for (PDFAnnotation *annotation in annotations) {
  1403. // [self.pdfView removeAnnotation:annotation];
  1404. // }
  1405. // }
  1406. }
  1407. @IBAction func noteFilterAction(_ sender: AnyObject?) {
  1408. let button = sender as? NSButton
  1409. let menu = NSMenu()
  1410. let filterViewController = KMNoteOutlineFilterViewController()
  1411. // let object = KMPopupMenuObject()
  1412. // menu.delegate = object
  1413. // object.enterControllerCallback = {
  1414. //
  1415. // }
  1416. //
  1417. var notes = NSMutableArray()
  1418. for section in self.annotationViewController.annotations {
  1419. if section.annotations?.count != 0 {
  1420. for item in section.annotations! {
  1421. notes.add(item.annotation!)
  1422. }
  1423. }
  1424. }
  1425. filterViewController.setNotesArray(notes)
  1426. filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
  1427. menu.cancelTracking()
  1428. if (isEmpty) {
  1429. self?.filterButtonLayer?.isHidden = true
  1430. } else {
  1431. self?.filterButtonLayer?.isHidden = false
  1432. }
  1433. //
  1434. // [blockSelf annotationSort:@[typeArr, colorArr, authorArr]];
  1435. }
  1436. filterViewController.cancelCallback = { isCancel in
  1437. if (isCancel) {
  1438. menu.cancelTracking()
  1439. }
  1440. }
  1441. let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
  1442. item.target = self
  1443. item.representedObject = filterViewController
  1444. item.view = filterViewController.view
  1445. menu.popUp(positioning: nil, at: CGPointMake(-130, 30), in: button)
  1446. }
  1447. @IBAction func outlineNormalSearchButtonAction(_ sender: NSButton) {
  1448. self.outlineSearchField.isHidden = false
  1449. self.outlineDoneButton.isHidden = false
  1450. self.outlineLabel.isHidden = true
  1451. self.outlineSearchButton.isHidden = true
  1452. self.outlineMoreButton.isHidden = true
  1453. self.outlineAddButton.isHidden = true
  1454. self.outlineSearchField.becomeFirstResponder()
  1455. }
  1456. @objc func outlineContextMenuItemClicked_AddEntry(_ sender: NSMenuItem) {
  1457. // NSMutableArray *PDFOutlineArray = [[NSMutableArray new] autorelease];
  1458. // NSIndexSet *rowSet = [self selectedRowIndexes] ;
  1459. //
  1460. // [rowSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1461. // [PDFOutlineArray addObject:[leftSideController.tocOutlineView itemAtRow:idx]];
  1462. // }];
  1463. //
  1464. // if (PDFOutlineArray.count == 0) {
  1465. // PDFOutline *lastPDFLine = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.numberOfRows - 1];
  1466. //
  1467. // PDFOutline *rootPDFOutline;
  1468. // if (lastPDFLine) {
  1469. // while (lastPDFLine.parent) {
  1470. // lastPDFLine = lastPDFLine.parent;
  1471. // }
  1472. // rootPDFOutline = lastPDFLine;
  1473. // } else {
  1474. // rootPDFOutline = self.pdfView.document.outlineRoot;
  1475. // if (!rootPDFOutline) {
  1476. // rootPDFOutline = [[[PDFOutline alloc] init] autorelease];
  1477. // [self.pdfView.document setOutlineRoot:rootPDFOutline];
  1478. // }
  1479. // }
  1480. //
  1481. // PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
  1482. // addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
  1483. // addOutLine.destination = self.pdfView.currentDestination;
  1484. // [self addoutlineWithParent:rootPDFOutline addOutline:addOutLine index:rootPDFOutline.numberOfChildren needExpand:NO];
  1485. //
  1486. // } else {
  1487. // PDFOutline *currentPDFline = PDFOutlineArray.lastObject;
  1488. // NSInteger currentIndex = currentPDFline.index;
  1489. // PDFOutline *parent;
  1490. // parent = currentPDFline.parent;
  1491. //
  1492. // PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
  1493. // addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
  1494. // addOutLine.destination = self.pdfView.currentDestination;
  1495. // [self addoutlineWithParent:parent addOutline:addOutLine index:currentIndex + 1 needExpand:NO];
  1496. // [self.leftSideController.tocOutlineView scrollRowToVisible:currentIndex + 1];
  1497. // [self.leftSideController.tocOutlineView deselectRow:currentIndex+1];
  1498. //
  1499. // }
  1500. }
  1501. @IBAction func toc_expandAllComments(_ sender: AnyObject?) {
  1502. if (self.tocType == .unfold) {
  1503. return
  1504. }
  1505. self.tocType = .unfold
  1506. self.tocOutlineView.reloadData()
  1507. self.tocOutlineView.expandItem(nil, expandChildren: true)
  1508. }
  1509. @IBAction func toc_foldAllComments(_ sender: AnyObject?) {
  1510. if (self.tocType == .fold) {
  1511. return
  1512. }
  1513. self.tocType = .fold
  1514. self.tocOutlineView.reloadData()
  1515. self.tocOutlineView.collapseItem(nil, collapseChildren: true)
  1516. }
  1517. @objc func leftSideEmptyAnnotationClick_DeleteOutline(_ sender: AnyObject?) {
  1518. KMPrint("leftSideEmptyAnnotationClick_DeleteOutline")
  1519. // NSAlert *alert = [[NSAlert alloc] init];
  1520. // [alert setAlertStyle:NSAlertStyleCritical];
  1521. // [alert setMessageText:@""];
  1522. // [alert setInformativeText:NSLocalizedString(@"This will permanently remove all outlines. Are you sure to continue?", nil)];
  1523. // [alert addButtonWithTitle:NSLocalizedString(@"Yes", nil)];
  1524. // [alert addButtonWithTitle:NSLocalizedString(@"No", nil)];
  1525. // NSModalResponse response = [alert runModal];
  1526. // if (response == NSAlertFirstButtonReturn) {
  1527. // PDFOutline * item = [[pdfView document] outlineRoot];
  1528. // [self removeAllOutline:item];
  1529. // }
  1530. }
  1531. @IBAction func thumbnailSizeScaling(_ sender: NSButton) {
  1532. let sud = UserDefaults.standard
  1533. let tag = sender.tag
  1534. if (tag == 0 || tag == 1) {
  1535. var scaling = sud.float(forKey: "KMThumbnailSizeScalingKey")
  1536. if (scaling <= 0) {
  1537. scaling = 1
  1538. }
  1539. if (tag == 0) { // thumbnail Zoom In
  1540. scaling += 0.1
  1541. } else if (tag == 1) { // thumbnail Zoom Out
  1542. scaling -= 0.1
  1543. }
  1544. sud.setValue(scaling, forKey: "KMThumbnailSizeScalingKey")
  1545. let selectRow = self.thumbnailTableView.selectedRow
  1546. self.thumbnailTableView.reloadData()
  1547. self.thumbnailTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  1548. } else if (tag == 2 || tag == 3) {
  1549. var scaling = sud.float(forKey: "KMSnapshotSizeScalingKey")
  1550. if (scaling <= 0) {
  1551. scaling = 1
  1552. }
  1553. if (tag == 2) { // snapshot Zoom In
  1554. scaling += 0.1
  1555. } else if (tag == 3) { // snapshot Zoom Out
  1556. scaling -= 0.1
  1557. }
  1558. sud.setValue(scaling, forKey: "KMSnapshotSizeScalingKey")
  1559. let selectRow = self.snapshotTableView.selectedRow
  1560. self.snapshotTableView.reloadData()
  1561. self.snapshotTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  1562. }
  1563. }
  1564. }
  1565. //MARK: NSTableViewDelegate,NSTableViewDataSource
  1566. //extension KMLeftSideViewController: NSTableViewDelegate,NSTableViewDataSource {
  1567. // func numberOfRows(in tableView: NSTableView) -> Int {
  1568. // return self.dataSource.count
  1569. // }
  1570. //
  1571. // func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1572. // let cell : KMLiftSideCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMLiftSideCellView"), owner: self) as! KMLiftSideCellView
  1573. // if row <= selectImage.count-1 {
  1574. // if self.dataSource[row] == self.type {
  1575. // cell.isSelect = true
  1576. // cell.mothedImage.image = NSImage(named: selectImage[row])
  1577. // cell.backgroundColor(NSColor.km_init(hex: "#DFE1E5"))
  1578. // } else {
  1579. // cell.isSelect = false
  1580. // cell.mothedImage.image = NSImage(named: norImage[row])
  1581. // cell.backgroundColor(NSColor.clear)
  1582. // }
  1583. // }
  1584. // cell.index = row
  1585. // cell.buttonClick = { [unowned self] index in
  1586. // if ((index < self.dataSource.count) && (index > -1)) {
  1587. //
  1588. // let isSearch = self.type.methodType == .Search
  1589. //
  1590. // var show = true
  1591. // if( self.type == self.dataSource[index]) {
  1592. // self.type = KMLeftMethodMode()
  1593. // show = false
  1594. // } else {
  1595. // self.type = self.dataSource[index]
  1596. // show = true
  1597. // }
  1598. //
  1599. // self.trackEvent(type: self.type.methodType)
  1600. //
  1601. // self.updateViewButtonState()
  1602. // self.delegate?.controlStateChange?(self,show:show)
  1603. //// self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  1604. //// self.leftTableview.reloadData()
  1605. //
  1606. // UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  1607. // UserDefaults.standard.synchronize()
  1608. //
  1609. // if (isSearch && show == false) {
  1610. // self.view.window?.makeFirstResponder(self)
  1611. // } else if (isSearch && self.type.methodType != .Search) { // 切换
  1612. // self.view.window?.makeFirstResponder(self)
  1613. // }
  1614. // }
  1615. // }
  1616. // return cell
  1617. // }
  1618. //
  1619. // func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1620. // return 48
  1621. // }
  1622. //
  1623. // func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  1624. // let rowView = KMCustomTableRowView()
  1625. // rowView.selectionColor = NSColor(calibratedRed: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1.0)
  1626. // rowView.color = NSColor.km_init(hex: "#F7F8FA")
  1627. // return rowView
  1628. // }
  1629. //
  1630. // func tableViewSelectionDidChange(_ notification: Notification) {
  1631. //
  1632. // }
  1633. //}
  1634. //extension KMLeftSideViewController: KMPDFViewPanelSetViewControllerDelegate {
  1635. // func controller(_ controller: KMPDFViewPanelSetViewController, dispayDidChange dispay: KMPDFDisplayType) {
  1636. // self.delegate?.controller?(self, dispayDidChange: dispay)
  1637. // }
  1638. //
  1639. // func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool) {
  1640. // self.listView?.displaysPageBreaks = pageBreaks
  1641. // self.listView?.layoutDocumentView()
  1642. // }
  1643. //
  1644. // func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType) {
  1645. //// if (rotateType == .clockwise) { /// 顺时针
  1646. //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1647. //// if page.rotation == 0 {
  1648. //// page.rotation = 90
  1649. //// } else if page.rotation == 90 {
  1650. //// page.rotation = 180
  1651. //// } else if page.rotation == 180 {
  1652. //// page.rotation = 270
  1653. //// } else if page.rotation == 270 {
  1654. //// page.rotation = 0
  1655. //// }
  1656. //// self.listView?.layoutDocumentView()
  1657. //// } else if (rotateType == .anticlockwise) { /// 逆时针
  1658. //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1659. //// if page.rotation == 0 {
  1660. //// page.rotation = 270
  1661. //// } else if page.rotation == 90 {
  1662. //// page.rotation = 0
  1663. //// } else if page.rotation == 180 {
  1664. //// page.rotation = 90
  1665. //// } else if page.rotation == 270 {
  1666. //// page.rotation = 180
  1667. //// }
  1668. //// self.listView?.layoutDocumentView()
  1669. //// }
  1670. ////
  1671. // self.delegate?.controller?(controller: self, rotateType: rotateType)
  1672. // }
  1673. //}
  1674. // MARK: -
  1675. // MARK: - 扩展
  1676. extension KMLeftSideViewController {
  1677. public func selectType(_ type: BotaType) {
  1678. // 更新 type
  1679. var show = true
  1680. if (self.type.methodType == .None) {
  1681. show = true
  1682. } else {
  1683. if (self.type.methodType == type) {
  1684. show = false
  1685. } else {
  1686. show = true
  1687. }
  1688. }
  1689. var index: Int = NSNotFound
  1690. switch type {
  1691. case .None:
  1692. index = NSNotFound
  1693. break
  1694. case .Thumbnail:
  1695. index = 0
  1696. break
  1697. case .Outline:
  1698. index = 1
  1699. break
  1700. case .BookMark:
  1701. index = 2
  1702. break
  1703. case .Annotation:
  1704. index = 3
  1705. break
  1706. case .Search:
  1707. index = 4
  1708. break
  1709. case .From:
  1710. index = 5
  1711. break
  1712. case .Signature:
  1713. index = 6
  1714. break
  1715. }
  1716. self.type = self.getMethodMode(show ? type : .None)
  1717. // 更新按钮状态
  1718. // self.updateViewButtonState()
  1719. // 将事件传递出去
  1720. self.delegate?.controlStateChange?(self,show:show)
  1721. if (index != NSNotFound) {
  1722. // self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  1723. // 记录当前选中
  1724. UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  1725. UserDefaults.standard.synchronize()
  1726. }
  1727. // self.leftTableview.reloadData()
  1728. }
  1729. private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
  1730. let mode = KMLeftMethodMode()
  1731. mode.methodType = type
  1732. switch type {
  1733. case .None:
  1734. mode.methodName = ""
  1735. break
  1736. case .Thumbnail:
  1737. mode.methodName = thumbnailMethodKey
  1738. break
  1739. case .Outline:
  1740. mode.methodName = outlineMethodKey
  1741. break
  1742. case .BookMark:
  1743. mode.methodName = bookMarkMethodKey
  1744. break
  1745. case .Annotation:
  1746. mode.methodName = anntationMethodKey
  1747. break
  1748. case .Search:
  1749. mode.methodName = searchMethodKey
  1750. break
  1751. case .From:
  1752. mode.methodName = formMethodKey
  1753. break
  1754. case .Signature:
  1755. mode.methodName = signatureMethodKey
  1756. break
  1757. }
  1758. return mode
  1759. }
  1760. }
  1761. //MARK: Cache
  1762. extension KMLeftSideViewController {
  1763. func clearAnnotationFilterData() {
  1764. if let _key = self.listView?.document?.documentURL?.path {
  1765. let userDefaults = UserDefaults.standard
  1766. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1767. userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + _key)
  1768. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1769. userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + _key)
  1770. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1771. userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + _key)
  1772. userDefaults.synchronize()
  1773. }
  1774. }
  1775. func clearNotification() {
  1776. self.bookViewController.removeNotification()
  1777. self.annotationViewController.removeNotification()
  1778. }
  1779. }
  1780. // MARK: - Analytics (埋点)
  1781. extension KMLeftSideViewController {
  1782. func trackEvent(type: BotaType) -> Void {
  1783. if (type == .Thumbnail) {
  1784. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Thumbnail", parameters: [
  1785. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1786. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1787. } else if (type == .Outline) {
  1788. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Outline", parameters: [
  1789. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1790. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1791. } else if (type == .BookMark) {
  1792. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_BookMark", parameters: [
  1793. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1794. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1795. } else if (type == .Annotation) {
  1796. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Annotation", parameters: [
  1797. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1798. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1799. } else if (type == .Search) {
  1800. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Search", parameters: [
  1801. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1802. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1803. }
  1804. }
  1805. }
  1806. // MARK: - Private Methods
  1807. extension KMLeftSideViewController {
  1808. @objc private func _themeChanged(_ notification: NSNotification) {
  1809. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  1810. self._updateViewColor()
  1811. }
  1812. }
  1813. private func _updateViewColor() {
  1814. if(KMAppearance.isDarkMode()){
  1815. self.leftListView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1816. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1817. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1818. self.noteView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1819. self.outlineView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1820. self.view.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1821. self.thumbnailTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1822. self.groupedFindTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1823. self.tocOutlineView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1824. self.findTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1825. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1826. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1827. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1828. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1829. self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1830. self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1831. self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1832. } else {
  1833. self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1834. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1835. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1836. self.noteView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1837. self.outlineView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1838. self.view.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1839. self.thumbnailTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1840. self.groupedFindTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1841. self.tocOutlineView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1842. self.findTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1843. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1844. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1845. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1846. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1847. self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1848. self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1849. self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1850. }
  1851. }
  1852. private func _hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {
  1853. // if ([outline.label rangeOfString:searchString options:self.outlineIgnoreCaseFlag?NSCaseInsensitiveSearch:0].location != NSNotFound){
  1854. // return YES;
  1855. // } else {
  1856. // BOOL subHas = NO;
  1857. // for (NSUInteger i = 0; i < outline.numberOfChildren; i ++) {
  1858. // PDFOutline *subOutline = [outline childAtIndex:i];
  1859. // subHas = [self hasContainString:searchString rootOutline:subOutline];
  1860. // if (subHas) {
  1861. // break;
  1862. // }
  1863. // }
  1864. // return subHas;
  1865. // }
  1866. return false
  1867. }
  1868. }
  1869. // MARK: - KMThumbnailTableViewDelegate, NSTableViewDataSource
  1870. extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
  1871. func numberOfRows(in tableView: NSTableView) -> Int {
  1872. if tableView.isEqual(to: self.thumbnailTableView) {
  1873. return self.thumbnails.count
  1874. } else if tableView.isEqual(to: self.findTableView) {
  1875. return self.searchResults.count
  1876. } else if tableView.isEqual(to: self.groupedFindTableView) {
  1877. // for result in self.searchResults {
  1878. // }
  1879. KMPrint(self.searchResults)
  1880. }
  1881. return 0
  1882. }
  1883. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1884. if tableView.isEqual(to: self.thumbnailTableView) {
  1885. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMThumbnailTableviewCell"), owner: self) as! KMThumbnailTableviewCell
  1886. let thumbnail = self.thumbnails[row]
  1887. cell.pageNumLabel.stringValue = thumbnail.label
  1888. // cell.thumImage.image = thumbnail.image
  1889. cell.pageView.page = self.listView.document.page(at: UInt(row))
  1890. if let _image = thumbnail.image {
  1891. let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
  1892. let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
  1893. if (_image.size.height > _image.size.width) {
  1894. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  1895. // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
  1896. // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  1897. } else {
  1898. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  1899. // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
  1900. // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  1901. }
  1902. }
  1903. if (self.isDisplayPageSize) {
  1904. cell.sizeLabel.isHidden = false
  1905. //获取Page的真实尺寸
  1906. let page = self.listView.document.page(at: UInt(row))
  1907. let rect = page?.bounds(for: .cropBox) ?? .zero
  1908. let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
  1909. let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
  1910. if let data = page?.rotation, data == 90 || data == 270 {
  1911. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
  1912. } else {
  1913. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
  1914. }
  1915. } else {
  1916. cell.sizeLabel.isHidden = true
  1917. }
  1918. cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
  1919. if(self.thumbnailTableView.selectedRowIndexes.contains(row)) {
  1920. cell.isSelectCell = true
  1921. } else {
  1922. cell.isSelectCell = false
  1923. }
  1924. return cell
  1925. } else if (tableView.isEqual(to: self.findTableView)) {
  1926. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMFindTableviewCell"), owner: self) as! KMFindTableviewCell
  1927. let selection = searchResults[row]
  1928. if let data = tableColumn?.identifier.rawValue, data == "results" {
  1929. cell.resultLabel.attributedStringValue = selection.selection.attributedString()
  1930. cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
  1931. } else if let data = tableColumn?.identifier.rawValue, data == "page" {
  1932. cell.resultLabel.stringValue = selection.selection.pages().first?.label ?? ""
  1933. cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
  1934. }
  1935. return cell
  1936. } else if tableView.isEqual(to: self.snapshotTableView) {
  1937. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMSnapshotTableViewCell"), owner: self) as! KMSnapshotTableViewCell
  1938. // SKSnapshotWindowController *snapshot = snapshots[row];
  1939. // cell.snapshotImage.image = snapshot.thumbnail;
  1940. // cell.snapshotLabel.stringValue = snapshot.pageLabel;
  1941. // if (snapshot.hasWindow) {
  1942. // cell.snapshotImageView.hidden = NO;
  1943. // } else {
  1944. // cell.snapshotImageView.hidden = YES;
  1945. // }
  1946. // if(selectCellList.count > 0 && [selectCellList.firstObject integerValue]< 0 && (NSUInteger)row == self.snapshots.count - 1) {
  1947. // cell.isSelectCell = YES;
  1948. // } else {
  1949. // cell.isSelectCell = NO;
  1950. // }
  1951. // for (NSUInteger i = 0; i < selectCellList.count; i ++) {
  1952. // NSInteger selectCell = [selectCellList[i] integerValue];
  1953. // if (selectCell == row) {
  1954. // cell.isSelectCell = YES;
  1955. // }
  1956. // }
  1957. // if (row == tableView.selectedRow) {
  1958. // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowSel]];
  1959. // } else {
  1960. // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowNor]];
  1961. // }
  1962. return cell
  1963. }
  1964. return nil
  1965. }
  1966. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1967. if tableView.isEqual(to: self.thumbnailTableView) {
  1968. let scaling = UserDefaults.standard.float(forKey: "KMThumbnailSizeScalingKey")
  1969. let thumbnailSize = self.thumbnails[row].size
  1970. let newScaling: CGFloat = scaling.cgFloat + 0.1
  1971. let newThumbnailHeight = thumbnailSize.width * newScaling
  1972. if (newThumbnailHeight > MIN_SIDE_PANE_WIDTH) {
  1973. self.thumbnailZoomOutButton.isEnabled = false
  1974. } else {
  1975. self.thumbnailZoomOutButton.isEnabled = true
  1976. }
  1977. if ((scaling - 0.1) < 0.3) {
  1978. self.thumbnailZoomInButton.isEnabled = false
  1979. } else {
  1980. self.thumbnailZoomInButton.isEnabled = true
  1981. }
  1982. var labelHeight = 0.0
  1983. if (self.isDisplayPageSize) {
  1984. labelHeight = 56.0
  1985. } else {
  1986. labelHeight = 41.5
  1987. }
  1988. let cellHeight = thumbnailSize.height + labelHeight
  1989. var thumbSize: NSSize = .zero
  1990. if (scaling != nil && scaling > 0) {
  1991. thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  1992. } else {
  1993. thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
  1994. }
  1995. return thumbSize.height
  1996. // NSSize cellSize = NSMakeSize([[tv tableColumnWithIdentifier:IMAGE_COLUMNID] width], fmin(thumbSize.height, roundedThumbnailSize));
  1997. // if (thumbSize.height < [tv rowHeight])
  1998. // return [tv rowHeight];
  1999. // else if (thumbSize.width / thumbSize.height < cellSize.width / cellSize.height)
  2000. // return cellSize.height;
  2001. // else
  2002. // return fmax([tv rowHeight], fmin(cellSize.width, thumbSize.width) * thumbSize.height / thumbSize.width);
  2003. } else if tableView.isEqual(to: self.snapshotTableView) {
  2004. let scaling = UserDefaults.standard.float(forKey: "KMSnapshotSizeScalingKey")
  2005. // NSSize snapshotSize = [[[[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row] thumbnail] size];
  2006. let snapshotSize = CGSizeMake(120, 63)
  2007. var newScaling = scaling + 0.1
  2008. let newSnapshotHeight = snapshotSize.width * newScaling.cgFloat;
  2009. if (newSnapshotHeight > MIN_SIDE_PANE_WIDTH) {
  2010. self.snapshotNormalZoomInButton.isEnabled = false
  2011. } else {
  2012. self.snapshotNormalZoomInButton.isEnabled = true
  2013. }
  2014. if ((scaling - 0.1) < 0.3 || (newSnapshotHeight < 150.0)) {
  2015. self.snapshotNormalZoomOutButton.isEnabled = false
  2016. } else {
  2017. self.snapshotNormalZoomOutButton.isEnabled = true
  2018. }
  2019. let cellHeight = snapshotSize.height + 24.0
  2020. var thumbSize: NSSize = .zero
  2021. if (scaling > 0) {
  2022. thumbSize = NSMakeSize(snapshotSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  2023. } else {
  2024. thumbSize = NSMakeSize(snapshotSize.width, cellHeight)
  2025. }
  2026. return thumbSize.height
  2027. } else if (tableView.isEqual(to: self.findTableView)) {
  2028. return 40.0
  2029. }
  2030. return tableView.rowHeight
  2031. }
  2032. func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  2033. if (tableView.isEqual(to: self.findTableView) || tableView.isEqual(to: self.groupedFindTableView)) {
  2034. let rowView = KMCustomTableRowView()
  2035. return rowView
  2036. }
  2037. return nil
  2038. }
  2039. func tableViewSelectionIsChanging(_ notification: Notification) {
  2040. KMPrint(self.thumbnailTableView.selectedRowIndexes)
  2041. }
  2042. func tableViewSelectionDidChange(_ notification: Notification) {
  2043. // if ([[aNotification object] isEqual:leftSideController.findTableView] || [[aNotification object] isEqual:leftSideController.groupedFindTableView]) {
  2044. // [self updateFindResultHighlightsForDirection:NSDirectSelection];
  2045. //
  2046. // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  2047. // [self hideLeftSideWindow];
  2048. // } else
  2049. if self.thumbnailTableView.isEqual(to: notification.object) {
  2050. // if (mwcFlags.updatingThumbnailSelection == 0) {
  2051. let row = self.thumbnailTableView.selectedRow
  2052. let curPage = self.listView.document.index(for: self.listView.currentPage())
  2053. if (row != -1 && row != curPage) {
  2054. // [pdfView goToPage:[[pdfView document] pageAtIndex:row]];
  2055. self.listView.go(toPageIndex: row, animated: true)
  2056. }
  2057. // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  2058. // [self hideLeftSideWindow];
  2059. // thumbnailSelectCount = row;
  2060. // var rowIndexSet = IndexSet()
  2061. // for i in 0 ..< self.thumbnailTableView.numberOfRows {
  2062. // rowIndexSet.insert(i)
  2063. // }
  2064. // self.thumbnailTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: IndexSet(integer: 0))
  2065. // }
  2066. let view = self.thumbnailTableView.view(atColumn: 0, row: self.preThumbnailRow, makeIfNecessary: false) as? KMThumbnailTableviewCell
  2067. view?.isSelectCell = false
  2068. let view2 = self.thumbnailTableView.view(atColumn: 0, row: row, makeIfNecessary: false) as? KMThumbnailTableviewCell
  2069. view2?.isSelectCell = true
  2070. self.preThumbnailRow = row
  2071. }
  2072. // else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
  2073. // NSInteger row = [rightSideController.snapshotTableView selectedRow];
  2074. // [selectCellList removeAllObjects];
  2075. // [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
  2076. // if (row != -1) {
  2077. // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
  2078. // if ([[controller window] isVisible])
  2079. // [[controller window] orderFront:self];
  2080. // }
  2081. // NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2082. // for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
  2083. // [rowIndexSet addIndex:i];
  2084. // }
  2085. // NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2086. // [columnIndexSet addIndex:0];
  2087. // [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
  2088. //
  2089. // }
  2090. }
  2091. /*
  2092. //- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  2093. // return nil;
  2094. //}
  2095. - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
  2096. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2097. NSUInteger idx = [rowIndexes firstIndex];
  2098. if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
  2099. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2100. NSString *fileExt = nil;
  2101. NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  2102. if ([[pdfView document] allowsPrinting]) {
  2103. NSData *pdfData = [page dataRepresentation];
  2104. fileExt = @"pdf";
  2105. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePDF, NSPasteboardTypeTIFF,NSFilenamesPboardType, NSFilesPromisePboardType, KPDFThumbnailLocalForDraggedTypes,KPDFThumbnailDoucumentURLForDraggedTypes,nil] owner:self];
  2106. [pboard setData:pdfData forType:NSPasteboardTypePDF];
  2107. NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
  2108. [pboard setData:zNSIndexSetData forType:KPDFThumbnailLocalForDraggedTypes];
  2109. NSData *documentURL = [NSKeyedArchiver archivedDataWithRootObject:[[pdfView document].documentURL absoluteString]];
  2110. NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
  2111. __block NSMutableString *pagesName = nil;
  2112. if (rowIndexes.count > 1) {
  2113. pagesName = [NSMutableString stringWithString:@" pages"];
  2114. } else {
  2115. pagesName = [NSMutableString stringWithString:@" page"];
  2116. }
  2117. NSString * tFileName = [NSString stringWithFormat:@"%@ %@",pagesName,[self fileNameWithSelectedPages:rowIndexes]];
  2118. PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
  2119. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2120. PDFPage *copyPage = [[pdfView.document pageAtIndex:idx] copy];
  2121. [pdf insertPage:copyPage atIndex:pdf.pageCount];
  2122. [copyPage release];
  2123. }];
  2124. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2125. NSString *cachesDir = [paths objectAtIndex:0];
  2126. docmentName = [NSString stringWithFormat:@"%@%@",docmentName,tFileName];
  2127. if (docmentName.length > 50) {
  2128. [docmentName substringWithRange:NSMakeRange(0, 50)];
  2129. }
  2130. cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
  2131. BOOL success = [pdf writeToFile:cachesDir];
  2132. if (success) {
  2133. [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
  2134. }else{
  2135. [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
  2136. }
  2137. [pboard setData:documentURL forType:KPDFThumbnailDoucumentURLForDraggedTypes];
  2138. } else {
  2139. fileExt = @"tiff";
  2140. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
  2141. }
  2142. [pboard setData:tiffData forType:NSPasteboardTypeTIFF];
  2143. [pboard setPropertyList:[NSArray arrayWithObject:fileExt] forType:NSFilesPromisePboardType];
  2144. return YES;
  2145. }
  2146. } else if ([tv isEqual:rightSideController.snapshotTableView]) {
  2147. NSUInteger idx = [rowIndexes firstIndex];
  2148. if (idx != NSNotFound) {
  2149. SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
  2150. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
  2151. [pboard setData:[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] forType:NSPasteboardTypeTIFF];
  2152. [pboard setPropertyList:[NSArray arrayWithObject:@"tiff"] forType:NSFilesPromisePboardType];
  2153. return YES;
  2154. }
  2155. }
  2156. return NO;
  2157. }
  2158. - (NSArray *)tableView:(NSTableView *)tv namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2159. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2160. __block NSMutableArray *fileURLArray = [NSMutableArray array];
  2161. if (rowIndexes.count > 1) {
  2162. NSString *docmentName = @"";
  2163. NSString * tFileName = [NSString stringWithFormat:@"%@",[self fileNameWithSelectedPages:rowIndexes]];
  2164. PDFDocument *pdf = [[[PDFDocument alloc] init] autorelease];
  2165. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2166. if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
  2167. PDFPage *copyPage = [[[pdfView document] pageAtIndex:idx] copy];
  2168. [pdf insertPage:copyPage atIndex:pdf.pageCount];
  2169. [copyPage release];
  2170. }
  2171. }];
  2172. NSURL *fileURL = [[[dropDestination URLByAppendingPathComponent:tFileName] URLByAppendingPathExtension:@"pdf"] uniqueFileURL];
  2173. docmentName = fileURL.path;
  2174. BOOL success = [pdf writeToFile:docmentName];
  2175. if(success) {
  2176. [fileURLArray addObject:[fileURL lastPathComponent]];
  2177. }
  2178. } else {
  2179. PDFPage *page = [[pdfView document] pageAtIndex:rowIndexes.firstIndex];
  2180. NSURL *fileURL = [dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
  2181. NSString *pathExt = nil;
  2182. NSData *data = nil;
  2183. if ([[pdfView document] allowsPrinting]) {
  2184. pathExt = @"pdf";
  2185. data = [page dataRepresentation];
  2186. } else {
  2187. pathExt = @"tiff";
  2188. data = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  2189. }
  2190. fileURL = [[fileURL URLByAppendingPathExtension:pathExt] uniqueFileURL];
  2191. if ([data writeToURL:fileURL atomically:YES]) {
  2192. [fileURLArray addObject:[fileURL lastPathComponent]];
  2193. }
  2194. }
  2195. return fileURLArray;
  2196. } else if ([tv isEqual:rightSideController.snapshotTableView]) {
  2197. NSUInteger idx = [rowIndexes firstIndex];
  2198. if (idx != NSNotFound) {
  2199. SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
  2200. PDFPage *page = [[pdfView document] pageAtIndex:[snapshot pageIndex]];
  2201. NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]] URLByAppendingPathExtension:@"tiff"];
  2202. fileURL = [fileURL uniqueFileURL];
  2203. if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] writeToURL:fileURL atomically:YES])
  2204. return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
  2205. }
  2206. }
  2207. return [NSArray array];
  2208. }
  2209. - (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors {
  2210. if ([tv isEqual:leftSideController.groupedFindTableView]) {
  2211. [leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
  2212. }
  2213. }
  2214. #pragma mark NSTableView delegate protocol
  2215. - (BOOL)tableView:(NSTableView *)tv commandSelectRow:(NSInteger)row {
  2216. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2217. // NSRect rect = [[[pdfView document] pageAtIndex:row] boundsForBox:kPDFDisplayBoxCropBox];
  2218. //
  2219. // rect.origin.y = NSMidY(rect) - 0.5 * SNAPSHOT_HEIGHT;
  2220. // rect.size.height = SNAPSHOT_HEIGHT;
  2221. // [self showSnapshotAtPageNumber:row forRect:rect scaleFactor:[pdfView scaleFactor] autoFits:NO];
  2222. KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
  2223. thumbailTabCell.isSelectCell = YES;
  2224. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2225. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2226. [rowIndexSet addIndex:idx];
  2227. }];
  2228. [rowIndexSet addIndex:row];
  2229. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  2230. return YES;
  2231. }
  2232. return NO;
  2233. }
  2234. - (BOOL)tableView:(NSTableView *)tv shiftSelectRow:(NSInteger)row {
  2235. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2236. if(leftSideController.thumbnailTableView.selectedRowIndexes.count == 0) {
  2237. KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
  2238. thumbailTabCell.isSelectCell = YES;
  2239. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] initWithIndex:row] autorelease];
  2240. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  2241. return YES;
  2242. } else if (leftSideController.thumbnailTableView.selectedRowIndexes.count == 1 && leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex == (NSUInteger)row) {
  2243. return NO;
  2244. } else {
  2245. __block NSInteger fristIndex = leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex;
  2246. __block NSInteger lastIndex = leftSideController.thumbnailTableView.selectedRowIndexes.lastIndex;
  2247. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2248. if(idx < (NSUInteger)fristIndex) {
  2249. fristIndex = idx;
  2250. }
  2251. if(idx > (NSUInteger)lastIndex) {
  2252. lastIndex = idx;
  2253. }
  2254. }];
  2255. if(row < fristIndex) {
  2256. fristIndex = row;
  2257. } else if (row > lastIndex) {
  2258. lastIndex = row;
  2259. }
  2260. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2261. for (NSInteger i = fristIndex; i<=lastIndex;i++) {
  2262. [rowIndexSet addIndex:i];
  2263. }
  2264. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  2265. return YES;
  2266. }
  2267. }
  2268. return NO;
  2269. }
  2270. - (void)tableViewColumnDidResize:(NSNotification *)aNotification {
  2271. if ([[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:IMAGE_COLUMNID]) {
  2272. if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
  2273. [leftSideController.thumbnailTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [leftSideController.thumbnailTableView numberOfRows])]];
  2274. } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
  2275. [rightSideController.snapshotTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.snapshotTableView numberOfRows])]];
  2276. }
  2277. }
  2278. }
  2279. - (void)tableView:(NSTableView *)tv deleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2280. if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
  2281. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2282. return;
  2283. }
  2284. if ([tv isEqual:rightSideController.snapshotTableView]) {
  2285. NSArray *controllers = [[rightSideController.snapshotArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
  2286. [controllers makeObjectsPerformSelector:@selector(close)];
  2287. } else if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2288. [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2289. if (idx >= [[pdfView document] pageCount]) {
  2290. return;
  2291. }
  2292. for (PDFAnnotation *item in [[[pdfView document] pageAtIndex:idx] notes]){
  2293. [pdfView removeAnnotation:item];
  2294. }
  2295. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2296. [[[[self document] undoManager] prepareWithInvocationTarget:self] insertPage:page pageAtIndex:idx];
  2297. [[pdfView document] removePageAtIndex:idx];
  2298. }];
  2299. [pdfView layoutDocumentView];
  2300. [pageLabels setArray:[[pdfView document] pageLabels]];
  2301. [self resetThumbnails];
  2302. NSUInteger idx = [rowIndexes firstIndex];
  2303. NSInteger index = MIN(idx, [[pdfView document] pageCount]-1);
  2304. [pdfView goToPage:[[pdfView document] pageAtIndex:index]];
  2305. }
  2306. }
  2307. - (void)insertPage:(PDFPage*)page pageAtIndex:(NSInteger)index {
  2308. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  2309. [[pdfView document] insertPage:page atIndex:index];
  2310. [pdfView layoutDocumentView];
  2311. [pageLabels setArray:[[pdfView document] pageLabels]];
  2312. [self resetThumbnails];
  2313. NSInteger pageIndex = MIN((NSUInteger)index, [[pdfView document] pageCount]-1);
  2314. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  2315. }
  2316. - (BOOL)tableView:(NSTableView *)tv canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2317. if ([tv isEqual:rightSideController.snapshotTableView]) {
  2318. return [rowIndexes count] > 0;
  2319. } else if ([tv isEqual:leftSideController.thumbnailTableView]){
  2320. if (self.pdfDocument.pageCount <= 1) {
  2321. return NO;
  2322. }
  2323. return YES;
  2324. }
  2325. return NO;
  2326. }
  2327. - (void)tableView:(NSTableView *)tv copyRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2328. if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  2329. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2330. return;
  2331. }
  2332. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2333. self.copysPages = [NSMutableArray array];
  2334. if ([[pdfView document] isLocked] == NO) {
  2335. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2336. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2337. [self.copysPages addObject:page];
  2338. }];
  2339. // NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  2340. // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  2341. // NSPasteboardItem *pboardItem = [[[NSPasteboardItem alloc] init] autorelease];
  2342. // if ([[pdfView document] allowsPrinting])
  2343. // [pboardItem setData:[page dataRepresentation] forType:NSPasteboardTypePDF];
  2344. // [pboardItem setData:tiffData forType:NSPasteboardTypeTIFF];
  2345. // [pboard clearContents];
  2346. // [pboard writeObjects:[NSArray arrayWithObjects:pboardItem, nil]];
  2347. }
  2348. } else if ([tv isEqual:leftSideController.findTableView]) {
  2349. NSMutableString *string = [NSMutableString string];
  2350. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  2351. PDFSelection *match = [searchResults objectAtIndex:idx];
  2352. [string appendString:@"* "];
  2353. [string appendFormat:NSLocalizedString(@"Page %@", @""), [match firstPageLabel]];
  2354. [string appendFormat:@": %@\n", [[match contextString] string]];
  2355. }];
  2356. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  2357. [pboard clearContents];
  2358. [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
  2359. } else if ([tv isEqual:leftSideController.groupedFindTableView]) {
  2360. NSMutableString *string = [NSMutableString string];
  2361. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  2362. SKGroupedSearchResult *result = [groupedSearchResults objectAtIndex:idx];
  2363. NSArray *matches = [result matches];
  2364. [string appendString:@"* "];
  2365. [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result page] displayLabel]];
  2366. [string appendString:@": "];
  2367. [string appendFormat:NSLocalizedString(@"%ld Results", @""), (long)[matches count]];
  2368. [string appendFormat:@":\n\t%@\n", [[matches valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
  2369. }];
  2370. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  2371. [pboard clearContents];
  2372. [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
  2373. }
  2374. }
  2375. - (BOOL)tableView:(NSTableView *)tv canCopyRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2376. if ([tv isEqual:leftSideController.thumbnailTableView] || [tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView]) {
  2377. return [rowIndexes count] > 0;
  2378. }
  2379. return NO;
  2380. }
  2381. - (void)tableView:(NSTableView *)tv cutRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2382. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2383. self.copysPages = [NSMutableArray array];
  2384. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2385. if (idx != NSNotFound) {
  2386. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2387. [self.copysPages addObject:page];;
  2388. }
  2389. }];
  2390. [self tableView:tv deleteRowsWithIndexes:rowIndexes];
  2391. }
  2392. }
  2393. - (void)tableView:(NSTableView *)tv rotateRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2394. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2395. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2396. if (idx != NSNotFound) {
  2397. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2398. [[[[self document] undoManager] prepareWithInvocationTarget:self] rotatePage:page pageAtIndex:idx];
  2399. if (page.rotation == 0) {
  2400. [page setRotation:90];
  2401. } else if (page.rotation == 90){
  2402. [page setRotation:180];
  2403. } else if (page.rotation == 180){
  2404. [page setRotation:270];
  2405. } else if (page.rotation == 270){
  2406. [page setRotation:0];
  2407. }
  2408. [pdfView layoutDocumentView];
  2409. [self resetThumbnails];
  2410. NSInteger pageIndex = MIN(idx, [[pdfView document] pageCount]-1);
  2411. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  2412. }
  2413. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexes byExtendingSelection:YES];
  2414. }];
  2415. }
  2416. }
  2417. - (void)rotatePage:(PDFPage*)page pageAtIndex:(NSInteger)index {
  2418. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView rotateRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  2419. if (page.rotation == 0) {
  2420. [page setRotation:270];
  2421. } else if (page.rotation == 90){
  2422. [page setRotation:0];
  2423. } else if (page.rotation == 180){
  2424. [page setRotation:90];
  2425. } else if (page.rotation == 270){
  2426. [page setRotation:180];
  2427. }
  2428. [pdfView layoutDocumentView];
  2429. [self resetThumbnails];
  2430. }
  2431. - (void)tableView:(NSTableView *)tv shareRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2432. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2433. NSUInteger idx = [rowIndexes firstIndex];
  2434. if (idx != NSNotFound) {
  2435. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2436. NSString *fileName = [[[pdfView document] documentURL] lastPathComponent];
  2437. NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  2438. NSString *filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Untitled"]];
  2439. filePath = [filePath stringByAppendingPathExtension:[fileName pathExtension]];
  2440. [self fileWithPage:page atPath:filePath];
  2441. if (rint(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
  2442. [KMMailHelper sendFileWithPaths:[NSArray arrayWithObject:filePath]];
  2443. } else {
  2444. NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
  2445. [service performWithItems:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]]];
  2446. }
  2447. }
  2448. }
  2449. }
  2450. - (void)tableView:(NSTableView *)tv extractRowsWithIndexes:(NSIndexSet *)rowIndexes {
  2451. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2452. NSMutableArray *pages = [NSMutableArray array];
  2453. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2454. if (idx < self.pdfView.document.pageCount) {
  2455. [pages addObject:[self.pdfView.document pageAtIndex:idx]];
  2456. }
  2457. }];
  2458. NSString * fileName = [self.pdfView.document getFileNameAccordingSelctPages:pages];
  2459. KMSavePanelAccessoryController *saveAccessCtr = [[KMSavePanelAccessoryController alloc] init];
  2460. NSSavePanel * outputSavePanel = [NSSavePanel savePanel];
  2461. [outputSavePanel setAllowedFileTypes:[NSArray arrayWithObject:@"pdf"]];
  2462. outputSavePanel.accessoryView = saveAccessCtr.view;
  2463. [outputSavePanel setNameFieldStringValue:fileName];
  2464. [outputSavePanel beginSheetModalForWindow:[self window]completionHandler:^(NSInteger result) {
  2465. if (result == NSModalResponseOK) {
  2466. [saveAccessCtr retain];
  2467. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2468. KMProgressWindowController * vc = [[[KMProgressWindowController alloc] init] autorelease];
  2469. // [NSApp beginSheet:[vc window]
  2470. // modalForWindow:self.window
  2471. // modalDelegate:nil
  2472. // didEndSelector:nil
  2473. // contextInfo:NULL];
  2474. [self.window beginSheet:[vc window] completionHandler:^(NSModalResponse returnCode) {
  2475. }];
  2476. NSString *saveFilePath = [[outputSavePanel URL] path];
  2477. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  2478. PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
  2479. BOOL success = [pdf extractAsOneDocumentWithPages:pages savePath:saveFilePath];
  2480. dispatch_async(dispatch_get_main_queue(), ^{
  2481. if (success) {
  2482. if (saveAccessCtr.openAutomaticButton.state == NSControlStateValueOn) {
  2483. [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:[outputSavePanel URL] display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
  2484. }];
  2485. } else {
  2486. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  2487. NSURL *url = [NSURL fileURLWithPath:saveFilePath];
  2488. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  2489. }
  2490. }
  2491. [NSApp endSheet:vc.window];
  2492. [vc close];
  2493. [saveAccessCtr release];
  2494. });
  2495. });
  2496. });
  2497. }
  2498. [saveAccessCtr release];
  2499. }];
  2500. }
  2501. }
  2502. - (void)fileWithPage:(PDFPage *)page atPath:(NSString *)filePath {
  2503. NSData *data = [page dataRepresentation];
  2504. PDFDocument *document = [[PDFDocument alloc] initWithData:data];
  2505. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  2506. BOOL success = [document writeToURL:[NSURL fileURLWithPath:filePath]];
  2507. if (success) {
  2508. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  2509. NSURL *url = [NSURL fileURLWithPath:filePath];
  2510. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  2511. }
  2512. [document release];
  2513. }
  2514. - (BOOL)tableView:(NSTableView *)aTableView canPasteFromPasteboard:(NSPasteboard *)pboard
  2515. {
  2516. if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
  2517. if(self.copysPages.count > 0){
  2518. return YES;
  2519. }
  2520. }
  2521. return NO;
  2522. }
  2523. - (void)tableView:(NSTableView *)aTableView pasteFromPasteboard:(NSPasteboard *)pboard
  2524. {
  2525. if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  2526. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2527. return;
  2528. }
  2529. if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
  2530. if (self.copysPages.count > 0) {
  2531. NSUInteger index = [[pdfView document] indexForPage:[pdfView currentPage]] + 1;
  2532. if (index == NSNotFound) {
  2533. return;
  2534. }
  2535. [self.copysPages enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(PDFPage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  2536. PDFPage *page = [obj copy];
  2537. [[pdfView document] insertPage:page atIndex:index];
  2538. [page release];
  2539. [pdfView layoutDocumentView];
  2540. [pageLabels setArray:[[pdfView document] pageLabels]];
  2541. [self resetThumbnails];
  2542. NSInteger pageIndex = MIN(index, [[pdfView document] pageCount]-1);
  2543. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  2544. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  2545. }];
  2546. }
  2547. }
  2548. }
  2549. - (NSUInteger)tableView:(NSTableView *)tv highlightLevelForRow:(NSInteger)row {
  2550. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2551. NSUInteger i, iMax = [lastViewedPages count];
  2552. for (i = 0; i < iMax; i++) {
  2553. if (row == (NSInteger)[lastViewedPages pointerAtIndex:i])
  2554. return i;
  2555. }
  2556. }
  2557. return NSNotFound;
  2558. }
  2559. - (void)tableViewMoveLeft:(NSTableView *)tv {
  2560. if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
  2561. [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
  2562. }
  2563. }
  2564. - (void)tableViewMoveRight:(NSTableView *)tv {
  2565. if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
  2566. [self updateFindResultHighlightsForDirection:NSSelectingNext];
  2567. }
  2568. }
  2569. - (id <SKImageToolTipContext>)tableView:(NSTableView *)tv imageContextForRow:(NSInteger)row {
  2570. if ([tv isEqual:leftSideController.findTableView])
  2571. return [[[leftSideController.findArrayController arrangedObjects] objectAtIndex:row] destination];
  2572. else if ([tv isEqual:leftSideController.groupedFindTableView])
  2573. return [[[[[leftSideController.groupedFindArrayController arrangedObjects] objectAtIndex:row] matches] objectAtIndex:0] destination];
  2574. return nil;
  2575. }
  2576. - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
  2577. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2578. return pageLabels;
  2579. }
  2580. return nil;
  2581. }
  2582. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
  2583. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2584. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  2585. }
  2586. }
  2587. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
  2588. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2589. if (searchString.length > 0)
  2590. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  2591. else
  2592. [self updateLeftStatus];
  2593. }
  2594. }
  2595. #pragma mark dragging
  2596. - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
  2597. {
  2598. if (dropOperation == NSTableViewDropOn || ![tableView isEqual:leftSideController.thumbnailTableView]) {
  2599. return NSDragOperationNone;
  2600. }
  2601. NSPasteboard *pboard = [info draggingPasteboard];
  2602. if ([pboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
  2603. return NSDragOperationMove;
  2604. } else if ([pboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]){
  2605. NSArray *fileNames = [pboard propertyListForType:NSFilenamesPboardType];
  2606. if (fileNames.count == 1) {
  2607. NSString *path = fileNames.firstObject;
  2608. NSString *pathExtension = [path.pathExtension lowercaseString];
  2609. if ([pathExtension isEqualToString:@"pdf"] ||
  2610. [[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
  2611. return NSDragOperationMove;
  2612. }
  2613. } else {
  2614. return NSDragOperationNone;
  2615. }
  2616. }
  2617. return NSDragOperationNone;
  2618. }
  2619. - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {
  2620. __block BOOL result = NO;
  2621. if (![tableView isEqual:leftSideController.thumbnailTableView]) {
  2622. return result;
  2623. }
  2624. NSPasteboard *pasteboard = [info draggingPasteboard];
  2625. if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
  2626. result = YES;
  2627. NSData *rowData = [pasteboard dataForType:KPDFThumbnailLocalForDraggedTypes];
  2628. NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
  2629. NSData *urlData = [pasteboard dataForType:KPDFThumbnailDoucumentURLForDraggedTypes];
  2630. NSString *url = [NSKeyedUnarchiver unarchiveObjectWithData:urlData];
  2631. if(![url isEqualToString:[pdfView document].documentURL.absoluteString] && url) {
  2632. if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
  2633. NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
  2634. if (fileNames.count == 1) {
  2635. NSString *path = fileNames.firstObject;
  2636. NSString *pathExtension = [path.pathExtension lowercaseString];
  2637. if ([pathExtension isEqualToString:@"pdf"]) {
  2638. __block NSInteger index = row;
  2639. __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2640. PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]] autorelease];
  2641. if ([pdf isEncrypted]) {
  2642. KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
  2643. vc.filePath = url;
  2644. [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  2645. if (password) {
  2646. [pdf unlockWithPassword:password];
  2647. for(NSUInteger i=0; i<pdf.pageCount;i++) {
  2648. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2649. [self.pdfView.document insertPage:page atIndex:index];
  2650. [insertIndexSet addIndex:index];
  2651. index++;
  2652. [page release];
  2653. }
  2654. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2655. }
  2656. }];
  2657. [vc release];
  2658. } else {
  2659. for(NSUInteger i=0; i<pdf.pageCount;i++) {
  2660. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2661. [self.pdfView.document insertPage:page atIndex:index];
  2662. [insertIndexSet addIndex:index];
  2663. index++;
  2664. [page release];
  2665. }
  2666. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2667. }
  2668. return YES;
  2669. }
  2670. }
  2671. }
  2672. }
  2673. __block NSInteger pageIndex = 0;
  2674. __block NSMutableArray *pages = [NSMutableArray array];
  2675. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2676. PDFPage *page = [[[pdfView document] pageAtIndex:idx] copy];
  2677. [pages addObject:page];
  2678. [page release];
  2679. }];
  2680. PDFPage *toPage = nil;
  2681. if (row < (NSInteger)pdfView.document.pageCount) {
  2682. toPage = [pdfView.document pageAtIndex:row];
  2683. }
  2684. __block NSInteger toPageIndex = 0;
  2685. if (toPage) {
  2686. toPageIndex = [pdfView.document indexForPage:toPage];
  2687. } else {
  2688. toPageIndex = pdfView.document.pageCount;
  2689. }
  2690. for(NSUInteger i = 0;i<pages.count;i++) {
  2691. PDFPage *page = pages[i];
  2692. [pdfView.document insertPage:page atIndex:toPageIndex+i];
  2693. pageIndex += 1;
  2694. [self.pdfView goToPage:page];
  2695. }
  2696. [self.pdfView layoutDocumentView];
  2697. __block NSMutableArray *deletepages = [NSMutableArray array];
  2698. [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2699. if((NSInteger)idx < toPageIndex) {
  2700. if((idx+pageIndex) < pdfView.document.pageCount) {
  2701. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2702. [deletepages addObject:page];
  2703. [pdfView.document removePageAtIndex:idx];
  2704. }
  2705. } else {
  2706. if((idx+pageIndex) < pdfView.document.pageCount) {
  2707. PDFPage *page = [[pdfView document] pageAtIndex:idx+pageIndex];
  2708. [deletepages addObject:page];
  2709. [pdfView.document removePageAtIndex:idx+pageIndex];
  2710. }
  2711. }
  2712. }];
  2713. [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
  2714. [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
  2715. [self.pdfView layoutDocumentView];
  2716. [self resetThumbnails];
  2717. } else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
  2718. if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
  2719. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2720. return NO;
  2721. }
  2722. NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
  2723. NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2724. __block NSInteger index = row;
  2725. if (fileNames.count == 1) {
  2726. NSString *path = fileNames.firstObject;
  2727. NSString *pathExtension = [path.pathExtension lowercaseString];
  2728. if ([pathExtension isEqualToString:@"pdf"]) {
  2729. PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
  2730. if ([pdf isEncrypted]) {
  2731. KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
  2732. vc.filePath = path;
  2733. [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  2734. if (password) {
  2735. [pdf unlockWithPassword:password];
  2736. for (NSUInteger i = 0; i< pdf.pageCount; i++) {
  2737. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2738. [self.pdfView.document insertPage:page atIndex:index];
  2739. [insertIndexSet addIndex:index];
  2740. index++;
  2741. [page release];
  2742. }
  2743. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2744. }
  2745. }];
  2746. [vc release];
  2747. } else {
  2748. for (NSUInteger i = 0; i < pdf.pageCount; i++) {
  2749. PDFPage * page = [[pdf pageAtIndex:i] copy];
  2750. [self.pdfView.document insertPage:page atIndex:index];
  2751. [insertIndexSet addIndex:index];
  2752. index++;
  2753. [page release];
  2754. }
  2755. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2756. }
  2757. } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
  2758. NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
  2759. PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
  2760. [pdfView.document insertPage:page atIndex:index];
  2761. [insertIndexSet addIndex:index];
  2762. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2763. }
  2764. result = YES;
  2765. } else {
  2766. result = NO;
  2767. }
  2768. }
  2769. return result;
  2770. }
  2771. */
  2772. }
  2773. // MARK: - NSOutlineViewDelegate, NSOutlineViewDataSource
  2774. /*
  2775. func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
  2776. if item is KMBOTAAnnotationSection {
  2777. let section = item as? KMBOTAAnnotationSection
  2778. return section!.annotations?[index] as Any
  2779. } else if item is KMBOTAAnnotationItem {
  2780. return item as Any
  2781. } else {
  2782. var tempArray: [KMBOTAAnnotationSection] = []
  2783. for temp in self.data {
  2784. if temp.annotations?.count != 0 {
  2785. tempArray.append(temp)
  2786. }
  2787. }
  2788. let section = tempArray[index]
  2789. return section as Any
  2790. }
  2791. }
  2792. func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
  2793. if item is KMBOTAAnnotationItem {
  2794. let cell : KMAnnotationOutlineCellView = KMAnnotationOutlineCellView.init()
  2795. cell.delegate = self
  2796. cell.model = item as? KMBOTAAnnotationItem
  2797. return cell
  2798. } else if item is KMBOTAAnnotationSection {
  2799. let section = item as? KMBOTAAnnotationSection
  2800. let cell : KMAnnotationOutlineSectionView = KMAnnotationOutlineSectionView.init()
  2801. cell.model = section
  2802. return cell
  2803. }
  2804. return NSTableCellView()
  2805. }
  2806. func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
  2807. let rowView = KMAnnotationOutlineRowView()
  2808. if item is KMBOTAAnnotationItem {
  2809. rowView.model = (item as? KMBOTAAnnotationItem)
  2810. } else if item is KMBOTAAnnotationSection {
  2811. rowView.section = (item as? KMBOTAAnnotationSection)
  2812. }
  2813. rowView.mouseDownAction = { [unowned self] view, event in
  2814. if rowView.section != nil {
  2815. let expanded = outlineView.isItemExpanded(outlineView.item(atRow: outlineView.selectedRow))
  2816. if expanded {
  2817. outlineView.collapseItem(outlineView.item(atRow: outlineView.selectedRow), collapseChildren: true)
  2818. outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
  2819. } else {
  2820. outlineView.expandItem(outlineView.item(atRow: outlineView.selectedRow), expandChildren: true)
  2821. outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
  2822. }
  2823. } else if rowView.model != nil {
  2824. self.didSelectItem(view: rowView, event: event)
  2825. }
  2826. }
  2827. rowView.rightMouseDownAction = { [unowned self] view, event in
  2828. if rowView.section != nil {
  2829. } else if rowView.model != nil {
  2830. if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
  2831. self.selectItems.count == 1 {
  2832. self.selectItem(item: item as! KMBOTAAnnotationItem)
  2833. }
  2834. DispatchQueue.main.async {
  2835. self.delegate?.annotationOutlineView(self, rightMouseDownDidSelectView: view, evnet: event)
  2836. }
  2837. }
  2838. }
  2839. rowView.hoverCallback = { [unowned self] (mouseEntered, mouseBox) in
  2840. self.outlineView.enumerateAvailableRowViews { view, row in
  2841. if view is KMAnnotationOutlineRowView {
  2842. (view as? KMAnnotationOutlineRowView)?.model?.hover = false
  2843. (view as? KMAnnotationOutlineRowView)?.reloadData()
  2844. }
  2845. }
  2846. if mouseEntered {
  2847. rowView.model?.hover = true
  2848. } else {
  2849. rowView.model?.hover = false
  2850. }
  2851. }
  2852. return rowView
  2853. }
  2854. func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
  2855. if item is KMBOTAAnnotationItem {
  2856. return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: self.maxWidth - 16, height: 1000))
  2857. } else if item is KMBOTAAnnotationSection {
  2858. return 40
  2859. } else {
  2860. return 30
  2861. }
  2862. }
  2863. func outlineViewSelectionDidChange(_ notification: Notification) {
  2864. if self.outlineView.selectedRow == -1 {
  2865. self.cancelSelect()
  2866. }
  2867. }
  2868. func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
  2869. if item is KMBOTAAnnotationItem {
  2870. return false
  2871. } else if item is KMBOTAAnnotationSection {
  2872. let section = item as? KMBOTAAnnotationSection
  2873. return section!.annotations?.count ?? 0 > 0
  2874. }
  2875. return false
  2876. }
  2877. func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
  2878. if let item = item as? KMBOTAAnnotationSection {
  2879. if !item.isItemExpanded {
  2880. item.isItemExpanded = true
  2881. outlineView.animator().expandItem(item, expandChildren: true)
  2882. return false
  2883. }
  2884. }
  2885. return true
  2886. }
  2887. func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool {
  2888. if let item = item as? KMBOTAAnnotationSection {
  2889. if item.isItemExpanded {
  2890. item.isItemExpanded = false
  2891. outlineView.animator().collapseItem(item, collapseChildren: true)
  2892. return false
  2893. }
  2894. }
  2895. return true
  2896. }
  2897. */
  2898. extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSource {
  2899. func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
  2900. if outlineView.isEqual(to: self.tocOutlineView) {
  2901. let isLocked = self.listView.document?.isLocked ?? true
  2902. if item == nil && isLocked == false {
  2903. var item = self.listView.document.outlineRoot()
  2904. if let data = item?.numberOfChildren, data == 0 && !self.isSearchOutlineMode {
  2905. let view = self.tocOutlineView.enclosingScrollView!
  2906. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  2907. //
  2908. 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)
  2909. self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  2910. self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
  2911. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
  2912. } else {
  2913. self.leftSideEmptyVC.emptyOutlineView.removeFromSuperview()
  2914. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = true
  2915. }
  2916. if let data = item?.numberOfChildren, data > 0 {
  2917. self.outlineSearchButton.isEnabled = true
  2918. } else {
  2919. self.outlineSearchButton.isEnabled = false
  2920. }
  2921. if (self.isSearchOutlineMode) {
  2922. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: item!) {
  2923. // [self showSearchOutlineBlankState:NO];
  2924. } else {
  2925. // [self showSearchOutlineBlankState:YES];
  2926. }
  2927. }
  2928. let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
  2929. // var bookMarks: [KMBookMarkItem] = []
  2930. // for bookMark in array {
  2931. // let item = KMBookMarkItem()
  2932. // item.bookMark = bookMark
  2933. // item.index = UInt(bookMark.pageIndex)
  2934. // item.label = bookMark.label
  2935. // bookMarks.append(item)
  2936. // }
  2937. var bookmarkNum = 0
  2938. if array.isEmpty == false {
  2939. bookmarkNum = 1
  2940. }
  2941. return Int(item?.numberOfChildren ?? 0) + bookmarkNum
  2942. }
  2943. if (self.isSearchOutlineMode) {
  2944. // var num = 0
  2945. // for (NSUInteger i = 0; i < [(PDFOutline *)item numberOfChildren]; i++) {
  2946. // PDFOutline *outline = [(PDFOutline *)item childAtIndex:i];
  2947. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
  2948. // num ++;
  2949. // }
  2950. // }
  2951. // return num;
  2952. } else {
  2953. // return [(PDFOutline *)item numberOfChildren];
  2954. }
  2955. // if item is CPDFBookmark {
  2956. // return 0
  2957. // }
  2958. // return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
  2959. let array = self.listView.document?.bookmarks() ?? [CPDFBookmark]()
  2960. if let data = item as? String, data == "Bookmarks" {
  2961. return array.count
  2962. } else if item is CPDFOutline {
  2963. // return Int(item?.numberOfChildren ?? 0)
  2964. return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
  2965. } else if item is CPDFBookmark {
  2966. return 0
  2967. }
  2968. } else if outlineView.isEqual(to: self.noteOutlineView) {
  2969. var count = 0
  2970. for section in self.annotationViewController.annotations {
  2971. if section.annotations?.count != 0 {
  2972. count += section.annotations!.count
  2973. }
  2974. }
  2975. // if (item == nil){
  2976. // NSInteger count = [[rightSideController.noteArrayController arrangedObjects] count];
  2977. if (count < 1) {
  2978. // if (notes.count < 1) {
  2979. // leftSideController.noteSearchButton.enabled = NO;
  2980. // leftSideController.noteFilterButton.enabled = NO;
  2981. // }
  2982. self.noteOutlineView.usesAlternatingRowBackgroundColors = false
  2983. let view = self.noteOutlineView.enclosingScrollView!
  2984. var emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  2985. 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)
  2986. self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  2987. self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
  2988. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
  2989. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
  2990. //
  2991. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  2992. self.noteHeaderView.isHidden = true
  2993. self.toolButtonBoxLayoutConstraint.constant = 40.0
  2994. }
  2995. } else {
  2996. self.noteSearchButton.isEnabled = true
  2997. self.noteFilterButton.isEnabled = true
  2998. self.noteOutlineView.usesAlternatingRowBackgroundColors = false
  2999. self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
  3000. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
  3001. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
  3002. //
  3003. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  3004. self.noteHeaderView.isHidden = false
  3005. self.toolButtonBoxLayoutConstraint.constant = 64.0
  3006. }
  3007. }
  3008. return count;
  3009. // } else {
  3010. // return [item hasNoteText];
  3011. // }
  3012. }
  3013. return 0
  3014. }
  3015. func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
  3016. if outlineView.isEqual(to: self.tocOutlineView) {
  3017. let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
  3018. var bookmarkNum = 0
  3019. if array.isEmpty == false {
  3020. bookmarkNum = 1
  3021. }
  3022. if item == nil && self.listView.document.isLocked == false {
  3023. if index == 0 && bookmarkNum == 1 {
  3024. return "Bookmarks"
  3025. } else {
  3026. var _index = bookmarkNum == 1 ? index-1 : index
  3027. var _item: CPDFOutline?
  3028. _item = self.listView.document.outlineRoot()
  3029. var obj = _item?.child(at: UInt(_index))
  3030. return obj as Any
  3031. }
  3032. } else {
  3033. if let data = item as? String, data == "Bookmarks" {
  3034. return array[index]
  3035. } else if item is CPDFOutline {
  3036. return (item as! CPDFOutline).child(at: UInt(index))
  3037. } else if item is CPDFBookmark {
  3038. // return nil?
  3039. }
  3040. }
  3041. // var obj = _item?.child(at: UInt(index))
  3042. // if (self.isSearchOutlineMode) {
  3043. // NSMutableArray *array = [NSMutableArray array];
  3044. // for (NSUInteger i = 0; i < [(PDFOutline *)item numberOfChildren]; i ++) {
  3045. // PDFOutline *subOutline = [(PDFOutline *)item childAtIndex:i];
  3046. // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:subOutline]) {
  3047. // [array addObject:subOutline];
  3048. // }
  3049. // }
  3050. // return [array objectAtIndex:anIndex];
  3051. // } else {
  3052. // return obj;
  3053. // }
  3054. // return obj as Any
  3055. } else if outlineView.isEqual(to: self.noteOutlineView) {
  3056. // if (item == nil)
  3057. // {
  3058. // return [[rightSideController.noteArrayController arrangedObjects] objectAtIndex:anIndex];
  3059. // // return [self.notes objectAtIndex:anIndex];
  3060. // }
  3061. // else
  3062. // return [item noteText];
  3063. var tempArray: [KMBOTAAnnotationItem] = []
  3064. for secion in self.annotationViewController.annotations {
  3065. if secion.annotations?.count != 0 {
  3066. for _item in secion.annotations! {
  3067. tempArray.append(_item)
  3068. }
  3069. }
  3070. }
  3071. return tempArray[index] as Any
  3072. }
  3073. return item
  3074. }
  3075. func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
  3076. if outlineView.isEqual(to: self.tocOutlineView) {
  3077. // let tcID = tableColumn?.identifier.rawValue ?? ""
  3078. // var ol = item as? CPDFOutline
  3079. // if(tcID == LABEL_COLUMNID) {
  3080. // if (self.isSearchOutlineMode) {
  3081. //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
  3082. //// NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
  3083. //// NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
  3084. //// for (NSUInteger i = 0; i <arr.count ; i++) {
  3085. //// NSValue * rangeValue = arr[i];
  3086. //// NSRange range = rangeValue.rangeValue;
  3087. //// range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
  3088. //// [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
  3089. //// }
  3090. //// [attributeString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:NSMakeRange(0, roughString.length)];
  3091. //// return attributeString;
  3092. // } else {
  3093. // var attributedString = NSMutableAttributedString()
  3094. //// attributedString
  3095. // attributedString.append(.init(string: ol?.label ?? "", attributes: [.foregroundColor : KMAppearance.Layout.h0Color()]))
  3096. //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
  3097. //// NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3098. //// NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
  3099. //// [attributedString appendAttributedString:attr1];
  3100. //
  3101. // return attributedString
  3102. // }
  3103. //
  3104. // }
  3105. // else if([tcID isEqualToString:PAGE_COLUMNID]) {
  3106. // NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  3107. // NSString *roughString = [ol pageLabel]? : @"";
  3108. // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3109. // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
  3110. // [attributedString appendAttributedString:attr1];
  3111. //
  3112. // return attributedString;
  3113. // }
  3114. }
  3115. // else if ([ov isEqual:rightSideController.noteOutlineView]) {
  3116. // NSString *tcID = [tableColumn identifier];
  3117. // PDFAnnotation *note = item;
  3118. // if (tableColumn == nil || [tcID isEqualToString:NOTE_COLUMNID])
  3119. // return [note objectValue];
  3120. // else if([tcID isEqualToString:TYPE_COLUMNID]){
  3121. // NSString *noteType = [note type];
  3122. // if ([note isKindOfClass:[PDFAnnotationButtonWidget class]]) {
  3123. // PDFAnnotationButtonWidget *buttonWidget = (PDFAnnotationButtonWidget *)note;
  3124. // if (buttonWidget.controlType == kPDFWidgetRadioButtonControl) {
  3125. // noteType = SKAnnotationFormRadioButtonKey;
  3126. // } else if (buttonWidget.controlType == kPDFWidgetCheckBoxControl){
  3127. // noteType = SKAnnotationFormCheckBoxKey;
  3128. // } else if (buttonWidget.controlType == kPDFWidgetPushButtonControl){
  3129. // noteType = SKAnnotationFormActionButtonKey;
  3130. // }
  3131. // } else if ([note isKindOfClass:[PDFAnnotationTextWidget class]]){
  3132. // noteType = SKAnnotationFormTextFieldKey;
  3133. // } else if ([note isKindOfClass:[PDFAnnotationChoiceWidget class]]){
  3134. // PDFAnnotationChoiceWidget *choiceWidget = (PDFAnnotationChoiceWidget *)note;
  3135. // if (choiceWidget.isListChoice) {
  3136. // noteType = SKAnnotationFormListMenuKey;
  3137. // } else {
  3138. // noteType = SKAnnotationFormComboBoxKey;
  3139. // }
  3140. //
  3141. // }
  3142. // return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:note == [pdfView activeAnnotation]], SKAnnotationTypeImageCellActiveKey, noteType, SKAnnotationTypeImageCellTypeKey,[note color],SKAnnotationTypeImageCellColorKey, nil];
  3143. // }
  3144. // else if([tcID isEqualToString:COLOR_COLUMNID])
  3145. // return [note type] ? [note color] : nil;
  3146. // else if([tcID isEqualToString:PAGE_COLUMNID])
  3147. // return [[note page] displayLabel];
  3148. // else if([tcID isEqualToString:AUTHOR_COLUMNID])
  3149. // return [note type] ? [note userName] : nil;
  3150. // else if([tcID isEqualToString:DATE_COLUMNID])
  3151. // return [note type] ? [note modificationDate] : nil;
  3152. // }
  3153. return nil
  3154. }
  3155. func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
  3156. if outlineView.isEqual(to: self.tocOutlineView) {
  3157. let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMTocTableCellView"), owner: self) as! KMTocTableCellView
  3158. let tcID = tableColumn?.identifier.rawValue
  3159. var title = ""
  3160. if let data = item as? String, data == "Bookmarks" {
  3161. title = NSLocalizedString("Bookmarks", comment: "")
  3162. } else if item is CPDFOutline {
  3163. title = (item as! CPDFOutline).label
  3164. } else if item is CPDFBookmark {
  3165. title = (item as! CPDFBookmark).label
  3166. }
  3167. if tcID == LABEL_COLUMNID {
  3168. if (self.isSearchOutlineMode) {
  3169. // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
  3170. // NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
  3171. // NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
  3172. //
  3173. // for (NSUInteger i = 0; i <arr.count ; i++) {
  3174. // NSValue * rangeValue = arr[i];
  3175. // NSRange range = rangeValue.rangeValue;
  3176. // range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
  3177. // [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
  3178. // }
  3179. // cell.tocLabel.attributedStringValue = attributeString;
  3180. } else {
  3181. cell.tocLabel.stringValue = title
  3182. }
  3183. // TODO: 不确定是哪个字段
  3184. cell.pageLabel.stringValue = ""
  3185. }
  3186. // else if([tcID isEqualToString:PAGE_COLUMNID]) {
  3187. // cell.pageLabel.stringValue = [ol pageLabel];
  3188. // }
  3189. return cell
  3190. } else if outlineView.isEqual(to: self.noteOutlineView) {
  3191. let note = (item as! KMBOTAAnnotationItem).annotation!
  3192. let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteTableViewCell"), owner: self) as! KMNoteTableViewCell
  3193. cell.cellNote = note
  3194. let noteColor = note.color
  3195. var noteType = note.type ?? ""
  3196. var noteString = note.string() ?? ""
  3197. // NSString *pageString = [[note page] displayLabel] ? : @"";
  3198. var pageString = note.page.label ?? ""
  3199. let date = note.modificationDate()
  3200. var authorString = note.userName() ?? ""
  3201. // NSString *noteTextString = [note noteText].string ? : @"";
  3202. var noteTextString = note.string() ?? ""
  3203. //
  3204. // if([noteType isEqualToString:@"Redact"]) {
  3205. // noteString = @"Redact";
  3206. // }
  3207. //
  3208. let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool
  3209. if timeKey == nil || timeKey == false {
  3210. if (date != nil) {
  3211. cell.timeLabel.stringValue = CPDFAnnotationModel.timeString(withTime: date)
  3212. } else {
  3213. cell.timeLabel.stringValue = ""
  3214. }
  3215. cell.timeLabel.isHidden = false
  3216. } else {
  3217. cell.timeLabel.isHidden = true
  3218. }
  3219. let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool
  3220. if pageKey == nil || pageKey == false {
  3221. let labelsize = cell.pageLabel.stringValue.boundingRect(with: CGSizeMake(CGFloat(MAXFLOAT),CGRectGetHeight(cell.pageLabel.bounds)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font : NSFont.systemFont(ofSize: 12)])
  3222. cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5
  3223. cell.pageLabel.stringValue = pageString
  3224. cell.pageLabel.isHidden = false
  3225. } else {
  3226. cell.pageLabel.isHidden = true
  3227. }
  3228. let autherKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool
  3229. if pageKey == nil || pageKey == false {
  3230. cell.autherLabel.stringValue = authorString
  3231. cell.autherLabel.isHidden = false
  3232. } else {
  3233. cell.autherLabel.isHidden = true
  3234. }
  3235. let imageView = KMNoteTypeImageView()
  3236. if note.isKind(of: CPDFStampAnnotation.self) {
  3237. let annotation_stamp = note as! CPDFStampAnnotation
  3238. if (annotation_stamp.stampImage() != nil) {
  3239. noteType = SKNStampString
  3240. }
  3241. } else if note.isKind(of: CPDFLineAnnotation.self) {
  3242. let annotation_line = note as! CPDFLineAnnotation
  3243. if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .none {
  3244. noteType = SKNLine_NoneString
  3245. } else if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .openArrow {
  3246. noteType = SKNLine_OpenArrowString
  3247. } else {
  3248. noteType = SKNLine_NoneString
  3249. }
  3250. } else if note.isKind(of: CPDFButtonWidgetAnnotation.self) {
  3251. let buttonWidget = note as! CPDFButtonWidgetAnnotation
  3252. if buttonWidget.controlType() == .radioButtonControl {
  3253. noteType = KMAnnotationFormRadioButtonKey
  3254. } else if buttonWidget.controlType() == .checkBoxControl {
  3255. noteType = KMAnnotationFormCheckBoxKey
  3256. } else if buttonWidget.controlType() == .pushButtonControl {
  3257. noteType = KMAnnotationFormActionButtonKey
  3258. }
  3259. } else if note.isKind(of: CPDFTextWidgetAnnotation.self) {
  3260. noteType = KMAnnotationFormTextFieldKey
  3261. } else if note.isKind(of: CPDFChoiceWidgetAnnotation.self) {
  3262. let choiceWidget = note as! CPDFChoiceWidgetAnnotation
  3263. if choiceWidget.isListChoice {
  3264. noteType = KMAnnotationFormListMenuKey
  3265. } else {
  3266. noteType = KMAnnotationFormComboBoxKey
  3267. }
  3268. } else if note.isKind(of: KMTableAnnotation.self) {
  3269. noteType = "Ink_Table"
  3270. } else if note.isKind(of: KMSelfSignAnnotation.self) {
  3271. let selfSignNote = note as! KMSelfSignAnnotation
  3272. if selfSignNote.annotationType == .signFalse {
  3273. noteType = "KMSelfSignTypeFalseActionButtonKey"
  3274. } else if (selfSignNote.annotationType == .signature) {
  3275. noteType = "KMSelfSignTypeTureActionButtonKey"
  3276. } else if (selfSignNote.annotationType == .signCircle) {
  3277. noteType = "KMSelfSignTypeCircleActionButtonKey"
  3278. } else if (selfSignNote.annotationType == .signLine) {
  3279. noteType = "KMSelfSignTypeLineActionButtonKey"
  3280. } else if (selfSignNote.annotationType == .signDot) {
  3281. noteType = "KMSelfSignTypeDotActionButtonKey"
  3282. } else if (selfSignNote.annotationType == .signText) {
  3283. noteType = "KMSelfSignTypeTextActionButtonKey"
  3284. }
  3285. } else if note.isKind(of: CPDFSquareAnnotation.self) {
  3286. noteType = SKNSquareString
  3287. } else if note.isKind(of: CPDFTextAnnotation.self) {
  3288. noteType = SKNNoteString
  3289. }
  3290. cell.typeImageView.image = imageView.noteTypeImage(withType: noteType, color: noteColor ?? .red)
  3291. cell.typeImageView.isHidden = false
  3292. if note.isKind(of: CPDFMarkupAnnotation.self) {
  3293. cell.isFold = true
  3294. }
  3295. cell.noteContentBox.isHidden = true
  3296. cell.noteImageView.isHidden = true
  3297. cell.foldButton.isHidden = true
  3298. cell.annotationContentLabel.isHidden = false
  3299. cell.noteContentLabel.stringValue = noteString
  3300. cell.contentView.isHidden = false
  3301. cell.contentViewHidden(false)
  3302. if note.isKind(of: CPDFMarkupAnnotation.self) {
  3303. let markup = note as! CPDFMarkupAnnotation
  3304. if(noteTextString.isEmpty == false) {
  3305. cell.foldButton.isHidden = false
  3306. }
  3307. var attributeStr = NSMutableAttributedString(string: noteTextString)
  3308. if (markup.markupType() == .highlight) {
  3309. attributeStr.addAttribute(.backgroundColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
  3310. } else if (markup.markupType() == .strikeOut) {
  3311. attributeStr.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
  3312. attributeStr.addAttribute(.strikethroughColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
  3313. } else if (markup.markupType() == .underline) {
  3314. attributeStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
  3315. attributeStr.addAttribute(.underlineColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
  3316. }
  3317. cell.annotationContentLabel.attributedStringValue = attributeStr
  3318. if (self.foldType == .unfold) {
  3319. cell.isFold = false
  3320. } else if (self.foldType == .fold) {
  3321. cell.isFold = true
  3322. } else {
  3323. // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
  3324. // cell.isFold = NO;
  3325. // } else {
  3326. // cell.isFold = YES;
  3327. // }
  3328. }
  3329. if (noteString.isEmpty == false && noteTextString.isEmpty == false) {
  3330. cell.contentViewHidden(false)
  3331. } else {
  3332. cell.contentViewHidden(true)
  3333. }
  3334. } else if note.isKind(of: CPDFLineAnnotation.self) || noteType == SKNSquareString || noteType == SKNCircleString || noteType == SKNInkString {
  3335. cell.annotationContentLabel.stringValue = noteString
  3336. if (noteString.isEmpty == false) {
  3337. cell.contentViewHidden(false)
  3338. } else {
  3339. cell.contentViewHidden(true)
  3340. }
  3341. } else if note.isKind(of: CPDFStampAnnotation.self) {
  3342. if note.isKind(of: KMSelfSignAnnotation.self) {
  3343. let newAnnotation = note as! KMSelfSignAnnotation
  3344. let type = newAnnotation.annotationType
  3345. var returnString = ""
  3346. if (type == .signFalse) {
  3347. returnString = KMLocalizedString("X", nil)
  3348. } else if (type == .signature) {
  3349. returnString = KMLocalizedString("Check mark", nil)
  3350. } else if (type == .signCircle) {
  3351. returnString = KMLocalizedString("Circle", nil)
  3352. } else if (type == .signLine) {
  3353. returnString = KMLocalizedString("Line", nil)
  3354. } else if (type == .signDot) {
  3355. returnString = KMLocalizedString("Dot", nil)
  3356. } else if (type == .signText) {
  3357. returnString = KMLocalizedString("Text", nil)
  3358. }
  3359. cell.annotationContentLabel.stringValue = returnString
  3360. } else {
  3361. cell.annotationContentLabel.isHidden = true
  3362. cell.noteImageView.isHidden = false
  3363. // PDFAnnotation *annotation = note;
  3364. // NSImage *stampImage = [self stampCreateImage:annotation];
  3365. // if (stampImage) {
  3366. // cell.noteImageView.image = [self stampCreateImage:annotation];
  3367. // } else {
  3368. // cell.noteImageView.hidden = YES;
  3369. // [cell contentViewHidden:YES];
  3370. // }
  3371. }
  3372. }
  3373. // else if ([note isKindOfClass:[SKNPDFAnnotationNote class]]) {
  3374. // cell.foldButton.hidden = NO;
  3375. // if (!noteString || noteString.length < 1){
  3376. // cell.annotationContentLabel.stringValue = noteTextString;
  3377. // }else{
  3378. // cell.annotationContentLabel.stringValue = noteString;
  3379. // cell.noteContentLabel.stringValue = noteTextString;
  3380. // }
  3381. //
  3382. // if (self.foldType == KMFoldAllAnnotationType_Unfold) {
  3383. // cell.isFold = NO;
  3384. // } else if (self.foldType == KMFoldAllAnnotationType_Fold) {
  3385. // cell.isFold = YES;
  3386. // } else {
  3387. // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
  3388. // cell.isFold = NO;
  3389. // } else {
  3390. // cell.isFold = YES;
  3391. // }
  3392. // }
  3393. // if (noteString.length > 0 || noteTextString.length > 0) {
  3394. // cell.contentView.hidden = NO;
  3395. // } else {
  3396. // cell.contentView.hidden = YES;
  3397. // [cell contentViewHidden:YES];
  3398. // }
  3399. // if (noteString.length > 0 && noteTextString.length > 0) {
  3400. // cell.foldButton.hidden = NO;
  3401. // }else{
  3402. // cell.foldButton.hidden = YES;
  3403. // }
  3404. //
  3405. // }
  3406. else {
  3407. cell.annotationContentLabel.stringValue = noteString
  3408. cell.imageViewHeightConstraint.constant = cell.contentView.frame.size.height
  3409. if (noteString.isEmpty == false) {
  3410. cell.contentViewHidden(false)
  3411. } else {
  3412. cell.contentViewHidden(true)
  3413. }
  3414. }
  3415. //
  3416. cell.autherLayoutConstraint.constant = cell.autherLabel.isHidden ? -(cell.autherLabel.bounds.size.width) + 10.0 : 10.0
  3417. cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.isHidden ? -(cell.typeImageView.bounds.size.width) : 0.0
  3418. cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.isHidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0
  3419. if note.isKind(of: CPDFStampAnnotation.self) && note.isKind(of: KMSelfSignAnnotation.self) == false {
  3420. //
  3421. } else {
  3422. if note.isKind(of: CPDFMarkupAnnotation.self) {
  3423. if (!cell.isFold) {
  3424. // [rightSideController.allFoldNotes addObject:note];
  3425. } else {
  3426. cell.imageViewHeightConstraint.constant = 18.0 + 8
  3427. }
  3428. } else {
  3429. cell.imageViewHeightConstraint.constant = 18.0 + 8
  3430. }
  3431. }
  3432. // cell.isUnFoldNote = ^(PDFAnnotation *cellNote, BOOL isUnfold) {
  3433. // if (isUnfold) {
  3434. // if ([rightSideController.allFoldNotes containsObject:note]) {
  3435. // [rightSideController.allFoldNotes removeObject:note];
  3436. // }
  3437. //
  3438. // if (rightSideController.allFoldNotes.count == 0) {
  3439. // self.foldType = KMFoldAllAnnotationType_Fold;
  3440. // } else {
  3441. // self.foldType = KMFoldAllAnnotationType_None;
  3442. // }
  3443. // } else {
  3444. // if (![rightSideController.allFoldNotes containsObject:note]) {
  3445. // [rightSideController.allFoldNotes addObject:note];
  3446. // }
  3447. //
  3448. // if (rightSideController.allFoldNotes.count == rightSideController.canFoldNotes.count) {
  3449. // self.foldType = KMFoldAllAnnotationType_Unfold;
  3450. // } else {
  3451. // self.foldType = KMFoldAllAnnotationType_None;
  3452. // }
  3453. // }
  3454. // };
  3455. return cell
  3456. }
  3457. return nil
  3458. }
  3459. func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
  3460. if outlineView.isEqual(self.noteOutlineView) {
  3461. if item is KMBOTAAnnotationItem {
  3462. return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: 260+40 - 16, height: 1000))
  3463. }
  3464. return 30
  3465. } else if outlineView.isEqual(self.tocOutlineView) {
  3466. if item is CPDFOutline {
  3467. let tempItem = item as! CPDFOutline
  3468. let string: NSString = tempItem.label as NSString
  3469. let paragraphStyle = NSMutableParagraphStyle()
  3470. paragraphStyle.lineHeightMultiple = 1.32
  3471. paragraphStyle.alignment = .left
  3472. let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle,
  3473. NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0)]
  3474. let size = string.boundingRect(with: CGSizeMake(outlineView.frame.size.width - 30, 200), options: NSString.DrawingOptions(rawValue: 3), attributes: attributes)
  3475. return max(40, size.height + 16)
  3476. }
  3477. return 40
  3478. }
  3479. return outlineView.rowHeight
  3480. }
  3481. func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
  3482. if outlineView.isEqual(self.tocOutlineView) {
  3483. // var _item: CPDFOutline?
  3484. // if item == nil && self.listView.document.isLocked == false {
  3485. // _item = self.listView.document.outlineRoot()
  3486. // }
  3487. if let data = item as? String, data == "Bookmarks" {
  3488. return true
  3489. } else if item is CPDFOutline {
  3490. return ((item as! CPDFOutline).numberOfChildren ?? 0) != 0
  3491. } else if item is CPDFBookmark {
  3492. return false
  3493. }
  3494. if (self.isSearchOutlineMode) {
  3495. // return [self subOutLineContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:(PDFOutline *)item];
  3496. } else {
  3497. // return ((_item?.numberOfChildren ?? 0) != 0)
  3498. }
  3499. } else if outlineView.isEqual(to: self.noteOutlineView) {
  3500. // return [item hasNoteText];
  3501. return false
  3502. }
  3503. return false
  3504. }
  3505. func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
  3506. if outlineView.isEqual(self.tocOutlineView) {
  3507. let itemView = KMCustomTableRowView()
  3508. return itemView
  3509. } else if outlineView.isEqual(self.noteOutlineView) {
  3510. let itemView = KMCustomTableRowView()
  3511. return itemView;
  3512. }
  3513. return nil
  3514. }
  3515. /*
  3516. #pragma mark NSOutlineView datasource protocol
  3517. - (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item{
  3518. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3519. PDFAnnotation *note = item;
  3520. if ([note type]) {
  3521. if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
  3522. if ([(object ?: @"") isEqualToString:([note string] ?: @"")] == NO)
  3523. [note setString:object];
  3524. } else if ([[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
  3525. if ([(object ?: @"") isEqualToString:([note userName] ?: @"")] == NO)
  3526. [note setUserName:object];
  3527. }
  3528. }
  3529. }
  3530. }
  3531. #pragma mark Drag
  3532. - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard{
  3533. if ([outlineView isEqual:leftSideController.tocOutlineView]) {
  3534. if (leftSideController.tocOutlineView.selectedRowIndexes.count > 1) {
  3535. return NO;
  3536. }
  3537. NSIndexSet *tIndex = [[[NSIndexSet alloc] initWithIndex:leftSideController.tocOutlineView.clickedRow] autorelease];
  3538. [leftSideController.tocOutlineView deselectRow:tIndex.firstIndex];
  3539. self.dragPDFOutline = items.firstObject;
  3540. NSIndexSet *set = [NSIndexSet indexSetWithIndex:0];
  3541. NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:set];
  3542. [pasteboard declareTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType] owner:self];
  3543. [pasteboard setData:zNSIndexSetData forType:kKMPDFViewOutlineDragDataType];
  3544. return YES;
  3545. }
  3546. return NO;
  3547. }
  3548. - (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)anIndex {
  3549. NSDragOperation dragOp = NSDragOperationNone;
  3550. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3551. NSPasteboard *pboard = [info draggingPasteboard];
  3552. if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
  3553. anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
  3554. dragOp = NSDragOperationEvery;
  3555. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3556. if (anIndex == -1) {
  3557. dragOp = NSDragOperationNone;
  3558. } else {
  3559. dragOp = NSDragOperationMove;
  3560. }
  3561. }
  3562. return dragOp;
  3563. }
  3564. - (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)anIndex {
  3565. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3566. NSPasteboard *pboard = [info draggingPasteboard];
  3567. if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]]) {
  3568. BOOL isShift = ([NSEvent standardModifierFlags] & NSEventModifierFlagShift) != 0;
  3569. BOOL isAlt = ([NSEvent standardModifierFlags] & NSEventModifierFlagOption) != 0;
  3570. [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
  3571. return YES;
  3572. }
  3573. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3574. if (anIndex < 0) {
  3575. return NO;
  3576. }
  3577. PDFOutline *outline = item;
  3578. //root,drag item to root
  3579. if (!outline.parent) {
  3580. //fetch root
  3581. PDFOutline *root = self.dragPDFOutline;
  3582. while (root.parent) {
  3583. root = root.parent;
  3584. }
  3585. if ([self.dragPDFOutline.parent isEqual:root]) {
  3586. if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
  3587. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
  3588. } else {
  3589. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:root];
  3590. }
  3591. } else {
  3592. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
  3593. }
  3594. } else {
  3595. //在同一个层级内移动
  3596. if ([self.dragPDFOutline.parent isEqual:item]) {
  3597. if (self.dragPDFOutline.index) {
  3598. if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
  3599. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
  3600. }else{
  3601. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:outline];
  3602. }
  3603. } else {
  3604. return NO;
  3605. }
  3606. } else {
  3607. PDFOutline *tOutlline = outline;
  3608. BOOL isContains = NO;
  3609. while (tOutlline) {
  3610. if ([tOutlline isEqual:self.dragPDFOutline]) {
  3611. isContains = YES;
  3612. break;
  3613. }
  3614. tOutlline = tOutlline.parent;
  3615. }
  3616. if (!isContains) {
  3617. [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
  3618. }
  3619. }
  3620. }
  3621. return YES;
  3622. }
  3623. return NO;
  3624. }
  3625. #pragma mark NSOutlineView delegate protocol
  3626. - (NSCell *)outlineView:(NSOutlineView *)ov dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
  3627. if ([ov isEqual:rightSideController.noteOutlineView] && tableColumn == nil && [(PDFAnnotation *)item type] == nil) {
  3628. return [[ov tableColumnWithIdentifier:NOTE_COLUMNID] dataCellForRow:[ov rowForItem:item]];
  3629. }
  3630. return [tableColumn dataCellForRow:[ov rowForItem:item]];
  3631. }
  3632. - (void)outlineView:(NSOutlineView *)ov willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
  3633. if ([ov isEqual:leftSideController.tocOutlineView] &&
  3634. [ov selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular &&
  3635. [ov isRowSelected:[ov rowForItem:item]]) {
  3636. [cell setBackgroundStyle:NSBackgroundStyleLowered];
  3637. }
  3638. }
  3639. - (BOOL)outlineView:(NSOutlineView *)ov shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item{
  3640. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3641. if (tableColumn == nil) {
  3642. if ([pdfView hideNotes] == NO && [[(SKNoteText *)item note] isNote]) {
  3643. PDFAnnotation *annotation = [(SKNoteText *)item note];
  3644. [pdfView scrollAnnotationToVisible:annotation];
  3645. [pdfView setActiveAnnotation:annotation];
  3646. [self showNote:annotation];
  3647. SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
  3648. [[noteController window] makeFirstResponder:[noteController textView]];
  3649. [[noteController textView] selectAll:nil];
  3650. }
  3651. return NO;
  3652. } else if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID] || [[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
  3653. return YES;
  3654. }
  3655. }
  3656. return NO;
  3657. }
  3658. - (void)outlineView:(NSOutlineView *)ov didClickTableColumn:(NSTableColumn *)tableColumn {
  3659. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3660. NSTableColumn *oldTableColumn = [ov highlightedTableColumn];
  3661. NSTableColumn *newTableColumn = ([NSEvent modifierFlags] & NSEventModifierFlagCommand) ? nil : tableColumn;
  3662. NSMutableArray *sortDescriptors = nil;
  3663. BOOL ascending = YES;
  3664. if ([oldTableColumn isEqual:newTableColumn]) {
  3665. sortDescriptors = [[[rightSideController.noteArrayController sortDescriptors] mutableCopy] autorelease];
  3666. [sortDescriptors replaceObjectAtIndex:0 withObject:[[sortDescriptors firstObject] reversedSortDescriptor]];
  3667. ascending = [[sortDescriptors firstObject] ascending];
  3668. } else {
  3669. NSString *tcID = [newTableColumn identifier];
  3670. NSSortDescriptor *pageIndexSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationPageIndexKey ascending:ascending] autorelease];
  3671. NSSortDescriptor *boundsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKPDFAnnotationBoundsOrderKey ascending:ascending selector:@selector(compare:)] autorelease];
  3672. sortDescriptors = [NSMutableArray arrayWithObjects:pageIndexSortDescriptor, boundsSortDescriptor, nil];
  3673. if ([tcID isEqualToString:TYPE_COLUMNID]) {
  3674. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationTypeKey ascending:YES selector:@selector(noteTypeCompare:)] autorelease] atIndex:0];
  3675. } else if ([tcID isEqualToString:COLOR_COLUMNID]) {
  3676. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationColorKey ascending:YES selector:@selector(colorCompare:)] autorelease] atIndex:0];
  3677. } else if ([tcID isEqualToString:NOTE_COLUMNID]) {
  3678. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationStringKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
  3679. } else if ([tcID isEqualToString:AUTHOR_COLUMNID]) {
  3680. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationUserNameKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
  3681. } else if ([tcID isEqualToString:DATE_COLUMNID]) {
  3682. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationModificationDateKey ascending:YES] autorelease] atIndex:0];
  3683. }
  3684. if (oldTableColumn)
  3685. [ov setIndicatorImage:nil inTableColumn:oldTableColumn];
  3686. [ov setHighlightedTableColumn:newTableColumn];
  3687. }
  3688. [rightSideController.noteArrayController setSortDescriptors:sortDescriptors];
  3689. if (newTableColumn)
  3690. [ov setIndicatorImage:[NSImage imageNamed:ascending ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
  3691. inTableColumn:newTableColumn];
  3692. [ov reloadData];
  3693. }
  3694. }
  3695. - (void)outlineViewSelectionDidChange:(NSNotification *)notification{
  3696. // Get the destination associated with the search result list. Tell the PDFView to go there.
  3697. if ([[notification object] isEqual:leftSideController.tocOutlineView] && (mwcFlags.updatingOutlineSelection == 0)){
  3698. mwcFlags.updatingOutlineSelection = 1;
  3699. [self goToSelectedOutlineItem:nil];
  3700. mwcFlags.updatingOutlineSelection = 0;
  3701. if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  3702. [self hideLeftSideWindow];
  3703. }
  3704. }
  3705. - (NSString *)outlineView:(NSOutlineView *)ov toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn item:(id)item mouseLocation:(NSPoint)mouseLocation {
  3706. if ([ov isEqual:rightSideController.noteOutlineView] &&
  3707. (tableColumn == nil || [[tableColumn identifier] isEqualToString:NOTE_COLUMNID])) {
  3708. return [item string];
  3709. }
  3710. return @"";
  3711. }
  3712. - (void)outlineViewItemDidExpand:(NSNotification *)notification{
  3713. if ([[notification object] isEqual:leftSideController.tocOutlineView]) {
  3714. [self updateOutlineSelection];
  3715. }
  3716. }
  3717. - (void)outlineViewItemDidCollapse:(NSNotification *)notification{
  3718. if ([[notification object] isEqual:leftSideController.tocOutlineView]) {
  3719. [self updateOutlineSelection];
  3720. }
  3721. }
  3722. - (void)outlineViewColumnDidResize:(NSNotification *)notification{
  3723. if (mwcFlags.autoResizeNoteRows &&
  3724. [[notification object] isEqual:rightSideController.noteOutlineView] &&
  3725. [[[[notification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:NOTE_COLUMNID] &&
  3726. [(SKScrollView *)[[notification object] enclosingScrollView] isResizingSubviews] == NO) {
  3727. [rowHeights removeAllFloats];
  3728. [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
  3729. }
  3730. }
  3731. - (void)outlineView:(NSOutlineView *)ov didChangeHiddenOfTableColumn:(NSTableColumn *)tableColumn {
  3732. if (mwcFlags.autoResizeNoteRows &&
  3733. [ov isEqual:rightSideController.noteOutlineView] &&
  3734. [[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
  3735. [rowHeights removeAllFloats];
  3736. [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
  3737. }
  3738. }
  3739. - (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item {
  3740. }
  3741. - (void)updateSelectRowHeight{
  3742. CGFloat rowHeight = 0;
  3743. PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.selectedRow];
  3744. if (!outline){
  3745. return;
  3746. }
  3747. NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  3748. NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3749. NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
  3750. [attributedString appendAttributedString:attr1];
  3751. NSInteger *row = [leftSideController.tocOutlineView selectedRow];
  3752. NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:row makeIfNecessary:YES];
  3753. NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
  3754. // id cell = [tableColumn dataCell];
  3755. id cell = [tableColumn dataCellForRow:row];
  3756. [cell setObjectValue:attributedString];
  3757. CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
  3758. NSInteger num = [self getNum:outline];
  3759. CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
  3760. rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
  3761. rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
  3762. [rowHeights setFloat:rowHeight forKey:outline];
  3763. if (@available(macOS 10.13, *)) {
  3764. } else {
  3765. rowHeight = 40.0;
  3766. }
  3767. CGRect fram = viewS.frame;
  3768. viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
  3769. [leftSideController.tocOutlineView reloadData];
  3770. }
  3771. - (NSInteger)getNum:(PDFOutline *)ol{
  3772. NSInteger num = 0;
  3773. PDFOutline *outLine = [ol parent];
  3774. do {
  3775. outLine = [outLine parent];
  3776. if (outLine){
  3777. num ++;
  3778. }
  3779. } while (outLine);
  3780. return num;
  3781. }
  3782. - (void)sizeOutlineViewToContents:(NSOutlineView*) outlineView;
  3783. {
  3784. NSInteger rowCount = [outlineView numberOfRows];
  3785. for (NSInteger i = 0; i < rowCount; i++){
  3786. CGFloat rowHeight = 0;
  3787. PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:i];
  3788. if (!outline){
  3789. continue;
  3790. }
  3791. NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  3792. NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  3793. NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
  3794. [attributedString appendAttributedString:attr1];
  3795. // NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:i makeIfNecessary:YES];
  3796. NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
  3797. // id cell = [tableColumn dataCell];
  3798. id cell = [tableColumn dataCellForRow:i];
  3799. [cell setObjectValue:attributedString];
  3800. CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
  3801. NSInteger num = [self getNum:outline];
  3802. CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
  3803. rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
  3804. rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
  3805. [rowHeights setFloat:rowHeight forKey:outline];
  3806. if (@available(macOS 10.13, *)) {
  3807. } else {
  3808. rowHeight = 40.0;
  3809. }
  3810. // CGRect fram = viewS.frame;
  3811. // viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
  3812. }
  3813. [leftSideController.tocOutlineView reloadData];
  3814. }
  3815. - (BOOL)outlineView:(NSOutlineView *)ov canResizeRowByItem:(id)item {
  3816. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3817. return YES;
  3818. }
  3819. return NO;
  3820. }
  3821. - (void)outlineView:(NSOutlineView *)ov setHeight:(CGFloat)newHeight ofRowByItem:(id)item {
  3822. [rowHeights setFloat:newHeight forKey:item];
  3823. }
  3824. - (NSArray *)noteItems:(NSArray *)items {
  3825. NSMutableArray *noteItems = [NSMutableArray array];
  3826. for (PDFAnnotation *item in items) {
  3827. if ([item type] == nil) {
  3828. item = [(SKNoteText *)item note];
  3829. }
  3830. if ([noteItems containsObject:item] == NO)
  3831. [noteItems addObject:item];
  3832. }
  3833. return noteItems;
  3834. }
  3835. - (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items {
  3836. if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
  3837. for (PDFAnnotation *item in [self noteItems:items])
  3838. [pdfView removeAnnotation:item];
  3839. [[[self document] undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
  3840. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3841. [self outlineContextMenuItemClicked_RemoveEntry:nil];
  3842. }
  3843. }
  3844. - (BOOL)outlineView:(NSOutlineView *)ov canDeleteItems:(NSArray *)items {
  3845. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3846. return [[self pdfDocument] allowsNotes] && [items count] > 0;
  3847. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3848. return [items count] > 0;
  3849. }
  3850. return NO;
  3851. }
  3852. - (void)outlineView:(NSOutlineView *)ov copyItems:(NSArray *)items {
  3853. if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
  3854. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  3855. NSMutableArray *copiedItems = [NSMutableArray array];
  3856. NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] init] autorelease];
  3857. BOOL isAttributed = NO;
  3858. id item;
  3859. for (item in [self noteItems:items]) {
  3860. if ([item isMovable])
  3861. [copiedItems addObject:item];
  3862. }
  3863. for (item in items) {
  3864. if ([attrString length])
  3865. [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:@"\n\n"];
  3866. if ([(PDFAnnotation *)item type] == nil && [[(SKNoteText *)item note] isNote]) {
  3867. [attrString appendAttributedString:[(SKNoteText *)item text]];
  3868. isAttributed = YES;
  3869. } else {
  3870. [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:[item string] ?: @""];
  3871. }
  3872. }
  3873. [pboard clearContents];
  3874. if (isAttributed)
  3875. [pboard writeObjects:[NSArray arrayWithObjects:attrString, nil]];
  3876. else
  3877. [pboard writeObjects:[NSArray arrayWithObjects:[attrString string], nil]];
  3878. if ([copiedItems count] > 0)
  3879. [pboard writeObjects:copiedItems];
  3880. }
  3881. }
  3882. - (BOOL)outlineView:(NSOutlineView *)ov canCopyItems:(NSArray *)items {
  3883. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3884. if ([items count] == 1) {
  3885. PDFAnnotation *annotation = [[self noteItems:items] lastObject];
  3886. if ([annotation isKindOfClass:[PDFAnnotationStamp class]] ||
  3887. [annotation isKindOfClass:[PDFAnnotationLink class]]) {
  3888. return NO;
  3889. }
  3890. }
  3891. return [items count] > 0;
  3892. }
  3893. return NO;
  3894. }
  3895. - (NSUInteger)outlineView:(NSOutlineView *)ov highlightLevelForRow:(NSInteger)row {
  3896. if ([ov isEqual:leftSideController.tocOutlineView]) {
  3897. NSInteger numRows = [ov numberOfRows];
  3898. NSUInteger firstPage = [[[ov itemAtRow:row] page] pageIndex];
  3899. NSUInteger lastPage = row + 1 < numRows ? [[[ov itemAtRow:row + 1] page] pageIndex] : [[self pdfDocument] pageCount];
  3900. NSRange range = NSMakeRange(firstPage, MAX(1LU, lastPage - firstPage));
  3901. NSUInteger i, iMax = [lastViewedPages count];
  3902. for (i = 0; i < iMax; i++) {
  3903. if (NSLocationInRange((NSUInteger)[lastViewedPages pointerAtIndex:i], range))
  3904. return i;
  3905. }
  3906. }
  3907. return NSNotFound;
  3908. }
  3909. - (id <SKImageToolTipContext>)outlineView:(NSOutlineView *)ov imageContextForItem:(id)item {
  3910. if ([ov isEqual:leftSideController.tocOutlineView])
  3911. return [item destination];
  3912. return nil;
  3913. }
  3914. - (void)outlineViewCommandKeyPressedDuringNavigation:(NSOutlineView *)ov {
  3915. PDFAnnotation *annotation = [[self selectedNotes] lastObject];
  3916. if (annotation) {
  3917. [pdfView scrollAnnotationToVisible:annotation];
  3918. [pdfView setActiveAnnotation:annotation];
  3919. }
  3920. }
  3921. - (NSArray *)outlineView:(NSOutlineView *)ov typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
  3922. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3923. NSInteger i, count = [rightSideController.noteOutlineView numberOfRows];
  3924. NSMutableArray *texts = [NSMutableArray arrayWithCapacity:count];
  3925. for (i = 0; i < count; i++) {
  3926. id item = [rightSideController.noteOutlineView itemAtRow:i];
  3927. NSString *string = [item string];
  3928. [texts addObject:string ?: @""];
  3929. }
  3930. return texts;
  3931. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3932. NSInteger i, count = [leftSideController.tocOutlineView numberOfRows];
  3933. NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
  3934. for (i = 0; i < count; i++)
  3935. [array addObject:[[(PDFOutline *)[leftSideController.tocOutlineView itemAtRow:i] label] lossyStringUsingEncoding:NSASCIIStringEncoding]];
  3936. return array;
  3937. }
  3938. return nil;
  3939. }
  3940. - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
  3941. if ([ov isEqual:rightSideController.noteOutlineView]) {
  3942. [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  3943. } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  3944. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  3945. }
  3946. }
  3947. - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
  3948. if ([typeSelectHelper isEqual:[leftSideController.thumbnailTableView typeSelectHelper]] || [typeSelectHelper isEqual:[pdfView typeSelectHelper]]) {
  3949. if (searchString)
  3950. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  3951. else
  3952. [self updateLeftStatus];
  3953. } else if ([typeSelectHelper isEqual:[rightSideController.noteOutlineView typeSelectHelper]]) {
  3954. if (searchString)
  3955. [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding note: \"%@\"", @"Status message"), searchString]];
  3956. else
  3957. [self updateRightStatus];
  3958. } else if ([typeSelectHelper isEqual:[leftSideController.tocOutlineView typeSelectHelper]]) {
  3959. if (searchString)
  3960. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding: \"%@\"", @"Status message"), searchString]];
  3961. else
  3962. [self updateLeftStatus];
  3963. }
  3964. }
  3965. */
  3966. }
  3967. extension KMLeftSideViewController: NSMenuDelegate {
  3968. func menuNeedsUpdate(_ menu: NSMenu) {
  3969. if menu.isEqual(to: self.tocOutlineView.menu) {
  3970. return
  3971. }
  3972. var item: NSMenuItem?
  3973. menu.removeAllItems()
  3974. if menu.isEqual(to: self.thumbnailTableView.menu) {
  3975. let row = self.thumbnailTableView.clickedRow
  3976. if self.listView.document.documentURL == nil || self.thumbnailTableView.selectedRowIndexes.contains(row) == false{
  3977. return
  3978. }
  3979. if (row != -1 && self.listView.document.isLocked == false) {
  3980. if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
  3981. item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: nil, target: self)
  3982. } else {
  3983. item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: #selector(cutPage), target: self)
  3984. }
  3985. item?.representedObject = IndexSet(integer: row)
  3986. item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(copyPage), target: self)
  3987. item?.representedObject = IndexSet(integer: row)
  3988. if (self._copysPages.count > 0) {
  3989. item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: #selector(pastePage), target: self)
  3990. }else{
  3991. item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: nil, target: self)
  3992. }
  3993. item?.representedObject = IndexSet(integer: row)
  3994. menu.addItem(.separator())
  3995. if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
  3996. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: nil, target: self)
  3997. } else {
  3998. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deletePage), target: self)
  3999. }
  4000. item?.representedObject = IndexSet(integer: row)
  4001. menu.addItem(.separator())
  4002. item = menu.addItem(title: KMLocalizedString("Rotate", "Menu item title"), action: #selector(rotatePage), target: self)
  4003. item?.representedObject = IndexSet(integer: row)
  4004. item = menu.addItem(title: KMLocalizedString("Insert", "Menu item title"), action: nil, target: self)
  4005. let subMenu = NSMenu()
  4006. subMenu.addItem(title: KMLocalizedString("Blank Page", "Menu item title"), action: #selector(quickInsert), target: self)
  4007. subMenu.addItem(title: KMLocalizedString("Blank Page - Custom...", "Menu item title"), action: #selector(insert), target: self)
  4008. subMenu.addItem(title: KMLocalizedString("From PDF", "Menu item title"), action: #selector(insertPDF), target: self)
  4009. item?.submenu = subMenu
  4010. item?.representedObject = IndexSet(integer: row)
  4011. item = menu.addItem(title: KMLocalizedString("Extract", "Menu item title"), action: #selector(extractPage), target: self)
  4012. item?.representedObject = IndexSet(integer: row)
  4013. item = menu.addItem(title: KMLocalizedString("Page Edit", "Menu item title"), action: #selector(pageEdit), target: self)
  4014. menu.addItem(.separator())
  4015. var displayStr = ""
  4016. if (self.isDisplayPageSize) {
  4017. displayStr = KMLocalizedString("Hide Page Size", "Menu item title")
  4018. } else {
  4019. displayStr = KMLocalizedString("Display Page Size", "Menu item title")
  4020. }
  4021. item = menu.addItem(title: displayStr, action: #selector(displayPageSize), target: self)
  4022. item?.representedObject = IndexSet(integer: row)
  4023. item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
  4024. // NSString * tName = [self fileNameWithSelectedPages:leftSideController.thumbnailTableView.selectedRowIndexes];
  4025. // if (tName.length > 50) {
  4026. // tName = [tName substringWithRange:NSMakeRange(0, 50)];
  4027. // }
  4028. var tName = self.listView.document.documentURL.lastPathComponent
  4029. item?.submenu = NSSharingServicePicker.menu(forSharingItems: [self.listView.document.documentURL], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
  4030. }
  4031. }
  4032. // else if ([menu isEqual:[leftSideController.findTableView menu]]) {
  4033. // NSIndexSet *rowIndexes = [leftSideController.findTableView selectedRowIndexes];
  4034. // NSInteger row = [leftSideController.findTableView clickedRow];
  4035. // if (row != -1) {
  4036. // if ([rowIndexes containsIndex:row] == NO)
  4037. // rowIndexes = [NSIndexSet indexSetWithIndex:row];
  4038. // NSArray *selections = [[leftSideController.findArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
  4039. // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  4040. // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Circle", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKCircleNote];
  4041. // [item setRepresentedObject:selections];
  4042. // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Rectangle", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKSquareNote];
  4043. // [item setRepresentedObject:selections];
  4044. // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Highlight", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKHighlightNote];
  4045. // [item setRepresentedObject:selections];
  4046. // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Underline", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKUnderlineNote];
  4047. // [item setRepresentedObject:selections];
  4048. // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Strikethrough", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKStrikeOutNote];
  4049. // [item setRepresentedObject:selections];
  4050. // }
  4051. // }
  4052. // // }
  4053. // // else if ([menu isEqual:[leftSideController.groupedFindTableView menu]]) {
  4054. // // NSIndexSet *rowIndexes = [leftSideController.groupedFindTableView selectedRowIndexes];
  4055. // // NSInteger row = [leftSideController.groupedFindTableView clickedRow];
  4056. // // if (row != -1) {
  4057. // // if ([rowIndexes containsIndex:row] == NO)
  4058. // // rowIndexes = [NSIndexSet indexSetWithIndex:row];
  4059. // // NSArray *selections = [[[leftSideController.groupedFindArrayController arrangedObjects] objectsAtIndexes:rowIndexes] valueForKeyPath:@"@unionOfArrays.matches"];
  4060. // // item = [menu addItemWithTitle:NSLocalizedString(@"Select", @"Menu item title") action:@selector(selectSelections:) target:self];
  4061. // // [item setRepresentedObject:selections];
  4062. // // [menu addItem:[NSMenuItem separatorItem]];
  4063. // // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  4064. // // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Circle", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKCircleNote];
  4065. // // [item setRepresentedObject:selections];
  4066. // // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Rectangle", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKSquareNote];
  4067. // // [item setRepresentedObject:selections];
  4068. // // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Highlight", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKHighlightNote];
  4069. // // [item setRepresentedObject:selections];
  4070. // // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Underline", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKUnderlineNote];
  4071. // // [item setRepresentedObject:selections];
  4072. // // item = [menu addItemWithTitle:NSLocalizedString(@"Add New Strikethrough", @"Menu item title") action:@selector(addAnnotationsForSelections:) target:self tag:SKStrikeOutNote];
  4073. // // [item setRepresentedObject:selections];
  4074. // // }
  4075. // // }
  4076. // } else if ([menu isEqual:[rightSideController.snapshotTableView menu]]) {
  4077. // NSInteger row = [rightSideController.snapshotTableView clickedRow];
  4078. // if (row != -1) {
  4079. // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
  4080. //
  4081. // if ([[controller window] isVisible]) {
  4082. // item = [menu addItemWithTitle:NSLocalizedString(@"Hide", @"Menu item title") action:@selector(hideSnapshot:) target:self];
  4083. // [item setRepresentedObject:controller];
  4084. // } else {
  4085. // item = [menu addItemWithTitle:NSLocalizedString(@"Show", @"Menu item title") action:@selector(showSnapshot:) target:self];
  4086. // [item setRepresentedObject:controller];
  4087. // }
  4088. // [menu addItem:[NSMenuItem separatorItem]];
  4089. //
  4090. // item = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil target:self];
  4091. // NSMenu *subMenu = [NSMenu menu];
  4092. //
  4093. // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(menuItemClick_ExportPNG:) target:self];
  4094. // [t setRepresentedObject:controller];
  4095. //
  4096. // t = [subMenu addItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(menuItemClick_ExportJPG:) target:self];
  4097. // [t setRepresentedObject:controller];
  4098. //
  4099. // t = [subMenu addItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(menuItemClick_ExportPDF:) target:self];
  4100. // [t setRepresentedObject:controller];
  4101. // item.submenu = subMenu;
  4102. //
  4103. // item = [menu addItemWithTitle:NSLocalizedString(@"Print", @"Menu item title") action:@selector(menuItemClick_Print:) target:self];
  4104. // [item setRepresentedObject:controller];
  4105. // [menu addItem:[NSMenuItem separatorItem]];
  4106. //
  4107. // item = [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") action:@selector(menuItemClick_Copy:) target:self];
  4108. // [item setRepresentedObject:controller];
  4109. // [menu addItem:[NSMenuItem separatorItem]];
  4110. //
  4111. // item = [menu addItemWithTitle:NSLocalizedString(@"Delete", @"Menu item title") action:@selector(deleteSnapshot:) target:self];
  4112. // [item setRepresentedObject:controller];
  4113. // item = [menu addItemWithTitle:NSLocalizedString(@"Delete All Snapshots", @"Menu item title") action:@selector(deleteAllSnapshot:) target:self];
  4114. // [item setRepresentedObject:controller];
  4115. // }
  4116. // } else if ([menu isEqual:[rightSideController.noteOutlineView menu]]) {
  4117. // NSArray *items;
  4118. // NSIndexSet *rowIndexes = [rightSideController.noteOutlineView selectedRowIndexes];
  4119. // NSInteger row = [rightSideController.noteOutlineView clickedRow];
  4120. // if (row != -1) {
  4121. // if ([rowIndexes containsIndex:row] == NO)
  4122. // rowIndexes = [NSIndexSet indexSetWithIndex:row];
  4123. // items = [rightSideController.noteOutlineView itemsAtRowIndexes:rowIndexes];
  4124. //
  4125. // PDFAnnotation *foldNote = (PDFAnnotation *)notes[row];
  4126. // BOOL isFold = YES;
  4127. // if ([rightSideController.allFoldNotes containsObject:foldNote]) {
  4128. // isFold = NO;
  4129. // }
  4130. // item = [menu addItemWithTitle:NSLocalizedString(@"Expand", nil) action:@selector(unfoldNoteAction:) target:self];
  4131. // if (isFold)
  4132. // [item setState:NSControlStateValueOff];
  4133. // else
  4134. // [item setState:NSControlStateValueOn];
  4135. // [item setRepresentedObject:items];
  4136. // item = [menu addItemWithTitle:NSLocalizedString(@"Collapse", nil) action:@selector(foldNoteAction:) target:self];
  4137. // if (isFold)
  4138. // [item setState:NSControlStateValueOn];
  4139. // else
  4140. // [item setState:NSControlStateValueOff];
  4141. // [item setRepresentedObject:items];
  4142. //
  4143. // //UX改版删除
  4144. // // if ([self outlineView:rightSideController.noteOutlineView canCopyItems:items]) {
  4145. // // item = [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") action:@selector(copyNotes:) target:self];
  4146. // // [item setRepresentedObject:items];
  4147. // // }
  4148. // [menu addItem:[NSMenuItem separatorItem]];
  4149. // if ([pdfView hideNotes] == NO && [items count] == 1) {
  4150. // PDFAnnotation *annotation = [[self noteItems:items] lastObject];
  4151. // if ([annotation isEditable]) {
  4152. // if ([(PDFAnnotation *)[items lastObject] type] == nil) {
  4153. // if ([[(SKNoteText *)[items lastObject] note] isNote]) {
  4154. // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editNoteTextFromTable:) target:self];
  4155. // [item setRepresentedObject:annotation];
  4156. // }
  4157. // } else if ([[rightSideController.noteOutlineView tableColumnWithIdentifier:NOTE_COLUMNID] isHidden]) {
  4158. // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
  4159. // [item setRepresentedObject:annotation];
  4160. // } else {
  4161. // item = [menu addItemWithTitle:NSLocalizedString(@"Edit", @"Menu item title") action:@selector(editNoteFromTable:) target:self];
  4162. // [item setRepresentedObject:annotation];
  4163. // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
  4164. // [item setRepresentedObject:annotation];
  4165. // [item setKeyEquivalentModifierMask:NSEventModifierFlagOption];
  4166. // [item setAlternate:YES];
  4167. // }
  4168. // }
  4169. // // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
  4170. // // if ([pdfView activeAnnotation] == annotation) {
  4171. // // item = [menu addItemWithTitle:NSLocalizedString(@"Deselect", @"Menu item title") action:@selector(deselectNote:) target:self];
  4172. // // [item setRepresentedObject:annotation];
  4173. // // } else {
  4174. // // item = [menu addItemWithTitle:NSLocalizedString(@"Select", @"Menu item title") action:@selector(selectNote:) target:self];
  4175. // // [item setRepresentedObject:annotation];
  4176. // // }
  4177. // // item = [menu addItemWithTitle:NSLocalizedString(@"Show", @"Menu item title") action:@selector(revealNote:) target:self];
  4178. // // [item setRepresentedObject:annotation];
  4179. // // }
  4180. // }
  4181. // // if ([menu numberOfItems] > 0)
  4182. // // [menu addItem:[NSMenuItem separatorItem]];
  4183. // // item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Auto Size Row", @"Menu item title") : NSLocalizedString(@"Auto Size Rows", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
  4184. // // [item setRepresentedObject:items];
  4185. // // item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Undo Auto Size Row", @"Menu item title") : NSLocalizedString(@"Undo Auto Size Rows", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
  4186. // // [item setRepresentedObject:items];
  4187. // // [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
  4188. // // [item setAlternate:YES];
  4189. // // [menu addItemWithTitle:NSLocalizedString(@"Auto Size All", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
  4190. // // item = [menu addItemWithTitle:NSLocalizedString(@"Undo Auto Size All", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
  4191. // // [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
  4192. // // [item setAlternate:YES];
  4193. // // [menu addItemWithTitle:NSLocalizedString(@"Automatically Resize", @"Menu item title") action:@selector(toggleAutoResizeNoteRows:) target:self];
  4194. //
  4195. // if ([menu numberOfItems] > 0) {
  4196. // // [menu addItem:[NSMenuItem separatorItem]];
  4197. // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Export Annotations…", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4198. //
  4199. // NSMenu *subMenu = [NSMenu menu];
  4200. // item.submenu = subMenu;
  4201. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4202. // item.tag = 0;
  4203. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Bundle", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4204. // item.tag = 1;
  4205. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Reader Pro Edition Notes", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4206. // item.tag = 2;
  4207. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as Text", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4208. // item.tag = 3;
  4209. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4210. // item.tag = 4;
  4211. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTFD", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4212. // item.tag = 5;
  4213. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as FDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4214. // item.tag = 6;
  4215. //
  4216. // [menu addItem:[NSMenuItem separatorItem]];
  4217. // if ([self outlineView:rightSideController.noteOutlineView canDeleteItems:items]) {
  4218. // item = [menu addItemWithTitle:NSLocalizedString(@"Delete", @"Menu item title") action:@selector(deleteNotes:) target:self];
  4219. // [item setRepresentedObject:items];
  4220. // }
  4221. // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Remove All Annotations", @"MainMenu", @"Menu item title") action:@selector(removeAllAnnotations:) target:self];
  4222. // }
  4223. //
  4224. //
  4225. // } else {
  4226. // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Export Annotations…", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4227. //
  4228. // NSMenu *subMenu = [NSMenu menu];
  4229. // item.submenu = subMenu;
  4230. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4231. // item.tag = 0;
  4232. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Bundle", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4233. // item.tag = 1;
  4234. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Reader Pro Edition Notes", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4235. // item.tag = 2;
  4236. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as Text", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4237. // item.tag = 3;
  4238. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4239. // item.tag = 4;
  4240. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTFD", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4241. // item.tag = 5;
  4242. // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as FDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
  4243. // item.tag = 6;
  4244. //
  4245. // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Remove All Annotations", @"MainMenu", @"Menu item title") action:@selector(removeAllAnnotations:) target:self];
  4246. // }
  4247. // }
  4248. }
  4249. }
  4250. // MARK: - Menu Item Actions
  4251. extension KMLeftSideViewController {
  4252. @objc func cutPage(_ sender: AnyObject?) {
  4253. KMPrint("KMLeftSideViewController-cutPage...")
  4254. // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  4255. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  4256. // return;
  4257. // }
  4258. // [self tableView:leftSideController.thumbnailTableView cutRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
  4259. }
  4260. @objc func copyPage(_ sender: AnyObject?) {
  4261. KMPrint("KMLeftSideViewController-copyPage...")
  4262. // [self tableView:leftSideController.thumbnailTableView copyRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
  4263. }
  4264. @objc func pastePage(_ sender: AnyObject?) {
  4265. KMPrint("KMLeftSideViewController-pastePage...")
  4266. // [self tableView:leftSideController.thumbnailTableView pasteFromPasteboard:nil];
  4267. }
  4268. @objc func deletePage(_ sender: AnyObject?) {
  4269. KMPrint("KMLeftSideViewController-deletePage...")
  4270. // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  4271. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  4272. // return;
  4273. // }
  4274. // [self tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
  4275. }
  4276. @objc func rotatePage(_ sender: AnyObject?) {
  4277. KMPrint("KMLeftSideViewController-rotatePage...")
  4278. // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  4279. // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  4280. // return;
  4281. // }
  4282. //
  4283. // [self tableView:leftSideController.thumbnailTableView rotateRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
  4284. }
  4285. @objc func quickInsert(_ sender: AnyObject?) {
  4286. KMPrint("KMLeftSideViewController-quickInsert...")
  4287. }
  4288. @objc func insert(_ sender: AnyObject?) {
  4289. KMPrint("KMLeftSideViewController-insert...")
  4290. }
  4291. @objc func insertPDF(_ sender: AnyObject?) {
  4292. KMPrint("KMLeftSideViewController-insertPDF...")
  4293. }
  4294. @objc func extractPage(_ sender: AnyObject?) {
  4295. KMPrint("KMLeftSideViewController-extractPage...")
  4296. }
  4297. @objc func pageEdit(_ sender: AnyObject?) {
  4298. KMPrint("KMLeftSideViewController-pageEdit...")
  4299. }
  4300. @objc func displayPageSize(_ sender: AnyObject?) {
  4301. KMPrint("KMLeftSideViewController-displayPageSize...")
  4302. }
  4303. @objc func sharePage(_ sender: AnyObject?) {
  4304. KMPrint("KMLeftSideViewController-sharePage...")
  4305. }
  4306. private func _tableView(_ tv: NSTableView, cutRowsWithIndexes rowIndexes: IndexSet) {
  4307. // if tv.isEqual(to: self.thumbnailTableView) {
  4308. // self._copysPages.removeAll()
  4309. // for i in rowIndexes {
  4310. // if (idx != NSNotFound) {
  4311. // let page = self.listView.document.page(at: idx)
  4312. // self._copysPages.append(page)
  4313. // }
  4314. // }
  4315. // [self tableView:tv deleteRowsWithIndexes:rowIndexes];
  4316. // }
  4317. }
  4318. }