KMBrowserWindowController.swift 87 KB

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