KMLeftSideViewController.swift 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435
  1. //
  2. // KMLeftSideViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lxy on 2022/10/10.
  6. //
  7. import Cocoa
  8. @objc protocol KMLeftSideViewControllerDelegate {
  9. @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
  10. @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
  11. @objc optional func searchAction(searchString:String, isCase:Bool)
  12. @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
  13. @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
  14. @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
  15. @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
  16. }
  17. class KMLeftSideViewController: KMSideViewController {
  18. // var listView : CPDFListView!
  19. // @IBOutlet weak var leftTableview: NSTableView!
  20. // @IBOutlet weak var contentBox: NSBox!
  21. // @IBOutlet weak var leftBox: NSBox!
  22. lazy var outlineViewController : KMOutlineViewController = {
  23. let outlineViewController = KMOutlineViewController()
  24. return outlineViewController
  25. }()
  26. lazy var annotationViewController : KMAnnotationViewController = {
  27. let annotationViewController = KMAnnotationViewController()
  28. return annotationViewController
  29. }()
  30. lazy var bookViewController : KMBookMarkViewController = {
  31. let bookViewController = KMBookMarkViewController()
  32. bookViewController.bookMarkDidChange = { [unowned self] (controller, bookMarks) in
  33. self.delegate?.controller?(controller: self, bookMarkDidChange: bookMarks)
  34. }
  35. return bookViewController
  36. }()
  37. lazy var fromViewController : KMFromViewController = {
  38. let fromViewController = KMFromViewController()
  39. return fromViewController
  40. }()
  41. lazy var signatureViewController : KMSignatureViewController = {
  42. let signatureViewController = KMSignatureViewController()
  43. return signatureViewController
  44. }()
  45. lazy var panelSetViewController : KMPDFViewPanelSetViewController = {
  46. let panelSetViewController = KMPDFViewPanelSetViewController()
  47. // panelSetViewController.delegate = self
  48. return panelSetViewController
  49. }()
  50. var dataSource : [KMLeftMethodMode] = [KMLeftMethodMode]()
  51. var type : KMLeftMethodMode = KMLeftMethodMode()
  52. var isShowPanel : Bool = false
  53. var norImage : [String] = []
  54. var selectImage : [String] = []
  55. var mainVC: KMMainViewController?
  56. //select page
  57. var selectPages: [Int]?
  58. open weak var delegate: KMLeftSideViewControllerDelegate?
  59. deinit {
  60. KMPrint("KMLeftSideViewController deinit.")
  61. NotificationCenter.default.removeObserver(self)
  62. }
  63. override var nibName: NSNib.Name? {
  64. return "LeftSideView"
  65. }
  66. convenience init(type : KMLeftMethodMode) {
  67. self.init()
  68. self.type = type
  69. }
  70. override func viewDidLoad() {
  71. super.viewDidLoad()
  72. // self.leftBox.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
  73. // self.leftTableview.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
  74. // self.leftTableview.border(NSColor.km_init(hex: "#EDEEF0"),1 , 0)
  75. // self.addMenuTitle()
  76. // self.refreshShowMethod()
  77. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  78. // self.resetThumbnails()
  79. }
  80. func showPanelView(show: Bool) {
  81. self.isShowPanel = show
  82. if show {
  83. // self.panelSetViewController.listView = self.listView
  84. // self.panelSetViewController.view.frame = self.view.frame
  85. // self.view.addSubview(self.panelSetViewController.view)
  86. // self.panelSetViewController.reloadListViewModel()
  87. // self.panelSetViewController.view.autoresizingMask = [.height]
  88. } else {
  89. // self.contentBox.isHidden = false
  90. // self.panelSetViewController.view.removeFromSuperview()
  91. // if self.type.methodType == .None {
  92. // self.delegate?.controlStateChange?(self, show: false)
  93. // }
  94. }
  95. }
  96. func refreshMethodType(methodType: BotaType) {
  97. if (self.isShowPanel) {
  98. self.showPanelView(show: false)
  99. return
  100. }
  101. let newType = KMLeftMethodMode()
  102. var show = true
  103. if self.type.methodType != methodType {
  104. newType.methodType = methodType
  105. }
  106. if self.type.methodType == methodType {
  107. show = false
  108. }
  109. self.type = newType;
  110. // self.refreshShowMethod()
  111. self.delegate?.controlStateChange?(self,show:show)
  112. }
  113. //
  114. // private func updateViewButtonState() {
  115. // switch self.type.methodType {
  116. // case .None: do {
  117. //// self.contentBox.contentView = NSView()
  118. // self.delegate?.controlStateChange?(self,show:false)
  119. // }
  120. // break
  121. // case .Thumbnail: do {
  122. // self.thumbnailViewController.listView = self.listView
  123. // self.thumbnailViewController.delegate = self
  124. //// self.contentBox.contentView = self.thumbnailViewController.view
  125. //// self.thumbnailViewController.reloadData()
  126. // }
  127. // break
  128. // case .Outline: do {
  129. // self.outlineViewController.listView = self.listView
  130. //// self.contentBox.contentView = self.outlineViewController.view
  131. // }
  132. // break
  133. // case .BookMark: do {
  134. // self.bookViewController.listView = self.listView
  135. //// self.contentBox.contentView = self.bookViewController.view
  136. // self.bookViewController.reloadData()
  137. // }
  138. // break
  139. // case .Annotation: do {
  140. // self.annotationViewController.listView = self.listView
  141. //// self.contentBox.contentView = self.annotationViewController.view
  142. //// self.annotationViewController.reloadData()
  143. // }
  144. // break
  145. // case .From: do {
  146. // self.fromViewController.listView = self.listView
  147. //// self.contentBox.contentView = self.fromViewController.view
  148. // self.fromViewController.reloadData()
  149. // }
  150. // break
  151. // case .Signature: do {
  152. // self.signatureViewController.listView = self.listView
  153. //// self.contentBox.contentView = self.signatureViewController.view
  154. // self.signatureViewController.reloadData()
  155. // }
  156. // break
  157. // }
  158. // }
  159. // func refreshShowMethod() {
  160. // self.dataSource = [KMLeftMethodMode]()
  161. // norImage = []
  162. // selectImage = []
  163. // if KMBOTAManagerClass.shard.getMethodShow(key: thumbnailMethodKey) {
  164. // let mode = KMLeftMethodMode()
  165. // mode.methodName = thumbnailMethodKey
  166. // mode.methodType = .Thumbnail
  167. // self.dataSource.insert(mode, at: self.dataSource.count)
  168. // norImage.append("KMImageNameSidebarThumbailNor")
  169. // selectImage.append("KMImageNameSidebarThumbailSelect")
  170. // }
  171. // if KMBOTAManagerClass.shard.getMethodShow(key: outlineMethodKey) {
  172. // let mode = KMLeftMethodMode()
  173. // mode.methodName = outlineMethodKey
  174. // mode.methodType = .Outline
  175. // self.dataSource.insert(mode, at: self.dataSource.count)
  176. // norImage.append("KMImageNameSidebarOutlineNor")
  177. // selectImage.append("KMImageNameSidebarOutlineSelect")
  178. // }
  179. // if KMBOTAManagerClass.shard.getMethodShow(key: bookMarkMethodKey) {
  180. // let mode = KMLeftMethodMode()
  181. // mode.methodName = bookMarkMethodKey
  182. // mode.methodType = .BookMark
  183. // self.dataSource.insert(mode, at: self.dataSource.count)
  184. // norImage.append("KMImageNameSidebarBookMarkNor")
  185. // selectImage.append("KMImageNameSidebarBookMarkSelect")
  186. // }
  187. // if KMBOTAManagerClass.shard.getMethodShow(key: anntationMethodKey) {
  188. // let mode = KMLeftMethodMode()
  189. // mode.methodName = anntationMethodKey
  190. // mode.methodType = .Annotation
  191. // self.dataSource.insert(mode, at: self.dataSource.count)
  192. // norImage.append("KMImageNameSidebarAnnotationNor")
  193. // selectImage.append("KMImageNameSidebarAnnotationSelect")
  194. // }
  195. // if KMBOTAManagerClass.shard.getMethodShow(key: searchMethodKey) {
  196. // let mode = KMLeftMethodMode()
  197. // mode.methodName = searchMethodKey
  198. // mode.methodType = .Search
  199. // self.dataSource.insert(mode, at: self.dataSource.count)
  200. // norImage.append("KMImageNameSidebarSearchNor")
  201. // selectImage.append("KMImageNameSidebarSearchSelect")
  202. // }
  203. //// if KMBOTAManagerClass.shard.getMethodShow(key: formMethodKey) {
  204. //// let mode = KMLeftMethodMode()
  205. //// mode.methodName = formMethodKey
  206. //// mode.methodType = .From
  207. //// self.dataSource.insert(mode, at: self.dataSource.count)
  208. //// }
  209. //// if KMBOTAManagerClass.shard.getMethodShow(key: signatureMethodKey) {
  210. //// let mode = KMLeftMethodMode()
  211. //// mode.methodName = signatureMethodKey
  212. //// mode.methodType = .Signature
  213. //// self.dataSource.insert(mode, at: self.dataSource.count)
  214. //// }
  215. // var isConstant = false
  216. // for source in dataSource {
  217. // if self.type.methodType == source.methodType {
  218. // isConstant = true
  219. // }
  220. // }
  221. // if(!isConstant) {
  222. // self.type = KMLeftMethodMode()
  223. // }
  224. //// self.leftTableview.reloadData()
  225. // var typeIndex = -1
  226. // for (index,value) in self.dataSource.enumerated() {
  227. // if value.methodType == self.type.methodType {
  228. // typeIndex = index
  229. // }
  230. // }
  231. //
  232. //// self.leftTableview.selectRowIndexes([typeIndex], byExtendingSelection: true)
  233. // if self.dataSource.count > 0 && typeIndex >= 0 {
  234. // self.type = self.dataSource[typeIndex]
  235. // }
  236. // self.updateViewButtonState()
  237. //
  238. // }
  239. //
  240. //MARK: menu
  241. // private func addMenuTitle() {
  242. // let menus : NSMenu = NSMenu(title: "")
  243. //
  244. // let addItem = self.menuItemWithTitle(title: NSLocalizedString("Thumbnails", comment: ""),type:thumbnailMethodKey,action: #selector(renameBookAction),tag: 1)
  245. // let outlineItem = self.menuItemWithTitle(title: NSLocalizedString("Outline", comment: ""),type:outlineMethodKey,action: #selector(renameBookAction),tag: 2)
  246. // let bookItem = self.menuItemWithTitle(title: NSLocalizedString("Bookmarks", comment: ""), type:bookMarkMethodKey,action: #selector(renameBookAction),tag: 3)
  247. // let annationItem = self.menuItemWithTitle(title: NSLocalizedString("Annotations", comment: ""), type:anntationMethodKey,action: #selector(renameBookAction),tag: 4)
  248. // let searchItem = self.menuItemWithTitle(title: NSLocalizedString("Search", comment: ""), type:searchMethodKey,action: #selector(renameBookAction),tag: 5)
  249. //// let formItem = self.menuItemWithTitle(title: NSLocalizedString("域", comment: ""), type:formMethodKey,action: #selector(renameBookAction),tag: 6)
  250. //// let signatureItem = self.menuItemWithTitle(title: NSLocalizedString("签名", comment: ""), type:signatureMethodKey,action: #selector(renameBookAction),tag: 7)
  251. //
  252. // menus.addItem(addItem)
  253. // menus.addItem(outlineItem)
  254. // menus.addItem(bookItem)
  255. // menus.addItem(annationItem)
  256. // menus.addItem(searchItem)
  257. //// menus.addItem(formItem)
  258. //// menus.addItem(signatureItem)
  259. //// self.leftTableview.menu = menus
  260. // }
  261. // func menuItemWithTitle(title:String,type:String,action:Selector?,tag:Int) -> NSMenuItem {
  262. // let menuItem = NSMenuItem.init(title: title as String, action: action, keyEquivalent: "")
  263. // menuItem.target = self
  264. // menuItem.tag = tag
  265. // if KMBOTAManagerClass.shard.getMethodShow(key: type) {
  266. // menuItem.state = NSControl.StateValue.on
  267. // } else {
  268. // menuItem.state = NSControl.StateValue.off
  269. // }
  270. // return menuItem
  271. // }
  272. // @objc func renameBookAction(menuItem:NSMenuItem) {
  273. // var show = true
  274. // if menuItem.state == NSControl.StateValue.on {
  275. // menuItem.state = NSControl.StateValue.off
  276. // show = false
  277. // } else {
  278. // menuItem.state = NSControl.StateValue.on
  279. // show = true
  280. // }
  281. // switch menuItem.tag {
  282. // case 1: do {
  283. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: thumbnailMethodKey)
  284. // }
  285. // case 2: do {
  286. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: outlineMethodKey)
  287. // }
  288. // case 3: do {
  289. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: bookMarkMethodKey)
  290. // }
  291. // case 4: do {
  292. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: anntationMethodKey)
  293. // }
  294. // case 5: do {
  295. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: searchMethodKey)
  296. // }
  297. // case 6: do {
  298. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: formMethodKey)
  299. // }
  300. // case 7: do {
  301. // KMBOTAManagerClass.shard.setLeftMethod(show: show, key: signatureMethodKey)
  302. // }
  303. // break
  304. // default:
  305. // break
  306. // }
  307. // self.refreshShowMethod()
  308. // }
  309. // MARK: - New
  310. /*
  311. typedef NS_ENUM(NSInteger, KMNoteSortType) {
  312. KMNoteSortType_None = 0,
  313. KMNoteSortType_Time,
  314. KMNoteSortType_Page,
  315. };
  316. @class SKTocOutlineView, SKThumbnailTableView, SKTableView;
  317. @interface SKLeftSideViewController : SKSideViewController {
  318. SKTocOutlineView *tocOutlineView;
  319. NSArrayController *thumbnailArrayController;
  320. NSArrayController *findArrayController;
  321. NSArrayController *groupedFindArrayController;
  322. SKTableView *groupedFindTableView;
  323. }
  324. @property (nonatomic, assign) BOOL isAscendSort;
  325. @property (nonatomic, assign) KMNoteSortType noteSortType;
  326. @property (nonatomic, retain) NSView *filterButtonLayer;
  327. @property (nonatomic, retain) KMButtonLayer *moreButtonLayer;
  328. - (void)applySearchTableHeader:(NSString *)message;
  329. - (void)displayFindState;
  330. */
  331. // @property (nonatomic, retain) IBOutlet NSArrayController *thumbnailArrayController, *findArrayController, *groupedFindArrayController;
  332. // @property (nonatomic, retain) IBOutlet SKTocOutlineView *tocOutlineView;
  333. // @property (nonatomic, retain) IBOutlet *;
  334. // @property (nonatomic, retain) IBOutlet *;
  335. // @property (nonatomic, retain) IBOutlet SKTableView *groupedFindTableView;
  336. @IBOutlet var segmentedControl: KMSegmentedControl!
  337. @IBOutlet var findTableView: KMBotaTableView!
  338. @IBOutlet var thumbnailTableView: KMThumbnailTableView!
  339. @IBOutlet weak var leftListView: NSView!
  340. @IBOutlet var searchViewController: KMBotaSearchViewController!
  341. @IBOutlet weak var toolButtonBox: NSBox!
  342. @IBOutlet weak var toolButtonBoxLayoutConstraint: NSLayoutConstraint!
  343. @IBOutlet weak var snapshotNormalView: NSView!
  344. @IBOutlet weak var snapshotLabel: NSTextField!
  345. @IBOutlet weak var snapshotNormalMoreButton: NSButton!
  346. @IBOutlet weak var snapshotNormalSearchButton: NSButton!
  347. @IBOutlet weak var snapshotNormalZoomOutButton: NSButton!
  348. @IBOutlet weak var snapshotNormalZoomInButton: NSButton!
  349. @IBOutlet weak var snapshotSearchZoomOutButton: NSButton!
  350. @IBOutlet weak var snapshotSearchZoomInButton: NSButton!
  351. @IBOutlet weak var snapshotSearchField: KMLeftSideViewSearchField!
  352. @IBOutlet weak var snapshotDoneButton: NSButton!
  353. @IBOutlet weak var outlineView: NSView!
  354. @IBOutlet weak var outlineMoreButton: NSButton!
  355. @IBOutlet weak var outlineAddButton: NSButton!
  356. @IBOutlet weak var outlineSearchButton: NSButton!
  357. @IBOutlet weak var outlineLabel: NSTextField!
  358. @IBOutlet weak var outlineSearchField: KMLeftSideViewSearchField!
  359. @IBOutlet weak var outlineDoneButton: NSButton!
  360. @IBOutlet weak var noteView: NSView!
  361. @IBOutlet weak var noteMoreButton: NSButton!
  362. @IBOutlet weak var noteFilterButton: NSButton!
  363. @IBOutlet weak var noteSearchButton: NSButton!
  364. @IBOutlet weak var noteSearchField: KMLeftSideViewSearchField!
  365. @IBOutlet weak var noteTitleLabel: NSTextField!
  366. @IBOutlet weak var noteHeaderView: NSView!
  367. @IBOutlet weak var sortTypeBox: KMBox!
  368. @IBOutlet weak var sortTypeLabel: NSTextField!
  369. @IBOutlet weak var noteSortButton: NSButton!
  370. @IBOutlet weak var noteDoneButton: NSButton!
  371. @IBOutlet weak var thumbnailView: NSView!
  372. @IBOutlet weak var thumbnailZoomOutButton: NSButton!
  373. @IBOutlet weak var thumbnailZoomInButton: NSButton!
  374. @IBOutlet weak var thumbnailTitleLabel: NSTextField!
  375. @IBOutlet weak var emptySearchBox: NSBox!
  376. @IBOutlet weak var emptySearchLabel: NSTextField!
  377. var thumbnails: [KMThumbnail] = []
  378. var isDisplayPageSize = false
  379. var thumbnailCacheSize: CGFloat = 0
  380. var findState: KMFindState = .content
  381. var searchResults: [CPDFSelection] = []
  382. private let MIN_SIDE_PANE_WIDTH: CGFloat = 270
  383. override func loadView() {
  384. super.loadView()
  385. self.view.wantsLayer = true
  386. self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  387. self.outlineView.wantsLayer = true
  388. self.outlineView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  389. self.noteView.wantsLayer = true
  390. self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  391. self.thumbnailView.wantsLayer = true
  392. self.thumbnailView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  393. self.snapshotNormalView.wantsLayer = true
  394. self.snapshotNormalView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  395. // tocOutlineView.backgroundColor = [KMAppearance KMColor_Layout_L0];
  396. self.findTableView.backgroundColor = KMAppearance.KMColor_Layout_L0()
  397. // groupedFindTableView.backgroundColor = [KMAppearance KMColor_Layout_L0];
  398. self.thumbnailTableView.backgroundColor = KMAppearance.Layout.l0Color()
  399. self.leftListView.wantsLayer = true
  400. self.leftListView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  401. self.emptySearchLabel.stringValue = KMLocalizedString("No Results",nil)
  402. self.emptySearchLabel.textColor = KMAppearance.Layout.h0Color()
  403. self.emptySearchBox.isHidden = true
  404. self.thumbnailTitleLabel.stringValue = KMLocalizedString("Thumbnails", nil)
  405. self.thumbnailTitleLabel.textColor = KMAppearance.Layout.h0Color()
  406. // self.thumbnailZoomInButton.action = #selector(thumbnailSizeScaling)
  407. // [_thumbnailZoomInButton setTarget:mainController];
  408. // _thumbnailZoomInButton.tag = 1;
  409. // [_thumbnailZoomOutButton setAction:@selector(thumbnailSizeScaling:)];
  410. // [_thumbnailZoomOutButton setTarget:mainController];
  411. // _thumbnailZoomOutButton.tag = 0;
  412. self.snapshotLabel.stringValue = KMLocalizedString("Snapshots", nil)
  413. self.snapshotLabel.textColor = KMAppearance.Layout.h0Color()
  414. // [_snapshotNormalZoomInButton setAction:@selector(thumbnailSizeScaling:)];
  415. // [_snapshotNormalZoomInButton setTarget:mainController];
  416. // _snapshotNormalZoomInButton.tag = 2;
  417. // [_snapshotNormalZoomOutButton setAction:@selector(thumbnailSizeScaling:)];
  418. // [_snapshotNormalZoomOutButton setTarget:mainController];
  419. // _snapshotNormalZoomOutButton.tag = 3;
  420. self.snapshotNormalSearchButton.toolTip = KMLocalizedString("Search", nil)
  421. // [_snapshotNormalMoreButton setAction:@selector(leftSideViewMoreButtonAction:)];
  422. // [_snapshotNormalMoreButton setTarget:mainController];
  423. // [_snapshotNormalMoreButton setTag:300];
  424. // [_snapshotSearchZoomInButton setAction:@selector(thumbnailSizeScaling:)];
  425. // [_snapshotSearchZoomInButton setTarget:mainController];
  426. // _snapshotSearchZoomInButton.tag = 2;
  427. // [_snapshotSearchZoomOutButton setAction:@selector(thumbnailSizeScaling:)];
  428. // [_snapshotSearchZoomOutButton setTarget:mainController];
  429. // _snapshotSearchZoomOutButton.tag = 3;
  430. self.snapshotDoneButton.title = KMLocalizedString("Done", nil)
  431. self.snapshotDoneButton.toolTip = KMLocalizedString("Done", nil)
  432. self.snapshotDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  433. self.snapshotDoneButton.wantsLayer = true
  434. self.snapshotDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  435. self.snapshotDoneButton.layer?.cornerRadius = 4.0
  436. // [self.snapshotDoneButton setAction:@selector(leftSideViewDoneButtonAction:)];
  437. // [self.snapshotDoneButton setTarget:mainController];
  438. // [self.snapshotDoneButton setTag:312];
  439. // self.snapshotDoneButton.hidden = YES;
  440. self.snapshotSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  441. self.outlineSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  442. self.noteSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  443. self.snapshotSearchField.wantsLayer = true
  444. self.outlineSearchField.wantsLayer = true
  445. self.noteSearchField.wantsLayer = true
  446. self.snapshotSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  447. self.outlineSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  448. self.noteSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  449. self.snapshotSearchField.layer?.borderWidth = 1.0
  450. self.outlineSearchField.layer?.borderWidth = 1.0
  451. self.noteSearchField.layer?.borderWidth = 1.0
  452. self.snapshotSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  453. self.outlineSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  454. self.noteSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  455. // __block typeof(self) blockSelf = self;
  456. // _snapshotSearchField.changeCallBack = ^(NSString *changeContent) {
  457. // NSString *editContent = @"";
  458. // if (changeContent) {
  459. // editContent = changeContent;
  460. // }
  461. // [blockSelf.mainController searchFieldChangeAction:editContent];
  462. // };
  463. self.snapshotSearchField.isHidden = true
  464. self.snapshotSearchZoomOutButton.isHidden = true
  465. self.snapshotSearchZoomInButton.isHidden = true
  466. // _snapshotSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  467. // if (isEndEdit/* && searchViewController.segmentedControl.segmentCount == 3*/) {
  468. // _snapshotSearchField.hidden = YES;
  469. // _snapshotSearchZoomOutButton.hidden = YES;
  470. // _snapshotSearchZoomInButton.hidden = YES;
  471. // _snapshotLabel.hidden = NO;
  472. // _snapshotNormalZoomOutButton.hidden = NO;
  473. // _snapshotNormalZoomInButton.hidden = NO;
  474. // }
  475. // };
  476. self.thumbnailZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  477. self.snapshotNormalZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  478. self.snapshotSearchZoomInButton.toolTip = KMLocalizedString("Zoom In", nil)
  479. self.thumbnailZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  480. self.snapshotNormalZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  481. self.snapshotSearchZoomOutButton.toolTip = KMLocalizedString("Zoom Out", nil)
  482. self.outlineLabel.stringValue = KMLocalizedString("Outline", nil);
  483. self.outlineLabel.textColor = KMAppearance.Layout.h0Color()
  484. // self.outlineAddButton.toolTip = NSLocalizedString(@"Add Item", nil);
  485. // [self.outlineAddButton setAction:@selector(outlineContextMenuItemClicked_AddEntry:)];
  486. // [self.outlineAddButton setTarget:mainController];
  487. // self.outlineSearchButton.toolTip = NSLocalizedString(@"Search", nil);
  488. // [self.outlineMoreButton setAction:@selector(leftSideViewMoreButtonAction:)];
  489. // [self.outlineMoreButton setTarget:mainController];
  490. // [self.outlineMoreButton setTag:302];
  491. self.outlineDoneButton.title = KMLocalizedString("Done", nil);
  492. self.outlineDoneButton.toolTip = KMLocalizedString("Done", nil);
  493. self.outlineDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  494. self.outlineDoneButton.wantsLayer = true
  495. self.outlineDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  496. self.outlineDoneButton.layer?.cornerRadius = 4.0
  497. // [self.outlineDoneButton setAction:@selector(leftSideViewDoneButtonAction:)];
  498. // [self.outlineDoneButton setTarget:mainController];
  499. // [self.outlineDoneButton setTag:310];
  500. // self.outlineDoneButton.hidden = YES;
  501. self.outlineSearchField.isHidden = true
  502. // _outlineSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  503. // if (isEndEdit) {
  504. // _outlineSearchField.hidden = YES;
  505. // _outlineLabel.hidden = NO;
  506. // _outlineSearchButton.hidden = NO;
  507. // }
  508. // };
  509. // NSMenu *menuOutline = [NSMenu menu];
  510. // [menuOutline addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleOutlineCaseInsensitiveSearch:) target:mainController];
  511. // [[_outlineSearchField cell] setSearchMenuTemplate:menuOutline];
  512. // [[_outlineSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Outline", nil)];
  513. // [_outlineSearchField setTarget:mainController];
  514. let sud = UserDefaults.standard
  515. self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
  516. self.noteTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  517. // [self.noteMoreButton setAction:@selector(leftSideViewMoreButtonAction:)];
  518. // [self.noteMoreButton setTarget:mainController];
  519. // [self.noteMoreButton setTag:304];
  520. // self.noteMoreButton.wantsLayer = YES;
  521. // _moreButtonLayer = [KMButtonLayer layer];
  522. // [self.noteMoreButton.layer addSublayer:_moreButtonLayer];
  523. // _moreButtonLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.noteMoreButton.bounds), CGRectGetHeight(self.noteMoreButton.bounds));
  524. // _moreButtonLayer.layerType = KMNoteFilerButtonLayerType_None;
  525. // _moreButtonLayer.hidden = YES;
  526. // [self.noteFilterButton setAction:@selector(noteFilterAction:)];
  527. // [self.noteFilterButton setTarget:mainController];
  528. // [self.noteFilterButton setToolTip:NSLocalizedString(@"Sort", nil)];
  529. // self.noteFilterButton.wantsLayer = YES;
  530. // _filterButtonLayer = [[NSView alloc] init];
  531. // [self.noteFilterButton addSubview:_filterButtonLayer];
  532. // _filterButtonLayer.frame = CGRectMake(14, 2, 8, 8);
  533. // _filterButtonLayer.layerType = KMNoteFilerButtonLayerType_Dot;
  534. // _filterButtonLayer.hidden = YES;
  535. // _filterButtonLayer.wantsLayer = YES;
  536. // _filterButtonLayer.layer.backgroundColor = [KMAppearance KMColor_Interactive_A0].CGColor;
  537. // _filterButtonLayer.layer.cornerRadius = 4.0;
  538. self.noteDoneButton.title = KMLocalizedString("Done", nil)
  539. self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
  540. self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  541. self.noteDoneButton.wantsLayer = true
  542. self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  543. self.noteDoneButton.layer?.cornerRadius = 4.0
  544. // [self.noteDoneButton setAction:@selector(leftSideViewDoneButtonAction:)]
  545. // [self.noteDoneButton setTarget:mainController];
  546. // [self.noteDoneButton setTag:311];
  547. // self.noteDoneButton.hidden = YES;
  548. self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
  549. self.noteSearchField.isHidden = true
  550. // _noteSearchField.endEditCallBack = ^(BOOL isEndEdit) {
  551. // if (isEndEdit) {
  552. // _noteSearchField.hidden = YES;
  553. // _noteSearchButton.hidden = NO;
  554. // _noteTitleLabel.hidden = NO;
  555. // }
  556. // };
  557. self.noteHeaderView.wantsLayer = true
  558. self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
  559. self.noteHeaderView.layer?.cornerRadius = 1.0
  560. // let sortType = sud.integer(forKey: KMLeftSideViewNoteSortTypeKey)
  561. // if (sortType) {
  562. // _noteSortType = sortType;
  563. // if (sortType == KMNoteSortType_Time) {
  564. // self.sortTypeLabel.stringValue = NSLocalizedString(@"Time", nil);
  565. // self.sortTypeBox.toolTip = NSLocalizedString(@"Time", nil);
  566. // } else if (sortType == KMNoteSortType_Page) {
  567. // self.sortTypeLabel.stringValue = NSLocalizedString(@"Page", nil);
  568. // self.sortTypeBox.toolTip = NSLocalizedString(@"Page", nil);
  569. // }
  570. // } else {
  571. // _noteSortType = KMNoteSortType_Time;
  572. // self.sortTypeLabel.stringValue = NSLocalizedString(@"Time", nil);
  573. // }
  574. self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
  575. // _isAscendSort = [sud boolForKey:KMLeftSideViewAscendSortBoolKey];
  576. // if (_isAscendSort) {
  577. // [_noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankReverse]];
  578. // [_noteSortButton setToolTip:NSLocalizedString(@"ascending sort", nil)];
  579. // } else {
  580. // [_noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankPositive]];
  581. // [_noteSortButton setToolTip:NSLocalizedString(@"descending sort", nil)];
  582. // }
  583. // self.sortTypeBox.mouseDownCallback = ^(BOOL downEntered, KMBox *mouseBox) {
  584. // if (downEntered) {
  585. // NSMenu *menu = [[[NSMenu alloc] init] autorelease];
  586. // NSMenuItem *timeItem = [menu addItemWithTitle:NSLocalizedString(@"Time", nil) action:@selector(sortTypeAction:) target:self];
  587. // [timeItem setRepresentedObject:self];
  588. // timeItem.tag = 0;
  589. // NSMenuItem *pageItem = [menu addItemWithTitle:NSLocalizedString(@"Page", nil) action:@selector(sortTypeAction:) target:self];
  590. // [pageItem setRepresentedObject:self];
  591. // timeItem.tag = 1;
  592. // if (self.noteSortType == KMNoteSortType_Time) {
  593. // timeItem.state = NSControlStateValueOn;
  594. // pageItem.state = NSControlStateValueOff;
  595. // } else if (self.noteSortType == KMNoteSortType_Page) {
  596. // timeItem.state = NSControlStateValueOff;
  597. // pageItem.state = NSControlStateValueOn;
  598. // }
  599. // [menu popUpMenuPositioningItem:nil atLocation:CGPointMake(-10, 0) inView:self.sortTypeBox];
  600. // }
  601. // };
  602. self.searchViewController.loadView()
  603. self.searchViewController.contentView = self.findTableView.enclosingScrollView
  604. self.searchField = self.searchViewController.searchField
  605. self.searchViewController.segmentedControl.setSegmentCount(2, with: 25)
  606. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarListNor)!, for: 0)
  607. self.searchViewController.segmentedControl.setImage(NSImage(named: KMImageNameUXIconBtnSidebarPageNor)!, for: 1)
  608. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Separate search results", nil), for: 0)
  609. self.searchViewController.segmentedControl.setToolTip(KMLocalizedString("Group search results by page", nil), for: 1)
  610. self.searchViewController.segmentedControl.isBackgroundHighlighted = true
  611. self.searchViewController.segmentedControl.selectedSegment = 0
  612. // [mainController bind:@"findPaneState" toObject:searchViewController.segmentedControl withKeyPath:@"selectedSegment" options:nil];
  613. self.segmentedControl.segmentCount = 5
  614. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 0)
  615. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 1)
  616. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 2)
  617. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 3)
  618. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 4)
  619. self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails", nil), for: 0)
  620. self.segmentedControl.setToolTip(KMLocalizedString("View Outline", nil), for: 1)
  621. self.segmentedControl.setToolTip(KMLocalizedString("View Notes", nil), for: 2)
  622. self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots", nil), for: 3)
  623. self.segmentedControl.setToolTip(KMLocalizedString("Search", nil), for: 4)
  624. self.segmentedControl.selectedSegment = 0
  625. // [segmentedControl bind:@"selectedSegment" toObject:mainController withKeyPath:@"leftSidePaneState" options:nil];
  626. // [mainController bind:@"leftSidePaneState" toObject:segmentedControl withKeyPath:@"selectedSegment" options:nil];
  627. self.segmentedControl.wantsLayer = true
  628. self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  629. self.segmentedControl.block = { [unowned self] segIndex in
  630. self.toolButtonBox.isHidden = false
  631. self.toolButtonBoxLayoutConstraint.constant = 40.0
  632. if (segIndex == 0) {
  633. self.toolButtonBox.contentView = self.thumbnailView
  634. self.displayThumbnailViewAnimating(true)
  635. } else if (segIndex == 1) {
  636. self.toolButtonBox.contentView = self.outlineView
  637. } else if (segIndex == 2) {
  638. self.toolButtonBox.contentView = self.noteView
  639. } else if (segIndex == 3) {
  640. self.toolButtonBox.contentView = self.snapshotNormalView
  641. } else if (segIndex == 4) {
  642. self.toolButtonBox.isHidden = true
  643. self.toolButtonBoxLayoutConstraint.constant = 0
  644. self.displayFindViewAnimating(false)
  645. }
  646. }
  647. // self.button.setHelp(KMLocalizedString("View Thumbnails", "Tool tip message"), for: KMLeftSidePaneState.thumbnail.rawValue)
  648. // self.button.setHelp(KMLocalizedString("View Outline", "Tool tip message"), for: KMLeftSidePaneState.outline.rawValue)
  649. // self.alternateButton.setHelp(KMLocalizedString("Separate search results", "Tool tip message"), for: KMFindPaneState.singular.rawValue)
  650. // self.alternateButton.setHelp(KMLocalizedString("Group search results by page", "Tool tip message"), for: KMFindPaneState.grouped.rawValue)
  651. // NSMenu *menu = [NSMenu menu];
  652. // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
  653. // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
  654. // [[searchField cell] setSearchMenuTemplate:menu];
  655. // [[searchField cell] setPlaceholderString:NSLocalizedString(@"Search PDF", @"placeholder")];
  656. // [searchField setAction:@selector(search:)];
  657. // [searchField setTarget:mainController];
  658. // [tocOutlineView setAutoresizesOutlineColumn: NO];
  659. // [tocOutlineView setAllowsMultipleSelection:YES];
  660. // [tocOutlineView setAllowsEmptySelection:YES];
  661. //
  662. // [tocOutlineView setDelegate:mainController];
  663. // [tocOutlineView setDataSource:mainController];
  664. self.thumbnailTableView.delegate = self
  665. self.thumbnailTableView.dataSource = self
  666. self.thumbnailTableView.allowsMultipleSelection = true
  667. self.findTableView.delegate = self
  668. // // [groupedFindTableView setDelegate:mainController];
  669. // [groupedFindTableView setDataSource:mainController];
  670. // [[thumbnailTableView menu] setDelegate:mainController];
  671. // [[findTableView menu] setDelegate:mainController];
  672. // [[groupedFindTableView menu] setDelegate:mainController];
  673. // [tocOutlineView setDoubleAction:@selector(goToSelectedOutlineItem:)];
  674. // [tocOutlineView setTarget:mainController];
  675. // [findTableView setDoubleAction:@selector(goToSelectedFindResults:)];
  676. // [findTableView setTarget:mainController];
  677. // [groupedFindTableView setDoubleAction:@selector(goToSelectedFindResults:)];
  678. // [groupedFindTableView setTarget:mainController];
  679. // [thumbnailTableView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKFullStringMatch]];
  680. // //支持拖拽的文字类型
  681. // [thumbnailTableView registerForDraggedTypes:@[KPDFThumbnailLocalForDraggedTypes,NSFilenamesPboardType]];
  682. // [tocOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
  683. // [tocOutlineView registerForDraggedTypes:[NSArray arrayWithObject:kKMPDFViewOutlineDragDataType]];
  684. // [[[findTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
  685. // [[[groupedFindTableView tableColumnWithIdentifier:PAGE_COLUMNID] headerCell] setTitle:NSLocalizedString(@"Page", @"Table header title")];
  686. // [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] dataCell] setEnabled:NO];
  687. // if (RUNNING_AFTER(10_9)) {
  688. // [thumbnailTableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
  689. // [(SKSourceListTextFieldCell *)[[thumbnailTableView tableColumnWithIdentifier:PAGE_COLUMNID] dataCell] setSimulatesSourceList:YES];
  690. // }
  691. // NSSortDescriptor *countDescriptor = [[[NSSortDescriptor alloc] initWithKey:SKGroupedSearchResultCountKey ascending:NO] autorelease];
  692. // [groupedFindArrayController setSortDescriptors:[NSArray arrayWithObjects:countDescriptor, nil]];
  693. //
  694. // [thumbnailTableView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
  695. // if (NO == [[NSUserDefaults standardUserDefaults] boolForKey:SKDisableTableToolTipsKey]) {
  696. // [tocOutlineView setHasImageToolTips:YES];
  697. // [findTableView setHasImageToolTips:YES];
  698. // [groupedFindTableView setHasImageToolTips:YES];
  699. // }
  700. // [self updateViewColor];
  701. }
  702. func displayThumbnailViewAnimating(_ animate: Bool) {
  703. self.replaceSideView(self.thumbnailTableView.enclosingScrollView!, animate: animate)
  704. var frame = self.thumbnailTableView.enclosingScrollView?.frame ?? .zero
  705. frame.origin.y = 0
  706. frame.size.height = self.thumbnailTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
  707. self.thumbnailTableView.enclosingScrollView?.frame = frame
  708. self.resetThumbnails()
  709. // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  710. // frame.origin.y = 0;
  711. // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  712. // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  713. // frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
  714. // frame.origin.y = 0;
  715. // frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
  716. // rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
  717. // [self updateThumbnailSelection];
  718. }
  719. func displayFindViewAnimating(_ animate: Bool) {
  720. self.replaceSideView(self.searchViewController.view, animate: animate)
  721. if (self.findState != .content) {
  722. self.findState = .content
  723. } else {
  724. self.displayFindState()
  725. }
  726. var frame = self.searchViewController.view.frame
  727. frame.origin.y = 0
  728. frame.size.height = self.searchViewController.view.superview?.frame.size.height ?? .zero
  729. self.searchViewController.view.frame = frame
  730. // frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  731. // frame.origin.y = 0;
  732. // frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  733. // rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  734. // frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
  735. // frame.origin.y = 0;
  736. // frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
  737. // rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
  738. // [self.leftSideEmptyVC.emptySnapView removeFromSuperview];
  739. // [self updataLeftSideSnapView];
  740. }
  741. func displayFindState() {
  742. if (self.findState == .content) {
  743. self.displayFind()
  744. } else if (self.findState == .note) {
  745. // [self displayNoteFind];
  746. } else if (self.findState == .snapshot) {
  747. // [self displaySnapshotFind];
  748. }
  749. }
  750. /*
  751. - (void) {
  752. }
  753. - (void)displayGroupedFindViewAnimating:(BOOL)animate {
  754. [leftSideController replaceSideView:leftSideController.searchViewController.view animate:animate];
  755. if (self.findState != SKFindStateContent) {
  756. self.findState = SKFindStateContent;
  757. } else {
  758. [leftSideController displayFindState];
  759. }
  760. NSRect frame = leftSideController.searchViewController.view.frame;
  761. frame.origin.y = 0;
  762. frame.size.height = leftSideController.searchViewController.view.superview.frame.size.height;
  763. leftSideController.searchViewController.view.frame = frame;
  764. frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  765. frame.origin.y = 0;
  766. frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  767. rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  768. frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
  769. frame.origin.y = 0;
  770. frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
  771. rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
  772. [self updataLeftSideSnapView];
  773. }
  774. - (void)displayNoteViewAnimating:(BOOL)animate {
  775. leftSideController.searchViewController.contentView = nil;
  776. [leftSideController replaceSideView:rightSideController.noteOutlineView.enclosingScrollView animate:animate];
  777. if (self.findState != SKFindStateNote) {
  778. self.findState = SKFindStateNote;
  779. } else {
  780. [leftSideController displayFindState];
  781. }
  782. NSRect frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  783. frame.origin.y = 0;
  784. frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  785. rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  786. frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  787. frame.origin.y = 0;
  788. frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  789. rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  790. frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
  791. frame.origin.y = 0;
  792. frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
  793. rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
  794. NSView *view = rightSideController.noteOutlineView.enclosingScrollView;
  795. CGSize emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size;
  796. self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((view.frame.size.width-emptyVcSize.width)/2.0,(view.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height);
  797. }
  798. - (void)displaySnapshotViewAnimating:(BOOL)animate {
  799. leftSideController.searchViewController.contentView = nil;
  800. [leftSideController replaceSideView:rightSideController.snapshotTableView.enclosingScrollView animate:animate];
  801. if (self.findState != SKFindStateSnapshot) {
  802. self.findState = SKFindStateSnapshot;
  803. } else {
  804. [leftSideController displayFindState];
  805. }
  806. NSRect frame = rightSideController.snapshotTableView.enclosingScrollView.frame;
  807. frame.origin.y = 0;
  808. frame.size.height = rightSideController.snapshotTableView.enclosingScrollView.superview.frame.size.height;
  809. rightSideController.snapshotTableView.enclosingScrollView.frame = frame;
  810. frame = rightSideController.noteOutlineView.enclosingScrollView.frame;
  811. frame.origin.y = 0;
  812. frame.size.height = rightSideController.noteOutlineView.enclosingScrollView.superview.frame.size.height;
  813. rightSideController.noteOutlineView.enclosingScrollView.frame = frame;
  814. frame = leftSideController.tocOutlineView.enclosingScrollView.frame;
  815. frame.origin.y = 0;
  816. frame.size.height = leftSideController.tocOutlineView.enclosingScrollView.superview.frame.size.height;
  817. leftSideController.tocOutlineView.enclosingScrollView.frame = frame;
  818. [self updateSnapshotsIfNeeded];
  819. }
  820. */
  821. func displayFind() {
  822. self.searchField = self.searchViewController.searchField
  823. let menu = NSMenu()
  824. // menu.addItem(title: <#T##String#>, action: <#T##Selector?#>, target: <#T##AnyObject?#>)
  825. // [menu addItemWithTitle:NSLocalizedString(@"Whole Words Only", @"Menu item title") action:@selector(toggleWholeWordSearch:) target:mainController];
  826. // [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveSearch:) target:mainController];
  827. // [[searchViewController.searchField cell] setSearchMenuTemplate:menu];
  828. (self.searchViewController.searchField.cell as? NSSearchFieldCell)?.placeholderString = KMLocalizedString("Search PDF", "placeholder")
  829. // self.searchViewController.searchField.target =
  830. // [searchViewController.searchField setAction:@selector(search:)];
  831. // [searchViewController.searchField setTarget:mainController];
  832. // if (mainController.findPaneState == SKFindPaneStateSingular) {
  833. self.searchViewController.contentView = self.findTableView.enclosingScrollView;
  834. // } else if (mainController.findPaneState == SKFindPaneStateGrouped) {
  835. // searchViewController.contentView = groupedFindTableView.enclosingScrollView;
  836. // }
  837. }
  838. /*
  839. - (void) {
  840. }
  841. @implementation SKLeftSideViewController
  842. @synthesize tocOutlineView, thumbnailArrayController, findArrayController, groupedFindArrayController, groupedFindTableView;
  843. - (BOOL)requiresAlternateButtonForView:(NSView *)aView {
  844. return NO;
  845. return [findTableView isDescendantOf:aView] || [groupedFindTableView isDescendantOf:aView];
  846. }
  847. - (void)applySearchTableHeader:(NSString *)message {
  848. [[[findTableView tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
  849. [[findTableView headerView] setNeedsDisplay:YES];
  850. [[[groupedFindTableView tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell] setStringValue:message];
  851. [[groupedFindTableView headerView] setNeedsDisplay:YES];
  852. }
  853. - (void)displayFindState {
  854. if (mainController.findState == SKFindStateContent) {
  855. [self displayFind];
  856. } else if (mainController.findState == SKFindStateNote) {
  857. [self displayNoteFind];
  858. } else if (mainController.findState == SKFindStateSnapshot) {
  859. [self displaySnapshotFind];
  860. }
  861. }
  862. - (void)displayNoteFind {
  863. mainController.rightSideController.searchField = self.noteSearchField;
  864. NSMenu *menu = [NSMenu menu];
  865. [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
  866. [[self.noteSearchField cell] setSearchMenuTemplate:menu];
  867. [[self.noteSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Notes", @"placeholder")];
  868. [self.noteSearchField setAction:@selector(searchNotes:)];
  869. [self.noteSearchField setTarget:mainController];
  870. }
  871. - (void)displaySnapshotFind {
  872. mainController.rightSideController.searchField = self.snapshotSearchField;
  873. NSMenu *menu = [NSMenu menu];
  874. [menu addItemWithTitle:NSLocalizedString(@"Ignore Case", @"Menu item title") action:@selector(toggleCaseInsensitiveNoteSearch:) target:mainController];
  875. [[self.snapshotSearchField cell] setSearchMenuTemplate:menu];
  876. [[self.snapshotSearchField cell] setPlaceholderString:NSLocalizedString(@"Search Snapshots", @"placeholder")];
  877. [self.snapshotSearchField setAction:@selector(searchNotes:)];
  878. [self.snapshotSearchField setTarget:mainController];
  879. [self.snapshotSearchField setDelegate:mainController];
  880. }
  881. #pragma mark - UI Action
  882. - (IBAction)snapshotNormalSearchButtonAction:(NSButton *)sender {
  883. _snapshotSearchField.hidden = NO;
  884. // _snapshotSearchZoomOutButton.hidden = YES;
  885. _snapshotSearchZoomInButton.hidden = YES;
  886. _snapshotNormalSearchButton.hidden = YES;
  887. _snapshotDoneButton.hidden = NO;
  888. _snapshotLabel.hidden = YES;
  889. _snapshotNormalZoomOutButton.hidden = YES;
  890. _snapshotNormalZoomInButton.hidden = YES;
  891. [_snapshotSearchField becomeFirstResponder];
  892. }
  893. - (IBAction)outlineNormalSearchButtonAction:(NSButton *)sender {
  894. _outlineSearchField.hidden = NO;
  895. _outlineDoneButton.hidden = NO;
  896. _outlineLabel.hidden = YES;
  897. _outlineSearchButton.hidden = YES;
  898. _outlineMoreButton.hidden = YES;
  899. _outlineAddButton.hidden = YES;
  900. [_outlineSearchField becomeFirstResponder];
  901. }
  902. - (IBAction)noteSearchAction:(NSButton *)sender {
  903. self.noteSearchField.hidden = NO;
  904. self.noteTitleLabel.hidden = YES;
  905. self.noteSearchButton.hidden = YES;
  906. self.noteDoneButton.hidden = NO;
  907. self.noteFilterButton.hidden = YES;
  908. self.noteMoreButton.hidden = YES;
  909. [self.noteSearchField becomeFirstResponder];
  910. }
  911. - (IBAction)noteSortAction:(id)sender {
  912. if (self.isAscendSort) {
  913. self.isAscendSort = NO;
  914. [self.noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankPositive]];
  915. [self.noteSortButton setToolTip:NSLocalizedString(@"descending sort", nil)];
  916. } else {
  917. self.isAscendSort = YES;
  918. [self.noteSortButton setImage:[NSImage imageNamed:KMImageNameBtnSidebarRankReverse]];
  919. [self.noteSortButton setToolTip:NSLocalizedString(@"ascending sort", nil)];
  920. }
  921. [[NSUserDefaults standardUserDefaults] setBool:self.isAscendSort forKey:KMLeftSideViewAscendSortBoolKey];
  922. }
  923. - (IBAction)sortTypeAction:(id)sender {
  924. NSMenuItem *item = (NSMenuItem *)sender;
  925. NSInteger tag = item.tag;
  926. if (item.state == NSControlStateValueOn) {
  927. item.state = NSControlStateValueOff;
  928. } else {
  929. item.state = NSControlStateValueOn;
  930. }
  931. if (tag == 0) {
  932. self.noteSortType = KMNoteSortType_Page;
  933. _sortTypeLabel.stringValue = NSLocalizedString(@"Page", nil);
  934. _sortTypeBox.toolTip = NSLocalizedString(@"Page", nil);
  935. } else if (tag == 1) {
  936. self.noteSortType = KMNoteSortType_Time;
  937. _sortTypeLabel.stringValue = NSLocalizedString(@"Time", nil);
  938. _sortTypeBox.toolTip = NSLocalizedString(@"Time", nil);
  939. }
  940. [[NSUserDefaults standardUserDefaults] setInteger:self.noteSortType forKey:KMLeftSideViewNoteSortTypeKey];
  941. [[NSUserDefaults standardUserDefaults] synchronize];
  942. }
  943. #pragma mark - get && set
  944. - (void)setIsAscendSort:(BOOL)isAscendSort {
  945. _isAscendSort = isAscendSort;
  946. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationSortTypeKeyNotification" object:self userInfo:nil];
  947. }
  948. - (void)setNoteSortType:(KMNoteSortType)noteSortType {
  949. _noteSortType = noteSortType;
  950. [[NSNotificationCenter defaultCenter] postNotificationName:@"KMAnnotationSortTypeKeyNotification" object:self userInfo:nil];
  951. }
  952. */
  953. func resetThumbnails() {
  954. // [self willChangeValueForKey:THUMBNAILS_KEY];
  955. self.thumbnailCacheSize = 400
  956. self.thumbnails.removeAll()
  957. let pageLabels = self.listView.document.pageLabels()
  958. if (pageLabels.isEmpty == false) {
  959. let isLocked = self.listView.document.isLocked
  960. let firstPage = self.listView.document.page(at: 0)
  961. // SKPDFPage
  962. let emptyPage = CPDFPage()
  963. let firstFrame = firstPage?.bounds(for: .cropBox) ?? .zero
  964. let firstFrame2 = firstPage?.bounds(for: .mediaBox) ?? .zero
  965. emptyPage.setBounds(firstFrame, for: .cropBox)
  966. emptyPage.setBounds(firstFrame2, for: .mediaBox)
  967. emptyPage.rotation = firstPage?.rotation ?? 0
  968. let pageImage = firstPage!.thumbnail(of: NSMakeSize(self.thumbnailCacheSize, self.thumbnailCacheSize))
  969. // NSImage * = [emptyPage thumbnailWithSize:thumbnailCacheSize forBox:[pdfView displayBox]];
  970. var rect: NSRect = .zero
  971. rect.size = pageImage?.size ?? .zero
  972. let width = 1.2 * fmin(NSWidth(rect), NSHeight(rect))
  973. rect = NSInsetRect(rect, 0.5 * (NSWidth(rect) - width), 0.5 * (NSHeight(rect) - width));
  974. pageImage?.lockFocus()
  975. NSImage(named: NSImage.applicationIconName)?.draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
  976. if (isLocked) {
  977. NSWorkspace.shared.icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kLockedBadgeIcon))).draw(in: rect, from: .zero, operation: .sourceOver, fraction: 0.5)
  978. // [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:0.5];
  979. }
  980. pageImage?.unlockFocus()
  981. // __block typeof(self) blockSelf = self;
  982. for (i, label) in pageLabels.enumerated() {
  983. let thumbnail = KMThumbnail(image: pageImage, label: label, pageIndex: i)
  984. // thumbnail.delegate = self
  985. thumbnail.dirty = true
  986. self.thumbnails.append(thumbnail)
  987. }
  988. }
  989. // [self didChangeValueForKey:THUMBNAILS_KEY];
  990. // [self allThumbnailsNeedUpdate];
  991. DispatchQueue.main.async {
  992. self.thumbnailTableView.reloadData()
  993. }
  994. }
  995. /*
  996. */
  997. }
  998. //MARK: NSTableViewDelegate,NSTableViewDataSource
  999. //extension KMLeftSideViewController: NSTableViewDelegate,NSTableViewDataSource {
  1000. // func numberOfRows(in tableView: NSTableView) -> Int {
  1001. // return self.dataSource.count
  1002. // }
  1003. //
  1004. // func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1005. // let cell : KMLiftSideCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMLiftSideCellView"), owner: self) as! KMLiftSideCellView
  1006. // if row <= selectImage.count-1 {
  1007. // if self.dataSource[row] == self.type {
  1008. // cell.isSelect = true
  1009. // cell.mothedImage.image = NSImage(named: selectImage[row])
  1010. // cell.backgroundColor(NSColor.km_init(hex: "#DFE1E5"))
  1011. // } else {
  1012. // cell.isSelect = false
  1013. // cell.mothedImage.image = NSImage(named: norImage[row])
  1014. // cell.backgroundColor(NSColor.clear)
  1015. // }
  1016. // }
  1017. // cell.index = row
  1018. // cell.buttonClick = { [unowned self] index in
  1019. // if ((index < self.dataSource.count) && (index > -1)) {
  1020. //
  1021. // let isSearch = self.type.methodType == .Search
  1022. //
  1023. // var show = true
  1024. // if( self.type == self.dataSource[index]) {
  1025. // self.type = KMLeftMethodMode()
  1026. // show = false
  1027. // } else {
  1028. // self.type = self.dataSource[index]
  1029. // show = true
  1030. // }
  1031. //
  1032. // self.trackEvent(type: self.type.methodType)
  1033. //
  1034. // self.updateViewButtonState()
  1035. // self.delegate?.controlStateChange?(self,show:show)
  1036. //// self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  1037. //// self.leftTableview.reloadData()
  1038. //
  1039. // UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  1040. // UserDefaults.standard.synchronize()
  1041. //
  1042. // if (isSearch && show == false) {
  1043. // self.view.window?.makeFirstResponder(self)
  1044. // } else if (isSearch && self.type.methodType != .Search) { // 切换
  1045. // self.view.window?.makeFirstResponder(self)
  1046. // }
  1047. // }
  1048. // }
  1049. // return cell
  1050. // }
  1051. //
  1052. // func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1053. // return 48
  1054. // }
  1055. //
  1056. // func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  1057. // let rowView = KMCustomTableRowView()
  1058. // rowView.selectionColor = NSColor(calibratedRed: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1.0)
  1059. // rowView.color = NSColor.km_init(hex: "#F7F8FA")
  1060. // return rowView
  1061. // }
  1062. //
  1063. // func tableViewSelectionDidChange(_ notification: Notification) {
  1064. //
  1065. // }
  1066. //}
  1067. //extension KMLeftSideViewController: KMPDFViewPanelSetViewControllerDelegate {
  1068. // func controller(_ controller: KMPDFViewPanelSetViewController, dispayDidChange dispay: KMPDFDisplayType) {
  1069. // self.delegate?.controller?(self, dispayDidChange: dispay)
  1070. // }
  1071. //
  1072. // func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool) {
  1073. // self.listView?.displaysPageBreaks = pageBreaks
  1074. // self.listView?.layoutDocumentView()
  1075. // }
  1076. //
  1077. // func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType) {
  1078. //// if (rotateType == .clockwise) { /// 顺时针
  1079. //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1080. //// if page.rotation == 0 {
  1081. //// page.rotation = 90
  1082. //// } else if page.rotation == 90 {
  1083. //// page.rotation = 180
  1084. //// } else if page.rotation == 180 {
  1085. //// page.rotation = 270
  1086. //// } else if page.rotation == 270 {
  1087. //// page.rotation = 0
  1088. //// }
  1089. //// self.listView?.layoutDocumentView()
  1090. //// } else if (rotateType == .anticlockwise) { /// 逆时针
  1091. //// let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  1092. //// if page.rotation == 0 {
  1093. //// page.rotation = 270
  1094. //// } else if page.rotation == 90 {
  1095. //// page.rotation = 0
  1096. //// } else if page.rotation == 180 {
  1097. //// page.rotation = 90
  1098. //// } else if page.rotation == 270 {
  1099. //// page.rotation = 180
  1100. //// }
  1101. //// self.listView?.layoutDocumentView()
  1102. //// }
  1103. ////
  1104. // self.delegate?.controller?(controller: self, rotateType: rotateType)
  1105. // }
  1106. //}
  1107. // MARK: -
  1108. // MARK: - 扩展
  1109. extension KMLeftSideViewController {
  1110. public func selectType(_ type: BotaType) {
  1111. // 更新 type
  1112. var show = true
  1113. if (self.type.methodType == .None) {
  1114. show = true
  1115. } else {
  1116. if (self.type.methodType == type) {
  1117. show = false
  1118. } else {
  1119. show = true
  1120. }
  1121. }
  1122. var index: Int = NSNotFound
  1123. switch type {
  1124. case .None:
  1125. index = NSNotFound
  1126. break
  1127. case .Thumbnail:
  1128. index = 0
  1129. break
  1130. case .Outline:
  1131. index = 1
  1132. break
  1133. case .BookMark:
  1134. index = 2
  1135. break
  1136. case .Annotation:
  1137. index = 3
  1138. break
  1139. case .Search:
  1140. index = 4
  1141. break
  1142. case .From:
  1143. index = 5
  1144. break
  1145. case .Signature:
  1146. index = 6
  1147. break
  1148. }
  1149. self.type = self.getMethodMode(show ? type : .None)
  1150. // 更新按钮状态
  1151. // self.updateViewButtonState()
  1152. // 将事件传递出去
  1153. self.delegate?.controlStateChange?(self,show:show)
  1154. if (index != NSNotFound) {
  1155. // self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  1156. // 记录当前选中
  1157. UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  1158. UserDefaults.standard.synchronize()
  1159. }
  1160. // self.leftTableview.reloadData()
  1161. }
  1162. private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
  1163. let mode = KMLeftMethodMode()
  1164. mode.methodType = type
  1165. switch type {
  1166. case .None:
  1167. mode.methodName = ""
  1168. break
  1169. case .Thumbnail:
  1170. mode.methodName = thumbnailMethodKey
  1171. break
  1172. case .Outline:
  1173. mode.methodName = outlineMethodKey
  1174. break
  1175. case .BookMark:
  1176. mode.methodName = bookMarkMethodKey
  1177. break
  1178. case .Annotation:
  1179. mode.methodName = anntationMethodKey
  1180. break
  1181. case .Search:
  1182. mode.methodName = searchMethodKey
  1183. break
  1184. case .From:
  1185. mode.methodName = formMethodKey
  1186. break
  1187. case .Signature:
  1188. mode.methodName = signatureMethodKey
  1189. break
  1190. }
  1191. return mode
  1192. }
  1193. }
  1194. //MARK: Cache
  1195. extension KMLeftSideViewController {
  1196. func clearAnnotationFilterData() {
  1197. if let _key = self.listView?.document?.documentURL?.path {
  1198. let userDefaults = UserDefaults.standard
  1199. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1200. userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + _key)
  1201. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1202. userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + _key)
  1203. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1204. userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + _key)
  1205. userDefaults.synchronize()
  1206. }
  1207. }
  1208. func clearNotification() {
  1209. self.bookViewController.removeNotification()
  1210. self.annotationViewController.removeNotification()
  1211. self.outlineViewController.removeNotification()
  1212. }
  1213. }
  1214. // MARK: - Analytics (埋点)
  1215. extension KMLeftSideViewController {
  1216. func trackEvent(type: BotaType) -> Void {
  1217. if (type == .Thumbnail) {
  1218. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Thumbnail", parameters: [
  1219. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1220. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1221. } else if (type == .Outline) {
  1222. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Outline", parameters: [
  1223. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1224. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1225. } else if (type == .BookMark) {
  1226. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_BookMark", parameters: [
  1227. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1228. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1229. } else if (type == .Annotation) {
  1230. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Annotation", parameters: [
  1231. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1232. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1233. } else if (type == .Search) {
  1234. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Search", parameters: [
  1235. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  1236. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  1237. }
  1238. }
  1239. }
  1240. // MARK: - Private Methods
  1241. extension KMLeftSideViewController {
  1242. @objc private func _themeChanged(_ notification: NSNotification) {
  1243. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  1244. self._updateViewColor()
  1245. }
  1246. }
  1247. private func _updateViewColor() {
  1248. if(KMAppearance.isDarkMode()){
  1249. self.leftListView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1250. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1251. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1252. self.noteView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1253. self.outlineView.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1254. self.view.layer?.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1).cgColor
  1255. self.thumbnailTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1256. // groupedFindTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1257. // tocOutlineView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1258. self.findTableView.backgroundColor = NSColor(red: 0.149, green: 0.157, blue: 0.169, alpha: 1)
  1259. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1260. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1261. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1262. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1).cgColor
  1263. self.snapshotSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1264. self.outlineSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1265. self.noteSearchField.backgroundColor = NSColor(red: 0.224, green: 0.235, blue: 0.243, alpha: 1)
  1266. } else {
  1267. self.leftListView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1268. self.snapshotNormalView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1269. self.thumbnailView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1270. self.noteView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1271. self.outlineView.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1272. self.view.layer?.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1, alpha: 1).cgColor
  1273. self.thumbnailTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1274. // groupedFindTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1275. // tocOutlineView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1276. self.findTableView.backgroundColor = NSColor(red: 0.988, green: 0.992, blue: 1.000, alpha: 1)
  1277. self.snapshotSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1278. self.outlineSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1279. self.noteSearchField.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1280. self.segmentedControl.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  1281. self.snapshotSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1282. self.outlineSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1283. self.noteSearchField.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1)
  1284. }
  1285. }
  1286. /*
  1287. */
  1288. }
  1289. // MARK: - KMThumbnailTableViewDelegate, NSTableViewDataSource
  1290. extension KMLeftSideViewController: NSTableViewDelegate, NSTableViewDataSource {
  1291. func numberOfRows(in tableView: NSTableView) -> Int {
  1292. if tableView.isEqual(to: self.thumbnailTableView) {
  1293. return self.thumbnails.count
  1294. } else if tableView.isEqual(to: self.findTableView) {
  1295. return self.searchResults.count
  1296. }
  1297. return 0
  1298. }
  1299. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1300. if tableView.isEqual(to: self.thumbnailTableView) {
  1301. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMThumbnailTableviewCell"), owner: self) as! KMThumbnailTableviewCell
  1302. let thumbnail = self.thumbnails[row]
  1303. cell.pageNumLabel.stringValue = thumbnail.label
  1304. cell.thumImage.image = thumbnail.image
  1305. if let _image = thumbnail.image {
  1306. let multiplierHToW = _image.size.height / (_image.size.width == 0 ? 1 : _image.size.width)
  1307. let multiplierWToH = _image.size.width / (_image.size.height == 0 ? 1 : _image.size.height)
  1308. if (_image.size.height > _image.size.width) {
  1309. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  1310. cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .height, relatedBy: .equal, toItem: cell.thumImage, attribute: .width, multiplier: multiplierHToW, constant: 0)
  1311. NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  1312. } else {
  1313. NSLayoutConstraint.deactivate([cell.imageAspectRatioLayout])
  1314. cell.imageAspectRatioLayout = NSLayoutConstraint(item: cell.thumImage, attribute: .width, relatedBy: .equal, toItem: cell.thumImage, attribute: .height, multiplier: multiplierWToH, constant: 0)
  1315. NSLayoutConstraint.activate([cell.imageAspectRatioLayout])
  1316. }
  1317. }
  1318. if (self.isDisplayPageSize) {
  1319. cell.sizeLabel.isHidden = false
  1320. //获取Page的真实尺寸
  1321. let page = self.listView.document.page(at: UInt(row))
  1322. let rect = page?.bounds(for: .cropBox) ?? .zero
  1323. let w = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetWidth(rect)/595 * 210))
  1324. let h = KMPageSizeTool.conversion(withUnit: "mm", value: (CGRectGetHeight(rect)/842 * 297))
  1325. if let data = page?.rotation, data == 90 || data == 270 {
  1326. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", h.stringToCGFloat(), w.stringToCGFloat(), KMLocalizedString("mm", nil))
  1327. } else {
  1328. cell.sizeLabel.stringValue = String(format: "%.f × %.f %@", w.stringToCGFloat(), h.stringToCGFloat(), KMLocalizedString("mm", nil))
  1329. }
  1330. } else {
  1331. cell.sizeLabel.isHidden = true
  1332. }
  1333. cell.sizeTopConstant.constant = cell.sizeLabel.isHidden ? -cell.sizeLabel.frame.size.height : 0
  1334. if(self.thumbnailTableView.selectedRowIndexes.contains(row)) {
  1335. cell.isSelectCell = true
  1336. } else {
  1337. cell.isSelectCell = false
  1338. }
  1339. return cell
  1340. } else if (tableView.isEqual(to: self.findTableView)) {
  1341. let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMFindTableviewCell"), owner: self) as! KMFindTableviewCell
  1342. let selection = searchResults[row]
  1343. if let data = tableColumn?.identifier.rawValue, data == "results" {
  1344. cell.resultLabel.attributedStringValue = selection.attributedString()
  1345. cell.resultLabel.textColor = KMAppearance.Layout.h0Color()
  1346. } else if let data = tableColumn?.identifier.rawValue, data == "page" {
  1347. cell.resultLabel.stringValue = selection.pages().first?.label ?? ""
  1348. cell.resultLabel.textColor = KMAppearance.Layout.h2Color()
  1349. }
  1350. return cell
  1351. }
  1352. // else if ([tableView isEqual:rightSideController.snapshotTableView]) {
  1353. //
  1354. // KMSnapshotTableViewCell *cell = [tableView makeViewWithIdentifier:@"KMSnapshotTableViewCell" owner:self];
  1355. // SKSnapshotWindowController *snapshot = snapshots[row];
  1356. // cell.snapshotImage.image = snapshot.thumbnail;
  1357. // cell.snapshotLabel.stringValue = snapshot.pageLabel;
  1358. // if (snapshot.hasWindow) {
  1359. // cell.snapshotImageView.hidden = NO;
  1360. // } else {
  1361. // cell.snapshotImageView.hidden = YES;
  1362. // }
  1363. // if(selectCellList.count > 0 && [selectCellList.firstObject integerValue]< 0 && (NSUInteger)row == self.snapshots.count - 1) {
  1364. // cell.isSelectCell = YES;
  1365. // } else {
  1366. // cell.isSelectCell = NO;
  1367. // }
  1368. // for (NSUInteger i = 0; i < selectCellList.count; i ++) {
  1369. // NSInteger selectCell = [selectCellList[i] integerValue];
  1370. // if (selectCell == row) {
  1371. // cell.isSelectCell = YES;
  1372. // }
  1373. // }
  1374. // if (row == tableView.selectedRow) {
  1375. // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowSel]];
  1376. // } else {
  1377. // [cell.snapshotImageView setImage:[NSImage imageNamed:KMImageNameUXIconSidebarSnapshotWindowNor]];
  1378. // }
  1379. // return cell;
  1380. // }
  1381. return nil;
  1382. }
  1383. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1384. if tableView.isEqual(to: self.thumbnailTableView) {
  1385. // if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1386. let scaling = UserDefaults.standard.float(forKey: "KMThumbnailSizeScalingKey")
  1387. let thumbnailSize = self.thumbnails[row].size
  1388. let newScaling: CGFloat = scaling.cgFloat + 0.1
  1389. let newThumbnailHeight = thumbnailSize.width * newScaling
  1390. if (newThumbnailHeight > MIN_SIDE_PANE_WIDTH) {
  1391. self.thumbnailZoomOutButton.isEnabled = false
  1392. } else {
  1393. self.thumbnailZoomOutButton.isEnabled = true
  1394. }
  1395. if ((scaling - 0.1) < 0.3) {
  1396. self.thumbnailZoomInButton.isEnabled = false
  1397. } else {
  1398. self.thumbnailZoomInButton.isEnabled = true
  1399. }
  1400. var labelHeight = 0.0
  1401. if (self.isDisplayPageSize) {
  1402. labelHeight = 56.0
  1403. } else {
  1404. labelHeight = 41.5
  1405. }
  1406. let cellHeight = thumbnailSize.height + labelHeight
  1407. var thumbSize: NSSize = .zero
  1408. if (scaling != nil && scaling > 0) {
  1409. thumbSize = NSMakeSize(thumbnailSize.width * scaling.cgFloat, cellHeight * scaling.cgFloat)
  1410. } else {
  1411. thumbSize = NSMakeSize(thumbnailSize.width, cellHeight)
  1412. }
  1413. return thumbSize.height
  1414. // NSSize cellSize = NSMakeSize([[tv tableColumnWithIdentifier:IMAGE_COLUMNID] width], fmin(thumbSize.height, roundedThumbnailSize));
  1415. // if (thumbSize.height < [tv rowHeight])
  1416. // return [tv rowHeight];
  1417. // else if (thumbSize.width / thumbSize.height < cellSize.width / cellSize.height)
  1418. // return cellSize.height;
  1419. // else
  1420. // return fmax([tv rowHeight], fmin(cellSize.width, thumbSize.width) * thumbSize.height / thumbSize.width);
  1421. }
  1422. // else if ([tv isEqual:rightSideController.snapshotTableView]) {
  1423. // CGFloat scaling = [[NSUserDefaults standardUserDefaults] floatForKey:@"KMSnapshotSizeScalingKey"];
  1424. // // NSSize snapshotSize = [[[[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row] thumbnail] size];
  1425. // NSSize snapshotSize = CGSizeMake(120, 63);
  1426. //
  1427. // CGFloat newScaling = scaling + 0.1;
  1428. // CGFloat newSnapshotHeight = snapshotSize.width * newScaling;
  1429. // if (newSnapshotHeight > MIN_SIDE_PANE_WIDTH) {
  1430. // leftSideController.snapshotNormalZoomInButton.enabled = NO;
  1431. // } else {
  1432. // leftSideController.snapshotNormalZoomInButton.enabled = YES;
  1433. // }
  1434. // if ((scaling - 0.1) < 0.3 || (newSnapshotHeight < 150.0)) {
  1435. // leftSideController.snapshotNormalZoomOutButton.enabled = NO;
  1436. // } else {
  1437. // leftSideController.snapshotNormalZoomOutButton.enabled = YES;
  1438. // }
  1439. //
  1440. // CGFloat cellHeight = snapshotSize.height + 24.0;
  1441. // NSSize thumbSize;
  1442. // if (scaling && scaling > 0) {
  1443. // thumbSize = NSMakeSize(snapshotSize.width * scaling, cellHeight * scaling);
  1444. // } else {
  1445. // thumbSize = NSMakeSize(snapshotSize.width, cellHeight);
  1446. // }
  1447. // return thumbSize.height;
  1448. // }
  1449. else if (tableView.isEqual(to: self.findTableView)) {
  1450. return 40.0
  1451. }
  1452. return tableView.rowHeight
  1453. }
  1454. func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  1455. if (tableView.isEqual(to: self.findTableView)) {
  1456. // if ([tableView isEqual:leftSideController.findTableView] || [tableView isEqual:leftSideController.groupedFindTableView]) {
  1457. let rowView = KMCustomTableRowView()
  1458. return rowView
  1459. }
  1460. return nil
  1461. }
  1462. /*
  1463. //- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
  1464. // return nil;
  1465. //}
  1466. - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
  1467. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1468. NSUInteger idx = [rowIndexes firstIndex];
  1469. if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
  1470. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1471. NSString *fileExt = nil;
  1472. NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  1473. if ([[pdfView document] allowsPrinting]) {
  1474. NSData *pdfData = [page dataRepresentation];
  1475. fileExt = @"pdf";
  1476. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePDF, NSPasteboardTypeTIFF,NSFilenamesPboardType, NSFilesPromisePboardType, KPDFThumbnailLocalForDraggedTypes,KPDFThumbnailDoucumentURLForDraggedTypes,nil] owner:self];
  1477. [pboard setData:pdfData forType:NSPasteboardTypePDF];
  1478. NSData *zNSIndexSetData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
  1479. [pboard setData:zNSIndexSetData forType:KPDFThumbnailLocalForDraggedTypes];
  1480. NSData *documentURL = [NSKeyedArchiver archivedDataWithRootObject:[[pdfView document].documentURL absoluteString]];
  1481. NSString *docmentName = [[[pdfView.document.documentURL path] lastPathComponent] stringByDeletingPathExtension];
  1482. __block NSMutableString *pagesName = nil;
  1483. if (rowIndexes.count > 1) {
  1484. pagesName = [NSMutableString stringWithString:@" pages"];
  1485. } else {
  1486. pagesName = [NSMutableString stringWithString:@" page"];
  1487. }
  1488. NSString * tFileName = [NSString stringWithFormat:@"%@ %@",pagesName,[self fileNameWithSelectedPages:rowIndexes]];
  1489. PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
  1490. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1491. PDFPage *copyPage = [[pdfView.document pageAtIndex:idx] copy];
  1492. [pdf insertPage:copyPage atIndex:pdf.pageCount];
  1493. [copyPage release];
  1494. }];
  1495. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  1496. NSString *cachesDir = [paths objectAtIndex:0];
  1497. docmentName = [NSString stringWithFormat:@"%@%@",docmentName,tFileName];
  1498. if (docmentName.length > 50) {
  1499. [docmentName substringWithRange:NSMakeRange(0, 50)];
  1500. }
  1501. cachesDir = [[cachesDir stringByAppendingPathComponent:docmentName] stringByAppendingPathExtension:@"pdf"];
  1502. BOOL success = [pdf writeToFile:cachesDir];
  1503. if (success) {
  1504. [pboard setPropertyList:@[cachesDir] forType:NSFilenamesPboardType];
  1505. }else{
  1506. [pboard setPropertyList:@[@""] forType:NSFilenamesPboardType];
  1507. }
  1508. [pboard setData:documentURL forType:KPDFThumbnailDoucumentURLForDraggedTypes];
  1509. } else {
  1510. fileExt = @"tiff";
  1511. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
  1512. }
  1513. [pboard setData:tiffData forType:NSPasteboardTypeTIFF];
  1514. [pboard setPropertyList:[NSArray arrayWithObject:fileExt] forType:NSFilesPromisePboardType];
  1515. return YES;
  1516. }
  1517. } else if ([tv isEqual:rightSideController.snapshotTableView]) {
  1518. NSUInteger idx = [rowIndexes firstIndex];
  1519. if (idx != NSNotFound) {
  1520. SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
  1521. [pboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSFilesPromisePboardType, nil] owner:self];
  1522. [pboard setData:[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] forType:NSPasteboardTypeTIFF];
  1523. [pboard setPropertyList:[NSArray arrayWithObject:@"tiff"] forType:NSFilesPromisePboardType];
  1524. return YES;
  1525. }
  1526. }
  1527. return NO;
  1528. }
  1529. - (NSArray *)tableView:(NSTableView *)tv namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1530. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1531. __block NSMutableArray *fileURLArray = [NSMutableArray array];
  1532. if (rowIndexes.count > 1) {
  1533. NSString *docmentName = @"";
  1534. NSString * tFileName = [NSString stringWithFormat:@"%@",[self fileNameWithSelectedPages:rowIndexes]];
  1535. PDFDocument *pdf = [[[PDFDocument alloc] init] autorelease];
  1536. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1537. if (idx != NSNotFound && [[pdfView document] isLocked] == NO) {
  1538. PDFPage *copyPage = [[[pdfView document] pageAtIndex:idx] copy];
  1539. [pdf insertPage:copyPage atIndex:pdf.pageCount];
  1540. [copyPage release];
  1541. }
  1542. }];
  1543. NSURL *fileURL = [[[dropDestination URLByAppendingPathComponent:tFileName] URLByAppendingPathExtension:@"pdf"] uniqueFileURL];
  1544. docmentName = fileURL.path;
  1545. BOOL success = [pdf writeToFile:docmentName];
  1546. if(success) {
  1547. [fileURLArray addObject:[fileURL lastPathComponent]];
  1548. }
  1549. } else {
  1550. PDFPage *page = [[pdfView document] pageAtIndex:rowIndexes.firstIndex];
  1551. NSURL *fileURL = [dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]];
  1552. NSString *pathExt = nil;
  1553. NSData *data = nil;
  1554. if ([[pdfView document] allowsPrinting]) {
  1555. pathExt = @"pdf";
  1556. data = [page dataRepresentation];
  1557. } else {
  1558. pathExt = @"tiff";
  1559. data = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  1560. }
  1561. fileURL = [[fileURL URLByAppendingPathExtension:pathExt] uniqueFileURL];
  1562. if ([data writeToURL:fileURL atomically:YES]) {
  1563. [fileURLArray addObject:[fileURL lastPathComponent]];
  1564. }
  1565. }
  1566. return fileURLArray;
  1567. } else if ([tv isEqual:rightSideController.snapshotTableView]) {
  1568. NSUInteger idx = [rowIndexes firstIndex];
  1569. if (idx != NSNotFound) {
  1570. SKSnapshotWindowController *snapshot = [self objectInSnapshotsAtIndex:idx];
  1571. PDFPage *page = [[pdfView document] pageAtIndex:[snapshot pageIndex]];
  1572. NSURL *fileURL = [[dropDestination URLByAppendingPathComponent:[self draggedFileNameForPage:page]] URLByAppendingPathExtension:@"tiff"];
  1573. fileURL = [fileURL uniqueFileURL];
  1574. if ([[[snapshot thumbnailWithSize:0.0] TIFFRepresentation] writeToURL:fileURL atomically:YES])
  1575. return [NSArray arrayWithObjects:[fileURL lastPathComponent], nil];
  1576. }
  1577. }
  1578. return [NSArray array];
  1579. }
  1580. - (void)tableView:(NSTableView *)tv sortDescriptorsDidChange:(NSArray *)oldDescriptors {
  1581. if ([tv isEqual:leftSideController.groupedFindTableView]) {
  1582. [leftSideController.groupedFindArrayController setSortDescriptors:[tv sortDescriptors]];
  1583. }
  1584. }
  1585. #pragma mark NSTableView delegate protocol
  1586. - (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
  1587. if ([[aNotification object] isEqual:leftSideController.findTableView] || [[aNotification object] isEqual:leftSideController.groupedFindTableView]) {
  1588. [self updateFindResultHighlightsForDirection:NSDirectSelection];
  1589. if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  1590. [self hideLeftSideWindow];
  1591. } else if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
  1592. if (mwcFlags.updatingThumbnailSelection == 0) {
  1593. NSInteger row = [leftSideController.thumbnailTableView selectedRow];
  1594. NSInteger curPage = [pdfView.document indexForPage:pdfView.currentPage];
  1595. if (row != -1 && row != curPage)
  1596. [pdfView goToPage:[[pdfView document] pageAtIndex:row]];
  1597. if ([self interactionMode] == SKPresentationMode && [[NSUserDefaults standardUserDefaults] boolForKey:SKAutoHidePresentationContentsKey])
  1598. [self hideLeftSideWindow];
  1599. thumbnailSelectCount = row;
  1600. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  1601. for (NSInteger i = 0; i < leftSideController.thumbnailTableView.numberOfRows; i ++) {
  1602. [rowIndexSet addIndex:i];
  1603. }
  1604. NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  1605. [columnIndexSet addIndex:0];
  1606. [leftSideController.thumbnailTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
  1607. }
  1608. } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
  1609. NSInteger row = [rightSideController.snapshotTableView selectedRow];
  1610. [selectCellList removeAllObjects];
  1611. [selectCellList addObject:[NSString stringWithFormat:@"%ld",row]];
  1612. if (row != -1) {
  1613. SKSnapshotWindowController *controller = [[rightSideController.snapshotArrayController arrangedObjects] objectAtIndex:row];
  1614. if ([[controller window] isVisible])
  1615. [[controller window] orderFront:self];
  1616. }
  1617. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  1618. for (NSInteger i = 0; i < rightSideController.snapshotTableView.numberOfRows; i ++) {
  1619. [rowIndexSet addIndex:i];
  1620. }
  1621. NSMutableIndexSet *columnIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  1622. [columnIndexSet addIndex:0];
  1623. [rightSideController.snapshotTableView reloadDataForRowIndexes:rowIndexSet columnIndexes:columnIndexSet];
  1624. }
  1625. }
  1626. - (BOOL)tableView:(NSTableView *)tv commandSelectRow:(NSInteger)row {
  1627. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1628. // NSRect rect = [[[pdfView document] pageAtIndex:row] boundsForBox:kPDFDisplayBoxCropBox];
  1629. //
  1630. // rect.origin.y = NSMidY(rect) - 0.5 * SNAPSHOT_HEIGHT;
  1631. // rect.size.height = SNAPSHOT_HEIGHT;
  1632. // [self showSnapshotAtPageNumber:row forRect:rect scaleFactor:[pdfView scaleFactor] autoFits:NO];
  1633. KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
  1634. thumbailTabCell.isSelectCell = YES;
  1635. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  1636. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1637. [rowIndexSet addIndex:idx];
  1638. }];
  1639. [rowIndexSet addIndex:row];
  1640. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  1641. return YES;
  1642. }
  1643. return NO;
  1644. }
  1645. - (BOOL)tableView:(NSTableView *)tv shiftSelectRow:(NSInteger)row {
  1646. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1647. if(leftSideController.thumbnailTableView.selectedRowIndexes.count == 0) {
  1648. KMThumbnailTableviewCell *thumbailTabCell = [tv viewAtColumn:0 row:row makeIfNecessary:YES];
  1649. thumbailTabCell.isSelectCell = YES;
  1650. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] initWithIndex:row] autorelease];
  1651. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  1652. return YES;
  1653. } else if (leftSideController.thumbnailTableView.selectedRowIndexes.count == 1 && leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex == (NSUInteger)row) {
  1654. return NO;
  1655. } else {
  1656. __block NSInteger fristIndex = leftSideController.thumbnailTableView.selectedRowIndexes.firstIndex;
  1657. __block NSInteger lastIndex = leftSideController.thumbnailTableView.selectedRowIndexes.lastIndex;
  1658. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1659. if(idx < (NSUInteger)fristIndex) {
  1660. fristIndex = idx;
  1661. }
  1662. if(idx > (NSUInteger)lastIndex) {
  1663. lastIndex = idx;
  1664. }
  1665. }];
  1666. if(row < fristIndex) {
  1667. fristIndex = row;
  1668. } else if (row > lastIndex) {
  1669. lastIndex = row;
  1670. }
  1671. NSMutableIndexSet *rowIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  1672. for (NSInteger i = fristIndex; i<=lastIndex;i++) {
  1673. [rowIndexSet addIndex:i];
  1674. }
  1675. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexSet byExtendingSelection:YES];
  1676. return YES;
  1677. }
  1678. }
  1679. return NO;
  1680. }
  1681. - (void)tableViewColumnDidResize:(NSNotification *)aNotification {
  1682. if ([[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] isEqualToString:IMAGE_COLUMNID]) {
  1683. if ([[aNotification object] isEqual:leftSideController.thumbnailTableView]) {
  1684. [leftSideController.thumbnailTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [leftSideController.thumbnailTableView numberOfRows])]];
  1685. } else if ([[aNotification object] isEqual:rightSideController.snapshotTableView]) {
  1686. [rightSideController.snapshotTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [rightSideController.snapshotTableView numberOfRows])]];
  1687. }
  1688. }
  1689. }
  1690. - (void)tableView:(NSTableView *)tv deleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1691. if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
  1692. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  1693. return;
  1694. }
  1695. if ([tv isEqual:rightSideController.snapshotTableView]) {
  1696. NSArray *controllers = [[rightSideController.snapshotArrayController arrangedObjects] objectsAtIndexes:rowIndexes];
  1697. [controllers makeObjectsPerformSelector:@selector(close)];
  1698. } else if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1699. [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1700. if (idx >= [[pdfView document] pageCount]) {
  1701. return;
  1702. }
  1703. for (PDFAnnotation *item in [[[pdfView document] pageAtIndex:idx] notes]){
  1704. [pdfView removeAnnotation:item];
  1705. }
  1706. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1707. [[[[self document] undoManager] prepareWithInvocationTarget:self] insertPage:page pageAtIndex:idx];
  1708. [[pdfView document] removePageAtIndex:idx];
  1709. }];
  1710. [pdfView layoutDocumentView];
  1711. [pageLabels setArray:[[pdfView document] pageLabels]];
  1712. [self resetThumbnails];
  1713. NSUInteger idx = [rowIndexes firstIndex];
  1714. NSInteger index = MIN(idx, [[pdfView document] pageCount]-1);
  1715. [pdfView goToPage:[[pdfView document] pageAtIndex:index]];
  1716. }
  1717. }
  1718. - (void)insertPage:(PDFPage*)page pageAtIndex:(NSInteger)index {
  1719. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  1720. [[pdfView document] insertPage:page atIndex:index];
  1721. [pdfView layoutDocumentView];
  1722. [pageLabels setArray:[[pdfView document] pageLabels]];
  1723. [self resetThumbnails];
  1724. NSInteger pageIndex = MIN((NSUInteger)index, [[pdfView document] pageCount]-1);
  1725. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  1726. }
  1727. - (BOOL)tableView:(NSTableView *)tv canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1728. if ([tv isEqual:rightSideController.snapshotTableView]) {
  1729. return [rowIndexes count] > 0;
  1730. } else if ([tv isEqual:leftSideController.thumbnailTableView]){
  1731. if (self.pdfDocument.pageCount <= 1) {
  1732. return NO;
  1733. }
  1734. return YES;
  1735. }
  1736. return NO;
  1737. }
  1738. - (void)tableView:(NSTableView *)tv copyRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1739. if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  1740. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  1741. return;
  1742. }
  1743. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1744. self.copysPages = [NSMutableArray array];
  1745. if ([[pdfView document] isLocked] == NO) {
  1746. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1747. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1748. [self.copysPages addObject:page];
  1749. }];
  1750. // NSData *tiffData = [page TIFFDataForRect:[page boundsForBox:[pdfView displayBox]]];
  1751. // NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  1752. // NSPasteboardItem *pboardItem = [[[NSPasteboardItem alloc] init] autorelease];
  1753. // if ([[pdfView document] allowsPrinting])
  1754. // [pboardItem setData:[page dataRepresentation] forType:NSPasteboardTypePDF];
  1755. // [pboardItem setData:tiffData forType:NSPasteboardTypeTIFF];
  1756. // [pboard clearContents];
  1757. // [pboard writeObjects:[NSArray arrayWithObjects:pboardItem, nil]];
  1758. }
  1759. } else if ([tv isEqual:leftSideController.findTableView]) {
  1760. NSMutableString *string = [NSMutableString string];
  1761. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  1762. PDFSelection *match = [searchResults objectAtIndex:idx];
  1763. [string appendString:@"* "];
  1764. [string appendFormat:NSLocalizedString(@"Page %@", @""), [match firstPageLabel]];
  1765. [string appendFormat:@": %@\n", [[match contextString] string]];
  1766. }];
  1767. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  1768. [pboard clearContents];
  1769. [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
  1770. } else if ([tv isEqual:leftSideController.groupedFindTableView]) {
  1771. NSMutableString *string = [NSMutableString string];
  1772. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  1773. SKGroupedSearchResult *result = [groupedSearchResults objectAtIndex:idx];
  1774. NSArray *matches = [result matches];
  1775. [string appendString:@"* "];
  1776. [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result page] displayLabel]];
  1777. [string appendString:@": "];
  1778. [string appendFormat:NSLocalizedString(@"%ld Results", @""), (long)[matches count]];
  1779. [string appendFormat:@":\n\t%@\n", [[matches valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
  1780. }];
  1781. NSPasteboard *pboard = [NSPasteboard generalPasteboard];
  1782. [pboard clearContents];
  1783. [pboard writeObjects:[NSArray arrayWithObjects:string, nil]];
  1784. }
  1785. }
  1786. - (BOOL)tableView:(NSTableView *)tv canCopyRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1787. if ([tv isEqual:leftSideController.thumbnailTableView] || [tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView]) {
  1788. return [rowIndexes count] > 0;
  1789. }
  1790. return NO;
  1791. }
  1792. - (void)tableView:(NSTableView *)tv cutRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1793. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1794. self.copysPages = [NSMutableArray array];
  1795. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1796. if (idx != NSNotFound) {
  1797. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1798. [self.copysPages addObject:page];;
  1799. }
  1800. }];
  1801. [self tableView:tv deleteRowsWithIndexes:rowIndexes];
  1802. }
  1803. }
  1804. - (void)tableView:(NSTableView *)tv rotateRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1805. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1806. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1807. if (idx != NSNotFound) {
  1808. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1809. [[[[self document] undoManager] prepareWithInvocationTarget:self] rotatePage:page pageAtIndex:idx];
  1810. if (page.rotation == 0) {
  1811. [page setRotation:90];
  1812. } else if (page.rotation == 90){
  1813. [page setRotation:180];
  1814. } else if (page.rotation == 180){
  1815. [page setRotation:270];
  1816. } else if (page.rotation == 270){
  1817. [page setRotation:0];
  1818. }
  1819. [pdfView layoutDocumentView];
  1820. [self resetThumbnails];
  1821. NSInteger pageIndex = MIN(idx, [[pdfView document] pageCount]-1);
  1822. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  1823. }
  1824. [leftSideController.thumbnailTableView selectRowIndexes:rowIndexes byExtendingSelection:YES];
  1825. }];
  1826. }
  1827. }
  1828. - (void)rotatePage:(PDFPage*)page pageAtIndex:(NSInteger)index {
  1829. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView rotateRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  1830. if (page.rotation == 0) {
  1831. [page setRotation:270];
  1832. } else if (page.rotation == 90){
  1833. [page setRotation:0];
  1834. } else if (page.rotation == 180){
  1835. [page setRotation:90];
  1836. } else if (page.rotation == 270){
  1837. [page setRotation:180];
  1838. }
  1839. [pdfView layoutDocumentView];
  1840. [self resetThumbnails];
  1841. }
  1842. - (void)tableView:(NSTableView *)tv shareRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1843. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1844. NSUInteger idx = [rowIndexes firstIndex];
  1845. if (idx != NSNotFound) {
  1846. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  1847. NSString *fileName = [[[pdfView document] documentURL] lastPathComponent];
  1848. NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  1849. NSString *filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Untitled"]];
  1850. filePath = [filePath stringByAppendingPathExtension:[fileName pathExtension]];
  1851. [self fileWithPage:page atPath:filePath];
  1852. if (rint(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
  1853. [KMMailHelper sendFileWithPaths:[NSArray arrayWithObject:filePath]];
  1854. } else {
  1855. NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
  1856. [service performWithItems:[NSArray arrayWithObject:[NSURL fileURLWithPath:filePath]]];
  1857. }
  1858. }
  1859. }
  1860. }
  1861. - (void)tableView:(NSTableView *)tv extractRowsWithIndexes:(NSIndexSet *)rowIndexes {
  1862. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1863. NSMutableArray *pages = [NSMutableArray array];
  1864. [leftSideController.thumbnailTableView.selectedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  1865. if (idx < self.pdfView.document.pageCount) {
  1866. [pages addObject:[self.pdfView.document pageAtIndex:idx]];
  1867. }
  1868. }];
  1869. NSString * fileName = [self.pdfView.document getFileNameAccordingSelctPages:pages];
  1870. KMSavePanelAccessoryController *saveAccessCtr = [[KMSavePanelAccessoryController alloc] init];
  1871. NSSavePanel * outputSavePanel = [NSSavePanel savePanel];
  1872. [outputSavePanel setAllowedFileTypes:[NSArray arrayWithObject:@"pdf"]];
  1873. outputSavePanel.accessoryView = saveAccessCtr.view;
  1874. [outputSavePanel setNameFieldStringValue:fileName];
  1875. [outputSavePanel beginSheetModalForWindow:[self window]completionHandler:^(NSInteger result) {
  1876. if (result == NSModalResponseOK) {
  1877. [saveAccessCtr retain];
  1878. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1879. KMProgressWindowController * vc = [[[KMProgressWindowController alloc] init] autorelease];
  1880. // [NSApp beginSheet:[vc window]
  1881. // modalForWindow:self.window
  1882. // modalDelegate:nil
  1883. // didEndSelector:nil
  1884. // contextInfo:NULL];
  1885. [self.window beginSheet:[vc window] completionHandler:^(NSModalResponse returnCode) {
  1886. }];
  1887. NSString *saveFilePath = [[outputSavePanel URL] path];
  1888. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1889. PDFDocument * pdf = [[[PDFDocument alloc] init] autorelease];
  1890. BOOL success = [pdf extractAsOneDocumentWithPages:pages savePath:saveFilePath];
  1891. dispatch_async(dispatch_get_main_queue(), ^{
  1892. if (success) {
  1893. if (saveAccessCtr.openAutomaticButton.state == NSControlStateValueOn) {
  1894. [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:[outputSavePanel URL] display:YES completionHandler:^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error) {
  1895. }];
  1896. } else {
  1897. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  1898. NSURL *url = [NSURL fileURLWithPath:saveFilePath];
  1899. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  1900. }
  1901. }
  1902. [NSApp endSheet:vc.window];
  1903. [vc close];
  1904. [saveAccessCtr release];
  1905. });
  1906. });
  1907. });
  1908. }
  1909. [saveAccessCtr release];
  1910. }];
  1911. }
  1912. }
  1913. - (void)fileWithPage:(PDFPage *)page atPath:(NSString *)filePath {
  1914. NSData *data = [page dataRepresentation];
  1915. PDFDocument *document = [[PDFDocument alloc] initWithData:data];
  1916. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  1917. BOOL success = [document writeToURL:[NSURL fileURLWithPath:filePath]];
  1918. if (success) {
  1919. NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  1920. NSURL *url = [NSURL fileURLWithPath:filePath];
  1921. [workspace activateFileViewerSelectingURLs:[NSArray arrayWithObject:url]];
  1922. }
  1923. [document release];
  1924. }
  1925. - (BOOL)tableView:(NSTableView *)aTableView canPasteFromPasteboard:(NSPasteboard *)pboard
  1926. {
  1927. if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
  1928. if(self.copysPages.count > 0){
  1929. return YES;
  1930. }
  1931. }
  1932. return NO;
  1933. }
  1934. - (void)tableView:(NSTableView *)aTableView pasteFromPasteboard:(NSPasteboard *)pboard
  1935. {
  1936. if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
  1937. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  1938. return;
  1939. }
  1940. if ([aTableView isEqual:leftSideController.thumbnailTableView]) {
  1941. if (self.copysPages.count > 0) {
  1942. NSUInteger index = [[pdfView document] indexForPage:[pdfView currentPage]] + 1;
  1943. if (index == NSNotFound) {
  1944. return;
  1945. }
  1946. [self.copysPages enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(PDFPage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1947. PDFPage *page = [obj copy];
  1948. [[pdfView document] insertPage:page atIndex:index];
  1949. [page release];
  1950. [pdfView layoutDocumentView];
  1951. [pageLabels setArray:[[pdfView document] pageLabels]];
  1952. [self resetThumbnails];
  1953. NSInteger pageIndex = MIN(index, [[pdfView document] pageCount]-1);
  1954. [pdfView goToPage:[[pdfView document] pageAtIndex:pageIndex]];
  1955. [[[[self document] undoManager] prepareWithInvocationTarget:self] tableView:leftSideController.thumbnailTableView deleteRowsWithIndexes:[NSIndexSet indexSetWithIndex:index]];
  1956. }];
  1957. }
  1958. }
  1959. }
  1960. - (NSUInteger)tableView:(NSTableView *)tv highlightLevelForRow:(NSInteger)row {
  1961. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1962. NSUInteger i, iMax = [lastViewedPages count];
  1963. for (i = 0; i < iMax; i++) {
  1964. if (row == (NSInteger)[lastViewedPages pointerAtIndex:i])
  1965. return i;
  1966. }
  1967. }
  1968. return NSNotFound;
  1969. }
  1970. - (void)tableViewMoveLeft:(NSTableView *)tv {
  1971. if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
  1972. [self updateFindResultHighlightsForDirection:NSSelectingPrevious];
  1973. }
  1974. }
  1975. - (void)tableViewMoveRight:(NSTableView *)tv {
  1976. if (([tv isEqual:leftSideController.findTableView] || [tv isEqual:leftSideController.groupedFindTableView])) {
  1977. [self updateFindResultHighlightsForDirection:NSSelectingNext];
  1978. }
  1979. }
  1980. - (id <SKImageToolTipContext>)tableView:(NSTableView *)tv imageContextForRow:(NSInteger)row {
  1981. if ([tv isEqual:leftSideController.findTableView])
  1982. return [[[leftSideController.findArrayController arrangedObjects] objectAtIndex:row] destination];
  1983. else if ([tv isEqual:leftSideController.groupedFindTableView])
  1984. return [[[[[leftSideController.groupedFindArrayController arrangedObjects] objectAtIndex:row] matches] objectAtIndex:0] destination];
  1985. return nil;
  1986. }
  1987. - (NSArray *)tableView:(NSTableView *)tv typeSelectHelperSelectionStrings:(SKTypeSelectHelper *)typeSelectHelper {
  1988. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1989. return pageLabels;
  1990. }
  1991. return nil;
  1992. }
  1993. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper didFailToFindMatchForSearchString:(NSString *)searchString {
  1994. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  1995. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"No match: \"%@\"", @"Status message"), searchString]];
  1996. }
  1997. }
  1998. - (void)tableView:(NSTableView *)tv typeSelectHelper:(SKTypeSelectHelper *)typeSelectHelper updateSearchString:(NSString *)searchString {
  1999. if ([tv isEqual:leftSideController.thumbnailTableView]) {
  2000. if (searchString.length > 0)
  2001. [statusBar setLeftStringValue:[NSString stringWithFormat:NSLocalizedString(@"Go to page: %@", @"Status message"), searchString]];
  2002. else
  2003. [self updateLeftStatus];
  2004. }
  2005. }
  2006. #pragma mark dragging
  2007. - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
  2008. {
  2009. if (dropOperation == NSTableViewDropOn || ![tableView isEqual:leftSideController.thumbnailTableView]) {
  2010. return NSDragOperationNone;
  2011. }
  2012. NSPasteboard *pboard = [info draggingPasteboard];
  2013. if ([pboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
  2014. return NSDragOperationMove;
  2015. } else if ([pboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]){
  2016. NSArray *fileNames = [pboard propertyListForType:NSFilenamesPboardType];
  2017. if (fileNames.count == 1) {
  2018. NSString *path = fileNames.firstObject;
  2019. NSString *pathExtension = [path.pathExtension lowercaseString];
  2020. if ([pathExtension isEqualToString:@"pdf"] ||
  2021. [[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
  2022. return NSDragOperationMove;
  2023. }
  2024. } else {
  2025. return NSDragOperationNone;
  2026. }
  2027. }
  2028. return NSDragOperationNone;
  2029. }
  2030. - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {
  2031. __block BOOL result = NO;
  2032. if (![tableView isEqual:leftSideController.thumbnailTableView]) {
  2033. return result;
  2034. }
  2035. NSPasteboard *pasteboard = [info draggingPasteboard];
  2036. if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:KPDFThumbnailLocalForDraggedTypes]]) {
  2037. result = YES;
  2038. NSData *rowData = [pasteboard dataForType:KPDFThumbnailLocalForDraggedTypes];
  2039. NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
  2040. NSData *urlData = [pasteboard dataForType:KPDFThumbnailDoucumentURLForDraggedTypes];
  2041. NSString *url = [NSKeyedUnarchiver unarchiveObjectWithData:urlData];
  2042. if(![url isEqualToString:[pdfView document].documentURL.absoluteString] && url) {
  2043. if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]){
  2044. NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
  2045. if (fileNames.count == 1) {
  2046. NSString *path = fileNames.firstObject;
  2047. NSString *pathExtension = [path.pathExtension lowercaseString];
  2048. if ([pathExtension isEqualToString:@"pdf"]) {
  2049. __block NSInteger index = row;
  2050. __block NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2051. PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]] autorelease];
  2052. if ([pdf isEncrypted]) {
  2053. KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
  2054. vc.filePath = url;
  2055. [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  2056. if (password) {
  2057. [pdf unlockWithPassword:password];
  2058. for(NSUInteger i=0; i<pdf.pageCount;i++) {
  2059. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2060. [self.pdfView.document insertPage:page atIndex:index];
  2061. [insertIndexSet addIndex:index];
  2062. index++;
  2063. [page release];
  2064. }
  2065. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2066. }
  2067. }];
  2068. [vc release];
  2069. } else {
  2070. for(NSUInteger i=0; i<pdf.pageCount;i++) {
  2071. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2072. [self.pdfView.document insertPage:page atIndex:index];
  2073. [insertIndexSet addIndex:index];
  2074. index++;
  2075. [page release];
  2076. }
  2077. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2078. }
  2079. return YES;
  2080. }
  2081. }
  2082. }
  2083. }
  2084. __block NSInteger pageIndex = 0;
  2085. __block NSMutableArray *pages = [NSMutableArray array];
  2086. [rowIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2087. PDFPage *page = [[[pdfView document] pageAtIndex:idx] copy];
  2088. [pages addObject:page];
  2089. [page release];
  2090. }];
  2091. PDFPage *toPage = nil;
  2092. if (row < (NSInteger)pdfView.document.pageCount) {
  2093. toPage = [pdfView.document pageAtIndex:row];
  2094. }
  2095. __block NSInteger toPageIndex = 0;
  2096. if (toPage) {
  2097. toPageIndex = [pdfView.document indexForPage:toPage];
  2098. } else {
  2099. toPageIndex = pdfView.document.pageCount;
  2100. }
  2101. for(NSUInteger i = 0;i<pages.count;i++) {
  2102. PDFPage *page = pages[i];
  2103. [pdfView.document insertPage:page atIndex:toPageIndex+i];
  2104. pageIndex += 1;
  2105. [self.pdfView goToPage:page];
  2106. }
  2107. [self.pdfView layoutDocumentView];
  2108. __block NSMutableArray *deletepages = [NSMutableArray array];
  2109. [rowIndexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
  2110. if((NSInteger)idx < toPageIndex) {
  2111. if((idx+pageIndex) < pdfView.document.pageCount) {
  2112. PDFPage *page = [[pdfView document] pageAtIndex:idx];
  2113. [deletepages addObject:page];
  2114. [pdfView.document removePageAtIndex:idx];
  2115. }
  2116. } else {
  2117. if((idx+pageIndex) < pdfView.document.pageCount) {
  2118. PDFPage *page = [[pdfView document] pageAtIndex:idx+pageIndex];
  2119. [deletepages addObject:page];
  2120. [pdfView.document removePageAtIndex:idx+pageIndex];
  2121. }
  2122. }
  2123. }];
  2124. [[[[self document] undoManager] prepareWithInvocationTarget:self] undoClick];
  2125. [self.pageLabels setArray:[[self.pdfView document] pageLabels]];
  2126. [self.pdfView layoutDocumentView];
  2127. [self resetThumbnails];
  2128. } else if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] && [tableView isEqual:leftSideController.thumbnailTableView]) {
  2129. if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
  2130. [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
  2131. return NO;
  2132. }
  2133. NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
  2134. NSMutableIndexSet *insertIndexSet = [[[NSMutableIndexSet alloc] init] autorelease];
  2135. __block NSInteger index = row;
  2136. if (fileNames.count == 1) {
  2137. NSString *path = fileNames.firstObject;
  2138. NSString *pathExtension = [path.pathExtension lowercaseString];
  2139. if ([pathExtension isEqualToString:@"pdf"]) {
  2140. PDFDocument *pdf = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]]autorelease];
  2141. if ([pdf isEncrypted]) {
  2142. KMDecryptWindowController *vc = [[KMDecryptWindowController alloc] init];
  2143. vc.filePath = path;
  2144. [vc beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
  2145. if (password) {
  2146. [pdf unlockWithPassword:password];
  2147. for (NSUInteger i = 0; i< pdf.pageCount; i++) {
  2148. PDFPage *page = [[pdf pageAtIndex:i] copy];
  2149. [self.pdfView.document insertPage:page atIndex:index];
  2150. [insertIndexSet addIndex:index];
  2151. index++;
  2152. [page release];
  2153. }
  2154. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2155. }
  2156. }];
  2157. [vc release];
  2158. } else {
  2159. for (NSUInteger i = 0; i < pdf.pageCount; i++) {
  2160. PDFPage * page = [[pdf pageAtIndex:i] copy];
  2161. [self.pdfView.document insertPage:page atIndex:index];
  2162. [insertIndexSet addIndex:index];
  2163. index++;
  2164. [page release];
  2165. }
  2166. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2167. }
  2168. } else if ([[KMImageToPDFMethod supportedImageTypes] containsObject:pathExtension]) {
  2169. NSImage *image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
  2170. PDFPage * page = [[[PDFPage alloc] initWithImage:image] autorelease];
  2171. [pdfView.document insertPage:page atIndex:index];
  2172. [insertIndexSet addIndex:index];
  2173. [self insertPages:insertIndexSet pageAtIndex:(index-1)];
  2174. }
  2175. result = YES;
  2176. } else {
  2177. result = NO;
  2178. }
  2179. }
  2180. return result;
  2181. }
  2182. */
  2183. }