KMBrowserWindowController.swift 85 KB

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