1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795 |
- //
- // KMLeftSideViewController.swift
- // PDF Master
- //
- // Created by lxy on 2022/10/10.
- //
- import Cocoa
- @objc protocol KMLeftSideViewControllerDelegate {
- @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
- @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
- @objc optional func searchAction(searchString:String, isCase:Bool)
-
- @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
- @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
-
- @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
-
- @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
- }
- class KMLeftSideViewController: KMSideViewController {
- // @IBOutlet weak var leftTableview: NSTableView!
- // @IBOutlet weak var leftBox: NSBox!
-
- lazy var annotationViewController : KMAnnotationViewController = {
- let annotationViewController = KMAnnotationViewController(nibName: "KMAnnotationViewController", bundle: nil)
- return annotationViewController
- }()
- lazy var bookViewController : KMBookMarkViewController = {
- let bookViewController = KMBookMarkViewController()
- bookViewController.bookMarkDidChange = { [unowned self] (controller, bookMarks) in
- self.delegate?.controller?(controller: self, bookMarkDidChange: bookMarks)
- }
- return bookViewController
- }()
- lazy var 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)
-
- self.annotationViewController.listView = self.listView
- self.view.addSubview(self.annotationViewController.view)
- self.annotationViewController.reloadData()
- self.annotationViewController.view.frame = NSMakeRect(0, 0, 1, 1)
- }
-
- 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]
- self.leftView.segmentedControl.selectedSegment = 0
- } else {
- // self.contentBox.isHidden = false
- // self.panelSetViewController.view.removeFromSuperview()
- // if self.type.methodType == .None {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- 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
- } else if methodType == .None {
- 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
- // }
- // }
-
- // 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
- /*
- NSArrayController *thumbnailArrayController;
- NSArrayController *findArrayController;
- NSArrayController *groupedFindArrayController;
- }
- - (void)applySearchTableHeader:(NSString *)message;
- */
-
- @IBOutlet var segmentedControl: KMSegmentedControl!
-
- @IBOutlet var thumbnailTableView: KMThumbnailTableView!
- @IBOutlet var tocOutlineView: KMTocOutlineView!
- @IBOutlet var noteOutlineView: KMNoteOutlineView!
- @IBOutlet var findTableView: KMBotaTableView!
- @IBOutlet var groupedFindTableView: KMBotaTableView!
- @IBOutlet var snapshotTableView: KMBotaTableView!
-
- @IBOutlet weak var leftListView: NSView!
-
- @IBOutlet var searchViewController: KMBotaSearchViewController!
- @IBOutlet weak var toolButtonBox: NSBox!
- @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
- @IBOutlet weak var snapshotNormalView: NSView!
- @IBOutlet weak var snapshotLabel: NSTextField!
- @IBOutlet weak var snapshotNormalMoreButton: NSButton!
- @IBOutlet weak var snapshotNormalSearchButton: NSButton!
- @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
- @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
- @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
- @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
- @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var snapshotDoneButton: NSButton!
-
- @IBOutlet weak var outlineView: NSView!
- @IBOutlet weak var outlineMoreButton: NSButton!
- @IBOutlet weak var outlineAddButton: NSButton!
- @IBOutlet weak var outlineSearchButton: NSButton!
- @IBOutlet weak var outlineLabel: NSTextField!
- @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var outlineDoneButton: NSButton!
-
- @IBOutlet weak var noteView: NSView!
- @IBOutlet weak var noteMoreButton: NSButton!
- @IBOutlet weak var noteFilterButton: NSButton!
- @IBOutlet weak var noteSearchButton: NSButton!
- @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
- @IBOutlet weak var noteTitleLabel: NSTextField!
- @IBOutlet weak var noteHeaderView: NSView!
- @IBOutlet weak var sortTypeBox: KMBox!
- @IBOutlet weak var sortTypeLabel: NSTextField!
- @IBOutlet weak var noteSortButton: NSButton!
- @IBOutlet weak var noteDoneButton: NSButton!
-
- @IBOutlet weak var thumbnailView: NSView!
- @IBOutlet weak var thumbnailZoomOutButton: NSButton!
- @IBOutlet weak var thumbnailZoomInButton: NSButton!
- @IBOutlet weak var thumbnailTitleLabel: NSTextField!
-
- @IBOutlet weak var emptySearchBox: NSBox!
- @IBOutlet weak var emptySearchLabel: NSTextField!
-
- var filterButtonLayer: NSView?
- var moreButtonLayer: KMButtonLayer?
-
- var thumbnails: [KMThumbnail] = []
- var isDisplayPageSize = false
- var thumbnailCacheSize: CGFloat = 32 * 3
- var findState: KMFindState = .content
- // var searchResults: [CPDFSelection] = []
- var searchResults : [KMSearchMode] = [] {
- didSet {
- self.updataLeftSideFindView()
- }
- }
- var groupSearchResults: [KMSearchMode] = []
- var findPaneState: KMFindPaneState = .singular
- var isSearchOutlineMode = false
- var outlineIgnoreCaseFlag = false
- var noteTypeDict: [String : Any] = [:]
-
- private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
- private let LABEL_COLUMNID = "label"
- var foldType: KMFoldAllAnnotationType = .none
- private let KMLeftSideViewNoteSortTypeKey = "KMLeftSideViewNoteSortTypeKey"
- private let KMLeftSideViewAscendSortBoolKey = "KMLeftSideViewAscendSortBoolKey"
- private let SKDisableTableToolTipsKey = "SKDisableTableToolTips"
-
- var tocType: KMFoldType = .none
-
- var snapshots: [Any] = []
-
- private var _noteSortType: KMNoteSortType = .none
- var noteSortType: KMNoteSortType {
- get {
- return self._noteSortType
- }
- set {
- self._noteSortType = newValue
-
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
- }
- }
-
- var isAscendSort = false {
- didSet {
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
- }
- }
-
- lazy var leftSideEmptyVC: KMLeftSideEmptyFileViewController = {
- let vc = KMLeftSideEmptyFileViewController(nibName: "KMLeftSideEmptyFileViewController", bundle: nil)
- vc.view.wantsLayer = true
- return vc
- }()
-
- var preThumbnailRow: Int = 0
- var leftMargin: CGFloat = 0
-
- lazy var leftView: KMBotaLeftView = {
- let view = KMBotaLeftView()
- return view
- }()
-
- private var _copysPages: [CPDFPage] = []
-
- override func loadView() {
- super.loadView()
-
- self.view.wantsLayer = true
- self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.view.addSubview(self.leftView)
- self.leftView.frame = NSMakeRect(0, 0, 44, NSHeight(self.view.frame))
- self.leftView.autoresizingMask = [.height]
- self.leftView.wantsLayer = true
- self.leftView.layer?.backgroundColor = .white
-
- self.outlineView.wantsLayer = true
- self.outlineView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.noteView.wantsLayer = true
- self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.thumbnailView.wantsLayer = true
- self.thumbnailView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- self.snapshotNormalView.wantsLayer = true
- self.snapshotNormalView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.tocOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
- self.noteOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
- self.findTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.groupedFindTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.snapshotTableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.thumbnailTableView.backgroundColor = KMAppearance.Layout.l0Color()
-
- self.leftListView.wantsLayer = true
- self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
-
- self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
- self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
- self.emptySearchBox.isHidden = true
-
- self.thumbnailTitleLabel.stringValue = KMLocalizedString("Thumbnails", nil)
- self.thumbnailTitleLabel.textColor = KMAppearance.Layout.h0Color()
- self.thumbnailZoomInButton.action = #selector(thumbnailSizeScaling)
- self.thumbnailZoomInButton.target = self
- self.thumbnailZoomInButton.tag = 1
- self.thumbnailZoomOutButton.action = #selector(thumbnailSizeScaling)
- self.thumbnailZoomOutButton.target = self
- self.thumbnailZoomOutButton.tag = 0
-
- self.snapshotTableView.delegate = self
- self.snapshotTableView.dataSource = self
- // [[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()
- self.snapshotNormalZoomInButton.action = #selector(thumbnailSizeScaling)
- self.snapshotNormalZoomInButton.target = self
- self.snapshotNormalZoomInButton.tag = 2
- self.snapshotNormalZoomOutButton.action = #selector(thumbnailSizeScaling)
- self.snapshotNormalZoomOutButton.target = self
- self.snapshotNormalZoomOutButton.tag = 3
- self.snapshotNormalSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.snapshotNormalMoreButton.action = #selector(leftSideViewMoreButtonAction)
- self.snapshotNormalMoreButton.target = self
- self.snapshotNormalMoreButton.tag = 300
-
- self.snapshotSearchZoomInButton.action = #selector(thumbnailSizeScaling)
- self.snapshotSearchZoomInButton.target = self
- self.snapshotSearchZoomInButton.tag = 2
- self.snapshotSearchZoomOutButton.action = #selector(thumbnailSizeScaling)
- self.snapshotSearchZoomOutButton.target = self
- self.snapshotSearchZoomOutButton.tag = 3
- self.snapshotDoneButton.title = KMLocalizedString("Done", nil)
- self.snapshotDoneButton.toolTip = KMLocalizedString("Done", nil)
- self.snapshotDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.snapshotDoneButton.wantsLayer = true
- self.snapshotDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.snapshotDoneButton.layer?.cornerRadius = 4.0
- self.snapshotDoneButton.action = #selector(leftSideViewDoneButtonAction)
- self.snapshotDoneButton.target = self
- self.snapshotDoneButton.tag = 312
- self.snapshotDoneButton.isHidden = true
-
- self.noteOutlineView.autoresizesOutlineColumn = false
-
- self.noteOutlineView.delegate = self
- self.noteOutlineView.dataSource = self
- self.noteOutlineView.menu = NSMenu()
- self.noteOutlineView.menu?.delegate = self
- // [noteOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
- self.noteOutlineView.indentationPerLevel = 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 = KMLocalizedString("Add Item", nil)
- self.outlineAddButton.action = #selector(outlineContextMenuItemClicked_AddEntry)
- self.outlineAddButton.target = self
- self.outlineSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.outlineMoreButton.action = #selector(leftSideViewMoreButtonAction)
- self.outlineMoreButton.target = self
- self.outlineMoreButton.tag = 302
- self.outlineDoneButton.title = KMLocalizedString("Done", nil);
- self.outlineDoneButton.toolTip = KMLocalizedString("Done", nil);
- self.outlineDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.outlineDoneButton.wantsLayer = true
- self.outlineDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.outlineDoneButton.layer?.cornerRadius = 4.0
- self.outlineDoneButton.action = #selector(leftSideViewDoneButtonAction)
- self.outlineDoneButton.target = self
- self.outlineDoneButton.tag = 310
- self.outlineDoneButton.isHidden = true
- self.outlineSearchField.isHidden = true
- // _outlineSearchField.endEditCallBack = ^(BOOL isEndEdit) {
- // if (isEndEdit) {
- // _outlineSearchField.hidden = YES;
- // _outlineLabel.hidden = NO;
- // _outlineSearchButton.hidden = NO;
- // }
- // };
- // NSMenu *menuOutline = [NSMenu menu];
- // [menuOutline addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleOutlineCaseInsensitiveSearch:) target:mainController];
- // [[_outlineSearchField cell] setSearchMenuTemplate:menuOutline];
- (self.outlineSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Outline", nil)
- self.outlineSearchField.target = self
-
- let sud = UserDefaults.standard
- self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
- self.noteTitleLabel.textColor = KMAppearance.Layout.h0Color()
- self.noteMoreButton.action = #selector(leftSideViewMoreButtonAction)
- self.noteMoreButton.target = self
- self.noteMoreButton.tag = 304
- self.noteMoreButton.wantsLayer = true
- self.moreButtonLayer = KMButtonLayer()
- self.noteMoreButton.layer?.addSublayer(self.moreButtonLayer!)
- self.moreButtonLayer?.frame = CGRectMake(0, 0, CGRectGetWidth(self.noteMoreButton.bounds), CGRectGetHeight(self.noteMoreButton.bounds))
- self.moreButtonLayer?.layerType = .none
- self.moreButtonLayer?.isHidden = true
-
- self.noteFilterButton.action = #selector(noteFilterAction)
- self.noteFilterButton.target = self
- self.noteFilterButton.toolTip = KMLocalizedString("Sort", nil)
- self.noteFilterButton.wantsLayer = true
- self.filterButtonLayer = NSView()
- self.noteFilterButton.addSubview(self.filterButtonLayer!)
- self.filterButtonLayer?.frame = CGRectMake(14, 2, 8, 8)
- // self.filterButtonLayer?.layerType = KMNoteFilerButtonLayerType_Dot
- self.filterButtonLayer?.isHidden = true
- self.filterButtonLayer?.wantsLayer = true
- self.filterButtonLayer?.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.filterButtonLayer?.layer?.cornerRadius = 4.0
-
- self.noteDoneButton.title = KMLocalizedString("Done", nil)
- self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
- self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
- self.noteDoneButton.wantsLayer = true
- self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
- self.noteDoneButton.layer?.cornerRadius = 4.0
- self.noteDoneButton.action = #selector(leftSideViewDoneButtonAction)
- self.noteDoneButton.target = self
- self.noteDoneButton.tag = 311
- self.noteDoneButton.isHidden = true
-
- self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
- self.noteSearchField.isHidden = true
- self.noteSearchField.endEditCallBack = { [unowned self] isEndEdit in
- if (isEndEdit) {
- self.noteSearchField.isHidden = true
- self.noteSearchButton.isHidden = false
- self.noteTitleLabel.isHidden = false
- }
- };
- self.noteHeaderView.wantsLayer = true
- self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
- self.noteHeaderView.layer?.cornerRadius = 1.0
- let sortType = sud.integer(forKey: KMLeftSideViewNoteSortTypeKey)
- if (sortType == 1) {
- self.noteSortType = KMNoteSortType(rawValue: sortType)!
- if (self.noteSortType == .time) {
- self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
- } else if (self._noteSortType == .page) {
- self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
- }
- } else {
- self.noteSortType = .time
- self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
- }
- self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
-
- self.isAscendSort = sud.bool(forKey: KMLeftSideViewAscendSortBoolKey)
- if (self.isAscendSort) {
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
- self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
- } else {
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
- self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
- }
-
- self.sortTypeBox.downCallback = { [unowned self] downEntered, mouseBox, _ in
- if (downEntered) {
- let menu = NSMenu()
- let timeItem = menu.addItem(title: KMLocalizedString("Time", nil), action: #selector(sortTypeAction), target: self)
- timeItem?.representedObject = self
- timeItem?.tag = 0
- let pageItem = menu.addItem(title: KMLocalizedString("Page", nil), action: #selector(sortTypeAction), target: self)
- pageItem?.representedObject = self
- timeItem?.tag = 1
- if (self.noteSortType == .time) {
- timeItem?.state = .on
- pageItem?.state = .off
- } else if (self.noteSortType == .page) {
- timeItem?.state = .off
- pageItem?.state = .on
- }
- menu.popUp(positioning: nil, at: CGPointMake(-10, 0), in: self.sortTypeBox)
- }
- }
-
- self.searchViewController.loadView()
- self.searchViewController.contentView = self.findTableView.enclosingScrollView
- self.searchField = self.searchViewController.searchField
-
- self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
- self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
- self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
- self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
- self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
- self.searchViewController.segmentedControl.isBackgroundHighlighted = true
- self.searchViewController.segmentedControl.selectedSegment = 0
- self.searchViewController.segmentedControl.block = { [unowned self] segIndex in
- if segIndex == 0 {
- self.findPaneState = .singular
- self.displayFindViewAnimating(false)
- } else {
- self.findPaneState = .grouped
- self.displayGroupedFindViewAnimating(false)
- }
- }
- // [mainController bind:@"findPaneState" toObject:searchViewController.segmentedControl withKeyPath:@"selectedSegment" options:nil];
- self.leftView.segmentedControl.block = { [unowned self] segIndex in
- self.toolButtonBox.isHidden = false
- self.toolButtonBoxLayoutConstraint.constant = 40.0
-
- if (segIndex == 0) {
- if self.type.methodType == .Thumbnail {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Thumbnail)
- DispatchQueue.main.async {
- self.toolButtonBox.contentView = self.thumbnailView
- self.displayThumbnailViewAnimating(true)
- }
- } else if (segIndex == 1) {
- if self.type.methodType == .Outline {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Outline)
- DispatchQueue.main.async {
- self.toolButtonBox.contentView = self.outlineView
- self.displayTocViewAnimating(false)
- }
- } else if (segIndex == 2) {
- if self.type.methodType == .Annotation {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Annotation)
- DispatchQueue.main.async {
- self.toolButtonBox.contentView = self.noteView
- self.displayNoteViewAnimating(false)
- }
- } else if (segIndex == 3) {
- self.toolButtonBox.contentView = self.snapshotNormalView
- self.displaySnapshotViewAnimating(false)
- self.updataLeftSideSnapView()
- } else if (segIndex == 4) {
- if self.type.methodType == .Search {
- self.leftView.segmentedControl.selectedSegment = UInt8.max
- self.refreshMethodType(methodType: .None)
- return
- }
-
- self.refreshMethodType(methodType: .Search)
- DispatchQueue.main.async {
- self.toolButtonBox.isHidden = true
- self.toolButtonBoxLayoutConstraint.constant = 0
- self.displayFindViewAnimating(false)
- }
- }
- }
-
- // self.button.setHelp(KMLocalizedString("View Thumbnails", "Tool tip message"), for: KMLeftSidePaneState.thumbnail.rawValue)
- // self.button.setHelp(KMLocalizedString("View Outline", "Tool tip message"), for: KMLeftSidePaneState.outline.rawValue)
- // self.alternateButton.setHelp(KMLocalizedString("Separate search results", "Tool tip message"), for: KMFindPaneState.singular.rawValue)
- // self.alternateButton.setHelp(KMLocalizedString("Group search results by page", "Tool tip message"), for: KMFindPaneState.grouped.rawValue)
-
- // 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")];
-
- self.searchField.action = #selector(search)
- self.searchField.target = self
-
- self.tocOutlineView.autoresizesOutlineColumn = false
- self.tocOutlineView.allowsMultipleSelection = true
- self.tocOutlineView.allowsEmptySelection = true
- self.tocOutlineView.delegate = self
- self.tocOutlineView.dataSource = self
-
- self.thumbnailTableView.delegate = self
- self.thumbnailTableView.dataSource = self
- self.thumbnailTableView.thumbDelegate = self
- self.thumbnailTableView.allowsMultipleSelection = true
- self.findTableView.delegate = self
- self.findTableView.dataSource = self
- self.findTableView.botaDelegate = self
- self.groupedFindTableView.delegate = self
- self.groupedFindTableView.dataSource = self
- self.groupedFindTableView.botaDelegate = self
- self.thumbnailTableView.menu?.delegate = self
- self.findTableView.menu?.delegate = self
- self.groupedFindTableView.menu?.delegate = self
-
- self.tocOutlineView.doubleAction = #selector(goToSelectedOutlineItem)
- self.tocOutlineView.target = self
- self.findTableView.doubleAction = #selector(goToSelectedFindResults)
- self.findTableView.target = self
- self.groupedFindTableView.doubleAction = #selector(goToSelectedFindResults)
- self.groupedFindTableView.target = self
-
- // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
- // //支持拖拽的文字类型
- // [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
- // [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)) {
- // [(SKSourceListTextFieldCell *)[[thumbnailTableView tableColumnWithIdentifier:PAGE_COLUMNID] dataCell] setSimulatesSourceList:YES];
- // }
- self.thumbnailTableView.selectionHighlightStyle = .none
-
- // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
- // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
- //
- self.thumbnailTableView.setDraggingSourceOperationMask(.every, forLocal: false)
-
- if UserDefaults.standard.bool(forKey: SKDisableTableToolTipsKey) == false {
- // [tocOutlineView setHasImageToolTips:YES];
- self.findTableView.hasImageToolTips = true
- self.groupedFindTableView.hasImageToolTips = true
- }
- 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.origin.x = self.leftMargin
- frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.thumbnailTableView.enclosingScrollView?.frame = frame
-
- self.resetThumbnails()
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.origin.x = self.leftMargin
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.origin.x = self.leftMargin
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // [self updateThumbnailSelection];
- }
-
- func displayFindViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.searchViewController.view, animate: animate)
- if (self.findState != .content) {
- self.findState = .content
- } else {
- self.displayFindState()
- }
-
- var frame = self.searchViewController.view.frame
- frame.origin.y = 0
- frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
- self.searchViewController.view.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
- self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
-
- self.updataLeftSideSnapView()
- }
-
- func displayFindState() {
- if (self.findState == .content) {
- self.displayFind()
- } else if (self.findState == .note) {
- self.displayNoteFind()
- } else if (self.findState == .snapshot) {
- // [self displaySnapshotFind];
- }
- }
-
- func updataLeftSideSnapView() {
- if (snapshots.count < 1) {
- self.snapshotNormalSearchButton.isEnabled = false
- // leftSideController.snapshotSearchZoomOutButton.enabled = NO;
- self.snapshotNormalZoomOutButton.isEnabled = false
- // leftSideController.snapshotSearchZoomInButton.enabled = NO;
- self.snapshotNormalZoomInButton.isEnabled = false
- self.snapshotNormalMoreButton.isEnabled = false
-
- self.leftSideEmptyVC.deleteSnapBtn.isEnabled = false
- self.leftSideEmptyVC.exportSnapBtn.isEnabled = false
- self.leftSideEmptyVC.printSnapBtn.isEnabled = false
- self.snapshotTableView.usesAlternatingRowBackgroundColors = false
- let view = self.snapshotTableView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptySnapView.frame.size
- self.leftSideEmptyVC.emptySnapView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
- self.leftSideEmptyVC.emptySnapView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptySnapView)
- } else {
- self.snapshotNormalSearchButton.isEnabled = true
- // leftSideController.snapshotSearchZoomOutButton.enabled = YES;
- self.snapshotNormalZoomOutButton.isEnabled = true
- // leftSideController.snapshotSearchZoomInButton.enabled = YES;
- self.snapshotNormalZoomInButton.isEnabled = true
- self.snapshotNormalMoreButton.isEnabled = true
- self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
- self.leftSideEmptyVC.deleteSnapBtn.isEnabled = true
- self.leftSideEmptyVC.exportSnapBtn.isEnabled = true
- self.leftSideEmptyVC.printSnapBtn.isEnabled = true
- }
- }
-
- func updataLeftSideFindView() {
- if (self.findState != .content) {
- return
- }
- if (self.searchResults.count > 0) {
- self.searchViewController.emptyBox.isHidden = true
- self.searchViewController.searchResultsView.isHidden = false
- self.searchViewController.searchResultsLabel.stringValue = String(format: KMLocalizedString("%ld Results", "Message in search table header"), self.searchResults.count)
- } else {
- self.searchViewController.emptyBox.isHidden = false
- self.searchViewController.searchResultsView.isHidden = true
- }
- }
-
- func displayGroupedFindViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.searchViewController.view , animate: animate)
- if (self.findState != .content) {
- self.findState = .content
- } else {
- self.displayFindState()
- }
-
- var frame = self.searchViewController.view.frame
- frame.origin.y = 0
- frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? 0
- self.searchViewController.view.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- self.updataLeftSideSnapView()
- }
-
- func displayNoteViewAnimating(_ animate: Bool) {
- self.searchViewController.contentView = nil
- self.replaceSideView(self.noteOutlineView.enclosingScrollView!, animate: animate)
- if (self.findState != .note) {
- self.findState = .note
- } else {
- self.displayFindState()
- }
-
- var frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- let view = self.noteOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
- self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
-
- DispatchQueue.main.async {
- self.noteOutlineView.reloadData()
- }
- }
-
- func displaySnapshotViewAnimating(_ animate: Bool) {
- self.searchViewController.contentView = nil
- self.replaceSideView(self.snapshotTableView.enclosingScrollView!, animate: animate)
- if (self.findState != .snapshot) {
- self.findState = .snapshot;
- } else {
- self.displayFindState()
- }
-
- var frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
- // frame.origin.y = 0;
- // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
- // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
-
- frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.tocOutlineView.enclosingScrollView?.frame = frame
-
- // [self updateSnapshotsIfNeeded];
- }
-
- func displayFind() {
- self.searchField = self.searchViewController.searchField
-
- let menu = NSMenu()
- menu.addItem(title: KMLocalizedString("Whole Words Only", "Menu item title"), action: #selector(toggleWholeWordSearch), target: self)
- menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveSearch), target: self)
- (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
- self.searchViewController.searchField.action = #selector(search)
- self.searchViewController.searchField.target = self
- if (self.findPaneState == .singular) {
- self.searchViewController.contentView = self.findTableView.enclosingScrollView
-
- self.findTableView.wantsLayer = true
- self.findTableView.layer?.backgroundColor = NSColor.red.cgColor
- DispatchQueue.main.async {
- self.findTableView.reloadData()
- }
- } else if (self.findPaneState == .grouped) {
- self.searchViewController.contentView = self.groupedFindTableView.enclosingScrollView
- var array = KMSearchMode.sortSearchResult(results: self.searchResults)
- array.sort(){$0.datas.count > $1.datas.count}
- self.groupSearchResults = array
- self.groupedFindTableView.reloadData()
- }
- }
-
- func displayTocViewAnimating(_ animate: Bool) {
- self.replaceSideView(self.tocOutlineView.enclosingScrollView!, animate: animate)
-
- var frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.tocOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.noteOutlineView.enclosingScrollView?.frame = frame
-
- frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
- frame.origin.y = 0
- frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
- self.snapshotTableView.enclosingScrollView?.frame = frame
-
- // [self updateOutlineSelection];
-
- let view = self.tocOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
-
- self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
- }
-
- override func requiresAlternateButton(forView aview: NSView?) -> Bool {
- return false
- }
-
- func displayNoteFind() {
- self.searchField = self.noteSearchField
-
- let menu = NSMenu()
- menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveNoteSearch), target: self)
- (self.noteSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.noteSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Notes", "placeholder")
- self.noteSearchField.action = #selector(searchNotes)
- self.noteSearchField.target = self
- }
-
- func displaySnapshotFind() {
- self.searchField = self.snapshotSearchField;
-
- let menu = NSMenu()
- menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveNoteSearch), target: self)
- (self.snapshotSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
- (self.snapshotSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Snapshots", "placeholder")
- self.snapshotSearchField.action = #selector(searchNotes)
- self.snapshotSearchField.target = self
- self.snapshotSearchField.delegate = self
- }
-
- /*
- - (void)applySearchTableHeader:(NSString *)message {
- [[[findTableView tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
- [[findTableView headerView] setNeedsDisplay:YES];
- [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell] setStringValue:message];
- [[groupedFindTableView headerView] setNeedsDisplay:YES];
- }
- - (void)displaySnapshotFind {
- }
- */
-
- @IBAction func search(_ sender: NSSearchField) {
- self.delegate?.searchAction?(searchString: sender.stringValue, isCase: false)
- }
-
- @IBAction func snapshotNormalSearchButtonAction(_ sender: NSButton) {
- self.snapshotSearchField.isHidden = false
- // _snapshotSearchZoomOutButton.hidden = YES;
- self.snapshotSearchZoomInButton.isHidden = true
- self.snapshotNormalSearchButton.isHidden = true
- self.snapshotDoneButton.isHidden = false
- self.snapshotLabel.isHidden = true
- self.snapshotNormalZoomOutButton.isHidden = true
- self.snapshotNormalZoomInButton.isHidden = true
-
- self.snapshotSearchField.becomeFirstResponder()
- }
-
- func resetThumbnails() {
- // [self willChangeValueForKey:THUMBNAILS_KEY];
-
- // self.thumbnailCacheSize = 160
-
- self.thumbnails.removeAll()
- let pageLabels = self.listView.document.pageLabels()
- if (pageLabels.isEmpty == false) {
- let isLocked = self.listView.document.isLocked
- let firstPage = self.listView.document.page(at: 0)
- // 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 firstPage = self.listView.document.page(at: UInt(i))
- let size = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
- let pageImage = firstPage!.thumbnail(of: size)
- let thumbnail = KMThumbnail(image: 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()
- }
- }
-
- @IBAction @objc func sortTypeAction(_ sender: NSMenuItem) {
- let item = sender
- let tag = item.tag
-
- if (item.state == .on) {
- item.state = .off
- } else {
- item.state = .on
- }
- if (tag == 0) {
- self.noteSortType = .page
- self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
- } else if (tag == 1) {
- self.noteSortType = .time
- self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
- self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
- }
- UserDefaults.standard.set(self.noteSortType.rawValue, forKey: KMLeftSideViewNoteSortTypeKey)
- UserDefaults.standard.synchronize()
- }
-
- @IBAction func noteSortAction(_ sender: AnyObject?) {
- if (self.isAscendSort) {
- self.isAscendSort = false
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
- self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
- } else {
- self.isAscendSort = true
- self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
- self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
- }
- UserDefaults.standard.setValue(self.isAscendSort, forKey: KMLeftSideViewAscendSortBoolKey)
- UserDefaults.standard.synchronize()
- }
-
- @IBAction func noteSearchAction(_ sender: NSButton) {
- self.noteSearchField.isHidden = false
- self.noteTitleLabel.isHidden = true
- self.noteSearchButton.isHidden = true
- self.noteDoneButton.isHidden = false
- self.noteFilterButton.isHidden = true
- self.noteMoreButton.isHidden = true
-
- self.noteSearchField.becomeFirstResponder()
- }
-
- @IBAction func leftSideViewDoneButtonAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
- let tag = button?.tag ?? 0
- if (tag == 310) {
- self.outlineSearchField.isHidden = true
- self.outlineDoneButton.isHidden = true
- self.outlineLabel.isHidden = false
- self.outlineSearchButton.isHidden = false
- self.outlineMoreButton.isHidden = false
- self.outlineAddButton.isHidden = false
- } else if (tag == 311) {
- self.noteSearchField.isHidden = true
- self.noteTitleLabel.isHidden = false
- self.noteSearchButton.isHidden = false
- self.noteDoneButton.isHidden = true
- self.noteFilterButton.isHidden = false
- self.noteMoreButton.isHidden = false
- } else if (tag == 312) {
- self.snapshotSearchField.isHidden = true
- // leftSideController.snapshotSearchZoomOutButton.hidden = YES;
- // leftSideController.snapshotSearchZoomInButton.hidden = YES;
- self.snapshotNormalSearchButton.isHidden = false
- self.snapshotDoneButton.isHidden = true
- self.snapshotLabel.isHidden = false
- self.snapshotNormalZoomOutButton.isHidden = false
- self.snapshotNormalZoomInButton.isHidden = false
- }
- }
-
- @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
- let tag = button?.tag ?? 0
- if (tag == 300) {
- // NSInteger selectedRow = 0;
- // if (rightSideController.snapshotTableView.selectedRow >= 0) {
- // selectedRow = rightSideController.snapshotTableView.selectedRow;
- // } else {
- // return;
- // }
- // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:selectedRow];
- // NSMenu *menu = [[[NSMenu alloc] init] autorelease];
- // NSMenuItem *itemExport = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil target:self];
- // NSMenu *subMenu = [NSMenu menu];
- //
- // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(menuItemClick_ExportPNG:) target:self];
- // [t setRepresentedObject:controller];
- //
- // t = [subMenu addItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(menuItemClick_ExportJPG:) target:self];
- // [t setRepresentedObject:controller];
- //
- // t = [subMenu addItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(menuItemClick_ExportPDF:) target:self];
- // [t setRepresentedObject:controller];
- // itemExport.submenu = subMenu;
- //
- // NSMenuItem *itemPrint = [menu addItemWithTitle:NSLocalizedString(@"Print", @"Menu item title") action:@selector(menuItemClick_Print:) target:self];
- // [itemPrint setRepresentedObject:controller];
- // [menu addItem:[NSMenuItem separatorItem]];
- //
- // NSMenuItem *itemSelectAll = [menu addItemWithTitle:NSLocalizedString(@"Select All", @"Menu item title") action:@selector(menuItemClick_SelectAll:) target:self];
- // [itemSelectAll setRepresentedObject:controller];
- // [menu addItem:[NSMenuItem separatorItem]];
- //
- // NSMenuItem *itemDeleteAllSnapshot = [menu addItemWithTitle:NSLocalizedString(@"Delete All Snapshots", @"Menu item title") action:@selector(deleteAllSnapshot:) target:self];
- // [itemDeleteAllSnapshot setRepresentedObject:controller];
- //
- // [NSMenu popUpContextMenu:menu withEvent:[NSApp currentEvent] forView:(NSButton *)sender];
- } else if (tag == 302) {
- let menu = NSMenu()
- // NSMenuItem *addEntryItem = [menu addItemWithTitle:NSLocalizedString(@"Add Item", nil) action:@selector(outlineContextMenuItemClicked_AddEntry:) target:self];
- // [addEntryItem setRepresentedObject:self.leftSideController.tocOutlineView];
- // NSMenuItem *addChildItem = [menu addItemWithTitle:NSLocalizedString(@"Add Sub-Item", nil) action:@selector(outlineContextMenuItemClicked_AddChildEntry:) target:self];
- // [addChildItem setRepresentedObject:self.leftSideController.tocOutlineView];
- // [menu addItem:[NSMenuItem separatorItem]];
- //
- // NSMenuItem *setDestinationItem = [menu addItemWithTitle:NSLocalizedString(@"Change Destination", nil) action:@selector(outlineContextMenuItemClicked_SetDestination:) target:self];
- // [setDestinationItem setRepresentedObject:self.leftSideController.tocOutlineView];
- // [menu addItem:[NSMenuItem separatorItem]];
- let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.tocOutlineView
- let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.tocOutlineView
- let item = self.listView.document.outlineRoot()
- var num = 0
- for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
- let outline = item?.child(at: UInt(i))
- if self.tocOutlineView.isItemExpanded(outline) {
- num += 1
- }
- }
- if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
- self.tocType = .fold
- } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
- self.tocType = .unfold
- } else {
- self.tocType = .none
- }
- if (self.tocType == .unfold) {
- expandAllCommentsItem?.state = .on
- foldAllCommentsItem?.state = .off
- } else if (self.tocType == .fold) {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .on
- } else {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .off
- }
- let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
- removeEntryItem?.representedObject = self.tocOutlineView
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
- } else if (tag == 304) {
- let menu = NSMenu()
- let object = KMPopupMenuObject()
- object.menuTag = 1001
- menu.delegate = object
- object.enterControllerCallback = { [weak self] isEnter in
- if (isEnter) {
- self?.moreButtonLayer?.isHidden = false
- } else {
- self?.moreButtonLayer?.isHidden = true
- }
- }
- let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.noteOutlineView
- let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
- foldAllCommentsItem?.representedObject = self.noteOutlineView
- if (self.foldType == .unfold) {
- expandAllCommentsItem?.state = .on
- foldAllCommentsItem?.state = .off
- } else if (self.foldType == .fold) {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .on
- } else {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .off
- }
- let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
- let subMenu = NSMenu()
- // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"Type", nil) action:@selector(noteShowNoteAction:) target:self];
- // if ([[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue]) {
- // [t setState:NSControlStateValueOff];
- // } else {
- // [t setState:NSControlStateValueOn];
- // }
- // [t setRepresentedObject:self.rightSideController.noteOutlineView];
- // t.tag = 100;
- var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
- let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
- if pageKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 101
- t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
- let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
- if timeKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 102
- t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
- let authorKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
- if authorKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 103
- showAnnotationItem?.submenu = subMenu
- menu.addItem(.separator())
- let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: ""), action: nil, target: self)
- let subMenu2 = NSMenu()
- var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 0
- t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 1
- t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 2
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 3
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 4
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 5
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 6
- exportAnnotationsItem?.submenu = subMenu2
- menu.addItem(.separator())
- let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
- removeAllAnnotationsItem?.representedObject = self.noteOutlineView
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: button!, with: nil)
- }
- }
-
- @IBAction func note_expandAllComments(_ sender: AnyObject?) {
- if (self.foldType == .unfold) {
- return
- }
- self.foldType = .unfold
- // [self loadUnfoldDate:KMFoldAllAnnotationType_None];
- self.noteOutlineView.reloadData()
- }
-
- @IBAction func note_foldAllComments(_ sender: AnyObject?) {
- if (self.foldType == .fold) {
- return
- }
- self.foldType = .fold
- // [self loadUnfoldDate:KMFoldAllAnnotationType_None];
- self.noteOutlineView.reloadData()
- }
- @IBAction func noteShowNoteAction(_ sender: AnyObject?) {
- let item = sender as? NSMenuItem
- let tag = item?.tag ?? 0
- if (tag == 100) {
- // BOOL isType = [[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue];
- // [self.noteTypeDict setObject:[NSNumber numberWithBool:!isType] forKey:@"kKMNoteFilterAnnotationTypeKey"];
- } else if (tag == 101) {
- let isPage = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
- self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] = isPage
- } else if (tag == 102) {
- let isTime = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
- self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] = isTime
- } else if (tag == 103) {
- let isAuther = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
- self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] = isAuther
- }
- UserDefaults.standard.set(self.noteTypeDict, forKey: "KMNoteOutlineViewTableColumnKey")
- UserDefaults.standard.synchronize()
-
- let selectRow = self.noteOutlineView.selectedRow
- self.noteOutlineView.reloadData()
- self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
- }
-
- @objc func exportAnnotationNotes(_ sender: AnyObject?) {
- // [self.document saveDocumentTo:sender];
- self.mainViewController.myDocument?.saveTo(sender)
- }
-
- @objc func leftSideEmptyAnnotationClick_DeleteAnnotation(_ sender: AnyObject?) {
- // NSAlert* alert = [[NSAlert alloc] init];
- // [alert setAlertStyle:NSAlertStyleCritical];
- // [alert setMessageText:NSLocalizedString(@"This will permanently remove all annotations. Are you sure to continue?", nil)];
- // [alert addButtonWithTitle:NSLocalizedString(@"Yes", nil)];
- // [alert addButtonWithTitle:NSLocalizedString(@"No", nil)];
- //
- // NSModalResponse response = [alert runModal];
- // if (response == NSAlertFirstButtonReturn) {
- // NSMutableArray *annotations = [NSMutableArray array];
- //
- // for (NSUInteger i = 0; i < self.pdfView.document.pageCount; i++) {
- // PDFPage *page = [[self.pdfView document] pageAtIndex:i];
- // for (PDFAnnotation *annotation in [page annotations]) {
- // if ([annotation isKindOfClass:[PDFAnnotationTextWidget class]] ||
- // [annotation isKindOfClass:[PDFAnnotationButtonWidget class]] ||
- // [annotation isKindOfClass:[PDFAnnotationChoiceWidget class]]) {
- // continue;
- // }
- // if (@available(macOS 10.13, *)) {
- // if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
- // continue;
- // }
- // }
- // if ([annotation isKindOfClass:[PDFAnnotationLink class]]) {
- // continue;
- // }
- // [annotations addObject:annotation];
- // }
- // }
- //
- // for (PDFAnnotation *annotation in annotations) {
- // [self.pdfView removeAnnotation:annotation];
- // }
- // }
- }
-
- @IBAction func noteFilterAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
-
- let menu = NSMenu()
- let filterViewController = KMNoteOutlineFilterViewController()
- // let object = KMPopupMenuObject()
- // menu.delegate = object
- // object.enterControllerCallback = {
- //
- // }
- //
- var notes = NSMutableArray()
- for section in self.annotationViewController.annotations {
- if section.annotations?.count != 0 {
- for item in section.annotations! {
- notes.add(item.annotation!)
- }
- }
- }
- filterViewController.setNotesArray(notes)
- filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
- menu.cancelTracking()
- if (isEmpty) {
- self?.filterButtonLayer?.isHidden = true
- } else {
- self?.filterButtonLayer?.isHidden = false
- }
- //
- // [blockSelf annotationSort:@[typeArr, colorArr, authorArr]];
- }
- filterViewController.cancelCallback = { isCancel in
- if (isCancel) {
- menu.cancelTracking()
- }
- }
- let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
- item.target = self
- item.representedObject = filterViewController
- item.view = filterViewController.view
- menu.popUp(positioning: nil, at: CGPointMake(-130, 30), in: button)
- }
-
- @IBAction func outlineNormalSearchButtonAction(_ sender: NSButton) {
- self.outlineSearchField.isHidden = false
- self.outlineDoneButton.isHidden = false
- self.outlineLabel.isHidden = true
- self.outlineSearchButton.isHidden = true
- self.outlineMoreButton.isHidden = true
- self.outlineAddButton.isHidden = true
-
- self.outlineSearchField.becomeFirstResponder()
- }
-
- @objc func outlineContextMenuItemClicked_AddEntry(_ sender: NSMenuItem) {
- // NSMutableArray *PDFOutlineArray = [[NSMutableArray new] autorelease];
- // NSIndexSet *rowSet = [self selectedRowIndexes] ;
- //
- // [rowSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- // [PDFOutlineArray addObject:[leftSideController.tocOutlineView itemAtRow:idx]];
- // }];
- //
- // if (PDFOutlineArray.count == 0) {
- // PDFOutline *lastPDFLine = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.numberOfRows - 1];
- //
- // PDFOutline *rootPDFOutline;
- // if (lastPDFLine) {
- // while (lastPDFLine.parent) {
- // lastPDFLine = lastPDFLine.parent;
- // }
- // rootPDFOutline = lastPDFLine;
- // } else {
- // rootPDFOutline = self.pdfView.document.outlineRoot;
- // if (!rootPDFOutline) {
- // rootPDFOutline = [[[PDFOutline alloc] init] autorelease];
- // [self.pdfView.document setOutlineRoot:rootPDFOutline];
- // }
- // }
- //
- // PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
- // addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
- // addOutLine.destination = self.pdfView.currentDestination;
- // [self addoutlineWithParent:rootPDFOutline addOutline:addOutLine index:rootPDFOutline.numberOfChildren needExpand:NO];
- //
- // } else {
- // PDFOutline *currentPDFline = PDFOutlineArray.lastObject;
- // NSInteger currentIndex = currentPDFline.index;
- // PDFOutline *parent;
- // parent = currentPDFline.parent;
- //
- // PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
- // addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
- // addOutLine.destination = self.pdfView.currentDestination;
- // [self addoutlineWithParent:parent addOutline:addOutLine index:currentIndex + 1 needExpand:NO];
- // [self.leftSideController.tocOutlineView scrollRowToVisible:currentIndex + 1];
- // [self.leftSideController.tocOutlineView deselectRow:currentIndex+1];
- //
- // }
- }
-
- @IBAction func toc_expandAllComments(_ sender: AnyObject?) {
- if (self.tocType == .unfold) {
- return
- }
- self.tocType = .unfold
- self.tocOutlineView.reloadData()
- self.tocOutlineView.expandItem(nil, expandChildren: true)
- }
-
- @IBAction func toc_foldAllComments(_ sender: AnyObject?) {
- if (self.tocType == .fold) {
- return
- }
- self.tocType = .fold
- self.tocOutlineView.reloadData()
- self.tocOutlineView.collapseItem(nil, collapseChildren: true)
- }
-
- @objc func leftSideEmptyAnnotationClick_DeleteOutline(_ sender: AnyObject?) {
- KMPrint("leftSideEmptyAnnotationClick_DeleteOutline")
- // NSAlert *alert = [[NSAlert alloc] init];
- // [alert setAlertStyle:NSAlertStyleCritical];
- // [alert setMessageText:@""];
- // [alert setInformativeText:NSLocalizedString(@"This will permanently remove all outlines. Are you sure to continue?", nil)];
- // [alert addButtonWithTitle:NSLocalizedString(@"Yes", nil)];
- // [alert addButtonWithTitle:NSLocalizedString(@"No", nil)];
- // NSModalResponse response = [alert runModal];
- // if (response == NSAlertFirstButtonReturn) {
- // PDFOutline * item = [[pdfView document] outlineRoot];
- // [self removeAllOutline:item];
- // }
- }
-
- @IBAction func thumbnailSizeScaling(_ sender: NSButton) {
- let sud = UserDefaults.standard
-
- let tag = sender.tag
- if (tag == 0 || tag == 1) {
- var scaling = sud.float(forKey: "KMThumbnailSizeScalingKey")
- if (scaling <= 0) {
- scaling = 1
- }
- if (tag == 0) { // thumbnail Zoom In
- scaling += 0.1
- } else if (tag == 1) { // thumbnail Zoom Out
- scaling -= 0.1
- }
- sud.setValue(scaling, forKey: "KMThumbnailSizeScalingKey")
- let selectRow = self.thumbnailTableView.selectedRow
- self.thumbnailTableView.reloadData()
-
- self.thumbnailTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
- } else if (tag == 2 || tag == 3) {
- var scaling = sud.float(forKey: "KMSnapshotSizeScalingKey")
- if (scaling <= 0) {
- scaling = 1
- }
-
- if (tag == 2) { // snapshot Zoom In
- scaling += 0.1
- } else if (tag == 3) { // snapshot Zoom Out
- scaling -= 0.1
- }
-
- sud.setValue(scaling, forKey: "KMSnapshotSizeScalingKey")
-
- let selectRow = self.snapshotTableView.selectedRow
- self.snapshotTableView.reloadData()
- self.snapshotTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
- }
- }
- }
- // MARK: - KMBotaTableViewDelegate
- extension KMLeftSideViewController: KMBotaTableViewDelegate {
-
- func tableView(_ aTableView: NSTableView, canCopyRowsWithIndexes rowIndexes: IndexSet) -> Bool {
- if aTableView.isEqual(to: self.thumbnailTableView) || aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
- return rowIndexes.count > 0
- }
- return false
- }
-
- func tableView(_ aTableView: NSTableView, canPasteFromPasteboard pboard: NSPasteboard) -> Bool {
- if aTableView.isEqual(to: self.thumbnailTableView) {
- if self._copysPages.count > 0 {
- return true
- }
- }
- return false
- }
-
- func tableView(_ aTableView: NSTableView, pasteFromPasteboard pboard: NSPasteboard) {
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
-
- if aTableView.isEqual(to: self.thumbnailTableView) {
- if self._copysPages.count > 0 {
- let index = self.listView.document.index(for: self.listView.currentPage()) + 1
- if (index == NSNotFound) {
- return
- }
- for page in self._copysPages.reversed() {
- if let newPage = page.copy() as? CPDFPage {
- self.listView.document.insertPageObject(newPage, at: index)
- }
- self.listView.layoutDocumentView()
- // [pageLabels setArray:[[pdfView document] pageLabels]];
- self.resetThumbnails()
- let pageIndex = min(index, self.listView.document.pageCount-1)
- self.listView.go(toPageIndex: Int(pageIndex), animated: true)
- // [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
- }
- }
- }
- }
-
- func tableViewMoveLeft(_ aTableView: NSTableView) {
- if aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
- // [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
- }
- }
-
- func tableViewMoveRight(_ aTableView: NSTableView) {
- if aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
- // [self updateFindResultHighlightsForDirection:NSSelectingNext];
- }
- }
-
- func tableView(_ aTableView: NSTableView, imageContextForRow rowIndex: Int) -> AnyObject? {
- if aTableView.isEqual(to: self.findTableView) {
- if rowIndex >= self.searchResults.count {
- return nil
- }
- let model = self.searchResults[rowIndex]
- let selection = model.selection
- let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
- return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
- } else if aTableView.isEqual(to: self.groupedFindTableView) {
- if rowIndex >= self.groupSearchResults.count {
- return nil
- }
- // let model = self.groupSearchResults[rowIndex]
- // let selection = model.selection
- // let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
- // return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
- }
- return nil
- }
-
- /*
- - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- return pageLabels;
- }
- return nil;
- }
- - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
- }
- }
- - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
- if ([tv isEqual:leftSideController.thumbnailTableView]) {
- if (searchString.length > 0)
- [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
- else
- [self updateLeftStatus];
- }
- }
- */
-
- }
- // MARK: - KMThumbnailTableViewDelegate
- extension KMLeftSideViewController: KMThumbnailTableViewDelegate {
- func tableView(_ tableView: NSTableView, highlightLevelForRow row: Int) -> UInt {
- if tableView.isEqual(to: self.thumbnailTableView) {
- // NSUInteger i, iMax = [lastViewedPages count];
- // for (i = 0; i < iMax; i++) {
- // if (row == (NSInteger)[lastViewedPages pointerAtIndex:i])
- // return i;
- // }
- }
- return UInt.max
- }
-
- func tableView(_ tableView: NSTableView, commandSelectRow rowIndex: Int) -> Bool {
- if tableView.isEqual(to: self.thumbnailTableView) {
- // NSRect rect = [[[pdfView document] pageAtIndex:row] boundsForBox:kPDFDisplayBoxCropBox];
- //
- // rect.origin.y = NSMidY(rect) - 0.5 * SNAPSHOT_HEIGHT;
- // rect.size.height = SNAPSHOT_HEIGHT;
- // [self showSnapshotAtPageNumber:row forRect:rect scaleFactor:[pdfView scaleFactor] autoFits:NO];
- let thumbailTabCell = tableView.view(atColumn: 0, row: rowIndex, makeIfNecessary: true) as? KMThumbnailTableviewCell
- thumbailTabCell?.isSelectCell = true
- var rowIndexSet = IndexSet()
- for i in self.thumbnailTableView.selectedRowIndexes {
- rowIndexSet.insert(i)
- }
- rowIndexSet.insert(rowIndex)
- self.thumbnailTableView.selectRowIndexes(rowIndexSet, byExtendingSelection: true)
- return true
- }
- return false
- }
-
- func tableView(_ tableView: NSTableView, shiftSelectRow rowIndex: Int) -> Bool {
- if tableView.isEqual(to: self.thumbnailTableView) {
- if (self.thumbnailTableView.selectedRowIndexes.count == 0) {
- let thumbailTabCell = tableView.view(atColumn: 0, row: rowIndex, makeIfNecessary: true) as? KMThumbnailTableviewCell
- thumbailTabCell?.isSelectCell = true
- var rowIndexSet = IndexSet()
- self.thumbnailTableView.selectRowIndexes(rowIndexSet, byExtendingSelection: true)
- return true
- } else if (self.thumbnailTableView.selectedRowIndexes.count == 1 && self.thumbnailTableView.selectedRowIndexes.first == rowIndex) {
- return false
- } else {
- var fristIndex = self.thumbnailTableView.selectedRowIndexes.first ?? Int.min
- var lastIndex = self.thumbnailTableView.selectedRowIndexes.last ?? Int.max
- for idx in self.thumbnailTableView.selectedRowIndexes {
- // [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if(idx < fristIndex) {
- fristIndex = idx
- }
- if(idx > lastIndex) {
- lastIndex = idx
- }
- }
-
- if(rowIndex < fristIndex) {
- fristIndex = rowIndex
- } else if (rowIndex > lastIndex) {
- lastIndex = rowIndex
- }
- var rowIndexSet = IndexSet()
- for i in fristIndex ... lastIndex {
- rowIndexSet.insert(i)
- }
- self.thumbnailTableView.selectRowIndexes(rowIndexSet, byExtendingSelection: true)
- return true
- }
- }
- return false
- }
- }
- //MARK: 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
- } else if tableView.isEqual(to: self.groupedFindTableView) {
- return self.groupSearchResults.count
- }
- return 0
- }
-
- func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- if tableView.isEqual(to: self.thumbnailTableView) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMThumbnailTableviewCell"), owner: self) as! KMThumbnailTableviewCell
- let thumbnail = self.thumbnails[row]
- cell.pageNumLabel.stringValue = thumbnail.label
- // cell.thumImage.image = thumbnail.image
- cell.pageView.page = self.listView.document.page(at: UInt(row))
- if let _image = thumbnail.image {
- let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
- let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
- if (_image.size.height > _image.size.width) {
- NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
- // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
- // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
- } else {
- NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
- // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
- // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
- }
- }
- if (self.isDisplayPageSize) {
- cell.sizeLabel.isHidden = false
- //获取Page的真实尺寸
- let page = self.listView.document.page(at: UInt(row))
- let rect = page?.bounds(for: .cropBox) ?? .zero
- let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
- let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
- if let data = page?.rotation, data == 90 || data == 270 {
- cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
- } else {
- cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
- }
- } else {
- cell.sizeLabel.isHidden = true
- }
- cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
- if(self.thumbnailTableView.selectedRowIndexes.contains(row)) {
- cell.isSelectCell = true
- } else {
- cell.isSelectCell = false
- }
- return cell
- } else if (tableView.isEqual(to: self.findTableView)) {
- let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMFindTableviewCell"), owner: self) as! KMFindTableviewCell
- let selection = searchResults[row]
- if let data = tableColumn?.identifier.rawValue, data == "results" {
- cell.resultLabel.attributedStringValue = selection.selection.attributedString()
- cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
- } else if let data = tableColumn?.identifier.rawValue, data == "page" {
- cell.resultLabel.stringValue = selection.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
- } else if tableView.isEqual(to: self.groupedFindTableView) {
- return 16
- }
- return tableView.rowHeight
- }
-
- func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
- if (tableView.isEqual(to: self.findTableView)) {
- let rowView = KMCustomTableRowView()
- return rowView
- } else if tableView.isEqual(to: self.groupedFindTableView) {
- let rowView = KMGroupFindTableRowView()
- rowView.totalNumber = self.groupSearchResults.first?.datas.count ?? 0
- let model = self.groupSearchResults[row]
- rowView.number = model.datas.count
- rowView.pageIndex = Int(model.selectionPageIndex) + 1
- return rowView
- }
- return nil
- }
-
- func tableViewSelectionIsChanging(_ notification: Notification) {
- KMPrint(self.thumbnailTableView.selectedRowIndexes)
- }
- func tableViewSelectionDidChange(_ notification: Notification) {
- // if ([[aNotification object] isEqual:leftSideController.findTableView] || [[aNotification object] isEqual:leftSideController.groupedFindTableView]) {
- // [self updateFindResultHighlightsForDirection:NSDirectSelection];
- //
- // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- // [self hideLeftSideWindow];
- // } else
- if self.thumbnailTableView.isEqual(to: notification.object) {
- // if (mwcFlags.updatingThumbnailSelection == 0) {
- let row = self.thumbnailTableView.selectedRow
- let curPage = self.listView.document.index(for: self.listView.currentPage())
-
- if (row != -1 && row != curPage) {
- // [pdfView goToPage:[[pdfView document] pageAtIndex:row]];
- self.listView.go(toPageIndex: row, animated: true)
- }
-
- // if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
- // [self hideLeftSideWindow];
-
- // thumbnailSelectCount = row;
- // var rowIndexSet = IndexSet()
- // for i in 0 ..< self.thumbnailTableView.numberOfRows {
- // rowIndexSet.insert(i)
- // }
- // self.thumbnailTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: IndexSet(integer: 0))
- // }
- let view = self.thumbnailTableView.view(atColumn: 0, row: self.preThumbnailRow, makeIfNecessary: false) as? KMThumbnailTableviewCell
- view?.isSelectCell = false
-
- let view2 = self.thumbnailTableView.view(atColumn: 0, row: row, makeIfNecessary: false) as? KMThumbnailTableviewCell
- view2?.isSelectCell = true
-
- self.preThumbnailRow = row
- }
- // else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
- // NSInteger row = [rightSideController.snapshotTableView selectedRow];
- // [selectCellList removeAllObjects];
- // [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
- // if (row != -1) {
- // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
- // if ([[controller window] isVisible])
- // [[controller window] orderFront:self];
- // }
- // NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- // for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
- // [rowIndexSet addIndex:i];
- // }
- // NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- // [columnIndexSet addIndex:0];
- // [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
- //
- // }
- }
-
- /*
- //- (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)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]];
- }
- }
- - (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];
-
- #pragma mark dragging
- - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
- {
- if (dropOperation == NSTableViewDropOn || ![tableView isEqual:leftSideController.thumbnailTableView]) {
- return NSDragOperationNone;
- }
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
- return NSDragOperationMove;
- } else if ([pboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]){
- NSArray *fileNames = [pboard propertyListForType:NSFilenamesPboardType];
- if (fileNames.count == 1) {
- NSString *path = fileNames.firstObject;
- NSString *pathExtension = [path.pathExtension lowercaseString];
- if ([pathExtension isEqualToString:@"pdf"] ||
- [[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
- return NSDragOperationMove;
- }
- } else {
- return NSDragOperationNone;
-
- }
- }
- return NSDragOperationNone;
- }
- - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {
- __block BOOL result = NO;
- if (![tableView isEqual:leftSideController.thumbnailTableView]) {
- return result;
- }
- NSPasteboard *pasteboard = [info draggingPasteboard];
-
- if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
- result = YES;
- NSData *rowData = [pasteboard dataForType:KPDFThumbnailLocalForDraggedTypes];
- NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
- NSData *urlData = [pasteboard dataForType:KPDFThumbnailDoucumentURLForDraggedTypes];
- NSString *url = [NSKeyedUnarchiver unarchiveObjectWithData:urlData];
- if(![url isEqualToString:[pdfView document].documentURL.absoluteString] && url) {
- if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
- NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
- if (fileNames.count == 1) {
- NSString *path = fileNames.firstObject;
- NSString *pathExtension = [path.pathExtension lowercaseString];
- if ([pathExtension isEqualToString:@"pdf"]) {
- __block NSInteger index = row;
- __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]] autorelease];
- if ([pdf isEncrypted]) {
- KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
- vc.filePath = url;
- [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
- if (password) {
- [pdf unlockWithPassword:password];
- for(NSUInteger i=0; i<pdf.pageCount;i++) {
- PDFPage *page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- }];
- [vc release];
- } else {
- for(NSUInteger i=0; i<pdf.pageCount;i++) {
- PDFPage *page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- return YES;
- }
- }
- }
- }
- __block NSInteger pageIndex = 0;
- __block NSMutableArray *pages = [NSMutableArray array];
- [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- PDFPage *page = [[[pdfView document] pageAtIndex:idx] copy];
- [pages addObject:page];
- [page release];
- }];
- PDFPage *toPage = nil;
- if (row < (NSInteger)pdfView.document.pageCount) {
- toPage = [pdfView.document pageAtIndex:row];
- }
- __block NSInteger toPageIndex = 0;
- if (toPage) {
- toPageIndex = [pdfView.document indexForPage:toPage];
- } else {
- toPageIndex = pdfView.document.pageCount;
- }
- for(NSUInteger i = 0;i<pages.count;i++) {
- PDFPage *page = pages[i];
- [pdfView.document insertPage:page atIndex:toPageIndex+i];
- pageIndex += 1;
- [self.pdfView goToPage:page];
- }
- [self.pdfView layoutDocumentView];
- __block NSMutableArray *deletepages = [NSMutableArray array];
- [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
- if((NSInteger)idx < toPageIndex) {
- if((idx+pageIndex) < pdfView.document.pageCount) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx];
- [deletepages addObject:page];
- [pdfView.document removePageAtIndex:idx];
- }
- } else {
- if((idx+pageIndex) < pdfView.document.pageCount) {
- PDFPage *page = [[pdfView document] pageAtIndex:idx+pageIndex];
- [deletepages addObject:page];
- [pdfView.document removePageAtIndex:idx+pageIndex];
- }
- }
- }];
- [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
- [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
- [self.pdfView layoutDocumentView];
- [self resetThumbnails];
-
- } else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
- if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
- [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- return NO;
- }
-
- NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
- NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
- __block NSInteger index = row;
- if (fileNames.count == 1) {
- NSString *path = fileNames.firstObject;
- NSString *pathExtension = [path.pathExtension lowercaseString];
- if ([pathExtension isEqualToString:@"pdf"]) {
- PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
- if ([pdf isEncrypted]) {
- KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
- vc.filePath = path;
- [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
- if (password) {
- [pdf unlockWithPassword:password];
- for (NSUInteger i = 0; i< pdf.pageCount; i++) {
- PDFPage *page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- }];
- [vc release];
- } else {
- for (NSUInteger i = 0; i < pdf.pageCount; i++) {
- PDFPage * page = [[pdf pageAtIndex:i] copy];
- [self.pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- index++;
- [page release];
- }
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
-
- }
- } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
- NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
- PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
- [pdfView.document insertPage:page atIndex:index];
- [insertIndexSet addIndex:index];
- [self insertPages:insertIndexSet pageAtIndex:(index-1)];
- }
- result = YES;
- } else {
- result = NO;
- }
- }
- return result;
- }
- */
- }
- // MARK: - NSOutlineViewDelegate, NSOutlineViewDataSource
- /*
-
- func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
- if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?[index] as Any
- } else if item is KMBOTAAnnotationItem {
- return item as Any
- } else {
- var tempArray: [KMBOTAAnnotationSection] = []
- for temp in self.data {
- if temp.annotations?.count != 0 {
- tempArray.append(temp)
- }
- }
- let section = tempArray[index]
- return section as Any
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
- if item is KMBOTAAnnotationItem {
- let cell : KMAnnotationOutlineCellView = KMAnnotationOutlineCellView.init()
- cell.delegate = self
- cell.model = item as? KMBOTAAnnotationItem
- return cell
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
-
- let cell : KMAnnotationOutlineSectionView = KMAnnotationOutlineSectionView.init()
- cell.model = section
- return cell
- }
- return NSTableCellView()
- }
-
- func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
- let rowView = KMAnnotationOutlineRowView()
- if item is KMBOTAAnnotationItem {
- rowView.model = (item as? KMBOTAAnnotationItem)
- } else if item is KMBOTAAnnotationSection {
- rowView.section = (item as? KMBOTAAnnotationSection)
- }
- rowView.mouseDownAction = { [unowned self] view, event in
- if rowView.section != nil {
- let expanded = outlineView.isItemExpanded(outlineView.item(atRow: outlineView.selectedRow))
- if expanded {
- outlineView.collapseItem(outlineView.item(atRow: outlineView.selectedRow), collapseChildren: true)
- outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
- } else {
- outlineView.expandItem(outlineView.item(atRow: outlineView.selectedRow), expandChildren: true)
- outlineView.reloadItem(outlineView.item(atRow: outlineView.selectedRow))
- }
- } else if rowView.model != nil {
- self.didSelectItem(view: rowView, event: event)
- }
- }
-
- rowView.rightMouseDownAction = { [unowned self] view, event in
- if rowView.section != nil {
-
- } else if rowView.model != nil {
- if !KMOCToolClass.arrayContains(array: self.selectItems, annotation: item) ||
- self.selectItems.count == 1 {
- self.selectItem(item: item as! KMBOTAAnnotationItem)
- }
-
- DispatchQueue.main.async {
- self.delegate?.annotationOutlineView(self, rightMouseDownDidSelectView: view, evnet: event)
- }
- }
- }
-
- rowView.hoverCallback = { [unowned self] (mouseEntered, mouseBox) in
- self.outlineView.enumerateAvailableRowViews { view, row in
- if view is KMAnnotationOutlineRowView {
- (view as? KMAnnotationOutlineRowView)?.model?.hover = false
- (view as? KMAnnotationOutlineRowView)?.reloadData()
- }
- }
- if mouseEntered {
- rowView.model?.hover = true
- } else {
- rowView.model?.hover = false
- }
- }
- return rowView
- }
-
- func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
- if item is KMBOTAAnnotationItem {
- return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: self.maxWidth - 16, height: 1000))
- } else if item is KMBOTAAnnotationSection {
- return 40
- } else {
- return 30
- }
- }
-
- func outlineViewSelectionDidChange(_ notification: Notification) {
- if self.outlineView.selectedRow == -1 {
- self.cancelSelect()
- }
- }
-
- func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
- if item is KMBOTAAnnotationItem {
- return false
- } else if item is KMBOTAAnnotationSection {
- let section = item as? KMBOTAAnnotationSection
- return section!.annotations?.count ?? 0 > 0
- }
- return false
- }
-
- func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
- if let item = item as? KMBOTAAnnotationSection {
- if !item.isItemExpanded {
- item.isItemExpanded = true
- outlineView.animator().expandItem(item, expandChildren: true)
- return false
- }
- }
- return true
- }
- func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool {
- if let item = item as? KMBOTAAnnotationSection {
- if item.isItemExpanded {
- item.isItemExpanded = false
- outlineView.animator().collapseItem(item, collapseChildren: true)
- return false
- }
- }
- return true
- }
- */
- extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSource {
- func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let isLocked = self.listView.document?.isLocked ?? true
- if item == nil && isLocked == false {
- var item = self.listView.document.outlineRoot()
- if let data = item?.numberOfChildren, data == 0 && !self.isSearchOutlineMode {
- let view = self.tocOutlineView.enclosingScrollView!
- let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
- //
- self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
-
- self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
- self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
- } else {
- self.leftSideEmptyVC.emptyOutlineView.removeFromSuperview()
- self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = true
- }
- 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];
- }
- }
-
- let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
- // var bookMarks: [KMBookMarkItem] = []
- // for bookMark in array {
- // let item = KMBookMarkItem()
- // item.bookMark = bookMark
- // item.index = UInt(bookMark.pageIndex)
- // item.label = bookMark.label
- // bookMarks.append(item)
- // }
- var bookmarkNum = 0
- if array.isEmpty == false {
- bookmarkNum = 1
- }
- return Int(item?.numberOfChildren ?? 0) + bookmarkNum
- }
- 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];
- }
- // if item is CPDFBookmark {
- // return 0
- // }
- // return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
- let array = self.listView.document?.bookmarks() ?? [CPDFBookmark]()
- if let data = item as? String, data == "Bookmarks" {
- return array.count
- } else if item is CPDFOutline {
- // return Int(item?.numberOfChildren ?? 0)
- return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
- } else if item is CPDFBookmark {
- return 0
- }
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- var count = 0
- for section in self.annotationViewController.annotations {
- if section.annotations?.count != 0 {
- count += section.annotations!.count
- }
- }
- // if (item == nil){
- // NSInteger count = [[rightSideController.noteArrayController arrangedObjects] count];
-
- if (count < 1) {
- // if (notes.count < 1) {
- // leftSideController.noteSearchButton.enabled = NO;
- // leftSideController.noteFilterButton.enabled = NO;
- // }
- self.noteOutlineView.usesAlternatingRowBackgroundColors = false
- let view = self.noteOutlineView.enclosingScrollView!
- var emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
- self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
-
- self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
- self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
- self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
- //
- if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
- self.noteHeaderView.isHidden = true
- self.toolButtonBoxLayoutConstraint.constant = 40.0
- }
- } else {
- self.noteSearchButton.isEnabled = true
- self.noteFilterButton.isEnabled = true
- self.noteOutlineView.usesAlternatingRowBackgroundColors = false
- self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
- self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
- self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
- //
- if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
- self.noteHeaderView.isHidden = false
- self.toolButtonBoxLayoutConstraint.constant = 64.0
- }
- }
- return count;
- // } else {
- // return [item hasNoteText];
- // }
- }
- return 0
- }
-
- func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
- var bookmarkNum = 0
- if array.isEmpty == false {
- bookmarkNum = 1
- }
-
- if item == nil && self.listView.document.isLocked == false {
- if index == 0 && bookmarkNum == 1 {
- return "Bookmarks"
- } else {
- var _index = bookmarkNum == 1 ? index-1 : index
- var _item: CPDFOutline?
- _item = self.listView.document.outlineRoot()
- var obj = _item?.child(at: UInt(_index))
- return obj as Any
- }
- } else {
- if let data = item as? String, data == "Bookmarks" {
- return array[index]
- } else if item is CPDFOutline {
- return (item as! CPDFOutline).child(at: UInt(index))
- } else if item is CPDFBookmark {
- // return nil?
- }
- }
- // 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];
- var tempArray: [KMBOTAAnnotationItem] = []
- for secion in self.annotationViewController.annotations {
- if secion.annotations?.count != 0 {
- for _item in secion.annotations! {
- tempArray.append(_item)
- }
- }
- }
- return tempArray[index] as Any
- }
- return item
- }
-
- func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
- if outlineView.isEqual(to: self.tocOutlineView) {
- // let tcID = tableColumn?.identifier.rawValue ?? ""
- // var ol = item as? CPDFOutline
- // if(tcID == LABEL_COLUMNID) {
- // if (self.isSearchOutlineMode) {
- //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- //// NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
- //// NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
- //// for (NSUInteger i = 0; i <arr.count ; i++) {
- //// NSValue * rangeValue = arr[i];
- //// NSRange range = rangeValue.rangeValue;
- //// range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
- //// [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
- //// }
- //// [attributeString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:NSMakeRange(0, roughString.length)];
- //// return attributeString;
- // } else {
- // var attributedString = NSMutableAttributedString()
- //// attributedString
- // attributedString.append(.init(string: ol?.label ?? "", attributes: [.foregroundColor : KMAppearance.Layout.h0Color()]))
- //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
- //// NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- //// NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- //// [attributedString appendAttributedString:attr1];
- //
- // return attributedString
- // }
- //
- // }
- // else if([tcID isEqualToString:PAGE_COLUMNID]) {
- // NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
- // NSString *roughString = [ol pageLabel]? : @"";
- // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
- // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
- // [attributedString appendAttributedString:attr1];
- //
- // return attributedString;
- // }
-
- }
- // else if ([ov isEqual:rightSideController.noteOutlineView]) {
- // NSString *tcID = [tableColumn identifier];
- // PDFAnnotation *note = item;
- // if (tableColumn == nil || [tcID isEqualToString:NOTE_COLUMNID])
- // return [note objectValue];
- // else if([tcID isEqualToString:TYPE_COLUMNID]){
- // NSString *noteType = [note type];
- // if ([note isKindOfClass:[PDFAnnotationButtonWidget class]]) {
- // PDFAnnotationButtonWidget *buttonWidget = (PDFAnnotationButtonWidget *)note;
- // if (buttonWidget.controlType == kPDFWidgetRadioButtonControl) {
- // noteType = SKAnnotationFormRadioButtonKey;
- // } else if (buttonWidget.controlType == kPDFWidgetCheckBoxControl){
- // noteType = SKAnnotationFormCheckBoxKey;
- // } else if (buttonWidget.controlType == kPDFWidgetPushButtonControl){
- // noteType = SKAnnotationFormActionButtonKey;
- // }
- // } else if ([note isKindOfClass:[PDFAnnotationTextWidget class]]){
- // noteType = SKAnnotationFormTextFieldKey;
- // } else if ([note isKindOfClass:[PDFAnnotationChoiceWidget class]]){
- // PDFAnnotationChoiceWidget *choiceWidget = (PDFAnnotationChoiceWidget *)note;
- // if (choiceWidget.isListChoice) {
- // noteType = SKAnnotationFormListMenuKey;
- // } else {
- // noteType = SKAnnotationFormComboBoxKey;
- // }
- //
- // }
- // return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:note == [pdfView activeAnnotation]], SKAnnotationTypeImageCellActiveKey, noteType, SKAnnotationTypeImageCellTypeKey,[note color],SKAnnotationTypeImageCellColorKey, nil];
- // }
- // else if([tcID isEqualToString:COLOR_COLUMNID])
- // return [note type] ? [note color] : nil;
- // else if([tcID isEqualToString:PAGE_COLUMNID])
- // return [[note page] displayLabel];
- // else if([tcID isEqualToString:AUTHOR_COLUMNID])
- // return [note type] ? [note userName] : nil;
- // else if([tcID isEqualToString:DATE_COLUMNID])
- // return [note type] ? [note modificationDate] : nil;
- // }
- return nil
- }
-
- func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
- if outlineView.isEqual(to: self.tocOutlineView) {
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMTocTableCellView"), owner: self) as! KMTocTableCellView
- let tcID = tableColumn?.identifier.rawValue
-
- var title = ""
- if let data = item as? String, data == "Bookmarks" {
- title = NSLocalizedString("Bookmarks", comment: "")
- } else if item is CPDFOutline {
- title = (item as! CPDFOutline).label
- } else if item is CPDFBookmark {
- title = (item as! CPDFBookmark).label
- }
-
- 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 = title
- }
- // TODO: 不确定是哪个字段
- cell.pageLabel.stringValue = ""
- }
- // else if([tcID isEqualToString:PAGE_COLUMNID]) {
- // cell.pageLabel.stringValue = [ol pageLabel];
- // }
- return cell
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- let note = (item as! KMBOTAAnnotationItem).annotation!
- let cell = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMNoteTableViewCell"), owner: self) as! KMNoteTableViewCell
- cell.cellNote = note
-
- let noteColor = note.color
- var noteType = note.type ?? ""
- var noteString = note.string() ?? ""
- // NSString *pageString = [[note page] displayLabel] ? : @"";
- var pageString = note.page.label ?? ""
- let date = note.modificationDate()
- var authorString = note.userName() ?? ""
- // NSString *noteTextString = [note noteText].string ? : @"";
- var noteTextString = note.string() ?? ""
- //
- // if([noteType isEqualToString:@"Redact"]) {
-
- // noteString = @"Redact";
- // }
- //
- let timeKey = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool
- if timeKey == nil || timeKey == false {
- if (date != nil) {
- cell.timeLabel.stringValue = CPDFAnnotationModel.timeString(withTime: date)
-
- } else {
- cell.timeLabel.stringValue = ""
- }
- cell.timeLabel.isHidden = false
- } else {
- cell.timeLabel.isHidden = true
- }
-
- let pageKey = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool
- if pageKey == nil || pageKey == false {
- let labelsize = cell.pageLabel.stringValue.boundingRect(with: CGSizeMake(CGFloat(MAXFLOAT),CGRectGetHeight(cell.pageLabel.bounds)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font : NSFont.systemFont(ofSize: 12)])
- cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5
- cell.pageLabel.stringValue = pageString
- cell.pageLabel.isHidden = false
- } else {
- cell.pageLabel.isHidden = true
- }
-
- let autherKey = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool
- if pageKey == nil || pageKey == false {
- cell.autherLabel.stringValue = authorString
- cell.autherLabel.isHidden = false
- } else {
- cell.autherLabel.isHidden = true
- }
- let imageView = KMNoteTypeImageView()
- if note.isKind(of: CPDFStampAnnotation.self) {
- let annotation_stamp = note as! CPDFStampAnnotation
- if (annotation_stamp.stampImage() != nil) {
- noteType = SKNStampString
- }
- } else if note.isKind(of: CPDFLineAnnotation.self) {
- let annotation_line = note as! CPDFLineAnnotation
- if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .none {
- noteType = SKNLine_NoneString
- } else if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .openArrow {
- noteType = SKNLine_OpenArrowString
- } else {
- noteType = SKNLine_NoneString
- }
- } else if note.isKind(of: CPDFButtonWidgetAnnotation.self) {
- let buttonWidget = note as! CPDFButtonWidgetAnnotation
- if buttonWidget.controlType() == .radioButtonControl {
- noteType = KMAnnotationFormRadioButtonKey
- } else if buttonWidget.controlType() == .checkBoxControl {
- noteType = KMAnnotationFormCheckBoxKey
- } else if buttonWidget.controlType() == .pushButtonControl {
- noteType = KMAnnotationFormActionButtonKey
- }
- } else if note.isKind(of: CPDFTextWidgetAnnotation.self) {
- noteType = KMAnnotationFormTextFieldKey
- } else if note.isKind(of: CPDFChoiceWidgetAnnotation.self) {
- let choiceWidget = note as! CPDFChoiceWidgetAnnotation
- if choiceWidget.isListChoice {
- noteType = KMAnnotationFormListMenuKey
- } else {
- noteType = KMAnnotationFormComboBoxKey
- }
- } else if note.isKind(of: KMTableAnnotation.self) {
- noteType = "Ink_Table"
- } else if note.isKind(of: KMSelfSignAnnotation.self) {
- let selfSignNote = note as! KMSelfSignAnnotation
- if selfSignNote.annotationType == .signFalse {
- noteType = "KMSelfSignTypeFalseActionButtonKey"
- } else if (selfSignNote.annotationType == .signature) {
- noteType = "KMSelfSignTypeTureActionButtonKey"
- } else if (selfSignNote.annotationType == .signCircle) {
- noteType = "KMSelfSignTypeCircleActionButtonKey"
- } else if (selfSignNote.annotationType == .signLine) {
- noteType = "KMSelfSignTypeLineActionButtonKey"
- } else if (selfSignNote.annotationType == .signDot) {
- noteType = "KMSelfSignTypeDotActionButtonKey"
- } else if (selfSignNote.annotationType == .signText) {
- noteType = "KMSelfSignTypeTextActionButtonKey"
- }
- } else if note.isKind(of: CPDFSquareAnnotation.self) {
- noteType = SKNSquareString
- } else if note.isKind(of: CPDFTextAnnotation.self) {
- noteType = SKNNoteString
- }
-
- cell.typeImageView.image = imageView.noteTypeImage(withType: noteType, color: noteColor ?? .red)
- cell.typeImageView.isHidden = false
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- cell.isFold = true
- }
- cell.noteContentBox.isHidden = true
- cell.noteImageView.isHidden = true
- cell.foldButton.isHidden = true
- cell.annotationContentLabel.isHidden = false
- cell.noteContentLabel.stringValue = noteString
- cell.contentView.isHidden = false
- cell.contentViewHidden(false)
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- let markup = note as! CPDFMarkupAnnotation
- if(noteTextString.isEmpty == false) {
- cell.foldButton.isHidden = false
- }
- var attributeStr = NSMutableAttributedString(string: noteTextString)
- if (markup.markupType() == .highlight) {
- attributeStr.addAttribute(.backgroundColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
- } else if (markup.markupType() == .strikeOut) {
- attributeStr.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
- attributeStr.addAttribute(.strikethroughColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
- } else if (markup.markupType() == .underline) {
- attributeStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: NSMakeRange(0, noteTextString.count))
- attributeStr.addAttribute(.underlineColor, value: noteColor as Any, range: NSMakeRange(0, noteTextString.count))
- }
- cell.annotationContentLabel.attributedStringValue = attributeStr
- if (self.foldType == .unfold) {
- cell.isFold = false
- } else if (self.foldType == .fold) {
- cell.isFold = true
- } else {
- // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
- // cell.isFold = NO;
- // } else {
- // cell.isFold = YES;
- // }
- }
- if (noteString.isEmpty == false && noteTextString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- } else if note.isKind(of: CPDFLineAnnotation.self) || noteType == SKNSquareString || noteType == SKNCircleString || noteType == SKNInkString {
- cell.annotationContentLabel.stringValue = noteString
- if (noteString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- } else if note.isKind(of: CPDFStampAnnotation.self) {
- if note.isKind(of: KMSelfSignAnnotation.self) {
- let newAnnotation = note as! KMSelfSignAnnotation
- let type = newAnnotation.annotationType
- var returnString = ""
- if (type == .signFalse) {
- returnString = KMLocalizedString("X", nil)
- } else if (type == .signature) {
- returnString = KMLocalizedString("Check mark", nil)
- } else if (type == .signCircle) {
- returnString = KMLocalizedString("Circle", nil)
- } else if (type == .signLine) {
- returnString = KMLocalizedString("Line", nil)
- } else if (type == .signDot) {
- returnString = KMLocalizedString("Dot", nil)
- } else if (type == .signText) {
- returnString = KMLocalizedString("Text", nil)
- }
- cell.annotationContentLabel.stringValue = returnString
- } else {
- cell.annotationContentLabel.isHidden = true
- cell.noteImageView.isHidden = false
- // PDFAnnotation *annotation = note;
- // NSImage *stampImage = [self stampCreateImage:annotation];
- // if (stampImage) {
- // cell.noteImageView.image = [self stampCreateImage:annotation];
- // } else {
- // cell.noteImageView.hidden = YES;
- // [cell contentViewHidden:YES];
- // }
- }
- }
- // else if ([note isKindOfClass:[SKNPDFAnnotationNote class]]) {
- // cell.foldButton.hidden = NO;
- // if (!noteString || noteString.length < 1){
- // cell.annotationContentLabel.stringValue = noteTextString;
- // }else{
- // cell.annotationContentLabel.stringValue = noteString;
- // cell.noteContentLabel.stringValue = noteTextString;
- // }
- //
- // if (self.foldType == KMFoldAllAnnotationType_Unfold) {
- // cell.isFold = NO;
- // } else if (self.foldType == KMFoldAllAnnotationType_Fold) {
- // cell.isFold = YES;
- // } else {
- // if (rightSideController.allFoldNotes.count > 0 && [rightSideController.allFoldNotes containsObject:note]) {
- // cell.isFold = NO;
- // } else {
- // cell.isFold = YES;
- // }
- // }
- // if (noteString.length > 0 || noteTextString.length > 0) {
- // cell.contentView.hidden = NO;
- // } else {
- // cell.contentView.hidden = YES;
- // [cell contentViewHidden:YES];
- // }
- // if (noteString.length > 0 && noteTextString.length > 0) {
- // cell.foldButton.hidden = NO;
- // }else{
- // cell.foldButton.hidden = YES;
- // }
- //
- // }
- else {
- cell.annotationContentLabel.stringValue = noteString
- cell.imageViewHeightConstraint.constant = cell.contentView.frame.size.height
- if (noteString.isEmpty == false) {
- cell.contentViewHidden(false)
- } else {
- cell.contentViewHidden(true)
- }
- }
- //
- cell.autherLayoutConstraint.constant = cell.autherLabel.isHidden ? -(cell.autherLabel.bounds.size.width) + 10.0 : 10.0
- cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.isHidden ? -(cell.typeImageView.bounds.size.width) : 0.0
- cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.isHidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0
- if note.isKind(of: CPDFStampAnnotation.self) && note.isKind(of: KMSelfSignAnnotation.self) == false {
- //
- } else {
- if note.isKind(of: CPDFMarkupAnnotation.self) {
- if (!cell.isFold) {
- // [rightSideController.allFoldNotes addObject:note];
- } else {
- cell.imageViewHeightConstraint.constant = 18.0 + 8
- }
- } else {
- cell.imageViewHeightConstraint.constant = 18.0 + 8
- }
- }
- // cell.isUnFoldNote = ^(PDFAnnotation *cellNote, BOOL isUnfold) {
- // if (isUnfold) {
- // if ([rightSideController.allFoldNotes containsObject:note]) {
- // [rightSideController.allFoldNotes removeObject:note];
- // }
- //
- // if (rightSideController.allFoldNotes.count == 0) {
- // self.foldType = KMFoldAllAnnotationType_Fold;
- // } else {
- // self.foldType = KMFoldAllAnnotationType_None;
- // }
- // } else {
- // if (![rightSideController.allFoldNotes containsObject:note]) {
- // [rightSideController.allFoldNotes addObject:note];
- // }
- //
- // if (rightSideController.allFoldNotes.count == rightSideController.canFoldNotes.count) {
- // self.foldType = KMFoldAllAnnotationType_Unfold;
- // } else {
- // self.foldType = KMFoldAllAnnotationType_None;
- // }
- // }
- // };
- return cell
- }
- return nil
- }
-
- func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
- if outlineView.isEqual(self.noteOutlineView) {
- if item is KMBOTAAnnotationItem {
- return KMBOTAAnnotationTool.fetchCellHeight(annotation: (item as? KMBOTAAnnotationItem)!.annotation!, maxSize: CGSize(width: 260+40 - 16, height: 1000))
- }
- return 30
- } else if outlineView.isEqual(self.tocOutlineView) {
- if item is CPDFOutline {
- let tempItem = item as! CPDFOutline
- let string: NSString = tempItem.label as NSString
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineHeightMultiple = 1.32
- paragraphStyle.alignment = .left
- let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle,
- NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0)]
- let size = string.boundingRect(with: CGSizeMake(outlineView.frame.size.width - 30, 200), options: NSString.DrawingOptions(rawValue: 3), attributes: attributes)
- return max(40, size.height + 16)
- }
- return 40
- }
- return outlineView.rowHeight
- }
-
- func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
- if outlineView.isEqual(self.tocOutlineView) {
- // var _item: CPDFOutline?
- // if item == nil && self.listView.document.isLocked == false {
- // _item = self.listView.document.outlineRoot()
- // }
- if let data = item as? String, data == "Bookmarks" {
- return true
- } else if item is CPDFOutline {
- return ((item as! CPDFOutline).numberOfChildren ?? 0) != 0
- } else if item is CPDFBookmark {
- return false
- }
-
- if (self.isSearchOutlineMode) {
- // return [self subOutLineContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:(PDFOutline *)item];
- } else {
- // return ((_item?.numberOfChildren ?? 0) != 0)
- }
- } else if outlineView.isEqual(to: self.noteOutlineView) {
- // return [item hasNoteText];
- return false
- }
- return false
- }
-
- func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
- if outlineView.isEqual(self.tocOutlineView) {
- let itemView = KMCustomTableRowView()
- return itemView
- } else if outlineView.isEqual(self.noteOutlineView) {
- let itemView = KMCustomTableRowView()
- return itemView;
- }
- return nil
- }
-
- /*
- #pragma mark NSOutlineView datasource protocol
- - (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item{
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- PDFAnnotation *note = item;
- if ([note type]) {
- if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID]) {
- if ([(object ?: @"") isEqualToString:([note string] ?: @"")] == NO)
- [note setString:object];
- } else if ([[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
- if ([(object ?: @"") isEqualToString:([note userName] ?: @"")] == NO)
- [note setUserName:object];
- }
- }
- }
- }
- #pragma mark Drag
- - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard{
-
- if ([outlineView isEqual:leftSideController.tocOutlineView]) {
- if (leftSideController.tocOutlineView.selectedRowIndexes.count > 1) {
- return NO;
- }
- NSIndexSet *tIndex = [[[NSIndexSet alloc] initWithIndex:leftSideController.tocOutlineView.clickedRow] autorelease];
- [leftSideController.tocOutlineView deselectRow:tIndex.firstIndex];
- self.dragPDFOutline = items.firstObject;
- NSIndexSet *set = [NSIndexSet indexSetWithIndex:0];
- NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:set];
- [pasteboard declareTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType] owner:self];
- [pasteboard setData:zNSIndexSetData forType:kKMPDFViewOutlineDragDataType];
- return YES;
- }
- return NO;
- }
- - (NSDragOperation)outlineView:(NSOutlineView *)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)anIndex {
- NSDragOperation dragOp = NSDragOperationNone;
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
- anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
- dragOp = NSDragOperationEvery;
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (anIndex == -1) {
- dragOp = NSDragOperationNone;
- } else {
- dragOp = NSDragOperationMove;
- }
- }
- return dragOp;
- }
- - (BOOL)outlineView:(NSOutlineView *)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)anIndex {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSPasteboard *pboard = [info draggingPasteboard];
- if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]]) {
- BOOL isShift = ([NSEvent standardModifierFlags] & NSEventModifierFlagShift) != 0;
- BOOL isAlt = ([NSEvent standardModifierFlags] & NSEventModifierFlagOption) != 0;
- [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
- return YES;
- }
- } else if ([ov isEqual:leftSideController.tocOutlineView]) {
- if (anIndex < 0) {
- return NO;
- }
- PDFOutline *outline = item;
-
- //root,drag item to root
- if (!outline.parent) {
- //fetch root
- PDFOutline *root = self.dragPDFOutline;
- while (root.parent) {
- root = root.parent;
- }
- if ([self.dragPDFOutline.parent isEqual:root]) {
- if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
- } else {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:root];
- }
- } else {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:root];
- }
- } else {
- //在同一个层级内移动
- if ([self.dragPDFOutline.parent isEqual:item]) {
- if (self.dragPDFOutline.index) {
- if (self.dragPDFOutline.index > (NSUInteger)anIndex) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
- }else{
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex - 1 newParentOutline:outline];
- }
- } else {
- return NO;
- }
- } else {
- PDFOutline *tOutlline = outline;
- BOOL isContains = NO;
- while (tOutlline) {
- if ([tOutlline isEqual:self.dragPDFOutline]) {
- isContains = YES;
- break;
- }
- tOutlline = tOutlline.parent;
- }
- if (!isContains) {
- [self dragPDFOutline:self.dragPDFOutline toIndex:anIndex newParentOutline:outline];
- }
- }
- }
- return YES;
- }
- return NO;
- }
- #pragma mark NSOutlineView delegate protocol
- - (NSCell *)outlineView:(NSOutlineView *)ov dataCellForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
- if ([ov isEqual:rightSideController.noteOutlineView] && tableColumn == nil && [(PDFAnnotation *)item type] == nil) {
- return [[ov tableColumnWithIdentifier:NOTE_COLUMNID] dataCellForRow:[ov rowForItem:item]];
- }
- return [tableColumn dataCellForRow:[ov rowForItem:item]];
- }
- - (void)outlineView:(NSOutlineView *)ov willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
- if ([ov isEqual:leftSideController.tocOutlineView] &&
- [ov selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular &&
- [ov isRowSelected:[ov rowForItem:item]]) {
- [cell setBackgroundStyle:NSBackgroundStyleLowered];
- }
- }
- - (BOOL)outlineView:(NSOutlineView *)ov shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item{
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- if (tableColumn == nil) {
- if ([pdfView hideNotes] == NO && [[(SKNoteText *)item note] isNote]) {
- PDFAnnotation *annotation = [(SKNoteText *)item note];
- [pdfView scrollAnnotationToVisible:annotation];
- [pdfView setActiveAnnotation:annotation];
- [self showNote:annotation];
- SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
- [[noteController window] makeFirstResponder:[noteController textView]];
- [[noteController textView] selectAll:nil];
- }
- return NO;
- } else if ([[tableColumn identifier] isEqualToString:NOTE_COLUMNID] || [[tableColumn identifier] isEqualToString:AUTHOR_COLUMNID]) {
- return YES;
- }
- }
- return NO;
- }
- - (void)outlineView:(NSOutlineView *)ov didClickTableColumn:(NSTableColumn *)tableColumn {
- if ([ov isEqual:rightSideController.noteOutlineView]) {
- NSTableColumn *oldTableColumn = [ov highlightedTableColumn];
- NSTableColumn *newTableColumn = ([NSEvent modifierFlags] & NSEventModifierFlagCommand) ? nil : tableColumn;
- NSMutableArray *sortDescriptors = nil;
- BOOL ascending = YES;
- if ([oldTableColumn isEqual:newTableColumn]) {
- sortDescriptors = [[[rightSideController.noteArrayController sortDescriptors] mutableCopy] autorelease];
- [sortDescriptors replaceObjectAtIndex:0 withObject:[[sortDescriptors firstObject] reversedSortDescriptor]];
- ascending = [[sortDescriptors firstObject] ascending];
- } else {
- NSString *tcID = [newTableColumn identifier];
- NSSortDescriptor *pageIndexSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationPageIndexKey ascending:ascending] autorelease];
- NSSortDescriptor *boundsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKPDFAnnotationBoundsOrderKey ascending:ascending selector:@selector(compare:)] autorelease];
- sortDescriptors = [NSMutableArray arrayWithObjects:pageIndexSortDescriptor, boundsSortDescriptor, nil];
- if ([tcID isEqualToString:TYPE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationTypeKey ascending:YES selector:@selector(noteTypeCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:COLOR_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationColorKey ascending:YES selector:@selector(colorCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:NOTE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationStringKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:AUTHOR_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationUserNameKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
- } else if ([tcID isEqualToString:DATE_COLUMNID]) {
- [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationModificationDateKey ascending:YES] autorelease] atIndex:0];
- }
- if (oldTableColumn)
- [ov setIndicatorImage:nil inTableColumn:oldTableColumn];
- [ov setHighlightedTableColumn:newTableColumn];
- }
- [rightSideController.noteArrayController setSortDescriptors:sortDescriptors];
- if (newTableColumn)
- [ov setIndicatorImage:[NSImage imageNamed:ascending ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
- inTableColumn:newTableColumn];
- [ov reloadData];
- }
- }
- - (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 {
-
- }
- - (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];
- }
- }
- */
- }
- extension KMLeftSideViewController: NSSearchFieldDelegate {
-
- }
- extension KMLeftSideViewController: NSMenuDelegate {
- func menuNeedsUpdate(_ menu: NSMenu) {
- if menu.isEqual(to: self.tocOutlineView.menu) {
- return
- }
- var item: NSMenuItem?
- menu.removeAllItems()
- if menu.isEqual(to: self.thumbnailTableView.menu) {
- let row = self.thumbnailTableView.clickedRow
- if self.listView.document.documentURL == nil || self.thumbnailTableView.selectedRowIndexes.contains(row) == false{
- return
- }
- if (row != -1 && self.listView.document.isLocked == false) {
- if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
- item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: nil, target: self)
- } else {
- item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: #selector(cutPage), target: self)
- }
- item?.representedObject = IndexSet(integer: row)
-
-
- item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(copyPage), target: self)
- item?.representedObject = IndexSet(integer: row)
-
- if (self._copysPages.count > 0) {
- item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: #selector(pastePage), target: self)
- }else{
- item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: nil, target: self)
- }
- item?.representedObject = IndexSet(integer: row)
- menu.addItem(.separator())
- if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: nil, target: self)
- } else {
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deletePage), target: self)
- }
- item?.representedObject = IndexSet(integer: row)
- menu.addItem(.separator())
- item = menu.addItem(title: KMLocalizedString("Rotate", "Menu item title"), action: #selector(rotatePage), target: self)
- item?.representedObject = IndexSet(integer: row)
- item = menu.addItem(title: KMLocalizedString("Insert", "Menu item title"), action: nil, target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: KMLocalizedString("Blank Page", "Menu item title"), action: #selector(quickInsert), target: self)
- subMenu.addItem(title: KMLocalizedString("Blank Page - Custom...", "Menu item title"), action: #selector(insert), target: self)
- subMenu.addItem(title: KMLocalizedString("From PDF", "Menu item title"), action: #selector(insertPDF), target: self)
- item?.submenu = subMenu
- item?.representedObject = IndexSet(integer: row)
- item = menu.addItem(title: KMLocalizedString("Extract", "Menu item title"), action: #selector(extractPage), target: self)
- item?.representedObject = IndexSet(integer: row)
- item = menu.addItem(title: KMLocalizedString("Page Edit", "Menu item title"), action: #selector(pageEdit), target: self)
- menu.addItem(.separator())
- var displayStr = ""
- if (self.isDisplayPageSize) {
- displayStr = KMLocalizedString("Hide Page Size", "Menu item title")
- } else {
- displayStr = KMLocalizedString("Display Page Size", "Menu item title")
- }
- item = menu.addItem(title: displayStr, action: #selector(displayPageSize), target: self)
- item?.representedObject = IndexSet(integer: row)
-
- item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
- // NSString * tName = [self fileNameWithSelectedPages:leftSideController.thumbnailTableView.selectedRowIndexes];
- // if (tName.length > 50) {
- // tName = [tName substringWithRange:NSMakeRange(0, 50)];
- // }
- var tName = self.listView.document.documentURL.lastPathComponent
- item?.submenu = NSSharingServicePicker.menu(forSharingItems: [self.listView.document.documentURL], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
- }
- } else if menu.isEqual(to: self.findTableView.menu) {
- var rowIndexes = self.findTableView.selectedRowIndexes
- var row = self.findTableView.clickedRow
- if (row != -1) {
- if rowIndexes.contains(row) == false {
- rowIndexes = IndexSet(integer: row)
- }
- // NSArray *selections = [[leftSideController.findArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
- // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
- item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 0)
- //// [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 1)
- //// [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 2)
- //// [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 3)
- //// [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 4)
- // [item setRepresentedObject:selections];
- // }
- }
- } else if menu.isEqual(to: self.groupedFindTableView.menu) {
- var rowIndexes = self.groupedFindTableView.selectedRowIndexes
- var row = self.groupedFindTableView.clickedRow
- if (row != -1) {
- if rowIndexes.contains(row) == false {
- rowIndexes = IndexSet(integer: row)
- }
- // NSArray *selections = [[[leftSideController.groupedFindArrayController arrangedObjects] objectsAtIndexes:rowIndexes] valueForKeyPath:@"@unionOfArrays.matches"];
- item = menu.addItem(title: KMLocalizedString("Select", "Menu item title"), action: #selector(selectSelections), target: self)
- // [item setRepresentedObject:selections];
- menu.addItem(.separator())
- // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
- item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 0)
- // [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 1)
- // [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 2)
- // [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 3)
- // [item setRepresentedObject:selections];
- item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: 4)
- // [item setRepresentedObject:selections];
- // }
- }
- }
- // else if ([menu isEqual:[rightSideController.snapshotTableView menu]]) {
- // NSInteger row = [rightSideController.snapshotTableView clickedRow];
- // if (row != -1) {
- // SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
- //
- // if ([[controller window] isVisible]) {
- // item = [menu addItemWithTitle:NSLocalizedString(@"Hide", @"Menu item title") action:@selector(hideSnapshot:) target:self];
- // [item setRepresentedObject:controller];
- // } else {
- // item = [menu addItemWithTitle:NSLocalizedString(@"Show", @"Menu item title") action:@selector(showSnapshot:) target:self];
- // [item setRepresentedObject:controller];
- // }
- // [menu addItem:[NSMenuItem separatorItem]];
- //
- // item = [menu addItemWithTitle:NSLocalizedString(@"Export", @"Menu item title") action:nil target:self];
- // NSMenu *subMenu = [NSMenu menu];
- //
- // NSMenuItem *t = [subMenu addItemWithTitle:NSLocalizedString(@"PNG", @"Menu item title") action:@selector(menuItemClick_ExportPNG:) target:self];
- // [t setRepresentedObject:controller];
- //
- // t = [subMenu addItemWithTitle:NSLocalizedString(@"JPG", @"Menu item title") action:@selector(menuItemClick_ExportJPG:) target:self];
- // [t setRepresentedObject:controller];
- //
- // t = [subMenu addItemWithTitle:NSLocalizedString(@"PDF", @"Menu item title") action:@selector(menuItemClick_ExportPDF:) target:self];
- // [t setRepresentedObject:controller];
- // item.submenu = subMenu;
- //
- // item = [menu addItemWithTitle:NSLocalizedString(@"Print", @"Menu item title") action:@selector(menuItemClick_Print:) target:self];
- // [item setRepresentedObject:controller];
- // [menu addItem:[NSMenuItem separatorItem]];
- //
- // item = [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") action:@selector(menuItemClick_Copy:) target:self];
- // [item setRepresentedObject:controller];
- // [menu addItem:[NSMenuItem separatorItem]];
- //
- // item = [menu addItemWithTitle:NSLocalizedString(@"Delete", @"Menu item title") action:@selector(deleteSnapshot:) target:self];
- // [item setRepresentedObject:controller];
- // item = [menu addItemWithTitle:NSLocalizedString(@"Delete All Snapshots", @"Menu item title") action:@selector(deleteAllSnapshot:) target:self];
- // [item setRepresentedObject:controller];
- // }
- // }
- else if menu.isEqual(to: self.noteOutlineView.menu) {
- // NSArray *items;
- var rowIndexes = self.noteOutlineView.selectedRowIndexes
- let row = self.noteOutlineView.clickedRow
- if (row != -1) {
- if rowIndexes.contains(row) == false {
- rowIndexes = IndexSet(integer: row)
- // items = [rightSideController.noteOutlineView itemsAtRowIndexes:rowIndexes];
-
- // PDFAnnotation *foldNote = (PDFAnnotation *)notes[row];
- var isFold = true
- // if ([rightSideController.allFoldNotes containsObject:foldNote]) {
- // isFold = NO;
- // }
- item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
- if (isFold) {
- item?.state = .off
- } else {
- item?.state = .on
- }
- // [item setRepresentedObject:items];
- item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
- if (isFold) {
- item?.state = .on
- } else {
- item?.state = .off
- }
- // [item setRepresentedObject:items];
-
- //UX改版删除
- // if ([self outlineView:rightSideController.noteOutlineView canCopyItems:items]) {
- // item = [menu addItemWithTitle:NSLocalizedString(@"Copy", @"Menu item title") action:@selector(copyNotes:) target:self];
- // [item setRepresentedObject:items];
- // }
- menu.addItem(.separator())
- if self.listView.hideNotes == false {
- // if ([pdfView hideNotes] == NO && [items count] == 1) {
- // PDFAnnotation *annotation = [[self noteItems:items] lastObject];
- // if ([annotation isEditable]) {
- // if ([(PDFAnnotation *)[items lastObject] type] == nil) {
- // if ([[(SKNoteText *)[items lastObject] note] isNote]) {
- // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editNoteTextFromTable:) target:self];
- // [item setRepresentedObject:annotation];
- // }
- // } else if ([[rightSideController.noteOutlineView tableColumnWithIdentifier:NOTE_COLUMNID] isHidden]) {
- // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
- // [item setRepresentedObject:annotation];
- // } else {
- // item = [menu addItemWithTitle:NSLocalizedString(@"Edit", @"Menu item title") action:@selector(editNoteFromTable:) target:self];
- // [item setRepresentedObject:annotation];
- // item = [menu addItemWithTitle:[NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis] action:@selector(editThisAnnotation:) target:pdfView];
- // [item setRepresentedObject:annotation];
- // [item setKeyEquivalentModifierMask:NSEventModifierFlagOption];
- // [item setAlternate:YES];
- // }
- // }
- // if ([pdfView hideNotes] == NO && [[self pdfDocument] allowsNotes]) {
- // if ([pdfView activeAnnotation] == annotation) {
- // item = [menu addItemWithTitle:NSLocalizedString(@"Deselect", @"Menu item title") action:@selector(deselectNote:) target:self];
- // [item setRepresentedObject:annotation];
- // } else {
- // item = [menu addItemWithTitle:NSLocalizedString(@"Select", @"Menu item title") action:@selector(selectNote:) target:self];
- // [item setRepresentedObject:annotation];
- // }
- // item = [menu addItemWithTitle:NSLocalizedString(@"Show", @"Menu item title") action:@selector(revealNote:) target:self];
- // [item setRepresentedObject:annotation];
- // }
- // }
- // if ([menu numberOfItems] > 0)
- // [menu addItem:[NSMenuItem separatorItem]];
- // item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Auto Size Row", @"Menu item title") : NSLocalizedString(@"Auto Size Rows", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
- // [item setRepresentedObject:items];
- // item = [menu addItemWithTitle:[items count] == 1 ? NSLocalizedString(@"Undo Auto Size Row", @"Menu item title") : NSLocalizedString(@"Undo Auto Size Rows", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
- // [item setRepresentedObject:items];
- // [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
- // [item setAlternate:YES];
- // [menu addItemWithTitle:NSLocalizedString(@"Auto Size All", @"Menu item title") action:@selector(autoSizeNoteRows:) target:self];
- // item = [menu addItemWithTitle:NSLocalizedString(@"Undo Auto Size All", @"Menu item title") action:@selector(resetHeightOfNoteRows:) target:self];
- // [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
- // [item setAlternate:YES];
- // [menu addItemWithTitle:NSLocalizedString(@"Automatically Resize", @"Menu item title") action:@selector(toggleAutoResizeNoteRows:) target:self];
-
- if menu.numberOfItems > 0 {
- item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-
- let subMenu = NSMenu()
- item?.submenu = subMenu
- item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 0
- item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 1
- item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 2
- item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 3
- item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 4
- item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 5
- item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 6
-
- menu.addItem(.separator())
- // if ([self outlineView:rightSideController.noteOutlineView canDeleteItems:items]) {
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
- // [item setRepresentedObject:items];
- // }
- item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
- }
- }
- }
- }
- }
- // else {
- // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Export Annotations…", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- //
- // NSMenu *subMenu = [NSMenu menu];
- // item.submenu = subMenu;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 0;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Bundle", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 1;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"PDF Reader Pro Edition Notes", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 2;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as Text", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 3;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 4;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as RTFD", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 5;
- // item = [subMenu addItemWithTitle:NSLocalizedStringFromTable(@"Notes as FDF", @"MainMenu", @"Menu item title") action:@selector(exportAnnotationNotes:) target:self];
- // item.tag = 6;
- //
- // item = [menu addItemWithTitle:NSLocalizedStringFromTable(@"Remove All Annotations", @"MainMenu", @"Menu item title") action:@selector(removeAllAnnotations:) target:self];
- // }
- // }
- }
- }
- // MARK: - Menu Item Actions
- extension KMLeftSideViewController {
- @objc func cutPage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-cutPage...")
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- // [self tableView:leftSideController.thumbnailTableView cutRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
- }
-
- @objc func copyPage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-copyPage...")
- // [self tableView:leftSideController.thumbnailTableView copyRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
- }
-
- @objc func pastePage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-pastePage...")
- // [self tableView:leftSideController.thumbnailTableView pasteFromPasteboard:nil];
- }
-
- @objc func deletePage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-deletePage...")
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- // [self tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
- }
-
- @objc func rotatePage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-rotatePage...")
- // if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
- // [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
- // return;
- // }
- //
- // [self tableView:leftSideController.thumbnailTableView rotateRowsWithIndexes:leftSideController.thumbnailTableView.selectedRowIndexes];
- }
-
- @objc func quickInsert(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-quickInsert...")
- }
-
- @objc func insert(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-insert...")
- }
-
- @objc func insertPDF(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-insertPDF...")
- }
-
- @objc func extractPage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-extractPage...")
- }
-
- @objc func pageEdit(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-pageEdit...")
- }
-
- @objc func displayPageSize(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-displayPageSize...")
- }
-
- @objc func sharePage(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-sharePage...")
- }
-
-
- @objc func unfoldNoteAction(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-unfoldNoteAction...")
- }
-
- @objc func foldNoteAction(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-foldNoteAction...")
- }
-
- @objc func deleteNotes(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-deleteNotes...")
- }
-
- @objc func removeAllAnnotations(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-removeAllAnnotations...")
- }
-
- @objc func addAnnotationsForSelections(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-addAnnotationsForSelections...")
- }
-
- @objc func selectSelections(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-selectSelections...")
- }
-
- @objc func toggleWholeWordSearch(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-toggleWholeWordSearch...")
- }
-
- @objc func toggleCaseInsensitiveSearch(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-toggleCaseInsensitiveSearch...")
- }
-
- @objc func toggleCaseInsensitiveNoteSearch(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-toggleCaseInsensitiveNoteSearch...")
- }
-
- @objc func searchNotes(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-searchNotes...")
- }
-
- private func _tableView(_ tv: NSTableView, cutRowsWithIndexes rowIndexes: IndexSet) {
- // if tv.isEqual(to: self.thumbnailTableView) {
- // self._copysPages.removeAll()
- // for i in rowIndexes {
- // if (idx != NSNotFound) {
- // let page = self.listView.document.page(at: idx)
- // self._copysPages.append(page)
- // }
- // }
- // [self tableView:tv deleteRowsWithIndexes:rowIndexes];
- // }
- }
- }
- // MARK: - Other
- extension KMLeftSideViewController {
- @objc func goToSelectedOutlineItem(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-goToSelectedOutlineItem...")
- // PDFOutline *outlineItem = [leftSideController.tocOutlineView itemAtRow:[leftSideController.tocOutlineView selectedRow]];
- // NSOutlineView *outline = (NSOutlineView *)leftSideController.tocOutlineView;
- // if (outline.selectedRowIndexes.count == 1) {
- // if ([outlineItem destination])
- // [pdfView goToDestination:[outlineItem destination]];
- // else if ([outlineItem action])
- // [pdfView performAction:[outlineItem action]];
- // }
- }
-
- @objc func goToSelectedFindResults(_ sender: AnyObject?) {
- KMPrint("KMLeftSideViewController-goToSelectedFindResults...")
- }
- }
|