KMBrowserWindowController.swift 50 KB

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