KMBrowserWindowController.swift 85 KB

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