KMLeftSideViewController.swift 115 KB

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