KMLeftSideViewController.swift 285 KB

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