|
@@ -9,31 +9,18 @@ import Cocoa
|
|
|
|
|
|
typealias KMPageEditThumbnailViewSelectionDidChange = (_ selectedIndexs: Set<IndexPath>) -> ()
|
|
|
class KMPageEditThumbnailView: KMPDFThumbnailView {
|
|
|
-
|
|
|
- var selectionDidChange: KMPageEditThumbnailViewSelectionDidChange!
|
|
|
+ var selectionDidChange: KMPageEditThumbnailViewSelectionDidChange?
|
|
|
|
|
|
private let defaultItemSize = NSMakeSize(208, 294)
|
|
|
- private var defaultThumbnailSzie: NSSize!
|
|
|
+ private var defaultThumbnailSzie: NSSize?
|
|
|
|
|
|
- var selectionIndexPaths: Set<IndexPath> {
|
|
|
+ override var selectionIndexPaths: Set<IndexPath> {
|
|
|
get {
|
|
|
- return self.collectionView.selectionIndexPaths
|
|
|
+ return super.selectionIndexPaths
|
|
|
}
|
|
|
set {
|
|
|
- var indexpaths: Set<IndexPath> = []
|
|
|
- for indexpath in newValue {
|
|
|
- if (indexpath.section >= self.collectionView.numberOfSections) {
|
|
|
- continue
|
|
|
- }
|
|
|
- if (indexpath.item >= self.collectionView.numberOfItems(inSection: indexpath.section)) {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- indexpaths.insert(indexpath)
|
|
|
- }
|
|
|
-
|
|
|
- self.collectionView.selectionIndexPaths = indexpaths
|
|
|
-
|
|
|
+ super.selectionIndexPaths = newValue
|
|
|
+
|
|
|
// 通知外面
|
|
|
guard let callback = self.selectionDidChange else {
|
|
|
return
|
|
@@ -45,70 +32,56 @@ class KMPageEditThumbnailView: KMPDFThumbnailView {
|
|
|
override func initDefaultValue() {
|
|
|
super.initDefaultValue()
|
|
|
|
|
|
- self.collectionView.allowsMultipleSelection = true
|
|
|
- self.register(KMPageEditThumbnailItem.self)
|
|
|
- self.collectionView.registerForDraggedTypes([NSPasteboard.PasteboardType(rawValue: "localForDraggedTypes"), .fileURL,.string,.pdf])
|
|
|
- self.collectionView.setDraggingSourceOperationMask([.copy, .delete], forLocal: false)
|
|
|
-
|
|
|
self.itemSize = NSMakeSize(208, 294)
|
|
|
-
|
|
|
self.defaultThumbnailSzie = self.thumbnailSzie
|
|
|
self.isShowPageSize = true
|
|
|
+
|
|
|
+ self.register(KMPageEditThumbnailItem.self)
|
|
|
+ self.collectionView.allowsMultipleSelection = true
|
|
|
}
|
|
|
|
|
|
func selectPages(at indexpaths: Set<IndexPath>) {
|
|
|
self.selectionIndexPaths = indexpaths
|
|
|
}
|
|
|
|
|
|
- public func refreshUI(indexs: Set<IndexPath> = []) {
|
|
|
- if (Thread.isMainThread) {
|
|
|
- if (indexs.isEmpty) {
|
|
|
- self.reloadData()
|
|
|
- } else {
|
|
|
- self.reloadData(indexs: indexs)
|
|
|
- }
|
|
|
- } else {
|
|
|
- DispatchQueue.main.async {
|
|
|
- if (indexs.isEmpty) {
|
|
|
- self.reloadData()
|
|
|
- } else {
|
|
|
- self.reloadData(indexs: indexs)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ public func canZoomOut() -> Bool {
|
|
|
+ return self.itemSize.width <= self.defaultItemSize.width
|
|
|
}
|
|
|
|
|
|
public func zoomOut() {
|
|
|
- if (self.itemSize.width > self.defaultItemSize.width) {
|
|
|
+ if (self.canZoomOut() == false) {
|
|
|
return
|
|
|
}
|
|
|
if (self.itemSize.width < self.defaultItemSize.width) {
|
|
|
self.itemSize = self.defaultItemSize
|
|
|
- self.thumbnailSzie = self.defaultThumbnailSzie
|
|
|
+ self.thumbnailSzie = self.defaultThumbnailSzie!
|
|
|
} else if (self.itemSize.width == self.defaultItemSize.width) {
|
|
|
self.itemSize = NSSize(width: self.defaultItemSize.width*1.5, height: self.defaultItemSize.height*1.5)
|
|
|
- self.thumbnailSzie = NSSize(width: self.defaultThumbnailSzie.width*1.5, height: self.defaultThumbnailSzie.height*1.5)
|
|
|
+ self.thumbnailSzie = NSSize(width: self.defaultThumbnailSzie!.width*1.5, height: self.defaultThumbnailSzie!.height*1.5)
|
|
|
}
|
|
|
|
|
|
let indexpaths = self.collectionView.selectionIndexPaths
|
|
|
- self.refreshUI()
|
|
|
+ self.reloadData()
|
|
|
self.collectionView.selectionIndexPaths = indexpaths
|
|
|
}
|
|
|
|
|
|
+ public func canZoomIn() -> Bool {
|
|
|
+ return self.itemSize.width >= self.defaultItemSize.width
|
|
|
+ }
|
|
|
public func zoomIn() {
|
|
|
- if (self.itemSize.width < self.defaultItemSize.width) {
|
|
|
+ if (self.canZoomIn() == false) {
|
|
|
return
|
|
|
}
|
|
|
if (self.itemSize.width > self.defaultItemSize.width) {
|
|
|
self.itemSize = self.defaultItemSize
|
|
|
- self.thumbnailSzie = self.defaultThumbnailSzie
|
|
|
+ self.thumbnailSzie = self.defaultThumbnailSzie!
|
|
|
} else if (self.itemSize.width == self.defaultItemSize.width) {
|
|
|
self.itemSize = NSSize(width: self.defaultItemSize.width*0.5, height: self.defaultItemSize.height*0.5)
|
|
|
- self.thumbnailSzie = NSSize(width: self.defaultThumbnailSzie.width*0.5, height: self.defaultThumbnailSzie.height*0.5)
|
|
|
+ self.thumbnailSzie = NSSize(width: self.defaultThumbnailSzie!.width*0.5, height: self.defaultThumbnailSzie!.height*0.5)
|
|
|
}
|
|
|
|
|
|
let indexpaths = self.collectionView.selectionIndexPaths
|
|
|
- self.refreshUI()
|
|
|
+ self.reloadData()
|
|
|
self.collectionView.selectionIndexPaths = indexpaths
|
|
|
}
|
|
|
}
|