KMBrowserWindowController.swift 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  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: NSMenuItem) {
  673. KMPrint("performFindPanelAction ...")
  674. var forward = true
  675. var findString: String?
  676. switch sender.tag {
  677. case 1:
  678. if let document = self.browser.activeTabContents() as? KMMainDocument {
  679. if document.isHome == false {
  680. document.mainViewController?.toolbarController.showFindBar()
  681. }
  682. }
  683. case 3:
  684. if let document = self.browser.activeTabContents() as? KMMainDocument {
  685. if document.isHome == false {
  686. document.mainViewController?.toolbarController.showFindString(forward: false)
  687. }
  688. }
  689. case 2:
  690. if let document = self.browser.activeTabContents() as? KMMainDocument {
  691. if document.isHome == false {
  692. document.mainViewController?.toolbarController.showFindString(forward: true)
  693. }
  694. }
  695. case 7:
  696. if let document = self.browser.activeTabContents() as? KMMainDocument {
  697. if document.isHome == false {
  698. document.mainViewController?.toolbarController.showAllAction()
  699. }
  700. }
  701. default: break
  702. }
  703. }
  704. @IBAction func scrollUp(_ sender: Any?) {
  705. KMPrint("scrollUp ...")
  706. }
  707. @IBAction func scrollDown(_ sender: Any?) {
  708. KMPrint("scrollDown ...")
  709. }
  710. @IBAction func scrollRight(_ sender: Any?) {
  711. KMPrint("scrollRight ...")
  712. }
  713. @IBAction func scrollLeft(_ sender: Any?) {
  714. KMPrint("scrollLeft ...")
  715. }
  716. @IBAction func selectSelectedNote(_ sender: Any?) {
  717. KMPrint("selectSelectedNote ...")
  718. }
  719. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  720. KMPrint("goToSelectedOutlineItem ...")
  721. }
  722. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  723. KMPrint("goToSelectedFindResults ...")
  724. }
  725. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  726. KMPrint("toggleSelectedSnapshots ...")
  727. }
  728. @IBAction func selfSignProfile(_ sender: Any?) {
  729. KMPrint("selfSignProfile ...")
  730. }
  731. @IBAction func link(_ sender: Any?) {
  732. KMPrint("link ...")
  733. }
  734. @IBAction func insertPage(_ sender: Any?) {
  735. KMPrint("insertPage ...")
  736. }
  737. @IBAction func split(_ sender: Any?) {
  738. KMPrint("split ...")
  739. }
  740. @IBAction func comparison(_ sender: Any?) {
  741. KMPrint("comparison ...")
  742. }
  743. @IBAction func contentComparison(_ sender: Any?) {
  744. KMPrint("contentComparison ...")
  745. }
  746. @IBAction func coverageComparison(_ sender: Any?) {
  747. KMPrint("coverageComparison ...")
  748. }
  749. @IBAction func readMode(_ sender: Any?) {
  750. KMPrint("readMode ...")
  751. }
  752. @IBAction func changeFormType(_ sender: Any?) {
  753. KMPrint("changeFormType ...")
  754. }
  755. @IBAction func changeSelfSignType(_ sender: Any?) {
  756. KMPrint("changeSelfSignType ...")
  757. }
  758. @IBAction func clearAllForm(_ sender: Any?) {
  759. KMPrint("clearAllForm ...")
  760. }
  761. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  762. KMPrint("thumbnailSizeScaling ...")
  763. }
  764. @IBAction func redactAction(_ sender: Any?) {
  765. if (self.canResponseDocumentAction() == false) {
  766. return
  767. }
  768. if let document = self.browser.activeTabContents() as? KMMainDocument {
  769. if document.isHome == false {
  770. document.mainViewController?.menuItemAction_redact(sender)
  771. }
  772. }
  773. }
  774. }
  775. // MARK: - KMSystemFileMenuProtocol
  776. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  777. func menuItemClick_saveAsFlattenedPDF(_ 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_mergePDF(sender)
  784. } else {
  785. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  786. }
  787. }
  788. }
  789. func menuItemClick_mergePDF(_ 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?.menuItemClick_mergePDF(sender)
  796. } else {
  797. document.mainViewController?.menuItemClick_mergePDF(sender)
  798. }
  799. }
  800. }
  801. func menuItemClick_Compress(_ 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?.menuItemClick_Compress(sender)
  808. } else {
  809. document.mainViewController?.menuItemClick_Compress(sender)
  810. }
  811. }
  812. }
  813. func menuItemAction_ConvertToWord(_ 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_ConvertToWord(sender)
  820. } else {
  821. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  822. }
  823. }
  824. }
  825. func menuItemAction_ConvertToExcel(_ 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_ConvertToExcel(sender)
  832. } else {
  833. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  834. }
  835. }
  836. }
  837. func menuItemAction_ConvertToPPT(_ 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_ConvertToPPT(sender)
  844. } else {
  845. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  846. }
  847. }
  848. }
  849. func menuItemAction_ConvertToRTF(_ 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_ConvertToRTF(sender)
  856. } else {
  857. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  858. }
  859. }
  860. }
  861. func menuItemAction_ConvertToHTML(_ 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_ConvertToHTML(sender)
  868. } else {
  869. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  870. }
  871. }
  872. }
  873. func menuItemAction_ConvertToText(_ 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_ConvertToText(sender)
  880. } else {
  881. document.mainViewController?.menuItemAction_ConvertToText(sender)
  882. }
  883. }
  884. }
  885. func menuItemAction_ConvertToCSV(_ 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?.menuItemAction_ConvertToCSV(sender)
  892. } else {
  893. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  894. }
  895. }
  896. }
  897. func menuItemAction_ConvertToImage(_ sender: Any) {
  898. if (self.canResponseDocumentAction() == false) {
  899. return
  900. }
  901. if let document = self.browser.activeTabContents() as? KMMainDocument {
  902. if (document.isHome) {
  903. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  904. } else {
  905. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  906. }
  907. }
  908. }
  909. func menuItemClick_SettingPassword(_ sender: Any) {
  910. if (self.canResponseDocumentAction() == false) {
  911. return
  912. }
  913. if let document = self.browser.activeTabContents() as? KMMainDocument {
  914. if (document.isHome) {
  915. document.homeViewController?.menuItemClick_SettingPassword(sender)
  916. } else {
  917. document.mainViewController?.menuItemClick_SettingPassword(sender)
  918. }
  919. }
  920. }
  921. func menuItemClick_RemovePassword(_ sender: Any) {
  922. if (self.canResponseDocumentAction() == false) {
  923. return
  924. }
  925. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  926. document.mainViewController?.menuItemClick_RemovePassword(sender)
  927. }
  928. }
  929. func menuItemAction_closeWindow(_ sender: Any) {
  930. if (self.canResponseDocumentAction() == false) {
  931. return
  932. }
  933. if let document = self.browser.activeTabContents() as? KMMainDocument {
  934. if (document.isHome) {
  935. document.homeViewController?.menuItemAction_closeWindow(sender)
  936. } else {
  937. document.mainViewController?.menuItemAction_closeWindow(sender)
  938. }
  939. }
  940. }
  941. func menuItemAction_closeAllWindows(_ sender: Any) {
  942. if (self.canResponseDocumentAction() == false) {
  943. return
  944. }
  945. if let document = self.browser.activeTabContents() as? KMMainDocument {
  946. if (document.isHome) {
  947. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  948. } else {
  949. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  950. }
  951. }
  952. }
  953. func menuItemAction_closeTagPage(_ 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_closeTagPage(sender)
  959. }
  960. }
  961. func menuItemAction_showInFinder(_ sender: Any) {
  962. if (self.canResponseDocumentAction() == false) {
  963. return
  964. }
  965. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  966. document.mainViewController?.menuItemAction_showInFinder(sender)
  967. }
  968. }
  969. func menuItemAction_property(_ sender: Any) {
  970. if (self.canResponseDocumentAction() == false) {
  971. return
  972. }
  973. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  974. document.mainViewController?.menuItemAction_property(sender)
  975. }
  976. }
  977. func menuItemAction_print(_ sender: Any) {
  978. if (self.canResponseDocumentAction() == false) {
  979. return
  980. }
  981. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  982. document.mainViewController?.menuItemAction_print(sender)
  983. }
  984. }
  985. @IBAction func newDocumentFromClipboard(_ sender: Any?) {
  986. KMPrint("newDocumentFromClipboard")
  987. }
  988. @IBAction func newDocumentFromImage(_ sender: Any?) {
  989. KMPrint("importFromWebPage")
  990. }
  991. @IBAction func importFromWebPage(_ sender: Any?) {
  992. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  993. if (document.isHome) {
  994. document.homeViewController?.importFromWebPage()
  995. } else {
  996. self.homeVC = KMHomeViewController()
  997. self.homeVC?.importFromWebPage()
  998. }
  999. }
  1000. @IBAction func screenShot_SelectArea(_ sender: Any?) {
  1001. KMPrint("screenShot_SelectArea")
  1002. }
  1003. @IBAction func screenShot_Window(_ sender: Any?) {
  1004. KMPrint("screenShot_Window")
  1005. }
  1006. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  1007. KMPrint("screenShot_FullScreenDelay")
  1008. }
  1009. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  1010. KMPrint("screenShot_FullScreen")
  1011. }
  1012. }
  1013. // MARK: - KMSystemViewMenuProtocol
  1014. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  1015. func menuItemAction_adjustWidth(_ 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_adjustWidth(sender)
  1021. }
  1022. }
  1023. func menuItemAction_adjustPage(_ 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_adjustPage(sender)
  1029. }
  1030. }
  1031. func menuItemAction_size(_ 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_size(sender)
  1037. }
  1038. }
  1039. func menuItemAction_zoomOut(_ 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_zoomOut(sender)
  1045. }
  1046. }
  1047. func menuItemAction_zoomIn(_ 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_zoomIn(sender)
  1053. }
  1054. }
  1055. func menuItemAction_singlePage(_ 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_singlePage(sender)
  1061. }
  1062. }
  1063. func menuItemAction_singlePageContinue(_ 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_singlePageContinue(sender)
  1069. }
  1070. }
  1071. func menuItemAction_doublePage(_ 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_doublePage(sender)
  1077. }
  1078. }
  1079. func menuItemAction_doublePageContinue(_ 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_doublePageContinue(sender)
  1085. }
  1086. }
  1087. func menuItemAction_bookMode(_ 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_bookMode(sender)
  1093. }
  1094. }
  1095. func menuItemAction_readMode(_ 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_readMode(sender)
  1101. }
  1102. }
  1103. func menuItemAction_showSplitPage(_ 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_showSplitPage(sender)
  1109. }
  1110. }
  1111. func menuItemAction_rotateLeft(_ 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_rotateLeft(sender)
  1117. }
  1118. }
  1119. func menuItemAction_rotateRight(_ 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_rotateRight(sender)
  1125. }
  1126. }
  1127. func menuItemAction_rotateAllPageLeft(_ 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_rotateAllPageLeft(sender)
  1133. }
  1134. }
  1135. func menuItemAction_rotateAllPageRight(_ 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_rotateAllPageRight(sender)
  1141. }
  1142. }
  1143. func menuItemAction_view_readMode(_ 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_view_readMode(sender)
  1149. }
  1150. }
  1151. func menuItemAction_hiddenLeftSide(_ 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_hiddenLeftSide(sender)
  1157. }
  1158. }
  1159. func menuItemAction_hiddenRightSide(_ 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_hiddenRightSide(sender)
  1165. }
  1166. }
  1167. func menuItemAction_thumai(_ 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_thumai(sender)
  1173. }
  1174. }
  1175. func menuItemAction_outline(_ 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_outline(sender)
  1181. }
  1182. }
  1183. func menuItemAction_bookmark(_ 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_bookmark(sender)
  1189. }
  1190. }
  1191. func menuItemAction_annotation(_ 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?.menuItemAction_annotation(sender)
  1197. }
  1198. }
  1199. func menuItemAction_search(_ 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?.menuItemAction_search(sender)
  1205. }
  1206. }
  1207. func menuItemAction_hiddenPageIndicator(_ 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?.menuItemAction_hiddenPageIndicator(sender)
  1213. }
  1214. }
  1215. @IBAction func togglePresentation(_ 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?.togglePresentation(sender)
  1221. }
  1222. }
  1223. @IBAction func chooseTransition(_ 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?.chooseTransition(sender)
  1229. }
  1230. }
  1231. @IBAction func toggleAutoFlow(_ 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?.toggleAutoFlow(sender)
  1237. }
  1238. }
  1239. @IBAction func chooseAutoFlowSetting(_ 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?.chooseAutoFlowSetting(sender)
  1245. }
  1246. }
  1247. @IBAction func toggleReadingBar(_ 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?.toggleReadingBar(sender)
  1253. }
  1254. }
  1255. @IBAction func toggleLeftSidePane(_ 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?.toggleLeftSidePane(sender)
  1261. }
  1262. }
  1263. @IBAction func changeLeftSidePaneState(_ 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?.changeLeftSidePaneState(sender)
  1269. }
  1270. }
  1271. @IBAction func splitViewAction(_ 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?.splitViewAction(sender)
  1277. }
  1278. }
  1279. @IBAction func themesColor(_ sender: Any?) {
  1280. if (self.canResponseDocumentAction() == false) {
  1281. return
  1282. }
  1283. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1284. document.mainViewController?.themesColor(sender)
  1285. }
  1286. }
  1287. @IBAction func toggleStatusBar(_ sender: Any?) {
  1288. if (self.canResponseDocumentAction() == false) {
  1289. return
  1290. }
  1291. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1292. document.mainViewController?.toggleStatusBar(sender)
  1293. }
  1294. }
  1295. @IBAction func toggleToolbarShow(_ sender: Any?) {
  1296. if (self.canResponseDocumentAction() == false) {
  1297. return
  1298. }
  1299. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1300. document.mainViewController?.toggleToolbarShow(sender)
  1301. }
  1302. }
  1303. }
  1304. // MARK: - KMSystemEditMenuProtocol
  1305. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1306. func menuItemAction_find(_ sender: Any) {
  1307. if (self.canResponseDocumentAction() == false) {
  1308. return
  1309. }
  1310. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1311. document.mainViewController?.menuItemAction_find(sender)
  1312. }
  1313. }
  1314. @IBAction func changeFont(_ sender: Any?) {
  1315. KMPrint("changeFont ...")
  1316. }
  1317. }
  1318. // MARK: - Annotation Menu
  1319. extension KMBrowserWindowController {
  1320. @IBAction func menuItemAction_highlight(_ 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_highlight(sender)
  1326. }
  1327. }
  1328. @IBAction func menuItemAction_underline(_ 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_underline(sender)
  1334. }
  1335. }
  1336. @IBAction func menuItemAction_deleteLine(_ 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_deleteLine(sender)
  1342. }
  1343. }
  1344. @IBAction func menuItemAction_freehand(_ 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_freehand(sender)
  1350. }
  1351. }
  1352. @IBAction func menuItemAction_text(_ 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_text(sender)
  1358. }
  1359. }
  1360. @IBAction func menuItemAction_note(_ 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_note(sender)
  1366. }
  1367. }
  1368. @IBAction func menuItemAction_squre(_ 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_squre(sender)
  1374. }
  1375. }
  1376. @IBAction func menuItemAction_circle(_ sender: Any) {
  1377. if (self.canResponseDocumentAction() == false) {
  1378. return
  1379. }
  1380. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1381. document.mainViewController?.menuItemAction_circle(sender)
  1382. }
  1383. }
  1384. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1385. if (self.canResponseDocumentAction() == false) {
  1386. return
  1387. }
  1388. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1389. document.mainViewController?.menuItemAction_arrow(sender)
  1390. }
  1391. }
  1392. @IBAction func menuItemAction_line(_ sender: Any) {
  1393. if (self.canResponseDocumentAction() == false) {
  1394. return
  1395. }
  1396. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1397. document.mainViewController?.menuItemAction_line(sender)
  1398. }
  1399. }
  1400. // link
  1401. @IBAction func menuItemAction_link(_ sender: Any) {
  1402. if (self.canResponseDocumentAction() == false) {
  1403. return
  1404. }
  1405. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1406. document.mainViewController?.menuItemAction_link(sender)
  1407. }
  1408. }
  1409. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1410. if (self.canResponseDocumentAction() == false) {
  1411. return
  1412. }
  1413. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1414. document.mainViewController?.menuItemAction_linkPage(sender)
  1415. }
  1416. }
  1417. // stamp
  1418. @IBAction func menuItemAction_stamp(_ 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_stamp(sender)
  1424. }
  1425. }
  1426. @IBAction func menuItemAction_signure(_ sender: Any) {
  1427. if (self.canResponseDocumentAction() == false) {
  1428. return
  1429. }
  1430. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1431. document.mainViewController?.menuItemAction_signure(sender)
  1432. }
  1433. }
  1434. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1435. if (self.canResponseDocumentAction() == false) {
  1436. return
  1437. }
  1438. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1439. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1440. }
  1441. }
  1442. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1443. if (self.canResponseDocumentAction() == false) {
  1444. return
  1445. }
  1446. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1447. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1448. }
  1449. }
  1450. }
  1451. // MARK: - KMSystemPDFMenuProtocol
  1452. extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
  1453. @IBAction func changeDisplayMode(_ 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?.changeDisplayMode(sender)
  1459. }
  1460. }
  1461. @IBAction func toggleDisplayAsBook(_ 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?.toggleDisplayAsBook(sender)
  1467. }
  1468. }
  1469. @IBAction func toggleDisplayPageBreaks(_ 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?.toggleDisplayPageBreaks(sender)
  1475. }
  1476. }
  1477. @IBAction func changeDisplayBox(_ 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?.changeDisplayBox(sender)
  1483. }
  1484. }
  1485. @IBAction func toggleAutoScale(_ 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?.toggleAutoScale(sender)
  1491. }
  1492. }
  1493. @IBAction func doZoomToActualSize(_ 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?.doZoomToActualSize(sender)
  1499. }
  1500. }
  1501. @IBAction func doZoomToFit(_ 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?.doZoomToFit(sender)
  1507. }
  1508. }
  1509. @IBAction func doZoomIn(_ 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?.doZoomIn(sender)
  1515. }
  1516. }
  1517. @IBAction func doZoomOut(_ 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?.doZoomOut(sender)
  1523. }
  1524. }
  1525. @IBAction func doMarqueeZoomTool(_ 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?.doMarqueeZoomTool(sender)
  1531. }
  1532. }
  1533. @IBAction func highlightFormFiled(_ 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?.highlightFormFiled(sender)
  1539. }
  1540. }
  1541. @IBAction func highlightLinks(_ 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?.highlightLinks(sender)
  1547. }
  1548. }
  1549. @IBAction func resetForm(_ sender: Any?) {
  1550. if (self.canResponseDocumentAction() == false) {
  1551. return
  1552. }
  1553. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1554. document.mainViewController?.resetForm(sender)
  1555. }
  1556. }
  1557. @IBAction func removeAllAnnotation(_ sender: Any?) {
  1558. if (self.canResponseDocumentAction() == false) {
  1559. return
  1560. }
  1561. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1562. document.mainViewController?.removeAllAnnotation(sender)
  1563. }
  1564. }
  1565. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  1566. if (self.canResponseDocumentAction() == false) {
  1567. return
  1568. }
  1569. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1570. document.mainViewController?.savePDFSettingToDefaults(sender)
  1571. }
  1572. }
  1573. }
  1574. // MARK: - KMSystemGotoMenuProtocol
  1575. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1576. func menuItemAction_nextPage(_ 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_nextPage(sender)
  1582. }
  1583. }
  1584. func menuItemAction_forwardPage(_ 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_forwardPage(sender)
  1590. }
  1591. }
  1592. func menuItemAction_firstPage(_ 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_firstPage(sender)
  1598. }
  1599. }
  1600. func menuItemAction_lastPage(_ 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_lastPage(sender)
  1606. }
  1607. }
  1608. func menuItemAction_forward(_ 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?.menuItemAction_forward(sender)
  1614. }
  1615. }
  1616. func menuItemAction_goback(_ 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?.menuItemAction_goback(sender)
  1622. }
  1623. }
  1624. func menuItemAction_gotoPage(_ sender: Any) {
  1625. if (self.canResponseDocumentAction() == false) {
  1626. return
  1627. }
  1628. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1629. document.mainViewController?.menuItemAction_gotoPage(sender)
  1630. }
  1631. }
  1632. @IBAction func goToMarkedPage(_ sender: Any?) {
  1633. if (self.canResponseDocumentAction() == false) {
  1634. return
  1635. }
  1636. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1637. document.mainViewController?.goToMarkedPage(sender)
  1638. }
  1639. }
  1640. @IBAction func markPage(_ sender: Any?) {
  1641. if (self.canResponseDocumentAction() == false) {
  1642. return
  1643. }
  1644. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1645. document.mainViewController?.markPage(sender)
  1646. }
  1647. }
  1648. }
  1649. // MARK: - KMSystemToolMenuProtocol
  1650. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1651. @IBAction func getInfo(_ sender: Any?) {
  1652. if (self.canResponseDocumentAction() == false) {
  1653. return
  1654. }
  1655. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1656. document.mainViewController?.getInfo(sender)
  1657. }
  1658. }
  1659. func orderFrontNotesPanel(_ sender: Any?) {
  1660. let windowC = KMNotesPanelController.shared
  1661. if let win = windowC.window {
  1662. if win.isVisible {
  1663. win.orderOut(sender)
  1664. } else {
  1665. win.orderFront(sender)
  1666. }
  1667. }
  1668. }
  1669. func menuItemAction_scrolTool(_ sender: Any) {
  1670. if (self.canResponseDocumentAction() == false) {
  1671. return
  1672. }
  1673. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1674. document.mainViewController?.menuItemAction_scrolTool(sender)
  1675. }
  1676. }
  1677. func menuItemAction_zoomOutTool(_ sender: Any) {
  1678. if (self.canResponseDocumentAction() == false) {
  1679. return
  1680. }
  1681. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1682. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1683. }
  1684. }
  1685. func menuItemAction_selectTool(_ sender: Any) {
  1686. if (self.canResponseDocumentAction() == false) {
  1687. return
  1688. }
  1689. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1690. document.mainViewController?.menuItemAction_selectTool(sender)
  1691. }
  1692. }
  1693. @IBAction func changeToolMode(_ sender: Any?) {
  1694. if (self.canResponseDocumentAction() == false) {
  1695. return
  1696. }
  1697. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1698. if (document.isHome) {
  1699. } else {
  1700. document.mainViewController?.changeToolMode(sender)
  1701. }
  1702. }
  1703. }
  1704. @IBAction func compression(_ sender: Any?) {
  1705. if (self.canResponseDocumentAction() == false) {
  1706. return
  1707. }
  1708. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1709. if (document.isHome) {
  1710. } else {
  1711. document.mainViewController?.compression(sender)
  1712. }
  1713. }
  1714. }
  1715. @IBAction func merge(_ sender: Any?) {
  1716. if (self.canResponseDocumentAction() == false) {
  1717. return
  1718. }
  1719. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1720. if (document.isHome) {
  1721. } else {
  1722. document.mainViewController?.merge(sender)
  1723. }
  1724. }
  1725. }
  1726. @IBAction func convert(_ sender: Any?) {
  1727. if (self.canResponseDocumentAction() == false) {
  1728. return
  1729. }
  1730. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1731. if (document.isHome) {
  1732. } else {
  1733. document.mainViewController?.convert(sender)
  1734. }
  1735. }
  1736. }
  1737. @IBAction func imageToPDF(_ sender: Any?) {
  1738. if (self.canResponseDocumentAction() == false) {
  1739. return
  1740. }
  1741. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1742. if (document.isHome) {
  1743. } else {
  1744. document.mainViewController?.imageToPDF(sender)
  1745. }
  1746. }
  1747. }
  1748. @IBAction func ocr(_ sender: Any?) {
  1749. if (self.canResponseDocumentAction() == false) {
  1750. return
  1751. }
  1752. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1753. if (document.isHome) {
  1754. } else {
  1755. document.mainViewController?.ocr(sender)
  1756. }
  1757. }
  1758. }
  1759. @IBAction func extractImage(_ sender: Any?) {
  1760. if (self.canResponseDocumentAction() == false) {
  1761. return
  1762. }
  1763. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1764. if (document.isHome) {
  1765. } else {
  1766. document.mainViewController?.extractImage(sender)
  1767. }
  1768. }
  1769. }
  1770. @IBAction func pageEdit(_ sender: Any?) {
  1771. if (self.canResponseDocumentAction() == false) {
  1772. return
  1773. }
  1774. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1775. if (document.isHome) {
  1776. } else {
  1777. document.mainViewController?.pageEdit(sender)
  1778. }
  1779. }
  1780. }
  1781. @IBAction func textEditAction(_ sender: Any?) {
  1782. if (self.canResponseDocumentAction() == false) {
  1783. return
  1784. }
  1785. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1786. if (document.isHome) {
  1787. } else {
  1788. document.mainViewController?.textEditAction(sender)
  1789. }
  1790. }
  1791. }
  1792. @IBAction func security(_ sender: Any?) {
  1793. if (self.canResponseDocumentAction() == false) {
  1794. return
  1795. }
  1796. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1797. if (document.isHome) {
  1798. } else {
  1799. document.mainViewController?.security(sender)
  1800. }
  1801. }
  1802. }
  1803. @IBAction func decryption(_ sender: Any?) {
  1804. if (self.canResponseDocumentAction() == false) {
  1805. return
  1806. }
  1807. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1808. if (document.isHome) {
  1809. } else {
  1810. document.mainViewController?.decryption(sender)
  1811. }
  1812. }
  1813. }
  1814. @IBAction func cropAll(_ sender: Any?) {
  1815. if (self.canResponseDocumentAction() == false) {
  1816. return
  1817. }
  1818. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1819. if (document.isHome) {
  1820. } else {
  1821. document.mainViewController?.cropAll(sender)
  1822. }
  1823. }
  1824. }
  1825. @IBAction func crop(_ sender: Any?) {
  1826. if (self.canResponseDocumentAction() == false) {
  1827. return
  1828. }
  1829. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1830. if (document.isHome) {
  1831. } else {
  1832. document.mainViewController?.crop(sender)
  1833. }
  1834. }
  1835. }
  1836. @IBAction func autoCropAll(_ sender: Any?) {
  1837. if (self.canResponseDocumentAction() == false) {
  1838. return
  1839. }
  1840. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1841. if (document.isHome) {
  1842. } else {
  1843. document.mainViewController?.autoCropAll(sender)
  1844. }
  1845. }
  1846. }
  1847. @IBAction func smartAutoCropAll(_ sender: Any?) {
  1848. if (self.canResponseDocumentAction() == false) {
  1849. return
  1850. }
  1851. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1852. if (document.isHome) {
  1853. } else {
  1854. document.mainViewController?.smartAutoCropAll(sender)
  1855. }
  1856. }
  1857. }
  1858. @IBAction func cropOptionsModel(_ sender: Any?) {
  1859. if (self.canResponseDocumentAction() == false) {
  1860. return
  1861. }
  1862. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1863. if (document.isHome) {
  1864. } else {
  1865. // document.mainViewController?.cropOptionsModel(sender)
  1866. }
  1867. }
  1868. }
  1869. @IBAction func selectToolModel(_ sender: Any?) {
  1870. if (self.canResponseDocumentAction() == false) {
  1871. return
  1872. }
  1873. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1874. if (document.isHome) {
  1875. } else {
  1876. document.mainViewController?.selectToolModel(sender)
  1877. }
  1878. }
  1879. }
  1880. @IBAction func takeSnapshot(_ sender: Any?) {
  1881. if (self.canResponseDocumentAction() == false) {
  1882. return
  1883. }
  1884. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1885. if (document.isHome) {
  1886. } else {
  1887. document.mainViewController?.takeSnapshot(sender)
  1888. }
  1889. }
  1890. }
  1891. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  1892. if (self.canResponseDocumentAction() == false) {
  1893. return
  1894. }
  1895. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1896. if (document.isHome) {
  1897. } else {
  1898. document.mainViewController?.takeSnapshotSelectContent(sender)
  1899. }
  1900. }
  1901. }
  1902. @IBAction func changeAnnotationMode(_ sender: Any?) {
  1903. if (self.canResponseDocumentAction() == false) {
  1904. return
  1905. }
  1906. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1907. if (document.isHome) {
  1908. } else {
  1909. document.mainViewController?.changeAnnotationMode(sender)
  1910. }
  1911. }
  1912. }
  1913. @IBAction func addBackground(_ sender: Any?) {
  1914. if (self.canResponseDocumentAction() == false) {
  1915. return
  1916. }
  1917. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1918. if (document.isHome) {
  1919. } else {
  1920. document.mainViewController?.addBackground(sender)
  1921. }
  1922. }
  1923. }
  1924. @IBAction func removeBackground(_ sender: Any?) {
  1925. if (self.canResponseDocumentAction() == false) {
  1926. return
  1927. }
  1928. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1929. if (document.isHome) {
  1930. } else {
  1931. document.mainViewController?.removeBackground(sender)
  1932. }
  1933. }
  1934. }
  1935. @IBAction func addWatermark(_ sender: Any?) {
  1936. if (self.canResponseDocumentAction() == false) {
  1937. return
  1938. }
  1939. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1940. if (document.isHome) {
  1941. } else {
  1942. document.mainViewController?.addWatermark(sender)
  1943. }
  1944. }
  1945. }
  1946. @IBAction func editWatermark(_ sender: Any?) {
  1947. KMPrint("editWatermark ...")
  1948. }
  1949. @IBAction func batchAddWatermark(_ sender: Any?) {
  1950. if (self.canResponseDocumentAction() == false) {
  1951. return
  1952. }
  1953. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1954. if (document.isHome) {
  1955. } else {
  1956. document.mainViewController?.batchAddWatermark(sender)
  1957. }
  1958. }
  1959. }
  1960. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  1961. if (self.canResponseDocumentAction() == false) {
  1962. return
  1963. }
  1964. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1965. if (document.isHome) {
  1966. } else {
  1967. document.mainViewController?.batchRemoveWatermark(sender)
  1968. }
  1969. }
  1970. }
  1971. @IBAction func removeWatermark(_ sender: Any?) {
  1972. if (self.canResponseDocumentAction() == false) {
  1973. return
  1974. }
  1975. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1976. if (document.isHome) {
  1977. } else {
  1978. document.mainViewController?.removeWatermark(sender)
  1979. }
  1980. }
  1981. }
  1982. @IBAction func templateWatermark(_ sender: Any?) {
  1983. if (self.canResponseDocumentAction() == false) {
  1984. return
  1985. }
  1986. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1987. if (document.isHome) {
  1988. } else {
  1989. document.mainViewController?.templateWatermark(sender)
  1990. }
  1991. }
  1992. }
  1993. @IBAction func batchAddBackground(_ sender: Any?) {
  1994. if (self.canResponseDocumentAction() == false) {
  1995. return
  1996. }
  1997. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1998. if (document.isHome) {
  1999. } else {
  2000. document.mainViewController?.batchAddBackground(sender)
  2001. }
  2002. }
  2003. }
  2004. @IBAction func batchRemoveBackground(_ sender: Any?) {
  2005. if (self.canResponseDocumentAction() == false) {
  2006. return
  2007. }
  2008. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2009. if (document.isHome) {
  2010. } else {
  2011. document.mainViewController?.batchRemoveBackground(sender)
  2012. }
  2013. }
  2014. }
  2015. @IBAction func templateBackground(_ sender: Any?) {
  2016. if (self.canResponseDocumentAction() == false) {
  2017. return
  2018. }
  2019. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2020. if (document.isHome) {
  2021. } else {
  2022. document.mainViewController?.templateBackground(sender)
  2023. }
  2024. }
  2025. }
  2026. @IBAction func addHeaderFooter(_ sender: Any?) {
  2027. if (self.canResponseDocumentAction() == false) {
  2028. return
  2029. }
  2030. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2031. if (document.isHome) {
  2032. } else {
  2033. document.mainViewController?.addHeaderFooter(sender)
  2034. }
  2035. }
  2036. }
  2037. @IBAction func removeHeaderFooter(_ sender: Any?) {
  2038. if (self.canResponseDocumentAction() == false) {
  2039. return
  2040. }
  2041. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2042. if (document.isHome) {
  2043. } else {
  2044. document.mainViewController?.removeHeaderFooter(sender)
  2045. }
  2046. }
  2047. }
  2048. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  2049. if (self.canResponseDocumentAction() == false) {
  2050. return
  2051. }
  2052. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2053. if (document.isHome) {
  2054. } else {
  2055. document.mainViewController?.batchAddHeaderFooter(sender)
  2056. }
  2057. }
  2058. }
  2059. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  2060. if (self.canResponseDocumentAction() == false) {
  2061. return
  2062. }
  2063. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2064. if (document.isHome) {
  2065. } else {
  2066. document.mainViewController?.batchRemoveHeaderFooter(sender)
  2067. }
  2068. }
  2069. }
  2070. @IBAction func templateHeaderFooter(_ sender: Any?) {
  2071. if (self.canResponseDocumentAction() == false) {
  2072. return
  2073. }
  2074. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2075. if (document.isHome) {
  2076. } else {
  2077. document.mainViewController?.templateHeaderFooter(sender)
  2078. }
  2079. }
  2080. }
  2081. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  2082. if (self.canResponseDocumentAction() == false) {
  2083. return
  2084. }
  2085. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2086. if (document.isHome) {
  2087. } else {
  2088. document.mainViewController?.addHeaderFooterBates(sender)
  2089. }
  2090. }
  2091. }
  2092. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  2093. if (self.canResponseDocumentAction() == false) {
  2094. return
  2095. }
  2096. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2097. if (document.isHome) {
  2098. } else {
  2099. document.mainViewController?.removeHeaderFooterBates(sender)
  2100. }
  2101. }
  2102. }
  2103. @IBAction func batchAddBates(_ sender: Any?) {
  2104. if (self.canResponseDocumentAction() == false) {
  2105. return
  2106. }
  2107. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2108. if (document.isHome) {
  2109. } else {
  2110. document.mainViewController?.batchAddBates(sender)
  2111. }
  2112. }
  2113. }
  2114. @IBAction func batchRemoveBates(_ sender: Any?) {
  2115. if (self.canResponseDocumentAction() == false) {
  2116. return
  2117. }
  2118. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2119. if (document.isHome) {
  2120. } else {
  2121. document.mainViewController?.batchRemoveBates(sender)
  2122. }
  2123. }
  2124. }
  2125. @IBAction func templateBates(_ sender: Any?) {
  2126. if (self.canResponseDocumentAction() == false) {
  2127. return
  2128. }
  2129. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2130. if (document.isHome) {
  2131. } else {
  2132. document.mainViewController?.templateBates(sender)
  2133. }
  2134. }
  2135. }
  2136. @IBAction func togglePoster(_ sender: Any?) {
  2137. if (self.canResponseDocumentAction() == false) {
  2138. return
  2139. }
  2140. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2141. if (document.isHome) {
  2142. } else {
  2143. document.mainViewController?.togglePoster(sender)
  2144. }
  2145. }
  2146. }
  2147. @IBAction func toggleMultiple(_ sender: Any?) {
  2148. if (self.canResponseDocumentAction() == false) {
  2149. return
  2150. }
  2151. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2152. if (document.isHome) {
  2153. } else {
  2154. document.mainViewController?.toggleMultiple(sender)
  2155. }
  2156. }
  2157. }
  2158. @IBAction func toggleBooklet(_ sender: Any?) {
  2159. if (self.canResponseDocumentAction() == false) {
  2160. return
  2161. }
  2162. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2163. if (document.isHome) {
  2164. } else {
  2165. document.mainViewController?.toggleBooklet(sender)
  2166. }
  2167. }
  2168. }
  2169. @IBAction func rotateRight(_ sender: Any?) {
  2170. if (self.canResponseDocumentAction() == false) {
  2171. return
  2172. }
  2173. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2174. if (document.isHome) {
  2175. } else {
  2176. document.mainViewController?.rotateRight(sender)
  2177. }
  2178. }
  2179. }
  2180. @IBAction func rotateLeft(_ sender: Any?) {
  2181. if (self.canResponseDocumentAction() == false) {
  2182. return
  2183. }
  2184. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2185. if (document.isHome) {
  2186. } else {
  2187. document.mainViewController?.rotateLeft(sender)
  2188. }
  2189. }
  2190. }
  2191. @IBAction func rotateAllRight(_ sender: Any?) {
  2192. if (self.canResponseDocumentAction() == false) {
  2193. return
  2194. }
  2195. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2196. if (document.isHome) {
  2197. } else {
  2198. document.mainViewController?.rotateAllRight(sender)
  2199. }
  2200. }
  2201. }
  2202. @IBAction func rotateAllLeft(_ sender: Any?) {
  2203. if (self.canResponseDocumentAction() == false) {
  2204. return
  2205. }
  2206. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2207. if (document.isHome) {
  2208. } else {
  2209. document.mainViewController?.rotateAllLeft(sender)
  2210. }
  2211. }
  2212. }
  2213. @IBAction func autoSelectContent(_ sender: Any?) {
  2214. if (self.canResponseDocumentAction() == false) {
  2215. return
  2216. }
  2217. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2218. if (document.isHome) {
  2219. } else {
  2220. document.mainViewController?.autoSelectContent(sender)
  2221. }
  2222. }
  2223. }
  2224. }
  2225. // MARK: - KMSystemWindowMenuRrotocol
  2226. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  2227. func menuItemAction_showForwardTagPage(_ 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_showForwardTagPage(sender)
  2234. } else {
  2235. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  2236. }
  2237. }
  2238. }
  2239. func menuItemAction_showNextTagPage(_ 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_showNextTagPage(sender)
  2246. } else {
  2247. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  2248. }
  2249. }
  2250. }
  2251. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  2252. if (self.canResponseDocumentAction() == false) {
  2253. return
  2254. }
  2255. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2256. if (document.isHome) {
  2257. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2258. } else {
  2259. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2260. }
  2261. }
  2262. }
  2263. func menuItemAction_mergeAllWindow(_ sender: Any) {
  2264. if (self.canResponseDocumentAction() == false) {
  2265. return
  2266. }
  2267. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2268. if (document.isHome) {
  2269. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  2270. } else {
  2271. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  2272. }
  2273. }
  2274. }
  2275. }
  2276. // MARK: - Analytics (埋点)
  2277. extension KMBrowserWindowController {
  2278. func trackEvent_upgrade() -> Void {
  2279. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  2280. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  2281. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  2282. }
  2283. }