123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367 |
- //
- // KMLeftSideViewController.swift
- // PDF Reader Pro
- //
- // Created by lxy on 2022/10/10.
- //
- import Cocoa
- @objc protocol KMLeftSideViewControllerDelegate {
- @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
- @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
- @objc optional func searchAction(searchString:String, isCase:Bool)
-
- @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
- @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
-
- @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
- @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
- }
- class KMLeftSideViewController: KMSideViewController {
- var dataSource : [KMLeftMethodMode] = [KMLeftMethodMode]()
- var type : KMLeftMethodMode = KMLeftMethodMode()
- var isShowPanel : Bool = false
- var norImage : [String] = []
- var selectImage : [String] = []
- var mainVC: KMMainViewController?
- var selectPages: [Int]?
- open weak var delegate: KMLeftSideViewControllerDelegate?
-
- deinit {
- KMPrint("KMLeftSideViewController deinit.")
-
- NotificationCenter.default.removeObserver(self)
- }
-
- override var nibName: NSNib.Name? {
- return "LeftSideView"
- }
-
- convenience init(type : KMLeftMethodMode) {
- self.init()
- self.type = type
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.reloadThumbnailSize()
- self.reloadSnapshotSize()
-
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
- self.isDisplayPageSize = UserDefaults.standard.bool(forKey: "kKMThumbnailDisplayPageSizeKey")
- }
-
- func showPanelView(show: Bool) {
- self.isShowPanel = show
- if show {
- self.leftView.segmentedControl.selectedSegment = 0
- } else {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.delegate?.controlStateChange?(self, show: false)
- }
- }
-
- func refreshMethodType(methodType: BotaType) {
- let newType = KMLeftMethodMode()
- var show = true
- if self.type.methodType != methodType {
- newType.methodType = methodType
- }
- if self.type.methodType == methodType {
- show = false
- } else if methodType == .None {
- show = false
- }
- self.type = newType;
- self.delegate?.controlStateChange?(self,show:show)
- }
-
- // MARK: - New
- /*
- NSArrayController *findArrayController;
- NSArrayController *groupedFindArrayController;
- }
- - (void)applySearchTableHeader:(NSString *)message;
- */
-
- @IBOutlet var segmentedControl: KMSegmentedControl!
-
- @IBOutlet var thumbnailTableView: KMThumbnailTableView!
- @IBOutlet var tocOutlineView: KMTocOutlineView!
- @IBOutlet var noteOutlineView: KMNoteOutlineView!
- @IBOutlet var findTableView: KMBotaTableView!
- @IBOutlet var groupedFindTableView: KMBotaTableView!
- @IBOutlet var snapshotTableView: KMBotaTableView!
-
- @IBOutlet weak var leftListView: NSView!
-
- @IBOutlet var searchViewController: KMBotaSearchViewController!
- @IBOutlet weak var toolButtonBox: NSBox!
- @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
- @IBOutlet weak var snapshotNormalView: NSView!
- @IBOutlet weak var snapshotLabel: NSTextField!
- @IBOutlet weak var snapshotNormalMoreButton: NSButton!
- @IBOutlet weak var snapshotNormalSearchButton: NSButton!
- @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
- @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
- @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
- @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
- @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var snapshotDoneButton: NSButton!
-
- @IBOutlet weak var outlineView: NSView!
- @IBOutlet weak var outlineMoreButton: NSButton!
- @IBOutlet weak var outlineAddButton: NSButton!
- @IBOutlet weak var outlineSearchButton: NSButton!
- @IBOutlet weak var outlineLabel: NSTextField!
- @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var outlineDoneButton: NSButton!
-
- @IBOutlet weak var noteView: NSView!
- @IBOutlet weak var noteMoreButton: NSButton!
- @IBOutlet weak var noteFilterButton: NSButton!
- @IBOutlet weak var noteSearchButton: NSButton!
- @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var noteTitleLabel: NSTextField!
- @IBOutlet weak var noteHeaderView: NSView!
- @IBOutlet weak var sortTypeBox: KMBox!
- @IBOutlet weak var sortTypeLabel: NSTextField!
- @IBOutlet weak var noteSortButton: NSButton!
- @IBOutlet weak var noteDoneButton: NSButton!
-
- @IBOutlet weak var thumbnailView: NSView!
- @IBOutlet weak var thumbnailZoomOutButton: NSButton!
- @IBOutlet weak var thumbnailZoomInButton: NSButton!
- @IBOutlet weak var thumbnailTitleLabel: NSTextField!
-
- @IBOutlet weak var emptySearchBox: NSBox!
- @IBOutlet weak var emptySearchLabel: NSTextField!
-
- var filterButtonLayer: NSView?
- var moreButtonLayer: KMButtonLayer?
-
- var thumbnails: [KMThumbnail] = []
- var isDisplayPageSize = false
- var thumbnailCacheSize: CGFloat = 32 * 3
- var snapshotCacheSize: CGFloat = 32 * 3
- private var _findState: KMFindState = .none
- var findState: KMFindState {
- get {
- return self._findState
- }
- set {
- if self._findState != newValue {
- self._findState = newValue
-
- self.displayFindState()
- if self._findState == .content {
- self.search(self.searchField)
- } else if self.findState == .note {
- // self.searchNotes(self.searchField)
- self.searchNotes(nil)
- } else if self.findState == .snapshot {
- self.searchNotes(self.searchField)
- }
- }
- }
- }
-
- var searchResults : [KMSearchMode] = [] {
- didSet {
- self.updataLeftSideFindView()
- }
- }
- var groupSearchResults: [KMSearchMode] = []
- var findPaneState: KMFindPaneState = .singular
- var isSearchOutlineMode = false
- var isSearchSnapshotMode = false
- var outlineIgnoreCaseFlag = false
- var noteTypeDict: [String : Any] = [:]
-
- private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
- private let LABEL_COLUMNID = "label"
- var foldType: KMFoldAllAnnotationType = .none
- private let KMLeftSideViewNoteSortTypeKey = "KMLeftSideViewNoteSortTypeKey"
- private let KMLeftSideViewAscendSortBoolKey = "KMLeftSideViewAscendSortBoolKey"
- private let SKDisableTableToolTipsKey = "SKDisableTableToolTips"
-
- var tocType: KMFoldType = .none
-
- var snapshots: [KMSnapshotModel] = []
- var searchSnapshots: [KMSnapshotModel] = []
-
- private var _noteSortType: KMNoteSortType = .none
- var noteSortType: KMNoteSortType {
- get {
- return self._noteSortType
- }
- set {
- self._noteSortType = newValue
-
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
- }
- }
-
- var isAscendSort = false {
- didSet {
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
- }
- }
-
- lazy var leftSideEmptyVC: KMLeftSideEmptyFileViewController = {
- let vc = KMLeftSideEmptyFileViewController(nibName: "KMLeftSideEmptyFileViewController", bundle: nil)
- vc.view.wantsLayer = true
- return vc
- }()
-
- var preThumbnailRow: Int = 0
- var leftMargin: CGFloat = 0
-
- lazy var leftView: KMBotaLeftView = {
- let view = KMBotaLeftView()
- return view
- }()
-
- private var _copysPages: [CPDFPage] = []
- var copyPages: [CPDFPage] {
- get {
- return self._copysPages
- }
- }
- private var _annotations: [KMBOTAAnnotationSection] = []
- private var _allAnnotations: [CPDFAnnotation] = []
- var allAnnotations: [CPDFAnnotation] {
- get {
- return self._allAnnotations
- }
- }
-
- private let kKMPDFViewOutlineDragDataType = "kKMPDFViewOutlineDragDataType"
- private let KPDFThumbnailDoucumentURLForDraggedTypes = NSPasteboard.PasteboardType("KPDFThumbnailDoucumentURLForDraggedTypes")
-
- var renamePDFOutline: CPDFOutline?
- var renamePDFOutlineTextField: NSTextField?
- var allFoldNotes: [CPDFAnnotation] = []
- var notes: [CPDFAnnotation] = []
- var canFoldNotes: [CPDFAnnotation] = []
-
- var isRenameNoteOutline = false
- var caseInsensitiveNoteSearch = false
- var noteSearchArray: [CPDFAnnotation] = []
- var noteSearchMode = false
-
- var mwcFlags: MwcFlags = MwcFlags()
-
- override func loadView() {
- super.loadView()
-
- self.view.wantsLayer = true
- self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.view.addSubview(self.leftView)
- self.leftView.frame = NSMakeRect(0, 0, 44, NSHeight(self.view.frame))
- self.leftView.autoresizingMask = [.height]
- self.leftView.wantsLayer = true
- self.leftView.layer?.backgroundColor = .white
-
- self.outlineView.wantsLayer = true
- self.outlineView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.noteView.wantsLayer = true
- self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.thumbnailView.wantsLayer = true
- self.thumbnailView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.snapshotNormalView.wantsLayer = true
- self.snapshotNormalView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.tocOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
- self.noteOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
- self.findTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.groupedFindTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.snapshotTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.thumbnailTableView.backgroundColor = KMAppearance.Layout.l0Color()
-
- self.leftListView.wantsLayer = true
- self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
- self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
- self.emptySearchBox.isHidden = true
-
- self.thumbnailTitleLabel.stringValue = KMLocalizedString("Thumbnails", nil)
- self.thumbnailTitleLabel.textColor = KMAppearance.Layout.h0Color()
- self.thumbnailZoomInButton.action = #selector(thumbnailSizeScaling)
- self.thumbnailZoomInButton.target = self
- self.thumbnailZoomInButton.tag = 1
- self.thumbnailZoomOutButton.action = #selector(thumbnailSizeScaling)
- self.thumbnailZoomOutButton.target = self
- self.thumbnailZoomOutButton.tag = 0
-
- self.snapshotTableView.delegate = self
- self.snapshotTableView.dataSource = self
- self.snapshotTableView.menu = NSMenu()
- self.snapshotTableView.menu?.delegate = self
- self.snapshotTableView.doubleAction = #selector(toggleSelectedSnapshots)
- self.snapshotTableView.target = self
- self.snapshotTableView.backgroundColor = .clear
- // [snapshotTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
- self.snapshotLabel.stringValue = KMLocalizedString("Snapshots", nil)
- self.snapshotLabel.textColor = KMAppearance.Layout.h0Color()
- self.snapshotNormalZoomInButton.action = #selector(thumbnailSizeScaling)
- self.snapshotNormalZoomInButton.target = self
- self.snapshotNormalZoomInButton.tag = 2
- self.snapshotNormalZoomOutButton.action = #selector(thumbnailSizeScaling)
- self.snapshotNormalZoomOutButton.target = self
- self.snapshotNormalZoomOutButton.tag = 3
- self.snapshotNormalSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.snapshotNormalMoreButton.action = #selector(leftSideViewMoreButtonAction)
- self.snapshotNormalMoreButton.target = self
- self.snapshotNormalMoreButton.tag = 300
-
- self.snapshotSearchZoomInButton.action = #selector(thumbnailSizeScaling)
- self.snapshotSearchZoomInButton.target = self
- self.snapshotSearchZoomInButton.tag = 2
- self.snapshotSearchZoomOutButton.action = #selector(thumbnailSizeScaling)
- self.snapshotSearchZoomOutButton.target = self
- self.snapshotSearchZoomOutButton.tag = 3
- self.snapshotDoneButton.title = KMLocalizedString("Done", nil)
- self.snapshotDoneButton.toolTip = KMLocalizedString("Done", nil)
- self.snapshotDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.snapshotDoneButton.wantsLayer = true
- self.snapshotDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.snapshotDoneButton.layer?.cornerRadius = 4.0
- self.snapshotDoneButton.action = #selector(leftSideViewDoneButtonAction)
- self.snapshotDoneButton.target = self
- self.snapshotDoneButton.tag = 312
- self.snapshotDoneButton.isHidden = true
-
- self.noteOutlineView.autoresizesOutlineColumn = false
-
- self.noteOutlineView.delegate = self
- self.noteOutlineView.dataSource = self
- self.noteOutlineView.botaDelegate = self
- self.noteOutlineView.botaDataSource = self
- self.noteOutlineView.noteDelegate = self
- self.noteOutlineView.menu = NSMenu()
- self.noteOutlineView.menu?.delegate = self
- // [noteOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
- self.noteOutlineView.indentationPerLevel = 0
- // [noteOutlineView registerForDraggedTypes:[NSColor readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]];
- self.noteOutlineView.target = self
- self.noteOutlineView.doubleAction = #selector(selectSelectedNote)
-
- self.tocOutlineView.menu = NSMenu()
- self.tocOutlineView.menu?.delegate = self
- self.outlineSearchField.delegate = self
- self.snapshotSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
- self.outlineSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
- self.noteSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
- self.snapshotSearchField.wantsLayer = true
- self.outlineSearchField.wantsLayer = true
- self.noteSearchField.wantsLayer = true
- self.snapshotSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.outlineSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.noteSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.snapshotSearchField.layer?.borderWidth = 1.0
- self.outlineSearchField.layer?.borderWidth = 1.0
- self.noteSearchField.layer?.borderWidth = 1.0
- self.snapshotSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.outlineSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.noteSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
-
- // __block typeof(self) blockSelf = self;
- // _snapshotSearchField.changeCallBack = ^(NSString *changeContent) {
- // NSString *editContent = @"";
- // if (changeContent) {
- // editContent = changeContent;
- // }
- // [blockSelf.mainController searchFieldChangeAction:editContent];
- // };
- self.snapshotSearchField.isHidden = true
- self.snapshotSearchZoomOutButton.isHidden = true
- self.snapshotSearchZoomInButton.isHidden = true
- // _snapshotSearchField.endEditCallBack = ^(BOOL isEndEdit) {
- // if (isEndEdit/* && searchViewController.segmentedControl.segmentCount == 3*/) {
- // _snapshotSearchField.hidden = YES;
- // _snapshotSearchZoomOutButton.hidden = YES;
- // _snapshotSearchZoomInButton.hidden = YES;
- // _snapshotLabel.hidden = NO;
- // _snapshotNormalZoomOutButton.hidden = NO;
- // _snapshotNormalZoomInButton.hidden = NO;
- // }
- // };
- self.thumbnailZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
- self.snapshotNormalZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
- self.snapshotSearchZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
- self.thumbnailZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
- self.snapshotNormalZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
- self.snapshotSearchZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
-
- self.outlineLabel.stringValue = KMLocalizedString("Outline", nil);
- self.outlineLabel.textColor = KMAppearance.Layout.h0Color()
- self.outlineAddButton.toolTip = KMLocalizedString("Add Item", nil)
- self.outlineAddButton.action = #selector(outlineContextMenuItemClicked_AddEntry)
- self.outlineAddButton.target = self
- self.outlineSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.outlineMoreButton.action = #selector(leftSideViewMoreButtonAction)
- self.outlineMoreButton.target = self
- self.outlineMoreButton.tag = 302
- self.outlineDoneButton.title = KMLocalizedString("Done", nil);
- self.outlineDoneButton.toolTip = KMLocalizedString("Done", nil);
- self.outlineDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.outlineDoneButton.wantsLayer = true
- self.outlineDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.outlineDoneButton.layer?.cornerRadius = 4.0
- self.outlineDoneButton.action = #selector(leftSideViewDoneButtonAction)
- self.outlineDoneButton.target = self
- self.outlineDoneButton.tag = 310
- self.outlineDoneButton.isHidden = true
- self.outlineSearchField.isHidden = true
- // _outlineSearchField.endEditCallBack = ^(BOOL isEndEdit) {
- // if (isEndEdit) {
- // _outlineSearchField.hidden = YES;
- // _outlineLabel.hidden = NO;
- // _outlineSearchButton.hidden = NO;
- // }
- // };
- let menuOutline = NSMenu()
- menuOutline.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleOutlineCaseInsensitiveSearch), target: self)
- (self.outlineSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menuOutline
- (self.outlineSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Outline", nil)
- self.outlineSearchField.target = self
-
- let sud = UserDefaults.standard
- self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
- self.noteTitleLabel.textColor = KMAppearance.Layout.h0Color()
- self.noteMoreButton.action = #selector(leftSideViewMoreButtonAction)
- self.noteMoreButton.target = self
- self.noteMoreButton.tag = 304
- self.noteMoreButton.wantsLayer = true
- self.moreButtonLayer = KMButtonLayer()
- self.noteMoreButton.layer?.addSublayer(self.moreButtonLayer!)
- self.moreButtonLayer?.frame = CGRectMake(0, 0, CGRectGetWidth(self.noteMoreButton.bounds), CGRectGetHeight(self.noteMoreButton.bounds))
- self.moreButtonLayer?.layerType = .none
- self.moreButtonLayer?.isHidden = true
-
- self.noteFilterButton.action = #selector(noteFilterAction)
- self.noteFilterButton.target = self
- self.noteFilterButton.toolTip = KMLocalizedString("Sort", nil)
- self.noteFilterButton.wantsLayer = true
- self.filterButtonLayer = NSView()
- self.noteFilterButton.addSubview(self.filterButtonLayer!)
- self.filterButtonLayer?.frame = CGRectMake(14, 2, 8, 8)
- self.filterButtonLayer?.isHidden = true
- self.filterButtonLayer?.wantsLayer = true
- self.filterButtonLayer?.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.filterButtonLayer?.layer?.cornerRadius = 4.0
-
- self.noteDoneButton.title = KMLocalizedString("Done", nil)
- self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
- self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.noteDoneButton.wantsLayer = true
- self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.noteDoneButton.layer?.cornerRadius = 4.0
- self.noteDoneButton.action = #selector(leftSideViewDoneButtonAction)
- self.noteDoneButton.target = self
- self.noteDoneButton.tag = 311
- self.noteDoneButton.isHidden = true
-
- self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.noteSearchField.delegate = self
- self.noteSearchField.isHidden = true
- self.noteSearchField.endEditCallBack = { [unowned self] isEndEdit in
- if (isEndEdit) {
- self.noteSearchField.isHidden = true
- self.noteSearchButton.isHidden = false
- self.noteTitleLabel.isHidden = false
- }
- };
- self.noteHeaderView.wantsLayer = true
- self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
- self.noteHeaderView.layer?.cornerRadius = 1.0
- let sortType = sud.integer(forKey: KMLeftSideViewNoteSortTypeKey)
- if (sortType == 1) {
- self.noteSortType = KMNoteSortType(rawValue: sortType)!
- if (self.noteSortType == .time) {
- self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
- } else if (self._noteSortType == .page) {
- self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
- }
- } else {
- self.noteSortType = .time
- self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
- }
- self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
-
- self.isAscendSort = sud.bool(forKey: KMLeftSideViewAscendSortBoolKey)
- if (self.isAscendSort) {
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
- self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
- } else {
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
- self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
- }
-
- self.sortTypeBox.downCallback = { [unowned self] downEntered, mouseBox, _ in
- if (downEntered) {
- let menu = NSMenu()
- let timeItem = menu.addItem(title: KMLocalizedString("Time", nil), action: #selector(sortTypeAction), target: self)
- timeItem?.representedObject = self
- timeItem?.tag = 0
- let pageItem = menu.addItem(title: KMLocalizedString("Page", nil), action: #selector(sortTypeAction), target: self)
- pageItem?.representedObject = self
- timeItem?.tag = 1
- if (self.noteSortType == .time) {
- timeItem?.state = .on
- pageItem?.state = .off
- } else if (self.noteSortType == .page) {
- timeItem?.state = .off
- pageItem?.state = .on
- }
- menu.popUp(positioning: nil, at: CGPointMake(-10, 0), in: self.sortTypeBox)
- }
- }
-
- self.searchViewController.loadView()
- self.searchViewController.contentView = self.findTableView.enclosingScrollView
- self.searchField = self.searchViewController.searchField
-
- self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
- self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
- self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
- self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
- self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
- self.searchViewController.segmentedControl.isBackgroundHighlighted = true
- self.searchViewController.segmentedControl.selectedSegment = 0
- self.searchViewController.segmentedControl.block = { [unowned self] segIndex in
- if segIndex == 0 {
- self.findPaneState = .singular
- self.displayFindViewAnimating(false)
- } else {
- self.findPaneState = .grouped
- self.displayGroupedFindViewAnimating(false)
- }
- }
- self.leftView.segmentedControl.block = { [unowned self] segIndex in
- self.toolButtonBox.isHidden = false
- self.toolButtonBoxLayoutConstraint.constant = 40.0
-
- if (segIndex == 0) {
- if self.type.methodType == .Thumbnail {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Thumbnail)
- DispatchQueue.main.async {
- self.toolButtonBox.contentView = self.thumbnailView
- self.displayThumbnailViewAnimating(false)
- }
- } else if (segIndex == 1) {
- if self.type.methodType == .Outline {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Outline)
- DispatchQueue.main.async {
- self.toolButtonBox.contentView = self.outlineView
- self.displayTocViewAnimating(false)
- }
- } else if (segIndex == 2) {
- if self.type.methodType == .Annotation {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Annotation)
- DispatchQueue.main.async {
- self.toolButtonBox.contentView = self.noteView
- self.displayNoteViewAnimating(false)
- }
- } else if (segIndex == 3) {
- self.toolButtonBox.contentView = self.snapshotNormalView
- self.updateSnapshotFilterPredicate()
- self.displaySnapshotViewAnimating(false)
- self.updataLeftSideSnapView()
- } else if (segIndex == 4) {
- if self.type.methodType == .Search {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Search)
- DispatchQueue.main.async {
- self.toolButtonBox.isHidden = true
- self.toolButtonBoxLayoutConstraint.constant = 0
- self.displayFindViewAnimating(false)
- }
- }
- }
-
- // self.button.setHelp(KMLocalizedString("View Thumbnails", "Tool tip message"), for: KMLeftSidePaneState.thumbnail.rawValue)
- // self.button.setHelp(KMLocalizedString("View Outline", "Tool tip message"), for: KMLeftSidePaneState.outline.rawValue)
- // self.alternateButton.setHelp(KMLocalizedString("Separate search results", "Tool tip message"), for: KMFindPaneState.singular.rawValue)
- // self.alternateButton.setHelp(KMLocalizedString("Group search results by page", "Tool tip message"), for: KMFindPaneState.grouped.rawValue)
-
- let menu = NSMenu()
- menu.addItem(title: KMLocalizedString("Whole Words Only", "Menu item title"), action: #selector(toggleWholeWordSearch), target: self)
- menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveSearch), target: self)
- (self.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
-
- self.searchField.action = #selector(search)
- self.searchField.target = self
-
- self.tocOutlineView.autoresizesOutlineColumn = false
- self.tocOutlineView.allowsMultipleSelection = true
- self.tocOutlineView.allowsEmptySelection = true
- self.tocOutlineView.delegate = self
- self.tocOutlineView.dataSource = self
- self.tocOutlineView.botaDelegate = self
- self.tocOutlineView.botaDataSource = self
- self.tocOutlineView.tocDelegate = self
-
- self.thumbnailTableView.delegate = self
- self.thumbnailTableView.dataSource = self
- self.thumbnailTableView.thumbDelegate = self
- self.thumbnailTableView.allowsMultipleSelection = true
- self.findTableView.delegate = self
- self.findTableView.dataSource = self
- self.findTableView.botaDelegate = self
- self.groupedFindTableView.delegate = self
- self.groupedFindTableView.dataSource = self
- self.groupedFindTableView.botaDelegate = self
- self.thumbnailTableView.menu?.delegate = self
- self.findTableView.menu?.delegate = self
- self.groupedFindTableView.menu?.delegate = self
-
- self.tocOutlineView.doubleAction = #selector(goToSelectedOutlineItem)
- self.tocOutlineView.target = self
- self.findTableView.doubleAction = #selector(goToSelectedFindResults)
- self.findTableView.target = self
- self.groupedFindTableView.doubleAction = #selector(goToSelectedFindResults)
- self.groupedFindTableView.target = self
-
- // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
- // //支持拖拽的文字类型
- // [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
- // self.thumbnailTableView.registerForDraggedTypes([.localDraggedTypes, .fileURL])
- self.thumbnailTableView.registerForDraggedTypes([.localDraggedTypes, .fileURL,.string,.pdf])
- // self.thumbnailTableView.registerForDraggedTypes(NSFilePromiseReceiver.readableDraggedTypes.map { NSPasteboard.PasteboardType($0) })
- // self.thumbnailTableView.setDraggingSourceOperationMask([.copy, .delete], forLocal: true)
- // [tocOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
- // [tocOutlineView registerForDraggedTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType]];
- // [[[findTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
- // [[[groupedFindTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
- // [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] dataCell] setEnabled:NO];
-
- self.thumbnailTableView.selectionHighlightStyle = .none
-
- // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
- // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
- //
- // self.thumbnailTableView.setDraggingSourceOperationMask(.every, forLocal: false)
-
- if UserDefaults.standard.bool(forKey: SKDisableTableToolTipsKey) == false {
- self.tocOutlineView.hasImageToolTips = true
- self.findTableView.hasImageToolTips = true
- self.groupedFindTableView.hasImageToolTips = true
- }
- self._updateViewColor()
-
- self.mwcFlags.wholeWordSearch = UserDefaults.standard.integer(forKey: SKWholeWordSearchKey)
- self.mwcFlags.caseInsensitiveSearch = UserDefaults.standard.integer(forKey: SKCaseInsensitiveSearchKey)
- }
-
- func displayThumbnailViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.thumbnailTableView.enclosingScrollView!, animate: animate)
-
- var frame = self.thumbnailTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.origin.x = self.leftMargin
- frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.thumbnailTableView.enclosingScrollView?.frame = frame
-
- self.resetThumbnails()
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.origin.x = self.leftMargin
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.origin.x = self.leftMargin
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // [self updateThumbnailSelection];
- }
-
- func displayFindViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.searchViewController.view, animate: animate)
- if (self.findState != .content) {
- self.findState = .content
- } else {
- self.displayFindState()
- }
-
- var frame = self.searchViewController.view.frame
- frame.origin.y = 0
- frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
- self.searchViewController.view.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
- self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
-
- self.updataLeftSideSnapView()
- }
-
- func displayFindState() {
- if (self.findState == .content) {
- self.displayFind()
- } else if (self.findState == .note) {
- self.displayNoteFind()
- } else if (self.findState == .snapshot) {
- self.displaySnapshotFind()
- }
- }
-
- func updataLeftSideSnapView() {
- if (snapshots.count < 1) {
- self.snapshotNormalSearchButton.isEnabled = false
- // leftSideController.snapshotSearchZoomOutButton.enabled = NO;
- self.snapshotNormalZoomOutButton.isEnabled = false
- // leftSideController.snapshotSearchZoomInButton.enabled = NO;
- self.snapshotNormalZoomInButton.isEnabled = false
- self.snapshotNormalMoreButton.isEnabled = false
-
- self.leftSideEmptyVC.deleteSnapBtn.isEnabled = false
- self.leftSideEmptyVC.exportSnapBtn.isEnabled = false
- self.leftSideEmptyVC.printSnapBtn.isEnabled = false
- self.snapshotTableView.usesAlternatingRowBackgroundColors = false
- let view = self.snapshotTableView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptySnapView.frame.size
- 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);
- self.leftSideEmptyVC.emptySnapView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptySnapView)
- } else {
- self.snapshotNormalSearchButton.isEnabled = true
- // leftSideController.snapshotSearchZoomOutButton.enabled = YES;
- self.snapshotNormalZoomOutButton.isEnabled = true
- // leftSideController.snapshotSearchZoomInButton.enabled = YES;
- self.snapshotNormalZoomInButton.isEnabled = true
- self.snapshotNormalMoreButton.isEnabled = true
- self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
- self.leftSideEmptyVC.deleteSnapBtn.isEnabled = true
- self.leftSideEmptyVC.exportSnapBtn.isEnabled = true
- self.leftSideEmptyVC.printSnapBtn.isEnabled = true
- }
- }
-
- func updataLeftSideFindView() {
- if (self.findState != .content) {
- return
- }
- if (self.searchResults.count > 0) {
- self.searchViewController.emptyBox.isHidden = true
- self.searchViewController.searchResultsView.isHidden = false
- self.searchViewController.searchResultsLabel.stringValue = String(format: KMLocalizedString("%ld Results", "Message in search table header"), self.searchResults.count)
- } else {
- self.searchViewController.emptyBox.isHidden = false
- self.searchViewController.searchResultsView.isHidden = true
- }
- }
-
- func displayGroupedFindViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.searchViewController.view , animate: animate)
- if (self.findState != .content) {
- self.findState = .content
- } else {
- self.displayFindState()
- }
-
- var frame = self.searchViewController.view.frame
- frame.origin.y = 0
- frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? 0
- self.searchViewController.view.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- self.updataLeftSideSnapView()
- }
-
- func displayNoteViewAnimating(_ animate: Bool) {
- self.reloadAnnotation()
- self.annotationSort(sortArray: [])
-
- self.searchViewController.contentView = nil
- self.replaceSideView(self.noteOutlineView.enclosingScrollView!, animate: animate)
- if (self.findState != .note) {
- self.findState = .note
- } else {
- self.displayFindState()
- }
-
- var frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- let view = self.noteOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
- 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)
-
- DispatchQueue.main.async {
- self.noteOutlineView.reloadData()
- }
- }
-
- func displaySnapshotViewAnimating(_ animate: Bool) {
- self.searchViewController.contentView = nil
- self.replaceSideView(self.snapshotTableView.enclosingScrollView!, animate: animate)
- if (self.findState != .snapshot) {
- self.findState = .snapshot
- } else {
- self.displayFindState()
- }
-
- var frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.tocOutlineView.enclosingScrollView?.frame = frame
-
- // [self updateSnapshotsIfNeeded];
- Task { @MainActor in
- self.snapshotTableView.reloadData()
- }
- }
-
- func displayFind() {
- self.searchField = self.searchViewController.searchField
-
- let menu = NSMenu()
- _ = menu.addItem(title: KMLocalizedString("Whole Words Only", "Menu item title"), action: #selector(toggleWholeWordSearch), target: self)
- _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveSearch), target: self)
- (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
- self.searchViewController.searchField.action = #selector(search)
- self.searchViewController.searchField.target = self
- if (self.findPaneState == .singular) {
- self.searchViewController.contentView = self.findTableView.enclosingScrollView
-
- self.findTableView.wantsLayer = true
- self.findTableView.layer?.backgroundColor = NSColor.red.cgColor
- DispatchQueue.main.async {
- self.findTableView.reloadData()
- }
- } else if (self.findPaneState == .grouped) {
- self.searchViewController.contentView = self.groupedFindTableView.enclosingScrollView
- var array = KMSearchMode.sortSearchResult(results: self.searchResults)
- array.sort(){$0.datas.count > $1.datas.count}
- self.groupSearchResults = array
- self.groupedFindTableView.reloadData()
- }
- }
-
- func displayTocViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.tocOutlineView.enclosingScrollView!, animate: animate)
-
- var frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.tocOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- let view = self.tocOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
-
- 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);
-
- DispatchQueue.main.async {
- self.tocOutlineView.reloadData()
- self.updateOutlineSelection()
- }
- }
-
- override func requiresAlternateButton(forView aview: NSView?) -> Bool {
- return false
- }
-
- func displayNoteFind() {
- self.searchField = self.noteSearchField
-
- let menu = NSMenu()
- _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveNoteSearch), target: self)
- (self.noteSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.noteSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Notes", "placeholder")
- self.noteSearchField.action = #selector(searchNotes)
- self.noteSearchField.target = self
- }
-
- func displaySnapshotFind() {
- self.searchField = self.snapshotSearchField;
-
- let menu = NSMenu()
- _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveNoteSearch), target: self)
- (self.snapshotSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.snapshotSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Snapshots", "placeholder")
- self.snapshotSearchField.action = #selector(searchNotes)
- self.snapshotSearchField.target = self
- self.snapshotSearchField.delegate = self
- }
-
- /*
- - (void)applySearchTableHeader:(NSString *)message {
- [[[findTableView tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
- [[findTableView headerView] setNeedsDisplay:YES];
- [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell] setStringValue:message];
- [[groupedFindTableView headerView] setNeedsDisplay:YES];
- }
- */
-
- @IBAction func search(_ sender: NSSearchField) {
- self.delegate?.searchAction?(searchString: sender.stringValue, isCase: self.mwcFlags.caseInsensitiveSearch == 1)
- }
-
- @IBAction func snapshotNormalSearchButtonAction(_ sender: NSButton) {
- self.snapshotSearchField.isHidden = false
- // _snapshotSearchZoomOutButton.hidden = YES;
- self.snapshotSearchZoomInButton.isHidden = true
- self.snapshotNormalSearchButton.isHidden = true
- self.snapshotDoneButton.isHidden = false
- self.snapshotLabel.isHidden = true
- self.snapshotNormalZoomOutButton.isHidden = true
- self.snapshotNormalZoomInButton.isHidden = true
-
- self.snapshotSearchField.becomeFirstResponder()
- }
-
- func resetThumbnails() {
- // [self willChangeValueForKey:THUMBNAILS_KEY];
- // self.thumbnailCacheSize = 160
- self.thumbnails.removeAll()
- let pageLabels = self.listView.document.pageLabels()
- if (pageLabels.isEmpty == false) {
- let isLocked = self.listView.document.isLocked
- let firstPage = self.listView.document.page(at: 0)
- let emptyPage = CPDFPage()
- let firstFrame = firstPage?.bounds(for: .cropBox) ?? .zero
- let firstFrame2 = firstPage?.bounds(for: .mediaBox) ?? .zero
- emptyPage.setBounds(firstFrame, for: .cropBox)
- emptyPage.setBounds(firstFrame2, for: .mediaBox)
- emptyPage.rotation = firstPage?.rotation ?? 0
-
- let pageImage = firstPage!.thumbnail(of: NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize))
- // NSImage * = [emptyPage thumbnailWithSize:thumbnailCacheSize forBox:[pdfView displayBox]];
- var rect: NSRect = .zero
- rect.size = pageImage?.size ?? .zero
- let width = 1.2 * fmin(NSWidth(rect), NSHeight(rect))
- rect = NSInsetRect(rect, 0.5 * (NSWidth(rect) - width), 0.5 * (NSHeight(rect) - width));
-
- pageImage?.lockFocus()
- // NSImage(named: NSImage.applicationIconName)?.draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
- if (isLocked) {
- NSWorkspace.shared.icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kLockedBadgeIcon))).draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
- // [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:0.5];
- }
- pageImage?.unlockFocus()
-
- for (i, label) in pageLabels.enumerated() {
- let firstPage = self.listView.document.page(at: UInt(i))
- let size = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
- // let pageImage = firstPage!.thumbnail(of: size)
- let thumbnail = KMThumbnail(image: nil, label: label, pageIndex: i)
- // thumbnail.delegate = self
- thumbnail.dirty = true
- self.thumbnails.append(thumbnail)
- }
- }
- // [self didChangeValueForKey:THUMBNAILS_KEY];
- // [self allThumbnailsNeedUpdate];
-
- DispatchQueue.main.async {
- self.thumbnailTableView.reloadData()
- }
- }
-
- @IBAction @objc func sortTypeAction(_ sender: NSMenuItem) {
- let item = sender
- let tag = item.tag
-
- if (item.state == .on) {
- item.state = .off
- } else {
- item.state = .on
- }
- if (tag == 0) {
- self.noteSortType = .page
- self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
- } else if (tag == 1) {
- self.noteSortType = .time
- self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
- }
- UserDefaults.standard.set(self.noteSortType.rawValue, forKey: KMLeftSideViewNoteSortTypeKey)
- UserDefaults.standard.synchronize()
-
- self.annotationSort(sortArray: [])
- }
-
- @IBAction func noteSortAction(_ sender: AnyObject?) {
- if (self.isAscendSort) {
- self.isAscendSort = false
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
- self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
- } else {
- self.isAscendSort = true
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
- self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
- }
- UserDefaults.standard.setValue(self.isAscendSort, forKey: KMLeftSideViewAscendSortBoolKey)
- UserDefaults.standard.synchronize()
-
- self.annotationSort(sortArray: [])
- }
-
- @IBAction func noteSearchAction(_ sender: NSButton) {
- self.noteSearchField.isHidden = false
- self.noteTitleLabel.isHidden = true
- self.noteSearchButton.isHidden = true
- self.noteDoneButton.isHidden = false
- self.noteFilterButton.isHidden = true
- self.noteMoreButton.isHidden = true
-
- self.noteSearchField.becomeFirstResponder()
- }
-
- @IBAction func leftSideViewDoneButtonAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
- let tag = button?.tag ?? 0
- if (tag == 310) {
- self.outlineSearchField.isHidden = true
- self.outlineDoneButton.isHidden = true
- self.outlineLabel.isHidden = false
- self.outlineSearchButton.isHidden = false
- self.outlineMoreButton.isHidden = false
- self.outlineAddButton.isHidden = false
- } else if (tag == 311) {
- self.noteSearchField.isHidden = true
- self.noteTitleLabel.isHidden = false
- self.noteSearchButton.isHidden = false
- self.noteDoneButton.isHidden = true
- self.noteFilterButton.isHidden = false
- self.noteMoreButton.isHidden = false
- } else if (tag == 312) {
- self.snapshotSearchField.isHidden = true
- // leftSideController.snapshotSearchZoomOutButton.hidden = YES;
- // leftSideController.snapshotSearchZoomInButton.hidden = YES;
- self.snapshotNormalSearchButton.isHidden = false
- self.snapshotDoneButton.isHidden = true
- self.snapshotLabel.isHidden = false
- self.snapshotNormalZoomOutButton.isHidden = false
- self.snapshotNormalZoomInButton.isHidden = false
- }
- }
-
- @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
- let tag = button?.tag ?? 0
- if (tag == 300) {
- var selectedRow = 0
- if (self.snapshotTableView.selectedRow >= 0) {
- selectedRow = self.snapshotTableView.selectedRow;
- } else {
- return
- }
- let model = self.snapshots[selectedRow]
- let controller = model.windowC
- let menu = NSMenu()
- let itemExport = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
- let subMenu = NSMenu()
- var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
- t?.representedObject = controller
- t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
- t?.representedObject = controller
- t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
- t?.representedObject = controller
- itemExport?.submenu = subMenu
- let itemPrint = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
- itemPrint?.representedObject = controller
- menu.addItem(.separator())
- let itemSelectAll = menu.addItem(title: KMLocalizedString("Select All", "Menu item title"), action: #selector(menuItemClick_SelectAll), target: self)
- itemSelectAll?.representedObject = controller
- menu.addItem(.separator())
- let itemDeleteAllSnapshot = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
- itemDeleteAllSnapshot?.representedObject = controller
- //
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
- } else if (tag == 302) {
- let menu = NSMenu()
- let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.tocOutlineView
- let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.tocOutlineView
- let item = self.listView.document.outlineRoot()
- var num = 0
- for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
- let outline = item?.child(at: UInt(i))
- if self.tocOutlineView.isItemExpanded(outline) {
- num += 1
- }
- }
- if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
- self.tocType = .fold
- } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
- self.tocType = .unfold
- } else {
- self.tocType = .none
- }
- if (self.tocType == .unfold) {
- expandAllCommentsItem?.state = .on
- foldAllCommentsItem?.state = .off
- } else if (self.tocType == .fold) {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .on
- } else {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .off
- }
- let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
- removeEntryItem?.representedObject = self.tocOutlineView
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
- } else if (tag == 304) {
- let menu = NSMenu()
- let object = KMPopupMenuObject()
- object.menuTag = 1001
- menu.delegate = object
- object.enterControllerCallback = { [weak self] isEnter in
- if (isEnter) {
- self?.moreButtonLayer?.isHidden = false
- } else {
- self?.moreButtonLayer?.isHidden = true
- }
- }
- let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.noteOutlineView
- let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
- foldAllCommentsItem?.representedObject = self.noteOutlineView
- if (self.foldType == .unfold) {
- expandAllCommentsItem?.state = .on
- foldAllCommentsItem?.state = .off
- } else if (self.foldType == .fold) {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .on
- } else {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .off
- }
- let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
- let subMenu = NSMenu()
- var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
- let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
- if pageKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 101
- t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
- let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
- if timeKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 102
- t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
- let authorKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
- if authorKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 103
- showAnnotationItem?.submenu = subMenu
- menu.addItem(.separator())
- let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: ""), action: nil, target: self)
- let subMenu2 = NSMenu()
- var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 0
- t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 1
- t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 2
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 3
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 4
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 5
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 6
- exportAnnotationsItem?.submenu = subMenu2
- menu.addItem(.separator())
- let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
- removeAllAnnotationsItem?.representedObject = self.noteOutlineView
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: button!, with: nil)
- }
- }
-
- @IBAction func noteFilterAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
-
- let menu = NSMenu()
- let filterViewController = KMNoteOutlineFilterViewController()
- filterViewController.listView = self.listView
- filterViewController.view.layer?.backgroundColor = .clear
- var notes = NSMutableArray()
- // for section in self._annotations {
- // if section.annotations?.count != 0 {
- // for item in section.annotations! {
- // notes.add(item.annotation!)
- // }
- // }
- // }
- filterViewController.setNotesArray(self.allAnnotations as NSArray)
- filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
- menu.cancelTracking()
- if (isEmpty) {
- self?.filterButtonLayer?.isHidden = true
- } else {
- self?.filterButtonLayer?.isHidden = false
- }
- self?.annotationSort(sortArray: [])
- }
- filterViewController.cancelCallback = { isCancel in
- if (isCancel) {
- menu.cancelTracking()
- }
- }
- let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
- item.target = self
- item.representedObject = filterViewController
- item.view = filterViewController.view
- menu.popUp(positioning: nil, at: CGPointMake(-130, 30), in: button)
- }
-
- @IBAction func outlineNormalSearchButtonAction(_ sender: NSButton) {
- self.outlineSearchField.isHidden = false
- self.outlineDoneButton.isHidden = false
- self.outlineLabel.isHidden = true
- self.outlineSearchButton.isHidden = true
- self.outlineMoreButton.isHidden = true
- self.outlineAddButton.isHidden = true
-
- self.outlineSearchField.becomeFirstResponder()
- }
-
- @IBAction func toc_expandAllComments(_ sender: AnyObject?) {
- if (self.tocType == .unfold) {
- return
- }
- self.tocType = .unfold
- self.tocOutlineView.reloadData()
- self.tocOutlineView.expandItem(nil, expandChildren: true)
- }
-
- @IBAction func toc_foldAllComments(_ sender: AnyObject?) {
- if (self.tocType == .fold) {
- return
- }
- self.tocType = .fold
- self.tocOutlineView.reloadData()
- self.tocOutlineView.collapseItem(nil, collapseChildren: true)
- }
-
- @objc func leftSideEmptyAnnotationClick_DeleteOutline(_ sender: AnyObject?) {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = ""
- alert.informativeText = KMLocalizedString("This will permanently remove all outlines. Are you sure to continue?", nil)
- alert.addButton(withTitle: KMLocalizedString("Yes", nil))
- alert.addButton(withTitle: KMLocalizedString("No", nil))
- let response = alert.runModal()
- if response == .alertFirstButtonReturn {
- if let item = self.listView.document.outlineRoot() {
- self.removeAllOutline(item)
- }
- }
- }
-
- @IBAction func thumbnailSizeScaling(_ sender: NSButton) {
- let sud = UserDefaults.standard
-
- let tag = sender.tag
- if (tag == 0 || tag == 1) {
- var scaling = sud.float(forKey: "KMThumbnailSizeScalingKey")
- if (scaling <= 0) {
- scaling = 1
- }
- if (tag == 0) { // thumbnail Zoom In
- scaling += 0.1
- if scaling >= 2.2 {
- return
- }
- } else if (tag == 1) { // thumbnail Zoom Out
- scaling -= 0.1
- if scaling <= 0.4 {
- return
- }
- }
- sud.setValue(scaling, forKey: "KMThumbnailSizeScalingKey")
- let selectRow = self.thumbnailTableView.selectedRow
- self.thumbnailTableView.reloadData()
-
- self.thumbnailTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
- } else if (tag == 2 || tag == 3) {
- var scaling = sud.float(forKey: "KMSnapshotSizeScalingKey")
- if (scaling <= 0) {
- scaling = 1
- }
-
- if (tag == 2) { // snapshot Zoom In
- scaling += 0.1
- } else if (tag == 3) { // snapshot Zoom Out
- scaling -= 0.1
- }
-
- sud.setValue(scaling, forKey: "KMSnapshotSizeScalingKey")
-
- let selectRow = self.snapshotTableView.selectedRow
- self.snapshotTableView.reloadData()
- self.snapshotTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
- }
- }
-
- func reloadAnnotation() {
- if self.listView != nil {
- var dataArray: [KMBOTAAnnotationSection] = []
- var annotationArray: [CPDFAnnotation] = []
- var allAnnotation: [CPDFAnnotation] = []
- for i in 0 ..< self.listView.document.pageCount {
- var annotationItemArray: [KMBOTAAnnotationItem] = []
- let page = self.listView.document.page(at: i)
- let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
- var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(annotations: page!.annotations,types: types) as! [CPDFAnnotation]
- //添加签名注释
- for annotation in page!.annotations {
- if annotation.isKind(of: CPDFSignatureAnnotation.self) {
- pageAnnotations.append(annotation)
- }
- }
-
- for annotation in pageAnnotations {
- if annotation.annotationShouldDisplay() == false {
- pageAnnotations.removeObject(annotation)
- }
- }
- //转换所有annotation类型
- let section = KMBOTAAnnotationSection()
- for annotation in pageAnnotations {
- let item = KMBOTAAnnotationItem()
- item.section = section
- item.annotation = annotation
- item.index = Int(annotation.page.pageIndex())
- annotationItemArray.append(item)
-
- allAnnotation.append(annotation)
- }
-
- if annotationItemArray.count != 0 {
- section.annotations = annotationItemArray
- section.page = page
- section.isItemExpanded = true
- dataArray.append(section)
- }
-
- //添加所有annotation 用于筛选
- annotationArray += pageAnnotations
- }
-
- if self.noteSortType == .page {
- /// 根据id进行排序(升序)
- if self.isAscendSort {
- dataArray.sort { $0.page!.pageIndex() > $1.page!.pageIndex()}
- } else {
- dataArray.sort { $0.page!.pageIndex() <= $1.page!.pageIndex()}
- }
- self._annotations = dataArray
- } else if self.noteSortType == .time {
- var datas: [KMBOTAAnnotationSection] = []
- /// 根据id进行排序(升序)
- if self.isAscendSort {
- allAnnotation.sort {
- if $0.modificationDate() == nil {
- return false
- }
- if $1.modificationDate() == nil {
- return false
- }
- return $0.modificationDate() > $1.modificationDate()
- }
- } else {
- allAnnotation.sort {
- if $0.modificationDate() == nil {
- return false
- }
- if $1.modificationDate() == nil {
- return false
- }
- return $0.modificationDate() <= $1.modificationDate()
- }
- }
- for anno in allAnnotation {
- let section = KMBOTAAnnotationSection()
- let item = KMBOTAAnnotationItem()
- item.section = section
- item.annotation = anno
- item.index = Int(anno.pageIndex())
-
- section.annotations = [item]
- section.page = anno.page
- section.isItemExpanded = true
-
- datas.append(section)
- }
- self._annotations = datas
- }
-
- //转换对象,用于数据显示
- // self._annotations = dataArray
- self._allAnnotations = annotationArray
-
- // if self.annotations.count < 1 {
- // self.filtrateButton.isEnabled = false
- // } else {
- // self.filtrateButton.isEnabled = true
- // }
- }
- }
-
- func annotationSort(sortArray:[[Any]]) {
- if self.listView != nil {
- var typeArr: [Any] = []
- var colorArr: [Any] = []
- var authorArr: [Any] = []
-
- let sud = UserDefaults.standard
- let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type" + self.listView.document.documentURL.path) as? Data
- // let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type") as? Data
- if typeData != nil {
- typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as! [Any]
- }
-
- let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color" + self.listView.document.documentURL.path) as? Data
- // let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color") as? Data
- if colorData != nil {
- colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as! [Any]
- }
-
- let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path) as? Data
- // let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author") as? Data
- if authorData != nil {
- authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as! [Any]
- }
-
- var colorMutableArray = NSMutableArray()
- var typeMutableArray = NSMutableArray()
- var authorMutableArray = NSMutableArray()
- for annotation in self.allAnnotations {
- if annotation.isKind(of: CPDFInkAnnotation.self) == false &&
- annotation.isKind(of: CPDFTextWidgetAnnotation.self) == false &&
- annotation.isKind(of: CPDFButtonWidgetAnnotation.self) == false &&
- annotation.isKind(of: CPDFChoiceWidgetAnnotation.self) == false
- // ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature] &&
- // ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeText] &&
- // ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeButton] &&
- // ![annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeChoice])
- {
- let noteColor = annotation.color ?? .clear
- let noteType = annotation.type ?? ""
- let authorString = annotation.userName() ?? ""
-
- if (noteColor != nil) {
- if (colorMutableArray.count > 0) {
- if colorMutableArray.contains(noteColor) == false {
- colorMutableArray.add(noteColor)
- }
- } else {
- colorMutableArray.add(noteColor)
- }
- }
-
- if noteType.isEmpty == false {
- if (typeMutableArray.count > 0) {
- if typeMutableArray.contains(noteType) == false {
- typeMutableArray.add(noteType)
- }
- } else {
- typeMutableArray.add(noteType)
- }
- }
-
- if authorString.isEmpty == false {
- if (authorMutableArray.count > 0) {
- if authorMutableArray.contains(authorString) == false {
- authorMutableArray.add(authorString)
- }
- } else {
- authorMutableArray.add(authorString)
- }
- }
- }
- }
-
- // var temporaryArr1 = NSMutableArray()
- // var temporaryArr2 = NSMutableArray()
- // var temporaryArr3 = NSMutableArray()
- // if typeArr.isEmpty == false {
- // for type in typeArr {
- // if typeMutableArray.contains(type) == false {
- // temporaryArr1.add(type)
- // }
- // }
- // }
- // if colorArr.isEmpty == false {
- // for color in colorArr {
- // if colorMutableArray.contains(color) == false {
- // temporaryArr2.add(type)
- // }
- // }
- // }
- // if authorArr.isEmpty == false {
- // for author in authorArr {
- // if authorMutableArray.contains(author) == false {
- // temporaryArr3.add(type)
- // }
- // }
- // }
-
- // if (temporaryArr1.count > 0) {
- // for type in temporaryArr1 {
- // guard let typeS = type as? String else {
- // continue
- // }
- //// [typeArr removeObject:type];
- //
- // var flag = -1
- // for (i, data) in typeArr.enumerated() {
- // if data as! String == typeS {
- // flag = i
- // }
- // }
- // if flag != -1 {
- // typeArr.remove(at: flag)
- // }
- // }
- // }
- // if (temporaryArr2.count > 0) {
- // for (NSColor *color in temporaryArr2) {
- // [colorArr removeObject:color];
- // }
- // }
- // for color in temporaryArr2 {
- // guard let colorT = color as? NSColor else {
- // continue
- // }
- //// [typeArr removeObject:type];
- //
- // var flag = -1
- // for (i, data) in colorArr.enumerated() {
- // if data as! NSColor == colorT {
- // flag = i
- // }
- // }
- // if flag != -1 {
- // colorArr.remove(at: flag)
- // }
- // }
- // if (temporaryArr3.count > 0) {
- // for (NSColor *author in temporaryArr3) {
- // [authorArr removeObject:author];
- // }
- // }
- // for author in temporaryArr3 {
- // guard let authorS = author as? String else {
- // continue
- // }
- //// [typeArr removeObject:type];
- //
- // var flag = -1
- // for (i, data) in authorArr.enumerated() {
- // if data as! String == authorS {
- // flag = i
- // }
- // }
- // if flag != -1 {
- // authorArr.remove(at: flag)
- // }
- // }
-
- // let data1 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: typeArr))
- // let data2 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: colorArr))
- // let data3 = NSKeyedArchiver.archivedData(withRootObject: NSArray(array: authorArr))
-
- // let sud = UserDefaults.standard
- // sud.set(data1, forKey: "KMNoteOutlineFilterSelectArray_Type")
- // sud.set(data2, forKey: "KMNoteOutlineFilterSelectArray_Color")
- // sud.set(data3, forKey: "KMNoteOutlineFilterSelectArray_Author")
- // sud.synchronize()
-
- if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
- // self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
- self.reloadAnnotation()
- } else {
- // self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")
- var dataArray: [KMBOTAAnnotationSection] = []
- var allAnnotation: [CPDFAnnotation] = []
- for i in 0 ..< self.listView.document.pageCount {
- var annotationItemArray: [KMBOTAAnnotationItem] = []
- let page = self.listView.document.page(at: i)
- if page!.annotations.count > 0 {
- var filterAnnotations: [CPDFAnnotation] = page!.annotations
- if typeArr.count > 0 {
- filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations, types: typeArr) as! [CPDFAnnotation])
- }
- if (colorArr.count > 0) {
- filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
- }
- if (authorArr.count > 0) {
- filterAnnotations = (KMOCToolClass.filterAnnotation(annotations: filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
- }
-
- let section = KMBOTAAnnotationSection()
- for annotation in filterAnnotations {
- let item = KMBOTAAnnotationItem()
- item.section = section
- item.annotation = annotation
- item.index = Int(page!.pageIndex())
- annotationItemArray.append(item)
- allAnnotation.append(annotation)
- }
-
- if annotationItemArray.count != 0 {
- section.annotations = annotationItemArray
- section.page = page
- section.isItemExpanded = true
- dataArray.append(section)
- }
- }
- }
-
- if self.noteSortType == .page {
- /// 根据id进行排序(升序)
- if self.isAscendSort {
- dataArray.sort { $0.page!.pageIndex() > $1.page!.pageIndex()}
- } else {
- dataArray.sort { $0.page!.pageIndex() <= $1.page!.pageIndex()}
- }
- self._annotations = dataArray
- } else if self.noteSortType == .time {
- var datas: [KMBOTAAnnotationSection] = []
- /// 根据id进行排序(升序)
- if self.isAscendSort {
- allAnnotation.sort { $0.modificationDate() > $1.modificationDate() }
- } else {
- allAnnotation.sort { $0.modificationDate() <= $1.modificationDate() }
- }
- for anno in allAnnotation {
- let section = KMBOTAAnnotationSection()
- let item = KMBOTAAnnotationItem()
- item.section = section
- item.annotation = anno
- item.index = Int(anno.pageIndex())
-
- section.annotations = [item]
- section.page = anno.page
- section.isItemExpanded = true
-
- datas.append(section)
- }
- self._annotations = datas
- }
- }
-
- Task { @MainActor in
- self.noteOutlineView.reloadData()
- }
- }
- }
-
- func showSearchOutlineBlankState(_ toShowState: Bool) {
- if (toShowState) {
- 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);
- self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.outlineSearchView)
- self.leftSideEmptyVC.outlineSearchView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- } else {
- self.leftSideEmptyVC.outlineSearchView.removeFromSuperview()
- }
- }
-
- // func allRangeOfRoughString(_ roughString: String, searchString: String) -> [NSRange] {
- //
- // }
-
- func removeAllOutline(_ outline: CPDFOutline) {
- self.listView.document.setNewOutlineRoot()
-
- for i in 0 ..< self.listView.document.pageCount {
- self.listView.document.removeBookmark(forPageIndex: i)
- }
- self.listView.layoutDocumentView()
- DispatchQueue.main.async {
- self.tocOutlineView.reloadData()
- }
- }
-
- func updateNoteFilterPredicate() {
- //注释筛选
- // [rightSideController.noteArrayController setFilterPredicate:[noteTypeSheetController filterPredicateForSearchString:[rightSideController.searchField stringValue] caseInsensitive:mwcFlags.caseInsensitiveNoteSearch]];
- let stringValue = self.noteSearchField.stringValue
-
- // NSPredicate *predicate = [noteTypeSheetController filterPredicateForSearchString:[rightSideController.searchField stringValue] caseInsensitive:mwcFlags.caseInsensitiveNoteSearch];
- // [self loadAnnotationSortData:[NSArray arrayWithObjects:predicate, nil]];
- self.noteSearchArray.removeAll()
- if stringValue.isEmpty {
- self.noteSearchArray = self.allAnnotations
- } else {
- for note in self.allAnnotations {
- var noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
- if let anno = note as? CPDFMarkupAnnotation {
- noteString = anno.markupContent()
- }
- if noteString.contains(stringValue) {
- self.noteSearchArray.append(note)
- }
- }
- }
-
- Task { @MainActor in
- self.noteOutlineView.reloadData()
- }
- }
-
- @objc func selectSelectedNote(_ sender: AnyObject?) {
- if self.listView.hideNotes == false {
- let selectedNotes = self.selectedNotes()
- if selectedNotes.count == 1 {
- let annotation = selectedNotes.last!
- self.listView.go(to: annotation.bounds, on: annotation.page, animated: true)
-
- // [pdfView scrollAnnotationToVisible:annotation];
- // [pdfView setActiveAnnotation:annotation];
-
- self.listView.updateActiveAnnotations([annotation])
- self.listView.setNeedsDisplayAnnotationViewForVisiblePages()
- // }
-
- }
- // NSInteger column = [sender clickedColumn];
- // if (column != -1) {
- // NSString *colID = [[[sender tableColumns] objectAtIndex:column] identifier];
- //
- // if ([colID isEqualToString:@"color"]){
- // for (PDFAnnotation *annotation in self.pdfView.activeAnnotations) {
- // if (![annotation isKindOfClass:[PDFAnnotationChoiceWidget class]] &&
- // ![annotation isKindOfClass:[PDFAnnotationButtonWidget class]] &&
- // ![annotation isKindOfClass:[PDFAnnotationTextWidget class]]) {
- // [[NSColorPanel sharedColorPanel] orderFront:nil];
- // break;
- // }
- //
- // }
- // }
- // }
- }
- }
-
- func selectedNotes() -> [CPDFAnnotation] {
- var selectedNotes: [CPDFAnnotation] = []
- let rowIndexes = self.noteOutlineView.selectedRowIndexes
- for row in rowIndexes {
- let item = self.noteOutlineView.item(atRow: row)
- if item is KMBOTAAnnotationItem {
- if let anno = (item as! KMBOTAAnnotationItem).annotation {
- // if anno.type == nil {
- // item = [(SKNoteText *)item note];
- // }
- if selectedNotes.contains(anno) == false {
- selectedNotes.append(anno)
- }
- }
- }
- }
- return selectedNotes
- }
- }
- // MARK: - Note
- extension KMLeftSideViewController {
- func loadAnnotationSortData(_ morePredicates: NSArray) {
- var isLink = false
- var typeMutableArr = NSMutableArray()
- if self.allAnnotations.count > 0 {
- for annotation in self.allAnnotations {
- if annotation is CPDFLinkAnnotation || annotation is CPDFTextWidgetAnnotation || annotation is CPDFButtonWidgetAnnotation || annotation is CPDFChoiceWidgetAnnotation {
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature] ||
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeText] ||
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeButton] ||
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeChoice]) {
- isLink = true
- } else {
- if typeMutableArr.contains(annotation.type) == false {
- typeMutableArr.add(annotation.type)
- }
- }
- }
- }
-
- var colorMutableArray = NSMutableArray()
- var typeMutableArray = NSMutableArray()
- var authorMutableArray = NSMutableArray()
- for annotation in self.allAnnotations {
- if annotation is CPDFLinkAnnotation || annotation is CPDFTextWidgetAnnotation || annotation is CPDFButtonWidgetAnnotation || annotation is CPDFChoiceWidgetAnnotation {
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature] ||
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeText] ||
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeButton] ||
- // [annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeChoice]) {
- let noteColor = annotation.color ?? .clear
- let noteType = annotation.type ?? ""
- let authorString = annotation.userName() ?? ""
- if (noteColor != nil) {
- if (colorMutableArray.count > 0) {
- if colorMutableArray.contains(noteColor) == false {
- colorMutableArray.add(noteColor)
- }
- } else {
- colorMutableArray.add(noteColor)
- }
- }
- if noteType.isEmpty == false {
- if typeMutableArray.count > 0 {
- if typeMutableArray.contains(noteType) == false {
- typeMutableArray.add(noteType)
- }
- } else {
- typeMutableArray.add(noteType)
- }
- }
- if authorString.isEmpty == false {
- if authorString.count > 0 {
- if authorMutableArray.contains(authorString) == false {
- authorMutableArray.add(authorString)
- }
- } else {
- authorMutableArray.add(authorString)
- }
- }
- } else {
- if typeMutableArr.contains(annotation.type) == false {
- typeMutableArr.add(annotation.type)
- }
- }
- }
-
- let sud = UserDefaults.standard
- var typeArr = NSMutableArray()
- if let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type") as? Data {
- if let data = NSKeyedUnarchiver.unarchiveObject(with: typeData) as? NSArray {
- typeArr = NSMutableArray(array: data)
- }
- }
- var colorArr = NSMutableArray()
- if let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color") as? Data {
- if let data = NSKeyedUnarchiver.unarchiveObject(with: colorData) as? NSArray {
- colorArr = NSMutableArray(array: data)
- }
- }
- var authorArr = NSMutableArray()
- if let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author") as? Data {
- if let data = NSKeyedUnarchiver.unarchiveObject(with: authorData) as? NSArray {
- authorArr = NSMutableArray(array: data)
- }
- }
-
- var temporaryArr1 = NSMutableArray()
- var temporaryArr2 = NSMutableArray()
- var temporaryArr3 = NSMutableArray()
- if (typeArr.count > 0) {
- for type in typeArr {
- if typeMutableArray.contains(type) == false {
- temporaryArr1.add(type)
- }
- }
- }
- if (colorArr.count > 0) {
- for color in colorArr {
- if colorMutableArray.contains(color) == false {
- temporaryArr2.add(color)
- }
- }
- }
- if (authorArr.count > 0) {
- for author in authorArr {
- if authorMutableArray.contains(author) == false {
- temporaryArr3.add(author)
- }
- }
- }
-
- if (temporaryArr1.count > 0) {
- for type in temporaryArr1 {
- typeArr.remove(type)
- }
- }
- if (temporaryArr2.count > 0) {
- for color in temporaryArr2 {
- colorArr.remove(color)
- }
- }
- if (temporaryArr3.count > 0) {
- for author in temporaryArr3 {
- authorArr.remove(author)
- }
- }
-
- var predicateMutableArr = NSMutableArray()
- // predicateMutableArr.add
- }
- }
- // MARK: - KMBotaTableViewDelegate
- extension KMLeftSideViewController: KMBotaTableViewDelegate {
- func tableView(_ aTableView: NSTableView, canCopyRowsWithIndexes rowIndexes: IndexSet) -> Bool {
- if aTableView.isEqual(to: self.thumbnailTableView) || aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
- return rowIndexes.count > 0
- }
- return false
- }
-
- func tableView(_ aTableView: NSTableView, canPasteFromPasteboard pboard: NSPasteboard) -> Bool {
- if aTableView.isEqual(to: self.thumbnailTableView) {
- if self._copysPages.count > 0 {
- return true
- }
- }
- return false
- }
-
- func tableView(_ aTableView: NSTableView, canDeleteRowsWithIndexes rowIndexes: IndexSet) -> Bool {
- // if ([tv isEqual:rightSideController.snapshotTableView]) {
- // return [rowIndexes count] > 0;
- // } else
- if aTableView.isEqual(to: self.thumbnailTableView) {
- if self.listView.document.pageCount <= 1 {
- return false
- }
- return true
- }
- return false
- }
-
- func tableView(_ aTableView: NSTableView, pasteFromPasteboard pboard: NSPasteboard?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
-
- if aTableView.isEqual(to: self.thumbnailTableView) {
- if self._copysPages.count > 0 {
- let index = self.listView.document.index(for: self.listView.currentPage()) + 1
- if (index == NSNotFound) {
- return
- }
- for page in self._copysPages.reversed() {
- // if let newPage = page.copy() as? CPDFPage {
- self.listView.document.insertPageObject(page, at: index)
- // }
- self.listView.layoutDocumentView()
- // [pageLabels setArray:[[pdfView document] pageLabels]];
- self.resetThumbnails()
- let pageIndex = min(index, self.listView.document.pageCount-1)
- self.listView.go(toPageIndex: Int(pageIndex), animated: true)
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).tableView(self.thumbnailTableView, deleteRowsWithIndexes: IndexSet(integer: IndexSet.Element(index)))
- }
- }
- }
- }
-
- func tableViewMoveLeft(_ aTableView: NSTableView) {
- if aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
- // [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
- }
- }
-
- func tableViewMoveRight(_ aTableView: NSTableView) {
- if aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
- // [self updateFindResultHighlightsForDirection:NSSelectingNext];
- }
- }
-
- func tableView(_ aTableView: NSTableView, imageContextForRow rowIndex: Int) -> AnyObject? {
- if aTableView.isEqual(to: self.findTableView) {
- if rowIndex >= self.searchResults.count {
- return nil
- }
- let model = self.searchResults[rowIndex]
- let selection = model.selection
- let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
- return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
- } else if aTableView.isEqual(to: self.groupedFindTableView) {
- if rowIndex >= self.groupSearchResults.count {
- return nil
- }
- // let model = self.groupSearchResults[rowIndex]
- // let selection = model.selection
- // let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
- // return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
- }
- return nil
- }
-
- /*
- - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- return pageLabels;
- }
- return nil;
- }
- - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- }
- }
- - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- if (searchString.length > 0)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- }
- }
- */
-
- }
- // MARK: - KMThumbnailTableViewDelegate
- extension KMLeftSideViewController: KMThumbnailTableViewDelegate {
- func tableView(_ tableView: NSTableView, highlightLevelForRow row: Int) -> UInt {
- if tableView.isEqual(to: self.thumbnailTableView) {
- // NSUInteger i, iMax = [lastViewedPages count];
- // for (i = 0; i < iMax; i++) {
- // if (row == (NSInteger)[lastViewedPages pointerAtIndex:i])
- // return i;
- // }
- }
- return UInt.max
- }
-
- func tableView(_ tableView: NSTableView, commandSelectRow rowIndex: Int) -> Bool {
- if tableView.isEqual(to: self.thumbnailTableView) {
- // NSRect rect = [[[pdfView document] pageAtIndex:row] boundsForBox:kPDFDisplayBoxCropBox];
- //
- // rect.origin.y = NSMidY(rect) - 0.5 * SNAPSHOT_HEIGHT;
- // rect.size.height = SNAPSHOT_HEIGHT;
- // [self showSnapshotAtPageNumber:row forRect:rect scaleFactor:[pdfView scaleFactor] autoFits:NO];
- let thumbailTabCell = tableView.view(atColumn: 0, row: rowIndex, makeIfNecessary: true) as? KMThumbnailTableviewCell
- thumbailTabCell?.isSelectCell = true
- var rowIndexSet = IndexSet()
- for i in self.thumbnailTableView.selectedRowIndexes {
- rowIndexSet.insert(i)
- }
- rowIndexSet.insert(rowIndex)
- self.thumbnailTableView.selectRowIndexes(rowIndexSet, byExtendingSelection: true)
- return true
- }
- return false
- }
-
- func tableView(_ tableView: NSTableView, shiftSelectRow rowIndex: Int) -> Bool {
- if tableView.isEqual(to: self.thumbnailTableView) {
- if (self.thumbnailTableView.selectedRowIndexes.count == 0) {
- let thumbailTabCell = tableView.view(atColumn: 0, row: rowIndex, makeIfNecessary: true) as? KMThumbnailTableviewCell
- thumbailTabCell?.isSelectCell = true
- var rowIndexSet = IndexSet()
- self.thumbnailTableView.selectRowIndexes(rowIndexSet, byExtendingSelection: true)
- return true
- } else if (self.thumbnailTableView.selectedRowIndexes.count == 1 && self.thumbnailTableView.selectedRowIndexes.first == rowIndex) {
- return false
- } else {
- var fristIndex = self.thumbnailTableView.selectedRowIndexes.first ?? Int.min
- var lastIndex = self.thumbnailTableView.selectedRowIndexes.last ?? Int.max
- for idx in self.thumbnailTableView.selectedRowIndexes {
- // [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if(idx < fristIndex) {
- fristIndex = idx
- }
- if(idx > lastIndex) {
- lastIndex = idx
- }
- }
-
- if(rowIndex < fristIndex) {
- fristIndex = rowIndex
- } else if (rowIndex > lastIndex) {
- lastIndex = rowIndex
- }
- var rowIndexSet = IndexSet()
- for i in fristIndex ... lastIndex {
- rowIndexSet.insert(i)
- }
- self.thumbnailTableView.selectRowIndexes(rowIndexSet, byExtendingSelection: true)
- return true
- }
- }
- return false
- }
- }
- // MARK: - 扩展
- extension KMLeftSideViewController {
- public func selectType(_ type: BotaType) {
- // 更新 type
- var show = true
- if (self.type.methodType == .None) {
- show = true
- } else {
- if (self.type.methodType == type) {
- show = false
- } else {
- show = true
- }
- }
-
- var index: Int = NSNotFound
- switch type {
- case .None:
- index = NSNotFound
- break
- case .Thumbnail:
- index = 0
- break
- case .Outline:
- index = 1
- break
- case .BookMark:
- index = 2
- break
- case .Annotation:
- index = 3
- break
- case .Search:
- index = 4
- break
- case .From:
- index = 5
- break
- case .Signature:
- index = 6
- break
- case .snapshot:
- index = 7
- break
- }
-
- self.type = self.getMethodMode(show ? type : .None)
-
- // 更新按钮状态
- // self.updateViewButtonState()
- // 将事件传递出去
- self.delegate?.controlStateChange?(self,show:show)
- if (index != NSNotFound) {
-
- // 记录当前选中
- UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
- UserDefaults.standard.synchronize()
- }
- }
-
- private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
- let mode = KMLeftMethodMode()
- mode.methodType = type
- switch type {
- case .None:
- mode.methodName = ""
- break
- case .Thumbnail:
- mode.methodName = thumbnailMethodKey
- break
- case .Outline:
- mode.methodName = outlineMethodKey
- break
- case .BookMark:
- mode.methodName = bookMarkMethodKey
- break
- case .Annotation:
- mode.methodName = anntationMethodKey
- break
- case .Search:
- mode.methodName = searchMethodKey
- break
- case .From:
- mode.methodName = formMethodKey
- break
- case .Signature:
- mode.methodName = signatureMethodKey
- break
- case .snapshot:
- mode.methodName = snapshotMethodKey
- }
- return mode
- }
- }
- //MARK: Cache
- extension KMLeftSideViewController {
- func clearAnnotationFilterData() {
- if let _key = self.listView?.document?.documentURL?.path {
- let userDefaults = UserDefaults.standard
- let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
- userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + _key)
- let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
- userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + _key)
- let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
- userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + _key)
- userDefaults.synchronize()
- }
- }
-
- func clearNotification() {
- }
- }
- // MARK: - Analytics (埋点)
- extension KMLeftSideViewController {
- func trackEvent(type: BotaType) -> Void {
- if (type == .Thumbnail) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Thumbnail", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .Outline) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Outline", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .BookMark) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_BookMark", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .Annotation) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Annotation", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .Search) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Search", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- }
- }
- }
- // MARK: - Private Methods
- extension KMLeftSideViewController {
- @objc private func _themeChanged(_ notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
- self._updateViewColor()
- }
- }
-
- private func _updateViewColor() {
- if(KMAppearance.isDarkMode()){
- self.leftListView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.noteView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.outlineView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.view.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.thumbnailTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
- self.groupedFindTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
- self.tocOutlineView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
- self.findTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
-
- self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
- self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
- self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
- self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
-
- self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
- self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
- self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
- } else {
- self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.noteView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.outlineView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.view.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
-
- self.thumbnailTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
- self.groupedFindTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
- self.tocOutlineView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
- self.findTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
-
- self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
-
- self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
- self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
- self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
- }
- }
-
- private func _hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {
- var label = outline.label ?? ""
- var searchLabel = searchString
- if self.outlineIgnoreCaseFlag {
- label = label.lowercased()
- searchLabel = searchLabel.lowercased()
- }
- if label.contains(searchLabel) {
- // if ([outline.label rangeOfString:searchString options:self.outlineIgnoreCaseFlag?NSCaseInsensitiveSearch:0].location != NSNotFound){
- return true
- } else {
- var subHas = false
- for i in 0 ..< outline.numberOfChildren {
- if let subOutline = outline.child(at: i) {
- subHas = self._hasContainString(searchString, rootOutline: subOutline)
- } else {
- continue
- }
- if (subHas) {
- break
- }
- }
- return subHas
- }
- return false
- }
- }
- // MARK: - NSTableViewDelegate, NSTableViewDataSource
- extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
- func numberOfRows(in tableView: NSTableView) -> Int {
- if tableView.isEqual(to: self.thumbnailTableView) {
- return self.thumbnails.count
- } else if tableView.isEqual(to: self.findTableView) {
- return self.searchResults.count
- } else if tableView.isEqual(to: self.groupedFindTableView) {
- return self.groupSearchResults.count
- } else if tableView.isEqual(to: self.snapshotTableView) {
- if self.isSearchSnapshotMode {
- return self.searchSnapshots.count
- }
- return self.snapshots.count
- }
- return 0
- }
-
- func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- if tableView.isEqual(to: self.thumbnailTableView) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMThumbnailTableviewCell"), owner: self) as! KMThumbnailTableviewCell
- let thumbnail = self.thumbnails[row]
- cell.pageNumLabel.stringValue = thumbnail.label
- // cell.thumImage.image = thumbnail.image
- cell.pageView.page = self.listView.document.page(at: UInt(row))
- if let _image = thumbnail.image {
- let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
- let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
- if (_image.size.height > _image.size.width) {
- NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
- // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
- // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
- } else {
- NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
- // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
- // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
- }
- }
- if (self.isDisplayPageSize) {
- cell.sizeLabel.isHidden = false
- //获取Page的真实尺寸
- let page = self.listView.document.page(at: UInt(row))
- let rect = page?.bounds(for: .cropBox) ?? .zero
- let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
- let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
- if let data = page?.rotation, data == 90 || data == 270 {
- cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
- } else {
- cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
- }
- } else {
- cell.sizeLabel.isHidden = true
- }
- cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
- if(self.thumbnailTableView.selectedRowIndexes.contains(row)) {
- cell.isSelectCell = true
- } else {
- cell.isSelectCell = false
- }
- return cell
- } else if (tableView.isEqual(to: self.findTableView)) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMFindTableviewCell"), owner: self) as! KMFindTableviewCell
- let selection = searchResults[row]
- if let data = tableColumn?.identifier.rawValue, data == "results" {
- cell.resultLabel.attributedStringValue = selection.attributedString
- cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
- } else if let data = tableColumn?.identifier.rawValue, data == "page" {
- cell.resultLabel.stringValue = "\(Int(selection.selection.page?.pageIndex() ?? 0) + 1)"
- cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
- }
- return cell
- } else if tableView.isEqual(to: self.snapshotTableView) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMSnapshotTableViewCell"), owner: self) as! KMSnapshotTableViewCell
- var snapshot: KMSnapshotModel?
- if self.isSearchSnapshotMode {
- snapshot = self.searchSnapshots[row]
- } else {
- snapshot = self.snapshots[row]
- }
-
- cell.snapshotImage.image = snapshot?.windowC?.thumbnail
- cell.snapshotLabel.stringValue = snapshot?.windowC?.pageLabel ?? ""
- if let data = snapshot?.windowC?.hasWindow, data {
- cell.snapshotImageView.isHidden = false
- } else {
- cell.snapshotImageView.isHidden = true
- }
- cell.isSelectCell = snapshot?.isSelected ?? false
- if (row == tableView.selectedRow) {
- cell.snapshotImageView.image = NSImage(named: KMImageNameUXIconSidebarSnapshotWindowSel)
- } else {
- cell.snapshotImageView.image = NSImage(named: KMImageNameUXIconSidebarSnapshotWindowNor)
- }
- return cell
- }
- return nil
- }
-
- func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
- if tableView.isEqual(to: self.thumbnailTableView) {
- let scaling = UserDefaults.standard.float(forKey: "KMThumbnailSizeScalingKey")
- // let thumbnailSize = self.thumbnails[row].size
- let thumbnailSize = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
-
- let newScaling: CGFloat = scaling.cgFloat + 0.1
- let newThumbnailHeight = thumbnailSize.width * newScaling
- if (newThumbnailHeight > MIN_SIDE_PANE_WIDTH) {
- self.thumbnailZoomOutButton.isEnabled = false
- } else {
- self.thumbnailZoomOutButton.isEnabled = true
- }
- if ((scaling - 0.1) < 0.3) {
- self.thumbnailZoomInButton.isEnabled = false
- } else {
- self.thumbnailZoomInButton.isEnabled = true
- }
- var labelHeight = 0.0
- if (self.isDisplayPageSize) {
- labelHeight = 56.0
- } else {
- labelHeight = 41.5
- }
- let cellHeight = thumbnailSize.height + labelHeight
- var thumbSize: NSSize = .zero
- if (scaling != nil && scaling > 0) {
- thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
- } else {
- thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
- }
- return thumbSize.height
-
- // NSSize cellSize = NSMakeSize([[tv tableColumnWithIdentifier:IMAGE_COLUMNID] width], fmin(thumbSize.height, roundedThumbnailSize));
- // if (thumbSize.height < [tv rowHeight])
- // return [tv rowHeight];
- // else if (thumbSize.width / thumbSize.height < cellSize.width / cellSize.height)
- // return cellSize.height;
- // else
- // return fmax([tv rowHeight], fmin(cellSize.width, thumbSize.width) * thumbSize.height / thumbSize.width);
- } else if tableView.isEqual(to: self.snapshotTableView) {
- let scaling = UserDefaults.standard.float(forKey: "KMSnapshotSizeScalingKey")
- // NSSize snapshotSize = [[[[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row] thumbnail] size];
- let snapshotSize = CGSizeMake(120, 63)
- var newScaling = scaling + 0.1
- let newSnapshotHeight = snapshotSize.width * newScaling.cgFloat;
- if (newSnapshotHeight > MIN_SIDE_PANE_WIDTH) {
- self.snapshotNormalZoomInButton.isEnabled = false
- } else {
- self.snapshotNormalZoomInButton.isEnabled = true
- }
- if ((scaling - 0.1) < 0.3 || (newSnapshotHeight < 150.0)) {
- self.snapshotNormalZoomOutButton.isEnabled = false
- } else {
- self.snapshotNormalZoomOutButton.isEnabled = true
- }
- let cellHeight = snapshotSize.height + 24.0
- var thumbSize: NSSize = .zero
- if (scaling > 0) {
- thumbSize = NSMakeSize(snapshotSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
- } else {
- thumbSize = NSMakeSize(snapshotSize.width, cellHeight)
- }
- return thumbSize.height
- } else if (tableView.isEqual(to: self.findTableView)) {
- return 40.0
- } else if tableView.isEqual(to: self.groupedFindTableView) {
- return 16
- }
- return tableView.rowHeight
- }
-
- func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
- if (tableView.isEqual(to: self.findTableView)) {
- let rowView = KMBotaTableRowView()
- return rowView
- } else if tableView.isEqual(to: self.groupedFindTableView) {
- let rowView = KMGroupFindTableRowView()
- rowView.totalNumber = self.groupSearchResults.first?.datas.count ?? 0
- let model = self.groupSearchResults[row]
- rowView.number = model.datas.count
- rowView.pageIndex = Int(model.selectionPageIndex) + 1
- return rowView
- }
- return nil
- }
-
- func tableViewSelectionIsChanging(_ notification: Notification) {
-
- }
- func tableViewSelectionDidChange(_ notification: Notification) {
- // if ([[aNotification object] isEqual:leftSideController.findTableView] || [[aNotification object] isEqual:leftSideController.groupedFindTableView]) {
- // [self updateFindResultHighlightsForDirection:NSDirectSelection];
- //
- // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- // [self hideLeftSideWindow];
- // } else
- if self.findTableView.isEqual(to: notification.object) {
- let row = self.findTableView.selectedRow
- if row >= 0 {
- let model = self.searchResults[row]
- if model.selection != nil {
- self.listView.go(to: model.selection, animated: true)
- self.listView.setHighlightedSelection(model.selection, animated: true)
- self.listView.setNeedsDisplayAnnotationViewForVisiblePages()
- }
- }
- } else if self.thumbnailTableView.isEqual(to: notification.object) {
- // if (mwcFlags.updatingThumbnailSelection == 0) {
- let row = self.thumbnailTableView.selectedRow
- let curPage = self.listView.document.index(for: self.listView.currentPage())
-
- if (row != -1 && row != curPage) {
- // [pdfView goToPage:[[pdfView document] pageAtIndex:row]];
- self.listView.go(toPageIndex: row, animated: true)
- }
-
- // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- // [self hideLeftSideWindow];
-
- // thumbnailSelectCount = row;
- // var rowIndexSet = IndexSet()
- // for i in 0 ..< self.thumbnailTableView.numberOfRows {
- // rowIndexSet.insert(i)
- // }
- // self.thumbnailTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: IndexSet(integer: 0))
- // }
- let view = self.thumbnailTableView.view(atColumn: 0, row: self.preThumbnailRow, makeIfNecessary: false) as? KMThumbnailTableviewCell
- view?.isSelectCell = false
-
- let view2 = self.thumbnailTableView.view(atColumn: 0, row: row, makeIfNecessary: false) as? KMThumbnailTableviewCell
- view2?.isSelectCell = true
-
- self.preThumbnailRow = row
- }
- // else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
- // NSInteger row = [rightSideController.snapshotTableView selectedRow];
- // [selectCellList removeAllObjects];
- // [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
- // if (row != -1) {
- // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
- // if ([[controller window] isVisible])
- // [[controller window] orderFront:self];
- // }
- // NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- // for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
- // [rowIndexSet addIndex:i];
- // }
- // NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- // [columnIndexSet addIndex:0];
- // [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
- //
- // }
- }
-
- func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
- if dropOperation == .on || tableView.isEqual(to: self.thumbnailTableView) == false {
- return NSDragOperation(rawValue: 0)
- }
- let pboard = info.draggingPasteboard
- if (pboard.availableType(from: [.localDraggedTypes]) != nil) {
- return .move
- } else if (pboard.availableType(from: [.fileURL]) != nil) && tableView.isEqual(to: self.thumbnailTableView) {
- guard let pbItems = pboard.pasteboardItems else {
- return NSDragOperation(rawValue: 0)
- }
-
- var hasValidFile = false
- for item in pbItems {
- guard let data = item.string(forType: .fileURL), let _url = URL(string: data) else {
- continue
- }
- let type = _url.pathExtension.lowercased()
- hasValidFile = true
- }
-
- if (!hasValidFile) {
- return NSDragOperation(rawValue: 0)
- }
- }
- return NSDragOperation(rawValue: 0)
- }
-
- func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
- var result = false
- if tableView.isEqual(to: self.thumbnailTableView) == false {
- return result
- }
-
- let pasteboard = info.draggingPasteboard
- if (pasteboard.availableType(from: [.localDraggedTypes]) != nil) {
- result = true
- let rowData = pasteboard.data(forType: .localDraggedTypes)
- let rowIndexes = NSKeyedUnarchiver.unarchiveObject(with: rowData!) as? IndexSet ?? IndexSet()
- let urlData = pasteboard.data(forType: KPDFThumbnailDoucumentURLForDraggedTypes)
- let url = NSKeyedUnarchiver.unarchiveObject(with: urlData!) as? String
- if url != nil && url != self.listView.document.documentURL.absoluteString {
- if (pasteboard.availableType(from: [.fileURL]) != nil) {
- // if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
- // NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
- var fileNames = pasteboard.propertyList(forType: .fileURL) as? [String] ?? []
- if (fileNames.count == 1) {
- let path = fileNames.first ?? ""
- let pathExtension = path.pathExtension.lowercased()
- if pathExtension == "pdf" {
- var index = row
- // __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- var insertIndexSet = IndexSet()
- var pdf = CPDFDocument(url: URL(fileURLWithPath: path))
- if let data = pdf?.isEncrypted, data {
- // if ([pdf isEncrypted]) {
- // KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
- // vc.filePath = url;
- // [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
- // if (password) {
- // [pdf unlockWithPassword:password];
- // for(NSUInteger i=0; i<pdf.pageCount;i++) {
- // PDFPage *page = [[pdf pageAtIndex:i] copy];
- // [self.pdfView.document insertPage:page atIndex:index];
- // [insertIndexSet addIndex:index];
- // index++;
- // [page release];
- // }
- // [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- // }
- // }];
- // [vc release];
- } else {
- for i in 0 ..< (pdf?.pageCount ?? 0) {
- // PDFPage *page = [[pdf pageAtIndex:i] copy];
- var page = pdf?.page(at: i)
- self.listView.document.insertPageObject(page, at: UInt(index))
- insertIndexSet.insert(index)
- index += 1
- }
- self.insertPages(insertIndexSet, pageAt: index-1)
- }
- }
- return true
- }
- }
- }
- var pageIndex = 0
- var pages: [CPDFPage] = []
- for idx in rowIndexes {
- let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage
- pages.append(page!)
- }
- var toPage: CPDFPage?
- if row < self.listView.document.pageCount {
- toPage = self.listView.document.page(at: UInt(row))
- }
- var toPageIndex = 0
- if (toPage != nil) {
- toPageIndex = Int(self.listView.document.index(for: toPage))
- } else {
- toPageIndex = Int(self.listView.document.pageCount)
- }
- for i in 0 ..< pages.count {
- var page = pages[i]
- self.listView.document.insertPageObject(page, at: UInt(toPageIndex+i))
- pageIndex += 1
- self.listView.go(toPageIndex: toPageIndex+i, animated: false)
- }
- self.listView.layoutDocumentView()
- var deletepages: [CPDFPage] = []
- for idx in rowIndexes {
- if idx < toPageIndex {
- if((idx+pageIndex) < self.listView.document.pageCount) {
- var page = self.listView.document.page(at: UInt(idx))
- deletepages.append(page!)
- self.listView.document.removePage(at: IndexSet(integer: idx))
- }
- } else {
- if((idx+pageIndex) < self.listView.document.pageCount) {
- let page = self.listView.document.page(at: UInt(idx+pageIndex))
- deletepages.append(page!)
- self.listView.document.removePage(at: IndexSet(integer: idx+pageIndex))
- }
- }
- }
- // [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
- // [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
- self.listView.layoutDocumentView()
- self.resetThumbnails()
- }
- // else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
- // if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- //
- // return NO;
- // }
- //
- // NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
- // NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- // __block NSInteger index = row;
- //
- // if (fileNames.count == 1) {
- // NSString *path = fileNames.firstObject;
- // NSString *pathExtension = [path.pathExtension lowercaseString];
- // if ([pathExtension isEqualToString:@"pdf"]) {
- // PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
- // if ([pdf isEncrypted]) {
- // KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
- // vc.filePath = path;
- // [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
- // if (password) {
- // [pdf unlockWithPassword:password];
- // for (NSUInteger i = 0; i< pdf.pageCount; i++) {
- // PDFPage *page = [[pdf pageAtIndex:i] copy];
- // [self.pdfView.document insertPage:page atIndex:index];
- // [insertIndexSet addIndex:index];
- // index++;
- // [page release];
- // }
- // [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- // }
- // }];
- // [vc release];
- // } else {
- // for (NSUInteger i = 0; i < pdf.pageCount; i++) {
- // PDFPage * page = [[pdf pageAtIndex:i] copy];
- // [self.pdfView.document insertPage:page atIndex:index];
- // [insertIndexSet addIndex:index];
- // index++;
- // [page release];
- // }
- // [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- //
- // }
- // } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
- // NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
- // PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
- // [pdfView.document insertPage:page atIndex:index];
- // [insertIndexSet addIndex:index];
- // [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- // }
- // result = YES;
- // } else {
- // result = NO;
- // }
- // }
- return result == false
- }
-
- func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
- if tableView.isEqual(to: self.thumbnailTableView) {
- let idx = rowIndexes.first ?? NSNotFound
- if (idx != NSNotFound && self.listView.document.isLocked == false) {
- let page = self.listView.document.page(at: UInt(idx))
- var fileExt: String?
- let tiffData = page?.PDFListViewTIFFData(for: page?.bounds(for: self.listView.displayBox) ?? .zero)
- if self.listView.document.allowsPrinting {
- // NSData *pdfData = [page dataRepresentation];
- fileExt = "pdf"
- // filenames
- pboard.declareTypes([.pdf, .tiff, .fileURL, .filePromise, .localDraggedTypes, KPDFThumbnailDoucumentURLForDraggedTypes], owner: self)
- // let newDoc = CPDFDocument()
- // newDoc?.insertPageObject(page, at: 0)
- // let data = newDoc?.dataRepresentation()
-
- // [pboard setData:pdfData forType:NSPasteboardTypePDF];
- pboard.setData(tiffData, forType: .pdf)
-
- // NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
- let zNSIndexSetData = NSKeyedArchiver.archivedData(withRootObject: rowIndexes)
- pboard.setData(zNSIndexSetData, forType: .localDraggedTypes)
-
- let documentURL = NSKeyedArchiver.archivedData(withRootObject: self.listView.document.documentURL?.absoluteString)
- // NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
- var docmentName = self.listView.document.documentURL.deletingPathExtension().lastPathComponent
- // __block NSMutableString *pagesName = nil;
- var pagesName = ""
- if (rowIndexes.count > 1) {
- pagesName = " pages"
- } else {
- pagesName = " page"
- }
- let tFileName = String(format: "%@ %@", pagesName, self.fileNameWithSelectedPages(rowIndexes))
- let pdf = CPDFDocument()
- for idx in rowIndexes {
- // var copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
- var copyPage = self.listView.document.page(at: UInt(idx))
- pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
- }
- let paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
- var cachesDir = paths.first ?? ""
- // docmentName = [NSString stringWithFormat:@"%@%@",docmentName,tFileName];
- docmentName = String(format: "%@%@", docmentName, tFileName)
- if (docmentName.count > 50) {
- docmentName = docmentName.substring(to: 50)
- }
- // cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
- cachesDir = "\(cachesDir)/\(docmentName).pdf"
- let success = pdf?.write(toFile: cachesDir) ?? false
- if (success) {
- // [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
- pboard.setPropertyList([cachesDir], forType: .fileURL)
- } else{
- // [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
- pboard.setPropertyList([], forType: .fileURL)
- }
- pboard.setData(documentURL, forType: KPDFThumbnailDoucumentURLForDraggedTypes)
- } else {
- fileExt = "tiff"
- pboard.declareTypes([.tiff, .filePromise], owner: self)
- }
- pboard.setData(tiffData, forType: .tiff)
- pboard.setPropertyList([fileExt], forType: .filePromise)
-
- // let data: Data = try! NSKeyedArchiver.archivedData(withRootObject: rowIndexes, requiringSecureCoding: true)
- // pboard.declareTypes([.localDraggedTypes], owner: self)
- // pboard.setData(data, forType: .localDraggedTypes)
- return true
- }
- }
- // else if ([tv isEqual:rightSideController.snapshotTableView]) {
- // NSUInteger idx = [rowIndexes firstIndex];
- // if (idx != NSNotFound) {
- // SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
- // [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
- // [pboard setData:[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] forType:NSPasteboardTypeTIFF];
- // [pboard setPropertyList:[NSArray arrayWithObject:@"tiff"] forType:NSFilesPromisePboardType];
- // return YES;
- // }
- // }
- return false
- }
-
- @objc dynamic func tableView(_ aTableView: NSTableView, deleteRowsWithIndexes rowIndexes: IndexSet) {
- // if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- // if ([tv isEqual:rightSideController.snapshotTableView]) {
- // NSArray *controllers = [[rightSideController.snapshotArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
- // [controllers makeObjectsPerformSelector:@selector(close)];
- // } else
- if aTableView.isEqual(to: self.thumbnailTableView) {
- for idx in rowIndexes {
- if idx >= self.listView.document.pageCount {
- return
- }
- if let page = self.listView.document.page(at: UInt(idx)) {
- for anno in page.annotations {
- page.removeAnnotation(anno)
- }
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).insertPage(page, pageAt: idx)
- self.listView.document.removePage(at: IndexSet(integer: idx))
- }
- }
- self.listView.layoutDocumentView()
- // [pageLabels setArray:[[pdfView document] pageLabels]];
- self.resetThumbnails()
- let idx = rowIndexes.first ?? -1
- let index = min(idx, Int(self.listView.document.pageCount)-1)
- self.listView.go(toPageIndex: index, animated: false)
- }
- }
-
- func tableView(_ aTableView: NSTableView, copyRowsWithIndexes rowIndexes: IndexSet) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- if aTableView.isEqual(to: self.thumbnailTableView) {
- self._copysPages.removeAll()
- if self.listView.document.isLocked == false {
- for idx in rowIndexes {
- if let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage {
- self._copysPages.append(page)
- }
- }
- // NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
- // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- // NSPasteboardItem *pboardItem = [[[NSPasteboardItem alloc] init] autorelease];
- // if ([[pdfView document] allowsPrinting])
- // [pboardItem setData:[page dataRepresentation] forType:NSPasteboardTypePDF];
- // [pboardItem setData:tiffData forType:NSPasteboardTypeTIFF];
- // [pboard clearContents];
- // [pboard writeObjects:[NSArray arrayWithObjects:pboardItem, nil]];
- }
- }
- // else if ([tv isEqual:leftSideController.findTableView]) {
- // NSMutableString *string = [NSMutableString string];
- // [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- // PDFSelection *match = [searchResults objectAtIndex:idx];
- // [string appendString:@"* "];
- // [string appendFormat:NSLocalizedString(@"Page %@", @""), [match firstPageLabel]];
- // [string appendFormat:@": %@\n", [[match contextString] string]];
- // }];
- // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- // [pboard clearContents];
- // [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
- // } else if ([tv isEqual:leftSideController.groupedFindTableView]) {
- // NSMutableString *string = [NSMutableString string];
- // [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- // SKGroupedSearchResult *result = [groupedSearchResults objectAtIndex:idx];
- // NSArray *matches = [result matches];
- // [string appendString:@"* "];
- // [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result page] displayLabel]];
- // [string appendString:@": "];
- // [string appendFormat:NSLocalizedString(@"%ld Results", @""), (long)[matches count]];
- // [string appendFormat:@":\n\t%@\n", [[matches valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
- // }];
- // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- // [pboard clearContents];
- // [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
- // }
- }
-
- /*
-
- #pragma mark dragging
- - (NSArray *)tableView:(NSTableView *)tv namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- __block NSMutableArray *fileURLArray = [NSMutableArray array];
- if (rowIndexes.count > 1) {
- NSString *docmentName = @"";
- NSString * tFileName = [NSString stringWithFormat:@"%@",[self fileNameWithSelectedPages:rowIndexes]];
- PDFDocument *pdf = [[[PDFDocument alloc] init] autorelease];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
- PDFPage *copyPage = [[[pdfView document] pageAtIndex:idx] copy];
- [pdf insertPage:copyPage atIndex:pdf.pageCount];
- [copyPage release];
- }
- }];
- NSURL *fileURL = [[[dropDestination URLByAppendingPathComponent:tFileName] URLByAppendingPathExtension:@"pdf"] uniqueFileURL];
- docmentName = fileURL.path;
- BOOL success = [pdf writeToFile:docmentName];
- if(success) {
- [fileURLArray addObject:[fileURL lastPathComponent]];
- }
- } else {
- PDFPage *page = [[pdfView document] pageAtIndex:rowIndexes.firstIndex];
- NSURL *fileURL = [dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
- NSString *pathExt = nil;
- NSData *data = nil;
-
- if ([[pdfView document] allowsPrinting]) {
- pathExt = @"pdf";
- data = [page dataRepresentation];
- } else {
- pathExt = @"tiff";
- data = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
- }
-
- fileURL = [[fileURL URLByAppendingPathExtension:pathExt] uniqueFileURL];
- if ([data writeToURL:fileURL atomically:YES]) {
- [fileURLArray addObject:[fileURL lastPathComponent]];
- }
- }
- return fileURLArray;
- } else if ([tv isEqual:rightSideController.snapshotTableView]) {
- NSUInteger idx = [rowIndexes firstIndex];
- if (idx != NSNotFound) {
- SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
- PDFPage *page = [[pdfView document] pageAtIndex:[snapshot pageIndex]];
- NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]] URLByAppendingPathExtension:@"tiff"];
- fileURL = [fileURL uniqueFileURL];
- if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] writeToURL:fileURL atomically:YES])
- return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
- }
- }
- return [NSArray array];
- }
- - (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors {
- if ([tv isEqual:leftSideController.groupedFindTableView]) {
- [leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
- }
- }
- #pragma mark NSTableView delegate protocol
- - (void)tableViewColumnDidResize:(NSNotification *)aNotification {
- if ([[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:IMAGE_COLUMNID]) {
- if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
- [leftSideController.thumbnailTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [leftSideController.thumbnailTableView numberOfRows])]];
- } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
- [rightSideController.snapshotTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.snapshotTableView numberOfRows])]];
- }
- }
- }
- - (void)tableView:(NSTableView *)tv shareRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- NSUInteger idx = [rowIndexes firstIndex];
- if (idx != NSNotFound) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- NSString *fileName = [[[pdfView document] documentURL] lastPathComponent];
- NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
- NSString *filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Untitled"]];
- filePath = [filePath stringByAppendingPathExtension:[fileName pathExtension]];
-
- [self fileWithPage:page atPath:filePath];
-
- if (rint(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
- [KMMailHelper sendFileWithPaths:[NSArray arrayWithObject:filePath]];
- } else {
- NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
- [service performWithItems:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]]];
- }
- }
- }
- }
- - (void)fileWithPage:(PDFPage *)page atPath:(NSString *)filePath {
- NSData *data = [page dataRepresentation];
- PDFDocument *document = [[PDFDocument alloc] initWithData:data];
-
- [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
- BOOL success = [document writeToURL:[NSURL fileURLWithPath:filePath]];
- if (success) {
- NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
- NSURL *url = [NSURL fileURLWithPath:filePath];
- [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
- }
-
- [document release];
- */
- }
- // MARK: - NSOutlineViewDelegate, NSOutlineViewDataSource
- /*
-
- func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
- if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?[index] as Any
- } else if item is KMBOTAAnnotationItem {
- return item as Any
- } else {
- var tempArray: [KMBOTAAnnotationSection] = []
- for temp in self.data {
- if temp.annotations?.count != 0 {
- tempArray.append(temp)
- }
- }
- let section = tempArray[index]
- return section as Any
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
- if item is KMBOTAAnnotationItem {
- let cell : KMAnnotationOutlineCellView = KMAnnotationOutlineCellView.init()
- cell.delegate = self
- cell.model = item as? KMBOTAAnnotationItem
- return cell
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
-
- let cell : KMAnnotationOutlineSectionView = KMAnnotationOutlineSectionView.init()
- cell.model = section
- return cell
- }
- return NSTableCellView()
- }
-
- func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
- let rowView = KMAnnotationOutlineRowView()
- if item is KMBOTAAnnotationItem {
- rowView.model = (item as? KMBOTAAnnotationItem)
- } else if item is KMBOTAAnnotationSection {
- rowView.section = (item as? KMBOTAAnnotationSection)
- }
- rowView.mouseDownAction = { [unowned self] view, event in
- if rowView.section != nil {
- let expanded = outlineView.isItemExpanded(outlineView.item(atRow: outlineView.selectedRow))
- if expanded {
- outlineView.collapseItem(outlineView.item(atRow: outlineView.selectedRow), collapseChildren: true)
- outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
- } else {
- outlineView.expandItem(outlineView.item(atRow: outlineView.selectedRow), expandChildren: true)
- outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
- }
- } else if rowView.model != nil {
- self.didSelectItem(view: rowView, event: event)
- }
- }
-
- rowView.rightMouseDownAction = { [unowned self] view, event in
- if rowView.section != nil {
-
- } else if rowView.model != nil {
- if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
- self.selectItems.count == 1 {
- self.selectItem(item: item as! KMBOTAAnnotationItem)
- }
-
- DispatchQueue.main.async {
- self.delegate?.annotationOutlineView(self, rightMouseDownDidSelectView: view, evnet: event)
- }
- }
- }
-
- rowView.hoverCallback = { [unowned self] (mouseEntered, mouseBox) in
- self.outlineView.enumerateAvailableRowViews { view, row in
- if view is KMAnnotationOutlineRowView {
- (view as? KMAnnotationOutlineRowView)?.model?.hover = false
- (view as? KMAnnotationOutlineRowView)?.reloadData()
- }
- }
- if mouseEntered {
- rowView.model?.hover = true
- } else {
- rowView.model?.hover = false
- }
- }
- return rowView
- }
-
- func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
- if item is KMBOTAAnnotationItem {
- return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: self.maxWidth - 16, height: 1000))
- } else if item is KMBOTAAnnotationSection {
- return 40
- } else {
- return 30
- }
- }
-
- func outlineViewSelectionDidChange(_ notification: Notification) {
- if self.outlineView.selectedRow == -1 {
- self.cancelSelect()
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
- if item is KMBOTAAnnotationItem {
- return false
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?.count ?? 0 > 0
- }
- return false
- }
-
- func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
- if let item = item as? KMBOTAAnnotationSection {
- if !item.isItemExpanded {
- item.isItemExpanded = true
- outlineView.animator().expandItem(item, expandChildren: true)
- return false
- }
- }
- return true
- }
- func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool {
- if let item = item as? KMBOTAAnnotationSection {
- if item.isItemExpanded {
- item.isItemExpanded = false
- outlineView.animator().collapseItem(item, collapseChildren: true)
- return false
- }
- }
- return true
- }
- */
- extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSource {
- func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let isLocked = self.listView.document?.isLocked ?? true
- if isLocked { // 文档不存在 或 已加锁
- return 0
- }
- if item == nil { // 第一层
- // 获取根
- guard let outline = self.listView.document.outlineRoot() else {
- let view = self.tocOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
- //
- 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)
- self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
- self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
- return 0
- }
- if outline.numberOfChildren == 0 {
- // return 0
- }
-
- if self.isSearchOutlineMode { // 是否为搜索模块
- if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: outline) {
- self.showSearchOutlineBlankState(false)
- } else {
- self.showSearchOutlineBlankState(true)
- return 0
- }
- } else {
- if outline.numberOfChildren > 0 { // 有数据
- self.leftSideEmptyVC.emptyOutlineView.removeFromSuperview()
- self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = true
- } else { // 没有数据
- let view = self.tocOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
- //
- 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)
- self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
- self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
- return 0
- }
- }
- // 搜索按钮
- if outline.numberOfChildren > 0 {
- self.outlineSearchButton.isEnabled = true
- } else {
- self.outlineSearchButton.isEnabled = false
- }
-
- if (self.isSearchOutlineMode) {
- var num = 0
- for i in 0 ..< outline.numberOfChildren {
- if let child = outline.child(at: i) {
- if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: child) {
- num += 1
- }
- }
- }
- return num
- } else {
- let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
- var bookmarkNum = 0
- if array.isEmpty == false {
- bookmarkNum = 1
- }
- return Int(outline.numberOfChildren) + bookmarkNum
- }
- } else { // 第二层 +
- if self.isSearchOutlineMode {
- if let data = item as? String, data == "Bookmarks" { // 书签group
- return 0
- } else if item is CPDFOutline { // 大纲
- let child = item as! CPDFOutline
- if child.numberOfChildren == 0 {
- return 0
- }
- var num = 0
- for i in 0 ..< child.numberOfChildren {
- if let _child = child.child(at: i) {
- if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: _child) {
- num += 1
- }
- }
- }
- return num
- } else if item is CPDFBookmark { // 书签
- return 0
- }
- } else {
- if let data = item as? String, data == "Bookmarks" { // 书签group
- return (self.listView.document?.bookmarks().count) ?? 0
- } else if item is CPDFOutline { // 大纲
- return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
- } else if item is CPDFBookmark { // 书签
- return 0
- }
- }
- }
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- if self.noteSearchMode {
- return self.noteSearchArray.count
- }
- var count = 0
- for section in self._annotations {
- if section.annotations?.count != 0 {
- count += section.annotations!.count
- }
- }
- // if (item == nil){
- // NSInteger count = [[rightSideController.noteArrayController arrangedObjects] count];
-
- if (count < 1) {
- // if (notes.count < 1) {
- self.noteSearchButton.isEnabled = false
- self.noteFilterButton.isEnabled = false
- // }
- self.noteOutlineView.usesAlternatingRowBackgroundColors = false
- let view = self.noteOutlineView.enclosingScrollView!
- var emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
- 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)
-
- self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
- self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
- self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
- //
- if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
- self.noteHeaderView.isHidden = true
- self.toolButtonBoxLayoutConstraint.constant = 40.0
- }
- } else {
- self.noteSearchButton.isEnabled = true
- self.noteFilterButton.isEnabled = true
- self.noteOutlineView.usesAlternatingRowBackgroundColors = false
- self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
- self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
- self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
- //
- if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
- self.noteHeaderView.isHidden = false
- self.toolButtonBoxLayoutConstraint.constant = 64.0
- }
- }
- return count
- // } else {
- // return [item hasNoteText];
- // }
- }
- return 0
- }
-
- func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let isLocked = self.listView.document?.isLocked ?? true
- if isLocked { // 文档不存在 或 已加锁
- return ""
- }
-
- let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
- var bookmarkNum = 0
- if array.isEmpty == false {
- bookmarkNum = 1
- }
- if item == nil {
- if self.isSearchOutlineMode {
- guard let outline = self.listView.document.outlineRoot() else {
- return ""
- }
- if outline.numberOfChildren == 0 {
- return ""
- }
- var array: [CPDFOutline] = []
- for i in 0 ..< outline.numberOfChildren {
- if let child = outline.child(at: i) {
- if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: child) {
- array.append(child)
- }
- }
- }
-
- if index < array.count {
- return array[index]
- }
- return ""
- } else {
- if index == 0 && bookmarkNum == 1 {
- return "Bookmarks"
- } else {
- var _index = bookmarkNum == 1 ? index-1 : index
- let outline = self.listView.document.outlineRoot()
- var obj = outline?.child(at: UInt(_index))
- return obj as Any
- }
- }
- } else {
- if let data = item as? String, data == "Bookmarks" {
- return array[index]
- } else if item is CPDFOutline {
- return (item as! CPDFOutline).child(at: UInt(index))
- } else if item is CPDFBookmark {
- return ""
- }
- }
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- // if (item == nil)
- // {
- // return [[rightSideController.noteArrayController arrangedObjects] objectAtIndex:anIndex];
- // // return [self.notes objectAtIndex:anIndex];
- // }
- // else
- // return [item noteText];
- if self.noteSearchMode {
- return self.noteSearchArray[index]
- }
- var tempArray: [KMBOTAAnnotationItem] = []
- for secion in self._annotations {
- if secion.annotations?.count != 0 {
- for _item in secion.annotations! {
- tempArray.append(_item)
- }
- }
- }
- return tempArray[index] as Any
- }
- return item
- }
-
- func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
- if outlineView.isEqual(to: self.tocOutlineView) {
- // let tcID = tableColumn?.identifier.rawValue ?? ""
- // var ol = item as? CPDFOutline
- // if(tcID == LABEL_COLUMNID) {
- // if (self.isSearchOutlineMode) {
- //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- //// NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
- //// NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
- //// for (NSUInteger i = 0; i <arr.count ; i++) {
- //// NSValue * rangeValue = arr[i];
- //// NSRange range = rangeValue.rangeValue;
- //// range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
- //// [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
- //// }
- //// [attributeString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:NSMakeRange(0, roughString.length)];
- //// return attributeString;
- // } else {
- // var attributedString = NSMutableAttributedString()
- //// attributedString
- // attributedString.append(.init(string: ol?.label ?? "", attributes: [.foregroundColor : KMAppearance.Layout.h0Color()]))
- //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- //// NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- //// NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- //// [attributedString appendAttributedString:attr1];
- //
- // return attributedString
- // }
- //
- // }
- // else if([tcID isEqualToString:PAGE_COLUMNID]) {
- // NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- // NSString *roughString = [ol pageLabel]? : @"";
- // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- // [attributedString appendAttributedString:attr1];
- //
- // return attributedString;
- // }
-
- }
- // else if ([ov isEqual:rightSideController.noteOutlineView]) {
- // NSString *tcID = [tableColumn identifier];
- // PDFAnnotation *note = item;
- // if (tableColumn == nil || [tcID isEqualToString:NOTE_COLUMNID])
- // return [note objectValue];
- // else if([tcID isEqualToString:TYPE_COLUMNID]){
- // NSString *noteType = [note type];
- // if ([note isKindOfClass:[PDFAnnotationButtonWidget class]]) {
- // PDFAnnotationButtonWidget *buttonWidget = (PDFAnnotationButtonWidget *)note;
- // if (buttonWidget.controlType == kPDFWidgetRadioButtonControl) {
- // noteType = SKAnnotationFormRadioButtonKey;
- // } else if (buttonWidget.controlType == kPDFWidgetCheckBoxControl){
- // noteType = SKAnnotationFormCheckBoxKey;
- // } else if (buttonWidget.controlType == kPDFWidgetPushButtonControl){
- // noteType = SKAnnotationFormActionButtonKey;
- // }
- // } else if ([note isKindOfClass:[PDFAnnotationTextWidget class]]){
- // noteType = SKAnnotationFormTextFieldKey;
- // } else if ([note isKindOfClass:[PDFAnnotationChoiceWidget class]]){
- // PDFAnnotationChoiceWidget *choiceWidget = (PDFAnnotationChoiceWidget *)note;
- // if (choiceWidget.isListChoice) {
- // noteType = SKAnnotationFormListMenuKey;
- // } else {
- // noteType = SKAnnotationFormComboBoxKey;
- // }
- //
- // }
- // return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:note == [pdfView activeAnnotation]], SKAnnotationTypeImageCellActiveKey, noteType, SKAnnotationTypeImageCellTypeKey,[note color],SKAnnotationTypeImageCellColorKey, nil];
- // }
- // else if([tcID isEqualToString:COLOR_COLUMNID])
- // return [note type] ? [note color] : nil;
- // else if([tcID isEqualToString:PAGE_COLUMNID])
- // return [[note page] displayLabel];
- // else if([tcID isEqualToString:AUTHOR_COLUMNID])
- // return [note type] ? [note userName] : nil;
- // else if([tcID isEqualToString:DATE_COLUMNID])
- // return [note type] ? [note modificationDate] : nil;
- // }
- return nil
- }
-
- func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMTocTableCellView"), owner: self) as! KMTocTableCellView
- let tcID = tableColumn?.identifier.rawValue
-
- var title = ""
- var pageLabel = ""
- if let data = item as? String, data == "Bookmarks" {
- title = NSLocalizedString("Bookmarks", comment: "")
- } else if item is CPDFOutline {
- title = (item as! CPDFOutline).label
- pageLabel = "\(((item as! CPDFOutline).destination?.pageIndex ?? 0) + 1)"
- } else if item is CPDFBookmark {
- title = (item as! CPDFBookmark).label
- pageLabel = "\((item as! CPDFBookmark).pageIndex + 1)"
- }
-
- if tcID == LABEL_COLUMNID {
- if (self.isSearchOutlineMode) {
- // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
- let roughString = title
- // NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
- // NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
- //
- // for (NSUInteger i = 0; i <arr.count ; i++) {
- // NSValue * rangeValue = arr[i];
- // NSRange range = rangeValue.rangeValue;
- // range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
- // [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
- // }
- // cell.tocLabel.attributedStringValue = attributeString;
- cell.tocLabel.stringValue = title
- } else {
- cell.tocLabel.stringValue = title
- }
- cell.pageLabel.stringValue = pageLabel
- }
- // else if([tcID isEqualToString:PAGE_COLUMNID]) {
- // cell.pageLabel.stringValue = [ol pageLabel];
- // }
- return cell
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- let model = item as? KMBOTAAnnotationItem
- var note: CPDFAnnotation!
- if self.noteSearchMode {
- note = item as! CPDFAnnotation
- } else {
- note = (item as! KMBOTAAnnotationItem).annotation!
- }
-
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteTableViewCell"), owner: self) as! KMNoteTableViewCell
- cell.cellNote = note
-
- let noteColor = note.color
- var noteType = note.type ?? ""
- var noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
- // NSString *pageString = [[note page] displayLabel] ? : @"";
- var pageString = "\((note.page?.pageIndex() ?? 0) + 1)"
- let formatter = DateFormatter()
- formatter.dateFormat = "hh:mm"
- var dateString = ""
- if let date = note.modificationDate() {
- dateString = formatter.string(from: date)
- }
- var authorString = note.userName() ?? ""
- // NSString *noteTextString = [note noteText].string ? : @"";
- var noteTextString = note.string() ?? ""
- //
- // if([noteType isEqualToString:@"Redact"]) {
-
- // noteString = @"Redact";
- // }
- //
- let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool
- if timeKey == nil || timeKey == false {
- // if (date != nil) {
- cell.timeLabel.stringValue = dateString
- //
- // } else {
- // cell.timeLabel.stringValue = ""
- // }
- cell.timeLabel.isHidden = false
- } else {
- cell.timeLabel.isHidden = true
- }
-
- let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool
- if pageKey == nil || pageKey == false {
- let labelsize = cell.pageLabel.stringValue.boundingRect(with: CGSizeMake(CGFloat(MAXFLOAT),CGRectGetHeight(cell.pageLabel.bounds)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font : NSFont.systemFont(ofSize: 12)])
- cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5
- cell.pageLabel.stringValue = pageString
- cell.pageLabel.isHidden = false
- } else {
- cell.pageLabel.isHidden = true
- }
-
- let autherKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool
- if pageKey == nil || pageKey == false {
- cell.autherLabel.stringValue = authorString
- cell.autherLabel.isHidden = false
- } else {
- cell.autherLabel.isHidden = true
- }
- let imageView = KMNoteTypeImageView()
- if note.isKind(of: CPDFStampAnnotation.self) {
- let annotation_stamp = note as! CPDFStampAnnotation
- if (annotation_stamp.stampImage() != nil) {
- noteType = SKNStampString
- }
- } else if note.isKind(of: CPDFLineAnnotation.self) {
- let annotation_line = note as! CPDFLineAnnotation
- if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .none {
- noteType = SKNLine_NoneString
- } else if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .openArrow {
- noteType = SKNLine_OpenArrowString
- } else {
- noteType = SKNLine_NoneString
- }
- } else if note.isKind(of: CPDFButtonWidgetAnnotation.self) {
- let buttonWidget = note as! CPDFButtonWidgetAnnotation
- if buttonWidget.controlType() == .radioButtonControl {
- noteType = KMAnnotationFormRadioButtonKey
- } else if buttonWidget.controlType() == .checkBoxControl {
- noteType = KMAnnotationFormCheckBoxKey
- } else if buttonWidget.controlType() == .pushButtonControl {
- noteType = KMAnnotationFormActionButtonKey
- }
- } else if note.isKind(of: CPDFTextWidgetAnnotation.self) {
- noteType = KMAnnotationFormTextFieldKey
- } else if note.isKind(of: CPDFChoiceWidgetAnnotation.self) {
- let choiceWidget = note as! CPDFChoiceWidgetAnnotation
- if choiceWidget.isListChoice {
- noteType = KMAnnotationFormListMenuKey
- } else {
- noteType = KMAnnotationFormComboBoxKey
- }
- } else if note.isKind(of: KMTableAnnotation.self) {
- noteType = "Ink_Table"
- } else if note.isKind(of: KMSelfSignAnnotation.self) {
- let selfSignNote = note as! KMSelfSignAnnotation
- if selfSignNote.annotationType == .signFalse {
- noteType = "KMSelfSignTypeFalseActionButtonKey"
- } else if (selfSignNote.annotationType == .signature) {
- noteType = "KMSelfSignTypeTureActionButtonKey"
- } else if (selfSignNote.annotationType == .signCircle) {
- noteType = "KMSelfSignTypeCircleActionButtonKey"
- } else if (selfSignNote.annotationType == .signLine) {
- noteType = "KMSelfSignTypeLineActionButtonKey"
- } else if (selfSignNote.annotationType == .signDot) {
- noteType = "KMSelfSignTypeDotActionButtonKey"
- } else if (selfSignNote.annotationType == .signText) {
- noteType = "KMSelfSignTypeTextActionButtonKey"
- }
- } else if note.isKind(of: CPDFSquareAnnotation.self) {
- noteType = SKNSquareString
- } else if note.isKind(of: CPDFTextAnnotation.self) {
- noteType = SKNNoteString
- } else if note.isKind(of: CPDFFreeTextAnnotation.self) {
- noteType = SKNFreeTextString
- } else if note.isKind(of: CPDFCircleAnnotation.self) {
- noteType = SKNCircleString
- } else if note.isKind(of: CPDFSignatureAnnotation.self) {
- noteType = SKNSignatureString
- } else if note.isKind(of: CPDFInkAnnotation.self) {
- noteType = SKNInkString
- } else if note.isKind(of: CPDFMarkupAnnotation.self) {
- let anno = note as! CPDFMarkupAnnotation
- if anno.markupType() == .highlight {
- noteType = SKNHighlightString
- } else if anno.markupType() == .underline {
- noteType = SKNUnderlineString
- } else if anno.markupType() == .strikeOut {
- noteType = SKNStrikeOutString
- }
- }
-
- cell.typeImageView.image = imageView.noteTypeImage(withType: noteType, color: noteColor ?? .red)
- cell.typeImageView.isHidden = false
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- cell.isFold = true
- }
- cell.noteContentBox.isHidden = true
- cell.noteImageView.isHidden = true
- cell.foldButton.isHidden = true
- cell.annotationContentLabel.isHidden = false
- cell.noteContentLabel.stringValue = noteString
- cell.contentView.isHidden = false
- cell.contentViewHidden(false)
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- let markup = note as! CPDFMarkupAnnotation
- var contentString = KMBOTAAnnotationTool.fetchText(text: markup.markupContent() ?? "")
- contentString = contentString.replacingOccurrences(of: "\r", with: "")
- contentString = contentString.replacingOccurrences(of: "\n", with: "")
- cell.noteContentLabel.stringValue = contentString
- if(contentString.isEmpty == false) {
- cell.foldButton.isHidden = false
- }
- var attributeStr = NSMutableAttributedString(string: contentString)
- if (markup.markupType() == .highlight) {
- attributeStr.addAttribute(.backgroundColor, value: noteColor as Any, range: NSMakeRange(0, contentString.count))
- } else if (markup.markupType() == .strikeOut) {
- attributeStr.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, contentString.count))
- attributeStr.addAttribute(.strikethroughColor, value: noteColor as Any, range: NSMakeRange(0, contentString.count))
- } else if (markup.markupType() == .underline) {
- attributeStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, contentString.count))
- attributeStr.addAttribute(.underlineColor, value: noteColor as Any, range: NSMakeRange(0, contentString.count))
- }
- cell.annotationContentLabel.attributedStringValue = attributeStr
- if let data = model?.foldType, data == .unfold {
- cell.isFold = false
- } else if let data = model?.foldType, data == .fold {
- cell.isFold = true
- } else {
- if self.allFoldNotes.isEmpty == false && self.allFoldNotes.contains(note) {
- cell.isFold = false
- } else {
- cell.isFold = true
- }
- }
- // noteString.isEmpty == false &&
- if (contentString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- } else if note.isKind(of: CPDFLineAnnotation.self) || noteType == SKNSquareString || noteType == SKNCircleString || noteType == SKNInkString {
- cell.annotationContentLabel.stringValue = noteString
- if (noteString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- } else if note.isKind(of: CPDFStampAnnotation.self) {
- if note.isKind(of: KMSelfSignAnnotation.self) {
- let newAnnotation = note as! KMSelfSignAnnotation
- let type = newAnnotation.annotationType
- var returnString = ""
- if (type == .signFalse) {
- returnString = KMLocalizedString("X", nil)
- } else if (type == .signature) {
- returnString = KMLocalizedString("Check mark", nil)
- } else if (type == .signCircle) {
- returnString = KMLocalizedString("Circle", nil)
- } else if (type == .signLine) {
- returnString = KMLocalizedString("Line", nil)
- } else if (type == .signDot) {
- returnString = KMLocalizedString("Dot", nil)
- } else if (type == .signText) {
- returnString = KMLocalizedString("Text", nil)
- }
- cell.annotationContentLabel.stringValue = returnString
- } else {
- cell.annotationContentLabel.isHidden = true
- cell.noteImageView.isHidden = false
- let anno = note as! CPDFStampAnnotation
- cell.noteImageView.image = anno.stampImage()
- }
- } else if note.isKind(of: CPDFTextAnnotation.self) {
- cell.foldButton.isHidden = false
- if noteString.isEmpty {
- cell.annotationContentLabel.stringValue = noteTextString
- }else{
- cell.annotationContentLabel.stringValue = noteString
- cell.noteContentLabel.stringValue = noteTextString
- }
- if (self.foldType == .unfold) {
- cell.isFold = false
- } else if (self.foldType == .fold) {
- cell.isFold = true
- } else {
- if self.allFoldNotes.isEmpty == false && self.allFoldNotes.contains(note) {
- cell.isFold = false
- } else {
- cell.isFold = true
- }
- }
- if (noteString.isEmpty == false || noteTextString.isEmpty == false) {
- cell.contentView.isHidden = false
- } else {
- cell.contentView.isHidden = true
- cell.contentViewHidden(true)
- }
- // noteString.isEmpty == false &&
- if (noteTextString.isEmpty == false) {
- cell.foldButton.isHidden = false
- }else{
- cell.foldButton.isHidden = true
- }
- } else {
- cell.annotationContentLabel.stringValue = noteString
- cell.imageViewHeightConstraint.constant = cell.contentView.frame.size.height
- if (noteString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- }
- cell.autherLayoutConstraint.constant = cell.autherLabel.isHidden ? -(cell.autherLabel.bounds.size.width) + 10.0 : 10.0
- cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.isHidden ? -(cell.typeImageView.bounds.size.width) : 0.0
- cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.isHidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0
- if note.isKind(of: CPDFStampAnnotation.self) && note.isKind(of: KMSelfSignAnnotation.self) == false {
- } else {
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- if (!cell.isFold) {
- self.allFoldNotes.append(note)
- } else {
- cell.imageViewHeightConstraint.constant = 18.0 + 8
- }
- } else {
- cell.imageViewHeightConstraint.constant = 18.0 + 8
- }
- }
- cell.isUnFoldNote = { [unowned self] cellNote, isUnfold in
- model?.foldType = isUnfold ? .unfold : .fold
- // let COLUMN_INDENTATION: CGFloat = 16
- // if let _cell = tableColumn?.dataCell as? NSCell {
- // _cell.objectValue = cell.annotationContentLabel.attributedStringValue
- // let bound = NSMakeRect(0.0, 0.0, fmax(10.0, NSWidth(outlineView.frame) - COLUMN_INDENTATION - outlineView.indentationPerLevel-40), CGFLOAT_MAX)
- // let height = _cell.cellSize(forBounds: bound).height
- // KMPrint(height)
- // }
- if cellNote is CPDFMarkupAnnotation {
- // let content = cell.annotationContentLabel.attributedStringValue
-
- // let bound = content.string.boundingRect(with: NSMakeSize(150, CGFLOAT_MAX), options: [.usesFontLeading, .usesLineFragmentOrigin], attributes: nil)
- // KMPrint(bound)
- // 154 34 273
- // 273 - 188 = 85 noteContentHeightConstraint maltlineLabelLayoutConstraint
- model?.foldH = isUnfold ? 30 : (cell.noteContentHeightConstraint.constant + cell.maltlineLabelLayoutConstraint.constant + 85)
- }
- if (isUnfold) {
- if (self.allFoldNotes.contains(note)) {
- self.allFoldNotes.removeObject(note)
- }
- if (self.allFoldNotes.count == 0) {
- self.foldType = .fold
- } else {
- self.foldType = .none
- }
- } else {
- if self.allFoldNotes.contains(note) == false {
- self.allFoldNotes.append(note)
- }
- // if (rightSideController.allFoldNotes.count == rightSideController.canFoldNotes.count) {
- self.foldType = .unfold
- // } else {
- // self.foldType = KMFoldAllAnnotationType_None;
- // }
- }
- }
- return cell
- }
- return nil
- }
-
- func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
- if outlineView.isEqual(self.noteOutlineView) {
- if item is KMBOTAAnnotationItem {
- let model = item as! KMBOTAAnnotationItem
- if model.foldType == .fold {
- return model.foldH
- }
- return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: 260+40 - 16, height: 1000))
- }
- return 30
- } else if outlineView.isEqual(self.tocOutlineView) {
- if item is CPDFOutline {
- let tempItem = item as! CPDFOutline
- let string: NSString = tempItem.label as NSString
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineHeightMultiple = 1.32
- paragraphStyle.alignment = .left
- let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle,
- NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0)]
- let size = string.boundingRect(with: CGSizeMake(outlineView.frame.size.width - 30, 200), options: NSString.DrawingOptions(rawValue: 3), attributes: attributes)
- return max(40, size.height + 16)
- }
- return 40
- }
- return outlineView.rowHeight
- }
-
- func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
- if outlineView.isEqual(self.tocOutlineView) {
- // var _item: CPDFOutline?
- // if item == nil && self.listView.document.isLocked == false {
- // _item = self.listView.document.outlineRoot()
- // }
- if let data = item as? String, data == "Bookmarks" {
- return true
- } else if item is CPDFOutline {
- return ((item as! CPDFOutline).numberOfChildren ?? 0) != 0
- } else if item is CPDFBookmark {
- return false
- }
-
- if (self.isSearchOutlineMode) {
- // return [self subOutLineContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:(PDFOutline *)item];
- } else {
- // return ((_item?.numberOfChildren ?? 0) != 0)
- }
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- // return [item hasNoteText];
- return false
- }
- return false
- }
-
- func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
- if outlineView.isEqual(self.tocOutlineView) {
- let itemView = KMBotaTableRowView()
- return itemView
- } else if outlineView.isEqual(self.noteOutlineView) {
- let itemView = KMBotaTableRowView()
- return itemView;
- }
- return nil
- }
-
- func outlineViewSelectionDidChange(_ notification: Notification) {
- if self.tocOutlineView.isEqual(to: notification.object) {
- // if ([[notification object] isEqual:leftSideController.tocOutlineView] && (mwcFlags.updatingOutlineSelection == 0)){
- // mwcFlags.updatingOutlineSelection = 1;
- self.goToSelectedOutlineItem(nil)
- // mwcFlags.updatingOutlineSelection = 0;
- // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- // [self hideLeftSideWindow];
- }
- }
-
- func outlineViewItemDidExpand(_ notification: Notification) {
- if self.tocOutlineView.isEqual(to: notification.object) {
- self.updateOutlineSelection()
- }
- }
-
- func outlineViewItemDidCollapse(_ notification: Notification) {
- if self.tocOutlineView.isEqual(to: notification.object) {
- self.updateOutlineSelection()
- }
- }
-
- /*
- #pragma mark NSOutlineView datasource protocol
- - (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item{
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- PDFAnnotation *note = item;
- if ([note type]) {
- if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
- if ([(object ?: @"") isEqualToString:([note string] ?: @"")] == NO)
- [note setString:object];
- } else if ([[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
- if ([(object ?: @"") isEqualToString:([note userName] ?: @"")] == NO)
- [note setUserName:object];
- }
- }
- }
- }
- #pragma mark Drag
- - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard{
-
- if ([outlineView isEqual:leftSideController.tocOutlineView]) {
- if (leftSideController.tocOutlineView.selectedRowIndexes.count > 1) {
- return NO;
- }
- NSIndexSet *tIndex = [[[NSIndexSet alloc] initWithIndex:leftSideController.tocOutlineView.clickedRow] autorelease];
- [leftSideController.tocOutlineView deselectRow:tIndex.firstIndex];
- self.dragPDFOutline = items.firstObject;
- NSIndexSet *set = [NSIndexSet indexSetWithIndex:0];
- NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:set];
- [pasteboard declareTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType] owner:self];
- [pasteboard setData:zNSIndexSetData forType:kKMPDFViewOutlineDragDataType];
- return YES;
- }
- return NO;
- }
- - (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)anIndex {
- NSDragOperation dragOp = NSDragOperationNone;
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
- anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
- dragOp = NSDragOperationEvery;
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (anIndex == -1) {
- dragOp = NSDragOperationNone;
- } else {
- dragOp = NSDragOperationMove;
- }
- }
- return dragOp;
- }
- - (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)anIndex {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]]) {
- BOOL isShift = ([NSEvent standardModifierFlags] & NSEventModifierFlagShift) != 0;
- BOOL isAlt = ([NSEvent standardModifierFlags] & NSEventModifierFlagOption) != 0;
- [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
- return YES;
- }
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (anIndex < 0) {
- return NO;
- }
- PDFOutline *outline = item;
-
- //root,drag item to root
- if (!outline.parent) {
- //fetch root
- PDFOutline *root = self.dragPDFOutline;
- while (root.parent) {
- root = root.parent;
- }
- if ([self.dragPDFOutline.parent isEqual:root]) {
- if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
- } else {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:root];
- }
- } else {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
- }
- } else {
- //在同一个层级内移动
- if ([self.dragPDFOutline.parent isEqual:item]) {
- if (self.dragPDFOutline.index) {
- if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
- }else{
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:outline];
- }
- } else {
- return NO;
- }
- } else {
- PDFOutline *tOutlline = outline;
- BOOL isContains = NO;
- while (tOutlline) {
- if ([tOutlline isEqual:self.dragPDFOutline]) {
- isContains = YES;
- break;
- }
- tOutlline = tOutlline.parent;
- }
- if (!isContains) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
- }
- }
- }
- return YES;
- }
- return NO;
- }
- #pragma mark NSOutlineView delegate protocol
- - (NSCell *)outlineView:(NSOutlineView *)ov dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
- if ([ov isEqual:rightSideController.noteOutlineView] && tableColumn == nil && [(PDFAnnotation *)item type] == nil) {
- return [[ov tableColumnWithIdentifier:NOTE_COLUMNID] dataCellForRow:[ov rowForItem:item]];
- }
- return [tableColumn dataCellForRow:[ov rowForItem:item]];
- }
- - (void)outlineView:(NSOutlineView *)ov willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
- if ([ov isEqual:leftSideController.tocOutlineView] &&
- [ov selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular &&
- [ov isRowSelected:[ov rowForItem:item]]) {
- [cell setBackgroundStyle:NSBackgroundStyleLowered];
- }
- }
- - (BOOL)outlineView:(NSOutlineView *)ov shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item{
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- if (tableColumn == nil) {
- if ([pdfView hideNotes] == NO && [[(SKNoteText *)item note] isNote]) {
- PDFAnnotation *annotation = [(SKNoteText *)item note];
- [pdfView scrollAnnotationToVisible:annotation];
- [pdfView setActiveAnnotation:annotation];
- [self showNote:annotation];
- SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
- [[noteController window] makeFirstResponder:[noteController textView]];
- [[noteController textView] selectAll:nil];
- }
- return NO;
- } else if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID] || [[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
- return YES;
- }
- }
- return NO;
- }
- - (void)outlineView:(NSOutlineView *)ov didClickTableColumn:(NSTableColumn *)tableColumn {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSTableColumn *oldTableColumn = [ov highlightedTableColumn];
- NSTableColumn *newTableColumn = ([NSEvent modifierFlags] & NSEventModifierFlagCommand) ? nil : tableColumn;
- NSMutableArray *sortDescriptors = nil;
- BOOL ascending = YES;
- if ([oldTableColumn isEqual:newTableColumn]) {
- sortDescriptors = [[[rightSideController.noteArrayController sortDescriptors] mutableCopy] autorelease];
- [sortDescriptors replaceObjectAtIndex:0 withObject:[[sortDescriptors firstObject] reversedSortDescriptor]];
- ascending = [[sortDescriptors firstObject] ascending];
- } else {
- NSString *tcID = [newTableColumn identifier];
- NSSortDescriptor *pageIndexSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationPageIndexKey ascending:ascending] autorelease];
- NSSortDescriptor *boundsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKPDFAnnotationBoundsOrderKey ascending:ascending selector:@selector(compare:)] autorelease];
- sortDescriptors = [NSMutableArray arrayWithObjects:pageIndexSortDescriptor, boundsSortDescriptor, nil];
- if ([tcID isEqualToString:TYPE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationTypeKey ascending:YES selector:@selector(noteTypeCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:COLOR_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationColorKey ascending:YES selector:@selector(colorCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:NOTE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationStringKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:AUTHOR_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationUserNameKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:DATE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationModificationDateKey ascending:YES] autorelease] atIndex:0];
- }
- if (oldTableColumn)
- [ov setIndicatorImage:nil inTableColumn:oldTableColumn];
- [ov setHighlightedTableColumn:newTableColumn];
- }
- [rightSideController.noteArrayController setSortDescriptors:sortDescriptors];
- if (newTableColumn)
- [ov setIndicatorImage:[NSImage imageNamed:ascending ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
- inTableColumn:newTableColumn];
- [ov reloadData];
- }
- }
- - (NSString *)outlineView:(NSOutlineView *)ov toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn item:(id)item mouseLocation:(NSPoint)mouseLocation {
- if ([ov isEqual:rightSideController.noteOutlineView] &&
- (tableColumn == nil || [[tableColumn identifier] isEqualToString:NOTE_COLUMNID])) {
- return [item string];
- }
- return @"";
- }
- - (void)outlineViewColumnDidResize:(NSNotification *)notification{
- if (mwcFlags.autoResizeNoteRows &&
- [[notification object] isEqual:rightSideController.noteOutlineView] &&
- [[[[notification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:NOTE_COLUMNID] &&
- [(SKScrollView *)[[notification object] enclosingScrollView] isResizingSubviews] == NO) {
- [rowHeights removeAllFloats];
- [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
- }
- }
- - (void)updateSelectRowHeight{
- CGFloat rowHeight = 0;
- PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.selectedRow];
- if (!outline){
- return;
- }
- NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
- [attributedString appendAttributedString:attr1];
-
- NSInteger *row = [leftSideController.tocOutlineView selectedRow];
- NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:row makeIfNecessary:YES];
- NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
- // id cell = [tableColumn dataCell];
- id cell = [tableColumn dataCellForRow:row];
- [cell setObjectValue:attributedString];
- CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
-
- NSInteger num = [self getNum:outline];
- CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
- rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
- [rowHeights setFloat:rowHeight forKey:outline];
-
- if (@available(macOS 10.13, *)) {
-
- } else {
- rowHeight = 40.0;
- }
- CGRect fram = viewS.frame;
- viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
- [leftSideController.tocOutlineView reloadData];
- }
- - (NSInteger)getNum:(PDFOutline *)ol{
- NSInteger num = 0;
- PDFOutline *outLine = [ol parent];
- do {
- outLine = [outLine parent];
- if (outLine){
- num ++;
- }
- } while (outLine);
- return num;
- }
- - (void)sizeOutlineViewToContents:(NSOutlineView*) outlineView;
- {
- NSInteger rowCount = [outlineView numberOfRows];
- for (NSInteger i = 0; i < rowCount; i++){
- CGFloat rowHeight = 0;
- PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:i];
- if (!outline){
- continue;
- }
- NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
- [attributedString appendAttributedString:attr1];
-
- // NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:i makeIfNecessary:YES];
- NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
- // id cell = [tableColumn dataCell];
- id cell = [tableColumn dataCellForRow:i];
- [cell setObjectValue:attributedString];
- CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
-
- NSInteger num = [self getNum:outline];
- CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
- rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
- [rowHeights setFloat:rowHeight forKey:outline];
-
- if (@available(macOS 10.13, *)) {
-
- } else {
- rowHeight = 40.0;
- }
- // CGRect fram = viewS.frame;
- // viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
- }
- [leftSideController.tocOutlineView reloadData];
- }
- */
- func noteItems(_ items: NSArray) -> NSArray {
- var noteItems = NSMutableArray()
-
- for item in items {
- guard let anno = (item as? KMBOTAAnnotationItem)?.annotation else {
- continue
- }
- if anno.type == nil {
- // item = [(SKNoteText *)item note];
- }
- if noteItems.contains(anno) == false {
- noteItems.add(anno)
- }
- }
- return noteItems
- }
- /*
- - (NSArray *)outlineView:(NSOutlineView *)ov typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSInteger i, count = [rightSideController.noteOutlineView numberOfRows];
- NSMutableArray *texts = [NSMutableArray arrayWithCapacity:count];
- for (i = 0; i < count; i++) {
- id item = [rightSideController.noteOutlineView itemAtRow:i];
- NSString *string = [item string];
- [texts addObject:string ?: @""];
- }
- return texts;
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- NSInteger i, count = [leftSideController.tocOutlineView numberOfRows];
- NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
- for (i = 0; i < count; i++)
- [array addObject:[[(PDFOutline *)[leftSideController.tocOutlineView itemAtRow:i] label] lossyStringUsingEncoding:NSASCIIStringEncoding]];
- return array;
- }
- return nil;
- }
- - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- }
- }
- - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
- if ([typeSelectHelper isEqual:[leftSideController.thumbnailTableView typeSelectHelper]] || [typeSelectHelper isEqual:[pdfView typeSelectHelper]]) {
- if (searchString)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- } else if ([typeSelectHelper isEqual:[rightSideController.noteOutlineView typeSelectHelper]]) {
- if (searchString)
- [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding note: \"%@\"", @"Status message"), searchString]];
- else
- [self updateRightStatus];
- } else if ([typeSelectHelper isEqual:[leftSideController.tocOutlineView typeSelectHelper]]) {
- if (searchString)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding: \"%@\"", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- }
- }
- */
- }
- // MARK: - KMCustomOutlineViewDelegate, KMCustomOutlineViewDataSource
- extension KMLeftSideViewController: KMCustomOutlineViewDelegate, KMCustomOutlineViewDataSource {
- func outlineView(_ anOutlineView: NSOutlineView, canDeleteItems items: [Any]) -> Bool {
- if anOutlineView.isEqual(to: self.noteOutlineView) {
- return self.listView.hideNotes == false && items.count > 0
- } else if anOutlineView.isEqual(to: self.tocOutlineView) {
- return items.count > 0
- }
- return false
- }
-
- func outlineView(_ anOutlineView: NSOutlineView, deleteItems items: [Any]) {
- if anOutlineView.isEqual(to: self.noteOutlineView) {
- if (items.isEmpty) {
- return
- }
- for item in self.noteItems(items as NSArray) {
- guard let anno = item as? CPDFAnnotation else {
- continue
- }
- self.listView.remove(anno)
- }
- self.listView.undoManager?.setActionName(KMLocalizedString("Remove Note", "Undo action name"))
-
- self.reloadAnnotation()
- self.annotationSort(sortArray: [])
- self.noteOutlineView.reloadData()
- } else if anOutlineView.isEqual(to: self.tocOutlineView) {
- self.outlineContextMenuItemClicked_RemoveEntry(nil)
- }
- }
- func outlineView(_ anOutlineView: NSOutlineView, canCopyItems items: [Any]) -> Bool {
- if anOutlineView.isEqual(to: self.noteOutlineView) {
- if (items.count == 1) {
- // PDFAnnotation *annotation = [[self noteItems:items] lastObject];
- // if ([annotation isKindOfClass:[PDFAnnotationStamp class]] ||
- // [annotation isKindOfClass:[PDFAnnotationLink class]]) {
- // return NO;
- // }
- }
- return items.count > 0
- }
- return false
- }
-
- func outlineView(_ anOutlineView: NSOutlineView, copyItems items: [Any]) {
- if anOutlineView.isEqual(to: self.noteOutlineView) && items.isEmpty == false {
- let pboard = NSPasteboard.general
- var copiedItems: [Any] = []
- var attrString = NSMutableAttributedString()
- var isAttributed = false
- var item: AnyObject?
-
- // for (item in [self noteItems:items]) {
- // if ([item isMovable])
- // [copiedItems addObject:item];
- // }
- // for (item in items) {
- // if ([attrString length])
- // [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:@"\n\n"];
- // if ([(PDFAnnotation *)item type] == nil && [[(SKNoteText *)item note] isNote]) {
- // [attrString appendAttributedString:[(SKNoteText *)item text]];
- // isAttributed = YES;
- // } else {
- // [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:[item string] ?: @""];
- // }
- // }
- //
- // [pboard clearContents];
- // if (isAttributed)
- // [pboard writeObjects:[NSArray arrayWithObjects:attrString, nil]];
- // else
- // [pboard writeObjects:[NSArray arrayWithObjects:[attrString string], nil]];
- // if ([copiedItems count] > 0)
- // [pboard writeObjects:copiedItems];
- }
- }
- }
- // MARK: - KMTocOutlineViewDelegate
- extension KMLeftSideViewController: KMTocOutlineViewDelegate {
- // func outlineView(_ anOutlineView: NSOutlineView, highlightLevelForRow row: Int) -> Int {
- // if ([ov isEqual:leftSideController.tocOutlineView]) {
- // NSInteger numRows = [ov numberOfRows];
- // NSUInteger firstPage = [[[ov itemAtRow:row] page] pageIndex];
- // NSUInteger lastPage = row + 1 < numRows ? [[[ov itemAtRow:row + 1] page] pageIndex] : [[self pdfDocument] pageCount];
- // NSRange range = NSMakeRange(firstPage, MAX(1LU, lastPage - firstPage));
- // NSUInteger i, iMax = [lastViewedPages count];
- // for (i = 0; i < iMax; i++) {
- // if (NSLocationInRange((NSUInteger)[lastViewedPages pointerAtIndex:i], range))
- // return i;
- // }
- // }
- // return NSNotFound;
- // }
-
- func outlineView(_ anOutlineView: NSOutlineView, imageContextForItem item: Any?) -> AnyObject? {
- if anOutlineView.isEqual(to: self.tocOutlineView) {
- if item == nil {
- return true as AnyObject
- }
- if item is CPDFOutline {
- return (item as! CPDFOutline).destination
- }
- }
- return nil
- }
- }
- extension KMLeftSideViewController: KMNoteOutlineViewDelegate {
- func outlineView(_ anOutlineView: NSOutlineView, canResizeRowByItem item: AnyObject?) -> Bool? {
- if anOutlineView.isEqual(to: self.noteOutlineView) {
- return true
- }
- return false
- }
-
- func outlineView(_ anOutlineView: NSOutlineView, setHeight newHeight: CGFloat, ofRowByItem item: AnyObject?) {
- // [rowHeights setFloat:newHeight forKey:item];
- }
-
- func outlineView(_ anOutlineView: NSOutlineView, didChangeHiddenOfTableColumn aTableColumn: NSTableColumn) {
- // if (mwcFlags.autoResizeNoteRows &&
- // [ov isEqual:rightSideController.noteOutlineView] &&
- // [[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
- // [rowHeights removeAllFloats];
- // [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
- // }
- }
-
- func outlineViewCommandKeyPressedDuringNavigation(_ anOutlineView: NSOutlineView) {
- // PDFAnnotation *annotation = [[self selectedNotes] lastObject];
- // if (annotation) {
- // [pdfView scrollAnnotationToVisible:annotation];
- // [pdfView setActiveAnnotation:annotation];
- // }
- }
-
-
- }
- // MARK: - Menu Item Actions
- extension KMLeftSideViewController {
- @objc func cutPage(_ sender: AnyObject?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- self._tableView(self.thumbnailTableView, cutRowsWithIndexes: self.thumbnailTableView.selectedRowIndexes)
- }
-
- @objc func copyPage(_ sender: AnyObject?) {
- self.tableView(self.thumbnailTableView, copyRowsWithIndexes: self.thumbnailTableView.selectedRowIndexes)
- }
-
- @objc func pastePage(_ sender: AnyObject?) {
- self.tableView(self.thumbnailTableView, pasteFromPasteboard: nil)
- }
-
- @objc func deletePage(_ sender: AnyObject?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- self.tableView(self.thumbnailTableView, deleteRowsWithIndexes: self.thumbnailTableView.selectedRowIndexes)
- }
-
- @objc func rotatePageMenuAction(_ sender: AnyObject?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- //
- self.tableView(self.thumbnailTableView, rotateRowsWithIndexes: self.thumbnailTableView.selectedRowIndexes as NSIndexSet)
- }
-
- @objc func quickInsert(_ sender: AnyObject?) {
- // if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- let idx = self.thumbnailTableView.selectedRowIndexes.first ?? NSNotFound
- if idx == NSNotFound || idx >= self.listView.document.pageCount {
- return
- }
-
- let result = self.listView.insertPage(KMNormalBlankSize, at: idx+1)
- if result == false {
- return
- }
-
- var selectedIndexSet = IndexSet()
- selectedIndexSet.insert(idx+1)
- self.insertPages(selectedIndexSet, pageAt: idx)
- }
-
- @objc func insert(_ sender: AnyObject?) {
- // if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
-
- guard let document = self.listView.document else {
- return
- }
- let idx = self.thumbnailTableView.selectedRowIndexes.first ?? NSNotFound
- if idx == NSNotFound || idx >= document.pageCount {
- return
- }
-
- if document.allowsCopying == false || document.allowsPrinting == false {
- Task {
- _ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
- }
- return
- }
- let insertVC = KMPDFEditInsertBlankPageWindow(document: document)
- insertVC.insertLocation = 3
- insertVC.currentPage = idx + 1
- insertVC.callback = { [weak self] pdfDoc, _, pages, insertI in
- if let _pages = pages {
- // mm 单位的大小
- guard let _winC = self?.kmCurrentWindowC as? KMPDFEditInsertBlankPageWindow else {
- self?.km_endSheet()
- return
- }
- var pageSize = _winC.pageSize
- let direction = _winC.pageRotation == 0 ? 0 : 1
- if (direction == 0) { // 纵向
- if (pageSize.width > pageSize.height) { // 需要交换
- let tmp = pageSize.width
- pageSize.width = pageSize.height
- pageSize.height = tmp
- } else {
- // no things.
- }
- } else { // 横向
- if (pageSize.width > pageSize.height) {
- // no things.
- } else { // 需要交换
- let tmp = pageSize.width
- pageSize.width = pageSize.height
- pageSize.height = tmp
- }
- }
- /// 插入位置
- let document = CPDFDocument()
- document?.insertPage(pageSize, at: 0)
- if let page: CPDFPage = (document?.page(at: 0)) {
- self?.insertPage(page, pageAt: insertI)
- }
- }
- self?.km_quick_endSheet()
- }
- self.km_beginSheet(windowC: insertVC)
- }
-
- @objc func insertPDF(_ sender: AnyObject?) {
- // if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
-
- guard let document = self.listView.document else {
- return
- }
- let idx = self.thumbnailTableView.selectedRowIndexes.first ?? NSNotFound
- if idx == NSNotFound || idx >= document.pageCount {
- return
- }
-
- if document.allowsCopying == false || document.allowsPrinting == false {
- Task {
- _ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
- }
- return
- }
-
- let panel = NSOpenPanel()
- panel.allowedFileTypes = ["pdf"]
- panel.beginSheetModal(for: self.view.window!) { response in
- if response == .cancel {
- return
- }
-
- for fileURL in panel.urls {
- let pdfDoc = CPDFDocument(url: fileURL)
- if let data = pdfDoc?.isLocked, data {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
- let com = PasswordWindowController(windowNibName: "PasswordWindowController")
- com.fileURL = fileURL
- self.km_beginSheet(windowC: com)
-
- com.closeCallBack = { [unowned self] password in
- self.km_quick_endSheet()
- // }
- if (password.isEmpty == false) {
-
- let insertVC = KMPDFEditInsertPageWindow(document: document, path: fileURL, password: password)
- insertVC.insertLocation = 3
- insertVC.currentPage = idx + 1
- self.km_beginSheet(windowC: insertVC)
- insertVC.callback = { [weak self] pdfDoc, pwd, pages, insertIdx in
- var indexs = IndexSet()
- guard let _winC = self?.kmCurrentWindowC as? KMPDFEditInsertPageWindow, _winC.insertDocument != nil else {
- self?.km_quick_endSheet()
- return
- }
- let doc = _winC.insertDocument!
- let fileAttribute = _winC.fileAttribute
- var insertIndex = insertIdx
- var insertPages: [CPDFPage] = []
- for number in fileAttribute.fetchSelectPages() {
- if let page = doc.page(at: UInt(number-1)) {
- insertPages.append(page)
- indexs.insert(insertIndex)
- insertIndex += 1
- }
- }
- for (i, page) in insertPages.enumerated() {
- self?.listView.document.insertPageObject(page, at: UInt(insertIdx + i))
- }
- self?.insertPages(indexs, pageAt: insertIdx)
- self?.km_quick_endSheet()
- }
- }
- }
- }
- } else {
- let insertVC = KMPDFEditInsertPageWindow(document: document, path: fileURL)
- insertVC.insertLocation = 3
- insertVC.currentPage = idx + 1
- self.km_beginSheet(windowC: insertVC)
- insertVC.callback = { [weak self] pdfDoc, pwd, pages, insertIdx in
- var indexs = IndexSet()
- guard let _winC = self?.kmCurrentWindowC as? KMPDFEditInsertPageWindow, _winC.insertDocument != nil else {
- self?.km_quick_endSheet()
- return
- }
- let doc = _winC.insertDocument!
- let fileAttribute = _winC.fileAttribute
- var insertIndex = insertIdx
- var insertPages: [CPDFPage] = []
- for number in fileAttribute.fetchSelectPages() {
- if let page = doc.page(at: UInt(number-1)) {
- insertPages.append(page)
- indexs.insert(insertIndex)
- insertIndex += 1
- }
- }
- for (i, page) in insertPages.enumerated() {
- self?.listView.document.insertPageObject(page, at: UInt(insertIdx + i))
- }
- self?.insertPages(indexs, pageAt: insertIdx)
- self?.km_quick_endSheet()
- }
-
- }
- }
- }
- }
-
- @objc func extractPage(_ sender: AnyObject?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- self.tableView(self.thumbnailTableView, extractRowsWithIndexes: self.thumbnailTableView.selectedRowIndexes)
- }
-
- @objc func pageEdit(_ sender: AnyObject?) {
- self.delegate?.controller?(controller: self, itemClick: nil, itemKey: .pageEdit, params: nil)
- }
-
- @objc func displayPageSize(_ sender: AnyObject?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
-
- self.isDisplayPageSize = !self.isDisplayPageSize;
- UserDefaults.standard.setValue(self.isDisplayPageSize, forKey: "kKMThumbnailDisplayPageSizeKey")
- UserDefaults.standard.synchronize()
-
- Task { @MainActor in
- self.thumbnailTableView.reloadData()
- }
- }
-
- @objc func sharePage(_ sender: AnyObject?) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
-
- guard let document = self.listView.document else {
- return
- }
- var pages = NSMutableArray()
- for idx in self.thumbnailTableView.selectedRowIndexes {
- if (idx < document.pageCount) {
- if let page = self.listView.document.page(at: UInt(idx)) {
- pages.add(page)
- }
- }
- }
- let pdf = CPDFDocument()
- for page in pages {
- // PDFPage *copyPage = [[page copy] autorelease];
- if let _page = page as? CPDFPage {
- pdf?.insertPageObject(_page, at: pdf?.pageCount ?? 0)
- }
- }
- // NSString * = nil;
- var fileName = ""
- // NSString * = [self.pdfDocument.documentURL.lastPathComponent stringByDeletingPathExtension];
- var documentFileName = document.documentURL?.deletingPathExtension().lastPathComponent ?? ""
- var tName = self.fileNameWithSelectedPages(self.thumbnailTableView.selectedRowIndexes)
- if (tName.count > 50) {
- tName = tName.substring(to: 50)
- }
- if (pages.count > 1) {
- fileName = String(format: "%@ pages %@", documentFileName, tName)
- } else {
- fileName = String(format: "%@ page %@", documentFileName, tName)
- }
- let paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
- var cachesDir = paths.first ?? ""
- cachesDir = "\(cachesDir)/\(fileName).pdf"
- var array = NSMutableArray()
- let url = URL(fileURLWithPath: cachesDir)
- array.add(url)
- let vc = KMProgressWindowController()
- // // [NSApp beginSheet:[vc window]
- // // modalForWindow:self.window
- // // modalDelegate:nil
- // // didEndSelector:nil
- // // contextInfo:NULL];
- self.view.window?.beginSheet(vc.window!, completionHandler: { [unowned self] returnCode in
- NSApp.endSheet(self.view.window!, returnCode: returnCode.rawValue)
- })
- DispatchQueue.global().async {
- let sucess = pdf?.write(toFile: cachesDir) ?? false
- if (sucess) {
- DispatchQueue.main.async {
- // [[sender representedObject] performWithItems:array];
- let represent : NSSharingService = (sender as! NSMenuItem).representedObject as! NSSharingService
- represent.perform(withItems: [url])
-
- NSApp.endSheet(vc.window!)
- vc.close()
- }
- } else {
- NSApp.endSheet(vc.window!)
- vc.close()
- }
- }
- // [vc release];
- }
-
- @objc func toggleCaseInsensitiveNoteSearch(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-toggleCaseInsensitiveNoteSearch...")
- }
-
- @objc func searchNotes(_ sender: AnyObject?) {
- self.noteSearchMode = false
- if self.findState == .note {
- if self.noteSearchField.isEqual(to: sender) {
- self.noteSearchMode = true
- }
- self.updateNoteFilterPredicate()
- } else {
- self.updateSnapshotFilterPredicate()
- }
- let textfield = sender as? NSSearchField
- if let data = textfield?.stringValue.isEmpty, data == false {
- let findPboard = NSPasteboard(name: .find)
- findPboard.clearContents()
- // findPboard.writeObjects([textfield!.stringValue])
- }
- }
-
- @objc func toggleSelectedSnapshots(_ sender: AnyObject?) {
- let indexs = self.snapshotTableView.selectedRowIndexes
- if indexs.isEmpty {
- return
- }
- let model = self.snapshots[indexs.last!]
- let windowC = model.windowC
- if let data = windowC?.window?.isVisible, data {
- windowC?.miniaturize()
- } else {
- windowC?.deminiaturize()
- }
-
- var rowIndexSet = IndexSet()
- let row = self.snapshotTableView.selectedRow
- if row >= 0 && row < self.snapshots.count {
- rowIndexSet.insert(row)
- }
- var columnIndexSet = IndexSet()
- columnIndexSet.insert(0)
- self.snapshotTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: columnIndexSet)
-
- }
-
- private func _tableView(_ tv: NSTableView, cutRowsWithIndexes rowIndexes: IndexSet) {
- if tv.isEqual(to: self.thumbnailTableView) {
- self._copysPages.removeAll()
- for idx in rowIndexes {
- if (idx != NSNotFound) {
- if let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage {
- self._copysPages.append(page)
- }
- }
- }
- self.tableView(tv, deleteRowsWithIndexes: rowIndexes)
- }
- }
-
- // MARK: - Snapshot
- @objc func menuItemClick_ExportPNG(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- let image = snapshot.thumbnailWithSize(0)
- NSPanel.savePanel_data_success(self.view.window!, imageData: image?.pngData(), allowedTypes: ["png"]) { url in
- NSWorkspace.shared.selectFile(url.path, inFileViewerRootedAtPath: "")
- }
- }
-
- @objc func menuItemClick_ExportJPG(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- let image = snapshot.thumbnailWithSize(0)
- NSPanel.savePanel_data_success(self.view.window!, imageData: image?.jpgData(), allowedTypes: ["jpg"]) { url in
- NSWorkspace.shared.selectFile(url.path, inFileViewerRootedAtPath: "")
- }
- }
-
- @objc func menuItemClick_ExportPDF(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- if let image = snapshot.thumbnailWithSize(0) {
- let document = CPDFDocument()
- _ = document?.km_insert(image: image, at: 0)
- NSPanel.savePanel_pdf_success(self.view.window!, document: document) { url in
- NSWorkspace.shared.selectFile(url.path, inFileViewerRootedAtPath: "")
- }
- }
- }
-
- @objc func menuItemClick_Print(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
-
- if let image = snapshot.thumbnailWithSize(0) {
- self.delegate?.controller?(controller: self, itemClick: nil, itemKey: .print, params: image)
- }
- }
-
- @objc func menuItemClick_SelectAll(_ sender: AnyObject?) {
- let selected = self.snapshotListIsAllSelected()
- for model in self.snapshots {
- model.isSelected = !selected
- }
- Task { @MainActor in
- self.snapshotTableView.reloadData()
- }
- }
-
- @objc func deleteAllSnapshot(_ sender: AnyObject?) {
- for model in self.snapshots {
- model.windowC?.close()
- }
- }
-
- @objc func hideSnapshot(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- if let data = snapshot.window?.isVisible, data {
- snapshot.miniaturize()
- }
- }
-
- @objc func showSnapshot(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- if let data = snapshot.window?.isVisible, data {
- snapshot.window?.orderFront(nil)
- } else {
- snapshot.deminiaturize()
- }
- }
-
- @objc func deleteSnapshot(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- snapshot.close()
- }
-
- @objc func menuItemClick_Copy(_ sender: AnyObject?) {
- guard let snapshot = (sender as? NSMenuItem)?.representedObject as? KMSnapshotWindowController else {
- return
- }
- let image = snapshot.thumbnailWithSize(0)
- if let tiffData = image?.tiffRepresentation {
- let pasteboardItem = NSPasteboardItem()
- pasteboardItem.setData(tiffData, forType: .tiff)
- let pboard = NSPasteboard.general
- pboard.clearContents()
- pboard.writeObjects([pasteboardItem])
- }
- }
-
- func updateSnapshotFilterPredicate() {
- let searchString = self.snapshotSearchField.stringValue
- self.searchSnapshots.removeAll()
- if self.findState == .snapshot && searchString.isEmpty == false {
- self.searchSnapshots = self.snapshots.filter({ model in
- let data = model.windowC?.string.contains(searchString) ?? false
- return data
- })
- }
- Task { @MainActor in
- self.updataLeftSideSnapView()
- self.snapshotTableView.reloadData()
- }
- }
-
- func snapshotListIsAllSelected() -> Bool {
- if self.snapshots.isEmpty {
- return false
- }
- for model in self.snapshots {
- if model.isSelected == false {
- return false
- }
- }
- return true
- }
- }
- // MARK: - Undo & Redo
- extension KMLeftSideViewController {
- @objc dynamic func tableView(_ tv: NSTableView, rotateRowsWithIndexes rowIndexes: NSIndexSet) {
- if tv.isEqual(to: self.thumbnailTableView) {
- for idx in rowIndexes {
- if (idx != NSNotFound) {
- let page = self.listView.document.page(at: UInt(idx))
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).rotatePage(page, pageAt: idx)
- page?.rightRotate()
- self.listView.layoutDocumentView()
- self.resetThumbnails()
- // NSInteger pageIndex = MIN(idx, [[pdfView document] pageCount]-1);
- // [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
- }
- self.thumbnailTableView.selectRowIndexes(rowIndexes as IndexSet, byExtendingSelection: true)
- }
- }
- }
-
- @objc dynamic func rotatePage(_ page: CPDFPage?, pageAt index: Int) {
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).tableView(self.thumbnailTableView, rotateRowsWithIndexes: NSIndexSet(index: index))
- page?.leftRotate()
- self.listView.layoutDocumentView()
- self.resetThumbnails()
- }
-
- @objc dynamic func insertPage(_ page: CPDFPage, pageAt index: Int) {
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).tableView(self.thumbnailTableView, deleteRowsWithIndexes: IndexSet(integer: index))
- self.listView.document.insertPageObject(page, at: UInt(index))
- self.listView.layoutDocumentView()
- // [pageLabels setArray:[[pdfView document] pageLabels]];
- self.resetThumbnails()
- let pageIndex = min(index, Int((self.listView.document?.pageCount ?? 0))-1)
- self.listView.go(toPageIndex: pageIndex, animated: false)
- }
-
- @objc dynamic func insertPages(_ selectedIndexSet: IndexSet, pageAt index: Int) {
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).deletePages(selectedIndexSet, pageAt: index)
- self.listView.layoutDocumentView()
- // [pageLabels setArray:[[pdfView document] pageLabels]];
- self.resetThumbnails()
-
- if let pageIndex = selectedIndexSet.first {
- self.listView.go(toPageIndex: pageIndex, animated: false)
- }
- }
-
- @objc dynamic func deletePages(_ selectedIndexSet: IndexSet, pageAt index: Int) {
- (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).insertPages(selectedIndexSet, pageAt: index)
-
- for idx in selectedIndexSet {
- if idx < self.listView.document.pageCount {
- self.listView.document.removePage(at: UInt(idx))
- }
- }
-
- self.listView.layoutDocumentView()
- // [pageLabels setArray:[[pdfView document] pageLabels]];
- self.resetThumbnails()
- let pageIndex = min(index, Int(self.listView.document.pageCount)-1)
- self.listView.go(toPageIndex: pageIndex, animated: false)
- }
- }
- // MARK: - Other
- extension KMLeftSideViewController {
- @objc func goToSelectedOutlineItem(_ sender: AnyObject?) {
- let outlineItem = self.tocOutlineView.item(atRow: self.tocOutlineView.selectedRow)
- let outline = self.tocOutlineView
- if let cnt = outline?.selectedRowIndexes.count, cnt == 1 {
- if outlineItem is CPDFOutline {
- let outline = (outlineItem as! CPDFOutline)
- if let des = outline.destination {
- self.listView.go(to: des)
- } else if let action = outline.action {
- self.listView.perform(action)
- }
- } else if outlineItem is CPDFBookmark {
- let bookmark = outlineItem as! CPDFBookmark
- self.listView.go(toPageIndex: bookmark.pageIndex, animated: true)
- }
- }
- }
-
- @objc func goToSelectedFindResults(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-goToSelectedFindResults...")
- }
-
- func tableView(_ tv: NSTableView, extractRowsWithIndexes rowIndexes: IndexSet) {
- if tv.isEqual(to: self.thumbnailTableView) {
- guard let document = self.listView.document else {
- return
- }
- var pages = NSMutableArray()
- for idx in self.thumbnailTableView.selectedRowIndexes {
- if (idx < document.pageCount) {
- if let page = self.listView.document.page(at: UInt(idx)) {
- pages.add(page)
- }
- }
- }
- let fileName = document.getFileNameAccordingSelctPages(pages as! [CPDFPage])
- let saveAccessCtr = KMSavePanelAccessoryController()
- let outputSavePanel = NSSavePanel()
- outputSavePanel.allowedFileTypes = ["pdf"]
- outputSavePanel.accessoryView = saveAccessCtr.view
- outputSavePanel.nameFieldStringValue = fileName
- outputSavePanel.beginSheetModal(for: self.view.window!) { result in
- if (result == .OK) {
- DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
- let vc = KMProgressWindowController()
- self.view.window?.beginSheet(vc.window!)
- let saveFilePath = outputSavePanel.url?.path
- DispatchQueue.global().async {
- let pdf = CPDFDocument()
- let success = pdf?.extractAsOneDocument(withPages: pages as! [CPDFPage], savePath: saveFilePath) ?? false
- DispatchQueue.main.async {
- if (success) {
- if (saveAccessCtr.openAutomaticButton.state == .on) {
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: outputSavePanel.url!, display: true) { _, _, _ in
-
- }
- } else {
- KMTools.viewFile(at: saveFilePath!)
- }
- }
- NSApp.endSheet(vc.window!)
- vc.close()
- }
- }
- }
- }
- }
- }
- }
-
- func fileNameWithSelectedPages(_ itemIndexes: IndexSet) -> String {
- var pagesName = ""
- if (itemIndexes.count > 1) {
- pagesName.append(" pages")
- } else {
- pagesName.append("page")
- }
-
- let docmentName = self.listView.document?.documentURL.deletingPathExtension().lastPathComponent ?? ""
- var fileName = ""
- if (itemIndexes.count > 0) {
- if (itemIndexes.count == 1) {
- let idx = itemIndexes.first! + 1
- let tFileName = String(format: "%@ %@", pagesName, "\(idx)")
- return String(format: "%@%@", docmentName, tFileName)
- }
-
- var sortIndex = IndexSet()
- for idx in itemIndexes {
- let _idx = idx + 1
- sortIndex.insert(_idx)
- }
- // NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
- // NSArray *sortDesc = @[sort];
- // NSArray *sortArray = [sortIndex sortedArrayUsingDescriptors:sortDesc];
- let sortArray = sortIndex.sorted()
-
- var a = 0
- var b = 0
-
- for num in sortArray {
- // for (NSNumber *num in sortArray) {
- if (fileName.isEmpty == false) {
- if (num == b+1) {
- b = num
- if (num == sortArray.last) {
- fileName = "\(fileName)\(a)-\(b)"
- }
- } else {
- if (a == b) {
- fileName = "\(fileName)\(a),"
- } else {
- fileName = "\(fileName)\(a)-\(b),"
- }
- b = num
- a = b
- if (num == sortArray.last) {
- fileName = "\(fileName)\(a)"
- }
- }
- } else {
- fileName = ""
- b = num
- a = b
- }
- }
- let tFileName = String(format: "%@ %@", pagesName,fileName)
- return String(format: "%@%@", docmentName,tFileName)
- }
- return ""
- }
-
- func switchType(_ type: BotaType) {
- if type == .Thumbnail {
- self.leftView.segmentedControl.selectedSegment = 0
- } else if type == .Outline {
- self.leftView.segmentedControl.selectedSegment = 1
- } else if type == .Annotation {
- self.leftView.segmentedControl.selectedSegment = 2
- } else if type == .snapshot {
- self.leftView.segmentedControl.selectedSegment = 3
- } else if type == .Search {
- self.leftView.segmentedControl.selectedSegment = 4
- }
- }
-
- var TINY_SIZE: Float {
- get {
- return 32.0
- }
- }
-
- var SMALL_SIZE: Float {
- get {
- return 64.0
- }
- }
-
- var LARGE_SIZE: Float {
- get {
- return 128.0
- }
- }
-
- var HUGE_SIZE: Float {
- get {
- return 256.0
- }
- }
-
- var FUDGE_SIZE: Float {
- get {
- return 0.1
- }
- }
-
- func updateTableFont() {
- let font = NSFont.systemFont(ofSize: KMPreference.shared.outlineFontSize.cgFloat)
- self.tocOutlineView.font = font
- self.noteOutlineView.font = font
- self.findTableView.font = font
- self.groupedFindTableView.font = font
- }
- }
|