KMBrowserWindowController.swift 48 KB

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