KMBrowserWindowController.swift 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  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. NSImage.makeTextAlignImages()
  20. window?.backgroundColor = NSColor.km_init(hex: "#DFE1E5")
  21. // window?.setFrameAutosaveName("")
  22. rightTabStripView_.delete = self
  23. homeRightTabStripView_.delete = self
  24. rightTabStripView_.updateView()
  25. fileUploadPanel.delete = self
  26. homeRightTabStripView_.homeRightSearchField.delegate = self
  27. isMultiTabMode = true
  28. addObserverForAppearanceChange()
  29. refreshToolBar(homeToolState: .Home)
  30. NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
  31. NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
  32. // if (KMWelcomeWindowController.welcomeHasShow() == false) {
  33. // //AI 版本禁掉首次开启帮助文档
  34. //// KMTools.openQuickStartStudy()
  35. //
  36. // DispatchQueue.main.async {
  37. // let welcome = KMWelcomeWindowController()
  38. // self.km_beginSheet(windowC: welcome)
  39. // welcome.itemClick = { [weak self] idx, param in
  40. // if (idx == 1) { // 关闭
  41. // self?.km_endSheet()
  42. // } else if (idx == 2) { // 以后提醒
  43. // self?.km_endSheet()
  44. // } else if (idx == 3) { // 注册
  45. // self?.km_endSheet()
  46. //
  47. // guard let window_ = self?.window else {
  48. // return
  49. // }
  50. // _ = KMLoginWindowController.show(window: window_, .Batch, .register)
  51. // }
  52. // }
  53. // }
  54. // }
  55. }
  56. @objc func closeAction() {
  57. self.window?.performClose(nil)
  58. }
  59. override func windowShouldClose(_ sender: NSWindow) -> Bool {
  60. if self.browser.tabStripModel.count() > 1 {
  61. self.browser.windowDidBeginToClose()
  62. return false
  63. }
  64. return true
  65. }
  66. override func layoutSubviews() {
  67. super.layoutSubviews()
  68. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
  69. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  70. }
  71. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
  72. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  73. }
  74. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
  75. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  76. }
  77. }
  78. // MARK: Dark&Light
  79. func addObserverForAppearanceChange() -> Void {
  80. window?.contentView!.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
  81. }
  82. func removeObserverForAppearanceChange() -> Void {
  83. window?.contentView!.removeObserver(self, forKeyPath: "effectiveAppearance")
  84. }
  85. override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  86. if keyPath == "effectiveAppearance" {
  87. updateViewColor()
  88. }
  89. }
  90. override func updateViewColor() {
  91. super.updateViewColor()
  92. window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
  93. }
  94. // MARK: Public Methods
  95. func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
  96. modeType = toolState
  97. let document = browser.activeTabContents()
  98. if document != nil {
  99. if document!.isHome {
  100. homeRightTabStripView_.isHidden = modeType == .Home
  101. } else {
  102. self.homeRightStripView.isHidden = true
  103. }
  104. } else {
  105. self.homeRightStripView.isHidden = true
  106. }
  107. homeRightTabStripView_.homeRefreshButton.isEnabled = true
  108. homeRightTabStripView_.homeUploadButton.isEnabled = true
  109. filterType = 0
  110. rightTabStripView_.sortPopUpButton.removeAllItems()
  111. rightTabStripView_.filterPopUpButton.removeAllItems()
  112. rightTabStripView_.updateView()
  113. }
  114. override var hasToolbar: Bool {
  115. get {
  116. return false
  117. }
  118. }
  119. var km_browser: KMBrowser? {
  120. get {
  121. return self.browser as? KMBrowser
  122. }
  123. }
  124. // MARK: Private Methods
  125. func openDocumentWindow() -> Void {
  126. // let panel = NSOpenPanel()
  127. // panel.allowsMultipleSelection = false
  128. // panel.allowedFileTypes = ["pdf"]
  129. // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  130. // if response == .OK {
  131. // let openPath = panel.url?.path
  132. // let selectDocument = self.selectTabContents(path: openPath!)
  133. // if selectDocument != nil {
  134. // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
  135. // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
  136. // return
  137. // }
  138. // if !panel.url!.path.isPDFValid() {
  139. // let alert = NSAlert()
  140. // alert.alertStyle = .critical
  141. // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  142. // alert.runModal()
  143. // return
  144. // }
  145. // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
  146. // print("openDocumentWindow")
  147. // }
  148. // }
  149. // }
  150. // MARK TODO: + 号开启
  151. // self.browser.addHomeTabContents()
  152. self.tabStripView?.addTabButton?.layer?.backgroundColor = .clear
  153. self.km_browser?.addNewTabContents()
  154. }
  155. // override func openDocument(_ sender: Any!) {
  156. // self.openDocumentWindow()
  157. // }
  158. func selectTabContents(path filePath: String) -> KMMainDocument? {
  159. let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
  160. var selectDocument: KMMainDocument?
  161. if document != nil {
  162. if document!.isKind(of: KMMainDocument.self) {
  163. selectDocument = document as! KMMainDocument
  164. }
  165. }
  166. return selectDocument
  167. }
  168. // MARK: Getter
  169. override var rightStripView: NSView! {
  170. get {
  171. return rightTabStripView_
  172. }
  173. }
  174. override var homeRightStripView: NSView! {
  175. get {
  176. return homeRightTabStripView_
  177. }
  178. }
  179. // MARK: Button Action
  180. func commandDispatch(_ sender: Any) -> Void {
  181. openDocumentWindow()
  182. }
  183. func closeAllTabs(_ sender: Any) -> Void {
  184. if self.browser != nil {
  185. self.browser.closeAllTabs()
  186. }
  187. }
  188. func openNewWindow(_ sender: Any) -> Void {
  189. if let noti = sender as? NSNotification, noti.object is CTTabController {
  190. if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
  191. return
  192. }
  193. }
  194. if self.browser != nil {
  195. let activeInt = self.browser.activeTabIndex()
  196. let activeTab = self.browser.activeTabContents()
  197. self.browser.closeTab(at: activeInt, makeHistory: false)
  198. let browser: KMBrowser = KMBrowser.init()
  199. browser.windowController = KMBrowserWindowController.init(browser: browser)
  200. browser.addHomeTabContents()
  201. browser.windowController.showWindow(self)
  202. // browser.add(activeTab, inForeground: false)
  203. // browser.selectTab(at: 1)
  204. if activeTab?.fileURL == nil {
  205. return
  206. }
  207. let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
  208. let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
  209. KMMainDocument().tryToUnlockDocument(pdfDoc!)
  210. if ((pdfDoc?.isLocked)! == true) {
  211. KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
  212. if result == .cancel { /// 关闭
  213. return
  214. }
  215. /// 解密成功
  216. var selectDocument: KMMainDocument? = nil
  217. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  218. selectDocument = (document as! KMMainDocument)
  219. }
  220. if selectDocument != nil {
  221. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  222. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  223. if (selectDocument?.browser.window.isVisible)! as Bool {
  224. selectDocument?.browser.window.orderFront(nil)
  225. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  226. selectDocument?.browser.window.orderFront(nil)
  227. }
  228. } else {
  229. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, _, error in
  230. if (error == nil) {
  231. (document as! KMMainDocument).mainViewController?.password = password
  232. }
  233. }
  234. }
  235. }
  236. } else {
  237. var selectDocument: KMMainDocument? = nil
  238. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  239. selectDocument = (document as! KMMainDocument)
  240. }
  241. if selectDocument != nil {
  242. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  243. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  244. if (selectDocument?.browser.window.isVisible)! as Bool {
  245. selectDocument?.browser.window.orderFront(nil)
  246. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  247. selectDocument?.browser.window.orderFront(nil)
  248. }
  249. } else {
  250. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
  251. }
  252. }
  253. }
  254. }
  255. }
  256. func canMergeAllWindow() -> Bool {
  257. return self.fetchBrowserWindowControllers().count > 0
  258. }
  259. fileprivate func fetchBrowserWindowControllers() -> [KMBrowserWindowController] {
  260. var windowArray: [KMBrowserWindowController] = []
  261. for window in NSApp.windows {
  262. guard let windowController = window.windowController, windowController is KMBrowserWindowController else {
  263. continue
  264. }
  265. if let _tabScripC = (windowController as? KMBrowserWindowController)?.tabStripController, _tabScripC.viewsCount() <= 1 {
  266. continue
  267. }
  268. if (window.isVisible && (windowController.isEqual(to: self) == false)) {
  269. windowArray.append(windowController as! KMBrowserWindowController)
  270. }
  271. }
  272. return windowArray
  273. }
  274. func mergeAllWindow(_ sender: Any) {
  275. let windowArray = self.fetchBrowserWindowControllers()
  276. if (windowArray.count <= 0) {
  277. return
  278. }
  279. for windowC in windowArray {
  280. // 拼接窗口 [拼接窗口里的标签,除了home标签]
  281. self.append(windowC, toTabView: NSView())
  282. if let browser = windowC.browser {
  283. if (browser.tabCount() <= 1 && browser.activeTabContents().isHome) {
  284. windowC.close()
  285. }
  286. }
  287. }
  288. }
  289. override func tabDidSelect(_ notification: Notification!) {
  290. super.tabDidSelect(notification)
  291. if let _userInfo = notification.userInfo, let _newContents = _userInfo[CTTabNewContentsUserInfoKey] as? KMMainDocument {
  292. _newContents.addWindowController(self)
  293. }
  294. }
  295. override func layoutTabContentArea(_ frame: NSRect) {
  296. super.layoutTabContentArea(frame)
  297. self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
  298. }
  299. override func openDocument(_ sender: Any!) {
  300. guard let _window = self.window else {
  301. return
  302. }
  303. NSOpenPanel.km_open_pdf_multi_success(_window, panel: nil) { urls in
  304. for url in urls {
  305. NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
  306. }
  307. }
  308. }
  309. }
  310. }
  311. // MARK: - KMToolbarRightViewDelegate
  312. extension KMBrowserWindowController: KMToolbarRightViewDelegate {
  313. func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
  314. self.trackEvent_upgrade()
  315. KMComparativeTableViewController.show(window: self.window!, .upgrade)
  316. }
  317. func userInfoButtonAction(_ sender: NSButton) {
  318. if KMLightMemberManager.manager.isLogin() {
  319. Task { @MainActor in
  320. if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
  321. KMAccountInfoWindowController.show(window: self.window!)
  322. } else {
  323. KMLoginWindowController.show(window: self.window!)
  324. }
  325. }
  326. } else {
  327. KMLoginWindowController.show(window: self.window!)
  328. }
  329. }
  330. func homeRefreshButtonAction(_ sender: NSButton?) {
  331. self.layoutSubviews()
  332. }
  333. func homeUploadButtonAction(_ sender: NSButton) {
  334. }
  335. func homeMenuSortAction(_ sender: NSPopUpButton) {
  336. }
  337. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  338. }
  339. }
  340. // MARK: - KMUploadFileDelegate
  341. extension KMBrowserWindowController: KMUploadFileDelegate {
  342. // override func cancelOperation(_ sender: Any?) {
  343. //
  344. // }
  345. }
  346. // MARK: - NSSearchFieldDelegate
  347. extension KMBrowserWindowController: NSSearchFieldDelegate {
  348. func controlTextDidChange(_ obj: Notification) {
  349. }
  350. func controlTextDidEndEditing(_ obj: Notification) {
  351. }
  352. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  353. var result = false
  354. return result
  355. }
  356. }
  357. // MARK: -
  358. // MARK: Menu Actions
  359. extension KMBrowserWindowController {
  360. func canResponseDocumentAction() -> Bool {
  361. if (self.browser == nil) {
  362. return false
  363. }
  364. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  365. return false
  366. }
  367. return true
  368. }
  369. }
  370. // MARK: -
  371. // MARK: File Menu
  372. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  373. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  374. if (self.browser == nil) {
  375. return false
  376. }
  377. guard let action = menuItem.action else {
  378. return false
  379. }
  380. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  381. return false
  382. }
  383. if (KMSystemMenu.isFileSelector(sel: action)) {
  384. if (document.isHome) {
  385. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  386. menuItem.action == KMSystemMenu.File.propertySelector ||
  387. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  388. menuItem.action == KMSystemMenu.File.printSelector ||
  389. menuItem.action == KMSystemMenu.File.saveAsFlattenedPDFSelector) {
  390. return false
  391. }
  392. return document.homeViewController!.validateMenuItem(menuItem)
  393. } else {
  394. return document.mainViewController!.validateMenuItem(menuItem)
  395. }
  396. }
  397. if (KMSystemMenu.isEditSelector(sel: action)) {
  398. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  399. }
  400. if (KMSystemMenu.isViewSelector(sel: action)) {
  401. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  402. }
  403. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  404. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  405. }
  406. if (KMSystemMenu.isGotoSelector(sel: action)) {
  407. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  408. }
  409. if (KMSystemMenu.isToolSelector(sel: action)) {
  410. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  411. }
  412. if (KMSystemMenu.isWindowSelector(sel: action)) {
  413. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  414. }
  415. if action == #selector(redactAction) {
  416. return document.isHome ? false : true
  417. }
  418. return true
  419. }
  420. }
  421. extension KMBrowserWindowController {
  422. @IBAction func menuItemAction_openFile(_ sender: Any) {
  423. super.openDocument(sender)
  424. }
  425. @IBAction func importFromFile(_ sender: Any) {
  426. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  427. if (document.isHome) {
  428. document.homeViewController?.importFromFile(sender)
  429. } else {
  430. self.homeVC = KMHomeViewController()
  431. self.homeVC?.importFromFile(sender)
  432. }
  433. }
  434. @IBAction func openBlankPage(_ sender: Any) {
  435. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  436. if (document.isHome) {
  437. document.homeViewController?.openBlankPage()
  438. } else {
  439. self.homeVC = KMHomeViewController()
  440. self.homeVC?.openBlankPage()
  441. }
  442. }
  443. @IBAction func importFromScanner(_ sender: Any) {
  444. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  445. if (document.isHome) {
  446. document.homeViewController?.importFromScanner()
  447. } else {
  448. self.homeVC = KMHomeViewController()
  449. self.homeVC?.importFromScanner()
  450. }
  451. }
  452. @IBAction func menuItemAction_newTab(_ sender: Any) {
  453. self.openDocumentWindow()
  454. }
  455. /// New
  456. @IBAction func newDocumentFromClipboard(_ sender: Any?) {
  457. KMPrint("newDocumentFromClipboard")
  458. }
  459. @IBAction func newDocumentFromImage(_ sender: Any?) {
  460. KMPrint("importFromWebPage")
  461. }
  462. @IBAction func importFromWebPage(_ sender: Any?) {
  463. KMPrint("importFromWebPage")
  464. }
  465. /// screenShot
  466. @IBAction func screenShot_SelectArea(_ sender: Any?) {
  467. KMPrint("screenShot_SelectArea")
  468. }
  469. @IBAction func screenShot_Window(_ sender: Any?) {
  470. KMPrint("screenShot_Window")
  471. }
  472. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  473. KMPrint("screenShot_FullScreenDelay")
  474. }
  475. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  476. KMPrint("screenShot_FullScreen")
  477. }
  478. @IBAction func pasteAsPlainText(_ sender: Any?) {
  479. KMPrint("pasteAsPlainText")
  480. }
  481. @IBAction func deselectAll(_ sender: Any?) {
  482. KMPrint("deselectAll")
  483. }
  484. @IBAction func searchPDF(_ sender: Any?) {
  485. KMPrint("searchPDF")
  486. }
  487. @IBAction func notesLink(_ sender: Any?) {
  488. KMPrint("notesLink")
  489. }
  490. @IBAction func notesStamp(_ sender: Any?) {
  491. KMPrint("notesStamp")
  492. }
  493. @IBAction func selectToolModel(_ sender: Any?) {
  494. KMPrint("selectToolModel")
  495. }
  496. @IBAction func table(_ sender: Any?) {
  497. KMPrint("table ...")
  498. }
  499. @IBAction func image(_ sender: Any?) {
  500. KMPrint("image ...")
  501. }
  502. @IBAction func addForm(_ sender: Any?) {
  503. KMPrint("addForm ...")
  504. }
  505. @IBAction func editNote(_ sender: Any?) {
  506. KMPrint("editNote ...")
  507. }
  508. @IBAction func togglePresentation(_ sender: Any?) {
  509. KMPrint("togglePresentation ...")
  510. }
  511. @IBAction func chooseTransition(_ sender: Any?) {
  512. KMPrint("chooseTransition ...")
  513. }
  514. @IBAction func toggleAutoFlow(_ sender: Any?) {
  515. KMPrint("toggleAutoFlow ...")
  516. }
  517. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  518. KMPrint("chooseAutoFlowSetting ...")
  519. }
  520. @IBAction func toggleReadingBar(_ sender: Any?) {
  521. KMPrint("toggleReadingBar ...")
  522. }
  523. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  524. KMPrint("toggleLeftSidePane ...")
  525. }
  526. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  527. KMPrint("changeLeftSidePaneState ...")
  528. }
  529. @IBAction func splitViewAction(_ sender: Any?) {
  530. KMPrint("splitViewAction ...")
  531. }
  532. @IBAction func themesColor(_ sender: Any?) {
  533. KMPrint("themesColor ...")
  534. }
  535. @IBAction func toggleStatusBar(_ sender: Any?) {
  536. KMPrint("toggleStatusBar ...")
  537. }
  538. @IBAction func toggleToolbarShow(_ sender: Any?) {
  539. KMPrint("toggleToolbarShow ...")
  540. }
  541. @IBAction func changeDisplayMode(_ sender: Any?) {
  542. KMPrint("changeDisplayMode ...")
  543. }
  544. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  545. KMPrint("toggleDisplayAsBook ...")
  546. }
  547. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  548. KMPrint("toggleDisplayPageBreaks ...")
  549. }
  550. @IBAction func changeDisplayBox(_ sender: Any?) {
  551. KMPrint("changeDisplayBox ...")
  552. }
  553. @IBAction func changeColor(_ sender: Any?) {
  554. KMPrint("changeColor ...")
  555. }
  556. @IBAction func changeFont(_ sender: Any?) {
  557. KMPrint("changeFont ...")
  558. }
  559. @IBAction func changeAttributes(_ sender: Any?) {
  560. KMPrint("changeAttributes ...")
  561. }
  562. @IBAction func alignLeft(_ sender: Any?) {
  563. KMPrint("alignLeft ...")
  564. }
  565. @IBAction func alignRight(_ sender: Any?) {
  566. KMPrint("alignRight ...")
  567. }
  568. @IBAction func alignCenter(_ sender: Any?) {
  569. KMPrint("alignCenter ...")
  570. }
  571. @IBAction func createNewNote(_ sender: Any?) {
  572. KMPrint("createNewNote ...")
  573. }
  574. @IBAction func toggleHideNotes(_ sender: Any?) {
  575. KMPrint("toggleHideNotes ...")
  576. }
  577. @IBAction func takeSnapshot(_ sender: Any?) {
  578. KMPrint("takeSnapshot ...")
  579. }
  580. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  581. KMPrint("takeSnapshotSelectContent ...")
  582. }
  583. @IBAction func changeDisplaySinglePages(_ sender: Any?) {
  584. KMPrint("changeDisplaySinglePages ...")
  585. }
  586. @IBAction func changeDisplayContinuous(_ sender: Any?) {
  587. KMPrint("changeDisplayContinuous ...")
  588. }
  589. @IBAction func doGoToNextPage(_ sender: Any?) {
  590. KMPrint("doGoToNextPage ...")
  591. }
  592. @IBAction func doGoToPreviousPage(_ sender: Any?) {
  593. KMPrint("doGoToPreviousPage ...")
  594. }
  595. @IBAction func doGoToFirstPage(_ sender: Any?) {
  596. KMPrint("doGoToFirstPage ...")
  597. }
  598. @IBAction func doGoToLastPage(_ sender: Any?) {
  599. KMPrint("doGoToLastPage ...")
  600. }
  601. @IBAction func allGoToNextPage(_ sender: Any?) {
  602. KMPrint("allGoToNextPage ...")
  603. }
  604. @IBAction func allGoToPreviousPage(_ sender: Any?) {
  605. KMPrint("allGoToPreviousPage ...")
  606. }
  607. @IBAction func allGoToFirstPage(_ sender: Any?) {
  608. KMPrint("allGoToFirstPage ...")
  609. }
  610. @IBAction func allGoToLastPage(_ sender: Any?) {
  611. KMPrint("allGoToLastPage ...")
  612. }
  613. @IBAction func doGoToPage(_ sender: Any?) {
  614. KMPrint("doGoToPage ...")
  615. }
  616. @IBAction func doGoBack(_ sender: Any?) {
  617. KMPrint("doGoBack ...")
  618. }
  619. @IBAction func doGoForward(_ sender: Any?) {
  620. KMPrint("doGoForward ...")
  621. }
  622. @IBAction func goToMarkedPage(_ sender: Any?) {
  623. KMPrint("goToMarkedPage ...")
  624. }
  625. @IBAction func markPage(_ sender: Any?) {
  626. KMPrint("markPage ...")
  627. }
  628. @IBAction func doZoomIn(_ sender: Any?) {
  629. KMPrint("doZoomIn ...")
  630. }
  631. @IBAction func doZoomOut(_ sender: Any?) {
  632. KMPrint("doZoomOut ...")
  633. }
  634. @IBAction func doZoomToActualSize(_ sender: Any?) {
  635. KMPrint("doZoomToActualSize ...")
  636. }
  637. @IBAction func doZoomToPhysicalSize(_ sender: Any?) {
  638. KMPrint("doZoomToPhysicalSize ...")
  639. }
  640. @IBAction func doZoomToFit(_ sender: Any?) {
  641. KMPrint("doZoomToFit ...")
  642. }
  643. @IBAction func alternateZoomToFit(_ sender: Any?) {
  644. KMPrint("alternateZoomToFit ...")
  645. }
  646. @IBAction func doZoomToSelection(_ sender: Any?) {
  647. KMPrint("doZoomToSelection ...")
  648. }
  649. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  650. KMPrint("doMarqueeZoomTool ...")
  651. }
  652. @IBAction func doAutoScale(_ sender: Any?) {
  653. KMPrint("doAutoScale ...")
  654. }
  655. @IBAction func toggleAutoScale(_ sender: Any?) {
  656. KMPrint("toggleAutoScale ...")
  657. }
  658. @IBAction func rotateRight(_ sender: Any?) {
  659. KMPrint("rotateRight ...")
  660. }
  661. @IBAction func rotateLeft(_ sender: Any?) {
  662. KMPrint("rotateLeft ...")
  663. }
  664. @IBAction func rotateAllRight(_ sender: Any?) {
  665. KMPrint("rotateAllRight ...")
  666. }
  667. @IBAction func rotateAllLeft(_ sender: Any?) {
  668. KMPrint("rotateAllLeft ...")
  669. }
  670. @IBAction func crop(_ sender: Any?) {
  671. KMPrint("crop ...")
  672. }
  673. @IBAction func cropAll(_ sender: Any?) {
  674. KMPrint("cropAll ...")
  675. }
  676. @IBAction func autoCropAll(_ sender: Any?) {
  677. KMPrint("autoCropAll ...")
  678. }
  679. @IBAction func smartAutoCropAll(_ sender: Any?) {
  680. KMPrint("smartAutoCropAll ...")
  681. }
  682. @IBAction func cropOptionsModel(_ sender: Any?) {
  683. KMPrint("cropOptionsModel ...")
  684. }
  685. @IBAction func autoSelectContent(_ sender: Any?) {
  686. KMPrint("autoSelectContent ...")
  687. }
  688. @IBAction func getInfo(_ sender: Any?) {
  689. KMPrint("getInfo ...")
  690. }
  691. // @IBAction func delete(_ sender: Any?) {
  692. // KMPrint("delete ...")
  693. // }
  694. // @IBAction func paste(_ sender: Any?) {
  695. // KMPrint("paste ...")
  696. // }
  697. @IBAction func alternatePaste(_ sender: Any?) {
  698. KMPrint("alternatePaste ...")
  699. }
  700. @IBAction func copy(_ sender: Any?) {
  701. KMPrint("copy ...")
  702. }
  703. @IBAction func cut(_ sender: Any?) {
  704. KMPrint("cut ...")
  705. }
  706. @IBAction func changeToolMode(_ sender: Any?) {
  707. KMPrint("changeToolMode ...")
  708. }
  709. @IBAction func changeAnnotationMode(_ sender: Any?) {
  710. KMPrint("changeAnnotationMode ...")
  711. }
  712. @IBAction func toggleFullscreen(_ sender: Any?) {
  713. KMPrint("toggleFullscreen ...")
  714. }
  715. @IBAction func toggleRightSidePane(_ sender: Any?) {
  716. KMPrint("toggleRightSidePane ...")
  717. }
  718. @IBAction func performFit(_ sender: Any?) {
  719. KMPrint("performFit ...")
  720. }
  721. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  722. KMPrint("changeRightSidePaneState ...")
  723. }
  724. @IBAction func changeFindPaneState(_ sender: Any?) {
  725. KMPrint("changeFindPaneState ...")
  726. }
  727. @IBAction func toggleSplitPDF(_ sender: Any?) {
  728. KMPrint("toggleSplitPDF ...")
  729. }
  730. @IBAction func search(_ sender: Any?) {
  731. KMPrint("search ...")
  732. }
  733. @IBAction func searchNotes(_ sender: Any?) {
  734. KMPrint("searchNotes ...")
  735. }
  736. @IBAction func password(_ sender: Any?) {
  737. KMPrint("password ...")
  738. }
  739. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  740. KMPrint("savePDFSettingToDefaults ...")
  741. }
  742. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  743. KMPrint("toggleCaseInsensitiveSearch ...")
  744. }
  745. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  746. KMPrint("toggleWholeWordSearch ...")
  747. }
  748. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  749. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  750. }
  751. @IBAction func performFindPanelAction(_ sender: Any?) {
  752. KMPrint("performFindPanelAction ...")
  753. }
  754. @IBAction func scrollUp(_ sender: Any?) {
  755. KMPrint("scrollUp ...")
  756. }
  757. @IBAction func scrollDown(_ sender: Any?) {
  758. KMPrint("scrollDown ...")
  759. }
  760. @IBAction func scrollRight(_ sender: Any?) {
  761. KMPrint("scrollRight ...")
  762. }
  763. @IBAction func scrollLeft(_ sender: Any?) {
  764. KMPrint("scrollLeft ...")
  765. }
  766. @IBAction func selectSelectedNote(_ sender: Any?) {
  767. KMPrint("selectSelectedNote ...")
  768. }
  769. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  770. KMPrint("goToSelectedOutlineItem ...")
  771. }
  772. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  773. KMPrint("goToSelectedFindResults ...")
  774. }
  775. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  776. KMPrint("toggleSelectedSnapshots ...")
  777. }
  778. @IBAction func selfSignProfile(_ sender: Any?) {
  779. KMPrint("selfSignProfile ...")
  780. }
  781. @IBAction func highlightFormFiled(_ sender: Any?) {
  782. KMPrint("highlightFormFiled ...")
  783. }
  784. @IBAction func highlightLinks(_ sender: Any?) {
  785. KMPrint("highlightLinks ...")
  786. }
  787. @IBAction func resetForm(_ sender: Any?) {
  788. KMPrint("resetForm ...")
  789. }
  790. @IBAction func removeAllAnnotation(_ sender: Any?) {
  791. KMPrint("removeAllAnnotation ...")
  792. }
  793. @IBAction func link(_ sender: Any?) {
  794. KMPrint("link ...")
  795. }
  796. @IBAction func addWatermark(_ sender: Any?) {
  797. KMPrint("addWatermark ...")
  798. }
  799. @IBAction func convert(_ sender: Any?) {
  800. KMPrint("convert ...")
  801. }
  802. @IBAction func imageToPDF(_ sender: Any?) {
  803. KMPrint("imageToPDF ...")
  804. }
  805. @IBAction func pageEdit(_ sender: Any?) {
  806. KMPrint("pageEdit ...")
  807. }
  808. @IBAction func ocr(_ sender: Any?) {
  809. KMPrint("ocr ...")
  810. }
  811. @IBAction func insertPage(_ sender: Any?) {
  812. KMPrint("insertPage ...")
  813. }
  814. @IBAction func merge(_ sender: Any?) {
  815. KMPrint("merge ...")
  816. }
  817. @IBAction func split(_ sender: Any?) {
  818. KMPrint("split ...")
  819. }
  820. @IBAction func comparison(_ sender: Any?) {
  821. KMPrint("comparison ...")
  822. }
  823. @IBAction func contentComparison(_ sender: Any?) {
  824. KMPrint("contentComparison ...")
  825. }
  826. @IBAction func coverageComparison(_ sender: Any?) {
  827. KMPrint("coverageComparison ...")
  828. }
  829. @IBAction func extractImage(_ sender: Any?) {
  830. KMPrint("extractImage ...")
  831. }
  832. @IBAction func security(_ sender: Any?) {
  833. KMPrint("security ...")
  834. }
  835. @IBAction func addBackground(_ sender: Any?) {
  836. KMPrint("addBackground ...")
  837. }
  838. @IBAction func removeBackground(_ sender: Any?) {
  839. KMPrint("removeBackground ...")
  840. }
  841. @IBAction func addHeaderFooter(_ sender: Any?) {
  842. KMPrint("addHeaderFooter ...")
  843. }
  844. @IBAction func removeHeaderFooter(_ sender: Any?) {
  845. KMPrint("removeHeaderFooter ...")
  846. }
  847. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  848. KMPrint("addHeaderFooterBates ...")
  849. }
  850. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  851. KMPrint("removeHeaderFooterBates ...")
  852. }
  853. @IBAction func editWatermark(_ sender: Any?) {
  854. KMPrint("editWatermark ...")
  855. }
  856. @IBAction func batchAddWatermark(_ sender: Any?) {
  857. KMPrint("batchAddWatermark ...")
  858. }
  859. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  860. KMPrint("batchRemoveWatermark ...")
  861. }
  862. @IBAction func removeWatermark(_ sender: Any?) {
  863. KMPrint("removeWatermark ...")
  864. }
  865. @IBAction func templateWatermark(_ sender: Any?) {
  866. KMPrint("templateWatermark ...")
  867. }
  868. @IBAction func batchAddBackground(_ sender: Any?) {
  869. KMPrint("batchAddBackground ...")
  870. }
  871. @IBAction func batchRemoveBackground(_ sender: Any?) {
  872. KMPrint("batchRemoveBackground ...")
  873. }
  874. @IBAction func templateBackground(_ sender: Any?) {
  875. KMPrint("templateBackground ...")
  876. }
  877. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  878. KMPrint("batchAddHeaderFooter ...")
  879. }
  880. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  881. KMPrint("batchRemoveHeaderFooter ...")
  882. }
  883. @IBAction func templateHeaderFooter(_ sender: Any?) {
  884. KMPrint("templateHeaderFooter ...")
  885. }
  886. @IBAction func batchAddBates(_ sender: Any?) {
  887. KMPrint("batchAddBates ...")
  888. }
  889. @IBAction func batchRemoveBates(_ sender: Any?) {
  890. KMPrint("batchRemoveBates ...")
  891. }
  892. @IBAction func templateBates(_ sender: Any?) {
  893. KMPrint("templateBates ...")
  894. }
  895. @IBAction func togglePoster(_ sender: Any?) {
  896. KMPrint("togglePoster ...")
  897. }
  898. @IBAction func toggleMultiple(_ sender: Any?) {
  899. KMPrint("toggleMultiple ...")
  900. }
  901. @IBAction func toggleBooklet(_ sender: Any?) {
  902. KMPrint("toggleBooklet ...")
  903. }
  904. @IBAction func decryption(_ sender: Any?) {
  905. KMPrint("decryption ...")
  906. }
  907. @IBAction func readMode(_ sender: Any?) {
  908. KMPrint("readMode ...")
  909. }
  910. @IBAction func changeFormType(_ sender: Any?) {
  911. KMPrint("changeFormType ...")
  912. }
  913. @IBAction func changeSelfSignType(_ sender: Any?) {
  914. KMPrint("changeSelfSignType ...")
  915. }
  916. @IBAction func clearAllForm(_ sender: Any?) {
  917. KMPrint("clearAllForm ...")
  918. }
  919. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  920. KMPrint("thumbnailSizeScaling ...")
  921. }
  922. @IBAction func textEditAction(_ sender: Any?) {
  923. KMPrint("textEditAction ...")
  924. }
  925. @IBAction func redactAction(_ sender: Any?) {
  926. if (self.canResponseDocumentAction() == false) {
  927. return
  928. }
  929. if let document = self.browser.activeTabContents() as? KMMainDocument {
  930. if document.isHome == false {
  931. document.mainViewController?.menuItemAction_redact(sender)
  932. }
  933. }
  934. }
  935. }
  936. // MARK: - KMSystemFileMenuProtocol
  937. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  938. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  939. if (self.canResponseDocumentAction() == false) {
  940. return
  941. }
  942. if let document = self.browser.activeTabContents() as? KMMainDocument {
  943. if (document.isHome) {
  944. // document.homeViewController?.menuItemClick_mergePDF(sender)
  945. } else {
  946. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  947. }
  948. }
  949. }
  950. func menuItemClick_mergePDF(_ sender: Any) {
  951. if (self.canResponseDocumentAction() == false) {
  952. return
  953. }
  954. if let document = self.browser.activeTabContents() as? KMMainDocument {
  955. if (document.isHome) {
  956. document.homeViewController?.menuItemClick_mergePDF(sender)
  957. } else {
  958. document.mainViewController?.menuItemClick_mergePDF(sender)
  959. }
  960. }
  961. }
  962. func menuItemClick_Compress(_ sender: Any) {
  963. if (self.canResponseDocumentAction() == false) {
  964. return
  965. }
  966. if let document = self.browser.activeTabContents() as? KMMainDocument {
  967. if (document.isHome) {
  968. document.homeViewController?.menuItemClick_Compress(sender)
  969. } else {
  970. document.mainViewController?.menuItemClick_Compress(sender)
  971. }
  972. }
  973. }
  974. func menuItemAction_ConvertToWord(_ sender: Any) {
  975. if (self.canResponseDocumentAction() == false) {
  976. return
  977. }
  978. if let document = self.browser.activeTabContents() as? KMMainDocument {
  979. if (document.isHome) {
  980. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  981. } else {
  982. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  983. }
  984. }
  985. }
  986. func menuItemAction_ConvertToExcel(_ sender: Any) {
  987. if (self.canResponseDocumentAction() == false) {
  988. return
  989. }
  990. if let document = self.browser.activeTabContents() as? KMMainDocument {
  991. if (document.isHome) {
  992. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  993. } else {
  994. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  995. }
  996. }
  997. }
  998. func menuItemAction_ConvertToPPT(_ sender: Any) {
  999. if (self.canResponseDocumentAction() == false) {
  1000. return
  1001. }
  1002. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1003. if (document.isHome) {
  1004. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  1005. } else {
  1006. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  1007. }
  1008. }
  1009. }
  1010. func menuItemAction_ConvertToRTF(_ sender: Any) {
  1011. if (self.canResponseDocumentAction() == false) {
  1012. return
  1013. }
  1014. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1015. if (document.isHome) {
  1016. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  1017. } else {
  1018. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  1019. }
  1020. }
  1021. }
  1022. func menuItemAction_ConvertToHTML(_ sender: Any) {
  1023. if (self.canResponseDocumentAction() == false) {
  1024. return
  1025. }
  1026. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1027. if (document.isHome) {
  1028. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  1029. } else {
  1030. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  1031. }
  1032. }
  1033. }
  1034. func menuItemAction_ConvertToText(_ sender: Any) {
  1035. if (self.canResponseDocumentAction() == false) {
  1036. return
  1037. }
  1038. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1039. if (document.isHome) {
  1040. document.homeViewController?.menuItemAction_ConvertToText(sender)
  1041. } else {
  1042. document.mainViewController?.menuItemAction_ConvertToText(sender)
  1043. }
  1044. }
  1045. }
  1046. func menuItemAction_ConvertToCSV(_ sender: Any) {
  1047. if (self.canResponseDocumentAction() == false) {
  1048. return
  1049. }
  1050. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1051. if (document.isHome) {
  1052. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  1053. } else {
  1054. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  1055. }
  1056. }
  1057. }
  1058. func menuItemAction_ConvertToImage(_ sender: Any) {
  1059. if (self.canResponseDocumentAction() == false) {
  1060. return
  1061. }
  1062. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1063. if (document.isHome) {
  1064. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  1065. } else {
  1066. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  1067. }
  1068. }
  1069. }
  1070. func menuItemClick_SettingPassword(_ sender: Any) {
  1071. if (self.canResponseDocumentAction() == false) {
  1072. return
  1073. }
  1074. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1075. if (document.isHome) {
  1076. document.homeViewController?.menuItemClick_SettingPassword(sender)
  1077. } else {
  1078. document.mainViewController?.menuItemClick_SettingPassword(sender)
  1079. }
  1080. }
  1081. }
  1082. func menuItemClick_RemovePassword(_ sender: Any) {
  1083. if (self.canResponseDocumentAction() == false) {
  1084. return
  1085. }
  1086. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1087. document.mainViewController?.menuItemClick_RemovePassword(sender)
  1088. }
  1089. }
  1090. func menuItemAction_closeWindow(_ sender: Any) {
  1091. if (self.canResponseDocumentAction() == false) {
  1092. return
  1093. }
  1094. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1095. if (document.isHome) {
  1096. document.homeViewController?.menuItemAction_closeWindow(sender)
  1097. } else {
  1098. document.mainViewController?.menuItemAction_closeWindow(sender)
  1099. }
  1100. }
  1101. }
  1102. func menuItemAction_closeAllWindows(_ sender: Any) {
  1103. if (self.canResponseDocumentAction() == false) {
  1104. return
  1105. }
  1106. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1107. if (document.isHome) {
  1108. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  1109. } else {
  1110. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  1111. }
  1112. }
  1113. }
  1114. func menuItemAction_closeTagPage(_ sender: Any) {
  1115. if (self.canResponseDocumentAction() == false) {
  1116. return
  1117. }
  1118. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1119. document.mainViewController?.menuItemAction_closeTagPage(sender)
  1120. }
  1121. }
  1122. func menuItemAction_showInFinder(_ sender: Any) {
  1123. if (self.canResponseDocumentAction() == false) {
  1124. return
  1125. }
  1126. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1127. document.mainViewController?.menuItemAction_showInFinder(sender)
  1128. }
  1129. }
  1130. func menuItemAction_property(_ sender: Any) {
  1131. if (self.canResponseDocumentAction() == false) {
  1132. return
  1133. }
  1134. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1135. document.mainViewController?.menuItemAction_property(sender)
  1136. }
  1137. }
  1138. func menuItemAction_print(_ sender: Any) {
  1139. if (self.canResponseDocumentAction() == false) {
  1140. return
  1141. }
  1142. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1143. document.mainViewController?.menuItemAction_print(sender)
  1144. }
  1145. }
  1146. }
  1147. // MARK: - KMSystemViewMenuProtocol
  1148. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  1149. func menuItemAction_adjustWidth(_ sender: Any) {
  1150. if (self.canResponseDocumentAction() == false) {
  1151. return
  1152. }
  1153. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1154. document.mainViewController?.menuItemAction_adjustWidth(sender)
  1155. }
  1156. }
  1157. func menuItemAction_adjustPage(_ sender: Any) {
  1158. if (self.canResponseDocumentAction() == false) {
  1159. return
  1160. }
  1161. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1162. document.mainViewController?.menuItemAction_adjustPage(sender)
  1163. }
  1164. }
  1165. func menuItemAction_size(_ sender: Any) {
  1166. if (self.canResponseDocumentAction() == false) {
  1167. return
  1168. }
  1169. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1170. document.mainViewController?.menuItemAction_size(sender)
  1171. }
  1172. }
  1173. func menuItemAction_zoomOut(_ sender: Any) {
  1174. if (self.canResponseDocumentAction() == false) {
  1175. return
  1176. }
  1177. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1178. document.mainViewController?.menuItemAction_zoomOut(sender)
  1179. }
  1180. }
  1181. func menuItemAction_zoomIn(_ sender: Any) {
  1182. if (self.canResponseDocumentAction() == false) {
  1183. return
  1184. }
  1185. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1186. document.mainViewController?.menuItemAction_zoomIn(sender)
  1187. }
  1188. }
  1189. func menuItemAction_singlePage(_ sender: Any) {
  1190. if (self.canResponseDocumentAction() == false) {
  1191. return
  1192. }
  1193. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1194. document.mainViewController?.menuItemAction_singlePage(sender)
  1195. }
  1196. }
  1197. func menuItemAction_singlePageContinue(_ sender: Any) {
  1198. if (self.canResponseDocumentAction() == false) {
  1199. return
  1200. }
  1201. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1202. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1203. }
  1204. }
  1205. func menuItemAction_doublePage(_ sender: Any) {
  1206. if (self.canResponseDocumentAction() == false) {
  1207. return
  1208. }
  1209. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1210. document.mainViewController?.menuItemAction_doublePage(sender)
  1211. }
  1212. }
  1213. func menuItemAction_doublePageContinue(_ sender: Any) {
  1214. if (self.canResponseDocumentAction() == false) {
  1215. return
  1216. }
  1217. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1218. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1219. }
  1220. }
  1221. func menuItemAction_bookMode(_ sender: Any) {
  1222. if (self.canResponseDocumentAction() == false) {
  1223. return
  1224. }
  1225. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1226. document.mainViewController?.menuItemAction_bookMode(sender)
  1227. }
  1228. }
  1229. func menuItemAction_readMode(_ sender: Any) {
  1230. if (self.canResponseDocumentAction() == false) {
  1231. return
  1232. }
  1233. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1234. document.mainViewController?.menuItemAction_readMode(sender)
  1235. }
  1236. }
  1237. func menuItemAction_showSplitPage(_ sender: Any) {
  1238. if (self.canResponseDocumentAction() == false) {
  1239. return
  1240. }
  1241. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1242. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1243. }
  1244. }
  1245. func menuItemAction_rotateLeft(_ sender: Any) {
  1246. if (self.canResponseDocumentAction() == false) {
  1247. return
  1248. }
  1249. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1250. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1251. }
  1252. }
  1253. func menuItemAction_rotateRight(_ sender: Any) {
  1254. if (self.canResponseDocumentAction() == false) {
  1255. return
  1256. }
  1257. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1258. document.mainViewController?.menuItemAction_rotateRight(sender)
  1259. }
  1260. }
  1261. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1262. if (self.canResponseDocumentAction() == false) {
  1263. return
  1264. }
  1265. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1266. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1267. }
  1268. }
  1269. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1270. if (self.canResponseDocumentAction() == false) {
  1271. return
  1272. }
  1273. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1274. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1275. }
  1276. }
  1277. func menuItemAction_view_readMode(_ sender: Any) {
  1278. if (self.canResponseDocumentAction() == false) {
  1279. return
  1280. }
  1281. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1282. document.mainViewController?.menuItemAction_view_readMode(sender)
  1283. }
  1284. }
  1285. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1286. if (self.canResponseDocumentAction() == false) {
  1287. return
  1288. }
  1289. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1290. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1291. }
  1292. }
  1293. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1294. if (self.canResponseDocumentAction() == false) {
  1295. return
  1296. }
  1297. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1298. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1299. }
  1300. }
  1301. func menuItemAction_thumai(_ sender: Any) {
  1302. if (self.canResponseDocumentAction() == false) {
  1303. return
  1304. }
  1305. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1306. document.mainViewController?.menuItemAction_thumai(sender)
  1307. }
  1308. }
  1309. func menuItemAction_outline(_ sender: Any) {
  1310. if (self.canResponseDocumentAction() == false) {
  1311. return
  1312. }
  1313. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1314. document.mainViewController?.menuItemAction_outline(sender)
  1315. }
  1316. }
  1317. func menuItemAction_bookmark(_ sender: Any) {
  1318. if (self.canResponseDocumentAction() == false) {
  1319. return
  1320. }
  1321. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1322. document.mainViewController?.menuItemAction_bookmark(sender)
  1323. }
  1324. }
  1325. func menuItemAction_annotation(_ sender: Any) {
  1326. if (self.canResponseDocumentAction() == false) {
  1327. return
  1328. }
  1329. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1330. document.mainViewController?.menuItemAction_annotation(sender)
  1331. }
  1332. }
  1333. func menuItemAction_search(_ sender: Any) {
  1334. if (self.canResponseDocumentAction() == false) {
  1335. return
  1336. }
  1337. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1338. document.mainViewController?.menuItemAction_search(sender)
  1339. }
  1340. }
  1341. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1342. if (self.canResponseDocumentAction() == false) {
  1343. return
  1344. }
  1345. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1346. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1347. }
  1348. }
  1349. }
  1350. // MARK: - KMSystemEditMenuProtocol
  1351. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1352. func menuItemAction_find(_ sender: Any) {
  1353. if (self.canResponseDocumentAction() == false) {
  1354. return
  1355. }
  1356. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1357. document.mainViewController?.menuItemAction_find(sender)
  1358. }
  1359. }
  1360. }
  1361. // MARK: - Annotation Menu
  1362. extension KMBrowserWindowController {
  1363. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1364. if (self.canResponseDocumentAction() == false) {
  1365. return
  1366. }
  1367. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1368. document.mainViewController?.menuItemAction_highlight(sender)
  1369. }
  1370. }
  1371. @IBAction func menuItemAction_underline(_ sender: Any) {
  1372. if (self.canResponseDocumentAction() == false) {
  1373. return
  1374. }
  1375. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1376. document.mainViewController?.menuItemAction_underline(sender)
  1377. }
  1378. }
  1379. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1380. if (self.canResponseDocumentAction() == false) {
  1381. return
  1382. }
  1383. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1384. document.mainViewController?.menuItemAction_deleteLine(sender)
  1385. }
  1386. }
  1387. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1388. if (self.canResponseDocumentAction() == false) {
  1389. return
  1390. }
  1391. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1392. document.mainViewController?.menuItemAction_freehand(sender)
  1393. }
  1394. }
  1395. @IBAction func menuItemAction_text(_ sender: Any) {
  1396. if (self.canResponseDocumentAction() == false) {
  1397. return
  1398. }
  1399. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1400. document.mainViewController?.menuItemAction_text(sender)
  1401. }
  1402. }
  1403. @IBAction func menuItemAction_note(_ sender: Any) {
  1404. if (self.canResponseDocumentAction() == false) {
  1405. return
  1406. }
  1407. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1408. document.mainViewController?.menuItemAction_note(sender)
  1409. }
  1410. }
  1411. @IBAction func menuItemAction_squre(_ sender: Any) {
  1412. if (self.canResponseDocumentAction() == false) {
  1413. return
  1414. }
  1415. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1416. document.mainViewController?.menuItemAction_squre(sender)
  1417. }
  1418. }
  1419. @IBAction func menuItemAction_circle(_ sender: Any) {
  1420. if (self.canResponseDocumentAction() == false) {
  1421. return
  1422. }
  1423. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1424. document.mainViewController?.menuItemAction_circle(sender)
  1425. }
  1426. }
  1427. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1428. if (self.canResponseDocumentAction() == false) {
  1429. return
  1430. }
  1431. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1432. document.mainViewController?.menuItemAction_arrow(sender)
  1433. }
  1434. }
  1435. @IBAction func menuItemAction_line(_ sender: Any) {
  1436. if (self.canResponseDocumentAction() == false) {
  1437. return
  1438. }
  1439. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1440. document.mainViewController?.menuItemAction_line(sender)
  1441. }
  1442. }
  1443. // link
  1444. @IBAction func menuItemAction_link(_ sender: Any) {
  1445. if (self.canResponseDocumentAction() == false) {
  1446. return
  1447. }
  1448. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1449. document.mainViewController?.menuItemAction_link(sender)
  1450. }
  1451. }
  1452. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1453. if (self.canResponseDocumentAction() == false) {
  1454. return
  1455. }
  1456. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1457. document.mainViewController?.menuItemAction_linkPage(sender)
  1458. }
  1459. }
  1460. // stamp
  1461. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1462. if (self.canResponseDocumentAction() == false) {
  1463. return
  1464. }
  1465. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1466. document.mainViewController?.menuItemAction_stamp(sender)
  1467. }
  1468. }
  1469. @IBAction func menuItemAction_signure(_ sender: Any) {
  1470. if (self.canResponseDocumentAction() == false) {
  1471. return
  1472. }
  1473. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1474. document.mainViewController?.menuItemAction_signure(sender)
  1475. }
  1476. }
  1477. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1478. if (self.canResponseDocumentAction() == false) {
  1479. return
  1480. }
  1481. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1482. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1483. }
  1484. }
  1485. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1486. if (self.canResponseDocumentAction() == false) {
  1487. return
  1488. }
  1489. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1490. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1491. }
  1492. }
  1493. }
  1494. // MARK: - KMSystemGotoMenuProtocol
  1495. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1496. func menuItemAction_nextPage(_ sender: Any) {
  1497. if (self.canResponseDocumentAction() == false) {
  1498. return
  1499. }
  1500. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1501. document.mainViewController?.menuItemAction_nextPage(sender)
  1502. }
  1503. }
  1504. func menuItemAction_forwardPage(_ sender: Any) {
  1505. if (self.canResponseDocumentAction() == false) {
  1506. return
  1507. }
  1508. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1509. document.mainViewController?.menuItemAction_forwardPage(sender)
  1510. }
  1511. }
  1512. func menuItemAction_firstPage(_ sender: Any) {
  1513. if (self.canResponseDocumentAction() == false) {
  1514. return
  1515. }
  1516. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1517. document.mainViewController?.menuItemAction_firstPage(sender)
  1518. }
  1519. }
  1520. func menuItemAction_lastPage(_ sender: Any) {
  1521. if (self.canResponseDocumentAction() == false) {
  1522. return
  1523. }
  1524. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1525. document.mainViewController?.menuItemAction_lastPage(sender)
  1526. }
  1527. }
  1528. func menuItemAction_forward(_ sender: Any) {
  1529. if (self.canResponseDocumentAction() == false) {
  1530. return
  1531. }
  1532. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1533. document.mainViewController?.menuItemAction_forward(sender)
  1534. }
  1535. }
  1536. func menuItemAction_goback(_ sender: Any) {
  1537. if (self.canResponseDocumentAction() == false) {
  1538. return
  1539. }
  1540. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1541. document.mainViewController?.menuItemAction_goback(sender)
  1542. }
  1543. }
  1544. func menuItemAction_gotoPage(_ sender: Any) {
  1545. if (self.canResponseDocumentAction() == false) {
  1546. return
  1547. }
  1548. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1549. document.mainViewController?.menuItemAction_gotoPage(sender)
  1550. }
  1551. }
  1552. }
  1553. // MARK: - KMSystemToolMenuProtocol
  1554. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1555. func menuItemAction_scrolTool(_ sender: Any) {
  1556. if (self.canResponseDocumentAction() == false) {
  1557. return
  1558. }
  1559. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1560. document.mainViewController?.menuItemAction_scrolTool(sender)
  1561. }
  1562. }
  1563. func menuItemAction_zoomOutTool(_ sender: Any) {
  1564. if (self.canResponseDocumentAction() == false) {
  1565. return
  1566. }
  1567. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1568. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1569. }
  1570. }
  1571. func menuItemAction_selectTool(_ sender: Any) {
  1572. if (self.canResponseDocumentAction() == false) {
  1573. return
  1574. }
  1575. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1576. document.mainViewController?.menuItemAction_selectTool(sender)
  1577. }
  1578. }
  1579. @IBAction func compression(_ sender: Any?) {
  1580. if (self.canResponseDocumentAction() == false) {
  1581. return
  1582. }
  1583. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1584. if (document.isHome) {
  1585. } else {
  1586. document.mainViewController?.compression(sender)
  1587. }
  1588. }
  1589. }
  1590. }
  1591. // MARK: - KMSystemWindowMenuRrotocol
  1592. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  1593. func menuItemAction_showForwardTagPage(_ sender: Any) {
  1594. if (self.canResponseDocumentAction() == false) {
  1595. return
  1596. }
  1597. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1598. if (document.isHome) {
  1599. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  1600. } else {
  1601. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  1602. }
  1603. }
  1604. }
  1605. func menuItemAction_showNextTagPage(_ sender: Any) {
  1606. if (self.canResponseDocumentAction() == false) {
  1607. return
  1608. }
  1609. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1610. if (document.isHome) {
  1611. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  1612. } else {
  1613. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  1614. }
  1615. }
  1616. }
  1617. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1618. if (self.canResponseDocumentAction() == false) {
  1619. return
  1620. }
  1621. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1622. if (document.isHome) {
  1623. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1624. } else {
  1625. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1626. }
  1627. }
  1628. }
  1629. func menuItemAction_mergeAllWindow(_ sender: Any) {
  1630. if (self.canResponseDocumentAction() == false) {
  1631. return
  1632. }
  1633. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1634. if (document.isHome) {
  1635. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  1636. } else {
  1637. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  1638. }
  1639. }
  1640. }
  1641. }
  1642. // MARK: - Analytics (埋点)
  1643. extension KMBrowserWindowController {
  1644. func trackEvent_upgrade() -> Void {
  1645. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  1646. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  1647. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  1648. }
  1649. }