KMLeftSideViewController.swift 254 KB

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