KMLeftSideViewController.swift 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380
  1. //
  2. // KMLeftSideViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lxy on 2022/10/10.
  6. //
  7. import Cocoa
  8. @objc protocol KMLeftSideViewControllerDelegate {
  9. @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
  10. @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
  11. @objc optional func searchAction(searchString:String, isCase:Bool)
  12. @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
  13. @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
  14. @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
  15. @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
  16. }
  17. extension KMLeftSideViewController.Key {
  18. static let disableTableToolTipsKey = "SKDisableTableToolTips"
  19. }
  20. class KMLeftSideViewController: KMSideViewController {
  21. var dataSource : [KMLeftMethodMode] = [KMLeftMethodMode]()
  22. var type : KMLeftMethodMode = KMLeftMethodMode()
  23. var isShowPanel : Bool = false
  24. var norImage : [String] = []
  25. var selectImage : [String] = []
  26. var mainVC: KMMainViewController?
  27. var selectPages: [Int]?
  28. open weak var delegate: KMLeftSideViewControllerDelegate?
  29. let noteColumnId = NSUserInterfaceItemIdentifier(rawValue: "note")
  30. let authorColumnId = NSUserInterfaceItemIdentifier(rawValue: "author")
  31. struct Key {}
  32. let scalingIncrement: Float = 0.1
  33. deinit {
  34. KMPrint("KMLeftSideViewController deinit.")
  35. NotificationCenter.default.removeObserver(self)
  36. DistributedNotificationCenter.default().removeObserver(self)
  37. }
  38. override var nibName: NSNib.Name? {
  39. return "LeftSideView"
  40. }
  41. convenience init(type : KMLeftMethodMode) {
  42. self.init()
  43. self.type = type
  44. }
  45. override func viewDidLoad() {
  46. super.viewDidLoad()
  47. self.reloadThumbnailSize()
  48. self.reloadSnapshotSize()
  49. // DistributedNotificationCenter.default().addObserver(self, selector: #selector(interfaceThemeDidChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  50. }
  51. func showPanelView(show: Bool) {
  52. self.isShowPanel = show
  53. if show {
  54. self.leftView.segmentedControl.selectedSegment = 0
  55. } else {
  56. self.leftView.segmentedControl.selectedSegment = UInt8.max
  57. self.type.methodType = .None
  58. self.delegate?.controlStateChange?(self, show: false)
  59. }
  60. }
  61. func refreshMethodType(methodType: BotaType) {
  62. let newType = KMLeftMethodMode()
  63. var show = true
  64. if self.type.methodType != methodType {
  65. newType.methodType = methodType
  66. }
  67. if self.type.methodType == methodType {
  68. show = false
  69. } else if methodType == .None {
  70. show = false
  71. }
  72. self.type = newType;
  73. self.delegate?.controlStateChange?(self,show:show)
  74. }
  75. // MARK: - New
  76. /*
  77. NSArrayController *findArrayController;
  78. NSArrayController *groupedFindArrayController;
  79. }
  80. */
  81. @IBOutlet var segmentedControl: KMSegmentedControl!
  82. @IBOutlet var thumbnailTableView: KMThumbnailTableView!
  83. @IBOutlet var tocOutlineView: KMTocOutlineView!
  84. @IBOutlet var noteOutlineView: KMNoteOutlineView!
  85. @IBOutlet var findTableView: KMBotaTableView!
  86. @IBOutlet var groupedFindTableView: KMBotaTableView!
  87. @IBOutlet var snapshotTableView: KMBotaTableView!
  88. @IBOutlet weak var leftListView: NSView!
  89. @IBOutlet var searchViewController: KMBotaSearchViewController!
  90. @IBOutlet weak var toolButtonBox: NSBox!
  91. @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
  92. @IBOutlet weak var snapshotNormalView: NSView!
  93. @IBOutlet weak var snapshotLabel: NSTextField!
  94. @IBOutlet weak var snapshotNormalMoreButton: NSButton!
  95. @IBOutlet weak var snapshotNormalSearchButton: NSButton!
  96. @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
  97. @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
  98. @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
  99. @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
  100. @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
  101. @IBOutlet weak var snapshotDoneButton: NSButton!
  102. @IBOutlet weak var outlineView: NSView!
  103. @IBOutlet weak var outlineMoreButton: NSButton!
  104. @IBOutlet weak var outlineAddButton: NSButton!
  105. @IBOutlet weak var outlineSearchButton: NSButton!
  106. @IBOutlet weak var outlineLabel: NSTextField!
  107. @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
  108. @IBOutlet weak var outlineDoneButton: NSButton!
  109. @IBOutlet weak var noteView: NSView!
  110. @IBOutlet weak var noteMoreButton: NSButton!
  111. @IBOutlet weak var noteFilterButton: NSButton!
  112. @IBOutlet weak var noteSearchButton: NSButton!
  113. @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
  114. @IBOutlet weak var noteTitleLabel: NSTextField!
  115. @IBOutlet weak var noteHeaderView: NSView!
  116. @IBOutlet weak var sortTypeBox: KMBox!
  117. @IBOutlet weak var sortTypeLabel: NSTextField!
  118. @IBOutlet weak var noteSortButton: NSButton!
  119. @IBOutlet weak var noteDoneButton: NSButton!
  120. @IBOutlet weak var thumbnailView: NSView!
  121. @IBOutlet weak var thumbnailZoomOutButton: NSButton!
  122. @IBOutlet weak var thumbnailZoomInButton: NSButton!
  123. @IBOutlet weak var thumbnailTitleLabel: NSTextField!
  124. @IBOutlet weak var emptySearchBox: NSBox!
  125. @IBOutlet weak var emptySearchLabel: NSTextField!
  126. var filterButtonLayer: NSView?
  127. var moreButtonLayer: KMButtonLayer?
  128. var thumbnails: [KMThumbnail] = []
  129. var isDisplayPageSize = false
  130. var thumbnailCacheSize: CGFloat = 32 * 3
  131. var snapshotCacheSize: CGFloat = 32 * 3
  132. private var _findState: KMFindState = .none
  133. var findState: KMFindState {
  134. get {
  135. return self._findState
  136. }
  137. set {
  138. if self._findState != newValue {
  139. self._findState = newValue
  140. self.displayFindState()
  141. if self._findState == .content {
  142. self.search(self.searchField)
  143. } else if self.findState == .note {
  144. // self.searchNotes(self.searchField)
  145. self.searchNotes(nil)
  146. } else if self.findState == .snapshot {
  147. self.searchNotes(self.searchField)
  148. }
  149. }
  150. }
  151. }
  152. var searchResults : [KMSearchMode] = [] {
  153. didSet {
  154. self.updataLeftSideFindView()
  155. }
  156. }
  157. var groupSearchResults: [KMSearchMode] = []
  158. var findPaneState: KMFindPaneState = .singular
  159. var isSearchOutlineMode = false
  160. var isSearchSnapshotMode = false
  161. var outlineIgnoreCaseFlag = false
  162. var noteTypeDict: [String : Any] = [:]
  163. private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
  164. private let LABEL_COLUMNID = "label"
  165. var foldType: KMFoldAllAnnotationType = .none
  166. var tocType: KMFoldType = .none
  167. var snapshots: [KMSnapshotModel] = []
  168. var dirtySnapshots: [KMSnapshotWindowController] = []
  169. var searchSnapshots: [KMSnapshotModel] = []
  170. private var _noteSortType: KMNoteSortType = .none
  171. var noteSortType: KMNoteSortType {
  172. get {
  173. return self._noteSortType
  174. }
  175. set {
  176. self._noteSortType = newValue
  177. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
  178. }
  179. }
  180. var isAscendSort = false {
  181. didSet {
  182. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMAnnotationSortTypeKeyNotification"), object: self)
  183. }
  184. }
  185. lazy var leftSideEmptyVC: KMLeftSideEmptyFileViewController = {
  186. let vc = KMLeftSideEmptyFileViewController(nibName: "KMLeftSideEmptyFileViewController", bundle: nil)
  187. vc.view.wantsLayer = true
  188. return vc
  189. }()
  190. var leftMargin: CGFloat = 0
  191. lazy var leftView: KMBotaLeftView = {
  192. let view = KMBotaLeftView()
  193. return view
  194. }()
  195. private var _copysPages: [CPDFPage] = []
  196. var copyPages: [CPDFPage] {
  197. get {
  198. return self._copysPages
  199. }
  200. }
  201. var annotations: [KMBOTAAnnotationSection] = []
  202. var allAnnotations: [CPDFAnnotation] = []
  203. private let kKMPDFViewOutlineDragDataType = NSPasteboard.PasteboardType("kKMPDFViewOutlineDragDataType")
  204. private let KPDFThumbnailDoucumentURLForDraggedTypes = NSPasteboard.PasteboardType("KPDFThumbnailDoucumentURLForDraggedTypes")
  205. var renamePDFOutline: CPDFOutline?
  206. var renamePDFOutlineTextField: NSTextField?
  207. var allFoldNotes: [CPDFAnnotation] = []
  208. var notes: [CPDFAnnotation] = []
  209. var canFoldNotes: [CPDFAnnotation] = []
  210. var isRenameNoteOutline = false
  211. var caseInsensitiveNoteSearch = false
  212. var noteSearchArray: [CPDFAnnotation] = []
  213. var noteSearchMode = false
  214. var mwcFlags: MwcFlags = MwcFlags()
  215. private var _dragPDFOutline: CPDFOutline?
  216. var updatingOutlineSelection = false
  217. fileprivate var dragFilePath: String?
  218. var dragFlag = false
  219. var filePromiseQueue: OperationQueue = {
  220. let queue = OperationQueue()
  221. return queue
  222. }()
  223. var dragIn = false
  224. var dragedIndexPaths: [Int] = []
  225. var updatingThumbnailSelection = false
  226. override func loadView() {
  227. super.loadView()
  228. self.initSubView()
  229. self.initDefalutValue()
  230. self.searchViewController.loadView()
  231. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  232. self.searchField = self.searchViewController.searchField
  233. self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
  234. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
  235. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
  236. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
  237. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
  238. self.searchViewController.segmentedControl.isBackgroundHighlighted = true
  239. self.searchViewController.segmentedControl.selectedSegment = 0
  240. self.searchViewController.segmentedControl.block = { [unowned self] segIndex in
  241. if segIndex == 0 {
  242. self.findPaneState = .singular
  243. self.displayFindViewAnimating(false)
  244. } else {
  245. self.findPaneState = .grouped
  246. self.displayGroupedFindViewAnimating(false)
  247. }
  248. }
  249. self.leftView.segmentedControl.block = { [unowned self] segIndex in
  250. self.toolButtonBox.isHidden = false
  251. self.toolButtonBoxLayoutConstraint.constant = 40.0
  252. if (segIndex == 0) {
  253. if self.type.methodType == .Thumbnail {
  254. self.leftView.segmentedControl.selectedSegment = UInt8.max
  255. self.refreshMethodType(methodType: .None)
  256. return
  257. }
  258. FMTrackEventManager.defaultManager.trackEvent(event: "LeftSidebar", withProperties: ["LeftSidebar_Btn": "Btn_LeftSidebar_Thumbnail"])
  259. self.refreshMethodType(methodType: .Thumbnail)
  260. DispatchQueue.main.async {
  261. self.toolButtonBox.contentView = self.thumbnailView
  262. self.displayThumbnailViewAnimating(false)
  263. }
  264. } else if (segIndex == 1) {
  265. if self.type.methodType == .Outline {
  266. self.leftView.segmentedControl.selectedSegment = UInt8.max
  267. self.refreshMethodType(methodType: .None)
  268. return
  269. }
  270. FMTrackEventManager.defaultManager.trackEvent(event: "LeftSidebar", withProperties: ["LeftSidebar_Btn": "Btn_LeftSidebar_Outline"])
  271. self.refreshMethodType(methodType: .Outline)
  272. DispatchQueue.main.async {
  273. self.toolButtonBox.contentView = self.outlineView
  274. self.displayTocViewAnimating(false)
  275. }
  276. } else if (segIndex == 2) {
  277. if self.type.methodType == .Annotation {
  278. self.leftView.segmentedControl.selectedSegment = UInt8.max
  279. self.refreshMethodType(methodType: .None)
  280. return
  281. }
  282. FMTrackEventManager.defaultManager.trackEvent(event: "LeftSidebar", withProperties: ["LeftSidebar_Btn": "Btn_LeftSidebar_Annotation"])
  283. self.refreshMethodType(methodType: .Annotation)
  284. DispatchQueue.main.async {
  285. self.toolButtonBox.contentView = self.noteView
  286. self.displayNoteViewAnimating(false)
  287. }
  288. } else if (segIndex == 3) {
  289. if self.type.methodType == .snapshot {
  290. self.leftView.segmentedControl.selectedSegment = UInt8.max
  291. self.refreshMethodType(methodType: .None)
  292. return
  293. }
  294. FMTrackEventManager.defaultManager.trackEvent(event: "LeftSidebar", withProperties: ["LeftSidebar_Btn": "Btn_LeftSidebar_Snapshot"])
  295. self.refreshMethodType(methodType: .snapshot)
  296. self.toolButtonBox.contentView = self.snapshotNormalView
  297. self.updateSnapshotFilterPredicate()
  298. self.displaySnapshotViewAnimating(false)
  299. self.updataLeftSideSnapView()
  300. } else if (segIndex == 4) {
  301. if self.type.methodType == .Search {
  302. self.leftView.segmentedControl.selectedSegment = UInt8.max
  303. self.refreshMethodType(methodType: .None)
  304. return
  305. }
  306. FMTrackEventManager.defaultManager.trackEvent(event: "LeftSidebar", withProperties: ["LeftSidebar_Btn": "Btn_LeftSidebar_Search"])
  307. self.refreshMethodType(methodType: .Search)
  308. DispatchQueue.main.async {
  309. self.toolButtonBox.isHidden = true
  310. self.toolButtonBoxLayoutConstraint.constant = 0
  311. self.displayFindViewAnimating(false)
  312. }
  313. }
  314. }
  315. let menu = NSMenu()
  316. _ = menu.addItem(title: KMLocalizedString("Whole Words Only", "Menu item title"), action: #selector(toggleWholeWordSearch), target: self)
  317. _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveSearch), target: self)
  318. (self.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
  319. (self.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
  320. self.searchField.action = #selector(search)
  321. self.searchField.target = self
  322. // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
  323. // //支持拖拽的文字类型
  324. // [tocOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
  325. // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
  326. // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
  327. if KMDataManager.ud_bool(forKey: Self.Key.disableTableToolTipsKey) == false {
  328. self.tocOutlineView.hasImageToolTips = true
  329. self.findTableView.hasImageToolTips = true
  330. self.groupedFindTableView.hasImageToolTips = true
  331. }
  332. self._updateViewColor()
  333. }
  334. func initSubView() {
  335. self.view.addSubview(self.leftView)
  336. self.leftView.frame = NSMakeRect(0, 0, 44, NSHeight(self.view.frame))
  337. self.leftView.autoresizingMask = [.height]
  338. self.thumb_initSubViews()
  339. self.outline_initSubViews()
  340. self.note_initSubViews()
  341. self.snapshot_initSubViews()
  342. self.search_initSubViews()
  343. }
  344. func initDefalutValue() {
  345. self.view.wantsLayer = true
  346. self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  347. self.leftView.wantsLayer = true
  348. self.leftView.layer?.backgroundColor = .white
  349. self.leftListView.wantsLayer = true
  350. self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  351. self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
  352. self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
  353. self.emptySearchBox.isHidden = true
  354. self.thumb_initDefalutValue()
  355. self.outline_initDefalutValue()
  356. self.note_initDefalutValue()
  357. self.snapshot_initDefalutValue()
  358. self.search_initDefalutValue()
  359. }
  360. func displayThumbnailViewAnimating(_ animate: Bool) {
  361. if let enclosingScrollView = self.thumbnailTableView.enclosingScrollView {
  362. self.replaceSideView(enclosingScrollView, animate: animate)
  363. }
  364. var frame = self.thumbnailTableView.enclosingScrollView?.frame ?? .zero
  365. frame.origin.y = 0
  366. frame.origin.x = self.leftMargin
  367. frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  368. self.thumbnailTableView.enclosingScrollView?.frame = frame
  369. self.resetThumbnails()
  370. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  371. frame.origin.y = 0
  372. frame.origin.x = self.leftMargin
  373. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  374. self.noteOutlineView.enclosingScrollView?.frame = frame
  375. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  376. frame.origin.y = 0
  377. frame.origin.x = self.leftMargin
  378. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  379. self.snapshotTableView.enclosingScrollView?.frame = frame
  380. self.updateThumbnailSelection()
  381. }
  382. func displayFindViewAnimating(_ animate: Bool) {
  383. self.replaceSideView(self.searchViewController.view, animate: animate)
  384. if (self.findState != .content) {
  385. self.findState = .content
  386. } else {
  387. self.displayFindState()
  388. }
  389. var frame = self.searchViewController.view.frame
  390. frame.origin.y = 0
  391. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
  392. self.searchViewController.view.frame = frame
  393. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  394. frame.origin.y = 0
  395. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  396. self.noteOutlineView.enclosingScrollView?.frame = frame
  397. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  398. frame.origin.y = 0
  399. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  400. self.snapshotTableView.enclosingScrollView?.frame = frame
  401. self.leftSideEmptyVC.emptySnapView.removeFromSuperview()
  402. self.updataLeftSideSnapView()
  403. }
  404. func displayFindState() {
  405. if (self.findState == .content) {
  406. self.displayFind()
  407. } else if (self.findState == .note) {
  408. self.displayNoteFind()
  409. } else if (self.findState == .snapshot) {
  410. self.displaySnapshotFind()
  411. }
  412. }
  413. func updataLeftSideFindView() {
  414. if (self.findState != .content) {
  415. return
  416. }
  417. if (self.searchResults.count > 0) {
  418. self.searchViewController.emptyBox.isHidden = true
  419. self.searchViewController.searchResultsView.isHidden = false
  420. self.searchViewController.searchResultsLabel.stringValue = String(format: KMLocalizedString("%ld Results", "Message in search table header"), self.searchResults.count)
  421. } else {
  422. self.searchViewController.emptyBox.isHidden = false
  423. self.searchViewController.searchResultsView.isHidden = true
  424. }
  425. }
  426. func displayGroupedFindViewAnimating(_ animate: Bool) {
  427. self.replaceSideView(self.searchViewController.view , animate: animate)
  428. if (self.findState != .content) {
  429. self.findState = .content
  430. } else {
  431. self.displayFindState()
  432. }
  433. var frame = self.searchViewController.view.frame
  434. frame.origin.y = 0
  435. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? 0
  436. self.searchViewController.view.frame = frame
  437. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  438. frame.origin.y = 0
  439. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  440. self.noteOutlineView.enclosingScrollView?.frame = frame
  441. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  442. frame.origin.y = 0
  443. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  444. self.snapshotTableView.enclosingScrollView?.frame = frame
  445. self.updataLeftSideSnapView()
  446. }
  447. func displayNoteViewAnimating(_ animate: Bool) {
  448. self.reloadAnnotation()
  449. self.annotationSort(sortArray: [])
  450. self.searchViewController.contentView = nil
  451. if let data = self.noteOutlineView.enclosingScrollView {
  452. self.replaceSideView(data, animate: animate)
  453. }
  454. if (self.findState != .note) {
  455. self.findState = .note
  456. } else {
  457. self.displayFindState()
  458. }
  459. var frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  460. frame.origin.y = 0
  461. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  462. self.noteOutlineView.enclosingScrollView?.frame = frame
  463. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  464. frame.origin.y = 0
  465. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  466. self.noteOutlineView.enclosingScrollView?.frame = frame
  467. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  468. frame.origin.y = 0
  469. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  470. self.snapshotTableView.enclosingScrollView?.frame = frame
  471. let view = self.noteOutlineView.enclosingScrollView
  472. let viewFrame = view?.frame ?? .zero
  473. let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  474. self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  475. DispatchQueue.main.async {
  476. self.noteOutlineView.reloadData()
  477. }
  478. }
  479. func displaySnapshotViewAnimating(_ animate: Bool) {
  480. self.searchViewController.contentView = nil
  481. if let data = self.snapshotTableView.enclosingScrollView {
  482. self.replaceSideView(data, animate: animate)
  483. }
  484. if (self.findState != .snapshot) {
  485. self.findState = .snapshot
  486. } else {
  487. self.displayFindState()
  488. }
  489. var frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  490. frame.origin.y = 0
  491. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  492. self.snapshotTableView.enclosingScrollView?.frame = frame
  493. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  494. frame.origin.y = 0
  495. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  496. self.noteOutlineView.enclosingScrollView?.frame = frame
  497. frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
  498. frame.origin.y = 0
  499. frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  500. self.tocOutlineView.enclosingScrollView?.frame = frame
  501. // [self updateSnapshotsIfNeeded];
  502. Task { @MainActor in
  503. self.snapshotTableView.reloadData()
  504. }
  505. }
  506. func displayFind() {
  507. self.searchField = self.searchViewController.searchField
  508. let menu = NSMenu()
  509. _ = menu.addItem(title: KMLocalizedString("Whole Words Only", "Menu item title"), action: #selector(toggleWholeWordSearch), target: self)
  510. _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveSearch), target: self)
  511. (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
  512. (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
  513. self.searchViewController.searchField.action = #selector(search)
  514. self.searchViewController.searchField.target = self
  515. if (self.findPaneState == .singular) {
  516. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  517. self.findTableView.wantsLayer = true
  518. self.findTableView.layer?.backgroundColor = NSColor.red.cgColor
  519. DispatchQueue.main.async {
  520. self.findTableView.reloadData()
  521. }
  522. } else if (self.findPaneState == .grouped) {
  523. self.searchViewController.contentView = self.groupedFindTableView.enclosingScrollView
  524. var array = KMSearchMode.sortSearchResult(results: self.searchResults)
  525. array.sort(){$0.datas.count > $1.datas.count}
  526. self.groupSearchResults = array
  527. self.groupedFindTableView.reloadData()
  528. }
  529. }
  530. func displayTocViewAnimating(_ animate: Bool) {
  531. if let data = self.tocOutlineView.enclosingScrollView {
  532. self.replaceSideView(data, animate: animate)
  533. }
  534. var frame = self.tocOutlineView.enclosingScrollView?.frame ?? .zero
  535. frame.origin.y = 0
  536. frame.size.height = self.tocOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  537. self.tocOutlineView.enclosingScrollView?.frame = frame
  538. frame = self.noteOutlineView.enclosingScrollView?.frame ?? .zero
  539. frame.origin.y = 0
  540. frame.size.height = self.noteOutlineView.enclosingScrollView?.superview?.frame.size.height ?? 0
  541. self.noteOutlineView.enclosingScrollView?.frame = frame
  542. frame = self.snapshotTableView.enclosingScrollView?.frame ?? .zero
  543. frame.origin.y = 0
  544. frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  545. self.snapshotTableView.enclosingScrollView?.frame = frame
  546. let view = self.tocOutlineView.enclosingScrollView
  547. let viewFrame = view?.frame ?? .zero
  548. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  549. self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
  550. DispatchQueue.main.async {
  551. self.tocOutlineView.reloadData()
  552. self.updateOutlineSelection()
  553. }
  554. }
  555. override func requiresAlternateButton(forView aview: NSView?) -> Bool {
  556. return false
  557. }
  558. func displayNoteFind() {
  559. self.searchField = self.noteSearchField
  560. let menu = NSMenu()
  561. _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveNoteSearch), target: self)
  562. (self.noteSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
  563. (self.noteSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Notes", "placeholder")
  564. self.noteSearchField.action = #selector(searchNotes)
  565. self.noteSearchField.target = self
  566. }
  567. func displaySnapshotFind() {
  568. self.searchField = self.snapshotSearchField;
  569. let menu = NSMenu()
  570. _ = menu.addItem(title: KMLocalizedString("Ignore Case", "Menu item title"), action: #selector(toggleCaseInsensitiveNoteSearch), target: self)
  571. (self.snapshotSearchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = menu
  572. (self.snapshotSearchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search Snapshots", "placeholder")
  573. self.snapshotSearchField.action = #selector(searchNotes)
  574. self.snapshotSearchField.target = self
  575. self.snapshotSearchField.delegate = self
  576. }
  577. func resetThumbnails() {
  578. self.thumbnails.removeAll()
  579. let pageLabels = self.listView?.document?.pageLabels() ?? []
  580. if (pageLabels.isEmpty == false) {
  581. for (i, label) in pageLabels.enumerated() {
  582. let thumbnail = KMThumbnail(image: nil, label: label, pageIndex: i)
  583. thumbnail.dirty = true
  584. self.thumbnails.append(thumbnail)
  585. }
  586. }
  587. DispatchQueue.main.async {
  588. let ris = self.thumbnailTableView.selectedRowIndexes
  589. self.thumbnailTableView.reloadData()
  590. self.thumbnailTableView.km_safe_selectRowIndexes(ris, byExtendingSelection: false)
  591. }
  592. }
  593. @IBAction func leftSideViewDoneButtonAction(_ sender: AnyObject?) {
  594. let button = sender as? NSButton
  595. let tag = button?.tag ?? 0
  596. if (tag == 310) {
  597. self.outlineSearchField.isHidden = true
  598. self.outlineDoneButton.isHidden = true
  599. self.outlineLabel.isHidden = false
  600. self.outlineSearchButton.isHidden = false
  601. self.outlineMoreButton.isHidden = false
  602. self.outlineAddButton.isHidden = false
  603. } else if (tag == 311) {
  604. self.noteSearchField.isHidden = true
  605. self.noteTitleLabel.isHidden = false
  606. self.noteSearchButton.isHidden = false
  607. self.noteDoneButton.isHidden = true
  608. self.noteFilterButton.isHidden = false
  609. self.noteMoreButton.isHidden = false
  610. } else if (tag == 312) {
  611. self.snapshotSearchField.isHidden = true
  612. // leftSideController.snapshotSearchZoomInButton.hidden = YES;
  613. self.snapshotNormalSearchButton.isHidden = false
  614. self.snapshotDoneButton.isHidden = true
  615. self.snapshotLabel.isHidden = false
  616. self.snapshotNormalZoomOutButton.isHidden = false
  617. self.snapshotNormalZoomInButton.isHidden = false
  618. }
  619. }
  620. @IBAction func thumbnailSizeScaling(_ sender: NSButton) {
  621. let tag = sender.tag
  622. if (tag == 0 || tag == 1) {
  623. var scaling = KMDataManager.ud_float(forKey: Self.Key.thumbSizeScaling)
  624. if (scaling <= 0) {
  625. scaling = 1
  626. }
  627. if (tag == 0) { // Zoom In
  628. scaling += self.scalingIncrement
  629. // if scaling >= 2.2 {
  630. // return
  631. // }
  632. } else if (tag == 1) { // Zoom Out
  633. scaling -= self.scalingIncrement
  634. if scaling <= 0.4 {
  635. return
  636. }
  637. }
  638. KMDataManager.ud_set(scaling, forKey: Self.Key.thumbSizeScaling)
  639. let selectRow = self.thumbnailTableView.selectedRow
  640. self.thumbnailTableView.reloadData()
  641. self.thumbnailTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  642. } else if (tag == 2 || tag == 3) {
  643. var scaling = KMDataManager.ud_float(forKey: Self.Key.snapshotSizeScaling)
  644. if (scaling <= 0) {
  645. scaling = 1
  646. }
  647. if (tag == 2) { // Zoom In
  648. scaling += self.scalingIncrement
  649. } else if (tag == 3) { // Zoom Out
  650. scaling -= self.scalingIncrement
  651. }
  652. KMDataManager.ud_set(scaling, forKey: Self.Key.snapshotSizeScaling)
  653. let selectRow = self.snapshotTableView.selectedRow
  654. self.snapshotTableView.reloadData()
  655. self.snapshotTableView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  656. }
  657. }
  658. func tableView(_ tv: NSTableView, cutRowsWithIndexes rowIndexes: IndexSet) {
  659. if tv.isEqual(to: self.thumbnailTableView) {
  660. self._copysPages.removeAll()
  661. for idx in rowIndexes {
  662. if (idx != NSNotFound) {
  663. if let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage {
  664. self._copysPages.append(page)
  665. }
  666. }
  667. }
  668. self.tableView(tv, deleteRowsWithIndexes: rowIndexes)
  669. }
  670. }
  671. }
  672. // MARK: - KMBotaTableViewDelegate
  673. extension KMLeftSideViewController: KMBotaTableViewDelegate {
  674. func tableView(_ aTableView: NSTableView, canCopyRowsWithIndexes rowIndexes: IndexSet) -> Bool {
  675. if aTableView.isEqual(to: self.thumbnailTableView) || aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
  676. return rowIndexes.count > 0
  677. }
  678. return false
  679. }
  680. func tableView(_ aTableView: NSTableView, canPasteFromPasteboard pboard: NSPasteboard) -> Bool {
  681. if aTableView.isEqual(to: self.thumbnailTableView) {
  682. if self._copysPages.count > 0 {
  683. return true
  684. }
  685. }
  686. return false
  687. }
  688. func tableView(_ aTableView: NSTableView, canDeleteRowsWithIndexes rowIndexes: IndexSet) -> Bool {
  689. if aTableView.isEqual(to: self.snapshotTableView) {
  690. return rowIndexes.count > 0
  691. } else if aTableView.isEqual(to: self.thumbnailTableView) {
  692. if self.listView.document.pageCount <= 1 {
  693. return false
  694. }
  695. return true
  696. }
  697. return false
  698. }
  699. func tableView(_ aTableView: NSTableView, pasteFromPasteboard pboard: NSPasteboard?) {
  700. if IAPProductsManager.default().isAvailableAllFunction() == false {
  701. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  702. return
  703. }
  704. if aTableView.isEqual(to: self.thumbnailTableView) {
  705. if self._copysPages.count > 0 {
  706. let index = self.listView.document.index(for: self.listView.currentPage()) + 1
  707. if (index == NSNotFound) {
  708. return
  709. }
  710. for page in self._copysPages.reversed() {
  711. self.listView.document.insertPageObject(page, at: index)
  712. self.listView.layoutDocumentView()
  713. self.resetThumbnails()
  714. let pageIndex = min(index, self.listView.document.pageCount-1)
  715. self.listView.go(toPageIndex: Int(pageIndex), animated: true)
  716. (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).tableView(self.thumbnailTableView, deleteRowsWithIndexes: IndexSet(integer: IndexSet.Element(index)))
  717. }
  718. }
  719. }
  720. }
  721. func tableViewMoveLeft(_ aTableView: NSTableView) {
  722. if aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
  723. // [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
  724. }
  725. }
  726. func tableViewMoveRight(_ aTableView: NSTableView) {
  727. if aTableView.isEqual(to: self.findTableView) || aTableView.isEqual(to: self.groupedFindTableView) {
  728. // [self updateFindResultHighlightsForDirection:NSSelectingNext];
  729. }
  730. }
  731. func tableView(_ aTableView: NSTableView, imageContextForRow rowIndex: Int) -> AnyObject? {
  732. if aTableView.isEqual(to: self.findTableView) {
  733. if rowIndex >= self.searchResults.count {
  734. return nil
  735. }
  736. let model = self.searchResults[rowIndex]
  737. let selection = model.selection
  738. let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
  739. return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
  740. } else if aTableView.isEqual(to: self.groupedFindTableView) {
  741. if rowIndex >= self.groupSearchResults.count {
  742. return nil
  743. }
  744. // let model = self.groupSearchResults[rowIndex]
  745. // let selection = model.selection
  746. // let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
  747. // return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
  748. }
  749. return nil
  750. }
  751. /*
  752. - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
  753. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  754. return pageLabels;
  755. }
  756. return nil;
  757. }
  758. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
  759. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  760. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  761. }
  762. }
  763. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
  764. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  765. if (searchString.length > 0)
  766. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  767. else
  768. [self updateLeftStatus];
  769. }
  770. }
  771. */
  772. }
  773. // MARK: - 扩展
  774. extension KMLeftSideViewController {
  775. public func selectType(_ type: BotaType) {
  776. // 更新 type
  777. var show = true
  778. if (self.type.methodType == .None) {
  779. show = true
  780. } else {
  781. if (self.type.methodType == type) {
  782. show = false
  783. } else {
  784. show = true
  785. }
  786. }
  787. var index: Int = NSNotFound
  788. switch type {
  789. case .None:
  790. index = NSNotFound
  791. break
  792. case .Thumbnail:
  793. index = 0
  794. break
  795. case .Outline:
  796. index = 1
  797. break
  798. case .BookMark:
  799. index = 2
  800. break
  801. case .Annotation:
  802. index = 3
  803. break
  804. case .Search:
  805. index = 4
  806. break
  807. case .From:
  808. index = 5
  809. break
  810. case .Signature:
  811. index = 6
  812. break
  813. case .snapshot:
  814. index = 7
  815. break
  816. }
  817. self.type = self.getMethodMode(show ? type : .None)
  818. // 更新按钮状态
  819. // self.updateViewButtonState()
  820. // 将事件传递出去
  821. self.delegate?.controlStateChange?(self,show:show)
  822. }
  823. private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
  824. let mode = KMLeftMethodMode()
  825. mode.methodType = type
  826. switch type {
  827. case .None:
  828. mode.methodName = ""
  829. break
  830. case .Thumbnail:
  831. mode.methodName = thumbnailMethodKey
  832. break
  833. case .Outline:
  834. mode.methodName = outlineMethodKey
  835. break
  836. case .BookMark:
  837. mode.methodName = bookMarkMethodKey
  838. break
  839. case .Annotation:
  840. mode.methodName = anntationMethodKey
  841. break
  842. case .Search:
  843. mode.methodName = searchMethodKey
  844. break
  845. case .From:
  846. mode.methodName = formMethodKey
  847. break
  848. case .Signature:
  849. mode.methodName = signatureMethodKey
  850. break
  851. case .snapshot:
  852. mode.methodName = snapshotMethodKey
  853. }
  854. return mode
  855. }
  856. }
  857. //MARK: Cache
  858. extension KMLeftSideViewController {
  859. func clearNotification() {
  860. }
  861. }
  862. // MARK: - Private Methods
  863. extension KMLeftSideViewController {
  864. func updateViewColor() {
  865. self._updateViewColor()
  866. }
  867. private func _updateViewColor() {
  868. if(KMAppearance.isDarkMode()){
  869. self.leftListView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  870. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  871. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  872. self.noteView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  873. self.outlineView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  874. self.view.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  875. self.thumbnailTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  876. self.groupedFindTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  877. self.tocOutlineView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  878. self.findTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  879. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  880. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  881. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  882. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  883. self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  884. self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  885. self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  886. } else {
  887. self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  888. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  889. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  890. self.noteView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  891. self.outlineView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  892. self.view.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  893. self.thumbnailTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  894. self.groupedFindTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  895. self.tocOutlineView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  896. self.findTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  897. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  898. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  899. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  900. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  901. self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  902. self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  903. self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  904. }
  905. }
  906. private func _hasContainString(_ searchString: String, rootOutline outline: CPDFOutline) -> Bool {
  907. var label = outline.label ?? ""
  908. var searchLabel = searchString
  909. if self.outlineIgnoreCaseFlag {
  910. label = label.lowercased()
  911. searchLabel = searchLabel.lowercased()
  912. }
  913. if label.contains(searchLabel) {
  914. // if ([outline.label rangeOfString:searchString options:self.outlineIgnoreCaseFlag?NSCaseInsensitiveSearch:0].location != NSNotFound){
  915. return true
  916. } else {
  917. var subHas = false
  918. for i in 0 ..< outline.numberOfChildren {
  919. if let subOutline = outline.child(at: i) {
  920. subHas = self._hasContainString(searchString, rootOutline: subOutline)
  921. } else {
  922. continue
  923. }
  924. if (subHas) {
  925. break
  926. }
  927. }
  928. return subHas
  929. }
  930. }
  931. }
  932. // MARK: - NSTableViewDelegate, NSTableViewDataSource
  933. extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
  934. func numberOfRows(in tableView: NSTableView) -> Int {
  935. if tableView.isEqual(to: self.thumbnailTableView) {
  936. return self.thumbnails.count
  937. } else if tableView.isEqual(to: self.findTableView) {
  938. return self.searchResults.count
  939. } else if tableView.isEqual(to: self.groupedFindTableView) {
  940. return self.groupSearchResults.count
  941. } else if tableView.isEqual(to: self.snapshotTableView) {
  942. if self.isSearchSnapshotMode {
  943. return self.searchSnapshots.count
  944. }
  945. return self.snapshots.count
  946. }
  947. return 0
  948. }
  949. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  950. if tableView.isEqual(to: self.thumbnailTableView) {
  951. let cell = tableView.makeView(withIdentifier: KMThumbnailTableviewCell.km_identifier, owner: self) as! KMThumbnailTableviewCell
  952. let thumbnail = self.thumbnails[row]
  953. cell.pageNumLabel.stringValue = thumbnail.label
  954. // cell.thumImage.image = thumbnail.image
  955. cell.pageView.page = self.listView.document.page(at: UInt(row))
  956. if let _image = thumbnail.image {
  957. let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
  958. let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
  959. if (_image.size.height > _image.size.width) {
  960. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  961. // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
  962. // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  963. } else {
  964. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  965. // cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
  966. // NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  967. }
  968. }
  969. if (self.isDisplayPageSize) {
  970. cell.sizeLabel.isHidden = false
  971. //获取Page的真实尺寸
  972. let page = self.listView.document.page(at: UInt(row))
  973. let rect = page?.bounds(for: .cropBox) ?? .zero
  974. let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
  975. let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
  976. if let data = page?.rotation, data == 90 || data == 270 {
  977. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
  978. } else {
  979. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
  980. }
  981. } else {
  982. cell.sizeLabel.isHidden = true
  983. }
  984. cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
  985. if (self.thumbnailTableView.selectedRowIndexes.contains(row)) {
  986. cell.isSelectCell = true
  987. } else {
  988. cell.isSelectCell = false
  989. }
  990. return cell
  991. } else if (tableView.isEqual(to: self.findTableView)) {
  992. let cell = tableView.makeView(withIdentifier: KMFindTableviewCell.km_identifier, owner: self) as! KMFindTableviewCell
  993. let selection = searchResults[row]
  994. if let data = tableColumn?.identifier.rawValue, data == kResultsColumnId.rawValue {
  995. cell.resultLabel.attributedStringValue = selection.attributedString
  996. cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
  997. } else if let data = tableColumn?.identifier.rawValue, data == kPageColumnId.rawValue {
  998. cell.resultLabel.stringValue = "\(Int(selection.selection.page?.pageIndex() ?? 0) + 1)"
  999. cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
  1000. }
  1001. return cell
  1002. } else if tableView.isEqual(to: self.snapshotTableView) {
  1003. let cell = tableView.makeView(withIdentifier: KMSnapshotTableViewCell.km_identifier, owner: self) as! KMSnapshotTableViewCell
  1004. var snapshot: KMSnapshotModel?
  1005. if self.isSearchSnapshotMode {
  1006. snapshot = self.searchSnapshots[row]
  1007. } else {
  1008. snapshot = self.snapshots[row]
  1009. }
  1010. cell.snapshotImage.image = snapshot?.windowC?.thumbnail
  1011. cell.snapshotLabel.stringValue = snapshot?.windowC?.pageLabel ?? ""
  1012. if let data = snapshot?.windowC?.hasWindow, data {
  1013. cell.snapshotImageView.isHidden = false
  1014. } else {
  1015. cell.snapshotImageView.isHidden = true
  1016. }
  1017. cell.isSelectCell = snapshot?.isSelected ?? false
  1018. if (row == tableView.selectedRow) {
  1019. cell.snapshotImageView.image = NSImage(named: KMImageNameUXIconSidebarSnapshotWindowSel)
  1020. } else {
  1021. cell.snapshotImageView.image = NSImage(named: KMImageNameUXIconSidebarSnapshotWindowNor)
  1022. }
  1023. return cell
  1024. }
  1025. return nil
  1026. }
  1027. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1028. if tableView.isEqual(to: self.thumbnailTableView) {
  1029. let scaling = KMDataManager.ud_float(forKey: Self.Key.thumbSizeScaling)
  1030. let thumbnailSize = NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize)
  1031. let newScaling: CGFloat = scaling.cgFloat + 0.1
  1032. let newThumbnailHeight = thumbnailSize.width * newScaling
  1033. if (newThumbnailHeight > MIN_SIDE_PANE_WIDTH) {
  1034. self.thumbnailZoomOutButton.isEnabled = false
  1035. } else {
  1036. self.thumbnailZoomOutButton.isEnabled = true
  1037. }
  1038. if ((scaling - 0.1) < 0.3) {
  1039. self.thumbnailZoomInButton.isEnabled = false
  1040. } else {
  1041. self.thumbnailZoomInButton.isEnabled = true
  1042. }
  1043. var labelHeight = 0.0
  1044. if (self.isDisplayPageSize) {
  1045. labelHeight = 56.0
  1046. } else {
  1047. labelHeight = 41.5
  1048. }
  1049. let cellHeight = thumbnailSize.height + labelHeight
  1050. var thumbSize: NSSize = .zero
  1051. if (scaling > 0) {
  1052. thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  1053. } else {
  1054. thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
  1055. }
  1056. return thumbSize.height
  1057. } else if tableView.isEqual(to: self.snapshotTableView) {
  1058. let scaling = KMDataManager.ud_float(forKey: Self.Key.snapshotSizeScaling)
  1059. let snapshotSize = (self.snapshots.safe_element(for: row) as? KMSnapshotModel)?.windowC?.thumbnail?.size ?? CGSizeMake(120, 63)
  1060. var newScaling = scaling + 0.1
  1061. let newSnapshotHeight = snapshotSize.width * newScaling.cgFloat;
  1062. if (newSnapshotHeight > MIN_SIDE_PANE_WIDTH) {
  1063. self.snapshotNormalZoomInButton.isEnabled = false
  1064. } else {
  1065. self.snapshotNormalZoomInButton.isEnabled = true
  1066. }
  1067. if ((scaling - 0.1) < 0.3 || (newSnapshotHeight < 150.0)) {
  1068. self.snapshotNormalZoomOutButton.isEnabled = false
  1069. } else {
  1070. self.snapshotNormalZoomOutButton.isEnabled = true
  1071. }
  1072. let cellHeight = snapshotSize.height + 24.0
  1073. var thumbSize: NSSize = .zero
  1074. if (scaling > 0) {
  1075. thumbSize = NSMakeSize(snapshotSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  1076. } else {
  1077. thumbSize = NSMakeSize(snapshotSize.width, cellHeight)
  1078. }
  1079. return thumbSize.height
  1080. } else if (tableView.isEqual(to: self.findTableView)) {
  1081. return 40.0
  1082. } else if tableView.isEqual(to: self.groupedFindTableView) {
  1083. return 16
  1084. }
  1085. return tableView.rowHeight
  1086. }
  1087. func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  1088. if (tableView.isEqual(to: self.findTableView)) {
  1089. let rowView = KMBotaTableRowView()
  1090. return rowView
  1091. } else if tableView.isEqual(to: self.groupedFindTableView) {
  1092. let rowView = KMGroupFindTableRowView()
  1093. rowView.totalNumber = self.groupSearchResults.first?.datas.count ?? 0
  1094. let model = self.groupSearchResults[row]
  1095. rowView.number = model.datas.count
  1096. rowView.pageIndex = Int(model.selectionPageIndex) + 1
  1097. return rowView
  1098. }
  1099. return nil
  1100. }
  1101. func tableViewSelectionIsChanging(_ notification: Notification) {
  1102. }
  1103. func tableViewSelectionDidChange(_ notification: Notification) {
  1104. if self.findTableView.isEqual(to: notification.object) {
  1105. // [self updateFindResultHighlightsForDirection:NSDirectSelection];
  1106. let row = self.findTableView.selectedRow
  1107. if row >= 0 {
  1108. let model = self.searchResults[row]
  1109. if model.selection != nil {
  1110. self.listView.go(to: model.selection, animated: true)
  1111. self.listView.setHighlightedSelection(model.selection, animated: true)
  1112. self.listView.setNeedsDisplayAnnotationViewForVisiblePages()
  1113. }
  1114. }
  1115. } else if self.groupedFindTableView.isEqual(to: notification.object) {
  1116. // [self updateFindResultHighlightsForDirection:NSDirectSelection];
  1117. } else if self.thumbnailTableView.isEqual(to: notification.object) {
  1118. let row = self.thumbnailTableView.selectedRow
  1119. let curPage = self.listView.document.index(for: self.listView.currentPage())
  1120. if (row != -1 && row != curPage) {
  1121. self.listView.go(toPageIndex: row, animated: true)
  1122. }
  1123. self.thumbnailTableView.ks_reloadData()
  1124. } else if self.snapshotTableView.isEqual(to: notification.object) {
  1125. let row = self.snapshotTableView.selectedRow
  1126. // 更新选中数据
  1127. for (i, model) in self.snapshots.enumerated() {
  1128. model.isSelected = i == row
  1129. }
  1130. if (row != -1) {
  1131. let controller = (self.snapshots.safe_element(for: row) as? KMSnapshotModel)?.windowC
  1132. if let data = controller?.window?.isVisible, data {
  1133. controller?.window?.orderFront(self)
  1134. }
  1135. }
  1136. // self.snapshotTableView.reloadData()
  1137. self.snapshotTableView.ks_reloadData()
  1138. }
  1139. }
  1140. func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
  1141. if dropOperation == .on || tableView.isEqual(to: self.thumbnailTableView) == false {
  1142. return NSDragOperation(rawValue: 0)
  1143. }
  1144. let pboard = info.draggingPasteboard
  1145. if (pboard.availableType(from: [.localDraggedTypes]) != nil) {
  1146. return .move
  1147. } else if (pboard.availableType(from: [.fileURL]) != nil) && tableView.isEqual(to: self.thumbnailTableView) {
  1148. guard let pbItems = pboard.pasteboardItems else {
  1149. return NSDragOperation(rawValue: 0)
  1150. }
  1151. var hasValidFile = false
  1152. for item in pbItems {
  1153. guard let data = item.string(forType: .fileURL), let _url = URL(string: data) else {
  1154. continue
  1155. }
  1156. let type = _url.pathExtension.lowercased()
  1157. if type == "pdf" || KMImageToPDFMethod.supportedImageTypes().contains(type) {
  1158. hasValidFile = true
  1159. }
  1160. }
  1161. if (!hasValidFile) {
  1162. return NSDragOperation(rawValue: 0)
  1163. } else {
  1164. return .move
  1165. }
  1166. }
  1167. return NSDragOperation(rawValue: 0)
  1168. }
  1169. func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {
  1170. var result = false
  1171. if tableView.isEqual(to: self.thumbnailTableView) == false {
  1172. return result
  1173. }
  1174. let pasteboard = info.draggingPasteboard
  1175. if (pasteboard.availableType(from: [.localDraggedTypes]) != nil) {
  1176. result = true
  1177. guard let rowData = pasteboard.data(forType: .localDraggedTypes) else {
  1178. return false
  1179. }
  1180. let rowIndexes = NSKeyedUnarchiver.unarchiveObject(with: rowData) as? IndexSet ?? IndexSet()
  1181. guard let urlData = pasteboard.data(forType: KPDFThumbnailDoucumentURLForDraggedTypes) else {
  1182. return false
  1183. }
  1184. let url = NSKeyedUnarchiver.unarchiveObject(with: urlData) as? String
  1185. if url != nil && url != self.listView.document.documentURL.absoluteString {
  1186. if (pasteboard.availableType(from: [.fileURL]) != nil) {
  1187. var fileNames = pasteboard.propertyList(forType: .fileURL) as? [String] ?? []
  1188. if (fileNames.count == 1) {
  1189. let path = fileNames.first ?? ""
  1190. let pathExtension = path.pathExtension.lowercased()
  1191. if pathExtension == "pdf" {
  1192. var index = row
  1193. var insertIndexSet = IndexSet()
  1194. var pdf = CPDFDocument(url: URL(fileURLWithPath: path))
  1195. if let data = pdf?.isEncrypted, data {
  1196. KMBaseWindowController.checkPassword(url: URL(fileURLWithPath: path), type: .owner) { success, resultPassword in
  1197. if success && resultPassword.isEmpty == false {
  1198. for i in 0 ..< (pdf?.pageCount ?? 0) {
  1199. if let page = pdf?.page(at: i).copy() as? CPDFPage {
  1200. self.listView.document.insertPageObject(page, at: UInt(index))
  1201. insertIndexSet.insert(index)
  1202. index += 1
  1203. }
  1204. }
  1205. self.insertPages(insertIndexSet, pageAt: index-1)
  1206. }
  1207. }
  1208. } else {
  1209. for i in 0 ..< (pdf?.pageCount ?? 0) {
  1210. var page = pdf?.page(at: i)
  1211. self.listView.document.insertPageObject(page, at: UInt(index))
  1212. insertIndexSet.insert(index)
  1213. index += 1
  1214. }
  1215. self.insertPages(insertIndexSet, pageAt: index-1)
  1216. }
  1217. }
  1218. return true
  1219. }
  1220. }
  1221. }
  1222. var pageIndex = 0
  1223. var pages: [CPDFPage] = []
  1224. for idx in rowIndexes {
  1225. if let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage {
  1226. pages.append(page)
  1227. }
  1228. }
  1229. var toPage: CPDFPage?
  1230. if row < self.listView.document.pageCount {
  1231. toPage = self.listView.document.page(at: UInt(row))
  1232. }
  1233. var toPageIndex = 0
  1234. if (toPage != nil) {
  1235. toPageIndex = Int(self.listView.document.index(for: toPage))
  1236. } else {
  1237. toPageIndex = Int(self.listView.document.pageCount)
  1238. }
  1239. for i in 0 ..< pages.count {
  1240. let page = pages[i]
  1241. self.listView.document.insertPageObject(page, at: UInt(toPageIndex+i))
  1242. pageIndex += 1
  1243. self.listView.go(toPageIndex: toPageIndex+i, animated: false)
  1244. }
  1245. self.listView.layoutDocumentView()
  1246. var deletepages: [CPDFPage] = []
  1247. for idx in rowIndexes {
  1248. if idx < toPageIndex {
  1249. if((idx+pageIndex) < self.listView.document.pageCount) {
  1250. if let page = self.listView.document.page(at: UInt(idx)) {
  1251. deletepages.append(page)
  1252. }
  1253. self.listView.document.removePage(at: IndexSet(integer: idx))
  1254. }
  1255. } else {
  1256. if((idx+pageIndex) < self.listView.document.pageCount) {
  1257. if let page = self.listView.document.page(at: UInt(idx+pageIndex)) {
  1258. deletepages.append(page)
  1259. }
  1260. self.listView.document.removePage(at: IndexSet(integer: idx+pageIndex))
  1261. }
  1262. }
  1263. }
  1264. self.listView.layoutDocumentView()
  1265. self.resetThumbnails()
  1266. } else if pasteboard.availableType(from: [.fileURL]) != nil && tableView.isEqual(to: self.thumbnailTableView) {
  1267. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1268. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  1269. return false
  1270. }
  1271. var fileNames = pasteboard.propertyList(forType: .fileURL)
  1272. var insertIndexSet = IndexSet()
  1273. var index = row
  1274. // if (fileNames.count == 1) {
  1275. if fileNames != nil {
  1276. // var path = fileNames.first as? String ?? ""
  1277. var path = fileNames as? String ?? ""
  1278. let url = URL(string: path)
  1279. let pathExtension = url?.pathExtension.lowercased() ?? ""
  1280. if pathExtension == "pdf" {
  1281. let pdf = CPDFDocument(url: url!)
  1282. if let data = pdf?.isEncrypted, data {
  1283. KMBaseWindowController.checkPassword(url: url!, type: .owner) { success, resultPassword in
  1284. if success && resultPassword.isEmpty == false {
  1285. pdf?.unlock(withPassword: resultPassword)
  1286. for i in 0 ..< (pdf?.pageCount ?? 0) {
  1287. // let page = pdf?.page(at: i).copy() as? CPDFPage
  1288. if let page = pdf?.page(at: i) {
  1289. self.listView.document.insertPageObject(page, at: UInt(index))
  1290. insertIndexSet.insert(index)
  1291. index += 1
  1292. }
  1293. }
  1294. self.insertPages(insertIndexSet, pageAt: index-1)
  1295. }
  1296. }
  1297. } else {
  1298. for i in 0 ..< (pdf?.pageCount ?? 0) {
  1299. // let page = pdf?.page(at: i).copy() as? CPDFPage
  1300. if let page = pdf?.page(at: i) {
  1301. self.listView.document.insertPageObject(page, at: UInt(index))
  1302. insertIndexSet.insert(index)
  1303. index += 1
  1304. }
  1305. }
  1306. self.insertPages(insertIndexSet, pageAt: index-1)
  1307. }
  1308. } else if KMImageToPDFMethod.supportedImageTypes().contains(pathExtension) {
  1309. if let image = NSImage(contentsOfFile: url?.path ?? "") {
  1310. // PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
  1311. // [pdfView.document insertPage:page atIndex:index];
  1312. _ = self.listView.document.km_insert(image: image, at: UInt(index))
  1313. insertIndexSet.insert(index)
  1314. self.insertPages(insertIndexSet, pageAt: index-1)
  1315. }
  1316. }
  1317. result = true
  1318. } else {
  1319. result = false
  1320. }
  1321. }
  1322. return result == false
  1323. }
  1324. func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
  1325. if tableView.isEqual(to: self.thumbnailTableView) {
  1326. let idx = rowIndexes.first ?? NSNotFound
  1327. if (idx != NSNotFound && self.listView.document.isLocked == false) {
  1328. let page = self.listView.document.page(at: UInt(idx))
  1329. var fileExt: String?
  1330. let tiffData = page?.PDFListViewTIFFData(for: page?.bounds(for: self.listView.displayBox) ?? .zero)
  1331. if self.listView.document.allowsPrinting {
  1332. // NSData *pdfData = [page dataRepresentation];
  1333. fileExt = "pdf"
  1334. // filenames
  1335. pboard.declareTypes([.pdf, .tiff, .fileURL, .filePromise, .localDraggedTypes, KPDFThumbnailDoucumentURLForDraggedTypes], owner: self)
  1336. // let newDoc = CPDFDocument()
  1337. // newDoc?.insertPageObject(page, at: 0)
  1338. // let data = newDoc?.dataRepresentation()
  1339. // [pboard setData:pdfData forType:NSPasteboardTypePDF];
  1340. pboard.setData(tiffData, forType: .pdf)
  1341. // NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
  1342. let zNSIndexSetData = NSKeyedArchiver.archivedData(withRootObject: rowIndexes)
  1343. pboard.setData(zNSIndexSetData, forType: .localDraggedTypes)
  1344. let documentURL = NSKeyedArchiver.archivedData(withRootObject: self.listView.document.documentURL?.absoluteString)
  1345. // NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
  1346. var docmentName = self.listView.document.documentURL.deletingPathExtension().lastPathComponent
  1347. // __block NSMutableString *pagesName = nil;
  1348. var pagesName = ""
  1349. if (rowIndexes.count > 1) {
  1350. pagesName = " pages"
  1351. } else {
  1352. pagesName = " page"
  1353. }
  1354. let tFileName = String(format: "%@ %@", pagesName, self.fileNameWithSelectedPages(rowIndexes))
  1355. let pdf = CPDFDocument()
  1356. for idx in rowIndexes {
  1357. // var copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
  1358. var copyPage = self.listView.document.page(at: UInt(idx))
  1359. pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
  1360. }
  1361. let paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
  1362. var cachesDir = paths.first ?? ""
  1363. docmentName = String(format: "%@%@", docmentName, tFileName)
  1364. if (docmentName.count > 50) {
  1365. docmentName = docmentName.substring(to: 50)
  1366. }
  1367. // cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
  1368. cachesDir = "\(cachesDir)/\(docmentName).pdf"
  1369. let success = pdf?.write(toFile: cachesDir) ?? false
  1370. if (success) {
  1371. // [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
  1372. pboard.setPropertyList([cachesDir], forType: .fileURL)
  1373. } else{
  1374. // [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
  1375. pboard.setPropertyList([], forType: .fileURL)
  1376. }
  1377. pboard.setData(documentURL, forType: KPDFThumbnailDoucumentURLForDraggedTypes)
  1378. } else {
  1379. fileExt = "tiff"
  1380. pboard.declareTypes([.tiff, .filePromise], owner: self)
  1381. }
  1382. pboard.setData(tiffData, forType: .tiff)
  1383. // kPasteboardTypeFileURLPromise
  1384. pboard.setPropertyList([fileExt], forType: .filePromise)
  1385. return true
  1386. }
  1387. } else if self.snapshotTableView.isEqual(to: tableView) {
  1388. let idx = rowIndexes.first ?? NSNotFound
  1389. if (idx != NSNotFound) {
  1390. let snapshot = (self.snapshots.safe_element(for: idx) as? KMSnapshotModel)?.windowC
  1391. if let data = snapshot?.thumbnailWithSize(0)?.tiffRepresentation {
  1392. pboard.declareTypes([.tiff, .filePromise], owner: self)
  1393. pboard.setData(data, forType: .tiff)
  1394. pboard.setPropertyList(["tiff"], forType: .filePromise)
  1395. return true
  1396. }
  1397. }
  1398. }
  1399. return false
  1400. }
  1401. // func tableView(_ tableView: NSTableView, pasteboardWriterForRow row: Int) -> NSPasteboardWriting? {
  1402. // var provider: NSFilePromiseProvider?
  1403. //
  1404. // 创建数据提供者
  1405. // let fileExtension = "pdf"
  1406. // if #available(macOS 11.0, *) {
  1407. // let typeIdentifier = UTType(filenameExtension: fileExtension)
  1408. // provider = KMFilePromiseProvider(fileType: typeIdentifier!.identifier, delegate: self)
  1409. // } else {
  1410. // let typeIdentifier =
  1411. // UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as CFString, nil)
  1412. // provider = KMFilePromiseProvider(fileType: typeIdentifier!.takeRetainedValue() as String, delegate: self)
  1413. // }
  1414. //
  1415. // // 记录拖拽索引
  1416. // self.dragedIndexPaths.append(row)
  1417. // do {
  1418. // if let _url = self.listView.document?.documentURL {
  1419. // let data = try NSKeyedArchiver.archivedData(withRootObject: row, requiringSecureCoding: false)
  1420. // provider!.userInfo = [KMFilePromiseProvider.UserInfoKeys.urlKey: _url,
  1421. // KMFilePromiseProvider.UserInfoKeys.indexPathKey: data]
  1422. // } else {
  1423. // let data = try NSKeyedArchiver.archivedData(withRootObject: row, requiringSecureCoding: false)
  1424. // provider!.userInfo = [KMFilePromiseProvider.UserInfoKeys.indexPathKey: data]
  1425. // }
  1426. // } catch {
  1427. // fatalError("failed to archive indexPath to pasteboard")
  1428. // }
  1429. // return provider
  1430. // }
  1431. func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: IndexSet) {
  1432. // if self.isNeedMarkerLine {
  1433. // self.markBeginIndexes = collectionView.selectionIndexes
  1434. // }
  1435. self.dragIn = true
  1436. // 将拖拽的page插入临时路径(文档)
  1437. var indexs = IndexSet()
  1438. for indexpath in self.dragedIndexPaths {
  1439. indexs.insert(indexpath)
  1440. }
  1441. // 清空临时数据
  1442. if let _path = self.dragTempFilePath, FileManager.default.fileExists(atPath: _path) {
  1443. try?FileManager.default.removeItem(atPath: _path)
  1444. }
  1445. // 重置拖拽标识
  1446. self.dragFlag = false
  1447. if (indexs.count > 0) {
  1448. let document = CPDFDocument()
  1449. document?.importPages(indexs, from: self.listView.document, at: 0)
  1450. if let data = self.dragTempFloderPath, !FileManager.default.fileExists(atPath: data) {
  1451. try?FileManager.default.createDirectory(atPath: data, withIntermediateDirectories: false)
  1452. }
  1453. if let data = self.dragTempFilePath, !FileManager.default.fileExists(atPath: data) {
  1454. FileManager.default.createFile(atPath: data, contents: nil)
  1455. }
  1456. if let data = self.dragTempFilePath {
  1457. document?.write(to: URL(fileURLWithPath: data))
  1458. }
  1459. self.dragFilePath = self.dragTempFilePath
  1460. }
  1461. }
  1462. func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
  1463. if (!self.dragIn) {
  1464. // var indexpaths = Set<IndexPath>()
  1465. // for indexpath in self.dragedIndexPaths {
  1466. // indexpaths.insert(indexpath)
  1467. // }
  1468. // 清空数据
  1469. self.dragedIndexPaths.removeAll()
  1470. // 刷新数据
  1471. // self.reloadData()
  1472. // 重新选中数据
  1473. // self.selectionIndexPaths = indexpaths
  1474. } else {
  1475. Swift.debugPrint("拖入文件 或 本地拖拽")
  1476. }
  1477. self.dragIn = false
  1478. }
  1479. @objc dynamic func tableView(_ aTableView: NSTableView, deleteRowsWithIndexes rowIndexes: IndexSet) {
  1480. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1481. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  1482. return
  1483. }
  1484. if aTableView.isEqual(to: self.snapshotTableView) {
  1485. var controllers: [KMSnapshotWindowController] = []
  1486. for i in rowIndexes {
  1487. let model: KMSnapshotModel? = self.snapshots.safe_element(for: i) as? KMSnapshotModel
  1488. if let winC = model?.windowC {
  1489. controllers.append(winC)
  1490. }
  1491. }
  1492. for c in controllers {
  1493. c.close()
  1494. }
  1495. } else if aTableView.isEqual(to: self.thumbnailTableView) {
  1496. for idx in rowIndexes {
  1497. if idx >= self.listView.document.pageCount {
  1498. return
  1499. }
  1500. if let page = self.listView.document.page(at: UInt(idx)) {
  1501. for anno in page.annotations {
  1502. page.removeAnnotation(anno)
  1503. }
  1504. (self.listView.undoManager?.prepare(withInvocationTarget: self) as AnyObject).insertPage(page, pageAt: idx)
  1505. self.listView.document.removePage(at: IndexSet(integer: idx))
  1506. }
  1507. }
  1508. if rowIndexes.isEmpty == false {
  1509. self.listView.layoutDocumentView()
  1510. self.resetThumbnails()
  1511. let idx = rowIndexes.first ?? -1
  1512. let index = min(idx, Int(self.listView.document.pageCount)-1)
  1513. self.listView.go(toPageIndex: index, animated: false)
  1514. }
  1515. }
  1516. }
  1517. func tableView(_ aTableView: NSTableView, copyRowsWithIndexes rowIndexes: IndexSet) {
  1518. if IAPProductsManager.default().isAvailableAllFunction() == false {
  1519. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  1520. return
  1521. }
  1522. if aTableView.isEqual(to: self.thumbnailTableView) {
  1523. self._copysPages.removeAll()
  1524. if self.listView.document.isLocked == false {
  1525. for idx in rowIndexes {
  1526. if let page = self.listView.document.page(at: UInt(idx))?.copy() as? CPDFPage {
  1527. self._copysPages.append(page)
  1528. }
  1529. }
  1530. }
  1531. } else if aTableView.isEqual(to: self.findTableView) {
  1532. var string = ""
  1533. for idx in rowIndexes {
  1534. let match = self.searchResults[idx].selection
  1535. string.append("* ")
  1536. // [string appendFormat:NSLocalizedString(@"Page %@", @""), [match firstPageLabel]];
  1537. string = string.appendingFormat(KMLocalizedString("Page %@", ""), "\(match.safeFirstPage()?.pageIndex() ?? 0)")
  1538. // [string appendFormat:@"", [[match contextString] string]];
  1539. string = string.appendingFormat(": %@\n", match.string() ?? "")
  1540. }
  1541. let pboard = NSPasteboard.general
  1542. pboard.clearContents()
  1543. pboard.writeObjects([string as NSPasteboardWriting])
  1544. } else if aTableView.isEqual(to: self.groupedFindTableView) {
  1545. var string = ""
  1546. for idx in rowIndexes {
  1547. let result = self.groupSearchResults[idx]
  1548. let matches = result.datas
  1549. string.append("* ")
  1550. string = string.appendingFormat(KMLocalizedString("Page %@", ""), "\(result.selectionPageIndex)")
  1551. string.append(": ")
  1552. string = string.appendingFormat(KMLocalizedString("%ld Results", ""), matches.count)
  1553. // [string appendFormat:@":\n\t%@\n", [[matches valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
  1554. var tmpString = ""
  1555. for model in matches {
  1556. tmpString.append("\(model.selection.string() ?? "")")
  1557. }
  1558. string = string.appendingFormat(":\n\t%@\n", tmpString)
  1559. }
  1560. let pboard = NSPasteboard.general
  1561. pboard.clearContents()
  1562. pboard.writeObjects([string as NSPasteboardWriting])
  1563. }
  1564. }
  1565. func tableView(_ tableView: NSTableView, namesOfPromisedFilesDroppedAtDestination dropDestination: URL, forDraggedRowsWith indexSet: IndexSet) -> [String] {
  1566. if self.thumbnailTableView.isEqual(to: tableView) {
  1567. var fileURLArray: [String] = []
  1568. if indexSet.count > 1 {
  1569. var docmentName = ""
  1570. var tFileName = String(format: "%@", self.fileNameWithSelectedPages(indexSet))
  1571. var pdf = CPDFDocument()
  1572. for idx in indexSet {
  1573. if idx != NSNotFound && self.listView.document.isLocked == false {
  1574. let copyPage = self.listView.document.page(at: UInt(idx)).copy() as? CPDFPage
  1575. pdf?.insertPageObject(copyPage, at: pdf?.pageCount ?? 0)
  1576. }
  1577. }
  1578. var fileURL = dropDestination.appendingPathComponent(tFileName).appendingPathExtension("pdf").uniqueFileURL()
  1579. docmentName = fileURL.path
  1580. let success = pdf?.write(toFile: docmentName) ?? false
  1581. if(success) {
  1582. fileURLArray.append(fileURL.lastPathComponent)
  1583. }
  1584. } else {
  1585. if let page = self.listView.document.page(at: UInt(indexSet.first ?? 0)) {
  1586. var fileURL = dropDestination.appendingPathComponent(self.draggedFileName(for: page))
  1587. var pathExt = ""
  1588. var fileData: Data?
  1589. if let data = self.listView?.document?.allowsPrinting, data {
  1590. pathExt = "pdf"
  1591. // data = [page dataRepresentation];
  1592. } else {
  1593. pathExt = "tiff"
  1594. fileData = page.PDFListViewTIFFData(for: page.bounds(for: self.listView?.displayBox ?? .cropBox))
  1595. }
  1596. fileURL = fileURL.appendingPathExtension(pathExt).uniqueFileURL()
  1597. let success = (try?fileData?.write(to: fileURL)) != nil
  1598. if success {
  1599. fileURLArray.append(fileURL.lastPathComponent)
  1600. }
  1601. }
  1602. }
  1603. return fileURLArray
  1604. } else if self.snapshotTableView.isEqual(to: tableView) {
  1605. let idx = indexSet.first ?? NSNotFound
  1606. if (idx != NSNotFound) {
  1607. if let snapshot = (self.snapshots.safe_element(for: idx) as? KMSnapshotModel)?.windowC {
  1608. if let page = self.listView?.document?.page(at: snapshot.pageIndex()) {
  1609. var fileURL = dropDestination.appendingPathComponent(self.draggedFileName(for: page)).appendingPathExtension("tiff")
  1610. fileURL = fileURL.uniqueFileURL()
  1611. if ((try?snapshot.thumbnailWithSize(0)?.tiffRepresentation?.write(to: fileURL)) != nil) {
  1612. return [fileURL.lastPathComponent]
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. return[]
  1619. }
  1620. func tableViewColumnDidResize(_ notification: Notification) {
  1621. guard let column = notification.userInfo?["NSTableColumn"] as? NSTableColumn else {
  1622. return
  1623. }
  1624. if column.identifier.rawValue == IMAGE_COLUMNID {
  1625. if self.thumbnailTableView.isEqual(to: notification.object) {
  1626. self.thumbnailTableView.noteHeightOfRows(withIndexesChanged: NSIndexSet(indexesIn: NSMakeRange(0, self.thumbnailTableView.numberOfRows)) as IndexSet)
  1627. } else if self.snapshotTableView.isEqual(to: notification.object) {
  1628. self.snapshotTableView.noteHeightOfRows(withIndexesChanged: NSIndexSet(indexesIn: NSMakeRange(0, self.snapshotTableView.numberOfRows)) as IndexSet)
  1629. }
  1630. }
  1631. }
  1632. func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) {
  1633. if tableView.isEqual(to: self.groupedFindTableView) {
  1634. // [leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
  1635. }
  1636. }
  1637. /*
  1638. #pragma mark NSTableView delegate protocol
  1639. - (void)tableView:(NSTableView *)tv shareRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1640. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1641. NSUInteger idx = [rowIndexes firstIndex];
  1642. if (idx != NSNotFound) {
  1643. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1644. NSString *fileName = [[[pdfView document] documentURL] lastPathComponent];
  1645. NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  1646. NSString *filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Untitled"]];
  1647. filePath = [filePath stringByAppendingPathExtension:[fileName pathExtension]];
  1648. [self fileWithPage:page atPath:filePath];
  1649. if (rint(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
  1650. [KMMailHelper sendFileWithPaths:[NSArray arrayWithObject:filePath]];
  1651. } else {
  1652. NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
  1653. [service performWithItems:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]]];
  1654. }
  1655. }
  1656. }
  1657. }
  1658. - (void)fileWithPage:(PDFPage *)page atPath:(NSString *)filePath {
  1659. NSData *data = [page dataRepresentation];
  1660. PDFDocument *document = [[PDFDocument alloc] initWithData:data];
  1661. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  1662. BOOL success = [document writeToURL:[NSURL fileURLWithPath:filePath]];
  1663. if (success) {
  1664. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  1665. NSURL *url = [NSURL fileURLWithPath:filePath];
  1666. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  1667. }
  1668. [document release];
  1669. */
  1670. }
  1671. // MARK: - NSFilePromiseProviderDelegate
  1672. extension KMLeftSideViewController: NSFilePromiseProviderDelegate {
  1673. func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, fileNameForType fileType: String) -> String {
  1674. var fileName: String = "Untitle"
  1675. if let _string = self.listView?.document?.documentURL.deletingPathExtension().lastPathComponent {
  1676. fileName = _string
  1677. }
  1678. fileName.append(" pages")
  1679. var indexs = IndexSet()
  1680. for indexpath in self.dragedIndexPaths {
  1681. indexs.insert(indexpath)
  1682. }
  1683. fileName.append(" ")
  1684. fileName.append(KMPageRangeTools.newParseSelectedIndexs(selectedIndex: indexs.sorted()))
  1685. fileName.append(".pdf")
  1686. return fileName
  1687. }
  1688. func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider,
  1689. writePromiseTo url: URL,
  1690. completionHandler: @escaping (Error?) -> Void) {
  1691. do {
  1692. /** Copy the file to the location provided to you. You always do a copy, not a move.
  1693. It's important you call the completion handler.
  1694. */
  1695. if let _urlString = self.dragFilePath, !self.dragFlag {
  1696. self.dragFlag = true
  1697. // if let should = self.delegate?.thumbnailView?(thumbanView: self, shouldPasteboardWriterForItemAt: IndexPath(item: 0, section: 0)), !should {
  1698. // completionHandler(nil)
  1699. // return
  1700. // }
  1701. try FileManager.default.copyItem(at: URL(fileURLWithPath: _urlString), to: url)
  1702. }
  1703. completionHandler(nil)
  1704. } catch let error {
  1705. OperationQueue.main.addOperation {
  1706. self.presentError(error, modalFor: self.view.window!,
  1707. delegate: nil, didPresent: nil, contextInfo: nil)
  1708. }
  1709. completionHandler(error)
  1710. }
  1711. }
  1712. /** You should provide a non main operation queue (e.g. one you create) via this function.
  1713. This way you don't stall the main thread while writing the promise file.
  1714. */
  1715. func operationQueue(for filePromiseProvider: NSFilePromiseProvider) -> OperationQueue {
  1716. return self.filePromiseQueue
  1717. }
  1718. }
  1719. extension KMLeftSideViewController {
  1720. var dragTempFloderPath: String? {
  1721. get {
  1722. return NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier ?? "").stringByAppendingPathComponent("KMPDFThumbnailView_Drag_Temp")
  1723. }
  1724. }
  1725. var dragTempFilePath: String? {
  1726. get {
  1727. return self.dragTempFloderPath?.stringByAppendingPathComponent("drag_tmp.pdf")
  1728. }
  1729. }
  1730. }
  1731. // MARK: - NSOutlineViewDelegate, NSOutlineViewDataSource
  1732. extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSource {
  1733. func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
  1734. if outlineView.isEqual(to: self.tocOutlineView) {
  1735. let isLocked = self.listView.document?.isLocked ?? true
  1736. if isLocked { // 文档不存在 或 已加锁
  1737. return 0
  1738. }
  1739. if item == nil { // 第一层
  1740. // 获取根
  1741. guard let outline = self.listView.document.outlineRoot() else {
  1742. let view = self.tocOutlineView.enclosingScrollView
  1743. let viewFrame = view?.frame ?? .zero
  1744. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  1745. //
  1746. self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  1747. self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  1748. self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
  1749. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
  1750. return 0
  1751. }
  1752. if outline.numberOfChildren == 0 {
  1753. // return 0
  1754. }
  1755. if self.isSearchOutlineMode { // 是否为搜索模块
  1756. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: outline) {
  1757. self.showSearchOutlineBlankState(false)
  1758. } else {
  1759. self.showSearchOutlineBlankState(true)
  1760. return 0
  1761. }
  1762. } else {
  1763. if outline.numberOfChildren > 0 { // 有数据
  1764. self.leftSideEmptyVC.emptyOutlineView.removeFromSuperview()
  1765. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = true
  1766. } else { // 没有数据
  1767. let view = self.tocOutlineView.enclosingScrollView
  1768. let viewFrame = view?.frame ?? .zero
  1769. let emptyVcSize = self.leftSideEmptyVC.emptyOutlineView.frame.size
  1770. //
  1771. self.leftSideEmptyVC.emptyOutlineView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  1772. self.leftSideEmptyVC.emptyOutlineView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  1773. self.tocOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyOutlineView)
  1774. self.leftSideEmptyVC.deleteOutlineBtn.isEnabled = false
  1775. return 0
  1776. }
  1777. }
  1778. // 搜索按钮
  1779. if outline.numberOfChildren > 0 {
  1780. self.outlineSearchButton.isEnabled = true
  1781. } else {
  1782. self.outlineSearchButton.isEnabled = false
  1783. }
  1784. if (self.isSearchOutlineMode) {
  1785. var num = 0
  1786. for i in 0 ..< outline.numberOfChildren {
  1787. if let child = outline.child(at: i) {
  1788. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: child) {
  1789. num += 1
  1790. }
  1791. }
  1792. }
  1793. return num
  1794. } else {
  1795. let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
  1796. var bookmarkNum = 0
  1797. if array.isEmpty == false {
  1798. bookmarkNum = 1
  1799. }
  1800. return Int(outline.numberOfChildren) + bookmarkNum
  1801. }
  1802. } else { // 第二层 +
  1803. if self.isSearchOutlineMode {
  1804. if let data = item as? String, data == "Bookmarks" { // 书签group
  1805. return 0
  1806. } else if let child = item as? CPDFOutline { // 大纲
  1807. if child.numberOfChildren == 0 {
  1808. return 0
  1809. }
  1810. var num = 0
  1811. for i in 0 ..< child.numberOfChildren {
  1812. if let _child = child.child(at: i) {
  1813. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: _child) {
  1814. num += 1
  1815. }
  1816. }
  1817. }
  1818. return num
  1819. } else if item is CPDFBookmark { // 书签
  1820. return 0
  1821. }
  1822. } else {
  1823. if let data = item as? String, data == "Bookmarks" { // 书签group
  1824. return (self.listView.document?.bookmarks().count) ?? 0
  1825. } else if item is CPDFOutline { // 大纲
  1826. return Int((item as? CPDFOutline)?.numberOfChildren ?? 0)
  1827. } else if item is CPDFBookmark { // 书签
  1828. return 0
  1829. }
  1830. }
  1831. }
  1832. } else if outlineView.isEqual(to: self.noteOutlineView) {
  1833. if self.noteSearchMode {
  1834. return self.noteSearchArray.count
  1835. }
  1836. var count = 0
  1837. for section in self.annotations {
  1838. if section.annotations?.count != 0 {
  1839. count += section.annotations!.count
  1840. }
  1841. }
  1842. // if (item == nil){
  1843. // NSInteger count = [[rightSideController.noteArrayController arrangedObjects] count];
  1844. if (count < 1) {
  1845. // if (notes.count < 1) {
  1846. self.noteSearchButton.isEnabled = false
  1847. self.noteFilterButton.isEnabled = false
  1848. // }
  1849. self.noteOutlineView.usesAlternatingRowBackgroundColors = false
  1850. let view = self.noteOutlineView.enclosingScrollView
  1851. let viewFrame = view?.frame ?? .zero
  1852. var emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  1853. self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  1854. self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  1855. self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
  1856. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
  1857. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
  1858. //
  1859. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  1860. self.noteHeaderView.isHidden = true
  1861. self.toolButtonBoxLayoutConstraint.constant = 40.0
  1862. }
  1863. } else {
  1864. self.noteSearchButton.isEnabled = true
  1865. self.noteFilterButton.isEnabled = true
  1866. self.noteOutlineView.usesAlternatingRowBackgroundColors = false
  1867. self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
  1868. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
  1869. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
  1870. //
  1871. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  1872. self.noteHeaderView.isHidden = false
  1873. self.toolButtonBoxLayoutConstraint.constant = 64.0
  1874. }
  1875. }
  1876. return count
  1877. // } else {
  1878. // return [item hasNoteText];
  1879. // }
  1880. }
  1881. return 0
  1882. }
  1883. func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
  1884. if outlineView.isEqual(to: self.tocOutlineView) {
  1885. let isLocked = self.listView.document?.isLocked ?? true
  1886. if isLocked { // 文档不存在 或 已加锁
  1887. return ""
  1888. }
  1889. let array = self.listView.document.bookmarks() ?? [CPDFBookmark]()
  1890. var bookmarkNum = 0
  1891. if array.isEmpty == false {
  1892. bookmarkNum = 1
  1893. }
  1894. if item == nil {
  1895. if self.isSearchOutlineMode {
  1896. guard let outline = self.listView.document.outlineRoot() else {
  1897. return ""
  1898. }
  1899. if outline.numberOfChildren == 0 {
  1900. return ""
  1901. }
  1902. var array: [CPDFOutline] = []
  1903. for i in 0 ..< outline.numberOfChildren {
  1904. if let child = outline.child(at: i) {
  1905. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: child) {
  1906. array.append(child)
  1907. }
  1908. }
  1909. }
  1910. if index < array.count {
  1911. return array[index]
  1912. }
  1913. return ""
  1914. } else {
  1915. if index == 0 && bookmarkNum == 1 {
  1916. return "Bookmarks"
  1917. } else {
  1918. var _index = bookmarkNum == 1 ? index-1 : index
  1919. let outline = self.listView.document.outlineRoot()
  1920. var obj = outline?.child(at: UInt(_index))
  1921. return obj as Any
  1922. }
  1923. }
  1924. } else {
  1925. if let data = item as? String, data == "Bookmarks" {
  1926. return array[index]
  1927. } else if let ol = item as? CPDFOutline {
  1928. if self.isSearchOutlineMode == false {
  1929. return ol.child(at: UInt(index)) as Any
  1930. }
  1931. var array: [CPDFOutline] = []
  1932. for i in 0 ..< ol.numberOfChildren {
  1933. if let _child = ol.child(at: i) {
  1934. if self._hasContainString(self.outlineSearchField.stringValue, rootOutline: _child) {
  1935. array.append(_child)
  1936. }
  1937. }
  1938. }
  1939. return array[index]
  1940. } else if item is CPDFBookmark {
  1941. return ""
  1942. }
  1943. }
  1944. } else if outlineView.isEqual(to: self.noteOutlineView) {
  1945. // if (item == nil)
  1946. // {
  1947. // return [[rightSideController.noteArrayController arrangedObjects] objectAtIndex:anIndex];
  1948. // // return [self.notes objectAtIndex:anIndex];
  1949. // }
  1950. // else
  1951. // return [item noteText];
  1952. if self.noteSearchMode {
  1953. return self.noteSearchArray[index]
  1954. }
  1955. var tempArray: [KMBOTAAnnotationItem] = []
  1956. for secion in self.annotations {
  1957. if secion.annotations?.count != 0 {
  1958. for _item in secion.annotations! {
  1959. tempArray.append(_item)
  1960. }
  1961. }
  1962. }
  1963. return tempArray[index] as Any
  1964. }
  1965. return item
  1966. }
  1967. func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
  1968. if outlineView.isEqual(to: self.tocOutlineView) {
  1969. // let tcID = tableColumn?.identifier.rawValue ?? ""
  1970. // var ol = item as? CPDFOutline
  1971. // if(tcID == LABEL_COLUMNID) {
  1972. // if (self.isSearchOutlineMode) {
  1973. //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
  1974. //// NSArray *arr = [self allRangeOfRoughString:roughString searchString:self.leftSideController.outlineSearchField.stringValue];
  1975. //// NSMutableAttributedString *attributeString = [[[NSMutableAttributedString alloc] initWithString:roughString] autorelease];
  1976. //// for (NSUInteger i = 0; i <arr.count ; i++) {
  1977. //// NSValue * rangeValue = arr[i];
  1978. //// NSRange range = rangeValue.rangeValue;
  1979. //// range.location += i * self.leftSideController.outlineSearchField.stringValue.length;
  1980. //// [attributeString addAttribute:NSFontAttributeName value:[NSFont boldSystemFontOfSize:13] range:range];
  1981. //// }
  1982. //// [attributeString addAttribute:NSForegroundColorAttributeName value:[KMAppearance KMColor_Layout_H0] range:NSMakeRange(0, roughString.length)];
  1983. //// return attributeString;
  1984. // } else {
  1985. // var attributedString = NSMutableAttributedString()
  1986. //// attributedString
  1987. // attributedString.append(.init(string: ol?.label ?? "", attributes: [.foregroundColor : KMAppearance.Layout.h0Color()]))
  1988. //// NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]? : @"";
  1989. //// NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  1990. //// NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
  1991. //// [attributedString appendAttributedString:attr1];
  1992. //
  1993. // return attributedString
  1994. // }
  1995. //
  1996. // }
  1997. // else if([tcID isEqualToString:PAGE_COLUMNID]) {
  1998. // NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  1999. // NSString *roughString = [ol pageLabel]? : @"";
  2000. // NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  2001. // NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:roughString attributes:dictAttr1];
  2002. // [attributedString appendAttributedString:attr1];
  2003. //
  2004. // return attributedString;
  2005. // }
  2006. }
  2007. // else if ([ov isEqual:rightSideController.noteOutlineView]) {
  2008. // NSString *tcID = [tableColumn identifier];
  2009. // PDFAnnotation *note = item;
  2010. // if (tableColumn == nil || [tcID isEqualToString:NOTE_COLUMNID])
  2011. // return [note objectValue];
  2012. // else if([tcID isEqualToString:TYPE_COLUMNID]){
  2013. // NSString *noteType = [note type];
  2014. // if ([note isKindOfClass:[PDFAnnotationButtonWidget class]]) {
  2015. // PDFAnnotationButtonWidget *buttonWidget = (PDFAnnotationButtonWidget *)note;
  2016. // if (buttonWidget.controlType == kPDFWidgetRadioButtonControl) {
  2017. // noteType = SKAnnotationFormRadioButtonKey;
  2018. // } else if (buttonWidget.controlType == kPDFWidgetCheckBoxControl){
  2019. // noteType = SKAnnotationFormCheckBoxKey;
  2020. // } else if (buttonWidget.controlType == kPDFWidgetPushButtonControl){
  2021. // noteType = SKAnnotationFormActionButtonKey;
  2022. // }
  2023. // } else if ([note isKindOfClass:[PDFAnnotationTextWidget class]]){
  2024. // noteType = SKAnnotationFormTextFieldKey;
  2025. // } else if ([note isKindOfClass:[PDFAnnotationChoiceWidget class]]){
  2026. // PDFAnnotationChoiceWidget *choiceWidget = (PDFAnnotationChoiceWidget *)note;
  2027. // if (choiceWidget.isListChoice) {
  2028. // noteType = SKAnnotationFormListMenuKey;
  2029. // } else {
  2030. // noteType = SKAnnotationFormComboBoxKey;
  2031. // }
  2032. //
  2033. // }
  2034. // return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:note == [pdfView activeAnnotation]], SKAnnotationTypeImageCellActiveKey, noteType, SKAnnotationTypeImageCellTypeKey,[note color],SKAnnotationTypeImageCellColorKey, nil];
  2035. // }
  2036. // else if([tcID isEqualToString:COLOR_COLUMNID])
  2037. // return [note type] ? [note color] : nil;
  2038. // else if([tcID isEqualToString:PAGE_COLUMNID])
  2039. // return [[note page] displayLabel];
  2040. // else if([tcID isEqualToString:AUTHOR_COLUMNID])
  2041. // return [note type] ? [note userName] : nil;
  2042. // else if([tcID isEqualToString:DATE_COLUMNID])
  2043. // return [note type] ? [note modificationDate] : nil;
  2044. // }
  2045. return nil
  2046. }
  2047. func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
  2048. if outlineView.isEqual(to: self.tocOutlineView) {
  2049. let cell = outlineView.makeView(withIdentifier: KMTocTableCellView.km_identifier, owner: self) as! KMTocTableCellView
  2050. let tcID = tableColumn?.identifier.rawValue
  2051. var title = ""
  2052. var pageLabel = ""
  2053. if let data = item as? String, data == "Bookmarks" {
  2054. title = NSLocalizedString("Bookmarks", comment: "")
  2055. } else if let ol = item as? CPDFOutline {
  2056. title = ol.label
  2057. if ol.actionType == .page {
  2058. pageLabel = "\((ol.destination?.pageIndex ?? 0) + 1)"
  2059. }
  2060. } else if let bk = item as? CPDFBookmark {
  2061. title = bk.label
  2062. pageLabel = "\(bk.pageIndex + 1)"
  2063. }
  2064. if tcID == kLabelColumnId.rawValue {
  2065. if (self.isSearchOutlineMode) {
  2066. // NSString *roughString = [[ol label] stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
  2067. let roughString = title
  2068. let attributeString = NSMutableAttributedString(string: roughString)
  2069. let searchString = self.outlineSearchField.stringValue
  2070. var _roughString = roughString
  2071. var _searchString = searchString
  2072. if self.outlineIgnoreCaseFlag {
  2073. _roughString = _roughString.lowercased()
  2074. _searchString = _searchString.lowercased()
  2075. }
  2076. let ranges = _roughString.ranges(of: _searchString)
  2077. for range in ranges.nsRnage {
  2078. attributeString.addAttribute(.font, value: NSFont.boldSystemFont(ofSize: 13), range: range)
  2079. }
  2080. cell.tocLabel.attributedStringValue = attributeString
  2081. } else {
  2082. cell.tocLabel.stringValue = title
  2083. }
  2084. cell.pageLabel.stringValue = pageLabel
  2085. }
  2086. // else if([tcID isEqualToString:PAGE_COLUMNID]) {
  2087. // cell.pageLabel.stringValue = [ol pageLabel];
  2088. // }
  2089. return cell
  2090. } else if outlineView.isEqual(to: self.noteOutlineView) {
  2091. let model = item as? KMBOTAAnnotationItem
  2092. var note: CPDFAnnotation?
  2093. if self.noteSearchMode {
  2094. note = item as? CPDFAnnotation
  2095. } else {
  2096. note = (item as? KMBOTAAnnotationItem)?.annotation
  2097. }
  2098. let cell = outlineView.makeView(withIdentifier: KMNoteTableViewCell.km_identifier, owner: self) as! KMNoteTableViewCell
  2099. cell.cellNote = note
  2100. let noteColor = note?.color
  2101. var noteType = note?.type ?? ""
  2102. var noteString = ""
  2103. if let data = note {
  2104. noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: data)
  2105. }
  2106. var pageString = "\((note?.page?.pageIndex() ?? 0) + 1)"
  2107. var dateString = ""
  2108. if let date = note?.modificationDate() {
  2109. dateString = KMTools.timeString(timeDate: date)
  2110. }
  2111. var authorString = note?.userName() ?? ""
  2112. var noteTextString = note?.string() ?? ""
  2113. // if([noteType isEqualToString:@"Redact"]) {
  2114. // noteString = @"Redact";
  2115. // }
  2116. //
  2117. let timeKey = self.noteTypeDict[Self.Key.noteFilterTime] as? Bool
  2118. if timeKey == nil || timeKey == false {
  2119. // if (date != nil) {
  2120. cell.timeLabel.stringValue = dateString
  2121. //
  2122. // } else {
  2123. // cell.timeLabel.stringValue = ""
  2124. // }
  2125. cell.timeLabel.isHidden = false
  2126. } else {
  2127. cell.timeLabel.isHidden = true
  2128. }
  2129. let pageKey = self.noteTypeDict[Self.Key.noteFilterPage] as? Bool
  2130. if pageKey == nil || pageKey == false {
  2131. let labelsize = cell.pageLabel.stringValue.boundingRect(with: CGSizeMake(CGFloat(MAXFLOAT),CGRectGetHeight(cell.pageLabel.bounds)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font : NSFont.systemFont(ofSize: 12)])
  2132. cell.pageLabelWidthConstraint.constant = labelsize.size.width + 5
  2133. cell.pageLabel.stringValue = pageString
  2134. cell.pageLabel.isHidden = false
  2135. } else {
  2136. cell.pageLabel.isHidden = true
  2137. }
  2138. let autherKey = self.noteTypeDict[Self.Key.noteFilterAuther] as? Bool
  2139. if autherKey == nil || autherKey == false {
  2140. cell.autherLabel.stringValue = authorString
  2141. cell.autherLabel.isHidden = false
  2142. } else {
  2143. cell.autherLabel.isHidden = true
  2144. }
  2145. let imageView = KMNoteTypeImageView()
  2146. if let data = note {
  2147. if data.isKind(of: CPDFStampAnnotation.self) {
  2148. let annotation_stamp = data as! CPDFStampAnnotation
  2149. if (annotation_stamp.stampImage() != nil) {
  2150. noteType = SKNStampString
  2151. }
  2152. } else if data.isKind(of: CPDFLineAnnotation.self) {
  2153. let annotation_line = data as! CPDFLineAnnotation
  2154. if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .none {
  2155. noteType = SKNLine_NoneString
  2156. } else if annotation_line.startLineStyle == .none && annotation_line.endLineStyle == .openArrow {
  2157. noteType = SKNLine_OpenArrowString
  2158. } else {
  2159. noteType = SKNLine_NoneString
  2160. }
  2161. } else if data.isKind(of: CPDFButtonWidgetAnnotation.self) {
  2162. let buttonWidget = data as! CPDFButtonWidgetAnnotation
  2163. if buttonWidget.controlType() == .radioButtonControl {
  2164. noteType = KMAnnotationFormRadioButtonKey
  2165. } else if buttonWidget.controlType() == .checkBoxControl {
  2166. noteType = KMAnnotationFormCheckBoxKey
  2167. } else if buttonWidget.controlType() == .pushButtonControl {
  2168. noteType = KMAnnotationFormActionButtonKey
  2169. }
  2170. } else if data.isKind(of: CPDFTextWidgetAnnotation.self) {
  2171. noteType = KMAnnotationFormTextFieldKey
  2172. } else if data.isKind(of: CPDFChoiceWidgetAnnotation.self) {
  2173. let choiceWidget = data as! CPDFChoiceWidgetAnnotation
  2174. if choiceWidget.isListChoice {
  2175. noteType = KMAnnotationFormListMenuKey
  2176. } else {
  2177. noteType = KMAnnotationFormComboBoxKey
  2178. }
  2179. } else if data.isKind(of: KMTableAnnotation.self) {
  2180. noteType = "Ink_Table"
  2181. } else if data.isKind(of: KMSelfSignAnnotation.self) {
  2182. let selfSignNote = data as! KMSelfSignAnnotation
  2183. if selfSignNote.annotationType == .signFalse {
  2184. noteType = "KMSelfSignTypeFalseActionButtonKey"
  2185. } else if (selfSignNote.annotationType == .signature) {
  2186. noteType = "KMSelfSignTypeTureActionButtonKey"
  2187. } else if (selfSignNote.annotationType == .signCircle) {
  2188. noteType = "KMSelfSignTypeCircleActionButtonKey"
  2189. } else if (selfSignNote.annotationType == .signLine) {
  2190. noteType = "KMSelfSignTypeLineActionButtonKey"
  2191. } else if (selfSignNote.annotationType == .signDot) {
  2192. noteType = "KMSelfSignTypeDotActionButtonKey"
  2193. } else if (selfSignNote.annotationType == .signText) {
  2194. noteType = "KMSelfSignTypeTextActionButtonKey"
  2195. }
  2196. } else if data.isKind(of: CPDFSquareAnnotation.self) {
  2197. noteType = SKNSquareString
  2198. } else if data.isKind(of: CPDFTextAnnotation.self) {
  2199. noteType = SKNNoteString
  2200. } else if data.isKind(of: CPDFFreeTextAnnotation.self) {
  2201. noteType = SKNFreeTextString
  2202. } else if data.isKind(of: CPDFCircleAnnotation.self) {
  2203. noteType = SKNCircleString
  2204. } else if data.isKind(of: CPDFSignatureAnnotation.self) {
  2205. noteType = SKNSignatureString
  2206. } else if data.isKind(of: CPDFInkAnnotation.self) {
  2207. noteType = SKNInkString
  2208. } else if data.isKind(of: CPDFMarkupAnnotation.self) {
  2209. let anno = data as! CPDFMarkupAnnotation
  2210. if anno.markupType() == .highlight {
  2211. noteType = SKNHighlightString
  2212. } else if anno.markupType() == .underline {
  2213. noteType = SKNUnderlineString
  2214. } else if anno.markupType() == .strikeOut {
  2215. noteType = SKNStrikeOutString
  2216. }
  2217. }
  2218. }
  2219. cell.typeImageView.image = imageView.noteTypeImage(withType: noteType, color: noteColor ?? .red)
  2220. cell.typeImageView.isHidden = false
  2221. if note is CPDFMarkupAnnotation {
  2222. cell.isFold = true
  2223. }
  2224. cell.noteContentBox.isHidden = true
  2225. cell.noteImageView.isHidden = true
  2226. cell.foldButton.isHidden = true
  2227. cell.annotationContentLabel.isHidden = false
  2228. cell.noteContentLabel.stringValue = noteString
  2229. cell.contentView.isHidden = false
  2230. cell.contentViewHidden(false)
  2231. if let data = note {
  2232. if data.isKind(of: CPDFMarkupAnnotation.self) {
  2233. let markup = data as! CPDFMarkupAnnotation
  2234. var contentString = KMBOTAAnnotationTool.fetchText(text: markup.markupContent() ?? "")
  2235. contentString = contentString.replacingOccurrences(of: "\r", with: "")
  2236. contentString = contentString.replacingOccurrences(of: "\n", with: "")
  2237. cell.noteContentLabel.stringValue = contentString
  2238. if(contentString.isEmpty == false) {
  2239. cell.foldButton.isHidden = false
  2240. }
  2241. var attributeStr = NSMutableAttributedString(string: contentString)
  2242. if (markup.markupType() == .highlight) {
  2243. attributeStr.addAttribute(.backgroundColor, value: noteColor as Any, range: NSMakeRange(0, contentString.count))
  2244. } else if (markup.markupType() == .strikeOut) {
  2245. attributeStr.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, contentString.count))
  2246. attributeStr.addAttribute(.strikethroughColor, value: noteColor as Any, range: NSMakeRange(0, contentString.count))
  2247. } else if (markup.markupType() == .underline) {
  2248. attributeStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, contentString.count))
  2249. attributeStr.addAttribute(.underlineColor, value: noteColor as Any, range: NSMakeRange(0, contentString.count))
  2250. }
  2251. cell.annotationContentLabel.attributedStringValue = attributeStr
  2252. if self.foldType == .unfold {
  2253. // if let data = model?.foldType, data == .unfold { // 全部展开
  2254. cell.isFold = false
  2255. } else if self.foldType == .fold {
  2256. // else if let data = model?.foldType, data == .fold { // 全部折叠
  2257. cell.isFold = true
  2258. } else { // 混合
  2259. if self.allFoldNotes.isEmpty == false && self.allFoldNotes.contains(data) {
  2260. cell.isFold = false
  2261. } else {
  2262. cell.isFold = true
  2263. }
  2264. }
  2265. // noteString.isEmpty == false &&
  2266. if (contentString.isEmpty == false) {
  2267. cell.contentViewHidden(false)
  2268. } else {
  2269. cell.contentViewHidden(true)
  2270. }
  2271. } else if data.isKind(of: CPDFLineAnnotation.self) || noteType == SKNSquareString || noteType == SKNCircleString || noteType == SKNInkString {
  2272. cell.annotationContentLabel.stringValue = noteString
  2273. if (noteString.isEmpty == false) {
  2274. cell.contentViewHidden(false)
  2275. } else {
  2276. cell.contentViewHidden(true)
  2277. }
  2278. } else if data.isKind(of: CPDFStampAnnotation.self) {
  2279. if data.isKind(of: KMSelfSignAnnotation.self) {
  2280. let newAnnotation = note as! KMSelfSignAnnotation
  2281. let type = newAnnotation.annotationType
  2282. var returnString = ""
  2283. if (type == .signFalse) {
  2284. returnString = KMLocalizedString("X", nil)
  2285. } else if (type == .signature) {
  2286. returnString = KMLocalizedString("Check mark", nil)
  2287. } else if (type == .signCircle) {
  2288. returnString = KMLocalizedString("Circle", nil)
  2289. } else if (type == .signLine) {
  2290. returnString = KMLocalizedString("Line", nil)
  2291. } else if (type == .signDot) {
  2292. returnString = KMLocalizedString("Dot", nil)
  2293. } else if (type == .signText) {
  2294. returnString = KMLocalizedString("Text", nil)
  2295. }
  2296. cell.annotationContentLabel.stringValue = returnString
  2297. } else {
  2298. cell.annotationContentLabel.isHidden = true
  2299. cell.noteImageView.isHidden = false
  2300. let anno = note as! CPDFStampAnnotation
  2301. cell.noteImageView.image = anno.stampImage()
  2302. }
  2303. } else if data.isKind(of: CPDFTextAnnotation.self) {
  2304. cell.foldButton.isHidden = false
  2305. if noteString.isEmpty {
  2306. cell.annotationContentLabel.stringValue = noteTextString
  2307. }else{
  2308. cell.annotationContentLabel.stringValue = noteString
  2309. cell.noteContentLabel.stringValue = noteTextString
  2310. }
  2311. if (self.foldType == .unfold) {
  2312. cell.isFold = false
  2313. } else if (self.foldType == .fold) {
  2314. cell.isFold = true
  2315. } else {
  2316. if self.allFoldNotes.isEmpty == false && self.allFoldNotes.contains(data) {
  2317. cell.isFold = false
  2318. } else {
  2319. cell.isFold = true
  2320. }
  2321. }
  2322. if (noteString.isEmpty == false || noteTextString.isEmpty == false) {
  2323. cell.contentView.isHidden = false
  2324. } else {
  2325. cell.contentView.isHidden = true
  2326. cell.contentViewHidden(true)
  2327. }
  2328. // noteString.isEmpty == false &&
  2329. if (noteTextString.isEmpty == false) {
  2330. cell.foldButton.isHidden = false
  2331. }else{
  2332. cell.foldButton.isHidden = true
  2333. }
  2334. } else {
  2335. cell.annotationContentLabel.stringValue = noteString
  2336. cell.imageViewHeightConstraint.constant = cell.contentView.frame.size.height
  2337. if (noteString.isEmpty == false) {
  2338. cell.contentViewHidden(false)
  2339. } else {
  2340. cell.contentViewHidden(true)
  2341. }
  2342. }
  2343. }
  2344. cell.autherLayoutConstraint.constant = cell.autherLabel.isHidden ? -(cell.autherLabel.bounds.size.width) + 10.0 : 10.0
  2345. cell.typeImageViewLayoutConstraint.constant = cell.typeImageView.isHidden ? -(cell.typeImageView.bounds.size.width) : 0.0
  2346. cell.contentBoxLayoutConstraint.constant = cell.noteContentBox.isHidden ? -(cell.noteContentBox.bounds.size.height+8.0) : 8.0
  2347. if let data = note {
  2348. if data.isKind(of: CPDFStampAnnotation.self) && data.isKind(of: KMSelfSignAnnotation.self) == false {
  2349. } else {
  2350. if data.isKind(of: CPDFMarkupAnnotation.self) {
  2351. if (!cell.isFold) {
  2352. self.allFoldNotes.append(data)
  2353. } else {
  2354. cell.imageViewHeightConstraint.constant = 18.0 + 8
  2355. }
  2356. } else {
  2357. cell.imageViewHeightConstraint.constant = 18.0 + 8
  2358. }
  2359. }
  2360. }
  2361. cell.isUnFoldNote = { [unowned self] cellNote, isUnfold in
  2362. model?.foldType = isUnfold ? .unfold : .fold
  2363. // let COLUMN_INDENTATION: CGFloat = 16
  2364. // if let _cell = tableColumn?.dataCell as? NSCell {
  2365. // _cell.objectValue = cell.annotationContentLabel.attributedStringValue
  2366. // let bound = NSMakeRect(0.0, 0.0, fmax(10.0, NSWidth(outlineView.frame) - COLUMN_INDENTATION - outlineView.indentationPerLevel-40), CGFLOAT_MAX)
  2367. // let height = _cell.cellSize(forBounds: bound).height
  2368. // KMPrint(height)
  2369. // }
  2370. if cellNote is CPDFMarkupAnnotation {
  2371. // let content = cell.annotationContentLabel.attributedStringValue
  2372. // let bound = content.string.boundingRect(with: NSMakeSize(150, CGFLOAT_MAX), options: [.usesFontLeading, .usesLineFragmentOrigin], attributes: nil)
  2373. // KMPrint(bound)
  2374. // 154 34 273
  2375. // 273 - 188 = 85 noteContentHeightConstraint maltlineLabelLayoutConstraint
  2376. model?.foldH = isUnfold ? 30 : (cell.noteContentHeightConstraint.constant + cell.maltlineLabelLayoutConstraint.constant + 85)
  2377. }
  2378. if (isUnfold) {
  2379. if let data = note {
  2380. if (self.allFoldNotes.contains(data)) {
  2381. self.allFoldNotes.removeObject(data)
  2382. }
  2383. }
  2384. if (self.allFoldNotes.count == 0) {
  2385. self.foldType = .fold
  2386. } else {
  2387. self.foldType = .none
  2388. }
  2389. } else {
  2390. if let data = note {
  2391. if self.allFoldNotes.contains(data) == false {
  2392. self.allFoldNotes.append(data)
  2393. }
  2394. }
  2395. // if (rightSideController.allFoldNotes.count == rightSideController.canFoldNotes.count) {
  2396. self.foldType = .unfold
  2397. // } else {
  2398. // self.foldType = KMFoldAllAnnotationType_None;
  2399. // }
  2400. }
  2401. }
  2402. return cell
  2403. }
  2404. return nil
  2405. }
  2406. func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
  2407. if outlineView.isEqual(self.noteOutlineView) {
  2408. if let model = item as? KMBOTAAnnotationItem {
  2409. if model.foldType == .fold {
  2410. return model.foldH
  2411. }
  2412. if let anno = model.annotation {
  2413. return KMBOTAAnnotationTool.fetchCellHeight(annotation: anno, maxSize: CGSize(width: 260+40 - 16, height: 1000))
  2414. }
  2415. }
  2416. return 30
  2417. } else if outlineView.isEqual(self.tocOutlineView) {
  2418. if let tempItem = item as? CPDFOutline {
  2419. let string: NSString = tempItem.label as NSString
  2420. let paragraphStyle = NSMutableParagraphStyle()
  2421. paragraphStyle.lineHeightMultiple = 1.32
  2422. paragraphStyle.alignment = .left
  2423. let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle,
  2424. NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0)]
  2425. let size = string.boundingRect(with: CGSizeMake(outlineView.frame.size.width - 30, 200), options: NSString.DrawingOptions(rawValue: 3), attributes: attributes)
  2426. return max(40, size.height + 16)
  2427. }
  2428. return 40
  2429. }
  2430. return outlineView.rowHeight
  2431. }
  2432. func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
  2433. if outlineView.isEqual(self.tocOutlineView) {
  2434. // var _item: CPDFOutline?
  2435. // if item == nil && self.listView.document.isLocked == false {
  2436. // _item = self.listView.document.outlineRoot()
  2437. // }
  2438. if let data = item as? String, data == "Bookmarks" {
  2439. return true
  2440. } else if item is CPDFOutline {
  2441. return ((item as? CPDFOutline)?.numberOfChildren ?? 0) != 0
  2442. } else if item is CPDFBookmark {
  2443. return false
  2444. }
  2445. if (self.isSearchOutlineMode) {
  2446. // return [self subOutLineContainString:self.leftSideController.outlineSearchField.stringValue rootOutline:(PDFOutline *)item];
  2447. } else {
  2448. // return ((_item?.numberOfChildren ?? 0) != 0)
  2449. }
  2450. } else if outlineView.isEqual(to: self.noteOutlineView) {
  2451. // return [item hasNoteText];
  2452. return false
  2453. }
  2454. return false
  2455. }
  2456. func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
  2457. if outlineView.isEqual(self.tocOutlineView) {
  2458. let itemView = KMBotaTableRowView()
  2459. return itemView
  2460. } else if outlineView.isEqual(self.noteOutlineView) {
  2461. let itemView = KMBotaTableRowView()
  2462. return itemView;
  2463. }
  2464. return nil
  2465. }
  2466. func outlineViewSelectionDidChange(_ notification: Notification) {
  2467. if self.tocOutlineView.isEqual(to: notification.object) {
  2468. if self.dragIn {
  2469. return
  2470. }
  2471. if self.updatingOutlineSelection == false {
  2472. self.updatingOutlineSelection = true
  2473. self.goToSelectedOutlineItem(nil)
  2474. self.updatingOutlineSelection = false
  2475. }
  2476. }
  2477. }
  2478. func outlineViewItemDidExpand(_ notification: Notification) {
  2479. if self.tocOutlineView.isEqual(to: notification.object) {
  2480. self.updateOutlineSelection()
  2481. }
  2482. }
  2483. func outlineViewItemDidCollapse(_ notification: Notification) {
  2484. if self.tocOutlineView.isEqual(to: notification.object) {
  2485. self.updateOutlineSelection()
  2486. }
  2487. }
  2488. func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
  2489. var dragOp = NSDragOperation(rawValue: 0)
  2490. if outlineView.isEqual(to: self.noteOutlineView) {
  2491. let pboard = info.draggingPasteboard
  2492. if pboard.canReadObject(forClasses: [NSColor.self], options: [:]) && index == NSOutlineViewDropOnItemIndex {
  2493. if let note = item as? CPDFAnnotation, note.type != nil {
  2494. dragOp = .every
  2495. }
  2496. }
  2497. } else if outlineView.isEqual(to: self.tocOutlineView) {
  2498. if (index == -1) {
  2499. dragOp = NSDragOperation(rawValue: 0)
  2500. } else {
  2501. dragOp = .move
  2502. }
  2503. }
  2504. return dragOp
  2505. }
  2506. func outlineView(_ outlineView: NSOutlineView, writeItems items: [Any], to pasteboard: NSPasteboard) -> Bool {
  2507. if outlineView.isEqual(to: self.tocOutlineView) {
  2508. if (self.tocOutlineView.selectedRowIndexes.count > 1) {
  2509. return false
  2510. }
  2511. let tIndex = IndexSet(integer: self.tocOutlineView.clickedRow)
  2512. self.tocOutlineView.deselectRow(tIndex.first ?? 0)
  2513. self._dragPDFOutline = items.first as? CPDFOutline
  2514. let set = IndexSet(integer: 0)
  2515. let zNSIndexSetData = NSKeyedArchiver.archivedData(withRootObject: set)
  2516. // [pasteboard declareTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType] owner:self];
  2517. pasteboard.declareTypes([.localDraggedTypes], owner: self)
  2518. pasteboard.setData(zNSIndexSetData, forType: .localDraggedTypes)
  2519. return true
  2520. }
  2521. return false
  2522. }
  2523. func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
  2524. if outlineView.isEqual(to: self.noteOutlineView) {
  2525. let pboard = info.draggingPasteboard
  2526. if pboard.canReadObject(forClasses: [NSColor.self], options: [:]) {
  2527. // [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
  2528. let isShift = NSEvent.modifierFlags.contains(.shift)
  2529. let isAlt = NSEvent.modifierFlags.contains(.option)
  2530. guard let note = item as? CPDFAnnotation else {
  2531. NSSound.beep()
  2532. return false
  2533. }
  2534. if let color = NSColor(from: pboard) {
  2535. note.setColor(color, alternate: isAlt, updateDefaults: isShift)
  2536. return true
  2537. }
  2538. return false
  2539. }
  2540. } else if outlineView.isEqual(to: self.tocOutlineView) {
  2541. if (index < 0) {
  2542. return false
  2543. }
  2544. // guard let outline = item as? CPDFOutline else {
  2545. // return false
  2546. // }
  2547. let outline = item as? CPDFOutline
  2548. guard let dragPDFOL = self._dragPDFOutline else {
  2549. return false
  2550. }
  2551. //root,drag item to root
  2552. if ((outline?.parent == nil)) {
  2553. //fetch root
  2554. var root = dragPDFOL
  2555. while (root.parent != nil) {
  2556. root = root.parent
  2557. }
  2558. if dragPDFOL.parent.isEqual(to: root) {
  2559. if dragPDFOL.index > index {
  2560. self.dragPDFOutline(self._dragPDFOutline, toIndex: index, newParentOutline: root)
  2561. } else {
  2562. self.dragPDFOutline(self._dragPDFOutline, toIndex: index-1, newParentOutline: root)
  2563. }
  2564. } else {
  2565. self.dragPDFOutline(self._dragPDFOutline, toIndex: index, newParentOutline: root)
  2566. }
  2567. } else {
  2568. //在同一个层级内移动
  2569. if dragPDFOL.parent.isEqual(to: item) {
  2570. if (dragPDFOL.index > 0) {
  2571. if dragPDFOL.index > index {
  2572. self.dragPDFOutline(self._dragPDFOutline, toIndex: index, newParentOutline: outline)
  2573. }else{
  2574. self.dragPDFOutline(self._dragPDFOutline, toIndex: index-1, newParentOutline: outline)
  2575. }
  2576. } else {
  2577. return false
  2578. }
  2579. } else {
  2580. var tOutlline: CPDFOutline? = outline
  2581. var isContains = false
  2582. while (tOutlline != nil) {
  2583. if tOutlline!.isEqual(to: self._dragPDFOutline) {
  2584. isContains = true
  2585. break
  2586. }
  2587. tOutlline = tOutlline?.parent
  2588. }
  2589. if (!isContains) {
  2590. self.dragPDFOutline(self._dragPDFOutline, toIndex: index, newParentOutline: outline)
  2591. }
  2592. }
  2593. }
  2594. return true
  2595. }
  2596. return false
  2597. }
  2598. func outlineView(_ outlineView: NSOutlineView, willDisplayOutlineCell cell: Any, for tableColumn: NSTableColumn?, item: Any) {
  2599. if outlineView.isEqual(to: self.tocOutlineView) {
  2600. if outlineView.selectionHighlightStyle == .regular && outlineView.isRowSelected(outlineView.row(forItem: item)) {
  2601. (cell as? NSCell)?.backgroundStyle = .lowered
  2602. }
  2603. }
  2604. }
  2605. func outlineView(_ outlineView: NSOutlineView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, byItem item: Any?) {
  2606. if outlineView.isEqual(to: self.noteOutlineView) {
  2607. // PDFAnnotation *note = item;
  2608. var note = item as? CPDFAnnotation
  2609. if note == nil && note is KMBOTAAnnotationItem {
  2610. note = (note as? KMBOTAAnnotationItem)?.annotation
  2611. }
  2612. if let data = note?.type, data.isEmpty == false {
  2613. if tableColumn?.identifier.rawValue == self.noteColumnId.rawValue {
  2614. let string1 = (object as? String) ?? ""
  2615. let string2 = note?.string() ?? ""
  2616. if string1 != string2 {
  2617. note?.setString(string1)
  2618. }
  2619. } else if tableColumn?.identifier.rawValue == self.authorColumnId.rawValue {
  2620. let string1 = (object as? String) ?? ""
  2621. let string2 = note?.userName() ?? ""
  2622. if string1 != string2 {
  2623. note?.setUserName(string1)
  2624. }
  2625. }
  2626. }
  2627. }
  2628. }
  2629. func outlineView(_ outlineView: NSOutlineView, dataCellFor tableColumn: NSTableColumn?, item: Any) -> NSCell? {
  2630. if self.noteOutlineView.isEqual(to: outlineView) {
  2631. if tableColumn == nil {
  2632. if let anno = item as? CPDFAnnotation, anno.type == nil {
  2633. return outlineView.tableColumn(withIdentifier: self.noteColumnId)?.dataCell(forRow: outlineView.row(forItem: item)) as? NSCell
  2634. }
  2635. }
  2636. }
  2637. return tableColumn?.dataCell(forRow: outlineView.row(forItem: item)) as? NSCell
  2638. }
  2639. func outlineView(_ outlineView: NSOutlineView, shouldEdit tableColumn: NSTableColumn?, item: Any) -> Bool {
  2640. if outlineView.isEqual(to: self.noteOutlineView) {
  2641. if (tableColumn == nil) {
  2642. if self.listView.hideNotes == false {
  2643. if let anno = item as? CPDFAnnotation, anno.isNote() {
  2644. // if ([pdfView hideNotes] == NO && [[(SKNoteText *)item note] isNote]) {
  2645. // PDFAnnotation *annotation = [(SKNoteText *)item note];
  2646. self.listView.scrollAnnotationToVisible(anno)
  2647. self.listView.updateActiveAnnotations([anno])
  2648. // [self showNote:annotation];
  2649. // SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
  2650. // [[noteController window] makeFirstResponder:[noteController textView]];
  2651. // [[noteController textView] selectAll:nil];
  2652. }
  2653. }
  2654. return false
  2655. } else if tableColumn?.identifier.rawValue == self.noteColumnId.rawValue || tableColumn?.identifier.rawValue == self.authorColumnId.rawValue {
  2656. return true
  2657. }
  2658. }
  2659. return false
  2660. }
  2661. func outlineView(_ outlineView: NSOutlineView, toolTipFor cell: NSCell, rect: NSRectPointer, tableColumn: NSTableColumn?, item: Any, mouseLocation: NSPoint) -> String {
  2662. if outlineView.isEqual(to: self.noteOutlineView) {
  2663. if tableColumn == nil || tableColumn?.identifier.rawValue == self.noteColumnId.rawValue {
  2664. return (item as? CPDFAnnotation)?.string() ?? ""
  2665. }
  2666. }
  2667. return ""
  2668. }
  2669. func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItems draggedItems: [Any]) {
  2670. self.dragIn = true
  2671. }
  2672. func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
  2673. self.dragIn = false
  2674. }
  2675. /*
  2676. #pragma mark NSOutlineView delegate protocol
  2677. - (void)outlineView:(NSOutlineView *)ov didClickTableColumn:(NSTableColumn *)tableColumn {
  2678. if ([ov isEqual:rightSideController.noteOutlineView]) {
  2679. NSTableColumn *oldTableColumn = [ov highlightedTableColumn];
  2680. NSTableColumn *newTableColumn = ([NSEvent modifierFlags] & NSEventModifierFlagCommand) ? nil : tableColumn;
  2681. NSMutableArray *sortDescriptors = nil;
  2682. BOOL ascending = YES;
  2683. if ([oldTableColumn isEqual:newTableColumn]) {
  2684. sortDescriptors = [[[rightSideController.noteArrayController sortDescriptors] mutableCopy] autorelease];
  2685. [sortDescriptors replaceObjectAtIndex:0 withObject:[[sortDescriptors firstObject] reversedSortDescriptor]];
  2686. ascending = [[sortDescriptors firstObject] ascending];
  2687. } else {
  2688. NSString *tcID = [newTableColumn identifier];
  2689. NSSortDescriptor *pageIndexSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationPageIndexKey ascending:ascending] autorelease];
  2690. NSSortDescriptor *boundsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKPDFAnnotationBoundsOrderKey ascending:ascending selector:@selector(compare:)] autorelease];
  2691. sortDescriptors = [NSMutableArray arrayWithObjects:pageIndexSortDescriptor, boundsSortDescriptor, nil];
  2692. if ([tcID isEqualToString:TYPE_COLUMNID]) {
  2693. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationTypeKey ascending:YES selector:@selector(noteTypeCompare:)] autorelease] atIndex:0];
  2694. } else if ([tcID isEqualToString:COLOR_COLUMNID]) {
  2695. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationColorKey ascending:YES selector:@selector(colorCompare:)] autorelease] atIndex:0];
  2696. } else if ([tcID isEqualToString:NOTE_COLUMNID]) {
  2697. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationStringKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
  2698. } else if ([tcID isEqualToString:AUTHOR_COLUMNID]) {
  2699. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationUserNameKey ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease] atIndex:0];
  2700. } else if ([tcID isEqualToString:DATE_COLUMNID]) {
  2701. [sortDescriptors insertObject:[[[NSSortDescriptor alloc] initWithKey:SKNPDFAnnotationModificationDateKey ascending:YES] autorelease] atIndex:0];
  2702. }
  2703. if (oldTableColumn)
  2704. [ov setIndicatorImage:nil inTableColumn:oldTableColumn];
  2705. [ov setHighlightedTableColumn:newTableColumn];
  2706. }
  2707. [rightSideController.noteArrayController setSortDescriptors:sortDescriptors];
  2708. if (newTableColumn)
  2709. [ov setIndicatorImage:[NSImage imageNamed:ascending ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
  2710. inTableColumn:newTableColumn];
  2711. [ov reloadData];
  2712. }
  2713. }
  2714. - (void)outlineViewColumnDidResize:(NSNotification *)notification{
  2715. if (mwcFlags.autoResizeNoteRows &&
  2716. [[notification object] isEqual:rightSideController.noteOutlineView] &&
  2717. [[[[notification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:NOTE_COLUMNID] &&
  2718. [(SKScrollView *)[[notification object] enclosingScrollView] isResizingSubviews] == NO) {
  2719. [rowHeights removeAllFloats];
  2720. [rightSideController.noteOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.noteOutlineView numberOfRows])]];
  2721. }
  2722. }
  2723. - (void)sizeOutlineViewToContents:(NSOutlineView*) outlineView;
  2724. {
  2725. NSInteger rowCount = [outlineView numberOfRows];
  2726. for (NSInteger i = 0; i < rowCount; i++){
  2727. CGFloat rowHeight = 0;
  2728. PDFOutline *outline = [leftSideController.tocOutlineView itemAtRow:i];
  2729. if (!outline){
  2730. continue;
  2731. }
  2732. NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc]init] autorelease];
  2733. NSDictionary *dictAttr1 = @{NSForegroundColorAttributeName:[KMAppearance KMColor_Layout_H0]};
  2734. NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:outline.label attributes:dictAttr1];
  2735. [attributedString appendAttributedString:attr1];
  2736. // NSTableCellView *viewS = [leftSideController.tocOutlineView viewAtColumn:0 row:i makeIfNecessary:YES];
  2737. NSTableColumn *tableColumn = [leftSideController.tocOutlineView tableColumnWithIdentifier:LABEL_COLUMNID];
  2738. // id cell = [tableColumn dataCell];
  2739. id cell = [tableColumn dataCellForRow:i];
  2740. [cell setObjectValue:attributedString];
  2741. CGFloat w = leftSideController.view.frame.size.width - 86;//[tableColumn width] > 260 ? [tableColumn width] : 260;
  2742. NSInteger num = [self getNum:outline];
  2743. CGFloat gap = [leftSideController.tocOutlineView indentationPerLevel];
  2744. rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, w - (num > 0?16:0) - gap*num, CGFLOAT_MAX)].height;
  2745. rowHeight = fmax(rowHeight, [leftSideController.tocOutlineView rowHeight]) + 25;
  2746. [rowHeights setFloat:rowHeight forKey:outline];
  2747. if (@available(macOS 10.13, *)) {
  2748. } else {
  2749. rowHeight = 40.0;
  2750. }
  2751. // CGRect fram = viewS.frame;
  2752. // viewS.frame = CGRectMake(fram.origin.x, fram.origin.y, fram.size.width, rowHeight);
  2753. }
  2754. [leftSideController.tocOutlineView reloadData];
  2755. }
  2756. */
  2757. func noteItems(_ items: NSArray) -> NSArray {
  2758. var noteItems = NSMutableArray()
  2759. for item in items {
  2760. guard let anno = (item as? KMBOTAAnnotationItem)?.annotation else {
  2761. continue
  2762. }
  2763. if anno.type == nil {
  2764. // item = [(SKNoteText *)item note];
  2765. }
  2766. if noteItems.contains(anno) == false {
  2767. noteItems.add(anno)
  2768. }
  2769. }
  2770. return noteItems
  2771. }
  2772. }
  2773. // MARK: - KMCustomOutlineViewDelegate, KMCustomOutlineViewDataSource
  2774. extension KMLeftSideViewController: KMCustomOutlineViewDelegate, KMCustomOutlineViewDataSource {
  2775. func outlineView(_ anOutlineView: NSOutlineView, canDeleteItems items: [Any]) -> Bool {
  2776. if anOutlineView.isEqual(to: self.noteOutlineView) {
  2777. return self.listView.hideNotes == false && items.count > 0
  2778. } else if anOutlineView.isEqual(to: self.tocOutlineView) {
  2779. return items.count > 0
  2780. }
  2781. return false
  2782. }
  2783. func outlineView(_ anOutlineView: NSOutlineView, deleteItems items: [Any]) {
  2784. if anOutlineView.isEqual(to: self.noteOutlineView) {
  2785. if (items.isEmpty) {
  2786. return
  2787. }
  2788. for item in self.noteItems(items as NSArray) {
  2789. guard let anno = item as? CPDFAnnotation else {
  2790. continue
  2791. }
  2792. self.listView.remove(anno)
  2793. }
  2794. self.listView.undoManager?.setActionName(KMLocalizedString("Remove Note", "Undo action name"))
  2795. self.reloadAnnotation()
  2796. self.annotationSort(sortArray: [])
  2797. self.noteOutlineView.reloadData()
  2798. } else if anOutlineView.isEqual(to: self.tocOutlineView) {
  2799. self.outlineContextMenuItemClicked_RemoveEntry(nil)
  2800. }
  2801. }
  2802. func outlineView(_ anOutlineView: NSOutlineView, canCopyItems items: [Any]) -> Bool {
  2803. if anOutlineView.isEqual(to: self.noteOutlineView) {
  2804. if (items.count == 1) {
  2805. // PDFAnnotation *annotation = [[self noteItems:items] lastObject];
  2806. // if ([annotation isKindOfClass:[PDFAnnotationStamp class]] ||
  2807. // [annotation isKindOfClass:[PDFAnnotationLink class]]) {
  2808. // return NO;
  2809. // }
  2810. }
  2811. return items.count > 0
  2812. }
  2813. return false
  2814. }
  2815. func outlineView(_ anOutlineView: NSOutlineView, copyItems items: [Any]) {
  2816. if anOutlineView.isEqual(to: self.noteOutlineView) && items.isEmpty == false {
  2817. let pboard = NSPasteboard.general
  2818. var copiedItems: [Any] = []
  2819. var attrString = NSMutableAttributedString()
  2820. var isAttributed = false
  2821. var item: AnyObject?
  2822. // for (item in [self noteItems:items]) {
  2823. // if ([item isMovable])
  2824. // [copiedItems addObject:item];
  2825. // }
  2826. // for (item in items) {
  2827. // if ([attrString length])
  2828. // [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:@"\n\n"];
  2829. // if ([(PDFAnnotation *)item type] == nil && [[(SKNoteText *)item note] isNote]) {
  2830. // [attrString appendAttributedString:[(SKNoteText *)item text]];
  2831. // isAttributed = YES;
  2832. // } else {
  2833. // [attrString replaceCharactersInRange:NSMakeRange([attrString length], 0) withString:[item string] ?: @""];
  2834. // }
  2835. // }
  2836. //
  2837. // [pboard clearContents];
  2838. // if (isAttributed)
  2839. // [pboard writeObjects:[NSArray arrayWithObjects:attrString, nil]];
  2840. // else
  2841. // [pboard writeObjects:[NSArray arrayWithObjects:[attrString string], nil]];
  2842. // if ([copiedItems count] > 0)
  2843. // [pboard writeObjects:copiedItems];
  2844. }
  2845. }
  2846. func outlineView(_ anOutlineView: NSOutlineView, typeSelectHelperSelectionStrings aTypeSelectHelper: SKTypeSelectHelper) -> NSArray {
  2847. if self.noteOutlineView.isEqual(to: anOutlineView) {
  2848. let count = self.noteOutlineView.numberOfRows
  2849. var texts = NSMutableArray(capacity: count)
  2850. for i in 0 ..< count {
  2851. let item = self.noteOutlineView.item(atRow: i)
  2852. let string = (item as? CPDFAnnotation)?.string() ?? ""
  2853. texts.add(string)
  2854. }
  2855. return texts
  2856. } else if self.tocOutlineView.isEqual(to: anOutlineView) {
  2857. let count = self.tocOutlineView.numberOfRows
  2858. var array = NSMutableArray(capacity: count)
  2859. for i in 0 ..< count {
  2860. // [array addObject:[[(PDFOutline *)[leftSideController.tocOutlineView itemAtRow:i] label] lossyStringUsingEncoding:NSASCIIStringEncoding]];
  2861. let item = self.tocOutlineView.item(atRow: i) as? CPDFOutline
  2862. array.add(item?.label ?? "")
  2863. }
  2864. return array
  2865. }
  2866. return NSArray()
  2867. }
  2868. func outlineView(_ anOutlineView: NSOutlineView, typeSelectHelper aTypeSelectHelper: SKTypeSelectHelper, didFailToFindMatchForSearchString searchString: String) {
  2869. // if ([ov isEqual:rightSideController.noteOutlineView]) {
  2870. // [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  2871. // } else if ([ov isEqual:leftSideController.tocOutlineView]) {
  2872. // [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  2873. // }
  2874. }
  2875. func tableView(_ aTableView: NSTableView, typeSelectHelper aTypeSelectHelper: SKTypeSelectHelper, updateSearchString searchString: String) {
  2876. // if ([typeSelectHelper isEqual:[leftSideController.thumbnailTableView typeSelectHelper]] || [typeSelectHelper isEqual:[pdfView typeSelectHelper]]) {
  2877. // if (searchString)
  2878. // [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  2879. // else
  2880. // [self updateLeftStatus];
  2881. // } else if ([typeSelectHelper isEqual:[rightSideController.noteOutlineView typeSelectHelper]]) {
  2882. // if (searchString)
  2883. // [statusBar setRightStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding note: \"%@\"", @"Status message"), searchString]];
  2884. // else
  2885. // [self updateRightStatus];
  2886. // } else if ([typeSelectHelper isEqual:[leftSideController.tocOutlineView typeSelectHelper]]) {
  2887. // if (searchString)
  2888. // [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Finding: \"%@\"", @"Status message"), searchString]];
  2889. // else
  2890. // [self updateLeftStatus];
  2891. // }
  2892. }
  2893. }
  2894. // MARK: - Other
  2895. extension KMLeftSideViewController {
  2896. @objc func goToSelectedOutlineItem(_ sender: AnyObject?) {
  2897. let outlineItem = self.tocOutlineView.item(atRow: self.tocOutlineView.selectedRow)
  2898. let outline = self.tocOutlineView
  2899. if let cnt = outline?.selectedRowIndexes.count, cnt == 1 {
  2900. if outlineItem is CPDFOutline {
  2901. let outline = (outlineItem as! CPDFOutline)
  2902. if let des = outline.destination {
  2903. self.listView.go(to: des)
  2904. } else if let action = outline.action {
  2905. self.listView.perform(action)
  2906. }
  2907. } else if outlineItem is CPDFBookmark {
  2908. let bookmark = outlineItem as! CPDFBookmark
  2909. self.listView.go(toPageIndex: bookmark.pageIndex, animated: true)
  2910. }
  2911. }
  2912. }
  2913. @objc func goToSelectedFindResults(_ sender: AnyObject?) {
  2914. KMPrint("KMLeftSideViewController-goToSelectedFindResults...")
  2915. }
  2916. func tableView(_ tv: NSTableView, extractRowsWithIndexes rowIndexes: IndexSet) {
  2917. if tv.isEqual(to: self.thumbnailTableView) {
  2918. guard let document = self.listView.document else {
  2919. return
  2920. }
  2921. var pages = NSMutableArray()
  2922. for idx in self.thumbnailTableView.selectedRowIndexes {
  2923. if (idx < document.pageCount) {
  2924. if let page = self.listView.document.page(at: UInt(idx)) {
  2925. pages.add(page)
  2926. }
  2927. }
  2928. }
  2929. let fileName = document.getFileNameAccordingSelctPages(pages as! [CPDFPage])
  2930. let saveAccessCtr = KMSavePanelAccessoryController()
  2931. let outputSavePanel = NSSavePanel()
  2932. outputSavePanel.allowedFileTypes = ["pdf"]
  2933. outputSavePanel.accessoryView = saveAccessCtr.view
  2934. outputSavePanel.nameFieldStringValue = fileName
  2935. outputSavePanel.beginSheetModal(for: self.view.window!) { result in
  2936. if (result == .OK) {
  2937. DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
  2938. let vc = KMProgressWindowController()
  2939. self.view.window?.beginSheet(vc.window!)
  2940. let saveFilePath = outputSavePanel.url?.path
  2941. DispatchQueue.global().async {
  2942. let pdf = CPDFDocument()
  2943. let success = pdf?.extractAsOneDocument(withPages: pages as! [CPDFPage], savePath: saveFilePath) ?? false
  2944. DispatchQueue.main.async {
  2945. if (success) {
  2946. if (saveAccessCtr.openAutomaticButton.state == .on) {
  2947. NSDocumentController.shared.km_safe_openDocument(withContentsOf: outputSavePanel.url!, display: true) { _, _, _ in
  2948. }
  2949. } else {
  2950. KMTools.viewFile(at: saveFilePath!)
  2951. }
  2952. }
  2953. NSApp.endSheet(vc.window!)
  2954. vc.close()
  2955. }
  2956. }
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. func fileNameWithSelectedPages(_ itemIndexes: IndexSet) -> String {
  2963. var pagesName = ""
  2964. if (itemIndexes.count > 1) {
  2965. pagesName.append(" pages")
  2966. } else {
  2967. pagesName.append("page")
  2968. }
  2969. let docmentName = self.listView.document?.documentURL.deletingPathExtension().lastPathComponent ?? ""
  2970. var fileName = ""
  2971. if (itemIndexes.count > 0) {
  2972. if (itemIndexes.count == 1) {
  2973. let idx = itemIndexes.first! + 1
  2974. let tFileName = String(format: "%@ %@", pagesName, "\(idx)")
  2975. return String(format: "%@%@", docmentName, tFileName)
  2976. }
  2977. var sortIndex = IndexSet()
  2978. for idx in itemIndexes {
  2979. let _idx = idx + 1
  2980. sortIndex.insert(_idx)
  2981. }
  2982. // NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
  2983. // NSArray *sortDesc = @[sort];
  2984. // NSArray *sortArray = [sortIndex sortedArrayUsingDescriptors:sortDesc];
  2985. let sortArray = sortIndex.sorted()
  2986. var a = 0
  2987. var b = 0
  2988. for num in sortArray {
  2989. // for (NSNumber *num in sortArray) {
  2990. if (fileName.isEmpty == false) {
  2991. if (num == b+1) {
  2992. b = num
  2993. if (num == sortArray.last) {
  2994. fileName = "\(fileName)\(a)-\(b)"
  2995. }
  2996. } else {
  2997. if (a == b) {
  2998. fileName = "\(fileName)\(a),"
  2999. } else {
  3000. fileName = "\(fileName)\(a)-\(b),"
  3001. }
  3002. b = num
  3003. a = b
  3004. if (num == sortArray.last) {
  3005. fileName = "\(fileName)\(a)"
  3006. }
  3007. }
  3008. } else {
  3009. fileName = ""
  3010. b = num
  3011. a = b
  3012. }
  3013. }
  3014. let tFileName = String(format: "%@ %@", pagesName,fileName)
  3015. return String(format: "%@%@", docmentName,tFileName)
  3016. }
  3017. return ""
  3018. }
  3019. func draggedFileName(for page: CPDFPage) -> String {
  3020. let pageIndex = "\(page.pageIndex() + 1)"
  3021. var fileName = ""
  3022. if let doc = self.view.window?.windowController?.document as? NSDocument {
  3023. fileName = doc.displayName.deletingPathExtension
  3024. }
  3025. return "\(fileName)-Page \(pageIndex)"
  3026. }
  3027. func switchType(_ type: BotaType) {
  3028. if type == .Thumbnail {
  3029. self.leftView.segmentedControl.selectedSegment = 0
  3030. } else if type == .Outline {
  3031. self.leftView.segmentedControl.selectedSegment = 1
  3032. } else if type == .Annotation {
  3033. self.leftView.segmentedControl.selectedSegment = 2
  3034. } else if type == .snapshot {
  3035. self.leftView.segmentedControl.selectedSegment = 3
  3036. } else if type == .Search {
  3037. self.leftView.segmentedControl.selectedSegment = 4
  3038. }
  3039. }
  3040. var TINY_SIZE: Float {
  3041. get {
  3042. return 32.0
  3043. }
  3044. }
  3045. var SMALL_SIZE: Float {
  3046. get {
  3047. return 64.0
  3048. }
  3049. }
  3050. var LARGE_SIZE: Float {
  3051. get {
  3052. return 128.0
  3053. }
  3054. }
  3055. var HUGE_SIZE: Float {
  3056. get {
  3057. return 256.0
  3058. }
  3059. }
  3060. var FUDGE_SIZE: Float {
  3061. get {
  3062. return 0.1
  3063. }
  3064. }
  3065. func updateTableFont() {
  3066. let font = NSFont.systemFont(ofSize: KMPreference.shared.outlineFontSize.cgFloat)
  3067. self.tocOutlineView.font = font
  3068. self.noteOutlineView.font = font
  3069. self.findTableView.font = font
  3070. self.groupedFindTableView.font = font
  3071. }
  3072. }