123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- //
- // KMMainViewController+UI.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2022/12/15.
- //
- import Foundation
- extension KMMainViewController {
- //通知
- func preferenceDidChangeNotification(notification:Notification) {
-
- }
-
- func convertNotesUsingPDFDocument(_ pdfDocument: CPDFDocument, callback: (()->Void)? = nil) {
- guard let doc = self.listView.document else {
- return
- }
- DispatchQueue.main.async {
- self.beginProgressSheet(withMessage: "", maxValue: 0)
-
- let count = pdfDocument.pageCount
- DispatchQueue.global().async {
- self.model.addAnnotations.removeAll()
- self.model.removeAnnotations.removeAll()
- for i in 0..<count {
- let page = pdfDocument.page(at: i)
-
- for annotation in page?.annotations ?? [] {
- var newAnnotation: CPDFAnnotation?
- if let inkAnnotation = annotation as? CPDFInkAnnotation, inkAnnotation.contents.hasPrefix("<?xml version=\"1.0\" encoding=\"utf-8\"?>") {
- let table = KMTableAnnotation(KMNoteBounds: inkAnnotation.bounds, document: doc)
- table.border = inkAnnotation.border
- table.color = inkAnnotation.color
- table.createForm(withList: inkAnnotation.contents, andPaths: inkAnnotation.bezierPaths())
- table.updateAppearanceInk(withIsAdd: false)
- table.contents = annotation.contents
- newAnnotation = table
- }
- if let newAnnotation = newAnnotation {
- self.model.addAnnotations.append(newAnnotation)
- self.model.removeAnnotations.append(annotation)
- }
- }
-
- }
-
- DispatchQueue.main.async {
- for i in 0..<self.model.addAnnotations.count {
- let newAnnotation = self.model.addAnnotations[i]
- let annotation = self.model.removeAnnotations[i]
-
- let page = annotation.page
- // this is only to make sure markup annotations generate the lineRects, for thread safety
- self.listView.addAnnotation(with: newAnnotation, to: page)
- self.listView.remove(annotation)
- if newAnnotation.contents != nil {
- if newAnnotation.contents.count == 0 {
- newAnnotation.autoUpdateString()
- }
- }
- }
-
- self.dismissProgressSheet()
-
- self.listView.undoManager?.removeAllActions()
- self.undoManager?.removeAllActions()
-
- // 清空数据
- self.model.addAnnotations.removeAll()
- self.model.removeAnnotations.removeAll()
-
- callback?()
- }
- }
- }
- }
-
- // MARK: - KMInterfaceThemeChangedProtocol
-
- override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
- super.interfaceThemeDidChanged(appearance)
-
- }
- }
- //MARK: - ReadModel
- extension KMMainViewController {
-
- @objc func addOutLineItemAction() {
-
- }
-
- @objc func lookUpAction() {
- let label = self.listView.currentSelection?.string() ?? ""
-
- }
-
- @objc func searchBaiduAction() {
- let label = self.listView.currentSelection?.string() ?? ""
- let query = label.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
- if let url = URL(string: "https://www.baidu.com/s?wd=\(query)") {
- NSWorkspace.shared.open(url)
- }
- }
-
- @objc func showInfoInFinder() {
-
- }
-
- @objc func NextPageAction() {
-
- }
-
- @objc func PreviousPageAction() {
-
- }
-
- @objc func TranslateItemAction() {
- // 获取选中的文本
- if let selection = self.listView.currentSelection?.string() {
- // 进行翻译
- let escapedText = selection.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
- let urlStr = "https://translate.google.com/?sl=auto&tl=zh-CN&text=\(escapedText)"
- if let url = URL(string: urlStr) {
- NSWorkspace.shared.open(url)
- }
- } else {
- print("No text selected.")
- }
- }
- @objc func AutoScrollItemAction() {
- //增加判断,如果是正在滚动,就停止,否则就开始滚动
- self.listView.autoFlow()
- }
-
-
- @objc func cutAction(sender: NSMenuItem) {
-
- }
- @objc func deleteAction(sender: NSMenuItem) {
-
- }
- @objc func ColorsItemAction(sender: NSMenuItem) {
-
- }
- @objc func LinesItemAction(sender: NSMenuItem) {
-
- }
- @objc func EditNoteItemAction(sender: NSMenuItem) {
-
- }
- @objc func AITranslateItemAction(sender: NSMenuItem) {
- self.showAITypeChooseView(aiConfigType: .translate)
- }
- @objc func AIProofreadItemAction(sender: NSMenuItem) {
- self.showAITypeChooseView(aiConfigType: .proofreading)
- }
- @objc func AIRewriteItemAction(sender: NSMenuItem) {
- self.showAITypeChooseView(aiConfigType: .reWriting)
- }
-
- }
- // MARK: - KMSnapshotWindowControllerDelegate
- extension KMMainViewController: KMSnapshotWindowControllerDelegate {
- func snapshotControllerWillClose(_ controller: KMSnapshotWindowController) {
-
- }
-
- func snapshotController(_ controller: KMSnapshotWindowController, miniaturizedRect isMiniaturize: Bool) -> NSRect {
- return CGRectZero
- }
-
- func snapshotControllerDidFinishSetup(_ controller: KMSnapshotWindowController) {
- }
- }
- // MARK: - CPDFDocumentDelegate
- extension KMMainViewController: CPDFDocumentDelegate {
- func documentDidBeginDocumentFind(_ document: CPDFDocument!) {
- }
-
- func documentDidEndDocumentFind(_ document: CPDFDocument!) {
- }
- }
|