KMLeftSideViewController.swift 244 KB

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