KMBrowserWindowController.swift 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522
  1. //
  2. // KMBrowserWindowController.swift
  3. // PDF Reader Pro
  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. var rightMessageVC: KMVerificationMessageViewController!
  17. var rightToolbarItemView: NSView!
  18. private var homeVC: KMHomeViewController?
  19. override func windowDidLoad() {
  20. super.windowDidLoad()
  21. NSImage.makeTextAlignImages()
  22. window?.backgroundColor = NSColor.km_init(hex: "#DFE1E5")
  23. // window?.setFrameAutosaveName("")
  24. rightTabStripView_.delete = self
  25. homeRightTabStripView_.delete = self
  26. rightTabStripView_.updateView()
  27. fileUploadPanel.delete = self
  28. homeRightTabStripView_.homeRightSearchField.delegate = self
  29. isMultiTabMode = true
  30. addObserverForAppearanceChange()
  31. refreshToolBar(homeToolState: .Home)
  32. NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
  33. NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
  34. // if (KMWelcomeWindowController.welcomeHasShow() == false) {
  35. // //AI 版本禁掉首次开启帮助文档
  36. //// KMTools.openQuickStartStudy()
  37. //
  38. // DispatchQueue.main.async {
  39. // let welcome = KMWelcomeWindowController()
  40. // self.km_beginSheet(windowC: welcome)
  41. // welcome.itemClick = { [weak self] idx, param in
  42. // if (idx == 1) { // 关闭
  43. // self?.km_endSheet()
  44. // } else if (idx == 2) { // 以后提醒
  45. // self?.km_endSheet()
  46. // } else if (idx == 3) { // 注册
  47. // self?.km_endSheet()
  48. //
  49. // guard let window_ = self?.window else {
  50. // return
  51. // }
  52. // _ = KMLoginWindowController.show(window: window_, .Batch, .register)
  53. // }
  54. // }
  55. // }
  56. // }
  57. updateViewColor()
  58. var tabbingMode = NSWindow.TabbingMode.automatic
  59. let openDocumentType = KMPreference.shared.openDocumentType
  60. if openDocumentType == .inSameWindow {
  61. tabbingMode = .preferred
  62. } else if openDocumentType == .newWindow {
  63. tabbingMode = .disallowed
  64. }
  65. #if VERSION_FREE
  66. if IAPProductsManager.default().isAvailableAllFunction() == false {
  67. tabbingMode = .disallowed
  68. }
  69. #endif
  70. self.window?.tabbingMode = tabbingMode
  71. }
  72. @objc func closeAction() {
  73. self.window?.performClose(nil)
  74. }
  75. override func windowShouldClose(_ sender: NSWindow) -> Bool {
  76. if self.browser.tabStripModel.count() > 1 {
  77. self.browser.windowDidBeginToClose()
  78. return false
  79. }
  80. return true
  81. }
  82. override func windowWillClose(_ notification: Notification) {
  83. iRate.sharedInstance().appLaunched()
  84. }
  85. override func layoutSubviews() {
  86. super.layoutSubviews()
  87. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
  88. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  89. }
  90. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
  91. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  92. }
  93. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
  94. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  95. }
  96. }
  97. // MARK: Dark&Light
  98. func addObserverForAppearanceChange() -> Void {
  99. window?.contentView!.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
  100. }
  101. func removeObserverForAppearanceChange() -> Void {
  102. window?.contentView!.removeObserver(self, forKeyPath: "effectiveAppearance")
  103. }
  104. override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  105. if keyPath == "effectiveAppearance" {
  106. updateViewColor()
  107. }
  108. }
  109. override func updateViewColor() {
  110. super.updateViewColor()
  111. window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
  112. }
  113. // MARK: Public Methods
  114. func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
  115. modeType = toolState
  116. let document = browser.activeTabContents()
  117. if document != nil {
  118. if document!.isHome {
  119. homeRightTabStripView_.isHidden = modeType == .Home
  120. } else {
  121. self.homeRightStripView.isHidden = true
  122. }
  123. } else {
  124. self.homeRightStripView.isHidden = true
  125. }
  126. homeRightTabStripView_.homeRefreshButton.isEnabled = true
  127. homeRightTabStripView_.homeUploadButton.isEnabled = true
  128. filterType = 0
  129. rightTabStripView_.sortPopUpButton.removeAllItems()
  130. rightTabStripView_.filterPopUpButton.removeAllItems()
  131. rightTabStripView_.updateView()
  132. }
  133. override var hasToolbar: Bool {
  134. get {
  135. return false
  136. }
  137. }
  138. var km_browser: KMBrowser? {
  139. get {
  140. return self.browser as? KMBrowser
  141. }
  142. }
  143. // MARK: Private Methods
  144. func openDocumentWindow() -> Void {
  145. // let panel = NSOpenPanel()
  146. // panel.allowsMultipleSelection = false
  147. // panel.allowedFileTypes = ["pdf"]
  148. // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  149. // if response == .OK {
  150. // let openPath = panel.url?.path
  151. // let selectDocument = self.selectTabContents(path: openPath!)
  152. // if selectDocument != nil {
  153. // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
  154. // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
  155. // return
  156. // }
  157. // if !panel.url!.path.isPDFValid() {
  158. // let alert = NSAlert()
  159. // alert.alertStyle = .critical
  160. // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  161. // alert.runModal()
  162. // return
  163. // }
  164. // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
  165. // print("openDocumentWindow")
  166. // }
  167. // }
  168. // }
  169. // MARK TODO: + 号开启
  170. // self.browser.addHomeTabContents()
  171. self.tabStripView?.addTabButton?.layer?.backgroundColor = .clear
  172. self.km_browser?.addNewTabContents()
  173. }
  174. // override func openDocument(_ sender: Any!) {
  175. // self.openDocumentWindow()
  176. // }
  177. func selectTabContents(path filePath: String) -> KMMainDocument? {
  178. let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
  179. var selectDocument: KMMainDocument?
  180. if document != nil {
  181. if document!.isKind(of: KMMainDocument.self) {
  182. selectDocument = document as! KMMainDocument
  183. }
  184. }
  185. return selectDocument
  186. }
  187. // MARK: Getter
  188. override var rightStripView: NSView! {
  189. get {
  190. if self.rightToolbarItemView == nil {
  191. self.rightToolbarItemView = NSView.init(frame: CGRectMake(0, 0, 184, 40))
  192. self.rightToolbarItemView.wantsLayer = true
  193. if self.rightMessageVC == nil {
  194. self.rightMessageVC = KMVerificationMessageViewController.init()
  195. }
  196. self.rightMessageVC.frameUpdateHandle = { [weak self] rect in
  197. var superRect = self?.rightToolbarItemView?.frame;
  198. superRect?.size.width = (self?.rightMessageVC.view.frame.size.width)! + 8
  199. self?.rightToolbarItemView.frame = superRect!;
  200. }
  201. var rect = self.rightMessageVC.view.frame;
  202. rect.origin.x = CGRectGetWidth(self.rightToolbarItemView.frame) - rect.size.width - 8
  203. rect.origin.y = (CGRectGetHeight(self.rightToolbarItemView.frame) - rect.size.height)/2
  204. self.rightMessageVC.view.frame = rect
  205. self.rightMessageVC.view.autoresizingMask = [.minYMargin, .maxXMargin, .maxYMargin]
  206. self.rightToolbarItemView.addSubview(self.rightMessageVC.view)
  207. }
  208. return self.rightToolbarItemView
  209. }
  210. }
  211. override var homeRightStripView: NSView! {
  212. get {
  213. return homeRightTabStripView_
  214. }
  215. }
  216. // MARK: Button Action
  217. func commandDispatch(_ sender: Any) -> Void {
  218. openDocumentWindow()
  219. }
  220. func closeAllTabs(_ sender: Any) -> Void {
  221. if self.browser != nil {
  222. self.browser.closeAllTabs()
  223. }
  224. }
  225. func openNewWindow(_ sender: Any) -> Void {
  226. if let noti = sender as? NSNotification, noti.object is CTTabController {
  227. if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
  228. return
  229. }
  230. }
  231. if self.browser != nil {
  232. let activeInt = self.browser.activeTabIndex()
  233. let activeTab = self.browser.activeTabContents()
  234. self.browser.closeTab(at: activeInt, makeHistory: false)
  235. let browser: KMBrowser = KMBrowser.init()
  236. browser.windowController = KMBrowserWindowController.init(browser: browser)
  237. browser.addHomeTabContents()
  238. browser.windowController.showWindow(self)
  239. // browser.add(activeTab, inForeground: false)
  240. // browser.selectTab(at: 1)
  241. if activeTab?.fileURL == nil {
  242. return
  243. }
  244. let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
  245. let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
  246. KMMainDocument().tryToUnlockDocument(pdfDoc!)
  247. if ((pdfDoc?.isLocked)! == true) {
  248. KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
  249. if result == .cancel { /// 关闭
  250. return
  251. }
  252. /// 解密成功
  253. var selectDocument: KMMainDocument? = nil
  254. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  255. selectDocument = (document as! KMMainDocument)
  256. }
  257. if selectDocument != nil {
  258. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  259. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  260. if (selectDocument?.browser.window.isVisible)! as Bool {
  261. selectDocument?.browser.window.orderFront(nil)
  262. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  263. selectDocument?.browser.window.orderFront(nil)
  264. }
  265. } else {
  266. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, _, error in
  267. if (error == nil) {
  268. (document as! KMMainDocument).mainViewController?.password = password
  269. }
  270. }
  271. }
  272. }
  273. } else {
  274. var selectDocument: KMMainDocument? = nil
  275. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  276. selectDocument = (document as! KMMainDocument)
  277. }
  278. if selectDocument != nil {
  279. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  280. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  281. if (selectDocument?.browser.window.isVisible)! as Bool {
  282. selectDocument?.browser.window.orderFront(nil)
  283. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  284. selectDocument?.browser.window.orderFront(nil)
  285. }
  286. } else {
  287. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
  288. }
  289. }
  290. }
  291. }
  292. }
  293. func canMergeAllWindow() -> Bool {
  294. return self.fetchBrowserWindowControllers().count > 0
  295. }
  296. fileprivate func fetchBrowserWindowControllers() -> [KMBrowserWindowController] {
  297. var windowArray: [KMBrowserWindowController] = []
  298. for window in NSApp.windows {
  299. guard let windowController = window.windowController, windowController is KMBrowserWindowController else {
  300. continue
  301. }
  302. if let _tabScripC = (windowController as? KMBrowserWindowController)?.tabStripController, _tabScripC.viewsCount() <= 1 {
  303. continue
  304. }
  305. if (window.isVisible && (windowController.isEqual(to: self) == false)) {
  306. windowArray.append(windowController as! KMBrowserWindowController)
  307. }
  308. }
  309. return windowArray
  310. }
  311. func mergeAllWindow(_ sender: Any) {
  312. let windowArray = self.fetchBrowserWindowControllers()
  313. if (windowArray.count <= 0) {
  314. return
  315. }
  316. for windowC in windowArray {
  317. // 拼接窗口 [拼接窗口里的标签,除了home标签]
  318. self.append(windowC, toTabView: NSView())
  319. if let browser = windowC.browser {
  320. if (browser.tabCount() <= 1 && browser.activeTabContents().isHome) {
  321. windowC.close()
  322. }
  323. }
  324. }
  325. }
  326. override func tabDidSelect(_ notification: Notification!) {
  327. super.tabDidSelect(notification)
  328. if let _userInfo = notification.userInfo, let _newContents = _userInfo[CTTabNewContentsUserInfoKey] as? KMMainDocument {
  329. _newContents.addWindowController(self)
  330. }
  331. }
  332. override func layoutTabContentArea(_ frame: NSRect) {
  333. super.layoutTabContentArea(frame)
  334. self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
  335. }
  336. override func openDocument(_ sender: Any!) {
  337. guard let _window = self.window else {
  338. return
  339. }
  340. NSOpenPanel.km_open_pdf_multi_success(_window, panel: nil) { urls in
  341. for url in urls {
  342. NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
  343. }
  344. }
  345. }
  346. }
  347. }
  348. // MARK: - KMToolbarRightViewDelegate
  349. extension KMBrowserWindowController: KMToolbarRightViewDelegate {
  350. func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
  351. self.trackEvent_upgrade()
  352. // KMComparativeTableViewController.show(window: self.window!, .upgrade)
  353. DispatchQueue.main.async {
  354. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  355. }
  356. }
  357. func userInfoButtonAction(_ sender: NSButton) {
  358. if KMLightMemberManager.manager.isLogin() {
  359. Task { @MainActor in
  360. if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
  361. KMAccountInfoWindowController.show(window: self.window!)
  362. } else {
  363. KMLoginWindowController.show(window: self.window!)
  364. }
  365. }
  366. } else {
  367. KMLoginWindowController.show(window: self.window!)
  368. }
  369. }
  370. func homeRefreshButtonAction(_ sender: NSButton?) {
  371. self.layoutSubviews()
  372. }
  373. func homeUploadButtonAction(_ sender: NSButton) {
  374. }
  375. func homeMenuSortAction(_ sender: NSPopUpButton) {
  376. }
  377. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  378. }
  379. }
  380. // MARK: - KMUploadFileDelegate
  381. extension KMBrowserWindowController: KMUploadFileDelegate {
  382. // override func cancelOperation(_ sender: Any?) {
  383. //
  384. // }
  385. }
  386. // MARK: - NSSearchFieldDelegate
  387. extension KMBrowserWindowController: NSSearchFieldDelegate {
  388. func controlTextDidChange(_ obj: Notification) {
  389. }
  390. func controlTextDidEndEditing(_ obj: Notification) {
  391. }
  392. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  393. var result = false
  394. return result
  395. }
  396. }
  397. // MARK: -
  398. // MARK: Menu Actions
  399. extension KMBrowserWindowController {
  400. func canResponseDocumentAction() -> Bool {
  401. if (self.browser == nil) {
  402. return false
  403. }
  404. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  405. return false
  406. }
  407. return true
  408. }
  409. }
  410. // MARK: -
  411. // MARK: File Menu
  412. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  413. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  414. if (self.browser == nil) {
  415. return false
  416. }
  417. guard let action = menuItem.action else {
  418. return false
  419. }
  420. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  421. return false
  422. }
  423. if (KMSystemMenu.isFileSelector(sel: action)) {
  424. if (document.isHome) {
  425. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  426. menuItem.action == KMSystemMenu.File.propertySelector ||
  427. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  428. menuItem.action == KMSystemMenu.File.printSelector ||
  429. menuItem.action == KMSystemMenu.File.saveAsFlattenedPDFSelector) {
  430. return false
  431. }
  432. return document.homeViewController!.validateMenuItem(menuItem)
  433. } else {
  434. return document.mainViewController!.validateMenuItem(menuItem)
  435. }
  436. }
  437. if (KMSystemMenu.isEditSelector(sel: action)) {
  438. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  439. }
  440. if (KMSystemMenu.isViewSelector(sel: action)) {
  441. if action == KMSystemMenu.Edit.changeFontSelector {
  442. return true
  443. } else {
  444. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  445. }
  446. }
  447. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  448. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  449. }
  450. if (KMSystemMenu.isPDFSelector(sel: action)) {
  451. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  452. }
  453. if (KMSystemMenu.isGotoSelector(sel: action)) {
  454. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  455. }
  456. if (KMSystemMenu.isToolSelector(sel: action)) {
  457. if action == KMSystemMenu.Tool.orderFrontNotesPanelSelector {
  458. if KMNotesPanelController.sharedControllerExists() {
  459. if let data = KMNotesPanelController.shared.window?.isVisible, data {
  460. menuItem.title = NSLocalizedString("Hide Note Type", comment: "Menu item title")
  461. } else {
  462. menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
  463. }
  464. } else {
  465. menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
  466. }
  467. return true
  468. } else {
  469. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  470. }
  471. }
  472. if (KMSystemMenu.isWindowSelector(sel: action)) {
  473. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  474. }
  475. if action == #selector(redactAction) {
  476. return document.isHome ? false : true
  477. }
  478. return true
  479. }
  480. }
  481. extension KMBrowserWindowController {
  482. @IBAction func menuItemAction_openFile(_ sender: Any) {
  483. super.openDocument(sender)
  484. }
  485. @IBAction func importFromFile(_ sender: Any) {
  486. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  487. if (document.isHome) {
  488. document.homeViewController?.importFromFile(sender)
  489. } else {
  490. self.homeVC = KMHomeViewController()
  491. self.homeVC?.importFromFile(sender)
  492. }
  493. }
  494. @IBAction func openBlankPage(_ sender: Any) {
  495. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  496. if (document.isHome) {
  497. document.homeViewController?.openBlankPage()
  498. } else {
  499. self.homeVC = KMHomeViewController()
  500. self.homeVC?.openBlankPage()
  501. }
  502. }
  503. @IBAction func importFromScanner(_ sender: Any) {
  504. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  505. if (document.isHome) {
  506. document.homeViewController?.importFromScanner()
  507. } else {
  508. self.homeVC = KMHomeViewController()
  509. self.homeVC?.importFromScanner()
  510. }
  511. }
  512. @IBAction func menuItemAction_newTab(_ sender: Any) {
  513. self.openDocumentWindow()
  514. }
  515. @IBAction func pasteAsPlainText(_ sender: Any?) {
  516. KMPrint("pasteAsPlainText")
  517. }
  518. @IBAction func deselectAll(_ sender: Any?) {
  519. KMPrint("deselectAll")
  520. }
  521. @IBAction func searchPDF(_ sender: Any?) {
  522. KMPrint("searchPDF")
  523. if let document = self.browser.activeTabContents() as? KMMainDocument {
  524. if (document.isHome) {
  525. // document.homeViewController?.menuItemClick_mergePDF(sender)
  526. } else {
  527. document.mainViewController?.leftSideViewController.showSearchMode("")
  528. }
  529. }
  530. }
  531. @IBAction func notesLink(_ sender: Any?) {
  532. KMPrint("notesLink")
  533. }
  534. @IBAction func notesStamp(_ sender: Any?) {
  535. KMPrint("notesStamp")
  536. }
  537. @IBAction func table(_ sender: Any?) {
  538. KMPrint("table ...")
  539. }
  540. @IBAction func image(_ sender: Any?) {
  541. KMPrint("image ...")
  542. }
  543. @IBAction func addForm(_ sender: Any?) {
  544. KMPrint("addForm ...")
  545. }
  546. @IBAction func editNote(_ sender: Any?) {
  547. KMPrint("editNote ...")
  548. }
  549. @IBAction func changeColor(_ sender: Any?) {
  550. KMPrint("changeColor ...")
  551. }
  552. @IBAction func changeAttributes(_ sender: Any?) {
  553. KMPrint("changeAttributes ...")
  554. }
  555. @IBAction func alignLeft(_ sender: Any?) {
  556. KMPrint("alignLeft ...")
  557. }
  558. @IBAction func alignRight(_ sender: Any?) {
  559. KMPrint("alignRight ...")
  560. }
  561. @IBAction func alignCenter(_ sender: Any?) {
  562. KMPrint("alignCenter ...")
  563. }
  564. @IBAction func createNewNote(_ sender: Any?) {
  565. KMPrint("createNewNote ...")
  566. }
  567. @IBAction func toggleHideNotes(_ sender: Any?) {
  568. KMPrint("toggleHideNotes ...")
  569. }
  570. @IBAction func changeDisplaySinglePages(_ sender: Any?) {
  571. KMPrint("changeDisplaySinglePages ...")
  572. }
  573. @IBAction func changeDisplayContinuous(_ sender: Any?) {
  574. KMPrint("changeDisplayContinuous ...")
  575. }
  576. @IBAction func doGoToNextPage(_ sender: Any?) {
  577. KMPrint("doGoToNextPage ...")
  578. }
  579. @IBAction func doGoToPreviousPage(_ sender: Any?) {
  580. KMPrint("doGoToPreviousPage ...")
  581. }
  582. @IBAction func doGoToFirstPage(_ sender: Any?) {
  583. KMPrint("doGoToFirstPage ...")
  584. }
  585. @IBAction func doGoToLastPage(_ sender: Any?) {
  586. KMPrint("doGoToLastPage ...")
  587. }
  588. @IBAction func allGoToNextPage(_ sender: Any?) {
  589. KMPrint("allGoToNextPage ...")
  590. }
  591. @IBAction func allGoToPreviousPage(_ sender: Any?) {
  592. KMPrint("allGoToPreviousPage ...")
  593. }
  594. @IBAction func allGoToFirstPage(_ sender: Any?) {
  595. KMPrint("allGoToFirstPage ...")
  596. }
  597. @IBAction func allGoToLastPage(_ sender: Any?) {
  598. KMPrint("allGoToLastPage ...")
  599. }
  600. @IBAction func doGoToPage(_ sender: Any?) {
  601. KMPrint("doGoToPage ...")
  602. }
  603. @IBAction func doGoBack(_ sender: Any?) {
  604. KMPrint("doGoBack ...")
  605. }
  606. @IBAction func doGoForward(_ sender: Any?) {
  607. KMPrint("doGoForward ...")
  608. }
  609. @IBAction func doZoomToPhysicalSize(_ sender: Any?) {
  610. KMPrint("doZoomToPhysicalSize ...")
  611. }
  612. @IBAction func alternateZoomToFit(_ sender: Any?) {
  613. KMPrint("alternateZoomToFit ...")
  614. }
  615. @IBAction func doZoomToSelection(_ sender: Any?) {
  616. KMPrint("doZoomToSelection ...")
  617. }
  618. @IBAction func doAutoScale(_ sender: Any?) {
  619. KMPrint("doAutoScale ...")
  620. }
  621. // @IBAction func delete(_ sender: Any?) {
  622. // KMPrint("delete ...")
  623. // }
  624. // @IBAction func paste(_ sender: Any?) {
  625. // KMPrint("paste ...")
  626. // }
  627. @IBAction func alternatePaste(_ sender: Any?) {
  628. KMPrint("alternatePaste ...")
  629. }
  630. @IBAction func copy(_ sender: Any?) {
  631. KMPrint("copy ...")
  632. }
  633. @IBAction func cut(_ sender: Any?) {
  634. KMPrint("cut ...")
  635. }
  636. @IBAction func toggleFullscreen(_ sender: Any?) {
  637. KMPrint("toggleFullscreen ...")
  638. }
  639. @IBAction func toggleRightSidePane(_ sender: Any?) {
  640. KMPrint("toggleRightSidePane ...")
  641. }
  642. @IBAction func performFit(_ sender: Any?) {
  643. KMPrint("performFit ...")
  644. }
  645. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  646. KMPrint("changeRightSidePaneState ...")
  647. }
  648. @IBAction func changeFindPaneState(_ sender: Any?) {
  649. KMPrint("changeFindPaneState ...")
  650. }
  651. @IBAction func toggleSplitPDF(_ sender: Any?) {
  652. KMPrint("toggleSplitPDF ...")
  653. }
  654. @IBAction func search(_ sender: Any?) {
  655. KMPrint("search ...")
  656. }
  657. @IBAction func searchNotes(_ sender: Any?) {
  658. KMPrint("searchNotes ...")
  659. }
  660. @IBAction func password(_ sender: Any?) {
  661. KMPrint("password ...")
  662. }
  663. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  664. KMPrint("toggleCaseInsensitiveSearch ...")
  665. }
  666. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  667. KMPrint("toggleWholeWordSearch ...")
  668. }
  669. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  670. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  671. }
  672. @IBAction func performFindPanelAction(_ sender: Any?) {
  673. KMPrint("performFindPanelAction ...")
  674. if let document = self.browser.activeTabContents() as? KMMainDocument {
  675. if document.isHome == false {
  676. document.mainViewController?.toolbarController.showFindBar()
  677. }
  678. }
  679. }
  680. @IBAction func scrollUp(_ sender: Any?) {
  681. KMPrint("scrollUp ...")
  682. }
  683. @IBAction func scrollDown(_ sender: Any?) {
  684. KMPrint("scrollDown ...")
  685. }
  686. @IBAction func scrollRight(_ sender: Any?) {
  687. KMPrint("scrollRight ...")
  688. }
  689. @IBAction func scrollLeft(_ sender: Any?) {
  690. KMPrint("scrollLeft ...")
  691. }
  692. @IBAction func selectSelectedNote(_ sender: Any?) {
  693. KMPrint("selectSelectedNote ...")
  694. }
  695. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  696. KMPrint("goToSelectedOutlineItem ...")
  697. }
  698. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  699. KMPrint("goToSelectedFindResults ...")
  700. }
  701. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  702. KMPrint("toggleSelectedSnapshots ...")
  703. }
  704. @IBAction func selfSignProfile(_ sender: Any?) {
  705. KMPrint("selfSignProfile ...")
  706. }
  707. @IBAction func link(_ sender: Any?) {
  708. KMPrint("link ...")
  709. }
  710. @IBAction func insertPage(_ sender: Any?) {
  711. KMPrint("insertPage ...")
  712. }
  713. @IBAction func split(_ sender: Any?) {
  714. KMPrint("split ...")
  715. }
  716. @IBAction func comparison(_ sender: Any?) {
  717. KMPrint("comparison ...")
  718. }
  719. @IBAction func contentComparison(_ sender: Any?) {
  720. KMPrint("contentComparison ...")
  721. }
  722. @IBAction func coverageComparison(_ sender: Any?) {
  723. KMPrint("coverageComparison ...")
  724. }
  725. @IBAction func readMode(_ sender: Any?) {
  726. KMPrint("readMode ...")
  727. }
  728. @IBAction func changeFormType(_ sender: Any?) {
  729. KMPrint("changeFormType ...")
  730. }
  731. @IBAction func changeSelfSignType(_ sender: Any?) {
  732. KMPrint("changeSelfSignType ...")
  733. }
  734. @IBAction func clearAllForm(_ sender: Any?) {
  735. KMPrint("clearAllForm ...")
  736. }
  737. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  738. KMPrint("thumbnailSizeScaling ...")
  739. }
  740. @IBAction func redactAction(_ sender: Any?) {
  741. if (self.canResponseDocumentAction() == false) {
  742. return
  743. }
  744. if let document = self.browser.activeTabContents() as? KMMainDocument {
  745. if document.isHome == false {
  746. document.mainViewController?.menuItemAction_redact(sender)
  747. }
  748. }
  749. }
  750. }
  751. // MARK: - KMSystemFileMenuProtocol
  752. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  753. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  754. if (self.canResponseDocumentAction() == false) {
  755. return
  756. }
  757. if let document = self.browser.activeTabContents() as? KMMainDocument {
  758. if (document.isHome) {
  759. // document.homeViewController?.menuItemClick_mergePDF(sender)
  760. } else {
  761. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  762. }
  763. }
  764. }
  765. func menuItemClick_mergePDF(_ sender: Any) {
  766. if (self.canResponseDocumentAction() == false) {
  767. return
  768. }
  769. if let document = self.browser.activeTabContents() as? KMMainDocument {
  770. if (document.isHome) {
  771. document.homeViewController?.menuItemClick_mergePDF(sender)
  772. } else {
  773. document.mainViewController?.menuItemClick_mergePDF(sender)
  774. }
  775. }
  776. }
  777. func menuItemClick_Compress(_ sender: Any) {
  778. if (self.canResponseDocumentAction() == false) {
  779. return
  780. }
  781. if let document = self.browser.activeTabContents() as? KMMainDocument {
  782. if (document.isHome) {
  783. document.homeViewController?.menuItemClick_Compress(sender)
  784. } else {
  785. document.mainViewController?.menuItemClick_Compress(sender)
  786. }
  787. }
  788. }
  789. func menuItemAction_ConvertToWord(_ sender: Any) {
  790. if (self.canResponseDocumentAction() == false) {
  791. return
  792. }
  793. if let document = self.browser.activeTabContents() as? KMMainDocument {
  794. if (document.isHome) {
  795. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  796. } else {
  797. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  798. }
  799. }
  800. }
  801. func menuItemAction_ConvertToExcel(_ sender: Any) {
  802. if (self.canResponseDocumentAction() == false) {
  803. return
  804. }
  805. if let document = self.browser.activeTabContents() as? KMMainDocument {
  806. if (document.isHome) {
  807. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  808. } else {
  809. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  810. }
  811. }
  812. }
  813. func menuItemAction_ConvertToPPT(_ sender: Any) {
  814. if (self.canResponseDocumentAction() == false) {
  815. return
  816. }
  817. if let document = self.browser.activeTabContents() as? KMMainDocument {
  818. if (document.isHome) {
  819. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  820. } else {
  821. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  822. }
  823. }
  824. }
  825. func menuItemAction_ConvertToRTF(_ sender: Any) {
  826. if (self.canResponseDocumentAction() == false) {
  827. return
  828. }
  829. if let document = self.browser.activeTabContents() as? KMMainDocument {
  830. if (document.isHome) {
  831. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  832. } else {
  833. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  834. }
  835. }
  836. }
  837. func menuItemAction_ConvertToHTML(_ sender: Any) {
  838. if (self.canResponseDocumentAction() == false) {
  839. return
  840. }
  841. if let document = self.browser.activeTabContents() as? KMMainDocument {
  842. if (document.isHome) {
  843. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  844. } else {
  845. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  846. }
  847. }
  848. }
  849. func menuItemAction_ConvertToText(_ sender: Any) {
  850. if (self.canResponseDocumentAction() == false) {
  851. return
  852. }
  853. if let document = self.browser.activeTabContents() as? KMMainDocument {
  854. if (document.isHome) {
  855. document.homeViewController?.menuItemAction_ConvertToText(sender)
  856. } else {
  857. document.mainViewController?.menuItemAction_ConvertToText(sender)
  858. }
  859. }
  860. }
  861. func menuItemAction_ConvertToCSV(_ sender: Any) {
  862. if (self.canResponseDocumentAction() == false) {
  863. return
  864. }
  865. if let document = self.browser.activeTabContents() as? KMMainDocument {
  866. if (document.isHome) {
  867. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  868. } else {
  869. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  870. }
  871. }
  872. }
  873. func menuItemAction_ConvertToImage(_ sender: Any) {
  874. if (self.canResponseDocumentAction() == false) {
  875. return
  876. }
  877. if let document = self.browser.activeTabContents() as? KMMainDocument {
  878. if (document.isHome) {
  879. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  880. } else {
  881. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  882. }
  883. }
  884. }
  885. func menuItemClick_SettingPassword(_ sender: Any) {
  886. if (self.canResponseDocumentAction() == false) {
  887. return
  888. }
  889. if let document = self.browser.activeTabContents() as? KMMainDocument {
  890. if (document.isHome) {
  891. document.homeViewController?.menuItemClick_SettingPassword(sender)
  892. } else {
  893. document.mainViewController?.menuItemClick_SettingPassword(sender)
  894. }
  895. }
  896. }
  897. func menuItemClick_RemovePassword(_ sender: Any) {
  898. if (self.canResponseDocumentAction() == false) {
  899. return
  900. }
  901. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  902. document.mainViewController?.menuItemClick_RemovePassword(sender)
  903. }
  904. }
  905. func menuItemAction_closeWindow(_ sender: Any) {
  906. if (self.canResponseDocumentAction() == false) {
  907. return
  908. }
  909. if let document = self.browser.activeTabContents() as? KMMainDocument {
  910. if (document.isHome) {
  911. document.homeViewController?.menuItemAction_closeWindow(sender)
  912. } else {
  913. document.mainViewController?.menuItemAction_closeWindow(sender)
  914. }
  915. }
  916. }
  917. func menuItemAction_closeAllWindows(_ sender: Any) {
  918. if (self.canResponseDocumentAction() == false) {
  919. return
  920. }
  921. if let document = self.browser.activeTabContents() as? KMMainDocument {
  922. if (document.isHome) {
  923. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  924. } else {
  925. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  926. }
  927. }
  928. }
  929. func menuItemAction_closeTagPage(_ sender: Any) {
  930. if (self.canResponseDocumentAction() == false) {
  931. return
  932. }
  933. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  934. document.mainViewController?.menuItemAction_closeTagPage(sender)
  935. }
  936. }
  937. func menuItemAction_showInFinder(_ sender: Any) {
  938. if (self.canResponseDocumentAction() == false) {
  939. return
  940. }
  941. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  942. document.mainViewController?.menuItemAction_showInFinder(sender)
  943. }
  944. }
  945. func menuItemAction_property(_ sender: Any) {
  946. if (self.canResponseDocumentAction() == false) {
  947. return
  948. }
  949. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  950. document.mainViewController?.menuItemAction_property(sender)
  951. }
  952. }
  953. func menuItemAction_print(_ sender: Any) {
  954. if (self.canResponseDocumentAction() == false) {
  955. return
  956. }
  957. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  958. document.mainViewController?.menuItemAction_print(sender)
  959. }
  960. }
  961. @IBAction func newDocumentFromClipboard(_ sender: Any?) {
  962. KMPrint("newDocumentFromClipboard")
  963. }
  964. @IBAction func newDocumentFromImage(_ sender: Any?) {
  965. KMPrint("importFromWebPage")
  966. }
  967. @IBAction func importFromWebPage(_ sender: Any?) {
  968. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  969. if (document.isHome) {
  970. document.homeViewController?.importFromWebPage()
  971. } else {
  972. self.homeVC = KMHomeViewController()
  973. self.homeVC?.importFromWebPage()
  974. }
  975. }
  976. @IBAction func screenShot_SelectArea(_ sender: Any?) {
  977. KMPrint("screenShot_SelectArea")
  978. }
  979. @IBAction func screenShot_Window(_ sender: Any?) {
  980. KMPrint("screenShot_Window")
  981. }
  982. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  983. KMPrint("screenShot_FullScreenDelay")
  984. }
  985. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  986. KMPrint("screenShot_FullScreen")
  987. }
  988. }
  989. // MARK: - KMSystemViewMenuProtocol
  990. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  991. func menuItemAction_adjustWidth(_ 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_adjustWidth(sender)
  997. }
  998. }
  999. func menuItemAction_adjustPage(_ 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_adjustPage(sender)
  1005. }
  1006. }
  1007. func menuItemAction_size(_ sender: Any) {
  1008. if (self.canResponseDocumentAction() == false) {
  1009. return
  1010. }
  1011. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1012. document.mainViewController?.menuItemAction_size(sender)
  1013. }
  1014. }
  1015. func menuItemAction_zoomOut(_ sender: Any) {
  1016. if (self.canResponseDocumentAction() == false) {
  1017. return
  1018. }
  1019. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1020. document.mainViewController?.menuItemAction_zoomOut(sender)
  1021. }
  1022. }
  1023. func menuItemAction_zoomIn(_ sender: Any) {
  1024. if (self.canResponseDocumentAction() == false) {
  1025. return
  1026. }
  1027. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1028. document.mainViewController?.menuItemAction_zoomIn(sender)
  1029. }
  1030. }
  1031. func menuItemAction_singlePage(_ sender: Any) {
  1032. if (self.canResponseDocumentAction() == false) {
  1033. return
  1034. }
  1035. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1036. document.mainViewController?.menuItemAction_singlePage(sender)
  1037. }
  1038. }
  1039. func menuItemAction_singlePageContinue(_ sender: Any) {
  1040. if (self.canResponseDocumentAction() == false) {
  1041. return
  1042. }
  1043. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1044. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1045. }
  1046. }
  1047. func menuItemAction_doublePage(_ sender: Any) {
  1048. if (self.canResponseDocumentAction() == false) {
  1049. return
  1050. }
  1051. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1052. document.mainViewController?.menuItemAction_doublePage(sender)
  1053. }
  1054. }
  1055. func menuItemAction_doublePageContinue(_ sender: Any) {
  1056. if (self.canResponseDocumentAction() == false) {
  1057. return
  1058. }
  1059. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1060. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1061. }
  1062. }
  1063. func menuItemAction_bookMode(_ sender: Any) {
  1064. if (self.canResponseDocumentAction() == false) {
  1065. return
  1066. }
  1067. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1068. document.mainViewController?.menuItemAction_bookMode(sender)
  1069. }
  1070. }
  1071. func menuItemAction_readMode(_ sender: Any) {
  1072. if (self.canResponseDocumentAction() == false) {
  1073. return
  1074. }
  1075. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1076. document.mainViewController?.menuItemAction_readMode(sender)
  1077. }
  1078. }
  1079. func menuItemAction_showSplitPage(_ sender: Any) {
  1080. if (self.canResponseDocumentAction() == false) {
  1081. return
  1082. }
  1083. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1084. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1085. }
  1086. }
  1087. func menuItemAction_rotateLeft(_ sender: Any) {
  1088. if (self.canResponseDocumentAction() == false) {
  1089. return
  1090. }
  1091. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1092. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1093. }
  1094. }
  1095. func menuItemAction_rotateRight(_ sender: Any) {
  1096. if (self.canResponseDocumentAction() == false) {
  1097. return
  1098. }
  1099. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1100. document.mainViewController?.menuItemAction_rotateRight(sender)
  1101. }
  1102. }
  1103. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1104. if (self.canResponseDocumentAction() == false) {
  1105. return
  1106. }
  1107. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1108. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1109. }
  1110. }
  1111. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1112. if (self.canResponseDocumentAction() == false) {
  1113. return
  1114. }
  1115. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1116. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1117. }
  1118. }
  1119. func menuItemAction_view_readMode(_ sender: Any) {
  1120. if (self.canResponseDocumentAction() == false) {
  1121. return
  1122. }
  1123. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1124. document.mainViewController?.menuItemAction_view_readMode(sender)
  1125. }
  1126. }
  1127. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1128. if (self.canResponseDocumentAction() == false) {
  1129. return
  1130. }
  1131. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1132. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1133. }
  1134. }
  1135. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1136. if (self.canResponseDocumentAction() == false) {
  1137. return
  1138. }
  1139. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1140. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1141. }
  1142. }
  1143. func menuItemAction_thumai(_ sender: Any) {
  1144. if (self.canResponseDocumentAction() == false) {
  1145. return
  1146. }
  1147. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1148. document.mainViewController?.menuItemAction_thumai(sender)
  1149. }
  1150. }
  1151. func menuItemAction_outline(_ sender: Any) {
  1152. if (self.canResponseDocumentAction() == false) {
  1153. return
  1154. }
  1155. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1156. document.mainViewController?.menuItemAction_outline(sender)
  1157. }
  1158. }
  1159. func menuItemAction_bookmark(_ sender: Any) {
  1160. if (self.canResponseDocumentAction() == false) {
  1161. return
  1162. }
  1163. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1164. document.mainViewController?.menuItemAction_bookmark(sender)
  1165. }
  1166. }
  1167. func menuItemAction_annotation(_ sender: Any) {
  1168. if (self.canResponseDocumentAction() == false) {
  1169. return
  1170. }
  1171. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1172. document.mainViewController?.menuItemAction_annotation(sender)
  1173. }
  1174. }
  1175. func menuItemAction_search(_ sender: Any) {
  1176. if (self.canResponseDocumentAction() == false) {
  1177. return
  1178. }
  1179. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1180. document.mainViewController?.menuItemAction_search(sender)
  1181. }
  1182. }
  1183. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1184. if (self.canResponseDocumentAction() == false) {
  1185. return
  1186. }
  1187. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1188. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1189. }
  1190. }
  1191. @IBAction func togglePresentation(_ sender: Any?) {
  1192. if (self.canResponseDocumentAction() == false) {
  1193. return
  1194. }
  1195. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1196. document.mainViewController?.togglePresentation(sender)
  1197. }
  1198. }
  1199. @IBAction func chooseTransition(_ sender: Any?) {
  1200. if (self.canResponseDocumentAction() == false) {
  1201. return
  1202. }
  1203. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1204. document.mainViewController?.chooseTransition(sender)
  1205. }
  1206. }
  1207. @IBAction func toggleAutoFlow(_ sender: Any?) {
  1208. if (self.canResponseDocumentAction() == false) {
  1209. return
  1210. }
  1211. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1212. document.mainViewController?.toggleAutoFlow(sender)
  1213. }
  1214. }
  1215. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  1216. if (self.canResponseDocumentAction() == false) {
  1217. return
  1218. }
  1219. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1220. document.mainViewController?.chooseAutoFlowSetting(sender)
  1221. }
  1222. }
  1223. @IBAction func toggleReadingBar(_ sender: Any?) {
  1224. if (self.canResponseDocumentAction() == false) {
  1225. return
  1226. }
  1227. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1228. document.mainViewController?.toggleReadingBar(sender)
  1229. }
  1230. }
  1231. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  1232. if (self.canResponseDocumentAction() == false) {
  1233. return
  1234. }
  1235. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1236. document.mainViewController?.toggleLeftSidePane(sender)
  1237. }
  1238. }
  1239. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  1240. if (self.canResponseDocumentAction() == false) {
  1241. return
  1242. }
  1243. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1244. document.mainViewController?.changeLeftSidePaneState(sender)
  1245. }
  1246. }
  1247. @IBAction func splitViewAction(_ sender: Any?) {
  1248. if (self.canResponseDocumentAction() == false) {
  1249. return
  1250. }
  1251. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1252. document.mainViewController?.splitViewAction(sender)
  1253. }
  1254. }
  1255. @IBAction func themesColor(_ sender: Any?) {
  1256. if (self.canResponseDocumentAction() == false) {
  1257. return
  1258. }
  1259. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1260. document.mainViewController?.themesColor(sender)
  1261. }
  1262. }
  1263. @IBAction func toggleStatusBar(_ sender: Any?) {
  1264. if (self.canResponseDocumentAction() == false) {
  1265. return
  1266. }
  1267. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1268. document.mainViewController?.toggleStatusBar(sender)
  1269. }
  1270. }
  1271. @IBAction func toggleToolbarShow(_ sender: Any?) {
  1272. if (self.canResponseDocumentAction() == false) {
  1273. return
  1274. }
  1275. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1276. document.mainViewController?.toggleToolbarShow(sender)
  1277. }
  1278. }
  1279. }
  1280. // MARK: - KMSystemEditMenuProtocol
  1281. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1282. func menuItemAction_find(_ sender: Any) {
  1283. if (self.canResponseDocumentAction() == false) {
  1284. return
  1285. }
  1286. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1287. document.mainViewController?.menuItemAction_find(sender)
  1288. }
  1289. }
  1290. @IBAction func changeFont(_ sender: Any?) {
  1291. KMPrint("changeFont ...")
  1292. }
  1293. }
  1294. // MARK: - Annotation Menu
  1295. extension KMBrowserWindowController {
  1296. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1297. if (self.canResponseDocumentAction() == false) {
  1298. return
  1299. }
  1300. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1301. document.mainViewController?.menuItemAction_highlight(sender)
  1302. }
  1303. }
  1304. @IBAction func menuItemAction_underline(_ sender: Any) {
  1305. if (self.canResponseDocumentAction() == false) {
  1306. return
  1307. }
  1308. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1309. document.mainViewController?.menuItemAction_underline(sender)
  1310. }
  1311. }
  1312. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1313. if (self.canResponseDocumentAction() == false) {
  1314. return
  1315. }
  1316. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1317. document.mainViewController?.menuItemAction_deleteLine(sender)
  1318. }
  1319. }
  1320. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1321. if (self.canResponseDocumentAction() == false) {
  1322. return
  1323. }
  1324. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1325. document.mainViewController?.menuItemAction_freehand(sender)
  1326. }
  1327. }
  1328. @IBAction func menuItemAction_text(_ sender: Any) {
  1329. if (self.canResponseDocumentAction() == false) {
  1330. return
  1331. }
  1332. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1333. document.mainViewController?.menuItemAction_text(sender)
  1334. }
  1335. }
  1336. @IBAction func menuItemAction_note(_ sender: Any) {
  1337. if (self.canResponseDocumentAction() == false) {
  1338. return
  1339. }
  1340. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1341. document.mainViewController?.menuItemAction_note(sender)
  1342. }
  1343. }
  1344. @IBAction func menuItemAction_squre(_ sender: Any) {
  1345. if (self.canResponseDocumentAction() == false) {
  1346. return
  1347. }
  1348. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1349. document.mainViewController?.menuItemAction_squre(sender)
  1350. }
  1351. }
  1352. @IBAction func menuItemAction_circle(_ 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_circle(sender)
  1358. }
  1359. }
  1360. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1361. if (self.canResponseDocumentAction() == false) {
  1362. return
  1363. }
  1364. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1365. document.mainViewController?.menuItemAction_arrow(sender)
  1366. }
  1367. }
  1368. @IBAction func menuItemAction_line(_ sender: Any) {
  1369. if (self.canResponseDocumentAction() == false) {
  1370. return
  1371. }
  1372. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1373. document.mainViewController?.menuItemAction_line(sender)
  1374. }
  1375. }
  1376. // link
  1377. @IBAction func menuItemAction_link(_ sender: Any) {
  1378. if (self.canResponseDocumentAction() == false) {
  1379. return
  1380. }
  1381. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1382. document.mainViewController?.menuItemAction_link(sender)
  1383. }
  1384. }
  1385. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1386. if (self.canResponseDocumentAction() == false) {
  1387. return
  1388. }
  1389. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1390. document.mainViewController?.menuItemAction_linkPage(sender)
  1391. }
  1392. }
  1393. // stamp
  1394. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1395. if (self.canResponseDocumentAction() == false) {
  1396. return
  1397. }
  1398. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1399. document.mainViewController?.menuItemAction_stamp(sender)
  1400. }
  1401. }
  1402. @IBAction func menuItemAction_signure(_ sender: Any) {
  1403. if (self.canResponseDocumentAction() == false) {
  1404. return
  1405. }
  1406. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1407. document.mainViewController?.menuItemAction_signure(sender)
  1408. }
  1409. }
  1410. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1411. if (self.canResponseDocumentAction() == false) {
  1412. return
  1413. }
  1414. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1415. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1416. }
  1417. }
  1418. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1419. if (self.canResponseDocumentAction() == false) {
  1420. return
  1421. }
  1422. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1423. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1424. }
  1425. }
  1426. }
  1427. // MARK: - KMSystemPDFMenuProtocol
  1428. extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
  1429. @IBAction func changeDisplayMode(_ sender: Any?) {
  1430. if (self.canResponseDocumentAction() == false) {
  1431. return
  1432. }
  1433. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1434. document.mainViewController?.changeDisplayMode(sender)
  1435. }
  1436. }
  1437. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  1438. if (self.canResponseDocumentAction() == false) {
  1439. return
  1440. }
  1441. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1442. document.mainViewController?.toggleDisplayAsBook(sender)
  1443. }
  1444. }
  1445. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  1446. if (self.canResponseDocumentAction() == false) {
  1447. return
  1448. }
  1449. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1450. document.mainViewController?.toggleDisplayPageBreaks(sender)
  1451. }
  1452. }
  1453. @IBAction func changeDisplayBox(_ sender: Any?) {
  1454. if (self.canResponseDocumentAction() == false) {
  1455. return
  1456. }
  1457. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1458. document.mainViewController?.changeDisplayBox(sender)
  1459. }
  1460. }
  1461. @IBAction func toggleAutoScale(_ 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?.toggleAutoScale(sender)
  1467. }
  1468. }
  1469. @IBAction func doZoomToActualSize(_ 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?.doZoomToActualSize(sender)
  1475. }
  1476. }
  1477. @IBAction func doZoomToFit(_ 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?.doZoomToFit(sender)
  1483. }
  1484. }
  1485. @IBAction func doZoomIn(_ 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?.doZoomIn(sender)
  1491. }
  1492. }
  1493. @IBAction func doZoomOut(_ sender: Any?) {
  1494. if (self.canResponseDocumentAction() == false) {
  1495. return
  1496. }
  1497. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1498. document.mainViewController?.doZoomOut(sender)
  1499. }
  1500. }
  1501. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  1502. if (self.canResponseDocumentAction() == false) {
  1503. return
  1504. }
  1505. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1506. document.mainViewController?.doMarqueeZoomTool(sender)
  1507. }
  1508. }
  1509. @IBAction func highlightFormFiled(_ sender: Any?) {
  1510. if (self.canResponseDocumentAction() == false) {
  1511. return
  1512. }
  1513. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1514. document.mainViewController?.highlightFormFiled(sender)
  1515. }
  1516. }
  1517. @IBAction func highlightLinks(_ sender: Any?) {
  1518. if (self.canResponseDocumentAction() == false) {
  1519. return
  1520. }
  1521. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1522. document.mainViewController?.highlightLinks(sender)
  1523. }
  1524. }
  1525. @IBAction func resetForm(_ sender: Any?) {
  1526. if (self.canResponseDocumentAction() == false) {
  1527. return
  1528. }
  1529. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1530. document.mainViewController?.resetForm(sender)
  1531. }
  1532. }
  1533. @IBAction func removeAllAnnotation(_ sender: Any?) {
  1534. if (self.canResponseDocumentAction() == false) {
  1535. return
  1536. }
  1537. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1538. document.mainViewController?.removeAllAnnotation(sender)
  1539. }
  1540. }
  1541. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  1542. if (self.canResponseDocumentAction() == false) {
  1543. return
  1544. }
  1545. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1546. document.mainViewController?.savePDFSettingToDefaults(sender)
  1547. }
  1548. }
  1549. }
  1550. // MARK: - KMSystemGotoMenuProtocol
  1551. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1552. func menuItemAction_nextPage(_ sender: Any) {
  1553. if (self.canResponseDocumentAction() == false) {
  1554. return
  1555. }
  1556. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1557. document.mainViewController?.menuItemAction_nextPage(sender)
  1558. }
  1559. }
  1560. func menuItemAction_forwardPage(_ sender: Any) {
  1561. if (self.canResponseDocumentAction() == false) {
  1562. return
  1563. }
  1564. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1565. document.mainViewController?.menuItemAction_forwardPage(sender)
  1566. }
  1567. }
  1568. func menuItemAction_firstPage(_ sender: Any) {
  1569. if (self.canResponseDocumentAction() == false) {
  1570. return
  1571. }
  1572. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1573. document.mainViewController?.menuItemAction_firstPage(sender)
  1574. }
  1575. }
  1576. func menuItemAction_lastPage(_ sender: Any) {
  1577. if (self.canResponseDocumentAction() == false) {
  1578. return
  1579. }
  1580. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1581. document.mainViewController?.menuItemAction_lastPage(sender)
  1582. }
  1583. }
  1584. func menuItemAction_forward(_ sender: Any) {
  1585. if (self.canResponseDocumentAction() == false) {
  1586. return
  1587. }
  1588. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1589. document.mainViewController?.menuItemAction_forward(sender)
  1590. }
  1591. }
  1592. func menuItemAction_goback(_ sender: Any) {
  1593. if (self.canResponseDocumentAction() == false) {
  1594. return
  1595. }
  1596. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1597. document.mainViewController?.menuItemAction_goback(sender)
  1598. }
  1599. }
  1600. func menuItemAction_gotoPage(_ sender: Any) {
  1601. if (self.canResponseDocumentAction() == false) {
  1602. return
  1603. }
  1604. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1605. document.mainViewController?.menuItemAction_gotoPage(sender)
  1606. }
  1607. }
  1608. @IBAction func goToMarkedPage(_ sender: Any?) {
  1609. if (self.canResponseDocumentAction() == false) {
  1610. return
  1611. }
  1612. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1613. document.mainViewController?.goToMarkedPage(sender)
  1614. }
  1615. }
  1616. @IBAction func markPage(_ sender: Any?) {
  1617. if (self.canResponseDocumentAction() == false) {
  1618. return
  1619. }
  1620. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1621. document.mainViewController?.markPage(sender)
  1622. }
  1623. }
  1624. }
  1625. // MARK: - KMSystemToolMenuProtocol
  1626. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1627. @IBAction func getInfo(_ sender: Any?) {
  1628. if (self.canResponseDocumentAction() == false) {
  1629. return
  1630. }
  1631. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1632. document.mainViewController?.getInfo(sender)
  1633. }
  1634. }
  1635. func orderFrontNotesPanel(_ sender: Any?) {
  1636. let windowC = KMNotesPanelController.shared
  1637. if let win = windowC.window {
  1638. if win.isVisible {
  1639. win.orderOut(sender)
  1640. } else {
  1641. win.orderFront(sender)
  1642. }
  1643. }
  1644. }
  1645. func menuItemAction_scrolTool(_ sender: Any) {
  1646. if (self.canResponseDocumentAction() == false) {
  1647. return
  1648. }
  1649. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1650. document.mainViewController?.menuItemAction_scrolTool(sender)
  1651. }
  1652. }
  1653. func menuItemAction_zoomOutTool(_ sender: Any) {
  1654. if (self.canResponseDocumentAction() == false) {
  1655. return
  1656. }
  1657. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1658. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1659. }
  1660. }
  1661. func menuItemAction_selectTool(_ sender: Any) {
  1662. if (self.canResponseDocumentAction() == false) {
  1663. return
  1664. }
  1665. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1666. document.mainViewController?.menuItemAction_selectTool(sender)
  1667. }
  1668. }
  1669. @IBAction func changeToolMode(_ sender: Any?) {
  1670. if (self.canResponseDocumentAction() == false) {
  1671. return
  1672. }
  1673. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1674. if (document.isHome) {
  1675. } else {
  1676. document.mainViewController?.changeToolMode(sender)
  1677. }
  1678. }
  1679. }
  1680. @IBAction func compression(_ sender: Any?) {
  1681. if (self.canResponseDocumentAction() == false) {
  1682. return
  1683. }
  1684. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1685. if (document.isHome) {
  1686. } else {
  1687. document.mainViewController?.compression(sender)
  1688. }
  1689. }
  1690. }
  1691. @IBAction func merge(_ sender: Any?) {
  1692. if (self.canResponseDocumentAction() == false) {
  1693. return
  1694. }
  1695. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1696. if (document.isHome) {
  1697. } else {
  1698. document.mainViewController?.merge(sender)
  1699. }
  1700. }
  1701. }
  1702. @IBAction func convert(_ sender: Any?) {
  1703. if (self.canResponseDocumentAction() == false) {
  1704. return
  1705. }
  1706. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1707. if (document.isHome) {
  1708. } else {
  1709. document.mainViewController?.convert(sender)
  1710. }
  1711. }
  1712. }
  1713. @IBAction func imageToPDF(_ sender: Any?) {
  1714. if (self.canResponseDocumentAction() == false) {
  1715. return
  1716. }
  1717. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1718. if (document.isHome) {
  1719. } else {
  1720. document.mainViewController?.imageToPDF(sender)
  1721. }
  1722. }
  1723. }
  1724. @IBAction func ocr(_ sender: Any?) {
  1725. if (self.canResponseDocumentAction() == false) {
  1726. return
  1727. }
  1728. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1729. if (document.isHome) {
  1730. } else {
  1731. document.mainViewController?.ocr(sender)
  1732. }
  1733. }
  1734. }
  1735. @IBAction func extractImage(_ sender: Any?) {
  1736. if (self.canResponseDocumentAction() == false) {
  1737. return
  1738. }
  1739. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1740. if (document.isHome) {
  1741. } else {
  1742. document.mainViewController?.extractImage(sender)
  1743. }
  1744. }
  1745. }
  1746. @IBAction func pageEdit(_ sender: Any?) {
  1747. if (self.canResponseDocumentAction() == false) {
  1748. return
  1749. }
  1750. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1751. if (document.isHome) {
  1752. } else {
  1753. document.mainViewController?.pageEdit(sender)
  1754. }
  1755. }
  1756. }
  1757. @IBAction func textEditAction(_ sender: Any?) {
  1758. if (self.canResponseDocumentAction() == false) {
  1759. return
  1760. }
  1761. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1762. if (document.isHome) {
  1763. } else {
  1764. document.mainViewController?.textEditAction(sender)
  1765. }
  1766. }
  1767. }
  1768. @IBAction func security(_ sender: Any?) {
  1769. if (self.canResponseDocumentAction() == false) {
  1770. return
  1771. }
  1772. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1773. if (document.isHome) {
  1774. } else {
  1775. document.mainViewController?.security(sender)
  1776. }
  1777. }
  1778. }
  1779. @IBAction func decryption(_ sender: Any?) {
  1780. if (self.canResponseDocumentAction() == false) {
  1781. return
  1782. }
  1783. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1784. if (document.isHome) {
  1785. } else {
  1786. document.mainViewController?.decryption(sender)
  1787. }
  1788. }
  1789. }
  1790. @IBAction func cropAll(_ sender: Any?) {
  1791. if (self.canResponseDocumentAction() == false) {
  1792. return
  1793. }
  1794. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1795. if (document.isHome) {
  1796. } else {
  1797. document.mainViewController?.cropAll(sender)
  1798. }
  1799. }
  1800. }
  1801. @IBAction func crop(_ sender: Any?) {
  1802. if (self.canResponseDocumentAction() == false) {
  1803. return
  1804. }
  1805. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1806. if (document.isHome) {
  1807. } else {
  1808. document.mainViewController?.crop(sender)
  1809. }
  1810. }
  1811. }
  1812. @IBAction func autoCropAll(_ sender: Any?) {
  1813. if (self.canResponseDocumentAction() == false) {
  1814. return
  1815. }
  1816. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1817. if (document.isHome) {
  1818. } else {
  1819. document.mainViewController?.autoCropAll(sender)
  1820. }
  1821. }
  1822. }
  1823. @IBAction func smartAutoCropAll(_ sender: Any?) {
  1824. if (self.canResponseDocumentAction() == false) {
  1825. return
  1826. }
  1827. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1828. if (document.isHome) {
  1829. } else {
  1830. document.mainViewController?.smartAutoCropAll(sender)
  1831. }
  1832. }
  1833. }
  1834. @IBAction func cropOptionsModel(_ sender: Any?) {
  1835. if (self.canResponseDocumentAction() == false) {
  1836. return
  1837. }
  1838. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1839. if (document.isHome) {
  1840. } else {
  1841. // document.mainViewController?.cropOptionsModel(sender)
  1842. }
  1843. }
  1844. }
  1845. @IBAction func selectToolModel(_ sender: Any?) {
  1846. if (self.canResponseDocumentAction() == false) {
  1847. return
  1848. }
  1849. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1850. if (document.isHome) {
  1851. } else {
  1852. document.mainViewController?.selectToolModel(sender)
  1853. }
  1854. }
  1855. }
  1856. @IBAction func takeSnapshot(_ sender: Any?) {
  1857. if (self.canResponseDocumentAction() == false) {
  1858. return
  1859. }
  1860. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1861. if (document.isHome) {
  1862. } else {
  1863. document.mainViewController?.takeSnapshot(sender)
  1864. }
  1865. }
  1866. }
  1867. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  1868. if (self.canResponseDocumentAction() == false) {
  1869. return
  1870. }
  1871. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1872. if (document.isHome) {
  1873. } else {
  1874. document.mainViewController?.takeSnapshotSelectContent(sender)
  1875. }
  1876. }
  1877. }
  1878. @IBAction func changeAnnotationMode(_ sender: Any?) {
  1879. if (self.canResponseDocumentAction() == false) {
  1880. return
  1881. }
  1882. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1883. if (document.isHome) {
  1884. } else {
  1885. document.mainViewController?.changeAnnotationMode(sender)
  1886. }
  1887. }
  1888. }
  1889. @IBAction func addBackground(_ sender: Any?) {
  1890. if (self.canResponseDocumentAction() == false) {
  1891. return
  1892. }
  1893. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1894. if (document.isHome) {
  1895. } else {
  1896. document.mainViewController?.addBackground(sender)
  1897. }
  1898. }
  1899. }
  1900. @IBAction func removeBackground(_ sender: Any?) {
  1901. if (self.canResponseDocumentAction() == false) {
  1902. return
  1903. }
  1904. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1905. if (document.isHome) {
  1906. } else {
  1907. document.mainViewController?.removeBackground(sender)
  1908. }
  1909. }
  1910. }
  1911. @IBAction func addWatermark(_ sender: Any?) {
  1912. if (self.canResponseDocumentAction() == false) {
  1913. return
  1914. }
  1915. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1916. if (document.isHome) {
  1917. } else {
  1918. document.mainViewController?.addWatermark(sender)
  1919. }
  1920. }
  1921. }
  1922. @IBAction func editWatermark(_ sender: Any?) {
  1923. KMPrint("editWatermark ...")
  1924. }
  1925. @IBAction func batchAddWatermark(_ sender: Any?) {
  1926. if (self.canResponseDocumentAction() == false) {
  1927. return
  1928. }
  1929. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1930. if (document.isHome) {
  1931. } else {
  1932. document.mainViewController?.batchAddWatermark(sender)
  1933. }
  1934. }
  1935. }
  1936. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  1937. if (self.canResponseDocumentAction() == false) {
  1938. return
  1939. }
  1940. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1941. if (document.isHome) {
  1942. } else {
  1943. document.mainViewController?.batchRemoveWatermark(sender)
  1944. }
  1945. }
  1946. }
  1947. @IBAction func removeWatermark(_ sender: Any?) {
  1948. if (self.canResponseDocumentAction() == false) {
  1949. return
  1950. }
  1951. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1952. if (document.isHome) {
  1953. } else {
  1954. document.mainViewController?.removeWatermark(sender)
  1955. }
  1956. }
  1957. }
  1958. @IBAction func templateWatermark(_ sender: Any?) {
  1959. if (self.canResponseDocumentAction() == false) {
  1960. return
  1961. }
  1962. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1963. if (document.isHome) {
  1964. } else {
  1965. document.mainViewController?.templateWatermark(sender)
  1966. }
  1967. }
  1968. }
  1969. @IBAction func batchAddBackground(_ sender: Any?) {
  1970. if (self.canResponseDocumentAction() == false) {
  1971. return
  1972. }
  1973. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1974. if (document.isHome) {
  1975. } else {
  1976. document.mainViewController?.batchAddBackground(sender)
  1977. }
  1978. }
  1979. }
  1980. @IBAction func batchRemoveBackground(_ sender: Any?) {
  1981. if (self.canResponseDocumentAction() == false) {
  1982. return
  1983. }
  1984. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1985. if (document.isHome) {
  1986. } else {
  1987. document.mainViewController?.batchRemoveBackground(sender)
  1988. }
  1989. }
  1990. }
  1991. @IBAction func templateBackground(_ sender: Any?) {
  1992. if (self.canResponseDocumentAction() == false) {
  1993. return
  1994. }
  1995. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1996. if (document.isHome) {
  1997. } else {
  1998. document.mainViewController?.templateBackground(sender)
  1999. }
  2000. }
  2001. }
  2002. @IBAction func addHeaderFooter(_ sender: Any?) {
  2003. if (self.canResponseDocumentAction() == false) {
  2004. return
  2005. }
  2006. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2007. if (document.isHome) {
  2008. } else {
  2009. document.mainViewController?.addHeaderFooter(sender)
  2010. }
  2011. }
  2012. }
  2013. @IBAction func removeHeaderFooter(_ sender: Any?) {
  2014. if (self.canResponseDocumentAction() == false) {
  2015. return
  2016. }
  2017. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2018. if (document.isHome) {
  2019. } else {
  2020. document.mainViewController?.removeHeaderFooter(sender)
  2021. }
  2022. }
  2023. }
  2024. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  2025. if (self.canResponseDocumentAction() == false) {
  2026. return
  2027. }
  2028. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2029. if (document.isHome) {
  2030. } else {
  2031. document.mainViewController?.batchAddHeaderFooter(sender)
  2032. }
  2033. }
  2034. }
  2035. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  2036. if (self.canResponseDocumentAction() == false) {
  2037. return
  2038. }
  2039. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2040. if (document.isHome) {
  2041. } else {
  2042. document.mainViewController?.batchRemoveHeaderFooter(sender)
  2043. }
  2044. }
  2045. }
  2046. @IBAction func templateHeaderFooter(_ sender: Any?) {
  2047. if (self.canResponseDocumentAction() == false) {
  2048. return
  2049. }
  2050. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2051. if (document.isHome) {
  2052. } else {
  2053. document.mainViewController?.templateHeaderFooter(sender)
  2054. }
  2055. }
  2056. }
  2057. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  2058. if (self.canResponseDocumentAction() == false) {
  2059. return
  2060. }
  2061. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2062. if (document.isHome) {
  2063. } else {
  2064. document.mainViewController?.addHeaderFooterBates(sender)
  2065. }
  2066. }
  2067. }
  2068. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  2069. if (self.canResponseDocumentAction() == false) {
  2070. return
  2071. }
  2072. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2073. if (document.isHome) {
  2074. } else {
  2075. document.mainViewController?.removeHeaderFooterBates(sender)
  2076. }
  2077. }
  2078. }
  2079. @IBAction func batchAddBates(_ sender: Any?) {
  2080. if (self.canResponseDocumentAction() == false) {
  2081. return
  2082. }
  2083. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2084. if (document.isHome) {
  2085. } else {
  2086. document.mainViewController?.batchAddBates(sender)
  2087. }
  2088. }
  2089. }
  2090. @IBAction func batchRemoveBates(_ sender: Any?) {
  2091. if (self.canResponseDocumentAction() == false) {
  2092. return
  2093. }
  2094. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2095. if (document.isHome) {
  2096. } else {
  2097. document.mainViewController?.batchRemoveBates(sender)
  2098. }
  2099. }
  2100. }
  2101. @IBAction func templateBates(_ sender: Any?) {
  2102. if (self.canResponseDocumentAction() == false) {
  2103. return
  2104. }
  2105. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2106. if (document.isHome) {
  2107. } else {
  2108. document.mainViewController?.templateBates(sender)
  2109. }
  2110. }
  2111. }
  2112. @IBAction func togglePoster(_ sender: Any?) {
  2113. if (self.canResponseDocumentAction() == false) {
  2114. return
  2115. }
  2116. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2117. if (document.isHome) {
  2118. } else {
  2119. document.mainViewController?.togglePoster(sender)
  2120. }
  2121. }
  2122. }
  2123. @IBAction func toggleMultiple(_ sender: Any?) {
  2124. if (self.canResponseDocumentAction() == false) {
  2125. return
  2126. }
  2127. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2128. if (document.isHome) {
  2129. } else {
  2130. document.mainViewController?.toggleMultiple(sender)
  2131. }
  2132. }
  2133. }
  2134. @IBAction func toggleBooklet(_ sender: Any?) {
  2135. if (self.canResponseDocumentAction() == false) {
  2136. return
  2137. }
  2138. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2139. if (document.isHome) {
  2140. } else {
  2141. document.mainViewController?.toggleBooklet(sender)
  2142. }
  2143. }
  2144. }
  2145. @IBAction func rotateRight(_ sender: Any?) {
  2146. if (self.canResponseDocumentAction() == false) {
  2147. return
  2148. }
  2149. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2150. if (document.isHome) {
  2151. } else {
  2152. document.mainViewController?.rotateRight(sender)
  2153. }
  2154. }
  2155. }
  2156. @IBAction func rotateLeft(_ sender: Any?) {
  2157. if (self.canResponseDocumentAction() == false) {
  2158. return
  2159. }
  2160. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2161. if (document.isHome) {
  2162. } else {
  2163. document.mainViewController?.rotateLeft(sender)
  2164. }
  2165. }
  2166. }
  2167. @IBAction func rotateAllRight(_ sender: Any?) {
  2168. if (self.canResponseDocumentAction() == false) {
  2169. return
  2170. }
  2171. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2172. if (document.isHome) {
  2173. } else {
  2174. document.mainViewController?.rotateAllRight(sender)
  2175. }
  2176. }
  2177. }
  2178. @IBAction func rotateAllLeft(_ sender: Any?) {
  2179. if (self.canResponseDocumentAction() == false) {
  2180. return
  2181. }
  2182. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2183. if (document.isHome) {
  2184. } else {
  2185. document.mainViewController?.rotateAllLeft(sender)
  2186. }
  2187. }
  2188. }
  2189. @IBAction func autoSelectContent(_ sender: Any?) {
  2190. if (self.canResponseDocumentAction() == false) {
  2191. return
  2192. }
  2193. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2194. if (document.isHome) {
  2195. } else {
  2196. document.mainViewController?.autoSelectContent(sender)
  2197. }
  2198. }
  2199. }
  2200. }
  2201. // MARK: - KMSystemWindowMenuRrotocol
  2202. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  2203. func menuItemAction_showForwardTagPage(_ sender: Any) {
  2204. if (self.canResponseDocumentAction() == false) {
  2205. return
  2206. }
  2207. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2208. if (document.isHome) {
  2209. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  2210. } else {
  2211. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  2212. }
  2213. }
  2214. }
  2215. func menuItemAction_showNextTagPage(_ sender: Any) {
  2216. if (self.canResponseDocumentAction() == false) {
  2217. return
  2218. }
  2219. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2220. if (document.isHome) {
  2221. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  2222. } else {
  2223. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  2224. }
  2225. }
  2226. }
  2227. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  2228. if (self.canResponseDocumentAction() == false) {
  2229. return
  2230. }
  2231. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2232. if (document.isHome) {
  2233. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2234. } else {
  2235. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2236. }
  2237. }
  2238. }
  2239. func menuItemAction_mergeAllWindow(_ sender: Any) {
  2240. if (self.canResponseDocumentAction() == false) {
  2241. return
  2242. }
  2243. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2244. if (document.isHome) {
  2245. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  2246. } else {
  2247. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  2248. }
  2249. }
  2250. }
  2251. }
  2252. // MARK: - Analytics (埋点)
  2253. extension KMBrowserWindowController {
  2254. func trackEvent_upgrade() -> Void {
  2255. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  2256. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  2257. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  2258. }
  2259. }