123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- import Foundation
- extension KMHomeViewController {
-
- func refreshRightBoxUI(_ state: KMHomeToolState) {
- rightFullBox.isHidden = true
- rightTopBox.isHidden = true
- rightBottomBox.isHidden = true
-
- homeButtonVC?.state = .Norm
- pdfToolsButtonVC?.state = .Norm
- cloudDocumentsButtonVC?.state = .Norm
- switch state {
- case .Home:
- rightTopBox.isHidden = false
- rightBottomBox.isHidden = false
- rightTopBox.contentView = fastToolViewController.view
- rightBottomBox.contentView = historyFileViewController.view
- rightFullBox.contentView = nil
-
- let isQuickToolsType:Bool = UserDefaults.standard.bool(forKey: "kHomeQucikToolsTypeKey")
- if isQuickToolsType {
- rightTopBoxHeightConstraint.constant = 230 + ScrollerViewWidget
- } else {
- rightTopBoxHeightConstraint.constant = 326 + ScrollerViewWidget
- }
-
- homeButtonVC?.state = .Sel
- refreshUI()
- break
- case .PDFTools:
- rightFullBox.isHidden = false
- rightFullBox.contentView = pdfToolsViewController.view
- rightTopBox.contentView = nil
- rightBottomBox.contentView = nil
- pdfToolsButtonVC?.state = .Sel
- refreshUI()
- break
- case .CloudDocuments:
- rightFullBox.isHidden = false
- rightFullBox.contentView = cloudDocumentsViewController.view
- rightTopBox.contentView = nil
- rightBottomBox.contentView = nil
-
- cloudDocumentsButtonVC?.state = .Sel
- refreshUI()
- break
- default:
-
- break
- }
- }
-
- func showConvertWindow(type: KMPDFConvertType) {
- Task { @MainActor in
- self.km_secure_openPanel_convert(type: type)
- }
- }
-
- func km_secure_openPanel_convert(type: KMPDFConvertType) {
- DispatchQueue.main.async {
- NSOpenPanel.km_secure_openPanel_success(window: self.view.window!) { url, password in
- if (url.path.isPDFValid() == false) {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
- alert.runModal()
- return
- }
-
- self._showConvertWindow(type: type, url: url, password: password)
- }
- }
- }
-
- func showSecurityWindow() {
- }
-
- func km_secure_openPanel_security(limit: Bool = false) {
- DispatchQueue.main.async {
- NSOpenPanel.km_secure_openPanel_success(window: self.view.window!, needOwner: true) { url, password in
- self._showSecurityWindow(url: url, password: password, limit: limit)
- }
- }
- }
-
- func refreshScrollView() -> Void {
- let rect = self.homeSplitView.frame
- let rightWidth = Int(rect.width) - 271
-
- if self.aiOpenPDFFilesViewController != nil {
- if rightWidth >= (360 + 20 + 328) {
- self.rightTopBoxHeightConstraint.constant = 348
- self.aiOpenPDFFilesViewController.refreshLayout(isLimit: false)
- } else {
- self.rightTopBoxHeightConstraint.constant = 348 * 2
- self.aiOpenPDFFilesViewController.refreshLayout(isLimit: true)
- }
- }
- var contentViewHeight = 0
- if self.historyFileViewController.files.count > 0 {
- if self.historyFileViewController.showMode == .Thumbnail {
- if self.historyFileViewController.thumbnailSCrollView != nil {
- var count = rightWidth/(226 + 32)
- if count <= 0 {
- count = 1
- }
- var row = self.historyFileViewController.files.count/count
- if self.historyFileViewController.files.count%count > 0 {
- row += 1
- }
- let height2 = (248 + 16) * row
- contentViewHeight = Int(self.rightTopBoxHeightConstraint.constant + CGFloat(height2) + 76)
- self.rightBottonHeight.constant = CGFloat(height2) + 76
- }
- } else {
- if self.historyFileViewController.listScrollView != nil {
- let height2 = self.historyFileViewController.files.count * 72 + 32
- contentViewHeight = Int(self.rightTopBoxHeightConstraint.constant + CGFloat(height2) + 76)
- self.rightBottonHeight.constant = CGFloat(height2) + 76
- }
- }
- } else {
- contentViewHeight = Int(rect.height - self.rightTopBox.frame.height)
- self.rightBottonHeight.constant = CGFloat(contentViewHeight)
- }
- if contentViewHeight < Int(rect.height) {
- contentViewHeight = Int(rect.height)
- self.rightBottonHeight.constant = rect.height - self.rightTopBoxHeightConstraint.constant
- }
-
- self.homeRightScrollViewView.documentView!.frame = NSRect(x: 271, y: 0, width: rightWidth, height: contentViewHeight)
-
- let scrollView: NSScrollView = self.homeRightScrollViewView
- let targetOrigin: NSPoint = NSPoint(x: 271, y: (self.homeRightScrollViewView.documentView?.frame.height)!)
- let documentVisibleRect = scrollView.documentVisibleRect
- let documentSize = scrollView.documentView?.frame.size ?? .zero
-
- let maxX = max(271, documentSize.width - documentVisibleRect.size.width)
- let maxY = max(0, documentSize.height - documentVisibleRect.size.height)
- let clampedOrigin = NSPoint(x: min(targetOrigin.x, maxX), y: min(targetOrigin.y, maxY))
- self.homeRightScrollViewView.contentView.scroll(to:clampedOrigin)
- }
-
-
-
- fileprivate func _showConvertWindow(type: KMPDFConvertType, url: URL, password: String? = nil) {
- }
-
- fileprivate func _showSecurityWindow(url: URL, password: String?, limit: Bool = false) {
- }
- }
- extension KMHomeViewController: NSSplitViewDelegate {
- func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return 270.0
- }
-
- func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return 270.0
- }
-
- func splitView(_ splitView: NSSplitView, shouldAdjustSizeOfSubview view: NSView) -> Bool {
- return false
- }
-
- func splitViewDidResizeSubviews(_ notification: Notification) {
- let rect = self.homeSplitView.frame
- self.leftBox.setFrameSize(CGSize(width: 270, height: rect.size.height))
-
- self.rightBox.frame = CGRect(origin: CGPoint(x: 271.0, y: 0), size: CGSize(width: rect.width - 271.0, height: rect.height))
-
- }
-
- func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return proposedPosition
- }
-
- func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
- return false
- }
-
- func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int) -> Bool {
- return false
- }
-
- func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
- return splitView.isEqual(to: self.homeSplitView)
- }
-
- func splitView(_ splitView: NSSplitView, effectiveRect proposedEffectiveRect: NSRect, forDrawnRect drawnRect: NSRect, ofDividerAt dividerIndex: Int) -> NSRect {
- return proposedEffectiveRect
- }
-
- func splitView(_ splitView: NSSplitView, additionalEffectiveRectOfDividerAt dividerIndex: Int) -> NSRect {
- return NSMakeRect(0, 0, 0, 0)
- }
- }
- extension KMHomeViewController: KMHomeFastToolViewControllerDelegate {
- func fastToolViewController(_ viewController: KMHomeFastToolViewController, foldChangeState: Bool) {
- if foldChangeState {
- rightTopBoxHeightConstraint.constant = 230.0 + ScrollerViewWidget
- } else {
- rightTopBoxHeightConstraint.constant = 326.0 + ScrollerViewWidget
- }
- }
- func fastToolDidSelectAllTools(_ viewController: KMHomeFastToolViewController) {
- fastToolDidSelectAllTools()
- }
- func fastToolViewController(_ viewController: KMHomeFastToolViewController, didSelectItemsAt indexPaths: [Int]) {
- for index in indexPaths {
- fastToolItemAction(DataNavigationViewButtonActionType(rawValue: index) ?? .Batch)
- }
- }
- }
- extension KMHomeViewController: KMHomeHistoryFileViewControllerDelegate {
- func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, deleteDocuments indexPaths: [URL]) {
- historyFile(deleteDocuments: indexPaths)
- }
-
- func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, didSelectItemsAt indexPaths: [URL]) {
- for url in indexPaths {
- openHistoryFilePath(url: url)
- }
- }
-
- func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, refreshLayout refresh: Bool) {
- self.refreshScrollView()
- }
- }
- extension KMHomeViewController: KMPDFToolsViewControllerDelegate {
- func pdfToolsViewController(_ viewController: KMPDFToolsViewController, didSelectItemsAt indexPaths: [Int]) {
- for index in indexPaths {
- fastToolItemAction(DataNavigationViewButtonActionType(rawValue: index) ?? .Batch)
- }
- }
- }
- extension KMHomeViewController: KMHomeDragViewDelegate {
- func homeDragView(_ viewController: KMHomeDragView, filePath: URL) {
- if self.aiHomeState == .AITranslation {
- self.aiTranslation(withFilePath: filePath.path)
- } else {
- self.openFile(withFilePath: filePath)
- }
- }
-
- func homeDragView(_ viewController: KMHomeDragView, notSupport: Bool) {
- }
- }
|