|
@@ -408,22 +408,25 @@ class KMThumbnailViewController: NSViewController {
|
|
let indexs = self.thumbnailView.collectionView.selectionIndexes
|
|
let indexs = self.thumbnailView.collectionView.selectionIndexes
|
|
let indexPaths = self.thumbnailView.collectionView.selectionIndexPaths
|
|
let indexPaths = self.thumbnailView.collectionView.selectionIndexPaths
|
|
if indexs.count >= 0 {
|
|
if indexs.count >= 0 {
|
|
|
|
+ var pageItems: [KMThumbnailPageItem] = []
|
|
let newDocument = self.thumbnailView.document
|
|
let newDocument = self.thumbnailView.document
|
|
for index in indexs {
|
|
for index in indexs {
|
|
let page : CPDFPage = newDocument.page(at: UInt(index))
|
|
let page : CPDFPage = newDocument.page(at: UInt(index))
|
|
- if page.rotation == 0 {
|
|
|
|
- page.rotation = 90
|
|
|
|
- } else if page.rotation == 90 {
|
|
|
|
- page.rotation = 180
|
|
|
|
- } else if page.rotation == 180 {
|
|
|
|
- page.rotation = 270
|
|
|
|
- } else if page.rotation == 270 {
|
|
|
|
- page.rotation = 0
|
|
|
|
|
|
+ var rotation = page.rotation
|
|
|
|
+ if rotation == 0 {
|
|
|
|
+ rotation = 90
|
|
|
|
+ } else if rotation == 90 {
|
|
|
|
+ rotation = 180
|
|
|
|
+ } else if rotation == 180 {
|
|
|
|
+ rotation = 270
|
|
|
|
+ } else if rotation == 270 {
|
|
|
|
+ rotation = 0
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ let pageItem = KMThumbnailPageItem(page: page, rotate: rotation, oldRotate: page.rotation)
|
|
|
|
+ pageItems.append(pageItem)
|
|
}
|
|
}
|
|
- self.listView.layoutDocumentView()
|
|
|
|
- self.thumbnailView.reloadData()
|
|
|
|
- self.thumbnailView.collectionView.selectItems(at: indexPaths, scrollPosition: .top)
|
|
|
|
|
|
+ self.rotatePageItems(pageItems: pageItems, indexPaths: indexPaths)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -431,22 +434,24 @@ class KMThumbnailViewController: NSViewController {
|
|
let indexs = self.thumbnailView.collectionView.selectionIndexes
|
|
let indexs = self.thumbnailView.collectionView.selectionIndexes
|
|
let indexPaths = self.thumbnailView.collectionView.selectionIndexPaths
|
|
let indexPaths = self.thumbnailView.collectionView.selectionIndexPaths
|
|
if indexs.count >= 0 {
|
|
if indexs.count >= 0 {
|
|
|
|
+ var pageItems: [KMThumbnailPageItem] = []
|
|
let newDocument = self.thumbnailView.document
|
|
let newDocument = self.thumbnailView.document
|
|
for index in indexs {
|
|
for index in indexs {
|
|
let page : CPDFPage = newDocument.page(at: UInt(index))
|
|
let page : CPDFPage = newDocument.page(at: UInt(index))
|
|
- if page.rotation == 0 {
|
|
|
|
- page.rotation = 270
|
|
|
|
- } else if page.rotation == 90 {
|
|
|
|
- page.rotation = 0
|
|
|
|
- } else if page.rotation == 180 {
|
|
|
|
- page.rotation = 90
|
|
|
|
- } else if page.rotation == 270 {
|
|
|
|
- page.rotation = 180
|
|
|
|
|
|
+ var rotation = page.rotation
|
|
|
|
+ if rotation == 0 {
|
|
|
|
+ rotation = 270
|
|
|
|
+ } else if rotation == 90 {
|
|
|
|
+ rotation = 0
|
|
|
|
+ } else if rotation == 180 {
|
|
|
|
+ rotation = 90
|
|
|
|
+ } else if rotation == 270 {
|
|
|
|
+ rotation = 180
|
|
}
|
|
}
|
|
|
|
+ let pageItem = KMThumbnailPageItem(page: page, rotate: rotation, oldRotate: page.rotation)
|
|
|
|
+ pageItems.append(pageItem)
|
|
}
|
|
}
|
|
- self.listView.layoutDocumentView()
|
|
|
|
- self.thumbnailView.reloadData()
|
|
|
|
- self.thumbnailView.collectionView.selectItems(at: indexPaths, scrollPosition: .top)
|
|
|
|
|
|
+ self.rotatePageItems(pageItems: pageItems, indexPaths: indexPaths)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -488,7 +493,7 @@ class KMThumbnailViewController: NSViewController {
|
|
@IBAction func deletePageItemAction(menu:NSMenuItem) {
|
|
@IBAction func deletePageItemAction(menu:NSMenuItem) {
|
|
let indexs = self.thumbnailView.collectionView.selectionIndexes
|
|
let indexs = self.thumbnailView.collectionView.selectionIndexes
|
|
if indexs.count > 0 {
|
|
if indexs.count > 0 {
|
|
- self.deletePageItemWithIndex(indexs: indexs)
|
|
|
|
|
|
+ self.deletePageItemWithIndexs(indexs: indexs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -537,7 +542,7 @@ class KMThumbnailViewController: NSViewController {
|
|
self.copysPages.append(page ?? CPDFPage())
|
|
self.copysPages.append(page ?? CPDFPage())
|
|
}
|
|
}
|
|
|
|
|
|
- self.deletePageItemWithIndex(indexs: indexs)
|
|
|
|
|
|
+ self.deletePageItemWithIndexs(indexs: indexs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -732,17 +737,28 @@ extension KMThumbnailViewController : NSMenuDelegate,NSMenuItemValidation {
|
|
|
|
|
|
//MARK: undoRedo
|
|
//MARK: undoRedo
|
|
extension KMThumbnailViewController {
|
|
extension KMThumbnailViewController {
|
|
- func rotatePageItemWithIndex(indexs: IndexSet) {
|
|
|
|
- var pageItems: [KMThumbnailPageItem] = []
|
|
|
|
- for index in indexs {
|
|
|
|
- let page: CPDFPage = self.listView.document.page(at: UInt(index))
|
|
|
|
- let pageItem = KMThumbnailPageItem(page: page, index: index, oldIndex: index)
|
|
|
|
- pageItems.append(pageItem)
|
|
|
|
|
|
+ func rotatePageItems(pageItems: [KMThumbnailPageItem], indexPaths: Set<IndexPath>) {
|
|
|
|
+ let tempPageItems = pageItems
|
|
|
|
+ for pageItem in tempPageItems {
|
|
|
|
+ pageItem.page.rotation = pageItem.rotate
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ self.listView.layoutDocumentView()
|
|
|
|
+ self.thumbnailView.reloadData()
|
|
|
|
+ self.thumbnailView.collectionView.selectItems(at: indexPaths, scrollPosition: .top)
|
|
|
|
+
|
|
|
|
+ self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
|
|
|
|
+ //替换下标顺序
|
|
|
|
+ var tempPageItems: [KMThumbnailPageItem] = []
|
|
|
|
+ for pageItem in pageItems {
|
|
|
|
+ let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
|
|
|
|
+ tempPageItems.append(item)
|
|
|
|
+ }
|
|
|
|
+ self.rotatePageItems(pageItems: tempPageItems, indexPaths: indexPaths)
|
|
}
|
|
}
|
|
- self.deletePageItems(pageItems: pageItems)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- func deletePageItemWithIndex(indexs: IndexSet) {
|
|
|
|
|
|
+ func deletePageItemWithIndexs(indexs: IndexSet) {
|
|
var pageItems: [KMThumbnailPageItem] = []
|
|
var pageItems: [KMThumbnailPageItem] = []
|
|
for index in indexs {
|
|
for index in indexs {
|
|
let page: CPDFPage = self.listView.document.page(at: UInt(index))
|
|
let page: CPDFPage = self.listView.document.page(at: UInt(index))
|
|
@@ -763,7 +779,7 @@ extension KMThumbnailViewController {
|
|
self.thumbnailView.reloadData()
|
|
self.thumbnailView.reloadData()
|
|
self.pdfCurrentPageChange()
|
|
self.pdfCurrentPageChange()
|
|
|
|
|
|
- self.undoRedoManager.registerUndo(withTarget: self) { targetType in
|
|
|
|
|
|
+ self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
|
|
self.addPageItems(pageItems: tempPageItems)
|
|
self.addPageItems(pageItems: tempPageItems)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -778,7 +794,7 @@ extension KMThumbnailViewController {
|
|
self.thumbnailView.reloadData()
|
|
self.thumbnailView.reloadData()
|
|
self.pdfCurrentPageChange()
|
|
self.pdfCurrentPageChange()
|
|
|
|
|
|
- self.undoRedoManager.registerUndo(withTarget: self) { targetType in
|
|
|
|
|
|
+ self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
|
|
self.deletePageItems(pageItems: tempPageItems)
|
|
self.deletePageItems(pageItems: tempPageItems)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -802,7 +818,7 @@ extension KMThumbnailViewController {
|
|
self.listView?.layoutDocumentView()
|
|
self.listView?.layoutDocumentView()
|
|
self.thumbnailView.reloadData()
|
|
self.thumbnailView.reloadData()
|
|
|
|
|
|
- self.undoRedoManager.registerUndo(withTarget: self) { targetType in
|
|
|
|
|
|
+ self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
|
|
//替换下标顺序
|
|
//替换下标顺序
|
|
var tempPageItems: [KMThumbnailPageItem] = []
|
|
var tempPageItems: [KMThumbnailPageItem] = []
|
|
for pageItem in pageItems {
|
|
for pageItem in pageItems {
|