KMLeftSideViewController.swift 284 KB

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