KMLeftSideViewController.swift 118 KB

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