KMBrowserWindowController.swift 48 KB

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