KMBrowserWindowController.swift 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. //
  2. // KMBrowserWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2022/12/9.
  6. //
  7. import Cocoa
  8. @objcMembers class KMBrowserWindowController: CTBrowserWindowController {
  9. var rightSegmentControl: KMSegmentedBox?
  10. var modeType: KMHomeToolState = .Home
  11. var filterType: Int = 0
  12. var mainViewController: NSViewController?
  13. var isShowingTokenTimeOutAlert: Bool = false
  14. var currentTimer: Timer?
  15. private(set) var isMultiTabMode: Bool = false
  16. override func windowDidLoad() {
  17. super.windowDidLoad()
  18. window?.backgroundColor = NSColor(hex: "#DFE1E5")
  19. // window?.setFrameAutosaveName("")
  20. rightTabStripView_.delete = self
  21. homeRightTabStripView_.delete = self
  22. rightTabStripView_.updateView()
  23. fileUploadPanel.delete = self
  24. homeRightTabStripView_.homeRightSearchField.delegate = self
  25. isMultiTabMode = true
  26. addObserverForAppearanceChange()
  27. refreshToolBar(homeToolState: .Home)
  28. NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
  29. NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
  30. if (WelcomeWindowController.welcomeHasShow() == false) {
  31. DispatchQueue.main.async {
  32. let welcome = WelcomeWindowController()
  33. self.window?.beginSheet(welcome.window!)
  34. welcome.itemClick = { [weak self] idx, param in
  35. if (idx == 1) { // 关闭
  36. self?.window?.endSheet((param as! NSWindowController).window!)
  37. } else if (idx == 2) { // 以后提醒
  38. self?.window?.endSheet((param as! NSWindowController).window!)
  39. } else if (idx == 3) { // 注册
  40. self?.window?.endSheet((param as! NSWindowController).window!)
  41. let _ = KMLoginWindowController.show(window: (self?.window)!, .Batch, .register)
  42. }
  43. }
  44. }
  45. }
  46. }
  47. override func windowShouldClose(_ sender: NSWindow) -> Bool {
  48. if self.browser.tabStripModel.count() > 1 {
  49. self.browser.windowDidBeginToClose()
  50. return false
  51. }
  52. return true
  53. }
  54. // MARK: Dark&Light
  55. func addObserverForAppearanceChange() -> Void {
  56. window?.contentView!.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
  57. }
  58. func removeObserverForAppearanceChange() -> Void {
  59. window?.contentView!.removeObserver(self, forKeyPath: "effectiveAppearance")
  60. }
  61. override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  62. if keyPath == "effectiveAppearance" {
  63. updateViewColor()
  64. }
  65. }
  66. override func updateViewColor() {
  67. super.updateViewColor()
  68. window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
  69. }
  70. // MARK: Public Methods
  71. func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
  72. modeType = toolState
  73. let document = browser.activeTabContents()
  74. if document != nil {
  75. if document!.isHome {
  76. homeRightTabStripView_.isHidden = modeType == .Home
  77. } else {
  78. self.homeRightStripView.isHidden = true
  79. }
  80. } else {
  81. self.homeRightStripView.isHidden = true
  82. }
  83. homeRightTabStripView_.homeRefreshButton.isEnabled = true
  84. homeRightTabStripView_.homeUploadButton.isEnabled = true
  85. filterType = 0
  86. rightTabStripView_.sortPopUpButton.removeAllItems()
  87. rightTabStripView_.filterPopUpButton.removeAllItems()
  88. rightTabStripView_.updateView()
  89. }
  90. override var hasToolbar: Bool {
  91. get {
  92. return false
  93. }
  94. }
  95. // MARK: Private Methods
  96. func openDocumentWindow() -> Void {
  97. // let panel = NSOpenPanel()
  98. // panel.allowsMultipleSelection = false
  99. // panel.allowedFileTypes = ["pdf"]
  100. // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  101. // if response == .OK {
  102. // let openPath = panel.url?.path
  103. // let selectDocument = self.selectTabContents(path: openPath!)
  104. // if selectDocument != nil {
  105. // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
  106. // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
  107. // return
  108. // }
  109. // if !panel.url!.path.isPDFValid() {
  110. // let alert = NSAlert()
  111. // alert.alertStyle = .critical
  112. // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  113. // alert.runModal()
  114. // return
  115. // }
  116. // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
  117. // print("openDocumentWindow")
  118. // }
  119. // }
  120. // }
  121. // MARK TODO: + 号开启
  122. self.browser.addHomeTabContents()
  123. }
  124. override func openDocument(_ sender: Any!) {
  125. self.openDocumentWindow()
  126. }
  127. func selectTabContents(path filePath: String) -> KMMainDocument? {
  128. let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
  129. var selectDocument: KMMainDocument?
  130. if document != nil {
  131. if document!.isKind(of: KMMainDocument.self) {
  132. selectDocument = document as! KMMainDocument
  133. }
  134. }
  135. return selectDocument
  136. }
  137. // MARK: Getter
  138. override var rightStripView: NSView! {
  139. get {
  140. return rightTabStripView_
  141. }
  142. }
  143. override var homeRightStripView: NSView! {
  144. get {
  145. return homeRightTabStripView_
  146. }
  147. }
  148. // MARK: Button Action
  149. func commandDispatch(_ sender: Any) -> Void {
  150. openDocumentWindow()
  151. }
  152. func closeAllTabs(_ sender: Any) -> Void {
  153. if self.browser != nil {
  154. self.browser.closeAllTabs()
  155. }
  156. }
  157. func openNewWindow(_ sender: Any) -> Void {
  158. if self.browser != nil {
  159. let activeInt = self.browser.activeTabIndex()
  160. let activeTab = self.browser.activeTabContents()
  161. self.browser.closeTab(at: activeInt, makeHistory: false)
  162. let browser: KMBrowser = KMBrowser.init()
  163. browser.windowController = KMBrowserWindowController.init(browser: browser)
  164. browser.addHomeTabContents()
  165. browser.windowController.showWindow(self)
  166. // browser.add(activeTab, inForeground: false)
  167. // browser.selectTab(at: 1)
  168. if activeTab?.fileURL == nil {
  169. return
  170. }
  171. let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
  172. let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
  173. KMMainDocument().tryToUnlockDocument(pdfDoc!)
  174. if ((pdfDoc?.isLocked)! == true) {
  175. KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
  176. if result == .cancel { /// 关闭
  177. return
  178. }
  179. /// 解密成功
  180. var selectDocument: KMMainDocument? = nil
  181. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  182. selectDocument = (document as! KMMainDocument)
  183. }
  184. if selectDocument != nil {
  185. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  186. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  187. if (selectDocument?.browser.window.isVisible)! as Bool {
  188. selectDocument?.browser.window.orderFront(nil)
  189. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  190. selectDocument?.browser.window.orderFront(nil)
  191. }
  192. } else {
  193. if !(activeTab?.fileURL)!.path.isPDFValid() {
  194. let alert = NSAlert()
  195. alert.alertStyle = .critical
  196. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  197. alert.runModal()
  198. return
  199. }
  200. NSDocumentController.shared.openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, documentWasAlreadyOpen, error in
  201. if error != nil {
  202. NSApp.presentError(error!)
  203. return
  204. }
  205. (document as! KMMainDocument).mainViewController?.password = password
  206. }
  207. }
  208. }
  209. } else {
  210. var selectDocument: KMMainDocument? = nil
  211. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  212. selectDocument = (document as! KMMainDocument)
  213. }
  214. if selectDocument != nil {
  215. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  216. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  217. if (selectDocument?.browser.window.isVisible)! as Bool {
  218. selectDocument?.browser.window.orderFront(nil)
  219. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  220. selectDocument?.browser.window.orderFront(nil)
  221. }
  222. } else {
  223. if !(activeTab?.fileURL)!.path.isPDFValid() {
  224. let alert = NSAlert()
  225. alert.alertStyle = .critical
  226. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  227. alert.runModal()
  228. return
  229. }
  230. NSDocumentController.shared.openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, documentWasAlreadyOpen, error in
  231. if error != nil {
  232. NSApp.presentError(error!)
  233. return
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. // MARK: 待补充[万军]
  241. func mergeAllWindow(_ sender: Any) {
  242. }
  243. override func layoutTabContentArea(_ frame: NSRect) {
  244. super.layoutTabContentArea(frame)
  245. self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
  246. }
  247. }
  248. // MARK: - KMToolbarRightViewDelegate
  249. extension KMBrowserWindowController: KMToolbarRightViewDelegate {
  250. func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
  251. KMComparativeTableViewController.show(window: self.window!)
  252. }
  253. func userInfoButtonAction(_ sender: NSButton) {
  254. if KMLightMemberManager.manager.isLogin() {
  255. Task { @MainActor in
  256. if await KMLightMemberManager.manager.canUseAdvanced() {
  257. KMAccountInfoWindowController.show(window: self.window!)
  258. } else {
  259. KMLoginWindowController.show(window: self.window!)
  260. }
  261. }
  262. } else {
  263. KMLoginWindowController.show(window: self.window!)
  264. }
  265. }
  266. func homeRefreshButtonAction(_ sender: NSButton?) {
  267. self.layoutSubviews()
  268. }
  269. func homeUploadButtonAction(_ sender: NSButton) {
  270. }
  271. func homeMenuSortAction(_ sender: NSPopUpButton) {
  272. }
  273. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  274. }
  275. }
  276. // MARK: - KMUploadFileDelegate
  277. extension KMBrowserWindowController: KMUploadFileDelegate {
  278. // override func cancelOperation(_ sender: Any?) {
  279. //
  280. // }
  281. }
  282. // MARK: - NSSearchFieldDelegate
  283. extension KMBrowserWindowController: NSSearchFieldDelegate {
  284. func controlTextDidChange(_ obj: Notification) {
  285. }
  286. func controlTextDidEndEditing(_ obj: Notification) {
  287. }
  288. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  289. var result = false
  290. return result
  291. }
  292. }
  293. // MARK: -
  294. // MARK: Menu Actions
  295. extension KMBrowserWindowController {
  296. func canResponseDocumentAction() -> Bool {
  297. if (self.browser == nil) {
  298. return false
  299. }
  300. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  301. return false
  302. }
  303. return true
  304. }
  305. }
  306. // MARK: -
  307. // MARK: File Menu
  308. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  309. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  310. if (self.browser == nil) {
  311. return false
  312. }
  313. guard let action = menuItem.action else {
  314. return false
  315. }
  316. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  317. return false
  318. }
  319. if (KMSystemMenu.isFileSelector(sel: action)) {
  320. if (document.isHome) {
  321. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  322. menuItem.action == KMSystemMenu.File.propertySelector ||
  323. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  324. menuItem.action == KMSystemMenu.File.printSelector) {
  325. return false
  326. }
  327. return document.homeViewController!.validateMenuItem(menuItem)
  328. } else {
  329. return document.mainViewController!.validateMenuItem(menuItem)
  330. }
  331. }
  332. if (KMSystemMenu.isEditSelector(sel: action)) {
  333. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  334. }
  335. if (KMSystemMenu.isViewSelector(sel: action)) {
  336. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  337. }
  338. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  339. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  340. }
  341. if (KMSystemMenu.isGotoSelector(sel: action)) {
  342. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  343. }
  344. if (KMSystemMenu.isToolSelector(sel: action)) {
  345. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  346. }
  347. if (KMSystemMenu.isWindowSelector(sel: action)) {
  348. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  349. }
  350. return true
  351. }
  352. }
  353. extension KMBrowserWindowController {
  354. @IBAction func menuItemAction_openFile(_ sender: Any) {
  355. super.openDocument(sender)
  356. }
  357. @IBAction func importFromFile(_ sender: Any) {
  358. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  359. document.homeViewController?.importFromFile(sender)
  360. }
  361. @IBAction func openBlankPage(_ sender: Any) {
  362. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  363. document.homeViewController?.openBlankPage(sender)
  364. }
  365. @IBAction func importFromScanner(_ sender: Any) {
  366. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  367. document.homeViewController?.importFromScanner(sender)
  368. }
  369. @IBAction func menuItemAction_newTab(_ sender: Any) {
  370. self.openDocumentWindow()
  371. }
  372. }
  373. // MARK: - KMSystemFileMenuProtocol
  374. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  375. func menuItemClick_mergePDF(_ sender: Any) {
  376. if (self.canResponseDocumentAction() == false) {
  377. return
  378. }
  379. if let document = self.browser.activeTabContents() as? KMMainDocument {
  380. if (document.isHome) {
  381. document.homeViewController?.menuItemClick_mergePDF(sender)
  382. } else {
  383. document.mainViewController?.menuItemClick_mergePDF(sender)
  384. }
  385. }
  386. }
  387. func menuItemClick_Compress(_ sender: Any) {
  388. if (self.canResponseDocumentAction() == false) {
  389. return
  390. }
  391. if let document = self.browser.activeTabContents() as? KMMainDocument {
  392. if (document.isHome) {
  393. document.homeViewController?.menuItemClick_Compress(sender)
  394. } else {
  395. document.mainViewController?.menuItemClick_Compress(sender)
  396. }
  397. }
  398. }
  399. func menuItemAction_ConvertToWord(_ sender: Any) {
  400. if (self.canResponseDocumentAction() == false) {
  401. return
  402. }
  403. if let document = self.browser.activeTabContents() as? KMMainDocument {
  404. if (document.isHome) {
  405. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  406. } else {
  407. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  408. }
  409. }
  410. }
  411. func menuItemAction_ConvertToExcel(_ sender: Any) {
  412. if (self.canResponseDocumentAction() == false) {
  413. return
  414. }
  415. if let document = self.browser.activeTabContents() as? KMMainDocument {
  416. if (document.isHome) {
  417. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  418. } else {
  419. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  420. }
  421. }
  422. }
  423. func menuItemAction_ConvertToPPT(_ sender: Any) {
  424. if (self.canResponseDocumentAction() == false) {
  425. return
  426. }
  427. if let document = self.browser.activeTabContents() as? KMMainDocument {
  428. if (document.isHome) {
  429. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  430. } else {
  431. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  432. }
  433. }
  434. }
  435. func menuItemAction_ConvertToRTF(_ sender: Any) {
  436. if (self.canResponseDocumentAction() == false) {
  437. return
  438. }
  439. if let document = self.browser.activeTabContents() as? KMMainDocument {
  440. if (document.isHome) {
  441. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  442. } else {
  443. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  444. }
  445. }
  446. }
  447. func menuItemAction_ConvertToHTML(_ sender: Any) {
  448. if (self.canResponseDocumentAction() == false) {
  449. return
  450. }
  451. if let document = self.browser.activeTabContents() as? KMMainDocument {
  452. if (document.isHome) {
  453. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  454. } else {
  455. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  456. }
  457. }
  458. }
  459. func menuItemAction_ConvertToText(_ sender: Any) {
  460. if (self.canResponseDocumentAction() == false) {
  461. return
  462. }
  463. if let document = self.browser.activeTabContents() as? KMMainDocument {
  464. if (document.isHome) {
  465. document.homeViewController?.menuItemAction_ConvertToText(sender)
  466. } else {
  467. document.mainViewController?.menuItemAction_ConvertToText(sender)
  468. }
  469. }
  470. }
  471. func menuItemAction_ConvertToCSV(_ sender: Any) {
  472. if (self.canResponseDocumentAction() == false) {
  473. return
  474. }
  475. if let document = self.browser.activeTabContents() as? KMMainDocument {
  476. if (document.isHome) {
  477. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  478. } else {
  479. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  480. }
  481. }
  482. }
  483. func menuItemAction_ConvertToImage(_ sender: Any) {
  484. if (self.canResponseDocumentAction() == false) {
  485. return
  486. }
  487. if let document = self.browser.activeTabContents() as? KMMainDocument {
  488. if (document.isHome) {
  489. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  490. } else {
  491. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  492. }
  493. }
  494. }
  495. func menuItemClick_SettingPassword(_ sender: Any) {
  496. if (self.canResponseDocumentAction() == false) {
  497. return
  498. }
  499. if let document = self.browser.activeTabContents() as? KMMainDocument {
  500. if (document.isHome) {
  501. document.homeViewController?.menuItemClick_SettingPassword(sender)
  502. } else {
  503. document.mainViewController?.menuItemClick_SettingPassword(sender)
  504. }
  505. }
  506. }
  507. func menuItemClick_RemovePassword(_ sender: Any) {
  508. if (self.canResponseDocumentAction() == false) {
  509. return
  510. }
  511. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  512. document.mainViewController?.menuItemClick_RemovePassword(sender)
  513. }
  514. }
  515. func menuItemAction_closeWindow(_ sender: Any) {
  516. if (self.canResponseDocumentAction() == false) {
  517. return
  518. }
  519. if let document = self.browser.activeTabContents() as? KMMainDocument {
  520. if (document.isHome) {
  521. document.homeViewController?.menuItemAction_closeWindow(sender)
  522. } else {
  523. document.mainViewController?.menuItemAction_closeWindow(sender)
  524. }
  525. }
  526. }
  527. func menuItemAction_closeAllWindows(_ sender: Any) {
  528. if (self.canResponseDocumentAction() == false) {
  529. return
  530. }
  531. if let document = self.browser.activeTabContents() as? KMMainDocument {
  532. if (document.isHome) {
  533. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  534. } else {
  535. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  536. }
  537. }
  538. }
  539. func menuItemAction_closeTagPage(_ sender: Any) {
  540. if (self.canResponseDocumentAction() == false) {
  541. return
  542. }
  543. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  544. document.mainViewController?.menuItemAction_closeTagPage(sender)
  545. }
  546. }
  547. func menuItemAction_showInFinder(_ sender: Any) {
  548. if (self.canResponseDocumentAction() == false) {
  549. return
  550. }
  551. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  552. document.mainViewController?.menuItemAction_showInFinder(sender)
  553. }
  554. }
  555. func menuItemAction_property(_ sender: Any) {
  556. if (self.canResponseDocumentAction() == false) {
  557. return
  558. }
  559. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  560. document.mainViewController?.menuItemAction_property(sender)
  561. }
  562. }
  563. func menuItemAction_print(_ sender: Any) {
  564. if (self.canResponseDocumentAction() == false) {
  565. return
  566. }
  567. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  568. document.mainViewController?.menuItemAction_print(sender)
  569. }
  570. }
  571. }
  572. // MARK: - KMSystemViewMenuProtocol
  573. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  574. func menuItemAction_adjustWidth(_ sender: Any) {
  575. if (self.canResponseDocumentAction() == false) {
  576. return
  577. }
  578. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  579. document.mainViewController?.menuItemAction_adjustWidth(sender)
  580. }
  581. }
  582. func menuItemAction_adjustPage(_ sender: Any) {
  583. if (self.canResponseDocumentAction() == false) {
  584. return
  585. }
  586. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  587. document.mainViewController?.menuItemAction_adjustPage(sender)
  588. }
  589. }
  590. func menuItemAction_size(_ sender: Any) {
  591. if (self.canResponseDocumentAction() == false) {
  592. return
  593. }
  594. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  595. document.mainViewController?.menuItemAction_size(sender)
  596. }
  597. }
  598. func menuItemAction_zoomOut(_ sender: Any) {
  599. if (self.canResponseDocumentAction() == false) {
  600. return
  601. }
  602. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  603. document.mainViewController?.menuItemAction_zoomOut(sender)
  604. }
  605. }
  606. func menuItemAction_zoomIn(_ sender: Any) {
  607. if (self.canResponseDocumentAction() == false) {
  608. return
  609. }
  610. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  611. document.mainViewController?.menuItemAction_zoomIn(sender)
  612. }
  613. }
  614. func menuItemAction_singlePage(_ sender: Any) {
  615. if (self.canResponseDocumentAction() == false) {
  616. return
  617. }
  618. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  619. document.mainViewController?.menuItemAction_singlePage(sender)
  620. }
  621. }
  622. func menuItemAction_singlePageContinue(_ sender: Any) {
  623. if (self.canResponseDocumentAction() == false) {
  624. return
  625. }
  626. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  627. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  628. }
  629. }
  630. func menuItemAction_doublePage(_ sender: Any) {
  631. if (self.canResponseDocumentAction() == false) {
  632. return
  633. }
  634. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  635. document.mainViewController?.menuItemAction_doublePage(sender)
  636. }
  637. }
  638. func menuItemAction_doublePageContinue(_ sender: Any) {
  639. if (self.canResponseDocumentAction() == false) {
  640. return
  641. }
  642. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  643. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  644. }
  645. }
  646. func menuItemAction_bookMode(_ sender: Any) {
  647. if (self.canResponseDocumentAction() == false) {
  648. return
  649. }
  650. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  651. document.mainViewController?.menuItemAction_bookMode(sender)
  652. }
  653. }
  654. func menuItemAction_readMode(_ sender: Any) {
  655. if (self.canResponseDocumentAction() == false) {
  656. return
  657. }
  658. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  659. document.mainViewController?.menuItemAction_readMode(sender)
  660. }
  661. }
  662. func menuItemAction_showSplitPage(_ sender: Any) {
  663. if (self.canResponseDocumentAction() == false) {
  664. return
  665. }
  666. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  667. document.mainViewController?.menuItemAction_showSplitPage(sender)
  668. }
  669. }
  670. func menuItemAction_rotateLeft(_ sender: Any) {
  671. if (self.canResponseDocumentAction() == false) {
  672. return
  673. }
  674. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  675. document.mainViewController?.menuItemAction_rotateLeft(sender)
  676. }
  677. }
  678. func menuItemAction_rotateRight(_ sender: Any) {
  679. if (self.canResponseDocumentAction() == false) {
  680. return
  681. }
  682. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  683. document.mainViewController?.menuItemAction_rotateRight(sender)
  684. }
  685. }
  686. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  687. if (self.canResponseDocumentAction() == false) {
  688. return
  689. }
  690. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  691. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  692. }
  693. }
  694. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  695. if (self.canResponseDocumentAction() == false) {
  696. return
  697. }
  698. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  699. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  700. }
  701. }
  702. func menuItemAction_view_readMode(_ sender: Any) {
  703. if (self.canResponseDocumentAction() == false) {
  704. return
  705. }
  706. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  707. document.mainViewController?.menuItemAction_view_readMode(sender)
  708. }
  709. }
  710. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  711. if (self.canResponseDocumentAction() == false) {
  712. return
  713. }
  714. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  715. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  716. }
  717. }
  718. func menuItemAction_hiddenRightSide(_ sender: Any) {
  719. if (self.canResponseDocumentAction() == false) {
  720. return
  721. }
  722. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  723. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  724. }
  725. }
  726. func menuItemAction_thumai(_ sender: Any) {
  727. if (self.canResponseDocumentAction() == false) {
  728. return
  729. }
  730. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  731. document.mainViewController?.menuItemAction_thumai(sender)
  732. }
  733. }
  734. func menuItemAction_outline(_ sender: Any) {
  735. if (self.canResponseDocumentAction() == false) {
  736. return
  737. }
  738. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  739. document.mainViewController?.menuItemAction_outline(sender)
  740. }
  741. }
  742. func menuItemAction_bookmark(_ sender: Any) {
  743. if (self.canResponseDocumentAction() == false) {
  744. return
  745. }
  746. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  747. document.mainViewController?.menuItemAction_bookmark(sender)
  748. }
  749. }
  750. func menuItemAction_annotation(_ sender: Any) {
  751. if (self.canResponseDocumentAction() == false) {
  752. return
  753. }
  754. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  755. document.mainViewController?.menuItemAction_annotation(sender)
  756. }
  757. }
  758. func menuItemAction_search(_ sender: Any) {
  759. if (self.canResponseDocumentAction() == false) {
  760. return
  761. }
  762. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  763. document.mainViewController?.menuItemAction_search(sender)
  764. }
  765. }
  766. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  767. if (self.canResponseDocumentAction() == false) {
  768. return
  769. }
  770. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  771. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  772. }
  773. }
  774. }
  775. // MARK: - KMSystemEditMenuProtocol
  776. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  777. func menuItemAction_find(_ sender: Any) {
  778. if (self.canResponseDocumentAction() == false) {
  779. return
  780. }
  781. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  782. document.mainViewController?.menuItemAction_find(sender)
  783. }
  784. }
  785. }
  786. // MARK: - Annotation Menu
  787. extension KMBrowserWindowController {
  788. @IBAction func menuItemAction_highlight(_ sender: Any) {
  789. if (self.canResponseDocumentAction() == false) {
  790. return
  791. }
  792. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  793. document.mainViewController?.menuItemAction_highlight(sender)
  794. }
  795. }
  796. @IBAction func menuItemAction_underline(_ sender: Any) {
  797. if (self.canResponseDocumentAction() == false) {
  798. return
  799. }
  800. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  801. document.mainViewController?.menuItemAction_underline(sender)
  802. }
  803. }
  804. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  805. if (self.canResponseDocumentAction() == false) {
  806. return
  807. }
  808. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  809. document.mainViewController?.menuItemAction_deleteLine(sender)
  810. }
  811. }
  812. @IBAction func menuItemAction_freehand(_ sender: Any) {
  813. if (self.canResponseDocumentAction() == false) {
  814. return
  815. }
  816. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  817. document.mainViewController?.menuItemAction_freehand(sender)
  818. }
  819. }
  820. @IBAction func menuItemAction_text(_ sender: Any) {
  821. if (self.canResponseDocumentAction() == false) {
  822. return
  823. }
  824. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  825. document.mainViewController?.menuItemAction_text(sender)
  826. }
  827. }
  828. @IBAction func menuItemAction_note(_ sender: Any) {
  829. if (self.canResponseDocumentAction() == false) {
  830. return
  831. }
  832. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  833. document.mainViewController?.menuItemAction_note(sender)
  834. }
  835. }
  836. @IBAction func menuItemAction_squre(_ sender: Any) {
  837. if (self.canResponseDocumentAction() == false) {
  838. return
  839. }
  840. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  841. document.mainViewController?.menuItemAction_squre(sender)
  842. }
  843. }
  844. @IBAction func menuItemAction_circle(_ sender: Any) {
  845. if (self.canResponseDocumentAction() == false) {
  846. return
  847. }
  848. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  849. document.mainViewController?.menuItemAction_circle(sender)
  850. }
  851. }
  852. @IBAction func menuItemAction_arrow(_ sender: Any) {
  853. if (self.canResponseDocumentAction() == false) {
  854. return
  855. }
  856. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  857. document.mainViewController?.menuItemAction_arrow(sender)
  858. }
  859. }
  860. @IBAction func menuItemAction_line(_ sender: Any) {
  861. if (self.canResponseDocumentAction() == false) {
  862. return
  863. }
  864. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  865. document.mainViewController?.menuItemAction_line(sender)
  866. }
  867. }
  868. // link
  869. @IBAction func menuItemAction_link(_ sender: Any) {
  870. if (self.canResponseDocumentAction() == false) {
  871. return
  872. }
  873. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  874. document.mainViewController?.menuItemAction_link(sender)
  875. }
  876. }
  877. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  878. if (self.canResponseDocumentAction() == false) {
  879. return
  880. }
  881. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  882. document.mainViewController?.menuItemAction_linkPage(sender)
  883. }
  884. }
  885. // stamp
  886. @IBAction func menuItemAction_stamp(_ sender: Any) {
  887. if (self.canResponseDocumentAction() == false) {
  888. return
  889. }
  890. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  891. document.mainViewController?.menuItemAction_stamp(sender)
  892. }
  893. }
  894. @IBAction func menuItemAction_signure(_ sender: Any) {
  895. if (self.canResponseDocumentAction() == false) {
  896. return
  897. }
  898. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  899. document.mainViewController?.menuItemAction_signure(sender)
  900. }
  901. }
  902. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  903. if (self.canResponseDocumentAction() == false) {
  904. return
  905. }
  906. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  907. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  908. }
  909. }
  910. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  911. if (self.canResponseDocumentAction() == false) {
  912. return
  913. }
  914. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  915. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  916. }
  917. }
  918. }
  919. // MARK: - KMSystemGotoMenuProtocol
  920. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  921. func menuItemAction_nextPage(_ sender: Any) {
  922. if (self.canResponseDocumentAction() == false) {
  923. return
  924. }
  925. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  926. document.mainViewController?.menuItemAction_nextPage(sender)
  927. }
  928. }
  929. func menuItemAction_forwardPage(_ sender: Any) {
  930. if (self.canResponseDocumentAction() == false) {
  931. return
  932. }
  933. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  934. document.mainViewController?.menuItemAction_forwardPage(sender)
  935. }
  936. }
  937. func menuItemAction_firstPage(_ sender: Any) {
  938. if (self.canResponseDocumentAction() == false) {
  939. return
  940. }
  941. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  942. document.mainViewController?.menuItemAction_firstPage(sender)
  943. }
  944. }
  945. func menuItemAction_lastPage(_ sender: Any) {
  946. if (self.canResponseDocumentAction() == false) {
  947. return
  948. }
  949. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  950. document.mainViewController?.menuItemAction_lastPage(sender)
  951. }
  952. }
  953. func menuItemAction_forward(_ sender: Any) {
  954. if (self.canResponseDocumentAction() == false) {
  955. return
  956. }
  957. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  958. document.mainViewController?.menuItemAction_forward(sender)
  959. }
  960. }
  961. func menuItemAction_goback(_ sender: Any) {
  962. if (self.canResponseDocumentAction() == false) {
  963. return
  964. }
  965. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  966. document.mainViewController?.menuItemAction_goback(sender)
  967. }
  968. }
  969. func menuItemAction_gotoPage(_ sender: Any) {
  970. if (self.canResponseDocumentAction() == false) {
  971. return
  972. }
  973. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  974. document.mainViewController?.menuItemAction_gotoPage(sender)
  975. }
  976. }
  977. }
  978. // MARK: - KMSystemToolMenuProtocol
  979. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  980. func menuItemAction_scrolTool(_ sender: Any) {
  981. if (self.canResponseDocumentAction() == false) {
  982. return
  983. }
  984. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  985. document.mainViewController?.menuItemAction_scrolTool(sender)
  986. }
  987. }
  988. func menuItemAction_zoomOutTool(_ sender: Any) {
  989. if (self.canResponseDocumentAction() == false) {
  990. return
  991. }
  992. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  993. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  994. }
  995. }
  996. func menuItemAction_selectTool(_ sender: Any) {
  997. if (self.canResponseDocumentAction() == false) {
  998. return
  999. }
  1000. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1001. document.mainViewController?.menuItemAction_selectTool(sender)
  1002. }
  1003. }
  1004. }
  1005. // MARK: - KMSystemWindowMenuRrotocol
  1006. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  1007. func menuItemAction_showForwardTagPage(_ sender: Any) {
  1008. if (self.canResponseDocumentAction() == false) {
  1009. return
  1010. }
  1011. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1012. if (document.isHome) {
  1013. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  1014. } else {
  1015. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  1016. }
  1017. }
  1018. }
  1019. func menuItemAction_showNextTagPage(_ sender: Any) {
  1020. if (self.canResponseDocumentAction() == false) {
  1021. return
  1022. }
  1023. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1024. if (document.isHome) {
  1025. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  1026. } else {
  1027. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  1028. }
  1029. }
  1030. }
  1031. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1032. if (self.canResponseDocumentAction() == false) {
  1033. return
  1034. }
  1035. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1036. if (document.isHome) {
  1037. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1038. } else {
  1039. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1040. }
  1041. }
  1042. }
  1043. func menuItemAction_mergeAllWindow(_ sender: Any) {
  1044. if (self.canResponseDocumentAction() == false) {
  1045. return
  1046. }
  1047. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1048. if (document.isHome) {
  1049. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  1050. } else {
  1051. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  1052. }
  1053. }
  1054. }
  1055. }