KMBrowserWindowController.swift 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  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. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  403. }
  404. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  405. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  406. }
  407. if (KMSystemMenu.isGotoSelector(sel: action)) {
  408. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  409. }
  410. if (KMSystemMenu.isToolSelector(sel: action)) {
  411. if action == KMSystemMenu.Tool.orderFrontNotesPanelSelector {
  412. if KMNotesPanelController.sharedControllerExists() {
  413. if let data = KMNotesPanelController.shared.window?.isVisible, data {
  414. menuItem.title = NSLocalizedString("Hide Note Type", comment: "Menu item title")
  415. } else {
  416. menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
  417. }
  418. } else {
  419. menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
  420. }
  421. return true
  422. } else {
  423. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  424. }
  425. }
  426. if (KMSystemMenu.isWindowSelector(sel: action)) {
  427. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  428. }
  429. if action == #selector(redactAction) {
  430. return document.isHome ? false : true
  431. }
  432. return true
  433. }
  434. }
  435. extension KMBrowserWindowController {
  436. @IBAction func menuItemAction_openFile(_ sender: Any) {
  437. super.openDocument(sender)
  438. }
  439. @IBAction func importFromFile(_ sender: Any) {
  440. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  441. if (document.isHome) {
  442. document.homeViewController?.importFromFile(sender)
  443. } else {
  444. self.homeVC = KMHomeViewController()
  445. self.homeVC?.importFromFile(sender)
  446. }
  447. }
  448. @IBAction func openBlankPage(_ sender: Any) {
  449. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  450. if (document.isHome) {
  451. document.homeViewController?.openBlankPage()
  452. } else {
  453. self.homeVC = KMHomeViewController()
  454. self.homeVC?.openBlankPage()
  455. }
  456. }
  457. @IBAction func importFromScanner(_ sender: Any) {
  458. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  459. if (document.isHome) {
  460. document.homeViewController?.importFromScanner()
  461. } else {
  462. self.homeVC = KMHomeViewController()
  463. self.homeVC?.importFromScanner()
  464. }
  465. }
  466. @IBAction func menuItemAction_newTab(_ sender: Any) {
  467. self.openDocumentWindow()
  468. }
  469. /// New
  470. @IBAction func newDocumentFromClipboard(_ sender: Any?) {
  471. KMPrint("newDocumentFromClipboard")
  472. }
  473. @IBAction func newDocumentFromImage(_ sender: Any?) {
  474. KMPrint("importFromWebPage")
  475. }
  476. @IBAction func importFromWebPage(_ sender: Any?) {
  477. KMPrint("importFromWebPage")
  478. }
  479. /// screenShot
  480. @IBAction func screenShot_SelectArea(_ sender: Any?) {
  481. KMPrint("screenShot_SelectArea")
  482. }
  483. @IBAction func screenShot_Window(_ sender: Any?) {
  484. KMPrint("screenShot_Window")
  485. }
  486. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  487. KMPrint("screenShot_FullScreenDelay")
  488. }
  489. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  490. KMPrint("screenShot_FullScreen")
  491. }
  492. @IBAction func pasteAsPlainText(_ sender: Any?) {
  493. KMPrint("pasteAsPlainText")
  494. }
  495. @IBAction func deselectAll(_ sender: Any?) {
  496. KMPrint("deselectAll")
  497. }
  498. @IBAction func searchPDF(_ sender: Any?) {
  499. KMPrint("searchPDF")
  500. }
  501. @IBAction func notesLink(_ sender: Any?) {
  502. KMPrint("notesLink")
  503. }
  504. @IBAction func notesStamp(_ sender: Any?) {
  505. KMPrint("notesStamp")
  506. }
  507. @IBAction func table(_ sender: Any?) {
  508. KMPrint("table ...")
  509. }
  510. @IBAction func image(_ sender: Any?) {
  511. KMPrint("image ...")
  512. }
  513. @IBAction func addForm(_ sender: Any?) {
  514. KMPrint("addForm ...")
  515. }
  516. @IBAction func editNote(_ sender: Any?) {
  517. KMPrint("editNote ...")
  518. }
  519. @IBAction func togglePresentation(_ sender: Any?) {
  520. KMPrint("togglePresentation ...")
  521. }
  522. @IBAction func chooseTransition(_ sender: Any?) {
  523. KMPrint("chooseTransition ...")
  524. }
  525. @IBAction func toggleAutoFlow(_ sender: Any?) {
  526. KMPrint("toggleAutoFlow ...")
  527. }
  528. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  529. KMPrint("chooseAutoFlowSetting ...")
  530. }
  531. @IBAction func toggleReadingBar(_ sender: Any?) {
  532. KMPrint("toggleReadingBar ...")
  533. }
  534. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  535. KMPrint("toggleLeftSidePane ...")
  536. }
  537. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  538. KMPrint("changeLeftSidePaneState ...")
  539. }
  540. @IBAction func splitViewAction(_ sender: Any?) {
  541. KMPrint("splitViewAction ...")
  542. }
  543. @IBAction func themesColor(_ sender: Any?) {
  544. KMPrint("themesColor ...")
  545. }
  546. @IBAction func toggleStatusBar(_ sender: Any?) {
  547. KMPrint("toggleStatusBar ...")
  548. }
  549. @IBAction func toggleToolbarShow(_ sender: Any?) {
  550. KMPrint("toggleToolbarShow ...")
  551. }
  552. @IBAction func changeColor(_ sender: Any?) {
  553. KMPrint("changeColor ...")
  554. }
  555. @IBAction func changeFont(_ sender: Any?) {
  556. KMPrint("changeFont ...")
  557. }
  558. @IBAction func changeAttributes(_ sender: Any?) {
  559. KMPrint("changeAttributes ...")
  560. }
  561. @IBAction func alignLeft(_ sender: Any?) {
  562. KMPrint("alignLeft ...")
  563. }
  564. @IBAction func alignRight(_ sender: Any?) {
  565. KMPrint("alignRight ...")
  566. }
  567. @IBAction func alignCenter(_ sender: Any?) {
  568. KMPrint("alignCenter ...")
  569. }
  570. @IBAction func createNewNote(_ sender: Any?) {
  571. KMPrint("createNewNote ...")
  572. }
  573. @IBAction func toggleHideNotes(_ sender: Any?) {
  574. KMPrint("toggleHideNotes ...")
  575. }
  576. @IBAction func changeDisplaySinglePages(_ sender: Any?) {
  577. KMPrint("changeDisplaySinglePages ...")
  578. }
  579. @IBAction func changeDisplayContinuous(_ sender: Any?) {
  580. KMPrint("changeDisplayContinuous ...")
  581. }
  582. @IBAction func doGoToNextPage(_ sender: Any?) {
  583. KMPrint("doGoToNextPage ...")
  584. }
  585. @IBAction func doGoToPreviousPage(_ sender: Any?) {
  586. KMPrint("doGoToPreviousPage ...")
  587. }
  588. @IBAction func doGoToFirstPage(_ sender: Any?) {
  589. KMPrint("doGoToFirstPage ...")
  590. }
  591. @IBAction func doGoToLastPage(_ sender: Any?) {
  592. KMPrint("doGoToLastPage ...")
  593. }
  594. @IBAction func allGoToNextPage(_ sender: Any?) {
  595. KMPrint("allGoToNextPage ...")
  596. }
  597. @IBAction func allGoToPreviousPage(_ sender: Any?) {
  598. KMPrint("allGoToPreviousPage ...")
  599. }
  600. @IBAction func allGoToFirstPage(_ sender: Any?) {
  601. KMPrint("allGoToFirstPage ...")
  602. }
  603. @IBAction func allGoToLastPage(_ sender: Any?) {
  604. KMPrint("allGoToLastPage ...")
  605. }
  606. @IBAction func doGoToPage(_ sender: Any?) {
  607. KMPrint("doGoToPage ...")
  608. }
  609. @IBAction func doGoBack(_ sender: Any?) {
  610. KMPrint("doGoBack ...")
  611. }
  612. @IBAction func doGoForward(_ sender: Any?) {
  613. KMPrint("doGoForward ...")
  614. }
  615. @IBAction func doZoomIn(_ sender: Any?) {
  616. KMPrint("doZoomIn ...")
  617. }
  618. @IBAction func doZoomOut(_ sender: Any?) {
  619. KMPrint("doZoomOut ...")
  620. }
  621. @IBAction func doZoomToActualSize(_ sender: Any?) {
  622. KMPrint("doZoomToActualSize ...")
  623. }
  624. @IBAction func doZoomToPhysicalSize(_ sender: Any?) {
  625. KMPrint("doZoomToPhysicalSize ...")
  626. }
  627. @IBAction func doZoomToFit(_ sender: Any?) {
  628. KMPrint("doZoomToFit ...")
  629. }
  630. @IBAction func alternateZoomToFit(_ sender: Any?) {
  631. KMPrint("alternateZoomToFit ...")
  632. }
  633. @IBAction func doZoomToSelection(_ sender: Any?) {
  634. KMPrint("doZoomToSelection ...")
  635. }
  636. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  637. KMPrint("doMarqueeZoomTool ...")
  638. }
  639. @IBAction func doAutoScale(_ sender: Any?) {
  640. KMPrint("doAutoScale ...")
  641. }
  642. // @IBAction func delete(_ sender: Any?) {
  643. // KMPrint("delete ...")
  644. // }
  645. // @IBAction func paste(_ sender: Any?) {
  646. // KMPrint("paste ...")
  647. // }
  648. @IBAction func alternatePaste(_ sender: Any?) {
  649. KMPrint("alternatePaste ...")
  650. }
  651. @IBAction func copy(_ sender: Any?) {
  652. KMPrint("copy ...")
  653. }
  654. @IBAction func cut(_ sender: Any?) {
  655. KMPrint("cut ...")
  656. }
  657. @IBAction func toggleFullscreen(_ sender: Any?) {
  658. KMPrint("toggleFullscreen ...")
  659. }
  660. @IBAction func toggleRightSidePane(_ sender: Any?) {
  661. KMPrint("toggleRightSidePane ...")
  662. }
  663. @IBAction func performFit(_ sender: Any?) {
  664. KMPrint("performFit ...")
  665. }
  666. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  667. KMPrint("changeRightSidePaneState ...")
  668. }
  669. @IBAction func changeFindPaneState(_ sender: Any?) {
  670. KMPrint("changeFindPaneState ...")
  671. }
  672. @IBAction func toggleSplitPDF(_ sender: Any?) {
  673. KMPrint("toggleSplitPDF ...")
  674. }
  675. @IBAction func search(_ sender: Any?) {
  676. KMPrint("search ...")
  677. }
  678. @IBAction func searchNotes(_ sender: Any?) {
  679. KMPrint("searchNotes ...")
  680. }
  681. @IBAction func password(_ sender: Any?) {
  682. KMPrint("password ...")
  683. }
  684. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  685. KMPrint("savePDFSettingToDefaults ...")
  686. }
  687. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  688. KMPrint("toggleCaseInsensitiveSearch ...")
  689. }
  690. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  691. KMPrint("toggleWholeWordSearch ...")
  692. }
  693. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  694. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  695. }
  696. @IBAction func performFindPanelAction(_ sender: Any?) {
  697. KMPrint("performFindPanelAction ...")
  698. }
  699. @IBAction func scrollUp(_ sender: Any?) {
  700. KMPrint("scrollUp ...")
  701. }
  702. @IBAction func scrollDown(_ sender: Any?) {
  703. KMPrint("scrollDown ...")
  704. }
  705. @IBAction func scrollRight(_ sender: Any?) {
  706. KMPrint("scrollRight ...")
  707. }
  708. @IBAction func scrollLeft(_ sender: Any?) {
  709. KMPrint("scrollLeft ...")
  710. }
  711. @IBAction func selectSelectedNote(_ sender: Any?) {
  712. KMPrint("selectSelectedNote ...")
  713. }
  714. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  715. KMPrint("goToSelectedOutlineItem ...")
  716. }
  717. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  718. KMPrint("goToSelectedFindResults ...")
  719. }
  720. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  721. KMPrint("toggleSelectedSnapshots ...")
  722. }
  723. @IBAction func selfSignProfile(_ sender: Any?) {
  724. KMPrint("selfSignProfile ...")
  725. }
  726. @IBAction func highlightFormFiled(_ sender: Any?) {
  727. KMPrint("highlightFormFiled ...")
  728. }
  729. @IBAction func highlightLinks(_ sender: Any?) {
  730. KMPrint("highlightLinks ...")
  731. }
  732. @IBAction func resetForm(_ sender: Any?) {
  733. KMPrint("resetForm ...")
  734. }
  735. @IBAction func removeAllAnnotation(_ sender: Any?) {
  736. KMPrint("removeAllAnnotation ...")
  737. }
  738. @IBAction func link(_ sender: Any?) {
  739. KMPrint("link ...")
  740. }
  741. @IBAction func insertPage(_ sender: Any?) {
  742. KMPrint("insertPage ...")
  743. }
  744. @IBAction func split(_ sender: Any?) {
  745. KMPrint("split ...")
  746. }
  747. @IBAction func comparison(_ sender: Any?) {
  748. KMPrint("comparison ...")
  749. }
  750. @IBAction func contentComparison(_ sender: Any?) {
  751. KMPrint("contentComparison ...")
  752. }
  753. @IBAction func coverageComparison(_ sender: Any?) {
  754. KMPrint("coverageComparison ...")
  755. }
  756. @IBAction func readMode(_ sender: Any?) {
  757. KMPrint("readMode ...")
  758. }
  759. @IBAction func changeFormType(_ sender: Any?) {
  760. KMPrint("changeFormType ...")
  761. }
  762. @IBAction func changeSelfSignType(_ sender: Any?) {
  763. KMPrint("changeSelfSignType ...")
  764. }
  765. @IBAction func clearAllForm(_ sender: Any?) {
  766. KMPrint("clearAllForm ...")
  767. }
  768. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  769. KMPrint("thumbnailSizeScaling ...")
  770. }
  771. @IBAction func redactAction(_ sender: Any?) {
  772. if (self.canResponseDocumentAction() == false) {
  773. return
  774. }
  775. if let document = self.browser.activeTabContents() as? KMMainDocument {
  776. if document.isHome == false {
  777. document.mainViewController?.menuItemAction_redact(sender)
  778. }
  779. }
  780. }
  781. }
  782. // MARK: - KMSystemFileMenuProtocol
  783. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  784. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  785. if (self.canResponseDocumentAction() == false) {
  786. return
  787. }
  788. if let document = self.browser.activeTabContents() as? KMMainDocument {
  789. if (document.isHome) {
  790. // document.homeViewController?.menuItemClick_mergePDF(sender)
  791. } else {
  792. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  793. }
  794. }
  795. }
  796. func menuItemClick_mergePDF(_ sender: Any) {
  797. if (self.canResponseDocumentAction() == false) {
  798. return
  799. }
  800. if let document = self.browser.activeTabContents() as? KMMainDocument {
  801. if (document.isHome) {
  802. document.homeViewController?.menuItemClick_mergePDF(sender)
  803. } else {
  804. document.mainViewController?.menuItemClick_mergePDF(sender)
  805. }
  806. }
  807. }
  808. func menuItemClick_Compress(_ sender: Any) {
  809. if (self.canResponseDocumentAction() == false) {
  810. return
  811. }
  812. if let document = self.browser.activeTabContents() as? KMMainDocument {
  813. if (document.isHome) {
  814. document.homeViewController?.menuItemClick_Compress(sender)
  815. } else {
  816. document.mainViewController?.menuItemClick_Compress(sender)
  817. }
  818. }
  819. }
  820. func menuItemAction_ConvertToWord(_ sender: Any) {
  821. if (self.canResponseDocumentAction() == false) {
  822. return
  823. }
  824. if let document = self.browser.activeTabContents() as? KMMainDocument {
  825. if (document.isHome) {
  826. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  827. } else {
  828. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  829. }
  830. }
  831. }
  832. func menuItemAction_ConvertToExcel(_ sender: Any) {
  833. if (self.canResponseDocumentAction() == false) {
  834. return
  835. }
  836. if let document = self.browser.activeTabContents() as? KMMainDocument {
  837. if (document.isHome) {
  838. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  839. } else {
  840. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  841. }
  842. }
  843. }
  844. func menuItemAction_ConvertToPPT(_ sender: Any) {
  845. if (self.canResponseDocumentAction() == false) {
  846. return
  847. }
  848. if let document = self.browser.activeTabContents() as? KMMainDocument {
  849. if (document.isHome) {
  850. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  851. } else {
  852. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  853. }
  854. }
  855. }
  856. func menuItemAction_ConvertToRTF(_ sender: Any) {
  857. if (self.canResponseDocumentAction() == false) {
  858. return
  859. }
  860. if let document = self.browser.activeTabContents() as? KMMainDocument {
  861. if (document.isHome) {
  862. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  863. } else {
  864. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  865. }
  866. }
  867. }
  868. func menuItemAction_ConvertToHTML(_ sender: Any) {
  869. if (self.canResponseDocumentAction() == false) {
  870. return
  871. }
  872. if let document = self.browser.activeTabContents() as? KMMainDocument {
  873. if (document.isHome) {
  874. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  875. } else {
  876. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  877. }
  878. }
  879. }
  880. func menuItemAction_ConvertToText(_ sender: Any) {
  881. if (self.canResponseDocumentAction() == false) {
  882. return
  883. }
  884. if let document = self.browser.activeTabContents() as? KMMainDocument {
  885. if (document.isHome) {
  886. document.homeViewController?.menuItemAction_ConvertToText(sender)
  887. } else {
  888. document.mainViewController?.menuItemAction_ConvertToText(sender)
  889. }
  890. }
  891. }
  892. func menuItemAction_ConvertToCSV(_ sender: Any) {
  893. if (self.canResponseDocumentAction() == false) {
  894. return
  895. }
  896. if let document = self.browser.activeTabContents() as? KMMainDocument {
  897. if (document.isHome) {
  898. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  899. } else {
  900. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  901. }
  902. }
  903. }
  904. func menuItemAction_ConvertToImage(_ sender: Any) {
  905. if (self.canResponseDocumentAction() == false) {
  906. return
  907. }
  908. if let document = self.browser.activeTabContents() as? KMMainDocument {
  909. if (document.isHome) {
  910. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  911. } else {
  912. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  913. }
  914. }
  915. }
  916. func menuItemClick_SettingPassword(_ sender: Any) {
  917. if (self.canResponseDocumentAction() == false) {
  918. return
  919. }
  920. if let document = self.browser.activeTabContents() as? KMMainDocument {
  921. if (document.isHome) {
  922. document.homeViewController?.menuItemClick_SettingPassword(sender)
  923. } else {
  924. document.mainViewController?.menuItemClick_SettingPassword(sender)
  925. }
  926. }
  927. }
  928. func menuItemClick_RemovePassword(_ sender: Any) {
  929. if (self.canResponseDocumentAction() == false) {
  930. return
  931. }
  932. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  933. document.mainViewController?.menuItemClick_RemovePassword(sender)
  934. }
  935. }
  936. func menuItemAction_closeWindow(_ sender: Any) {
  937. if (self.canResponseDocumentAction() == false) {
  938. return
  939. }
  940. if let document = self.browser.activeTabContents() as? KMMainDocument {
  941. if (document.isHome) {
  942. document.homeViewController?.menuItemAction_closeWindow(sender)
  943. } else {
  944. document.mainViewController?.menuItemAction_closeWindow(sender)
  945. }
  946. }
  947. }
  948. func menuItemAction_closeAllWindows(_ sender: Any) {
  949. if (self.canResponseDocumentAction() == false) {
  950. return
  951. }
  952. if let document = self.browser.activeTabContents() as? KMMainDocument {
  953. if (document.isHome) {
  954. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  955. } else {
  956. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  957. }
  958. }
  959. }
  960. func menuItemAction_closeTagPage(_ sender: Any) {
  961. if (self.canResponseDocumentAction() == false) {
  962. return
  963. }
  964. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  965. document.mainViewController?.menuItemAction_closeTagPage(sender)
  966. }
  967. }
  968. func menuItemAction_showInFinder(_ sender: Any) {
  969. if (self.canResponseDocumentAction() == false) {
  970. return
  971. }
  972. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  973. document.mainViewController?.menuItemAction_showInFinder(sender)
  974. }
  975. }
  976. func menuItemAction_property(_ sender: Any) {
  977. if (self.canResponseDocumentAction() == false) {
  978. return
  979. }
  980. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  981. document.mainViewController?.menuItemAction_property(sender)
  982. }
  983. }
  984. func menuItemAction_print(_ sender: Any) {
  985. if (self.canResponseDocumentAction() == false) {
  986. return
  987. }
  988. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  989. document.mainViewController?.menuItemAction_print(sender)
  990. }
  991. }
  992. }
  993. // MARK: - KMSystemViewMenuProtocol
  994. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  995. func menuItemAction_adjustWidth(_ sender: Any) {
  996. if (self.canResponseDocumentAction() == false) {
  997. return
  998. }
  999. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1000. document.mainViewController?.menuItemAction_adjustWidth(sender)
  1001. }
  1002. }
  1003. func menuItemAction_adjustPage(_ sender: Any) {
  1004. if (self.canResponseDocumentAction() == false) {
  1005. return
  1006. }
  1007. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1008. document.mainViewController?.menuItemAction_adjustPage(sender)
  1009. }
  1010. }
  1011. func menuItemAction_size(_ sender: Any) {
  1012. if (self.canResponseDocumentAction() == false) {
  1013. return
  1014. }
  1015. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1016. document.mainViewController?.menuItemAction_size(sender)
  1017. }
  1018. }
  1019. func menuItemAction_zoomOut(_ sender: Any) {
  1020. if (self.canResponseDocumentAction() == false) {
  1021. return
  1022. }
  1023. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1024. document.mainViewController?.menuItemAction_zoomOut(sender)
  1025. }
  1026. }
  1027. func menuItemAction_zoomIn(_ sender: Any) {
  1028. if (self.canResponseDocumentAction() == false) {
  1029. return
  1030. }
  1031. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1032. document.mainViewController?.menuItemAction_zoomIn(sender)
  1033. }
  1034. }
  1035. func menuItemAction_singlePage(_ sender: Any) {
  1036. if (self.canResponseDocumentAction() == false) {
  1037. return
  1038. }
  1039. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1040. document.mainViewController?.menuItemAction_singlePage(sender)
  1041. }
  1042. }
  1043. func menuItemAction_singlePageContinue(_ sender: Any) {
  1044. if (self.canResponseDocumentAction() == false) {
  1045. return
  1046. }
  1047. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1048. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1049. }
  1050. }
  1051. func menuItemAction_doublePage(_ sender: Any) {
  1052. if (self.canResponseDocumentAction() == false) {
  1053. return
  1054. }
  1055. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1056. document.mainViewController?.menuItemAction_doublePage(sender)
  1057. }
  1058. }
  1059. func menuItemAction_doublePageContinue(_ sender: Any) {
  1060. if (self.canResponseDocumentAction() == false) {
  1061. return
  1062. }
  1063. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1064. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1065. }
  1066. }
  1067. func menuItemAction_bookMode(_ sender: Any) {
  1068. if (self.canResponseDocumentAction() == false) {
  1069. return
  1070. }
  1071. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1072. document.mainViewController?.menuItemAction_bookMode(sender)
  1073. }
  1074. }
  1075. func menuItemAction_readMode(_ sender: Any) {
  1076. if (self.canResponseDocumentAction() == false) {
  1077. return
  1078. }
  1079. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1080. document.mainViewController?.menuItemAction_readMode(sender)
  1081. }
  1082. }
  1083. func menuItemAction_showSplitPage(_ sender: Any) {
  1084. if (self.canResponseDocumentAction() == false) {
  1085. return
  1086. }
  1087. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1088. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1089. }
  1090. }
  1091. func menuItemAction_rotateLeft(_ sender: Any) {
  1092. if (self.canResponseDocumentAction() == false) {
  1093. return
  1094. }
  1095. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1096. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1097. }
  1098. }
  1099. func menuItemAction_rotateRight(_ sender: Any) {
  1100. if (self.canResponseDocumentAction() == false) {
  1101. return
  1102. }
  1103. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1104. document.mainViewController?.menuItemAction_rotateRight(sender)
  1105. }
  1106. }
  1107. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1108. if (self.canResponseDocumentAction() == false) {
  1109. return
  1110. }
  1111. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1112. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1113. }
  1114. }
  1115. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1116. if (self.canResponseDocumentAction() == false) {
  1117. return
  1118. }
  1119. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1120. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1121. }
  1122. }
  1123. func menuItemAction_view_readMode(_ sender: Any) {
  1124. if (self.canResponseDocumentAction() == false) {
  1125. return
  1126. }
  1127. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1128. document.mainViewController?.menuItemAction_view_readMode(sender)
  1129. }
  1130. }
  1131. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1132. if (self.canResponseDocumentAction() == false) {
  1133. return
  1134. }
  1135. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1136. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1137. }
  1138. }
  1139. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1140. if (self.canResponseDocumentAction() == false) {
  1141. return
  1142. }
  1143. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1144. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1145. }
  1146. }
  1147. func menuItemAction_thumai(_ sender: Any) {
  1148. if (self.canResponseDocumentAction() == false) {
  1149. return
  1150. }
  1151. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1152. document.mainViewController?.menuItemAction_thumai(sender)
  1153. }
  1154. }
  1155. func menuItemAction_outline(_ sender: Any) {
  1156. if (self.canResponseDocumentAction() == false) {
  1157. return
  1158. }
  1159. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1160. document.mainViewController?.menuItemAction_outline(sender)
  1161. }
  1162. }
  1163. func menuItemAction_bookmark(_ sender: Any) {
  1164. if (self.canResponseDocumentAction() == false) {
  1165. return
  1166. }
  1167. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1168. document.mainViewController?.menuItemAction_bookmark(sender)
  1169. }
  1170. }
  1171. func menuItemAction_annotation(_ sender: Any) {
  1172. if (self.canResponseDocumentAction() == false) {
  1173. return
  1174. }
  1175. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1176. document.mainViewController?.menuItemAction_annotation(sender)
  1177. }
  1178. }
  1179. func menuItemAction_search(_ sender: Any) {
  1180. if (self.canResponseDocumentAction() == false) {
  1181. return
  1182. }
  1183. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1184. document.mainViewController?.menuItemAction_search(sender)
  1185. }
  1186. }
  1187. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1188. if (self.canResponseDocumentAction() == false) {
  1189. return
  1190. }
  1191. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1192. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1193. }
  1194. }
  1195. }
  1196. // MARK: - KMSystemEditMenuProtocol
  1197. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1198. func menuItemAction_find(_ sender: Any) {
  1199. if (self.canResponseDocumentAction() == false) {
  1200. return
  1201. }
  1202. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1203. document.mainViewController?.menuItemAction_find(sender)
  1204. }
  1205. }
  1206. }
  1207. // MARK: - Annotation Menu
  1208. extension KMBrowserWindowController {
  1209. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1210. if (self.canResponseDocumentAction() == false) {
  1211. return
  1212. }
  1213. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1214. document.mainViewController?.menuItemAction_highlight(sender)
  1215. }
  1216. }
  1217. @IBAction func menuItemAction_underline(_ sender: Any) {
  1218. if (self.canResponseDocumentAction() == false) {
  1219. return
  1220. }
  1221. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1222. document.mainViewController?.menuItemAction_underline(sender)
  1223. }
  1224. }
  1225. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1226. if (self.canResponseDocumentAction() == false) {
  1227. return
  1228. }
  1229. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1230. document.mainViewController?.menuItemAction_deleteLine(sender)
  1231. }
  1232. }
  1233. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1234. if (self.canResponseDocumentAction() == false) {
  1235. return
  1236. }
  1237. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1238. document.mainViewController?.menuItemAction_freehand(sender)
  1239. }
  1240. }
  1241. @IBAction func menuItemAction_text(_ sender: Any) {
  1242. if (self.canResponseDocumentAction() == false) {
  1243. return
  1244. }
  1245. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1246. document.mainViewController?.menuItemAction_text(sender)
  1247. }
  1248. }
  1249. @IBAction func menuItemAction_note(_ sender: Any) {
  1250. if (self.canResponseDocumentAction() == false) {
  1251. return
  1252. }
  1253. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1254. document.mainViewController?.menuItemAction_note(sender)
  1255. }
  1256. }
  1257. @IBAction func menuItemAction_squre(_ sender: Any) {
  1258. if (self.canResponseDocumentAction() == false) {
  1259. return
  1260. }
  1261. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1262. document.mainViewController?.menuItemAction_squre(sender)
  1263. }
  1264. }
  1265. @IBAction func menuItemAction_circle(_ sender: Any) {
  1266. if (self.canResponseDocumentAction() == false) {
  1267. return
  1268. }
  1269. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1270. document.mainViewController?.menuItemAction_circle(sender)
  1271. }
  1272. }
  1273. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1274. if (self.canResponseDocumentAction() == false) {
  1275. return
  1276. }
  1277. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1278. document.mainViewController?.menuItemAction_arrow(sender)
  1279. }
  1280. }
  1281. @IBAction func menuItemAction_line(_ sender: Any) {
  1282. if (self.canResponseDocumentAction() == false) {
  1283. return
  1284. }
  1285. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1286. document.mainViewController?.menuItemAction_line(sender)
  1287. }
  1288. }
  1289. // link
  1290. @IBAction func menuItemAction_link(_ sender: Any) {
  1291. if (self.canResponseDocumentAction() == false) {
  1292. return
  1293. }
  1294. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1295. document.mainViewController?.menuItemAction_link(sender)
  1296. }
  1297. }
  1298. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1299. if (self.canResponseDocumentAction() == false) {
  1300. return
  1301. }
  1302. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1303. document.mainViewController?.menuItemAction_linkPage(sender)
  1304. }
  1305. }
  1306. // stamp
  1307. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1308. if (self.canResponseDocumentAction() == false) {
  1309. return
  1310. }
  1311. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1312. document.mainViewController?.menuItemAction_stamp(sender)
  1313. }
  1314. }
  1315. @IBAction func menuItemAction_signure(_ sender: Any) {
  1316. if (self.canResponseDocumentAction() == false) {
  1317. return
  1318. }
  1319. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1320. document.mainViewController?.menuItemAction_signure(sender)
  1321. }
  1322. }
  1323. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1324. if (self.canResponseDocumentAction() == false) {
  1325. return
  1326. }
  1327. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1328. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1329. }
  1330. }
  1331. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1332. if (self.canResponseDocumentAction() == false) {
  1333. return
  1334. }
  1335. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1336. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1337. }
  1338. }
  1339. }
  1340. // MARK: - KMSystemPDFMenuProtocol
  1341. extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
  1342. @IBAction func changeDisplayMode(_ sender: Any?) {
  1343. if (self.canResponseDocumentAction() == false) {
  1344. return
  1345. }
  1346. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1347. document.mainViewController?.changeDisplayMode(sender)
  1348. }
  1349. }
  1350. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  1351. if (self.canResponseDocumentAction() == false) {
  1352. return
  1353. }
  1354. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1355. document.mainViewController?.toggleDisplayAsBook(sender)
  1356. }
  1357. }
  1358. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  1359. if (self.canResponseDocumentAction() == false) {
  1360. return
  1361. }
  1362. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1363. document.mainViewController?.toggleDisplayPageBreaks(sender)
  1364. }
  1365. }
  1366. @IBAction func changeDisplayBox(_ sender: Any?) {
  1367. if (self.canResponseDocumentAction() == false) {
  1368. return
  1369. }
  1370. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1371. document.mainViewController?.changeDisplayBox(sender)
  1372. }
  1373. }
  1374. @IBAction func toggleAutoScale(_ sender: Any?) {
  1375. if (self.canResponseDocumentAction() == false) {
  1376. return
  1377. }
  1378. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1379. document.mainViewController?.toggleAutoScale(sender)
  1380. }
  1381. }
  1382. }
  1383. // MARK: - KMSystemGotoMenuProtocol
  1384. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1385. func menuItemAction_nextPage(_ sender: Any) {
  1386. if (self.canResponseDocumentAction() == false) {
  1387. return
  1388. }
  1389. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1390. document.mainViewController?.menuItemAction_nextPage(sender)
  1391. }
  1392. }
  1393. func menuItemAction_forwardPage(_ sender: Any) {
  1394. if (self.canResponseDocumentAction() == false) {
  1395. return
  1396. }
  1397. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1398. document.mainViewController?.menuItemAction_forwardPage(sender)
  1399. }
  1400. }
  1401. func menuItemAction_firstPage(_ sender: Any) {
  1402. if (self.canResponseDocumentAction() == false) {
  1403. return
  1404. }
  1405. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1406. document.mainViewController?.menuItemAction_firstPage(sender)
  1407. }
  1408. }
  1409. func menuItemAction_lastPage(_ sender: Any) {
  1410. if (self.canResponseDocumentAction() == false) {
  1411. return
  1412. }
  1413. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1414. document.mainViewController?.menuItemAction_lastPage(sender)
  1415. }
  1416. }
  1417. func menuItemAction_forward(_ sender: Any) {
  1418. if (self.canResponseDocumentAction() == false) {
  1419. return
  1420. }
  1421. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1422. document.mainViewController?.menuItemAction_forward(sender)
  1423. }
  1424. }
  1425. func menuItemAction_goback(_ sender: Any) {
  1426. if (self.canResponseDocumentAction() == false) {
  1427. return
  1428. }
  1429. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1430. document.mainViewController?.menuItemAction_goback(sender)
  1431. }
  1432. }
  1433. func menuItemAction_gotoPage(_ sender: Any) {
  1434. if (self.canResponseDocumentAction() == false) {
  1435. return
  1436. }
  1437. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1438. document.mainViewController?.menuItemAction_gotoPage(sender)
  1439. }
  1440. }
  1441. @IBAction func goToMarkedPage(_ sender: Any?) {
  1442. if (self.canResponseDocumentAction() == false) {
  1443. return
  1444. }
  1445. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1446. document.mainViewController?.goToMarkedPage(sender)
  1447. }
  1448. }
  1449. @IBAction func markPage(_ sender: Any?) {
  1450. if (self.canResponseDocumentAction() == false) {
  1451. return
  1452. }
  1453. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1454. document.mainViewController?.markPage(sender)
  1455. }
  1456. }
  1457. }
  1458. // MARK: - KMSystemToolMenuProtocol
  1459. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1460. @IBAction func getInfo(_ sender: Any?) {
  1461. if (self.canResponseDocumentAction() == false) {
  1462. return
  1463. }
  1464. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1465. document.mainViewController?.getInfo(sender)
  1466. }
  1467. }
  1468. func orderFrontNotesPanel(_ sender: Any?) {
  1469. let windowC = KMNotesPanelController.shared
  1470. if let win = windowC.window {
  1471. if win.isVisible {
  1472. win.orderOut(sender)
  1473. } else {
  1474. win.orderFront(sender)
  1475. }
  1476. }
  1477. }
  1478. func menuItemAction_scrolTool(_ sender: Any) {
  1479. if (self.canResponseDocumentAction() == false) {
  1480. return
  1481. }
  1482. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1483. document.mainViewController?.menuItemAction_scrolTool(sender)
  1484. }
  1485. }
  1486. func menuItemAction_zoomOutTool(_ sender: Any) {
  1487. if (self.canResponseDocumentAction() == false) {
  1488. return
  1489. }
  1490. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1491. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1492. }
  1493. }
  1494. func menuItemAction_selectTool(_ sender: Any) {
  1495. if (self.canResponseDocumentAction() == false) {
  1496. return
  1497. }
  1498. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1499. document.mainViewController?.menuItemAction_selectTool(sender)
  1500. }
  1501. }
  1502. @IBAction func changeToolMode(_ sender: Any?) {
  1503. if (self.canResponseDocumentAction() == false) {
  1504. return
  1505. }
  1506. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1507. if (document.isHome) {
  1508. } else {
  1509. document.mainViewController?.changeToolMode(sender)
  1510. }
  1511. }
  1512. }
  1513. @IBAction func compression(_ sender: Any?) {
  1514. if (self.canResponseDocumentAction() == false) {
  1515. return
  1516. }
  1517. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1518. if (document.isHome) {
  1519. } else {
  1520. document.mainViewController?.compression(sender)
  1521. }
  1522. }
  1523. }
  1524. @IBAction func merge(_ sender: Any?) {
  1525. if (self.canResponseDocumentAction() == false) {
  1526. return
  1527. }
  1528. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1529. if (document.isHome) {
  1530. } else {
  1531. document.mainViewController?.merge(sender)
  1532. }
  1533. }
  1534. }
  1535. @IBAction func convert(_ sender: Any?) {
  1536. if (self.canResponseDocumentAction() == false) {
  1537. return
  1538. }
  1539. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1540. if (document.isHome) {
  1541. } else {
  1542. document.mainViewController?.convert(sender)
  1543. }
  1544. }
  1545. }
  1546. @IBAction func imageToPDF(_ sender: Any?) {
  1547. if (self.canResponseDocumentAction() == false) {
  1548. return
  1549. }
  1550. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1551. if (document.isHome) {
  1552. } else {
  1553. document.mainViewController?.imageToPDF(sender)
  1554. }
  1555. }
  1556. }
  1557. @IBAction func ocr(_ sender: Any?) {
  1558. if (self.canResponseDocumentAction() == false) {
  1559. return
  1560. }
  1561. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1562. if (document.isHome) {
  1563. } else {
  1564. document.mainViewController?.ocr(sender)
  1565. }
  1566. }
  1567. }
  1568. @IBAction func extractImage(_ sender: Any?) {
  1569. if (self.canResponseDocumentAction() == false) {
  1570. return
  1571. }
  1572. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1573. if (document.isHome) {
  1574. } else {
  1575. document.mainViewController?.extractImage(sender)
  1576. }
  1577. }
  1578. }
  1579. @IBAction func pageEdit(_ sender: Any?) {
  1580. if (self.canResponseDocumentAction() == false) {
  1581. return
  1582. }
  1583. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1584. if (document.isHome) {
  1585. } else {
  1586. document.mainViewController?.pageEdit(sender)
  1587. }
  1588. }
  1589. }
  1590. @IBAction func textEditAction(_ sender: Any?) {
  1591. if (self.canResponseDocumentAction() == false) {
  1592. return
  1593. }
  1594. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1595. if (document.isHome) {
  1596. } else {
  1597. document.mainViewController?.textEditAction(sender)
  1598. }
  1599. }
  1600. }
  1601. @IBAction func security(_ sender: Any?) {
  1602. if (self.canResponseDocumentAction() == false) {
  1603. return
  1604. }
  1605. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1606. if (document.isHome) {
  1607. } else {
  1608. document.mainViewController?.security(sender)
  1609. }
  1610. }
  1611. }
  1612. @IBAction func decryption(_ sender: Any?) {
  1613. if (self.canResponseDocumentAction() == false) {
  1614. return
  1615. }
  1616. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1617. if (document.isHome) {
  1618. } else {
  1619. document.mainViewController?.decryption(sender)
  1620. }
  1621. }
  1622. }
  1623. @IBAction func cropAll(_ sender: Any?) {
  1624. if (self.canResponseDocumentAction() == false) {
  1625. return
  1626. }
  1627. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1628. if (document.isHome) {
  1629. } else {
  1630. document.mainViewController?.cropAll(sender)
  1631. }
  1632. }
  1633. }
  1634. @IBAction func crop(_ sender: Any?) {
  1635. if (self.canResponseDocumentAction() == false) {
  1636. return
  1637. }
  1638. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1639. if (document.isHome) {
  1640. } else {
  1641. document.mainViewController?.crop(sender)
  1642. }
  1643. }
  1644. }
  1645. @IBAction func autoCropAll(_ sender: Any?) {
  1646. if (self.canResponseDocumentAction() == false) {
  1647. return
  1648. }
  1649. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1650. if (document.isHome) {
  1651. } else {
  1652. document.mainViewController?.autoCropAll(sender)
  1653. }
  1654. }
  1655. }
  1656. @IBAction func smartAutoCropAll(_ sender: Any?) {
  1657. if (self.canResponseDocumentAction() == false) {
  1658. return
  1659. }
  1660. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1661. if (document.isHome) {
  1662. } else {
  1663. document.mainViewController?.smartAutoCropAll(sender)
  1664. }
  1665. }
  1666. }
  1667. @IBAction func cropOptionsModel(_ sender: Any?) {
  1668. if (self.canResponseDocumentAction() == false) {
  1669. return
  1670. }
  1671. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1672. if (document.isHome) {
  1673. } else {
  1674. // document.mainViewController?.cropOptionsModel(sender)
  1675. }
  1676. }
  1677. }
  1678. @IBAction func selectToolModel(_ sender: Any?) {
  1679. if (self.canResponseDocumentAction() == false) {
  1680. return
  1681. }
  1682. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1683. if (document.isHome) {
  1684. } else {
  1685. document.mainViewController?.selectToolModel(sender)
  1686. }
  1687. }
  1688. }
  1689. @IBAction func takeSnapshot(_ sender: Any?) {
  1690. if (self.canResponseDocumentAction() == false) {
  1691. return
  1692. }
  1693. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1694. if (document.isHome) {
  1695. } else {
  1696. document.mainViewController?.takeSnapshot(sender)
  1697. }
  1698. }
  1699. }
  1700. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  1701. if (self.canResponseDocumentAction() == false) {
  1702. return
  1703. }
  1704. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1705. if (document.isHome) {
  1706. } else {
  1707. document.mainViewController?.takeSnapshotSelectContent(sender)
  1708. }
  1709. }
  1710. }
  1711. @IBAction func changeAnnotationMode(_ sender: Any?) {
  1712. if (self.canResponseDocumentAction() == false) {
  1713. return
  1714. }
  1715. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1716. if (document.isHome) {
  1717. } else {
  1718. document.mainViewController?.changeAnnotationMode(sender)
  1719. }
  1720. }
  1721. }
  1722. @IBAction func addBackground(_ sender: Any?) {
  1723. if (self.canResponseDocumentAction() == false) {
  1724. return
  1725. }
  1726. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1727. if (document.isHome) {
  1728. } else {
  1729. document.mainViewController?.addBackground(sender)
  1730. }
  1731. }
  1732. }
  1733. @IBAction func removeBackground(_ sender: Any?) {
  1734. if (self.canResponseDocumentAction() == false) {
  1735. return
  1736. }
  1737. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1738. if (document.isHome) {
  1739. } else {
  1740. document.mainViewController?.removeBackground(sender)
  1741. }
  1742. }
  1743. }
  1744. @IBAction func addWatermark(_ sender: Any?) {
  1745. if (self.canResponseDocumentAction() == false) {
  1746. return
  1747. }
  1748. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1749. if (document.isHome) {
  1750. } else {
  1751. document.mainViewController?.addWatermark(sender)
  1752. }
  1753. }
  1754. }
  1755. @IBAction func editWatermark(_ sender: Any?) {
  1756. KMPrint("editWatermark ...")
  1757. }
  1758. @IBAction func batchAddWatermark(_ 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?.batchAddWatermark(sender)
  1766. }
  1767. }
  1768. }
  1769. @IBAction func batchRemoveWatermark(_ 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?.batchRemoveWatermark(sender)
  1777. }
  1778. }
  1779. }
  1780. @IBAction func removeWatermark(_ 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?.removeWatermark(sender)
  1788. }
  1789. }
  1790. }
  1791. @IBAction func templateWatermark(_ 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?.templateWatermark(sender)
  1799. }
  1800. }
  1801. }
  1802. @IBAction func batchAddBackground(_ 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?.batchAddBackground(sender)
  1810. }
  1811. }
  1812. }
  1813. @IBAction func batchRemoveBackground(_ 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?.batchRemoveBackground(sender)
  1821. }
  1822. }
  1823. }
  1824. @IBAction func templateBackground(_ 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?.templateBackground(sender)
  1832. }
  1833. }
  1834. }
  1835. @IBAction func addHeaderFooter(_ 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?.addHeaderFooter(sender)
  1843. }
  1844. }
  1845. }
  1846. @IBAction func removeHeaderFooter(_ 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?.removeHeaderFooter(sender)
  1854. }
  1855. }
  1856. }
  1857. @IBAction func batchAddHeaderFooter(_ 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?.batchAddHeaderFooter(sender)
  1865. }
  1866. }
  1867. }
  1868. @IBAction func batchRemoveHeaderFooter(_ 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?.batchRemoveHeaderFooter(sender)
  1876. }
  1877. }
  1878. }
  1879. @IBAction func templateHeaderFooter(_ 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?.templateHeaderFooter(sender)
  1887. }
  1888. }
  1889. }
  1890. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  1891. if (self.canResponseDocumentAction() == false) {
  1892. return
  1893. }
  1894. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1895. if (document.isHome) {
  1896. } else {
  1897. document.mainViewController?.addHeaderFooterBates(sender)
  1898. }
  1899. }
  1900. }
  1901. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  1902. if (self.canResponseDocumentAction() == false) {
  1903. return
  1904. }
  1905. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1906. if (document.isHome) {
  1907. } else {
  1908. document.mainViewController?.removeHeaderFooterBates(sender)
  1909. }
  1910. }
  1911. }
  1912. @IBAction func batchAddBates(_ sender: Any?) {
  1913. if (self.canResponseDocumentAction() == false) {
  1914. return
  1915. }
  1916. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1917. if (document.isHome) {
  1918. } else {
  1919. document.mainViewController?.batchAddBates(sender)
  1920. }
  1921. }
  1922. }
  1923. @IBAction func batchRemoveBates(_ sender: Any?) {
  1924. if (self.canResponseDocumentAction() == false) {
  1925. return
  1926. }
  1927. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1928. if (document.isHome) {
  1929. } else {
  1930. document.mainViewController?.batchRemoveBates(sender)
  1931. }
  1932. }
  1933. }
  1934. @IBAction func templateBates(_ sender: Any?) {
  1935. if (self.canResponseDocumentAction() == false) {
  1936. return
  1937. }
  1938. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1939. if (document.isHome) {
  1940. } else {
  1941. document.mainViewController?.templateBates(sender)
  1942. }
  1943. }
  1944. }
  1945. @IBAction func togglePoster(_ sender: Any?) {
  1946. if (self.canResponseDocumentAction() == false) {
  1947. return
  1948. }
  1949. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1950. if (document.isHome) {
  1951. } else {
  1952. document.mainViewController?.togglePoster(sender)
  1953. }
  1954. }
  1955. }
  1956. @IBAction func toggleMultiple(_ sender: Any?) {
  1957. if (self.canResponseDocumentAction() == false) {
  1958. return
  1959. }
  1960. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1961. if (document.isHome) {
  1962. } else {
  1963. document.mainViewController?.toggleMultiple(sender)
  1964. }
  1965. }
  1966. }
  1967. @IBAction func toggleBooklet(_ sender: Any?) {
  1968. if (self.canResponseDocumentAction() == false) {
  1969. return
  1970. }
  1971. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1972. if (document.isHome) {
  1973. } else {
  1974. document.mainViewController?.toggleBooklet(sender)
  1975. }
  1976. }
  1977. }
  1978. @IBAction func rotateRight(_ sender: Any?) {
  1979. if (self.canResponseDocumentAction() == false) {
  1980. return
  1981. }
  1982. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1983. if (document.isHome) {
  1984. } else {
  1985. document.mainViewController?.rotateRight(sender)
  1986. }
  1987. }
  1988. }
  1989. @IBAction func rotateLeft(_ sender: Any?) {
  1990. if (self.canResponseDocumentAction() == false) {
  1991. return
  1992. }
  1993. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1994. if (document.isHome) {
  1995. } else {
  1996. document.mainViewController?.rotateLeft(sender)
  1997. }
  1998. }
  1999. }
  2000. @IBAction func rotateAllRight(_ sender: Any?) {
  2001. if (self.canResponseDocumentAction() == false) {
  2002. return
  2003. }
  2004. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2005. if (document.isHome) {
  2006. } else {
  2007. document.mainViewController?.rotateAllRight(sender)
  2008. }
  2009. }
  2010. }
  2011. @IBAction func rotateAllLeft(_ sender: Any?) {
  2012. if (self.canResponseDocumentAction() == false) {
  2013. return
  2014. }
  2015. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2016. if (document.isHome) {
  2017. } else {
  2018. document.mainViewController?.rotateAllLeft(sender)
  2019. }
  2020. }
  2021. }
  2022. @IBAction func autoSelectContent(_ sender: Any?) {
  2023. if (self.canResponseDocumentAction() == false) {
  2024. return
  2025. }
  2026. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2027. if (document.isHome) {
  2028. } else {
  2029. document.mainViewController?.autoSelectContent(sender)
  2030. }
  2031. }
  2032. }
  2033. }
  2034. // MARK: - KMSystemWindowMenuRrotocol
  2035. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  2036. func menuItemAction_showForwardTagPage(_ sender: Any) {
  2037. if (self.canResponseDocumentAction() == false) {
  2038. return
  2039. }
  2040. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2041. if (document.isHome) {
  2042. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  2043. } else {
  2044. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  2045. }
  2046. }
  2047. }
  2048. func menuItemAction_showNextTagPage(_ sender: Any) {
  2049. if (self.canResponseDocumentAction() == false) {
  2050. return
  2051. }
  2052. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2053. if (document.isHome) {
  2054. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  2055. } else {
  2056. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  2057. }
  2058. }
  2059. }
  2060. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  2061. if (self.canResponseDocumentAction() == false) {
  2062. return
  2063. }
  2064. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2065. if (document.isHome) {
  2066. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2067. } else {
  2068. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2069. }
  2070. }
  2071. }
  2072. func menuItemAction_mergeAllWindow(_ sender: Any) {
  2073. if (self.canResponseDocumentAction() == false) {
  2074. return
  2075. }
  2076. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2077. if (document.isHome) {
  2078. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  2079. } else {
  2080. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  2081. }
  2082. }
  2083. }
  2084. }
  2085. // MARK: - Analytics (埋点)
  2086. extension KMBrowserWindowController {
  2087. func trackEvent_upgrade() -> Void {
  2088. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  2089. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  2090. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  2091. }
  2092. }