KMLeftSideViewController.swift 289 KB

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