123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552 |
- //
- // 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()
- 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 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)
- }
-
- 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
-
-
- private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
- private let LABEL_COLUMNID = "label"
-
- 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);
- }
-
- 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
- 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];
- }
- }
- 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];
- }
- 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) {
- // PDFAnnotation *note = item;
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteTableViewCell"), owner: self) as! KMNoteTableViewCell
- // cell.cellNote = note;
- //
- // NSColor *noteColor = [note color] ? : nil;
- // NSString *noteType = [note type] ? : @"";
- // NSString *noteString = [note objectValue] ? : @"";
- // NSString *pageString = [[note page] displayLabel] ? : @"";
- // NSDate *date = [note modificationDate] ? : nil;
- // NSString *authorString = [note userName] ? : @"";
- // NSString *noteTextString = [note noteText].string ? : @"";
- //
- // if([noteType isEqualToString:@"Redact"]) {
- // noteString = @"Redact";
- // }
- //
- // if (![[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTimeKey"] boolValue]) {
- // if (date) {
- // cell.timeLabel.stringValue = [NSDate timeStringWithTimeDate:date];
- // } else {
- // cell.timeLabel.stringValue = @"";
- // }
- // cell.timeLabel.hidden = NO;
- // } else {
- // cell.timeLabel.hidden = YES;
- // }
- // if (![[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationPageKey"] boolValue]) {
- // CGRect labelsize =[cell.pageLabel.stringValue boundingRectWithSize:CGSizeMake(MAXFLOAT,CGRectGetHeight(cell.pageLabel.bounds)) options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[NSFont systemFontOfSize:12.0]}context:nil];
- // cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5;
- // cell.pageLabel.stringValue = pageString;
- // cell.pageLabel.hidden = NO;
- // } else {
- // cell.pageLabel.hidden = YES;
- // }
- // if (![[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationAutherKey"] boolValue]) {
- // cell.autherLabel.stringValue = authorString;
- // cell.autherLabel.hidden = NO;
- // } else {
- // cell.autherLabel.hidden = YES;
- // }
- // KMNoteTypeImageView *imageView = [[[KMNoteTypeImageView alloc] init] autorelease];
- // if ([note isKindOfClass:[KMAnnotationStamp class]]) {
- // KMAnnotationStamp *annotation_stamp = (KMAnnotationStamp *)note;
- // if (annotation_stamp.image) {
- // noteType = @"Stamp_Image";
- // }
- // } else if ([note isKindOfClass:[PDFAnnotationLine class]]) {
- // PDFAnnotationLine *annotation_line = (PDFAnnotationLine *)note;
- // if (annotation_line.startLineStyle == kPDFLineStyleNone &&
- // annotation_line.endLineStyle == kPDFLineStyleNone) {
- // noteType = @"Line_None";
- // } else if (annotation_line.startLineStyle == kPDFLineStyleNone &&
- // annotation_line.endLineStyle == kPDFLineStyleOpenArrow) {
- // noteType = @"Line_OpenArrow";
- // } else {
- // noteType = @"Line_None";
- // }
- // } else 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;
- // }
- // } else if ([note isKindOfClass:[KMTableAnnotation class]]) {
- // KMTableAnnotation *table = (KMTableAnnotation *)note;
- // noteType = @"Ink_Table";
- // } else if ([note isKindOfClass:[KMSelfSignAnnotation class]]) {
- // KMSelfSignAnnotation *selfSignNote = (KMSelfSignAnnotation *)note;
- // if (selfSignNote.annotationType == KMSelfSignTypeFalse) {
- // noteType = @"KMSelfSignTypeFalseActionButtonKey";
- // } else if (selfSignNote.annotationType == KMSelfSignTypeTure) {
- // noteType = @"KMSelfSignTypeTureActionButtonKey";
- // } else if (selfSignNote.annotationType == KMSelfSignTypeCircle) {
- // noteType = @"KMSelfSignTypeCircleActionButtonKey";
- // } else if (selfSignNote.annotationType == KMSelfSignTypeLine) {
- // noteType = @"KMSelfSignTypeLineActionButtonKey";
- // } else if (selfSignNote.annotationType == KMSelfSignTypeDot) {
- // noteType = @"KMSelfSignTypeDotActionButtonKey";
- // } else if (selfSignNote.annotationType == KMSelfSignTypeText) {
- // noteType = @"KMSelfSignTypeTextActionButtonKey";
- // }
- // }
- // cell.typeImageView.image = [imageView noteTypeImageWithType:noteType Color:noteColor];
- // cell.typeImageView.hidden = NO;
- //
- // if (![note isKindOfClass:[PDFAnnotationMarkup class]]) {
- // cell.isFold = YES;
- // }
- //
- // cell.noteContentBox.hidden = YES;
- // cell.noteImageView.hidden = YES;
- // cell.foldButton.hidden = YES;
- // cell.annotationContentLabel.hidden = NO;
- //
- // cell.noteContentLabel.stringValue = noteString;
- //
- // cell.contentView.hidden = NO;
- // [cell contentViewHidden:NO];
- // if ([note isKindOfClass:[PDFAnnotationMarkup class]]) {
- // PDFAnnotationMarkup *markup = (PDFAnnotationMarkup *)note;
- // if(noteTextString.length > 0) {
- // cell.foldButton.hidden = NO;
- // }
- // NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:noteTextString];
- // if (markup.markupType == kPDFMarkupTypeHighlight) {
- // [attributeStr addAttribute:NSBackgroundColorAttributeName value:noteColor range:NSMakeRange(0, noteTextString.length)];
- // } else if (markup.markupType == kPDFMarkupTypeStrikeOut) {
- // [attributeStr addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, noteTextString.length)];
- // [attributeStr addAttribute:NSStrikethroughColorAttributeName value:noteColor range:NSMakeRange(0, noteTextString.length)];
- // } else if (markup.markupType == kPDFMarkupTypeUnderline) {
- // [attributeStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, noteTextString.length)];
- // [attributeStr addAttribute:NSUnderlineColorAttributeName value:noteColor range:NSMakeRange(0, noteTextString.length)];
- // }
- // cell.annotationContentLabel.attributedStringValue = attributeStr;
- //
- // 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 contentViewHidden:NO];
- // else
- // [cell contentViewHidden:YES];
- // }
- //
- // else if ([note isKindOfClass:[PDFAnnotationLine class]] ||
- // [noteType isEqualToString:SKNSquareString] ||
- // [noteType isEqualToString:SKNCircleString] ||
- // [noteType isEqualToString:SKNInkString]) {
- // cell.annotationContentLabel.stringValue = noteString ? : @"";
- // if (noteString.length > 0)
- // [cell contentViewHidden:NO];
- // else
- // [cell contentViewHidden:YES];
- // } else if([note isKindOfClass:[PDFAnnotationStamp class]]) {
- // if ([note isKindOfClass:[KMSelfSignAnnotation class]]) {
- // KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)note;
- // KMSelfSignType type = newAnnotation.annotationType;
- // NSString *returnString = @"";
- // if (type == KMSelfSignTypeFalse) {
- // returnString = NSLocalizedString(@"X", nil);
- // } else if (type == KMSelfSignTypeTure) {
- // returnString = NSLocalizedString(@"Check mark", nil);
- // } else if (type == KMSelfSignTypeCircle) {
- // returnString = NSLocalizedString(@"Circle", nil);
- // } else if (type == KMSelfSignTypeLine) {
- // returnString = NSLocalizedString(@"Line", nil);
- // } else if (type == KMSelfSignTypeDot) {
- // returnString = NSLocalizedString(@"Dot", nil);
- // } else if (type == KMSelfSignTypeText) {
- // returnString = NSLocalizedString(@"Text", nil);
- // }
- // cell.annotationContentLabel.stringValue = returnString;
- // } else {
- // cell.annotationContentLabel.hidden = YES;
- //
- // cell.noteImageView.hidden = NO;
- // 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.length > 0)
- // [cell contentViewHidden:NO];
- // else
- // [cell contentViewHidden:YES];
- // }
- //
- // cell.autherLayoutConstraint.constant = cell.autherLabel.hidden ? -(cell.autherLabel.bounds.size.width) + 10.0f : 10.0f;
- // cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.hidden ? -(cell.typeImageView.bounds.size.width) : 0.0f;
- // cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.hidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0f;
- // if ([note isKindOfClass:[PDFAnnotationStamp class]] && ![note isKindOfClass:[KMSelfSignAnnotation class]]) {
- //
- // } else {
- // if ([note isKindOfClass:[PDFAnnotationMarkup class]]) {
- // 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;
- // }
- // }
- // };
- //
- // if (@available(macOS 10.13, *)) {
- //
- // } else {
- // cell.foldButton.hidden = YES;
- // }
- return cell
- }
- return nil
- }
-
- /*
- #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];
- }
- }
- */
- }
|