KMBrowserWindowController.swift 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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. if KMLightMemberManager.manager.isLogin() {
  315. Task { @MainActor in
  316. if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
  317. KMAccountInfoWindowController.show(window: self.window!)
  318. } else {
  319. KMLoginWindowController.show(window: self.window!)
  320. }
  321. }
  322. } else {
  323. KMLoginWindowController.show(window: self.window!)
  324. }
  325. }
  326. func homeRefreshButtonAction(_ sender: NSButton?) {
  327. self.layoutSubviews()
  328. }
  329. func homeUploadButtonAction(_ sender: NSButton) {
  330. }
  331. func homeMenuSortAction(_ sender: NSPopUpButton) {
  332. }
  333. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  334. }
  335. }
  336. // MARK: - KMUploadFileDelegate
  337. extension KMBrowserWindowController: KMUploadFileDelegate {
  338. // override func cancelOperation(_ sender: Any?) {
  339. //
  340. // }
  341. }
  342. // MARK: - NSSearchFieldDelegate
  343. extension KMBrowserWindowController: NSSearchFieldDelegate {
  344. func controlTextDidChange(_ obj: Notification) {
  345. }
  346. func controlTextDidEndEditing(_ obj: Notification) {
  347. }
  348. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  349. var result = false
  350. return result
  351. }
  352. }
  353. // MARK: -
  354. // MARK: Menu Actions
  355. extension KMBrowserWindowController {
  356. func canResponseDocumentAction() -> Bool {
  357. if (self.browser == nil) {
  358. return false
  359. }
  360. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  361. return false
  362. }
  363. return true
  364. }
  365. }
  366. // MARK: -
  367. // MARK: File Menu
  368. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  369. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  370. if (self.browser == nil) {
  371. return false
  372. }
  373. guard let action = menuItem.action else {
  374. return false
  375. }
  376. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  377. return false
  378. }
  379. if (KMSystemMenu.isFileSelector(sel: action)) {
  380. if (document.isHome) {
  381. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  382. menuItem.action == KMSystemMenu.File.propertySelector ||
  383. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  384. menuItem.action == KMSystemMenu.File.printSelector ||
  385. menuItem.action == KMSystemMenu.File.saveAsFlattenedPDFSelector) {
  386. return false
  387. }
  388. return document.homeViewController!.validateMenuItem(menuItem)
  389. } else {
  390. return document.mainViewController!.validateMenuItem(menuItem)
  391. }
  392. }
  393. if (KMSystemMenu.isEditSelector(sel: action)) {
  394. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  395. }
  396. if (KMSystemMenu.isViewSelector(sel: action)) {
  397. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  398. }
  399. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  400. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  401. }
  402. if (KMSystemMenu.isGotoSelector(sel: action)) {
  403. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  404. }
  405. if (KMSystemMenu.isToolSelector(sel: action)) {
  406. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  407. }
  408. if (KMSystemMenu.isWindowSelector(sel: action)) {
  409. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  410. }
  411. return true
  412. }
  413. }
  414. extension KMBrowserWindowController {
  415. @IBAction func menuItemAction_openFile(_ sender: Any) {
  416. super.openDocument(sender)
  417. }
  418. @IBAction func importFromFile(_ sender: Any) {
  419. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  420. if (document.isHome) {
  421. document.homeViewController?.importFromFile(sender)
  422. } else {
  423. self.homeVC = KMHomeViewController()
  424. self.homeVC?.importFromFile(sender)
  425. }
  426. }
  427. @IBAction func openBlankPage(_ sender: Any) {
  428. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  429. if (document.isHome) {
  430. document.homeViewController?.openBlankPage(sender)
  431. } else {
  432. self.homeVC = KMHomeViewController()
  433. self.homeVC?.openBlankPage(sender)
  434. }
  435. }
  436. @IBAction func importFromScanner(_ sender: Any) {
  437. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  438. if (document.isHome) {
  439. document.homeViewController?.importFromScanner(sender)
  440. } else {
  441. self.homeVC = KMHomeViewController()
  442. self.homeVC?.importFromScanner(sender)
  443. }
  444. }
  445. @IBAction func menuItemAction_newTab(_ sender: Any) {
  446. self.openDocumentWindow()
  447. }
  448. }
  449. // MARK: - KMSystemFileMenuProtocol
  450. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  451. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  452. if (self.canResponseDocumentAction() == false) {
  453. return
  454. }
  455. if let document = self.browser.activeTabContents() as? KMMainDocument {
  456. if (document.isHome) {
  457. // document.homeViewController?.menuItemClick_mergePDF(sender)
  458. } else {
  459. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  460. }
  461. }
  462. }
  463. func menuItemClick_mergePDF(_ sender: Any) {
  464. if (self.canResponseDocumentAction() == false) {
  465. return
  466. }
  467. if let document = self.browser.activeTabContents() as? KMMainDocument {
  468. if (document.isHome) {
  469. document.homeViewController?.menuItemClick_mergePDF(sender)
  470. } else {
  471. document.mainViewController?.menuItemClick_mergePDF(sender)
  472. }
  473. }
  474. }
  475. func menuItemClick_Compress(_ sender: Any) {
  476. if (self.canResponseDocumentAction() == false) {
  477. return
  478. }
  479. if let document = self.browser.activeTabContents() as? KMMainDocument {
  480. if (document.isHome) {
  481. document.homeViewController?.menuItemClick_Compress(sender)
  482. } else {
  483. document.mainViewController?.menuItemClick_Compress(sender)
  484. }
  485. }
  486. }
  487. func menuItemAction_ConvertToWord(_ sender: Any) {
  488. if (self.canResponseDocumentAction() == false) {
  489. return
  490. }
  491. if let document = self.browser.activeTabContents() as? KMMainDocument {
  492. if (document.isHome) {
  493. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  494. } else {
  495. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  496. }
  497. }
  498. }
  499. func menuItemAction_ConvertToExcel(_ sender: Any) {
  500. if (self.canResponseDocumentAction() == false) {
  501. return
  502. }
  503. if let document = self.browser.activeTabContents() as? KMMainDocument {
  504. if (document.isHome) {
  505. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  506. } else {
  507. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  508. }
  509. }
  510. }
  511. func menuItemAction_ConvertToPPT(_ sender: Any) {
  512. if (self.canResponseDocumentAction() == false) {
  513. return
  514. }
  515. if let document = self.browser.activeTabContents() as? KMMainDocument {
  516. if (document.isHome) {
  517. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  518. } else {
  519. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  520. }
  521. }
  522. }
  523. func menuItemAction_ConvertToRTF(_ sender: Any) {
  524. if (self.canResponseDocumentAction() == false) {
  525. return
  526. }
  527. if let document = self.browser.activeTabContents() as? KMMainDocument {
  528. if (document.isHome) {
  529. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  530. } else {
  531. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  532. }
  533. }
  534. }
  535. func menuItemAction_ConvertToHTML(_ sender: Any) {
  536. if (self.canResponseDocumentAction() == false) {
  537. return
  538. }
  539. if let document = self.browser.activeTabContents() as? KMMainDocument {
  540. if (document.isHome) {
  541. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  542. } else {
  543. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  544. }
  545. }
  546. }
  547. func menuItemAction_ConvertToText(_ sender: Any) {
  548. if (self.canResponseDocumentAction() == false) {
  549. return
  550. }
  551. if let document = self.browser.activeTabContents() as? KMMainDocument {
  552. if (document.isHome) {
  553. document.homeViewController?.menuItemAction_ConvertToText(sender)
  554. } else {
  555. document.mainViewController?.menuItemAction_ConvertToText(sender)
  556. }
  557. }
  558. }
  559. func menuItemAction_ConvertToCSV(_ sender: Any) {
  560. if (self.canResponseDocumentAction() == false) {
  561. return
  562. }
  563. if let document = self.browser.activeTabContents() as? KMMainDocument {
  564. if (document.isHome) {
  565. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  566. } else {
  567. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  568. }
  569. }
  570. }
  571. func menuItemAction_ConvertToImage(_ sender: Any) {
  572. if (self.canResponseDocumentAction() == false) {
  573. return
  574. }
  575. if let document = self.browser.activeTabContents() as? KMMainDocument {
  576. if (document.isHome) {
  577. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  578. } else {
  579. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  580. }
  581. }
  582. }
  583. func menuItemClick_SettingPassword(_ sender: Any) {
  584. if (self.canResponseDocumentAction() == false) {
  585. return
  586. }
  587. if let document = self.browser.activeTabContents() as? KMMainDocument {
  588. if (document.isHome) {
  589. document.homeViewController?.menuItemClick_SettingPassword(sender)
  590. } else {
  591. document.mainViewController?.menuItemClick_SettingPassword(sender)
  592. }
  593. }
  594. }
  595. func menuItemClick_RemovePassword(_ sender: Any) {
  596. if (self.canResponseDocumentAction() == false) {
  597. return
  598. }
  599. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  600. document.mainViewController?.menuItemClick_RemovePassword(sender)
  601. }
  602. }
  603. func menuItemAction_closeWindow(_ sender: Any) {
  604. if (self.canResponseDocumentAction() == false) {
  605. return
  606. }
  607. if let document = self.browser.activeTabContents() as? KMMainDocument {
  608. if (document.isHome) {
  609. document.homeViewController?.menuItemAction_closeWindow(sender)
  610. } else {
  611. document.mainViewController?.menuItemAction_closeWindow(sender)
  612. }
  613. }
  614. }
  615. func menuItemAction_closeAllWindows(_ sender: Any) {
  616. if (self.canResponseDocumentAction() == false) {
  617. return
  618. }
  619. if let document = self.browser.activeTabContents() as? KMMainDocument {
  620. if (document.isHome) {
  621. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  622. } else {
  623. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  624. }
  625. }
  626. }
  627. func menuItemAction_closeTagPage(_ sender: Any) {
  628. if (self.canResponseDocumentAction() == false) {
  629. return
  630. }
  631. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  632. document.mainViewController?.menuItemAction_closeTagPage(sender)
  633. }
  634. }
  635. func menuItemAction_showInFinder(_ sender: Any) {
  636. if (self.canResponseDocumentAction() == false) {
  637. return
  638. }
  639. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  640. document.mainViewController?.menuItemAction_showInFinder(sender)
  641. }
  642. }
  643. func menuItemAction_property(_ sender: Any) {
  644. if (self.canResponseDocumentAction() == false) {
  645. return
  646. }
  647. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  648. document.mainViewController?.menuItemAction_property(sender)
  649. }
  650. }
  651. func menuItemAction_print(_ sender: Any) {
  652. if (self.canResponseDocumentAction() == false) {
  653. return
  654. }
  655. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  656. document.mainViewController?.menuItemAction_print(sender)
  657. }
  658. }
  659. }
  660. // MARK: - KMSystemViewMenuProtocol
  661. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  662. func menuItemAction_adjustWidth(_ sender: Any) {
  663. if (self.canResponseDocumentAction() == false) {
  664. return
  665. }
  666. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  667. document.mainViewController?.menuItemAction_adjustWidth(sender)
  668. }
  669. }
  670. func menuItemAction_adjustPage(_ sender: Any) {
  671. if (self.canResponseDocumentAction() == false) {
  672. return
  673. }
  674. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  675. document.mainViewController?.menuItemAction_adjustPage(sender)
  676. }
  677. }
  678. func menuItemAction_size(_ sender: Any) {
  679. if (self.canResponseDocumentAction() == false) {
  680. return
  681. }
  682. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  683. document.mainViewController?.menuItemAction_size(sender)
  684. }
  685. }
  686. func menuItemAction_zoomOut(_ sender: Any) {
  687. if (self.canResponseDocumentAction() == false) {
  688. return
  689. }
  690. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  691. document.mainViewController?.menuItemAction_zoomOut(sender)
  692. }
  693. }
  694. func menuItemAction_zoomIn(_ sender: Any) {
  695. if (self.canResponseDocumentAction() == false) {
  696. return
  697. }
  698. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  699. document.mainViewController?.menuItemAction_zoomIn(sender)
  700. }
  701. }
  702. func menuItemAction_singlePage(_ sender: Any) {
  703. if (self.canResponseDocumentAction() == false) {
  704. return
  705. }
  706. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  707. document.mainViewController?.menuItemAction_singlePage(sender)
  708. }
  709. }
  710. func menuItemAction_singlePageContinue(_ sender: Any) {
  711. if (self.canResponseDocumentAction() == false) {
  712. return
  713. }
  714. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  715. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  716. }
  717. }
  718. func menuItemAction_doublePage(_ sender: Any) {
  719. if (self.canResponseDocumentAction() == false) {
  720. return
  721. }
  722. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  723. document.mainViewController?.menuItemAction_doublePage(sender)
  724. }
  725. }
  726. func menuItemAction_doublePageContinue(_ sender: Any) {
  727. if (self.canResponseDocumentAction() == false) {
  728. return
  729. }
  730. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  731. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  732. }
  733. }
  734. func menuItemAction_bookMode(_ sender: Any) {
  735. if (self.canResponseDocumentAction() == false) {
  736. return
  737. }
  738. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  739. document.mainViewController?.menuItemAction_bookMode(sender)
  740. }
  741. }
  742. func menuItemAction_readMode(_ sender: Any) {
  743. if (self.canResponseDocumentAction() == false) {
  744. return
  745. }
  746. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  747. document.mainViewController?.menuItemAction_readMode(sender)
  748. }
  749. }
  750. func menuItemAction_showSplitPage(_ sender: Any) {
  751. if (self.canResponseDocumentAction() == false) {
  752. return
  753. }
  754. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  755. document.mainViewController?.menuItemAction_showSplitPage(sender)
  756. }
  757. }
  758. func menuItemAction_rotateLeft(_ sender: Any) {
  759. if (self.canResponseDocumentAction() == false) {
  760. return
  761. }
  762. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  763. document.mainViewController?.menuItemAction_rotateLeft(sender)
  764. }
  765. }
  766. func menuItemAction_rotateRight(_ sender: Any) {
  767. if (self.canResponseDocumentAction() == false) {
  768. return
  769. }
  770. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  771. document.mainViewController?.menuItemAction_rotateRight(sender)
  772. }
  773. }
  774. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  775. if (self.canResponseDocumentAction() == false) {
  776. return
  777. }
  778. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  779. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  780. }
  781. }
  782. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  783. if (self.canResponseDocumentAction() == false) {
  784. return
  785. }
  786. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  787. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  788. }
  789. }
  790. func menuItemAction_view_readMode(_ sender: Any) {
  791. if (self.canResponseDocumentAction() == false) {
  792. return
  793. }
  794. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  795. document.mainViewController?.menuItemAction_view_readMode(sender)
  796. }
  797. }
  798. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  799. if (self.canResponseDocumentAction() == false) {
  800. return
  801. }
  802. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  803. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  804. }
  805. }
  806. func menuItemAction_hiddenRightSide(_ sender: Any) {
  807. if (self.canResponseDocumentAction() == false) {
  808. return
  809. }
  810. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  811. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  812. }
  813. }
  814. func menuItemAction_thumai(_ sender: Any) {
  815. if (self.canResponseDocumentAction() == false) {
  816. return
  817. }
  818. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  819. document.mainViewController?.menuItemAction_thumai(sender)
  820. }
  821. }
  822. func menuItemAction_outline(_ sender: Any) {
  823. if (self.canResponseDocumentAction() == false) {
  824. return
  825. }
  826. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  827. document.mainViewController?.menuItemAction_outline(sender)
  828. }
  829. }
  830. func menuItemAction_bookmark(_ sender: Any) {
  831. if (self.canResponseDocumentAction() == false) {
  832. return
  833. }
  834. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  835. document.mainViewController?.menuItemAction_bookmark(sender)
  836. }
  837. }
  838. func menuItemAction_annotation(_ sender: Any) {
  839. if (self.canResponseDocumentAction() == false) {
  840. return
  841. }
  842. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  843. document.mainViewController?.menuItemAction_annotation(sender)
  844. }
  845. }
  846. func menuItemAction_search(_ sender: Any) {
  847. if (self.canResponseDocumentAction() == false) {
  848. return
  849. }
  850. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  851. document.mainViewController?.menuItemAction_search(sender)
  852. }
  853. }
  854. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  855. if (self.canResponseDocumentAction() == false) {
  856. return
  857. }
  858. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  859. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  860. }
  861. }
  862. }
  863. // MARK: - KMSystemEditMenuProtocol
  864. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  865. func menuItemAction_find(_ sender: Any) {
  866. if (self.canResponseDocumentAction() == false) {
  867. return
  868. }
  869. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  870. document.mainViewController?.menuItemAction_find(sender)
  871. }
  872. }
  873. }
  874. // MARK: - Annotation Menu
  875. extension KMBrowserWindowController {
  876. @IBAction func menuItemAction_highlight(_ sender: Any) {
  877. if (self.canResponseDocumentAction() == false) {
  878. return
  879. }
  880. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  881. document.mainViewController?.menuItemAction_highlight(sender)
  882. }
  883. }
  884. @IBAction func menuItemAction_underline(_ sender: Any) {
  885. if (self.canResponseDocumentAction() == false) {
  886. return
  887. }
  888. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  889. document.mainViewController?.menuItemAction_underline(sender)
  890. }
  891. }
  892. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  893. if (self.canResponseDocumentAction() == false) {
  894. return
  895. }
  896. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  897. document.mainViewController?.menuItemAction_deleteLine(sender)
  898. }
  899. }
  900. @IBAction func menuItemAction_freehand(_ sender: Any) {
  901. if (self.canResponseDocumentAction() == false) {
  902. return
  903. }
  904. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  905. document.mainViewController?.menuItemAction_freehand(sender)
  906. }
  907. }
  908. @IBAction func menuItemAction_text(_ sender: Any) {
  909. if (self.canResponseDocumentAction() == false) {
  910. return
  911. }
  912. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  913. document.mainViewController?.menuItemAction_text(sender)
  914. }
  915. }
  916. @IBAction func menuItemAction_note(_ sender: Any) {
  917. if (self.canResponseDocumentAction() == false) {
  918. return
  919. }
  920. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  921. document.mainViewController?.menuItemAction_note(sender)
  922. }
  923. }
  924. @IBAction func menuItemAction_squre(_ sender: Any) {
  925. if (self.canResponseDocumentAction() == false) {
  926. return
  927. }
  928. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  929. document.mainViewController?.menuItemAction_squre(sender)
  930. }
  931. }
  932. @IBAction func menuItemAction_circle(_ sender: Any) {
  933. if (self.canResponseDocumentAction() == false) {
  934. return
  935. }
  936. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  937. document.mainViewController?.menuItemAction_circle(sender)
  938. }
  939. }
  940. @IBAction func menuItemAction_arrow(_ sender: Any) {
  941. if (self.canResponseDocumentAction() == false) {
  942. return
  943. }
  944. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  945. document.mainViewController?.menuItemAction_arrow(sender)
  946. }
  947. }
  948. @IBAction func menuItemAction_line(_ sender: Any) {
  949. if (self.canResponseDocumentAction() == false) {
  950. return
  951. }
  952. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  953. document.mainViewController?.menuItemAction_line(sender)
  954. }
  955. }
  956. // link
  957. @IBAction func menuItemAction_link(_ sender: Any) {
  958. if (self.canResponseDocumentAction() == false) {
  959. return
  960. }
  961. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  962. document.mainViewController?.menuItemAction_link(sender)
  963. }
  964. }
  965. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  966. if (self.canResponseDocumentAction() == false) {
  967. return
  968. }
  969. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  970. document.mainViewController?.menuItemAction_linkPage(sender)
  971. }
  972. }
  973. // stamp
  974. @IBAction func menuItemAction_stamp(_ sender: Any) {
  975. if (self.canResponseDocumentAction() == false) {
  976. return
  977. }
  978. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  979. document.mainViewController?.menuItemAction_stamp(sender)
  980. }
  981. }
  982. @IBAction func menuItemAction_signure(_ sender: Any) {
  983. if (self.canResponseDocumentAction() == false) {
  984. return
  985. }
  986. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  987. document.mainViewController?.menuItemAction_signure(sender)
  988. }
  989. }
  990. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  991. if (self.canResponseDocumentAction() == false) {
  992. return
  993. }
  994. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  995. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  996. }
  997. }
  998. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  999. if (self.canResponseDocumentAction() == false) {
  1000. return
  1001. }
  1002. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1003. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1004. }
  1005. }
  1006. }
  1007. // MARK: - KMSystemGotoMenuProtocol
  1008. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1009. func menuItemAction_nextPage(_ sender: Any) {
  1010. if (self.canResponseDocumentAction() == false) {
  1011. return
  1012. }
  1013. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1014. document.mainViewController?.menuItemAction_nextPage(sender)
  1015. }
  1016. }
  1017. func menuItemAction_forwardPage(_ sender: Any) {
  1018. if (self.canResponseDocumentAction() == false) {
  1019. return
  1020. }
  1021. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1022. document.mainViewController?.menuItemAction_forwardPage(sender)
  1023. }
  1024. }
  1025. func menuItemAction_firstPage(_ sender: Any) {
  1026. if (self.canResponseDocumentAction() == false) {
  1027. return
  1028. }
  1029. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1030. document.mainViewController?.menuItemAction_firstPage(sender)
  1031. }
  1032. }
  1033. func menuItemAction_lastPage(_ sender: Any) {
  1034. if (self.canResponseDocumentAction() == false) {
  1035. return
  1036. }
  1037. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1038. document.mainViewController?.menuItemAction_lastPage(sender)
  1039. }
  1040. }
  1041. func menuItemAction_forward(_ sender: Any) {
  1042. if (self.canResponseDocumentAction() == false) {
  1043. return
  1044. }
  1045. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1046. document.mainViewController?.menuItemAction_forward(sender)
  1047. }
  1048. }
  1049. func menuItemAction_goback(_ sender: Any) {
  1050. if (self.canResponseDocumentAction() == false) {
  1051. return
  1052. }
  1053. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1054. document.mainViewController?.menuItemAction_goback(sender)
  1055. }
  1056. }
  1057. func menuItemAction_gotoPage(_ sender: Any) {
  1058. if (self.canResponseDocumentAction() == false) {
  1059. return
  1060. }
  1061. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1062. document.mainViewController?.menuItemAction_gotoPage(sender)
  1063. }
  1064. }
  1065. }
  1066. // MARK: - KMSystemToolMenuProtocol
  1067. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1068. func menuItemAction_scrolTool(_ sender: Any) {
  1069. if (self.canResponseDocumentAction() == false) {
  1070. return
  1071. }
  1072. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1073. document.mainViewController?.menuItemAction_scrolTool(sender)
  1074. }
  1075. }
  1076. func menuItemAction_zoomOutTool(_ sender: Any) {
  1077. if (self.canResponseDocumentAction() == false) {
  1078. return
  1079. }
  1080. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1081. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1082. }
  1083. }
  1084. func menuItemAction_selectTool(_ sender: Any) {
  1085. if (self.canResponseDocumentAction() == false) {
  1086. return
  1087. }
  1088. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1089. document.mainViewController?.menuItemAction_selectTool(sender)
  1090. }
  1091. }
  1092. }
  1093. // MARK: - KMSystemWindowMenuRrotocol
  1094. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  1095. func menuItemAction_showForwardTagPage(_ sender: Any) {
  1096. if (self.canResponseDocumentAction() == false) {
  1097. return
  1098. }
  1099. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1100. if (document.isHome) {
  1101. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  1102. } else {
  1103. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  1104. }
  1105. }
  1106. }
  1107. func menuItemAction_showNextTagPage(_ sender: Any) {
  1108. if (self.canResponseDocumentAction() == false) {
  1109. return
  1110. }
  1111. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1112. if (document.isHome) {
  1113. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  1114. } else {
  1115. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  1116. }
  1117. }
  1118. }
  1119. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1120. if (self.canResponseDocumentAction() == false) {
  1121. return
  1122. }
  1123. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1124. if (document.isHome) {
  1125. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1126. } else {
  1127. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1128. }
  1129. }
  1130. }
  1131. func menuItemAction_mergeAllWindow(_ sender: Any) {
  1132. if (self.canResponseDocumentAction() == false) {
  1133. return
  1134. }
  1135. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1136. if (document.isHome) {
  1137. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  1138. } else {
  1139. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  1140. }
  1141. }
  1142. }
  1143. }
  1144. // MARK: - Analytics (埋点)
  1145. extension KMBrowserWindowController {
  1146. func trackEvent_upgrade() -> Void {
  1147. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  1148. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  1149. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  1150. }
  1151. }