KMBrowserWindowController.swift 85 KB

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