12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785 |
- //
- // KMLeftSideViewController.swift
- // PDF Master
- //
- // Created by lxy on 2022/10/10.
- //
- import Cocoa
- @objc protocol KMLeftSideViewControllerDelegate {
- @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
- @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
- @objc optional func searchAction(searchString:String, isCase:Bool)
-
- @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
- @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
-
- @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
-
- @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
- }
- class KMLeftSideViewController: KMSideViewController {
- // @IBOutlet weak var leftTableview: NSTableView!
- // @IBOutlet weak var leftBox: NSBox!
-
- lazy var annotationViewController : KMAnnotationViewController = {
- let annotationViewController = KMAnnotationViewController(nibName: "KMAnnotationViewController", bundle: nil)
- return annotationViewController
- }()
- lazy var bookViewController : KMBookMarkViewController = {
- let bookViewController = KMBookMarkViewController()
- bookViewController.bookMarkDidChange = { [unowned self] (controller, bookMarks) in
- self.delegate?.controller?(controller: self, bookMarkDidChange: bookMarks)
- }
- return bookViewController
- }()
- // lazy var signatureViewController : KMSignatureViewController = {
- // let signatureViewController = KMSignatureViewController()
- // return signatureViewController
- // }()
- lazy var panelSetViewController : KMPDFViewPanelSetViewController = {
- let panelSetViewController = KMPDFViewPanelSetViewController()
- // panelSetViewController.delegate = self
- return panelSetViewController
- }()
-
- var dataSource : [KMLeftMethodMode] = [KMLeftMethodMode]()
- var type : KMLeftMethodMode = KMLeftMethodMode()
- var isShowPanel : Bool = false
- var norImage : [String] = []
- var selectImage : [String] = []
- var mainVC: KMMainViewController?
- var selectPages: [Int]?
- open weak var delegate: KMLeftSideViewControllerDelegate?
-
- deinit {
- KMPrint("KMLeftSideViewController deinit.")
-
- NotificationCenter.default.removeObserver(self)
- }
-
- override var nibName: NSNib.Name? {
- return "LeftSideView"
- }
-
- convenience init(type : KMLeftMethodMode) {
- self.init()
- self.type = type
- }
-
- override func viewDidAppear() {
- super.viewDidAppear()
-
- // self.annotationViewController.view.isHidden = true
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- // self.leftBox.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
- // self.leftTableview.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
- // self.leftTableview.border(NSColor.km_init(hex: "#EDEEF0"),1 , 0)
- // self.addMenuTitle()
- // self.refreshShowMethod()
-
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
-
- self.annotationViewController.listView = self.listView
- self.view.addSubview(self.annotationViewController.view)
- self.annotationViewController.reloadData()
- // self.annotationViewController.view.isHidden = true
- self.annotationViewController.view.frame = NSMakeRect(0, 0, 1, 1)
- // self.annotationViewController.annotationOutlineView.outlineView.delegate = nil
- // self.annotationViewController.annotationOutlineView.outlineView.dataSource = nil
- }
-
- func showPanelView(show: Bool) {
- self.isShowPanel = show
- if show {
- // self.panelSetViewController.listView = self.listView
- // self.panelSetViewController.view.frame = self.view.frame
- // self.view.addSubview(self.panelSetViewController.view)
- // self.panelSetViewController.reloadListViewModel()
- // self.panelSetViewController.view.autoresizingMask = [.height]
- } else {
- // self.contentBox.isHidden = false
- // self.panelSetViewController.view.removeFromSuperview()
- // if self.type.methodType == .None {
- // self.delegate?.controlStateChange?(self, show: false)
- // }
- }
- }
-
- func refreshMethodType(methodType: BotaType) {
- if (self.isShowPanel) {
- self.showPanelView(show: false)
- return
- }
- let newType = KMLeftMethodMode()
- var show = true
- if self.type.methodType != methodType {
- newType.methodType = methodType
- }
- if self.type.methodType == methodType {
- show = false
- }
- self.type = newType;
- // self.refreshShowMethod()
- self.delegate?.controlStateChange?(self,show:show)
- }
- //
- // private func updateViewButtonState() {
- // switch self.type.methodType {
- // case .None: do {
- //// self.contentBox.contentView = NSView()
- // self.delegate?.controlStateChange?(self,show:false)
- // }
- // break
- // case .Thumbnail: do {
- // self.thumbnailViewController.listView = self.listView
- // self.thumbnailViewController.delegate = self
- //// self.contentBox.contentView = self.thumbnailViewController.view
- //// self.thumbnailViewController.reloadData()
- // }
- // break
- // case .Outline: do {
- // }
- // break
- // case .BookMark: do {
- // self.bookViewController.listView = self.listView
- //// self.contentBox.contentView = self.bookViewController.view
- // self.bookViewController.reloadData()
- // }
- // break
- // case .Annotation: do {
- // self.annotationViewController.listView = self.listView
- //// self.contentBox.contentView = self.annotationViewController.view
- //// self.annotationViewController.reloadData()
- // }
- // break
- // break
- // case .Signature: do {
- // self.signatureViewController.listView = self.listView
- //// self.contentBox.contentView = self.signatureViewController.view
- // self.signatureViewController.reloadData()
- // }
- // break
- // }
- // }
-
- // func refreshShowMethod() {
- // self.dataSource = [KMLeftMethodMode]()
- // norImage = []
- // selectImage = []
- // if KMBOTAManagerClass.shard.getMethodShow(key: thumbnailMethodKey) {
- // let mode = KMLeftMethodMode()
- // mode.methodName = thumbnailMethodKey
- // mode.methodType = .Thumbnail
- // self.dataSource.insert(mode, at: self.dataSource.count)
- // norImage.append("KMImageNameSidebarThumbailNor")
- // selectImage.append("KMImageNameSidebarThumbailSelect")
- // }
- // if KMBOTAManagerClass.shard.getMethodShow(key: outlineMethodKey) {
- // let mode = KMLeftMethodMode()
- // mode.methodName = outlineMethodKey
- // mode.methodType = .Outline
- // self.dataSource.insert(mode, at: self.dataSource.count)
- // norImage.append("KMImageNameSidebarOutlineNor")
- // selectImage.append("KMImageNameSidebarOutlineSelect")
- // }
- // if KMBOTAManagerClass.shard.getMethodShow(key: bookMarkMethodKey) {
- // let mode = KMLeftMethodMode()
- // mode.methodName = bookMarkMethodKey
- // mode.methodType = .BookMark
- // self.dataSource.insert(mode, at: self.dataSource.count)
- // norImage.append("KMImageNameSidebarBookMarkNor")
- // selectImage.append("KMImageNameSidebarBookMarkSelect")
- // }
- // if KMBOTAManagerClass.shard.getMethodShow(key: anntationMethodKey) {
- // let mode = KMLeftMethodMode()
- // mode.methodName = anntationMethodKey
- // mode.methodType = .Annotation
- // self.dataSource.insert(mode, at: self.dataSource.count)
- // norImage.append("KMImageNameSidebarAnnotationNor")
- // selectImage.append("KMImageNameSidebarAnnotationSelect")
- // }
- // if KMBOTAManagerClass.shard.getMethodShow(key: searchMethodKey) {
- // let mode = KMLeftMethodMode()
- // mode.methodName = searchMethodKey
- // mode.methodType = .Search
- // self.dataSource.insert(mode, at: self.dataSource.count)
- // norImage.append("KMImageNameSidebarSearchNor")
- // selectImage.append("KMImageNameSidebarSearchSelect")
- // }
- //// if KMBOTAManagerClass.shard.getMethodShow(key: formMethodKey) {
- //// let mode = KMLeftMethodMode()
- //// mode.methodName = formMethodKey
- //// mode.methodType = .From
- //// self.dataSource.insert(mode, at: self.dataSource.count)
- //// }
- //// if KMBOTAManagerClass.shard.getMethodShow(key: signatureMethodKey) {
- //// let mode = KMLeftMethodMode()
- //// mode.methodName = signatureMethodKey
- //// mode.methodType = .Signature
- //// self.dataSource.insert(mode, at: self.dataSource.count)
- //// }
- // var isConstant = false
- // for source in dataSource {
- // if self.type.methodType == source.methodType {
- // isConstant = true
- // }
- // }
- // if(!isConstant) {
- // self.type = KMLeftMethodMode()
- // }
- //// self.leftTableview.reloadData()
- // var typeIndex = -1
- // for (index,value) in self.dataSource.enumerated() {
- // if value.methodType == self.type.methodType {
- // typeIndex = index
- // }
- // }
- //
- //// self.leftTableview.selectRowIndexes([typeIndex], byExtendingSelection: true)
- // if self.dataSource.count > 0 && typeIndex >= 0 {
- // self.type = self.dataSource[typeIndex]
- // }
- // self.updateViewButtonState()
- //
- // }
- //
- //MARK: menu
-
- // private func addMenuTitle() {
- // let menus : NSMenu = NSMenu(title: "")
- //
- // let addItem = self.menuItemWithTitle(title: NSLocalizedString("Thumbnails", comment: ""),type:thumbnailMethodKey,action: #selector(renameBookAction),tag: 1)
- // let outlineItem = self.menuItemWithTitle(title: NSLocalizedString("Outline", comment: ""),type:outlineMethodKey,action: #selector(renameBookAction),tag: 2)
- // let bookItem = self.menuItemWithTitle(title: NSLocalizedString("Bookmarks", comment: ""), type:bookMarkMethodKey,action: #selector(renameBookAction),tag: 3)
- // let annationItem = self.menuItemWithTitle(title: NSLocalizedString("Annotations", comment: ""), type:anntationMethodKey,action: #selector(renameBookAction),tag: 4)
- // let searchItem = self.menuItemWithTitle(title: NSLocalizedString("Search", comment: ""), type:searchMethodKey,action: #selector(renameBookAction),tag: 5)
- //// let formItem = self.menuItemWithTitle(title: NSLocalizedString("域", comment: ""), type:formMethodKey,action: #selector(renameBookAction),tag: 6)
- //// let signatureItem = self.menuItemWithTitle(title: NSLocalizedString("签名", comment: ""), type:signatureMethodKey,action: #selector(renameBookAction),tag: 7)
- //
- // menus.addItem(addItem)
- // menus.addItem(outlineItem)
- // menus.addItem(bookItem)
- // menus.addItem(annationItem)
- // menus.addItem(searchItem)
- //// menus.addItem(formItem)
- //// menus.addItem(signatureItem)
- //// self.leftTableview.menu = menus
- // }
- // func menuItemWithTitle(title:String,type:String,action:Selector?,tag:Int) -> NSMenuItem {
- // let menuItem = NSMenuItem.init(title: title as String, action: action, keyEquivalent: "")
- // menuItem.target = self
- // menuItem.tag = tag
- // if KMBOTAManagerClass.shard.getMethodShow(key: type) {
- // menuItem.state = NSControl.StateValue.on
- // } else {
- // menuItem.state = NSControl.StateValue.off
- // }
- // return menuItem
- // }
-
- // @objc func renameBookAction(menuItem:NSMenuItem) {
- // var show = true
- // if menuItem.state == NSControl.StateValue.on {
- // menuItem.state = NSControl.StateValue.off
- // show = false
- // } else {
- // menuItem.state = NSControl.StateValue.on
- // show = true
- // }
- // switch menuItem.tag {
- // case 1: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: thumbnailMethodKey)
- // }
- // case 2: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: outlineMethodKey)
- // }
- // case 3: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: bookMarkMethodKey)
- // }
- // case 4: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: anntationMethodKey)
- // }
- // case 5: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: searchMethodKey)
- // }
- // case 6: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: formMethodKey)
- // }
- // case 7: do {
- // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: signatureMethodKey)
- // }
- // break
- // default:
- // break
- // }
- // self.refreshShowMethod()
- // }
-
- // MARK: - New
-
- /*
- typedef NS_ENUM(NSInteger, KMNoteSortType) {
- KMNoteSortType_None = 0,
- KMNoteSortType_Time,
- KMNoteSortType_Page,
- };
- NSArrayController *thumbnailArrayController;
- NSArrayController *findArrayController;
- NSArrayController *groupedFindArrayController;
- }
- @property (nonatomic, assign) BOOL isAscendSort;
- @property (nonatomic, assign) KMNoteSortType noteSortType;
- @property (nonatomic, retain) NSView *filterButtonLayer;
- @property (nonatomic, retain) KMButtonLayer *moreButtonLayer;
- - (void)applySearchTableHeader:(NSString *)message;
- - (void)displayFindState;
- */
-
- // @property (nonatomic, retain) IBOutlet NSArrayController *thumbnailArrayController, *findArrayController, *groupedFindArrayController;
-
- @IBOutlet var segmentedControl: KMSegmentedControl!
-
- @IBOutlet var thumbnailTableView: KMThumbnailTableView!
- @IBOutlet var tocOutlineView: KMTocOutlineView!
- @IBOutlet var noteOutlineView: KMNoteOutlineView!
- @IBOutlet var findTableView: KMBotaTableView!
- @IBOutlet var groupedFindTableView: KMBotaTableView!
- @IBOutlet var snapshotTableView: KMBotaTableView!
-
- @IBOutlet weak var leftListView: NSView!
-
- @IBOutlet var searchViewController: KMBotaSearchViewController!
- @IBOutlet weak var toolButtonBox: NSBox!
- @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
- @IBOutlet weak var snapshotNormalView: NSView!
- @IBOutlet weak var snapshotLabel: NSTextField!
- @IBOutlet weak var snapshotNormalMoreButton: NSButton!
- @IBOutlet weak var snapshotNormalSearchButton: NSButton!
- @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
- @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
- @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
- @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
- @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var snapshotDoneButton: NSButton!
-
- @IBOutlet weak var outlineView: NSView!
- @IBOutlet weak var outlineMoreButton: NSButton!
- @IBOutlet weak var outlineAddButton: NSButton!
- @IBOutlet weak var outlineSearchButton: NSButton!
- @IBOutlet weak var outlineLabel: NSTextField!
- @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var outlineDoneButton: NSButton!
-
- @IBOutlet weak var noteView: NSView!
- @IBOutlet weak var noteMoreButton: NSButton!
- @IBOutlet weak var noteFilterButton: NSButton!
- @IBOutlet weak var noteSearchButton: NSButton!
- @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var noteTitleLabel: NSTextField!
- @IBOutlet weak var noteHeaderView: NSView!
- @IBOutlet weak var sortTypeBox: KMBox!
- @IBOutlet weak var sortTypeLabel: NSTextField!
- @IBOutlet weak var noteSortButton: NSButton!
- @IBOutlet weak var noteDoneButton: NSButton!
-
- @IBOutlet weak var thumbnailView: NSView!
- @IBOutlet weak var thumbnailZoomOutButton: NSButton!
- @IBOutlet weak var thumbnailZoomInButton: NSButton!
- @IBOutlet weak var thumbnailTitleLabel: NSTextField!
-
- @IBOutlet weak var emptySearchBox: NSBox!
- @IBOutlet weak var emptySearchLabel: NSTextField!
-
- var thumbnails: [KMThumbnail] = []
- var isDisplayPageSize = false
- var thumbnailCacheSize: CGFloat = 0
- var findState: KMFindState = .content
- var searchResults: [CPDFSelection] = []
- var findPaneState: KMFindPaneState = .singular
- var isSearchOutlineMode = false
- var outlineIgnoreCaseFlag = false
- var noteTypeDict: [String : Any] = [:]
-
-
- private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
- private let LABEL_COLUMNID = "label"
- var foldType: KMFoldAllAnnotationType = .none
-
- override func loadView() {
- super.loadView()
-
- self.view.wantsLayer = true
- self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.outlineView.wantsLayer = true
- self.outlineView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.noteView.wantsLayer = true
- self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.thumbnailView.wantsLayer = true
- self.thumbnailView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.snapshotNormalView.wantsLayer = true
- self.snapshotNormalView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.tocOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
- self.noteOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
- self.findTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.groupedFindTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.snapshotTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.thumbnailTableView.backgroundColor = KMAppearance.Layout.l0Color()
-
- self.leftListView.wantsLayer = true
- self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
- self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
- self.emptySearchBox.isHidden = true
-
- self.thumbnailTitleLabel.stringValue = KMLocalizedString("Thumbnails", nil)
- self.thumbnailTitleLabel.textColor = KMAppearance.Layout.h0Color()
- // self.thumbnailZoomInButton.action = #selector(thumbnailSizeScaling)
- // [_thumbnailZoomInButton setTarget:mainController];
- // _thumbnailZoomInButton.tag = 1;
- // [_thumbnailZoomOutButton setAction:@selector(thumbnailSizeScaling:)];
- // [_thumbnailZoomOutButton setTarget:mainController];
- // _thumbnailZoomOutButton.tag = 0;
-
- self.snapshotTableView.delegate = self
- self.snapshotTableView.dataSource = self
- // [[snapshotTableView menu] setDelegate:mainController];
- // [snapshotTableView setDoubleAction:@selector(toggleSelectedSnapshots:)];
- // [snapshotTableView setTarget:mainController];
- self.snapshotTableView.backgroundColor = .clear
- // [snapshotTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
- self.snapshotLabel.stringValue = KMLocalizedString("Snapshots", nil)
- self.snapshotLabel.textColor = KMAppearance.Layout.h0Color()
- // [_snapshotNormalZoomInButton setAction:@selector(thumbnailSizeScaling:)];
- // [_snapshotNormalZoomInButton setTarget:mainController];
- // _snapshotNormalZoomInButton.tag = 2;
- // [_snapshotNormalZoomOutButton setAction:@selector(thumbnailSizeScaling:)];
- // [_snapshotNormalZoomOutButton setTarget:mainController];
- // _snapshotNormalZoomOutButton.tag = 3;
- self.snapshotNormalSearchButton.toolTip = KMLocalizedString("Search", nil)
- // [_snapshotNormalMoreButton setAction:@selector(leftSideViewMoreButtonAction:)];
- // [_snapshotNormalMoreButton setTarget:mainController];
- // [_snapshotNormalMoreButton setTag:300];
-
- // [_snapshotSearchZoomInButton setAction:@selector(thumbnailSizeScaling:)];
- // [_snapshotSearchZoomInButton setTarget:mainController];
- // _snapshotSearchZoomInButton.tag = 2;
- // [_snapshotSearchZoomOutButton setAction:@selector(thumbnailSizeScaling:)];
- // [_snapshotSearchZoomOutButton setTarget:mainController];
- // _snapshotSearchZoomOutButton.tag = 3;
- self.snapshotDoneButton.title = KMLocalizedString("Done", nil)
- self.snapshotDoneButton.toolTip = KMLocalizedString("Done", nil)
- self.snapshotDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.snapshotDoneButton.wantsLayer = true
- self.snapshotDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.snapshotDoneButton.layer?.cornerRadius = 4.0
- // [self.snapshotDoneButton setAction:@selector(leftSideViewDoneButtonAction:)];
- // [self.snapshotDoneButton setTarget:mainController];
- // [self.snapshotDoneButton setTag:312];
- // self.snapshotDoneButton.hidden = YES;
-
- // [noteOutlineView setAutoresizesOutlineColumn: NO];
-
- self.noteOutlineView.delegate = self
- self.noteOutlineView.dataSource = self
- // [[noteOutlineView menu] setDelegate:mainController];
- // [noteOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
- // [noteOutlineView setIndentationPerLevel:0.0];
- // [noteOutlineView registerForDraggedTypes:[NSColor readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]];
-
- self.snapshotSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
- self.outlineSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
- self.noteSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
- self.snapshotSearchField.wantsLayer = true
- self.outlineSearchField.wantsLayer = true
- self.noteSearchField.wantsLayer = true
- self.snapshotSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.outlineSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.noteSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.snapshotSearchField.layer?.borderWidth = 1.0
- self.outlineSearchField.layer?.borderWidth = 1.0
- self.noteSearchField.layer?.borderWidth = 1.0
- self.snapshotSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.outlineSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
- self.noteSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
-
- // __block typeof(self) blockSelf = self;
- // _snapshotSearchField.changeCallBack = ^(NSString *changeContent) {
- // NSString *editContent = @"";
- // if (changeContent) {
- // editContent = changeContent;
- // }
- // [blockSelf.mainController searchFieldChangeAction:editContent];
- // };
- self.snapshotSearchField.isHidden = true
- self.snapshotSearchZoomOutButton.isHidden = true
- self.snapshotSearchZoomInButton.isHidden = true
- // _snapshotSearchField.endEditCallBack = ^(BOOL isEndEdit) {
- // if (isEndEdit/* && searchViewController.segmentedControl.segmentCount == 3*/) {
- // _snapshotSearchField.hidden = YES;
- // _snapshotSearchZoomOutButton.hidden = YES;
- // _snapshotSearchZoomInButton.hidden = YES;
- // _snapshotLabel.hidden = NO;
- // _snapshotNormalZoomOutButton.hidden = NO;
- // _snapshotNormalZoomInButton.hidden = NO;
- // }
- // };
- self.thumbnailZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
- self.snapshotNormalZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
- self.snapshotSearchZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
- self.thumbnailZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
- self.snapshotNormalZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
- self.snapshotSearchZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
-
- self.outlineLabel.stringValue = KMLocalizedString("Outline", nil);
- self.outlineLabel.textColor = KMAppearance.Layout.h0Color()
- // self.outlineAddButton.toolTip = NSLocalizedString(@"Add Item", nil);
- // [self.outlineAddButton setAction:@selector(outlineContextMenuItemClicked_AddEntry:)];
- // [self.outlineAddButton setTarget:mainController];
- // self.outlineSearchButton.toolTip = NSLocalizedString(@"Search", nil);
- // [self.outlineMoreButton setAction:@selector(leftSideViewMoreButtonAction:)];
- // [self.outlineMoreButton setTarget:mainController];
- // [self.outlineMoreButton setTag:302];
- self.outlineDoneButton.title = KMLocalizedString("Done", nil);
- self.outlineDoneButton.toolTip = KMLocalizedString("Done", nil);
- self.outlineDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.outlineDoneButton.wantsLayer = true
- self.outlineDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.outlineDoneButton.layer?.cornerRadius = 4.0
- // [self.outlineDoneButton setAction:@selector(leftSideViewDoneButtonAction:)];
- // [self.outlineDoneButton setTarget:mainController];
- // [self.outlineDoneButton setTag:310];
- // self.outlineDoneButton.hidden = YES;
- self.outlineSearchField.isHidden = true
- // _outlineSearchField.endEditCallBack = ^(BOOL isEndEdit) {
- // if (isEndEdit) {
- // _outlineSearchField.hidden = YES;
- // _outlineLabel.hidden = NO;
- // _outlineSearchButton.hidden = NO;
- // }
- // };
- // NSMenu *menuOutline = [NSMenu menu];
- // [menuOutline addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleOutlineCaseInsensitiveSearch:) target:mainController];
- // [[_outlineSearchField cell] setSearchMenuTemplate:menuOutline];
- // [[_outlineSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Outline", nil)];
- // [_outlineSearchField setTarget:mainController];
-
- let sud = UserDefaults.standard
- self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
- self.noteTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
- // [self.noteMoreButton setAction:@selector(leftSideViewMoreButtonAction:)];
- // [self.noteMoreButton setTarget:mainController];
- // [self.noteMoreButton setTag:304];
- // self.noteMoreButton.wantsLayer = YES;
- // _moreButtonLayer = [KMButtonLayer layer];
- // [self.noteMoreButton.layer addSublayer:_moreButtonLayer];
- // _moreButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.noteMoreButton.bounds), CGRectGetHeight(self.noteMoreButton.bounds));
- // _moreButtonLayer.layerType = KMNoteFilerButtonLayerType_None;
- // _moreButtonLayer.hidden = YES;
-
- // [self.noteFilterButton setAction:@selector(noteFilterAction:)];
- // [self.noteFilterButton setTarget:mainController];
- // [self.noteFilterButton setToolTip:NSLocalizedString(@"Sort", nil)];
- // self.noteFilterButton.wantsLayer = YES;
- // _filterButtonLayer = [[NSView alloc] init];
- // [self.noteFilterButton addSubview:_filterButtonLayer];
- // _filterButtonLayer.frame = CGRectMake(14, 2, 8, 8);
- // _filterButtonLayer.layerType = KMNoteFilerButtonLayerType_Dot;
- // _filterButtonLayer.hidden = YES;
- // _filterButtonLayer.wantsLayer = YES;
- // _filterButtonLayer.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
- // _filterButtonLayer.layer.cornerRadius = 4.0;
-
- self.noteDoneButton.title = KMLocalizedString("Done", nil)
- self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
- self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.noteDoneButton.wantsLayer = true
- self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.noteDoneButton.layer?.cornerRadius = 4.0
- // [self.noteDoneButton setAction:@selector(leftSideViewDoneButtonAction:)]
- // [self.noteDoneButton setTarget:mainController];
- // [self.noteDoneButton setTag:311];
- // self.noteDoneButton.hidden = YES;
-
- self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.noteSearchField.isHidden = true
- // _noteSearchField.endEditCallBack = ^(BOOL isEndEdit) {
- // if (isEndEdit) {
- // _noteSearchField.hidden = YES;
- // _noteSearchButton.hidden = NO;
- // _noteTitleLabel.hidden = NO;
- // }
- // };
- self.noteHeaderView.wantsLayer = true
- self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
- self.noteHeaderView.layer?.cornerRadius = 1.0
- // let sortType = sud.integer(forKey: KMLeftSideViewNoteSortTypeKey)
- // if (sortType) {
- // _noteSortType = sortType;
- // if (sortType == KMNoteSortType_Time) {
- // self.sortTypeLabel.stringValue = NSLocalizedString(@"Time", nil);
- // self.sortTypeBox.toolTip = NSLocalizedString(@"Time", nil);
- // } else if (sortType == KMNoteSortType_Page) {
- // self.sortTypeLabel.stringValue = NSLocalizedString(@"Page", nil);
- // self.sortTypeBox.toolTip = NSLocalizedString(@"Page", nil);
- // }
- // } else {
- // _noteSortType = KMNoteSortType_Time;
- // self.sortTypeLabel.stringValue = NSLocalizedString(@"Time", nil);
- // }
- self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
-
- // _isAscendSort = [sud boolForKey:KMLeftSideViewAscendSortBoolKey];
- // if (_isAscendSort) {
- // [_noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankReverse]];
- // [_noteSortButton setToolTip:NSLocalizedString(@"ascending sort", nil)];
- // } else {
- // [_noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankPositive]];
- // [_noteSortButton setToolTip:NSLocalizedString(@"descending sort", nil)];
- // }
-
- // self.sortTypeBox.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
- // if (downEntered) {
- // NSMenu *menu = [[[NSMenu alloc] init] autorelease];
- // NSMenuItem *timeItem = [menu addItemWithTitle:NSLocalizedString(@"Time", nil) action:@selector(sortTypeAction:) target:self];
- // [timeItem setRepresentedObject:self];
- // timeItem.tag = 0;
- // NSMenuItem *pageItem = [menu addItemWithTitle:NSLocalizedString(@"Page", nil) action:@selector(sortTypeAction:) target:self];
- // [pageItem setRepresentedObject:self];
- // timeItem.tag = 1;
- // if (self.noteSortType == KMNoteSortType_Time) {
- // timeItem.state = NSControlStateValueOn;
- // pageItem.state = NSControlStateValueOff;
- // } else if (self.noteSortType == KMNoteSortType_Page) {
- // timeItem.state = NSControlStateValueOff;
- // pageItem.state = NSControlStateValueOn;
- // }
- // [menu popUpMenuPositioningItem:nil atLocation:CGPointMake(-10, 0) inView:self.sortTypeBox];
- // }
- // };
-
- self.searchViewController.loadView()
- self.searchViewController.contentView = self.findTableView.enclosingScrollView
- self.searchField = self.searchViewController.searchField
-
- self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
- self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
- self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
- self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
- self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
- self.searchViewController.segmentedControl.isBackgroundHighlighted = true
- self.searchViewController.segmentedControl.selectedSegment = 0
- // [mainController bind:@"findPaneState" toObject:searchViewController.segmentedControl withKeyPath:@"selectedSegment" options:nil];
- self.segmentedControl.segmentCount = 5
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 0)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 1)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 2)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 3)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 4)
- self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails", nil), for: 0)
- self.segmentedControl.setToolTip(KMLocalizedString("View Outline", nil), for: 1)
- self.segmentedControl.setToolTip(KMLocalizedString("View Notes", nil), for: 2)
- self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots", nil), for: 3)
- self.segmentedControl.setToolTip(KMLocalizedString("Search", nil), for: 4)
- self.segmentedControl.selectedSegment = 0
- // [segmentedControl bind:@"selectedSegment" toObject:mainController withKeyPath:@"leftSidePaneState" options:nil];
- // [mainController bind:@"leftSidePaneState" toObject:segmentedControl withKeyPath:@"selectedSegment" options:nil];
- self.segmentedControl.wantsLayer = true
- self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- self.segmentedControl.block = { [unowned self] segIndex in
- self.toolButtonBox.isHidden = false
- self.toolButtonBoxLayoutConstraint.constant = 40.0
-
- if (segIndex == 0) {
- self.toolButtonBox.contentView = self.thumbnailView
- self.displayThumbnailViewAnimating(true)
- } else if (segIndex == 1) {
- self.toolButtonBox.contentView = self.outlineView
- self.displayTocViewAnimating(false)
- } else if (segIndex == 2) {
- self.toolButtonBox.contentView = self.noteView
- self.displayNoteViewAnimating(false)
- } else if (segIndex == 3) {
- self.toolButtonBox.contentView = self.snapshotNormalView
- self.displaySnapshotViewAnimating(false)
- } else if (segIndex == 4) {
- self.toolButtonBox.isHidden = true
- self.toolButtonBoxLayoutConstraint.constant = 0
- self.displayFindViewAnimating(false)
- }
- }
-
- // self.button.setHelp(KMLocalizedString("View Thumbnails", "Tool tip message"), for: KMLeftSidePaneState.thumbnail.rawValue)
- // self.button.setHelp(KMLocalizedString("View Outline", "Tool tip message"), for: KMLeftSidePaneState.outline.rawValue)
- // self.alternateButton.setHelp(KMLocalizedString("Separate search results", "Tool tip message"), for: KMFindPaneState.singular.rawValue)
- // self.alternateButton.setHelp(KMLocalizedString("Group search results by page", "Tool tip message"), for: KMFindPaneState.grouped.rawValue)
-
- // NSMenu *menu = [NSMenu menu];
- // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
- // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
- // [[searchField cell] setSearchMenuTemplate:menu];
- // [[searchField cell] setPlaceholderString:NSLocalizedString(@"Search PDF", @"placeholder")];
-
- // [searchField setAction:@selector(search:)];
- // [searchField setTarget:mainController];
-
- self.tocOutlineView.autoresizesOutlineColumn = false
- self.tocOutlineView.allowsMultipleSelection = true
- self.tocOutlineView.allowsEmptySelection = true
- self.tocOutlineView.delegate = self
- self.tocOutlineView.dataSource = self
-
- self.thumbnailTableView.delegate = self
- self.thumbnailTableView.dataSource = self
- self.thumbnailTableView.allowsMultipleSelection = true
- self.findTableView.delegate = self
- // [groupedFindTableView setDelegate:mainController];
- self.groupedFindTableView.dataSource = self
- // [[thumbnailTableView menu] setDelegate:mainController];
- // [[findTableView menu] setDelegate:mainController];
- // [[groupedFindTableView menu] setDelegate:mainController];
-
- // [tocOutlineView setDoubleAction:@selector(goToSelectedOutlineItem:)];
- // [tocOutlineView setTarget:mainController];
- // [findTableView setDoubleAction:@selector(goToSelectedFindResults:)];
- // [findTableView setTarget:mainController];
- // [groupedFindTableView setDoubleAction:@selector(goToSelectedFindResults:)];
- // [groupedFindTableView setTarget:mainController];
-
- // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
- // //支持拖拽的文字类型
- // [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
- // [tocOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
- // [tocOutlineView registerForDraggedTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType]];
- // [[[findTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
- // [[[groupedFindTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
- // [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] dataCell] setEnabled:NO];
-
- // if (RUNNING_AFTER(10_9)) {
- // [thumbnailTableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
- // [(SKSourceListTextFieldCell *)[[thumbnailTableView tableColumnWithIdentifier:PAGE_COLUMNID] dataCell] setSimulatesSourceList:YES];
- // }
-
- // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
- // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
- //
- // [thumbnailTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
-
- // if (NO == [[NSUserDefaults standardUserDefaults] boolForKey:SKDisableTableToolTipsKey]) {
- // [tocOutlineView setHasImageToolTips:YES];
- // [findTableView setHasImageToolTips:YES];
- // [groupedFindTableView setHasImageToolTips:YES];
- // }
- // [self updateViewColor];
- }
-
- func displayThumbnailViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.thumbnailTableView.enclosingScrollView!, animate: animate)
-
- var frame = self.thumbnailTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.thumbnailTableView.enclosingScrollView?.frame = frame
-
- self.resetThumbnails()
-
- // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- // frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
-
- // [self updateThumbnailSelection];
- }
-
- func displayFindViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.searchViewController.view, animate: animate)
- if (self.findState != .content) {
- self.findState = .content
- } else {
- self.displayFindState()
- }
-
- var frame = self.searchViewController.view.frame
- frame.origin.y = 0
- frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
- self.searchViewController.view.frame = frame
-
- // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- // frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
- // [self.leftSideEmptyVC.emptySnapView removeFromSuperview];
-
- // [self updataLeftSideSnapView];
- }
-
- func displayFindState() {
- if (self.findState == .content) {
- self.displayFind()
- } else if (self.findState == .note) {
- // [self displayNoteFind];
- } else if (self.findState == .snapshot) {
- // [self displaySnapshotFind];
- }
- }
- /*
-
- - (void) {
- }
- - (void)displayGroupedFindViewAnimating:(BOOL)animate {
- [leftSideController replaceSideView:leftSideController.searchViewController.view animate:animate];
- if (self.findState != SKFindStateContent) {
- self.findState = SKFindStateContent;
- } else {
- [leftSideController displayFindState];
- }
-
- NSRect frame = leftSideController.searchViewController.view.frame;
- frame.origin.y = 0;
- frame.size.height = leftSideController.searchViewController.view.superview.frame.size.height;
- leftSideController.searchViewController.view.frame = frame;
-
- frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- frame.origin.y = 0;
- frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
- frame.origin.y = 0;
- frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
- rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
-
- [self updataLeftSideSnapView];
- }
- */
-
- func displayNoteViewAnimating(_ animate: Bool) {
- self.searchViewController.contentView = nil
- self.replaceSideView(self.noteOutlineView.enclosingScrollView!, animate: animate)
- if (self.findState != .note) {
- self.findState = .note
- } else {
- self.displayFindState()
- }
-
- var frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- let view = self.noteOutlineView.enclosingScrollView
- // CGSize emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size;
- // self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
-
- DispatchQueue.main.async {
- self.noteOutlineView.reloadData()
- }
- }
-
- func displaySnapshotViewAnimating(_ animate: Bool) {
- self.searchViewController.contentView = nil
- self.replaceSideView(self.snapshotTableView.enclosingScrollView!, animate: animate)
- if (self.findState != .snapshot) {
- self.findState = .snapshot;
- } else {
- self.displayFindState()
- }
-
- var frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.tocOutlineView.enclosingScrollView?.frame = frame
-
- // [self updateSnapshotsIfNeeded];
- }
-
- func displayFind() {
- self.searchField = self.searchViewController.searchField
-
- let menu = NSMenu()
- // menu.addItem(title: <#T##String#>, action: <#T##Selector?#>, target: <#T##AnyObject?#>)
- // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
- // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
- // [[searchViewController.searchField cell] setSearchMenuTemplate:menu];
- (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
- // self.searchViewController.searchField.target =
- // [searchViewController.searchField setAction:@selector(search:)];
- // [searchViewController.searchField setTarget:mainController];
- if (self.findPaneState == .singular) {
- self.searchViewController.contentView = self.findTableView.enclosingScrollView
- } else if (self.findPaneState == .grouped) {
- self.searchViewController.contentView = self.groupedFindTableView.enclosingScrollView
- }
- }
-
- func displayTocViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.tocOutlineView.enclosingScrollView!, animate: animate)
-
- var frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.tocOutlineView.enclosingScrollView?.frame = frame
-
- // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // [self updateOutlineSelection];
-
- let view = self.tocOutlineView.enclosingScrollView
- // CGSize emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size;
-
- // self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
- }
- /*
-
- @implementation SKLeftSideViewController
- @synthesize thumbnailArrayController, findArrayController, groupedFindArrayController;
- - (BOOL)requiresAlternateButtonForView:(NSView *)aView {
- return NO;
- return [findTableView isDescendantOf:aView] || [groupedFindTableView isDescendantOf:aView];
- }
- - (void)applySearchTableHeader:(NSString *)message {
- [[[findTableView tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
- [[findTableView headerView] setNeedsDisplay:YES];
- [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell] setStringValue:message];
- [[groupedFindTableView headerView] setNeedsDisplay:YES];
- }
- - (void)displayFindState {
- if (mainController.findState == SKFindStateContent) {
- [self displayFind];
- } else if (mainController.findState == SKFindStateNote) {
- [self displayNoteFind];
- } else if (mainController.findState == SKFindStateSnapshot) {
- [self displaySnapshotFind];
- }
- }
- - (void)displayNoteFind {
- mainController.rightSideController.searchField = self.noteSearchField;
-
- NSMenu *menu = [NSMenu menu];
- [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
- [[self.noteSearchField cell] setSearchMenuTemplate:menu];
- [[self.noteSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Notes", @"placeholder")];
- [self.noteSearchField setAction:@selector(searchNotes:)];
- [self.noteSearchField setTarget:mainController];
- }
- - (void)displaySnapshotFind {
- mainController.rightSideController.searchField = self.snapshotSearchField;
-
- NSMenu *menu = [NSMenu menu];
- [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
- [[self.snapshotSearchField cell] setSearchMenuTemplate:menu];
- [[self.snapshotSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Snapshots", @"placeholder")];
- [self.snapshotSearchField setAction:@selector(searchNotes:)];
- [self.snapshotSearchField setTarget:mainController];
- [self.snapshotSearchField setDelegate:mainController];
- }
- #pragma mark - UI Action
- - (IBAction)snapshotNormalSearchButtonAction:(NSButton *)sender {
- _snapshotSearchField.hidden = NO;
- // _snapshotSearchZoomOutButton.hidden = YES;
- _snapshotSearchZoomInButton.hidden = YES;
- _snapshotNormalSearchButton.hidden = YES;
- _snapshotDoneButton.hidden = NO;
- _snapshotLabel.hidden = YES;
- _snapshotNormalZoomOutButton.hidden = YES;
- _snapshotNormalZoomInButton.hidden = YES;
-
- [_snapshotSearchField becomeFirstResponder];
- }
- - (IBAction)outlineNormalSearchButtonAction:(NSButton *)sender {
- _outlineSearchField.hidden = NO;
- _outlineDoneButton.hidden = NO;
- _outlineLabel.hidden = YES;
- _outlineSearchButton.hidden = YES;
- _outlineMoreButton.hidden = YES;
- _outlineAddButton.hidden = YES;
-
- [_outlineSearchField becomeFirstResponder];
- }
- - (IBAction)noteSearchAction:(NSButton *)sender {
- self.noteSearchField.hidden = NO;
- self.noteTitleLabel.hidden = YES;
- self.noteSearchButton.hidden = YES;
- self.noteDoneButton.hidden = NO;
- self.noteFilterButton.hidden = YES;
- self.noteMoreButton.hidden = YES;
-
- [self.noteSearchField becomeFirstResponder];
- }
- - (IBAction)noteSortAction:(id)sender {
- if (self.isAscendSort) {
- self.isAscendSort = NO;
- [self.noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankPositive]];
- [self.noteSortButton setToolTip:NSLocalizedString(@"descending sort", nil)];
- } else {
- self.isAscendSort = YES;
- [self.noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankReverse]];
- [self.noteSortButton setToolTip:NSLocalizedString(@"ascending sort", nil)];
- }
- [[NSUserDefaults standardUserDefaults] setBool:self.isAscendSort forKey:KMLeftSideViewAscendSortBoolKey];
- }
- - (IBAction)sortTypeAction:(id)sender {
- NSMenuItem *item = (NSMenuItem *)sender;
- NSInteger tag = item.tag;
-
- if (item.state == NSControlStateValueOn) {
- item.state = NSControlStateValueOff;
- } else {
- item.state = NSControlStateValueOn;
- }
- if (tag == 0) {
- self.noteSortType = KMNoteSortType_Page;
- _sortTypeLabel.stringValue = NSLocalizedString(@"Page", nil);
- _sortTypeBox.toolTip = NSLocalizedString(@"Page", nil);
- } else if (tag == 1) {
- self.noteSortType = KMNoteSortType_Time;
- _sortTypeLabel.stringValue = NSLocalizedString(@"Time", nil);
- _sortTypeBox.toolTip = NSLocalizedString(@"Time", nil);
- }
- [[NSUserDefaults standardUserDefaults] setInteger:self.noteSortType forKey:KMLeftSideViewNoteSortTypeKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- #pragma mark - get && set
- - (void)setIsAscendSort:(BOOL)isAscendSort {
- _isAscendSort = isAscendSort;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationSortTypeKeyNotification" object:self userInfo:nil];
- }
- - (void)setNoteSortType:(KMNoteSortType)noteSortType {
- _noteSortType = noteSortType;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationSortTypeKeyNotification" object:self userInfo:nil];
- }
- */
-
- func resetThumbnails() {
- // [self willChangeValueForKey:THUMBNAILS_KEY];
-
- self.thumbnailCacheSize = 400
-
- self.thumbnails.removeAll()
- let pageLabels = self.listView.document.pageLabels()
- if (pageLabels.isEmpty == false) {
- let isLocked = self.listView.document.isLocked
- let firstPage = self.listView.document.page(at: 0)
- // SKPDFPage
- let emptyPage = CPDFPage()
- let firstFrame = firstPage?.bounds(for: .cropBox) ?? .zero
- let firstFrame2 = firstPage?.bounds(for: .mediaBox) ?? .zero
- emptyPage.setBounds(firstFrame, for: .cropBox)
- emptyPage.setBounds(firstFrame2, for: .mediaBox)
- emptyPage.rotation = firstPage?.rotation ?? 0
-
- let pageImage = firstPage!.thumbnail(of: NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize))
- // NSImage * = [emptyPage thumbnailWithSize:thumbnailCacheSize forBox:[pdfView displayBox]];
- var rect: NSRect = .zero
- rect.size = pageImage?.size ?? .zero
- let width = 1.2 * fmin(NSWidth(rect), NSHeight(rect))
- rect = NSInsetRect(rect, 0.5 * (NSWidth(rect) - width), 0.5 * (NSHeight(rect) - width));
-
- pageImage?.lockFocus()
- NSImage(named: NSImage.applicationIconName)?.draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
- if (isLocked) {
- NSWorkspace.shared.icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kLockedBadgeIcon))).draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
- // [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:0.5];
- }
- pageImage?.unlockFocus()
-
- // __block typeof(self) blockSelf = self;
- for (i, label) in pageLabels.enumerated() {
- let thumbnail = KMThumbnail(image: pageImage, label: label, pageIndex: i)
- // thumbnail.delegate = self
- thumbnail.dirty = true
- self.thumbnails.append(thumbnail)
- }
- }
- // [self didChangeValueForKey:THUMBNAILS_KEY];
- // [self allThumbnailsNeedUpdate];
-
- DispatchQueue.main.async {
- self.thumbnailTableView.reloadData()
- }
- }
- /*
-
-
- */
- }
- //MARK: NSTableViewDelegate,NSTableViewDataSource
- //extension KMLeftSideViewController: NSTableViewDelegate,NSTableViewDataSource {
- // func numberOfRows(in tableView: NSTableView) -> Int {
- // return self.dataSource.count
- // }
- //
- // func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- // let cell : KMLiftSideCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMLiftSideCellView"), owner: self) as! KMLiftSideCellView
- // if row <= selectImage.count-1 {
- // if self.dataSource[row] == self.type {
- // cell.isSelect = true
- // cell.mothedImage.image = NSImage(named: selectImage[row])
- // cell.backgroundColor(NSColor.km_init(hex: "#DFE1E5"))
- // } else {
- // cell.isSelect = false
- // cell.mothedImage.image = NSImage(named: norImage[row])
- // cell.backgroundColor(NSColor.clear)
- // }
- // }
- // cell.index = row
- // cell.buttonClick = { [unowned self] index in
- // if ((index < self.dataSource.count) && (index > -1)) {
- //
- // let isSearch = self.type.methodType == .Search
- //
- // var show = true
- // if( self.type == self.dataSource[index]) {
- // self.type = KMLeftMethodMode()
- // show = false
- // } else {
- // self.type = self.dataSource[index]
- // show = true
- // }
- //
- // self.trackEvent(type: self.type.methodType)
- //
- // self.updateViewButtonState()
- // self.delegate?.controlStateChange?(self,show:show)
- //// self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
- //// self.leftTableview.reloadData()
- //
- // UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
- // UserDefaults.standard.synchronize()
- //
- // if (isSearch && show == false) {
- // self.view.window?.makeFirstResponder(self)
- // } else if (isSearch && self.type.methodType != .Search) { // 切换
- // self.view.window?.makeFirstResponder(self)
- // }
- // }
- // }
- // return cell
- // }
- //
- // func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
- // return 48
- // }
- //
- // func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
- // let rowView = KMCustomTableRowView()
- // rowView.selectionColor = NSColor(calibratedRed: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1.0)
- // rowView.color = NSColor.km_init(hex: "#F7F8FA")
- // return rowView
- // }
- //
- // func tableViewSelectionDidChange(_ notification: Notification) {
- //
- // }
- //}
- //extension KMLeftSideViewController: KMPDFViewPanelSetViewControllerDelegate {
- // func controller(_ controller: KMPDFViewPanelSetViewController, dispayDidChange dispay: KMPDFDisplayType) {
- // self.delegate?.controller?(self, dispayDidChange: dispay)
- // }
- //
- // func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool) {
- // self.listView?.displaysPageBreaks = pageBreaks
- // self.listView?.layoutDocumentView()
- // }
- //
- // func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType) {
- //// if (rotateType == .clockwise) { /// 顺时针
- //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
- //// if page.rotation == 0 {
- //// page.rotation = 90
- //// } else if page.rotation == 90 {
- //// page.rotation = 180
- //// } else if page.rotation == 180 {
- //// page.rotation = 270
- //// } else if page.rotation == 270 {
- //// page.rotation = 0
- //// }
- //// self.listView?.layoutDocumentView()
- //// } else if (rotateType == .anticlockwise) { /// 逆时针
- //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
- //// if page.rotation == 0 {
- //// page.rotation = 270
- //// } else if page.rotation == 90 {
- //// page.rotation = 0
- //// } else if page.rotation == 180 {
- //// page.rotation = 90
- //// } else if page.rotation == 270 {
- //// page.rotation = 180
- //// }
- //// self.listView?.layoutDocumentView()
- //// }
- ////
- // self.delegate?.controller?(controller: self, rotateType: rotateType)
- // }
- //}
- // MARK: -
- // MARK: - 扩展
- extension KMLeftSideViewController {
- public func selectType(_ type: BotaType) {
- // 更新 type
- var show = true
- if (self.type.methodType == .None) {
- show = true
- } else {
- if (self.type.methodType == type) {
- show = false
- } else {
- show = true
- }
- }
-
- var index: Int = NSNotFound
- switch type {
- case .None:
- index = NSNotFound
- break
- case .Thumbnail:
- index = 0
- break
- case .Outline:
- index = 1
- break
- case .BookMark:
- index = 2
- break
- case .Annotation:
- index = 3
- break
- case .Search:
- index = 4
- break
- case .From:
- index = 5
- break
- case .Signature:
- index = 6
- break
- }
-
- self.type = self.getMethodMode(show ? type : .None)
-
- // 更新按钮状态
- // self.updateViewButtonState()
- // 将事件传递出去
- self.delegate?.controlStateChange?(self,show:show)
- if (index != NSNotFound) {
- // self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
-
- // 记录当前选中
- UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
- UserDefaults.standard.synchronize()
- }
- // self.leftTableview.reloadData()
- }
-
- private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
- let mode = KMLeftMethodMode()
- mode.methodType = type
- switch type {
- case .None:
- mode.methodName = ""
- break
- case .Thumbnail:
- mode.methodName = thumbnailMethodKey
- break
- case .Outline:
- mode.methodName = outlineMethodKey
- break
- case .BookMark:
- mode.methodName = bookMarkMethodKey
- break
- case .Annotation:
- mode.methodName = anntationMethodKey
- break
- case .Search:
- mode.methodName = searchMethodKey
- break
- case .From:
- mode.methodName = formMethodKey
- break
- case .Signature:
- mode.methodName = signatureMethodKey
- break
- }
- return mode
- }
- }
- //MARK: Cache
- extension KMLeftSideViewController {
- func clearAnnotationFilterData() {
- if let _key = self.listView?.document?.documentURL?.path {
- let userDefaults = UserDefaults.standard
- let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
- userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + _key)
- let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
- userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + _key)
- let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
- userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + _key)
- userDefaults.synchronize()
- }
- }
-
- func clearNotification() {
- self.bookViewController.removeNotification()
- self.annotationViewController.removeNotification()
- }
- }
- // MARK: - Analytics (埋点)
- extension KMLeftSideViewController {
- func trackEvent(type: BotaType) -> Void {
- if (type == .Thumbnail) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Thumbnail", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .Outline) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Outline", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .BookMark) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_BookMark", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .Annotation) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Annotation", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- } else if (type == .Search) {
- KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Search", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
- }
- }
- }
- // MARK: - Private Methods
- extension KMLeftSideViewController {
- @objc private func _themeChanged(_ notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
- self._updateViewColor()
- }
- }
-
- private func _updateViewColor() {
- if(KMAppearance.isDarkMode()){
- self.leftListView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.noteView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.outlineView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.view.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
- self.thumbnailTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
- self.groupedFindTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
- self.tocOutlineView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
- self.findTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
-
- self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
- self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
- self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
- self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
-
- self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
- self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
- self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
- } else {
- self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.noteView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.outlineView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
- self.view.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
-
- self.thumbnailTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
- self.groupedFindTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
- self.tocOutlineView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
- self.findTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
-
- self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
-
- self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
- self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
- self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
- }
- }
-
- private func _hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {
- // if ([outline.label rangeOfString:searchString options:self.outlineIgnoreCaseFlag?NSCaseInsensitiveSearch:0].location != NSNotFound){
- // return YES;
- // } else {
- // BOOL subHas = NO;
- // for (NSUInteger i = 0; i < outline.numberOfChildren; i ++) {
- // PDFOutline *subOutline = [outline childAtIndex:i];
- // subHas = [self hasContainString:searchString rootOutline:subOutline];
- // if (subHas) {
- // break;
- // }
- // }
- // return subHas;
- // }
- return false
- }
- }
- // MARK: - KMThumbnailTableViewDelegate, NSTableViewDataSource
- extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
- func numberOfRows(in tableView: NSTableView) -> Int {
- if tableView.isEqual(to: self.thumbnailTableView) {
- return self.thumbnails.count
- } else if tableView.isEqual(to: self.findTableView) {
- return self.searchResults.count
- }
- return 0
- }
-
- func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- if tableView.isEqual(to: self.thumbnailTableView) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMThumbnailTableviewCell"), owner: self) as! KMThumbnailTableviewCell
- let thumbnail = self.thumbnails[row]
- cell.pageNumLabel.stringValue = thumbnail.label
- cell.thumImage.image = thumbnail.image
- if let _image = thumbnail.image {
- let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
- let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
- if (_image.size.height > _image.size.width) {
- NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
- cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
- NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
- } else {
- NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
- cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
- NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
- }
- }
- if (self.isDisplayPageSize) {
- cell.sizeLabel.isHidden = false
- //获取Page的真实尺寸
- let page = self.listView.document.page(at: UInt(row))
- let rect = page?.bounds(for: .cropBox) ?? .zero
- let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
- let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
- if let data = page?.rotation, data == 90 || data == 270 {
- cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
- } else {
- cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
- }
- } else {
- cell.sizeLabel.isHidden = true
- }
- cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
- if(self.thumbnailTableView.selectedRowIndexes.contains(row)) {
- cell.isSelectCell = true
- } else {
- cell.isSelectCell = false
- }
- return cell
- } else if (tableView.isEqual(to: self.findTableView)) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMFindTableviewCell"), owner: self) as! KMFindTableviewCell
- let selection = searchResults[row]
- if let data = tableColumn?.identifier.rawValue, data == "results" {
- cell.resultLabel.attributedStringValue = selection.attributedString()
- cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
- } else if let data = tableColumn?.identifier.rawValue, data == "page" {
- cell.resultLabel.stringValue = selection.pages().first?.label ?? ""
- cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
- }
- return cell
- } else if tableView.isEqual(to: self.snapshotTableView) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMSnapshotTableViewCell"), owner: self) as! KMSnapshotTableViewCell
- // SKSnapshotWindowController *snapshot = snapshots[row];
- // cell.snapshotImage.image = snapshot.thumbnail;
- // cell.snapshotLabel.stringValue = snapshot.pageLabel;
- // if (snapshot.hasWindow) {
- // cell.snapshotImageView.hidden = NO;
- // } else {
- // cell.snapshotImageView.hidden = YES;
- // }
- // if(selectCellList.count > 0 && [selectCellList.firstObject integerValue]< 0 && (NSUInteger)row == self.snapshots.count - 1) {
- // cell.isSelectCell = YES;
- // } else {
- // cell.isSelectCell = NO;
- // }
- // for (NSUInteger i = 0; i < selectCellList.count; i ++) {
- // NSInteger selectCell = [selectCellList[i] integerValue];
- // if (selectCell == row) {
- // cell.isSelectCell = YES;
- // }
- // }
- // if (row == tableView.selectedRow) {
- // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowSel]];
- // } else {
- // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowNor]];
- // }
- return cell
- }
- return nil
- }
-
- func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
- if tableView.isEqual(to: self.thumbnailTableView) {
- let scaling = UserDefaults.standard.float(forKey: "KMThumbnailSizeScalingKey")
- let thumbnailSize = self.thumbnails[row].size
-
- let newScaling: CGFloat = scaling.cgFloat + 0.1
- let newThumbnailHeight = thumbnailSize.width * newScaling
- if (newThumbnailHeight > MIN_SIDE_PANE_WIDTH) {
- self.thumbnailZoomOutButton.isEnabled = false
- } else {
- self.thumbnailZoomOutButton.isEnabled = true
- }
- if ((scaling - 0.1) < 0.3) {
- self.thumbnailZoomInButton.isEnabled = false
- } else {
- self.thumbnailZoomInButton.isEnabled = true
- }
- var labelHeight = 0.0
- if (self.isDisplayPageSize) {
- labelHeight = 56.0
- } else {
- labelHeight = 41.5
- }
- let cellHeight = thumbnailSize.height + labelHeight
- var thumbSize: NSSize = .zero
- if (scaling != nil && scaling > 0) {
- thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
- } else {
- thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
- }
- return thumbSize.height
-
- // NSSize cellSize = NSMakeSize([[tv tableColumnWithIdentifier:IMAGE_COLUMNID] width], fmin(thumbSize.height, roundedThumbnailSize));
- // if (thumbSize.height < [tv rowHeight])
- // return [tv rowHeight];
- // else if (thumbSize.width / thumbSize.height < cellSize.width / cellSize.height)
- // return cellSize.height;
- // else
- // return fmax([tv rowHeight], fmin(cellSize.width, thumbSize.width) * thumbSize.height / thumbSize.width);
- } else if tableView.isEqual(to: self.snapshotTableView) {
- let scaling = UserDefaults.standard.float(forKey: "KMSnapshotSizeScalingKey")
- // NSSize snapshotSize = [[[[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row] thumbnail] size];
- let snapshotSize = CGSizeMake(120, 63)
- var newScaling = scaling + 0.1
- let newSnapshotHeight = snapshotSize.width * newScaling.cgFloat;
- if (newSnapshotHeight > MIN_SIDE_PANE_WIDTH) {
- self.snapshotNormalZoomInButton.isEnabled = false
- } else {
- self.snapshotNormalZoomInButton.isEnabled = true
- }
- if ((scaling - 0.1) < 0.3 || (newSnapshotHeight < 150.0)) {
- self.snapshotNormalZoomOutButton.isEnabled = false
- } else {
- self.snapshotNormalZoomOutButton.isEnabled = true
- }
- let cellHeight = snapshotSize.height + 24.0
- var thumbSize: NSSize = .zero
- if (scaling > 0) {
- thumbSize = NSMakeSize(snapshotSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
- } else {
- thumbSize = NSMakeSize(snapshotSize.width, cellHeight)
- }
- return thumbSize.height
- } else if (tableView.isEqual(to: self.findTableView)) {
- return 40.0
- }
- return tableView.rowHeight
- }
-
- func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
- if (tableView.isEqual(to: self.findTableView) || tableView.isEqual(to: self.groupedFindTableView)) {
- let rowView = KMCustomTableRowView()
- return rowView
- }
- return nil
- }
-
- /*
- //- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
- // return nil;
- //}
- - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- NSUInteger idx = [rowIndexes firstIndex];
- if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- NSString *fileExt = nil;
- NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
-
- if ([[pdfView document] allowsPrinting]) {
- NSData *pdfData = [page dataRepresentation];
- fileExt = @"pdf";
- [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePDF, NSPasteboardTypeTIFF,NSFilenamesPboardType, NSFilesPromisePboardType, KPDFThumbnailLocalForDraggedTypes,KPDFThumbnailDoucumentURLForDraggedTypes,nil] owner:self];
- [pboard setData:pdfData forType:NSPasteboardTypePDF];
-
- NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
-
- [pboard setData:zNSIndexSetData forType:KPDFThumbnailLocalForDraggedTypes];
-
- NSData *documentURL = [NSKeyedArchiver archivedDataWithRootObject:[[pdfView document].documentURL absoluteString]];
- NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
- __block NSMutableString *pagesName = nil;
- if (rowIndexes.count > 1) {
- pagesName = [NSMutableString stringWithString:@" pages"];
- } else {
- pagesName = [NSMutableString stringWithString:@" page"];
-
- }
- NSString * tFileName = [NSString stringWithFormat:@"%@ %@",pagesName,[self fileNameWithSelectedPages:rowIndexes]];
- PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- PDFPage *copyPage = [[pdfView.document pageAtIndex:idx] copy];
- [pdf insertPage:copyPage atIndex:pdf.pageCount];
- [copyPage release];
- }];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachesDir = [paths objectAtIndex:0];
- docmentName = [NSString stringWithFormat:@"%@%@",docmentName,tFileName];
- if (docmentName.length > 50) {
- [docmentName substringWithRange:NSMakeRange(0, 50)];
- }
- cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
-
- BOOL success = [pdf writeToFile:cachesDir];
- if (success) {
- [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
- }else{
- [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
- }
- [pboard setData:documentURL forType:KPDFThumbnailDoucumentURLForDraggedTypes];
- } else {
- fileExt = @"tiff";
- [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
- }
- [pboard setData:tiffData forType:NSPasteboardTypeTIFF];
- [pboard setPropertyList:[NSArray arrayWithObject:fileExt] forType:NSFilesPromisePboardType];
- return YES;
- }
- } else if ([tv isEqual:rightSideController.snapshotTableView]) {
- NSUInteger idx = [rowIndexes firstIndex];
- if (idx != NSNotFound) {
- SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
- [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
- [pboard setData:[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] forType:NSPasteboardTypeTIFF];
- [pboard setPropertyList:[NSArray arrayWithObject:@"tiff"] forType:NSFilesPromisePboardType];
- return YES;
- }
- }
- return NO;
- }
- - (NSArray *)tableView:(NSTableView *)tv namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- __block NSMutableArray *fileURLArray = [NSMutableArray array];
- if (rowIndexes.count > 1) {
- NSString *docmentName = @"";
- NSString * tFileName = [NSString stringWithFormat:@"%@",[self fileNameWithSelectedPages:rowIndexes]];
- PDFDocument *pdf = [[[PDFDocument alloc] init] autorelease];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
- PDFPage *copyPage = [[[pdfView document] pageAtIndex:idx] copy];
- [pdf insertPage:copyPage atIndex:pdf.pageCount];
- [copyPage release];
- }
- }];
- NSURL *fileURL = [[[dropDestination URLByAppendingPathComponent:tFileName] URLByAppendingPathExtension:@"pdf"] uniqueFileURL];
- docmentName = fileURL.path;
- BOOL success = [pdf writeToFile:docmentName];
- if(success) {
- [fileURLArray addObject:[fileURL lastPathComponent]];
- }
- } else {
- PDFPage *page = [[pdfView document] pageAtIndex:rowIndexes.firstIndex];
- NSURL *fileURL = [dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
- NSString *pathExt = nil;
- NSData *data = nil;
-
- if ([[pdfView document] allowsPrinting]) {
- pathExt = @"pdf";
- data = [page dataRepresentation];
- } else {
- pathExt = @"tiff";
- data = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
- }
-
- fileURL = [[fileURL URLByAppendingPathExtension:pathExt] uniqueFileURL];
- if ([data writeToURL:fileURL atomically:YES]) {
- [fileURLArray addObject:[fileURL lastPathComponent]];
- }
- }
- return fileURLArray;
- } else if ([tv isEqual:rightSideController.snapshotTableView]) {
- NSUInteger idx = [rowIndexes firstIndex];
- if (idx != NSNotFound) {
- SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
- PDFPage *page = [[pdfView document] pageAtIndex:[snapshot pageIndex]];
- NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]] URLByAppendingPathExtension:@"tiff"];
- fileURL = [fileURL uniqueFileURL];
- if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] writeToURL:fileURL atomically:YES])
- return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
- }
- }
- return [NSArray array];
- }
- - (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors {
- if ([tv isEqual:leftSideController.groupedFindTableView]) {
- [leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
- }
- }
- #pragma mark NSTableView delegate protocol
- - (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
- if ([[aNotification object] isEqual:leftSideController.findTableView] || [[aNotification object] isEqual:leftSideController.groupedFindTableView]) {
- [self updateFindResultHighlightsForDirection:NSDirectSelection];
-
- if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- [self hideLeftSideWindow];
- } else if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
- if (mwcFlags.updatingThumbnailSelection == 0) {
- NSInteger row = [leftSideController.thumbnailTableView selectedRow];
- NSInteger curPage = [pdfView.document indexForPage:pdfView.currentPage];
- if (row != -1 && row != curPage)
- [pdfView goToPage:[[pdfView document] pageAtIndex:row]];
-
- if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- [self hideLeftSideWindow];
-
- thumbnailSelectCount = row;
- NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- for (NSInteger i = 0; i < leftSideController.thumbnailTableView.numberOfRows; i ++) {
- [rowIndexSet addIndex:i];
- }
- NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- [columnIndexSet addIndex:0];
- [leftSideController.thumbnailTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
- }
- } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
- NSInteger row = [rightSideController.snapshotTableView selectedRow];
- [selectCellList removeAllObjects];
- [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
- if (row != -1) {
- SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
- if ([[controller window] isVisible])
- [[controller window] orderFront:self];
- }
- NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
- [rowIndexSet addIndex:i];
- }
- NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- [columnIndexSet addIndex:0];
- [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
-
- }
- }
- - (BOOL)tableView:(NSTableView *)tv commandSelectRow:(NSInteger)row {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- // NSRect rect = [[[pdfView document] pageAtIndex:row] boundsForBox:kPDFDisplayBoxCropBox];
- //
- // rect.origin.y = NSMidY(rect) - 0.5 * SNAPSHOT_HEIGHT;
- // rect.size.height = SNAPSHOT_HEIGHT;
- // [self showSnapshotAtPageNumber:row forRect:rect scaleFactor:[pdfView scaleFactor] autoFits:NO];
- KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
- thumbailTabCell.isSelectCell = YES;
- NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- [rowIndexSet addIndex:idx];
- }];
- [rowIndexSet addIndex:row];
- [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
- return YES;
- }
- return NO;
- }
- - (BOOL)tableView:(NSTableView *)tv shiftSelectRow:(NSInteger)row {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- if(leftSideController.thumbnailTableView.selectedRowIndexes.count == 0) {
- KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
- thumbailTabCell.isSelectCell = YES;
- NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] initWithIndex:row] autorelease];
- [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
- return YES;
- } else if (leftSideController.thumbnailTableView.selectedRowIndexes.count == 1 && leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex == (NSUInteger)row) {
- return NO;
- } else {
- __block NSInteger fristIndex = leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex;
- __block NSInteger lastIndex = leftSideController.thumbnailTableView.selectedRowIndexes.lastIndex;
- [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if(idx < (NSUInteger)fristIndex) {
- fristIndex = idx;
- }
- if(idx > (NSUInteger)lastIndex) {
- lastIndex = idx;
- }
- }];
-
- if(row < fristIndex) {
- fristIndex = row;
- } else if (row > lastIndex) {
- lastIndex = row;
- }
- NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- for (NSInteger i = fristIndex; i<=lastIndex;i++) {
- [rowIndexSet addIndex:i];
- }
- [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
- return YES;
- }
- }
- return NO;
- }
- - (void)tableViewColumnDidResize:(NSNotification *)aNotification {
- if ([[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:IMAGE_COLUMNID]) {
- if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
- [leftSideController.thumbnailTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [leftSideController.thumbnailTableView numberOfRows])]];
- } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
- [rightSideController.snapshotTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.snapshotTableView numberOfRows])]];
- }
- }
- }
- - (void)tableView:(NSTableView *)tv deleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- return;
- }
- if ([tv isEqual:rightSideController.snapshotTableView]) {
- NSArray *controllers = [[rightSideController.snapshotArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
- [controllers makeObjectsPerformSelector:@selector(close)];
- } else if ([tv isEqual:leftSideController.thumbnailTableView]) {
- [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx >= [[pdfView document] pageCount]) {
- return;
- }
- for (PDFAnnotation *item in [[[pdfView document] pageAtIndex:idx] notes]){
- [pdfView removeAnnotation:item];
- }
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- [[[[self document] undoManager] prepareWithInvocationTarget:self] insertPage:page pageAtIndex:idx];
- [[pdfView document] removePageAtIndex:idx];
-
- }];
- [pdfView layoutDocumentView];
- [pageLabels setArray:[[pdfView document] pageLabels]];
- [self resetThumbnails];
- NSUInteger idx = [rowIndexes firstIndex];
- NSInteger index = MIN(idx, [[pdfView document] pageCount]-1);
- [pdfView goToPage:[[pdfView document] pageAtIndex:index]];
- }
- }
- - (void)insertPage:(PDFPage*)page pageAtIndex:(NSInteger)index {
- [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
- [[pdfView document] insertPage:page atIndex:index];
- [pdfView layoutDocumentView];
- [pageLabels setArray:[[pdfView document] pageLabels]];
- [self resetThumbnails];
- NSInteger pageIndex = MIN((NSUInteger)index, [[pdfView document] pageCount]-1);
- [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
- }
- - (BOOL)tableView:(NSTableView *)tv canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:rightSideController.snapshotTableView]) {
- return [rowIndexes count] > 0;
- } else if ([tv isEqual:leftSideController.thumbnailTableView]){
- if (self.pdfDocument.pageCount <= 1) {
- return NO;
- }
- return YES;
- }
- return NO;
- }
- - (void)tableView:(NSTableView *)tv copyRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- return;
- }
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- self.copysPages = [NSMutableArray array];
- if ([[pdfView document] isLocked] == NO) {
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- [self.copysPages addObject:page];
- }];
- // NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
- // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- // NSPasteboardItem *pboardItem = [[[NSPasteboardItem alloc] init] autorelease];
- // if ([[pdfView document] allowsPrinting])
- // [pboardItem setData:[page dataRepresentation] forType:NSPasteboardTypePDF];
- // [pboardItem setData:tiffData forType:NSPasteboardTypeTIFF];
- // [pboard clearContents];
- // [pboard writeObjects:[NSArray arrayWithObjects:pboardItem, nil]];
- }
- } else if ([tv isEqual:leftSideController.findTableView]) {
- NSMutableString *string = [NSMutableString string];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- PDFSelection *match = [searchResults objectAtIndex:idx];
- [string appendString:@"* "];
- [string appendFormat:NSLocalizedString(@"Page %@", @""), [match firstPageLabel]];
- [string appendFormat:@": %@\n", [[match contextString] string]];
- }];
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- [pboard clearContents];
- [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
- } else if ([tv isEqual:leftSideController.groupedFindTableView]) {
- NSMutableString *string = [NSMutableString string];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- SKGroupedSearchResult *result = [groupedSearchResults objectAtIndex:idx];
- NSArray *matches = [result matches];
- [string appendString:@"* "];
- [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result page] displayLabel]];
- [string appendString:@": "];
- [string appendFormat:NSLocalizedString(@"%ld Results", @""), (long)[matches count]];
- [string appendFormat:@":\n\t%@\n", [[matches valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
- }];
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- [pboard clearContents];
- [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
- }
- }
- - (BOOL)tableView:(NSTableView *)tv canCopyRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView] || [tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView]) {
- return [rowIndexes count] > 0;
- }
- return NO;
- }
- - (void)tableView:(NSTableView *)tv cutRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- self.copysPages = [NSMutableArray array];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx != NSNotFound) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- [self.copysPages addObject:page];;
- }
- }];
- [self tableView:tv deleteRowsWithIndexes:rowIndexes];
- }
- }
- - (void)tableView:(NSTableView *)tv rotateRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx != NSNotFound) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- [[[[self document] undoManager] prepareWithInvocationTarget:self] rotatePage:page pageAtIndex:idx];
- if (page.rotation == 0) {
- [page setRotation:90];
- } else if (page.rotation == 90){
- [page setRotation:180];
- } else if (page.rotation == 180){
- [page setRotation:270];
- } else if (page.rotation == 270){
- [page setRotation:0];
- }
- [pdfView layoutDocumentView];
- [self resetThumbnails];
- NSInteger pageIndex = MIN(idx, [[pdfView document] pageCount]-1);
- [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
- }
- [leftSideController.thumbnailTableView selectRowIndexes:rowIndexes byExtendingSelection:YES];
- }];
- }
- }
- - (void)rotatePage:(PDFPage*)page pageAtIndex:(NSInteger)index {
- [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView rotateRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
- if (page.rotation == 0) {
- [page setRotation:270];
- } else if (page.rotation == 90){
- [page setRotation:0];
- } else if (page.rotation == 180){
- [page setRotation:90];
- } else if (page.rotation == 270){
- [page setRotation:180];
- }
- [pdfView layoutDocumentView];
- [self resetThumbnails];
- }
- - (void)tableView:(NSTableView *)tv shareRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- NSUInteger idx = [rowIndexes firstIndex];
- if (idx != NSNotFound) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- NSString *fileName = [[[pdfView document] documentURL] lastPathComponent];
- NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
- NSString *filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Untitled"]];
- filePath = [filePath stringByAppendingPathExtension:[fileName pathExtension]];
-
- [self fileWithPage:page atPath:filePath];
-
- if (rint(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
- [KMMailHelper sendFileWithPaths:[NSArray arrayWithObject:filePath]];
- } else {
- NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
- [service performWithItems:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]]];
- }
- }
- }
- }
- - (void)tableView:(NSTableView *)tv extractRowsWithIndexes:(NSIndexSet *)rowIndexes {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- NSMutableArray *pages = [NSMutableArray array];
- [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx < self.pdfView.document.pageCount) {
- [pages addObject:[self.pdfView.document pageAtIndex:idx]];
- }
- }];
- NSString * fileName = [self.pdfView.document getFileNameAccordingSelctPages:pages];
- KMSavePanelAccessoryController *saveAccessCtr = [[KMSavePanelAccessoryController alloc] init];
- NSSavePanel * outputSavePanel = [NSSavePanel savePanel];
- [outputSavePanel setAllowedFileTypes:[NSArray arrayWithObject:@"pdf"]];
- outputSavePanel.accessoryView = saveAccessCtr.view;
- [outputSavePanel setNameFieldStringValue:fileName];
- [outputSavePanel beginSheetModalForWindow:[self window]completionHandler:^(NSInteger result) {
- if (result == NSModalResponseOK) {
- [saveAccessCtr retain];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- KMProgressWindowController * vc = [[[KMProgressWindowController alloc] init] autorelease];
- // [NSApp beginSheet:[vc window]
- // modalForWindow:self.window
- // modalDelegate:nil
- // didEndSelector:nil
- // contextInfo:NULL];
- [self.window beginSheet:[vc window] completionHandler:^(NSModalResponse returnCode) {
-
- }];
- NSString *saveFilePath = [[outputSavePanel URL] path];
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
- BOOL success = [pdf extractAsOneDocumentWithPages:pages savePath:saveFilePath];
- dispatch_async(dispatch_get_main_queue(), ^{
- if (success) {
- if (saveAccessCtr.openAutomaticButton.state == NSControlStateValueOn) {
- [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:[outputSavePanel URL] display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
- }];
- } else {
- NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
- NSURL *url = [NSURL fileURLWithPath:saveFilePath];
- [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
- }
- }
- [NSApp endSheet:vc.window];
- [vc close];
- [saveAccessCtr release];
- });
- });
- });
- }
- [saveAccessCtr release];
- }];
- }
- }
- - (void)fileWithPage:(PDFPage *)page atPath:(NSString *)filePath {
- NSData *data = [page dataRepresentation];
- PDFDocument *document = [[PDFDocument alloc] initWithData:data];
-
- [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
- BOOL success = [document writeToURL:[NSURL fileURLWithPath:filePath]];
- if (success) {
- NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
- NSURL *url = [NSURL fileURLWithPath:filePath];
- [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
- }
-
- [document release];
- }
- - (BOOL)tableView:(NSTableView *)aTableView canPasteFromPasteboard:(NSPasteboard *)pboard
- {
- if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
- if(self.copysPages.count > 0){
- return YES;
- }
- }
- return NO;
- }
- - (void)tableView:(NSTableView *)aTableView pasteFromPasteboard:(NSPasteboard *)pboard
- {
- if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- return;
- }
- if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
- if (self.copysPages.count > 0) {
- NSUInteger index = [[pdfView document] indexForPage:[pdfView currentPage]] + 1;
- if (index == NSNotFound) {
- return;
- }
- [self.copysPages enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(PDFPage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- PDFPage *page = [obj copy];
- [[pdfView document] insertPage:page atIndex:index];
- [page release];
- [pdfView layoutDocumentView];
- [pageLabels setArray:[[pdfView document] pageLabels]];
- [self resetThumbnails];
- NSInteger pageIndex = MIN(index, [[pdfView document] pageCount]-1);
- [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
- [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
- }];
- }
- }
- }
- - (NSUInteger)tableView:(NSTableView *)tv highlightLevelForRow:(NSInteger)row {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- NSUInteger i, iMax = [lastViewedPages count];
- for (i = 0; i < iMax; i++) {
- if (row == (NSInteger)[lastViewedPages pointerAtIndex:i])
- return i;
- }
- }
- return NSNotFound;
- }
- - (void)tableViewMoveLeft:(NSTableView *)tv {
- if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
- [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
- }
- }
- - (void)tableViewMoveRight:(NSTableView *)tv {
- if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
- [self updateFindResultHighlightsForDirection:NSSelectingNext];
- }
- }
- - (id <SKImageToolTipContext>)tableView:(NSTableView *)tv imageContextForRow:(NSInteger)row {
- if ([tv isEqual:leftSideController.findTableView])
- return [[[leftSideController.findArrayController arrangedObjects] objectAtIndex:row] destination];
- else if ([tv isEqual:leftSideController.groupedFindTableView])
- return [[[[[leftSideController.groupedFindArrayController arrangedObjects] objectAtIndex:row] matches] objectAtIndex:0] destination];
- return nil;
- }
- - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- return pageLabels;
- }
- return nil;
- }
- - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- }
- }
- - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- if (searchString.length > 0)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- }
- }
- #pragma mark dragging
- - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
- {
- if (dropOperation == NSTableViewDropOn || ![tableView isEqual:leftSideController.thumbnailTableView]) {
- return NSDragOperationNone;
- }
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
- return NSDragOperationMove;
- } else if ([pboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]){
- NSArray *fileNames = [pboard propertyListForType:NSFilenamesPboardType];
- if (fileNames.count == 1) {
- NSString *path = fileNames.firstObject;
- NSString *pathExtension = [path.pathExtension lowercaseString];
- if ([pathExtension isEqualToString:@"pdf"] ||
- [[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
- return NSDragOperationMove;
- }
- } else {
- return NSDragOperationNone;
-
- }
- }
- return NSDragOperationNone;
- }
- - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {
- __block BOOL result = NO;
- if (![tableView isEqual:leftSideController.thumbnailTableView]) {
- return result;
- }
- NSPasteboard *pasteboard = [info draggingPasteboard];
-
- if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
- result = YES;
- NSData *rowData = [pasteboard dataForType:KPDFThumbnailLocalForDraggedTypes];
- NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
- NSData *urlData = [pasteboard dataForType:KPDFThumbnailDoucumentURLForDraggedTypes];
- NSString *url = [NSKeyedUnarchiver unarchiveObjectWithData:urlData];
- if(![url isEqualToString:[pdfView document].documentURL.absoluteString] && url) {
- if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
- NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
- if (fileNames.count == 1) {
- NSString *path = fileNames.firstObject;
- NSString *pathExtension = [path.pathExtension lowercaseString];
- if ([pathExtension isEqualToString:@"pdf"]) {
- __block NSInteger index = row;
- __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]] autorelease];
- if ([pdf isEncrypted]) {
- KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
- vc.filePath = url;
- [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
- if (password) {
- [pdf unlockWithPassword:password];
- for(NSUInteger i=0; i<pdf.pageCount;i++) {
- PDFPage *page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- }];
- [vc release];
- } else {
- for(NSUInteger i=0; i<pdf.pageCount;i++) {
- PDFPage *page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- return YES;
- }
- }
- }
- }
- __block NSInteger pageIndex = 0;
- __block NSMutableArray *pages = [NSMutableArray array];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- PDFPage *page = [[[pdfView document] pageAtIndex:idx] copy];
- [pages addObject:page];
- [page release];
- }];
- PDFPage *toPage = nil;
- if (row < (NSInteger)pdfView.document.pageCount) {
- toPage = [pdfView.document pageAtIndex:row];
- }
- __block NSInteger toPageIndex = 0;
- if (toPage) {
- toPageIndex = [pdfView.document indexForPage:toPage];
- } else {
- toPageIndex = pdfView.document.pageCount;
- }
- for(NSUInteger i = 0;i<pages.count;i++) {
- PDFPage *page = pages[i];
- [pdfView.document insertPage:page atIndex:toPageIndex+i];
- pageIndex += 1;
- [self.pdfView goToPage:page];
- }
- [self.pdfView layoutDocumentView];
- __block NSMutableArray *deletepages = [NSMutableArray array];
- [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if((NSInteger)idx < toPageIndex) {
- if((idx+pageIndex) < pdfView.document.pageCount) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- [deletepages addObject:page];
- [pdfView.document removePageAtIndex:idx];
- }
- } else {
- if((idx+pageIndex) < pdfView.document.pageCount) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx+pageIndex];
- [deletepages addObject:page];
- [pdfView.document removePageAtIndex:idx+pageIndex];
- }
- }
- }];
- [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
- [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
- [self.pdfView layoutDocumentView];
- [self resetThumbnails];
-
- } else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
- if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- return NO;
- }
-
- NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
- NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- __block NSInteger index = row;
- if (fileNames.count == 1) {
- NSString *path = fileNames.firstObject;
- NSString *pathExtension = [path.pathExtension lowercaseString];
- if ([pathExtension isEqualToString:@"pdf"]) {
- PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
- if ([pdf isEncrypted]) {
- KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
- vc.filePath = path;
- [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
- if (password) {
- [pdf unlockWithPassword:password];
- for (NSUInteger i = 0; i< pdf.pageCount; i++) {
- PDFPage *page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- }];
- [vc release];
- } else {
- for (NSUInteger i = 0; i < pdf.pageCount; i++) {
- PDFPage * page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
-
- }
- } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
- NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
- PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
- [pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- result = YES;
- } else {
- result = NO;
- }
- }
- return result;
- }
- */
- }
- // MARK: - NSOutlineViewDelegate, NSOutlineViewDataSource
- /*
-
- func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
- if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?[index] as Any
- } else if item is KMBOTAAnnotationItem {
- return item as Any
- } else {
- var tempArray: [KMBOTAAnnotationSection] = []
- for temp in self.data {
- if temp.annotations?.count != 0 {
- tempArray.append(temp)
- }
- }
- let section = tempArray[index]
- return section as Any
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
- if item is KMBOTAAnnotationItem {
- let cell : KMAnnotationOutlineCellView = KMAnnotationOutlineCellView.init()
- cell.delegate = self
- cell.model = item as? KMBOTAAnnotationItem
- return cell
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
-
- let cell : KMAnnotationOutlineSectionView = KMAnnotationOutlineSectionView.init()
- cell.model = section
- return cell
- }
- return NSTableCellView()
- }
-
- func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
- let rowView = KMAnnotationOutlineRowView()
- if item is KMBOTAAnnotationItem {
- rowView.model = (item as? KMBOTAAnnotationItem)
- } else if item is KMBOTAAnnotationSection {
- rowView.section = (item as? KMBOTAAnnotationSection)
- }
- rowView.mouseDownAction = { [unowned self] view, event in
- if rowView.section != nil {
- let expanded = outlineView.isItemExpanded(outlineView.item(atRow: outlineView.selectedRow))
- if expanded {
- outlineView.collapseItem(outlineView.item(atRow: outlineView.selectedRow), collapseChildren: true)
- outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
- } else {
- outlineView.expandItem(outlineView.item(atRow: outlineView.selectedRow), expandChildren: true)
- outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
- }
- } else if rowView.model != nil {
- self.didSelectItem(view: rowView, event: event)
- }
- }
-
- rowView.rightMouseDownAction = { [unowned self] view, event in
- if rowView.section != nil {
-
- } else if rowView.model != nil {
- if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
- self.selectItems.count == 1 {
- self.selectItem(item: item as! KMBOTAAnnotationItem)
- }
-
- DispatchQueue.main.async {
- self.delegate?.annotationOutlineView(self, rightMouseDownDidSelectView: view, evnet: event)
- }
- }
- }
-
- rowView.hoverCallback = { [unowned self] (mouseEntered, mouseBox) in
- self.outlineView.enumerateAvailableRowViews { view, row in
- if view is KMAnnotationOutlineRowView {
- (view as? KMAnnotationOutlineRowView)?.model?.hover = false
- (view as? KMAnnotationOutlineRowView)?.reloadData()
- }
- }
- if mouseEntered {
- rowView.model?.hover = true
- } else {
- rowView.model?.hover = false
- }
- }
- return rowView
- }
-
- func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
- if item is KMBOTAAnnotationItem {
- return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: self.maxWidth - 16, height: 1000))
- } else if item is KMBOTAAnnotationSection {
- return 40
- } else {
- return 30
- }
- }
-
- func outlineViewSelectionDidChange(_ notification: Notification) {
- if self.outlineView.selectedRow == -1 {
- self.cancelSelect()
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
- if item is KMBOTAAnnotationItem {
- return false
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?.count ?? 0 > 0
- }
- return false
- }
-
- func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
- if let item = item as? KMBOTAAnnotationSection {
- if !item.isItemExpanded {
- item.isItemExpanded = true
- outlineView.animator().expandItem(item, expandChildren: true)
- return false
- }
- }
- return true
- }
- func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool {
- if let item = item as? KMBOTAAnnotationSection {
- if item.isItemExpanded {
- item.isItemExpanded = false
- outlineView.animator().collapseItem(item, collapseChildren: true)
- return false
- }
- }
- return true
- }
- */
- extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSource {
- func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
- if outlineView.isEqual(to: self.tocOutlineView) {
- if item == nil && self.listView.document.isLocked == false {
- // if (item == nil && [[pdfView document] isLocked] == NO) {
- // item = [[pdfView document] outlineRoot];
- var item = self.listView.document.outlineRoot()
- if let data = item?.numberOfChildren, data == 0 && !self.isSearchOutlineMode {
- let view = self.tocOutlineView.enclosingScrollView
- // CGSize emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size;
-
- // self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
-
- // self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin| NSViewMaxYMargin | NSViewMinYMargin;
- // [leftSideController.tocOutlineView.enclosingScrollView.documentView addSubview:self.leftSideEmptyVC.emptyOutlineView];
- // self.leftSideEmptyVC.deleteOutlineBtn.enabled = NO;
- } else {
- // [self.leftSideEmptyVC.emptyOutlineView removeFromSuperview];
- // self.leftSideEmptyVC.deleteOutlineBtn.enabled = YES;
- }
- // PDFOutline *item = [[pdfView document] outlineRoot];
- if let data = item?.numberOfChildren, data > 0 {
- self.outlineSearchButton.isEnabled = true
- } else {
- self.outlineSearchButton.isEnabled = false
- }
-
- if (self.isSearchOutlineMode) {
- if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: item!) {
- // [self showSearchOutlineBlankState:NO];
- } else {
- // [self showSearchOutlineBlankState:YES];
- }
- }
- return Int(item?.numberOfChildren ?? 0)
- }
- if (self.isSearchOutlineMode) {
- // var num = 0
- // for (NSUInteger i = 0; i < [(PDFOutline *)item numberOfChildren]; i++) {
- // PDFOutline *outline = [(PDFOutline *)item childAtIndex:i];
- // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:outline]) {
- // num ++;
- // }
- // }
- // return num;
- } else {
- // return [(PDFOutline *)item numberOfChildren];
- }
- return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- // if (item == nil){
- // NSInteger count = [[rightSideController.noteArrayController arrangedObjects] count];
- // if (count < 1) {
- // if (notes.count < 1) {
- // leftSideController.noteSearchButton.enabled = NO;
- // leftSideController.noteFilterButton.enabled = NO;
- // }
- //
- // rightSideController.noteOutlineView.usesAlternatingRowBackgroundColors = NO;
- // NSView *view = rightSideController.noteOutlineView.enclosingScrollView;
- // CGSize emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size;
- // self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
- // self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin | NSViewMaxYMargin | NSViewMinYMargin;
- // [rightSideController.noteOutlineView.enclosingScrollView.documentView addSubview:self.leftSideEmptyVC.emptyAnnotationView];
- // self.leftSideEmptyVC.exportAnnotationBtn.enabled = NO;
- // self.leftSideEmptyVC.deleteAnnotationBtn.enabled = NO;
- //
- // if (leftSideController.segmentedControl.selectedSegment == KMSelectedSegmentType_Annotation) {
- // leftSideController.noteHeaderView.hidden = YES;
- // leftSideController.toolButtonBoxLayoutConstraint.constant = 40.0;
- // }
- // } else {
- // leftSideController.noteSearchButton.enabled = YES;
- // leftSideController.noteFilterButton.enabled = YES;
- //
- // rightSideController.noteOutlineView.usesAlternatingRowBackgroundColors = NO;
- //
- // [self.leftSideEmptyVC.emptyAnnotationView removeFromSuperview];
- // self.leftSideEmptyVC.exportAnnotationBtn.enabled = YES;
- // self.leftSideEmptyVC.deleteAnnotationBtn.enabled = YES;
- //
- // if (leftSideController.segmentedControl.selectedSegment == KMSelectedSegmentType_Annotation) {
- // leftSideController.noteHeaderView.hidden = NO;
- // leftSideController.toolButtonBoxLayoutConstraint.constant = 64.0;
- // }
- // }
- // return count;
- // } else {
- // return [item hasNoteText];
- // }
- if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?.count ?? 0
- } else if item is KMBOTAAnnotationItem {
- return 1
- } else {
- var count = 0
- for section in self.annotationViewController.annotations {
- if section.annotations?.count != 0 {
- count += 1
- }
- }
- return count
- }
- }
- return 0
- }
-
- // child
- func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
- if outlineView.isEqual(to: self.tocOutlineView) {
- var _item: CPDFOutline?
- if item == nil && self.listView.document.isLocked == false {
- _item = self.listView.document.outlineRoot()
- }
- var obj = _item?.child(at: UInt(index))
- // if (self.isSearchOutlineMode) {
- // NSMutableArray *array = [NSMutableArray array];
- // for (NSUInteger i = 0; i < [(PDFOutline *)item numberOfChildren]; i ++) {
- // PDFOutline *subOutline = [(PDFOutline *)item childAtIndex:i];
- // if ([self hasContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:subOutline]) {
- // [array addObject:subOutline];
- // }
- // }
- // return [array objectAtIndex:anIndex];
- // } else {
- // return obj;
- // }
- return obj as Any
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- // if (item == nil)
- // {
- // return [[rightSideController.noteArrayController arrangedObjects] objectAtIndex:anIndex];
- // // return [self.notes objectAtIndex:anIndex];
- // }
- // else
- // return [item noteText];
- if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?[index] as Any
- } else if item is KMBOTAAnnotationItem {
- return item as Any
- } else {
- var tempArray: [KMBOTAAnnotationSection] = []
- for temp in self.annotationViewController.annotations {
- if temp.annotations?.count != 0 {
- tempArray.append(temp)
- }
- }
- let section = tempArray[index]
- return section as Any
- }
- }
- return item
- }
-
- func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let tcID = tableColumn?.identifier.rawValue ?? ""
- var ol = item as? CPDFOutline
- if(tcID == LABEL_COLUMNID) {
- if (self.isSearchOutlineMode) {
- // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- // NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
- // NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
- // for (NSUInteger i = 0; i <arr.count ; i++) {
- // NSValue * rangeValue = arr[i];
- // NSRange range = rangeValue.rangeValue;
- // range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
- // [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
- // }
- // [attributeString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:NSMakeRange(0, roughString.length)];
- // return attributeString;
- } else {
- var attributedString = NSMutableAttributedString()
- // attributedString
- attributedString.append(.init(string: ol?.label ?? "", attributes: [.foregroundColor : KMAppearance.Layout.h0Color()]))
- // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- // [attributedString appendAttributedString:attr1];
- return attributedString
- }
- }
- // else if([tcID isEqualToString:PAGE_COLUMNID]) {
- // NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- // NSString *roughString = [ol pageLabel]? : @"";
- // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- // [attributedString appendAttributedString:attr1];
- //
- // return attributedString;
- // }
-
- }
- // else if ([ov isEqual:rightSideController.noteOutlineView]) {
- // NSString *tcID = [tableColumn identifier];
- // PDFAnnotation *note = item;
- // if (tableColumn == nil || [tcID isEqualToString:NOTE_COLUMNID])
- // return [note objectValue];
- // else if([tcID isEqualToString:TYPE_COLUMNID]){
- // NSString *noteType = [note type];
- // if ([note isKindOfClass:[PDFAnnotationButtonWidget class]]) {
- // PDFAnnotationButtonWidget *buttonWidget = (PDFAnnotationButtonWidget *)note;
- // if (buttonWidget.controlType == kPDFWidgetRadioButtonControl) {
- // noteType = SKAnnotationFormRadioButtonKey;
- // } else if (buttonWidget.controlType == kPDFWidgetCheckBoxControl){
- // noteType = SKAnnotationFormCheckBoxKey;
- // } else if (buttonWidget.controlType == kPDFWidgetPushButtonControl){
- // noteType = SKAnnotationFormActionButtonKey;
- // }
- // } else if ([note isKindOfClass:[PDFAnnotationTextWidget class]]){
- // noteType = SKAnnotationFormTextFieldKey;
- // } else if ([note isKindOfClass:[PDFAnnotationChoiceWidget class]]){
- // PDFAnnotationChoiceWidget *choiceWidget = (PDFAnnotationChoiceWidget *)note;
- // if (choiceWidget.isListChoice) {
- // noteType = SKAnnotationFormListMenuKey;
- // } else {
- // noteType = SKAnnotationFormComboBoxKey;
- // }
- //
- // }
- // return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:note == [pdfView activeAnnotation]], SKAnnotationTypeImageCellActiveKey, noteType, SKAnnotationTypeImageCellTypeKey,[note color],SKAnnotationTypeImageCellColorKey, nil];
- // }
- // else if([tcID isEqualToString:COLOR_COLUMNID])
- // return [note type] ? [note color] : nil;
- // else if([tcID isEqualToString:PAGE_COLUMNID])
- // return [[note page] displayLabel];
- // else if([tcID isEqualToString:AUTHOR_COLUMNID])
- // return [note type] ? [note userName] : nil;
- // else if([tcID isEqualToString:DATE_COLUMNID])
- // return [note type] ? [note modificationDate] : nil;
- // }
- return nil
- }
-
- func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMTocTableCellView"), owner: self) as! KMTocTableCellView
- let tcID = tableColumn?.identifier.rawValue
- var ol = item as? CPDFOutline
- if tcID == LABEL_COLUMNID {
- if (self.isSearchOutlineMode) {
- // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
- // NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
- // NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
- //
- // for (NSUInteger i = 0; i <arr.count ; i++) {
- // NSValue * rangeValue = arr[i];
- // NSRange range = rangeValue.rangeValue;
- // range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
- // [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
- // }
- // cell.tocLabel.attributedStringValue = attributeString;
- } else {
- cell.tocLabel.stringValue = ol?.label ?? ""
- }
- // cell.pageLabel.stringValue = [ol pageLabel]?[ol pageLabel]:@"";
- }
- // else if([tcID isEqualToString:PAGE_COLUMNID]) {
- // cell.pageLabel.stringValue = [ol pageLabel];
- // }
- return cell
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- if item is KMBOTAAnnotationItem {
- // let cell : KMAnnotationOutlineCellView = KMAnnotationOutlineCellView.init()
- // cell.delegate = self
- // cell.model = item as? KMBOTAAnnotationItem
- // return cell
- } else if item is KMBOTAAnnotationSection {
- // let section = item as? KMBOTAAnnotationSection
- //
- // let cell : KMAnnotationOutlineSectionView = KMAnnotationOutlineSectionView.init()
- // cell.model = section
- // return cell
- return nil
- }
- // return NSTableCellView()
-
- let note = (item as! KMBOTAAnnotationItem).annotation!
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteTableViewCell"), owner: self) as! KMNoteTableViewCell
- cell.cellNote = note
-
- let noteColor = note.color
- var noteType = note.type ?? ""
- var noteString = note.string() ?? ""
- // NSString *pageString = [[note page] displayLabel] ? : @"";
- var pageString = note.page.label ?? ""
- let date = note.modificationDate()
- var authorString = note.userName() ?? ""
- // NSString *noteTextString = [note noteText].string ? : @"";
- var noteTextString = note.string() ?? ""
- //
- // if([noteType isEqualToString:@"Redact"]) {
-
- // noteString = @"Redact";
- // }
- //
- let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool
- if timeKey == nil || timeKey == false {
- if (date != nil) {
- cell.timeLabel.stringValue = CPDFAnnotationModel.timeString(withTime: date)
-
- } else {
- cell.timeLabel.stringValue = "kkkkkkkkk"
- }
- cell.timeLabel.isHidden = false
- } else {
- cell.timeLabel.isHidden = true
- }
-
- let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool
- if pageKey == nil || pageKey == false {
- let labelsize = cell.pageLabel.stringValue.boundingRect(with: CGSizeMake(CGFloat(MAXFLOAT),CGRectGetHeight(cell.pageLabel.bounds)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font : NSFont.systemFont(ofSize: 12)])
- cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5
- cell.pageLabel.stringValue = pageString
- cell.pageLabel.isHidden = false
- } else {
- cell.pageLabel.isHidden = true
- }
-
- let autherKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool
- if pageKey == nil || pageKey == false {
- cell.autherLabel.stringValue = authorString
- cell.autherLabel.isHidden = false
- } else {
- cell.autherLabel.isHidden = true
- }
- let imageView = KMNoteTypeImageView()
- if note.isKind(of: CPDFStampAnnotation.self) {
- let annotation_stamp = note as! CPDFStampAnnotation
- if (annotation_stamp.stampImage() != nil) {
- noteType = SKNStampString
- }
- } else if note.isKind(of: CPDFLineAnnotation.self) {
- let annotation_line = note as! CPDFLineAnnotation
- if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .none {
- noteType = SKNLine_NoneString
- } else if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .openArrow {
- noteType = SKNLine_OpenArrowString
- } else {
- noteType = SKNLine_NoneString
- }
- } else if note.isKind(of: CPDFButtonWidgetAnnotation.self) {
- let buttonWidget = note as! CPDFButtonWidgetAnnotation
- if buttonWidget.controlType() == .radioButtonControl {
- noteType = KMAnnotationFormRadioButtonKey
- } else if buttonWidget.controlType() == .checkBoxControl {
- noteType = KMAnnotationFormCheckBoxKey
- } else if buttonWidget.controlType() == .pushButtonControl {
- noteType = KMAnnotationFormActionButtonKey
- }
- } else if note.isKind(of: CPDFTextWidgetAnnotation.self) {
- noteType = KMAnnotationFormTextFieldKey
- } else if note.isKind(of: CPDFChoiceWidgetAnnotation.self) {
- let choiceWidget = note as! CPDFChoiceWidgetAnnotation
- if choiceWidget.isListChoice {
- noteType = KMAnnotationFormListMenuKey
- } else {
- noteType = KMAnnotationFormComboBoxKey
- }
- } else if note.isKind(of: KMTableAnnotation.self) {
- noteType = "Ink_Table"
- } else if note.isKind(of: KMSelfSignAnnotation.self) {
- let selfSignNote = note as! KMSelfSignAnnotation
- if selfSignNote.annotationType == .signFalse {
- noteType = "KMSelfSignTypeFalseActionButtonKey"
- } else if (selfSignNote.annotationType == .signature) {
- noteType = "KMSelfSignTypeTureActionButtonKey"
- } else if (selfSignNote.annotationType == .signCircle) {
- noteType = "KMSelfSignTypeCircleActionButtonKey"
- } else if (selfSignNote.annotationType == .signLine) {
- noteType = "KMSelfSignTypeLineActionButtonKey"
- } else if (selfSignNote.annotationType == .signDot) {
- noteType = "KMSelfSignTypeDotActionButtonKey"
- } else if (selfSignNote.annotationType == .signText) {
- noteType = "KMSelfSignTypeTextActionButtonKey"
- }
- } else if note.isKind(of: CPDFSquareAnnotation.self) {
- noteType = SKNSquareString
- } else if note.isKind(of: CPDFTextAnnotation.self) {
- let newAnnotation = note as! CPDFTextAnnotation
- if newAnnotation.iconType() == .note {
-
- }
- noteType = SKNNoteString
- }
-
- cell.typeImageView.image = imageView.noteTypeImage(withType: noteType, color: noteColor ?? .red)
- // cell.typeImageView.image = [imageView noteTypeImageWithType:noteType Color:noteColor];
- cell.typeImageView.isHidden = false
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- cell.isFold = true
- }
- cell.noteContentBox.isHidden = true
- cell.noteImageView.isHidden = true
- cell.foldButton.isHidden = true
- cell.annotationContentLabel.isHidden = false
- cell.noteContentLabel.stringValue = noteString
- cell.contentView.isHidden = false
- cell.contentViewHidden(false)
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- let markup = note as! CPDFMarkupAnnotation
- if(noteTextString.isEmpty == false) {
- cell.foldButton.isHidden = false
- }
- var attributeStr = NSMutableAttributedString(string: noteTextString)
- if (markup.markupType() == .highlight) {
- attributeStr.addAttribute(.backgroundColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
- } else if (markup.markupType() == .strikeOut) {
- attributeStr.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
- attributeStr.addAttribute(.strikethroughColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
- } else if (markup.markupType() == .underline) {
- attributeStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
- attributeStr.addAttribute(.underlineColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
- }
- cell.annotationContentLabel.attributedStringValue = attributeStr
- if (self.foldType == .unfold) {
- cell.isFold = false
- } else if (self.foldType == .fold) {
- cell.isFold = true
- } else {
- // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
- // cell.isFold = NO;
- // } else {
- // cell.isFold = YES;
- // }
- }
- if (noteString.isEmpty == false && noteTextString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- } else if note.isKind(of: CPDFLineAnnotation.self) || noteType == SKNSquareString || noteType == SKNCircleString || noteType == SKNInkString {
- cell.annotationContentLabel.stringValue = noteString
- if (noteString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- } else if note.isKind(of: CPDFStampAnnotation.self) {
- if note.isKind(of: KMSelfSignAnnotation.self) {
- let newAnnotation = note as! KMSelfSignAnnotation
- let type = newAnnotation.annotationType
- var returnString = ""
- if (type == .signFalse) {
- returnString = KMLocalizedString("X", nil)
- } else if (type == .signature) {
- returnString = KMLocalizedString("Check mark", nil)
- } else if (type == .signCircle) {
- returnString = KMLocalizedString("Circle", nil)
- } else if (type == .signLine) {
- returnString = KMLocalizedString("Line", nil)
- } else if (type == .signDot) {
- returnString = KMLocalizedString("Dot", nil)
- } else if (type == .signText) {
- returnString = KMLocalizedString("Text", nil)
- }
- cell.annotationContentLabel.stringValue = returnString
- } else {
- cell.annotationContentLabel.isHidden = true
- cell.noteImageView.isHidden = false
- // PDFAnnotation *annotation = note;
- // NSImage *stampImage = [self stampCreateImage:annotation];
- // if (stampImage) {
- // cell.noteImageView.image = [self stampCreateImage:annotation];
- // } else {
- // cell.noteImageView.hidden = YES;
- // [cell contentViewHidden:YES];
- // }
- }
- }
- // else if ([note isKindOfClass:[SKNPDFAnnotationNote class]]) {
- // cell.foldButton.hidden = NO;
- // if (!noteString || noteString.length < 1){
- // cell.annotationContentLabel.stringValue = noteTextString;
- // }else{
- // cell.annotationContentLabel.stringValue = noteString;
- // cell.noteContentLabel.stringValue = noteTextString;
- // }
- //
- // if (self.foldType == KMFoldAllAnnotationType_Unfold) {
- // cell.isFold = NO;
- // } else if (self.foldType == KMFoldAllAnnotationType_Fold) {
- // cell.isFold = YES;
- // } else {
- // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
- // cell.isFold = NO;
- // } else {
- // cell.isFold = YES;
- // }
- // }
- // if (noteString.length > 0 || noteTextString.length > 0) {
- // cell.contentView.hidden = NO;
- // } else {
- // cell.contentView.hidden = YES;
- // [cell contentViewHidden:YES];
- // }
- // if (noteString.length > 0 && noteTextString.length > 0) {
- // cell.foldButton.hidden = NO;
- // }else{
- // cell.foldButton.hidden = YES;
- // }
- //
- // }
- else {
- cell.annotationContentLabel.stringValue = noteString
- cell.imageViewHeightConstraint.constant = cell.contentView.frame.size.height
- if (noteString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- }
- //
- cell.autherLayoutConstraint.constant = cell.autherLabel.isHidden ? -(cell.autherLabel.bounds.size.width) + 10.0 : 10.0
- cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.isHidden ? -(cell.typeImageView.bounds.size.width) : 0.0
- cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.isHidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0
- if note.isKind(of: CPDFStampAnnotation.self) && note.isKind(of: KMSelfSignAnnotation.self) == false {
- //
- } else {
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- if (!cell.isFold) {
- // [rightSideController.allFoldNotes addObject:note];
- } else {
- cell.imageViewHeightConstraint.constant = 18.0 + 8
- }
- } else {
- cell.imageViewHeightConstraint.constant = 18.0 + 8
- }
- }
- // cell.isUnFoldNote = ^(PDFAnnotation *cellNote, BOOL isUnfold) {
- // if (isUnfold) {
- // if ([rightSideController.allFoldNotes containsObject:note]) {
- // [rightSideController.allFoldNotes removeObject:note];
- // }
- //
- // if (rightSideController.allFoldNotes.count == 0) {
- // self.foldType = KMFoldAllAnnotationType_Fold;
- // } else {
- // self.foldType = KMFoldAllAnnotationType_None;
- // }
- // } else {
- // if (![rightSideController.allFoldNotes containsObject:note]) {
- // [rightSideController.allFoldNotes addObject:note];
- // }
- //
- // if (rightSideController.allFoldNotes.count == rightSideController.canFoldNotes.count) {
- // self.foldType = KMFoldAllAnnotationType_Unfold;
- // } else {
- // self.foldType = KMFoldAllAnnotationType_None;
- // }
- // }
- // };
- return cell
- }
- return nil
- }
-
- func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
- if item is KMBOTAAnnotationItem {
- return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: 260+40 - 16, height: 1000))
- } else if item is KMBOTAAnnotationSection {
- return 40
- } else {
- return 30
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
- if item is KMBOTAAnnotationItem {
- return false
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?.count ?? 0 > 0
- }
- return false
- }
-
- /*
- #pragma mark NSOutlineView datasource protocol
- - (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:(id)item{
- if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (item == nil && [[pdfView document] isLocked] == NO)
- item = [[pdfView document] outlineRoot];
-
- if (self.isSearchOutlineMode) {
- return [self subOutLineContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:(PDFOutline *)item];
- } else {
- return ([(PDFOutline *)item numberOfChildren] > 0);
- }
-
- } else if ([ov isEqual:rightSideController.noteOutlineView]) {
- // return [item hasNoteText];
- return NO;
- }
- return NO;
- }
- - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
-
-
- }
- - (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item{
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- PDFAnnotation *note = item;
- if ([note type]) {
- if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
- if ([(object ?: @"") isEqualToString:([note string] ?: @"")] == NO)
- [note setString:object];
- } else if ([[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
- if ([(object ?: @"") isEqualToString:([note userName] ?: @"")] == NO)
- [note setUserName:object];
- }
- }
- }
- }
- - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item {
- if ([outlineView isEqual:leftSideController.tocOutlineView]) {
- KMCustomTableRowView *itemView = [[[KMCustomTableRowView alloc] init] autorelease];
- return itemView;
- } else if ([outlineView isEqual:rightSideController.noteOutlineView]) {
- KMCustomTableRowView *itemView = [[[KMCustomTableRowView alloc] init] autorelease];
- return itemView;
- }
- return nil;
- }
- #pragma mark Drag
- - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard{
-
- if ([outlineView isEqual:leftSideController.tocOutlineView]) {
- if (leftSideController.tocOutlineView.selectedRowIndexes.count > 1) {
- return NO;
- }
- NSIndexSet *tIndex = [[[NSIndexSet alloc] initWithIndex:leftSideController.tocOutlineView.clickedRow] autorelease];
- [leftSideController.tocOutlineView deselectRow:tIndex.firstIndex];
- self.dragPDFOutline = items.firstObject;
- NSIndexSet *set = [NSIndexSet indexSetWithIndex:0];
- NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:set];
- [pasteboard declareTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType] owner:self];
- [pasteboard setData:zNSIndexSetData forType:kKMPDFViewOutlineDragDataType];
- return YES;
- }
- return NO;
- }
- - (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)anIndex {
- NSDragOperation dragOp = NSDragOperationNone;
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
- anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
- dragOp = NSDragOperationEvery;
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (anIndex == -1) {
- dragOp = NSDragOperationNone;
- } else {
- dragOp = NSDragOperationMove;
- }
- }
- return dragOp;
- }
- - (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)anIndex {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]]) {
- BOOL isShift = ([NSEvent standardModifierFlags] & NSEventModifierFlagShift) != 0;
- BOOL isAlt = ([NSEvent standardModifierFlags] & NSEventModifierFlagOption) != 0;
- [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
- return YES;
- }
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (anIndex < 0) {
- return NO;
- }
- PDFOutline *outline = item;
-
- //root,drag item to root
- if (!outline.parent) {
- //fetch root
- PDFOutline *root = self.dragPDFOutline;
- while (root.parent) {
- root = root.parent;
- }
- if ([self.dragPDFOutline.parent isEqual:root]) {
- if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
- } else {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:root];
- }
- } else {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
- }
- } else {
- //在同一个层级内移动
- if ([self.dragPDFOutline.parent isEqual:item]) {
- if (self.dragPDFOutline.index) {
- if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
- }else{
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:outline];
- }
- } else {
- return NO;
- }
- } else {
- PDFOutline *tOutlline = outline;
- BOOL isContains = NO;
- while (tOutlline) {
- if ([tOutlline isEqual:self.dragPDFOutline]) {
- isContains = YES;
- break;
- }
- tOutlline = tOutlline.parent;
- }
- if (!isContains) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
- }
- }
- }
- return YES;
- }
- return NO;
- }
- #pragma mark NSOutlineView delegate protocol
- - (NSCell *)outlineView:(NSOutlineView *)ov dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
- if ([ov isEqual:rightSideController.noteOutlineView] && tableColumn == nil && [(PDFAnnotation *)item type] == nil) {
- return [[ov tableColumnWithIdentifier:NOTE_COLUMNID] dataCellForRow:[ov rowForItem:item]];
- }
- return [tableColumn dataCellForRow:[ov rowForItem:item]];
- }
- - (void)outlineView:(NSOutlineView *)ov willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
- if ([ov isEqual:leftSideController.tocOutlineView] &&
- [ov selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular &&
- [ov isRowSelected:[ov rowForItem:item]]) {
- [cell setBackgroundStyle:NSBackgroundStyleLowered];
- }
- }
- - (BOOL)outlineView:(NSOutlineView *)ov shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item{
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- if (tableColumn == nil) {
- if ([pdfView hideNotes] == NO && [[(SKNoteText *)item note] isNote]) {
- PDFAnnotation *annotation = [(SKNoteText *)item note];
- [pdfView scrollAnnotationToVisible:annotation];
- [pdfView setActiveAnnotation:annotation];
- [self showNote:annotation];
- SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
- [[noteController window] makeFirstResponder:[noteController textView]];
- [[noteController textView] selectAll:nil];
- }
- return NO;
- } else if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID] || [[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
- return YES;
- }
- }
- return NO;
- }
- - (void)outlineView:(NSOutlineView *)ov didClickTableColumn:(NSTableColumn *)tableColumn {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSTableColumn *oldTableColumn = [ov highlightedTableColumn];
- NSTableColumn *newTableColumn = ([NSEvent modifierFlags] & NSEventModifierFlagCommand) ? nil : tableColumn;
- NSMutableArray *sortDescriptors = nil;
- BOOL ascending = YES;
- if ([oldTableColumn isEqual:newTableColumn]) {
- sortDescriptors = [[[rightSideController.noteArrayController sortDescriptors] mutableCopy] autorelease];
- [sortDescriptors replaceObjectAtIndex:0 withObject:[[sortDescriptors firstObject] reversedSortDescriptor]];
- ascending = [[sortDescriptors firstObject] ascending];
- } else {
- NSString *tcID = [newTableColumn identifier];
- NSSortDescriptor *pageIndexSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationPageIndexKey ascending:ascending] autorelease];
- NSSortDescriptor *boundsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKPDFAnnotationBoundsOrderKey ascending:ascending selector:@selector(compare:)] autorelease];
- sortDescriptors = [NSMutableArray arrayWithObjects:pageIndexSortDescriptor, boundsSortDescriptor, nil];
- if ([tcID isEqualToString:TYPE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationTypeKey ascending:YES selector:@selector(noteTypeCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:COLOR_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationColorKey ascending:YES selector:@selector(colorCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:NOTE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationStringKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:AUTHOR_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationUserNameKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:DATE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationModificationDateKey ascending:YES] autorelease] atIndex:0];
- }
- if (oldTableColumn)
- [ov setIndicatorImage:nil inTableColumn:oldTableColumn];
- [ov setHighlightedTableColumn:newTableColumn];
- }
- [rightSideController.noteArrayController setSortDescriptors:sortDescriptors];
- if (newTableColumn)
- [ov setIndicatorImage:[NSImage imageNamed:ascending ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
- inTableColumn:newTableColumn];
- [ov reloadData];
- }
- }
- - (void)outlineViewSelectionDidChange:(NSNotification *)notification{
- // Get the destination associated with the search result list. Tell the PDFView to go there.
- if ([[notification object] isEqual:leftSideController.tocOutlineView] && (mwcFlags.updatingOutlineSelection == 0)){
- mwcFlags.updatingOutlineSelection = 1;
- [self goToSelectedOutlineItem:nil];
- mwcFlags.updatingOutlineSelection = 0;
- if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- [self hideLeftSideWindow];
- }
- }
- - (NSString *)outlineView:(NSOutlineView *)ov toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn item:(id)item mouseLocation:(NSPoint)mouseLocation {
- if ([ov isEqual:rightSideController.noteOutlineView] &&
- (tableColumn == nil || [[tableColumn identifier] isEqualToString:NOTE_COLUMNID])) {
- return [item string];
- }
- return @"";
- }
- - (void)outlineViewItemDidExpand:(NSNotification *)notification{
- if ([[notification object] isEqual:leftSideController.tocOutlineView]) {
- [self updateOutlineSelection];
- }
- }
- - (void)outlineViewItemDidCollapse:(NSNotification *)notification{
- if ([[notification object] isEqual:leftSideController.tocOutlineView]) {
- [self updateOutlineSelection];
- }
- }
- - (void)outlineViewColumnDidResize:(NSNotification *)notification{
- if (mwcFlags.autoResizeNoteRows &&
- [[notification object] isEqual:rightSideController.noteOutlineView] &&
- [[[[notification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:NOTE_COLUMNID] &&
- [(SKScrollView *)[[notification object] enclosingScrollView] isResizingSubviews] == NO) {
- [rowHeights removeAllFloats];
- [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
- }
- }
- - (void)outlineView:(NSOutlineView *)ov didChangeHiddenOfTableColumn:(NSTableColumn *)tableColumn {
- if (mwcFlags.autoResizeNoteRows &&
- [ov isEqual:rightSideController.noteOutlineView] &&
- [[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
- [rowHeights removeAllFloats];
- [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
- }
- }
- - (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- CGFloat rowHeight = [rowHeights floatForKey:item];
- if (rowHeight <= 0.0) {
- if (mwcFlags.autoResizeNoteRows) {
- NSTableColumn *tableColumn = [ov tableColumnWithIdentifier:NOTE_COLUMNID];
- id cell = [tableColumn dataCell];
- [cell setObjectValue:[item objectValue]];
- if ([(PDFAnnotation *)item type] == nil) {
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, fmax(10.0, NSWidth([ov frame]) - COLUMN_INDENTATION - [ov indentationPerLevel]), CGFLOAT_MAX)].height;
- } else if ([tableColumn isHidden] == NO) {
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, [tableColumn width] - COLUMN_INDENTATION, CGFLOAT_MAX)].height;
- }
- rowHeight = fmax(rowHeight, [ov rowHeight]) + EXTRA_ROW_HEIGHT;
- [rowHeights setFloat:rowHeight forKey:item];
- } else {
- rowHeight = [(PDFAnnotation *)item type] ? [ov rowHeight] + EXTRA_ROW_HEIGHT : ([[(SKNoteText *)item note] isNote] ? DEFAULT_TEXT_ROW_HEIGHT : DEFAULT_MARKUP_ROW_HEIGHT);
- }
- }
- if (@available(macOS 10.13, *)) {
-
- } else {
- rowHeight = 75.0;
- }
- return rowHeight;
- } else if ([ov isEqual:leftSideController.tocOutlineView]){
- CGFloat rowHeight = [rowHeights floatForKey:item];
- if (rowHeight <= 0.0) {
- PDFOutline *ol = item;
- NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- [attributedString appendAttributedString:attr1];
- NSTableColumn *tableColumn = [ov tableColumnWithIdentifier:LABEL_COLUMNID];
- id cell = [tableColumn dataCell];
- [cell setObjectValue:attributedString];
-
- CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
-
- NSInteger num = [self getNum:ol];
- CGFloat gap = [ov indentationPerLevel];
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
- rowHeight = fmax(rowHeight, [ov rowHeight]) + 25;
- [rowHeights setFloat:rowHeight forKey:item];
- }
- if (@available(macOS 10.13, *)) {
- } else {
- rowHeight = 40.0;
- }
- return rowHeight < 40 ?40.0:rowHeight;//60.0;
- }
- return [ov rowHeight];
- }
- - (void)updateSelectRowHeight{
- CGFloat rowHeight = 0;
- PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.selectedRow];
- if (!outline){
- return;
- }
- NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
- [attributedString appendAttributedString:attr1];
-
- NSInteger *row = [leftSideController.tocOutlineView selectedRow];
- NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:row makeIfNecessary:YES];
- NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
- // id cell = [tableColumn dataCell];
- id cell = [tableColumn dataCellForRow:row];
- [cell setObjectValue:attributedString];
- CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
-
- NSInteger num = [self getNum:outline];
- CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
- rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
- [rowHeights setFloat:rowHeight forKey:outline];
-
- if (@available(macOS 10.13, *)) {
-
- } else {
- rowHeight = 40.0;
- }
- CGRect fram = viewS.frame;
- viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
- [leftSideController.tocOutlineView reloadData];
- }
- - (NSInteger)getNum:(PDFOutline *)ol{
- NSInteger num = 0;
- PDFOutline *outLine = [ol parent];
- do {
- outLine = [outLine parent];
- if (outLine){
- num ++;
- }
- } while (outLine);
- return num;
- }
- - (void)sizeOutlineViewToContents:(NSOutlineView*) outlineView;
- {
- NSInteger rowCount = [outlineView numberOfRows];
- for (NSInteger i = 0; i < rowCount; i++){
- CGFloat rowHeight = 0;
- PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:i];
- if (!outline){
- continue;
- }
- NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
- [attributedString appendAttributedString:attr1];
-
- // NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:i makeIfNecessary:YES];
- NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
- // id cell = [tableColumn dataCell];
- id cell = [tableColumn dataCellForRow:i];
- [cell setObjectValue:attributedString];
- CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
-
- NSInteger num = [self getNum:outline];
- CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
- rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
- rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
- [rowHeights setFloat:rowHeight forKey:outline];
-
- if (@available(macOS 10.13, *)) {
-
- } else {
- rowHeight = 40.0;
- }
- // CGRect fram = viewS.frame;
- // viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
- }
- [leftSideController.tocOutlineView reloadData];
- }
- - (BOOL)outlineView:(NSOutlineView *)ov canResizeRowByItem:(id)item {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- return YES;
- }
- return NO;
- }
- - (void)outlineView:(NSOutlineView *)ov setHeight:(CGFloat)newHeight ofRowByItem:(id)item {
- [rowHeights setFloat:newHeight forKey:item];
- }
- - (NSArray *)noteItems:(NSArray *)items {
- NSMutableArray *noteItems = [NSMutableArray array];
-
- for (PDFAnnotation *item in items) {
- if ([item type] == nil) {
- item = [(SKNoteText *)item note];
- }
- if ([noteItems containsObject:item] == NO)
- [noteItems addObject:item];
- }
- return noteItems;
- }
- - (void)outlineView:(NSOutlineView *)ov deleteItems:(NSArray *)items {
- if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
- for (PDFAnnotation *item in [self noteItems:items])
- [pdfView removeAnnotation:item];
- [[[self document] undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- [self outlineContextMenuItemClicked_RemoveEntry:nil];
- }
- }
- - (BOOL)outlineView:(NSOutlineView *)ov canDeleteItems:(NSArray *)items {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- return [[self pdfDocument] allowsNotes] && [items count] > 0;
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- return [items count] > 0;
- }
- return NO;
- }
- - (void)outlineView:(NSOutlineView *)ov copyItems:(NSArray *)items {
- if ([ov isEqual:rightSideController.noteOutlineView] && [items count]) {
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- NSMutableArray *copiedItems = [NSMutableArray array];
- NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] init] autorelease];
- BOOL isAttributed = NO;
- id item;
-
- for (item in [self noteItems:items]) {
- if ([item isMovable])
- [copiedItems addObject:item];
- }
- for (item in items) {
- if ([attrString length])
- [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:@"\n\n"];
- if ([(PDFAnnotation *)item type] == nil && [[(SKNoteText *)item note] isNote]) {
- [attrString appendAttributedString:[(SKNoteText *)item text]];
- isAttributed = YES;
- } else {
- [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:[item string] ?: @""];
- }
- }
-
- [pboard clearContents];
- if (isAttributed)
- [pboard writeObjects:[NSArray arrayWithObjects:attrString, nil]];
- else
- [pboard writeObjects:[NSArray arrayWithObjects:[attrString string], nil]];
- if ([copiedItems count] > 0)
- [pboard writeObjects:copiedItems];
- }
- }
- - (BOOL)outlineView:(NSOutlineView *)ov canCopyItems:(NSArray *)items {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- if ([items count] == 1) {
- PDFAnnotation *annotation = [[self noteItems:items] lastObject];
- if ([annotation isKindOfClass:[PDFAnnotationStamp class]] ||
- [annotation isKindOfClass:[PDFAnnotationLink class]]) {
- return NO;
- }
- }
- return [items count] > 0;
- }
- return NO;
- }
- - (NSUInteger)outlineView:(NSOutlineView *)ov highlightLevelForRow:(NSInteger)row {
- if ([ov isEqual:leftSideController.tocOutlineView]) {
- NSInteger numRows = [ov numberOfRows];
- NSUInteger firstPage = [[[ov itemAtRow:row] page] pageIndex];
- NSUInteger lastPage = row + 1 < numRows ? [[[ov itemAtRow:row + 1] page] pageIndex] : [[self pdfDocument] pageCount];
- NSRange range = NSMakeRange(firstPage, MAX(1LU, lastPage - firstPage));
- NSUInteger i, iMax = [lastViewedPages count];
- for (i = 0; i < iMax; i++) {
- if (NSLocationInRange((NSUInteger)[lastViewedPages pointerAtIndex:i], range))
- return i;
- }
- }
- return NSNotFound;
- }
- - (id <SKImageToolTipContext>)outlineView:(NSOutlineView *)ov imageContextForItem:(id)item {
- if ([ov isEqual:leftSideController.tocOutlineView])
- return [item destination];
- return nil;
- }
- - (void)outlineViewCommandKeyPressedDuringNavigation:(NSOutlineView *)ov {
- PDFAnnotation *annotation = [[self selectedNotes] lastObject];
- if (annotation) {
- [pdfView scrollAnnotationToVisible:annotation];
- [pdfView setActiveAnnotation:annotation];
- }
- }
- - (NSArray *)outlineView:(NSOutlineView *)ov typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSInteger i, count = [rightSideController.noteOutlineView numberOfRows];
- NSMutableArray *texts = [NSMutableArray arrayWithCapacity:count];
- for (i = 0; i < count; i++) {
- id item = [rightSideController.noteOutlineView itemAtRow:i];
- NSString *string = [item string];
- [texts addObject:string ?: @""];
- }
- return texts;
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- NSInteger i, count = [leftSideController.tocOutlineView numberOfRows];
- NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
- for (i = 0; i < count; i++)
- [array addObject:[[(PDFOutline *)[leftSideController.tocOutlineView itemAtRow:i] label] lossyStringUsingEncoding:NSASCIIStringEncoding]];
- return array;
- }
- return nil;
- }
- - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- }
- }
- - (void)outlineView:(NSOutlineView *)ov typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
- if ([typeSelectHelper isEqual:[leftSideController.thumbnailTableView typeSelectHelper]] || [typeSelectHelper isEqual:[pdfView typeSelectHelper]]) {
- if (searchString)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- } else if ([typeSelectHelper isEqual:[rightSideController.noteOutlineView typeSelectHelper]]) {
- if (searchString)
- [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding note: \"%@\"", @"Status message"), searchString]];
- else
- [self updateRightStatus];
- } else if ([typeSelectHelper isEqual:[leftSideController.tocOutlineView typeSelectHelper]]) {
- if (searchString)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding: \"%@\"", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- }
- }
- */
- }
|