KMBrowserWindowController.swift 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377
  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 doZoomToPhysicalSize(_ sender: Any?) {
  616. KMPrint("doZoomToPhysicalSize ...")
  617. }
  618. @IBAction func alternateZoomToFit(_ sender: Any?) {
  619. KMPrint("alternateZoomToFit ...")
  620. }
  621. @IBAction func doZoomToSelection(_ sender: Any?) {
  622. KMPrint("doZoomToSelection ...")
  623. }
  624. @IBAction func doAutoScale(_ sender: Any?) {
  625. KMPrint("doAutoScale ...")
  626. }
  627. // @IBAction func delete(_ sender: Any?) {
  628. // KMPrint("delete ...")
  629. // }
  630. // @IBAction func paste(_ sender: Any?) {
  631. // KMPrint("paste ...")
  632. // }
  633. @IBAction func alternatePaste(_ sender: Any?) {
  634. KMPrint("alternatePaste ...")
  635. }
  636. @IBAction func copy(_ sender: Any?) {
  637. KMPrint("copy ...")
  638. }
  639. @IBAction func cut(_ sender: Any?) {
  640. KMPrint("cut ...")
  641. }
  642. @IBAction func toggleFullscreen(_ sender: Any?) {
  643. KMPrint("toggleFullscreen ...")
  644. }
  645. @IBAction func toggleRightSidePane(_ sender: Any?) {
  646. KMPrint("toggleRightSidePane ...")
  647. }
  648. @IBAction func performFit(_ sender: Any?) {
  649. KMPrint("performFit ...")
  650. }
  651. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  652. KMPrint("changeRightSidePaneState ...")
  653. }
  654. @IBAction func changeFindPaneState(_ sender: Any?) {
  655. KMPrint("changeFindPaneState ...")
  656. }
  657. @IBAction func toggleSplitPDF(_ sender: Any?) {
  658. KMPrint("toggleSplitPDF ...")
  659. }
  660. @IBAction func search(_ sender: Any?) {
  661. KMPrint("search ...")
  662. }
  663. @IBAction func searchNotes(_ sender: Any?) {
  664. KMPrint("searchNotes ...")
  665. }
  666. @IBAction func password(_ sender: Any?) {
  667. KMPrint("password ...")
  668. }
  669. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  670. KMPrint("savePDFSettingToDefaults ...")
  671. }
  672. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  673. KMPrint("toggleCaseInsensitiveSearch ...")
  674. }
  675. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  676. KMPrint("toggleWholeWordSearch ...")
  677. }
  678. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  679. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  680. }
  681. @IBAction func performFindPanelAction(_ sender: Any?) {
  682. KMPrint("performFindPanelAction ...")
  683. }
  684. @IBAction func scrollUp(_ sender: Any?) {
  685. KMPrint("scrollUp ...")
  686. }
  687. @IBAction func scrollDown(_ sender: Any?) {
  688. KMPrint("scrollDown ...")
  689. }
  690. @IBAction func scrollRight(_ sender: Any?) {
  691. KMPrint("scrollRight ...")
  692. }
  693. @IBAction func scrollLeft(_ sender: Any?) {
  694. KMPrint("scrollLeft ...")
  695. }
  696. @IBAction func selectSelectedNote(_ sender: Any?) {
  697. KMPrint("selectSelectedNote ...")
  698. }
  699. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  700. KMPrint("goToSelectedOutlineItem ...")
  701. }
  702. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  703. KMPrint("goToSelectedFindResults ...")
  704. }
  705. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  706. KMPrint("toggleSelectedSnapshots ...")
  707. }
  708. @IBAction func selfSignProfile(_ sender: Any?) {
  709. KMPrint("selfSignProfile ...")
  710. }
  711. @IBAction func highlightLinks(_ sender: Any?) {
  712. KMPrint("highlightLinks ...")
  713. }
  714. @IBAction func resetForm(_ sender: Any?) {
  715. KMPrint("resetForm ...")
  716. }
  717. @IBAction func removeAllAnnotation(_ sender: Any?) {
  718. KMPrint("removeAllAnnotation ...")
  719. }
  720. @IBAction func link(_ sender: Any?) {
  721. KMPrint("link ...")
  722. }
  723. @IBAction func insertPage(_ sender: Any?) {
  724. KMPrint("insertPage ...")
  725. }
  726. @IBAction func split(_ sender: Any?) {
  727. KMPrint("split ...")
  728. }
  729. @IBAction func comparison(_ sender: Any?) {
  730. KMPrint("comparison ...")
  731. }
  732. @IBAction func contentComparison(_ sender: Any?) {
  733. KMPrint("contentComparison ...")
  734. }
  735. @IBAction func coverageComparison(_ sender: Any?) {
  736. KMPrint("coverageComparison ...")
  737. }
  738. @IBAction func readMode(_ sender: Any?) {
  739. KMPrint("readMode ...")
  740. }
  741. @IBAction func changeFormType(_ sender: Any?) {
  742. KMPrint("changeFormType ...")
  743. }
  744. @IBAction func changeSelfSignType(_ sender: Any?) {
  745. KMPrint("changeSelfSignType ...")
  746. }
  747. @IBAction func clearAllForm(_ sender: Any?) {
  748. KMPrint("clearAllForm ...")
  749. }
  750. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  751. KMPrint("thumbnailSizeScaling ...")
  752. }
  753. @IBAction func redactAction(_ sender: Any?) {
  754. if (self.canResponseDocumentAction() == false) {
  755. return
  756. }
  757. if let document = self.browser.activeTabContents() as? KMMainDocument {
  758. if document.isHome == false {
  759. document.mainViewController?.menuItemAction_redact(sender)
  760. }
  761. }
  762. }
  763. }
  764. // MARK: - KMSystemFileMenuProtocol
  765. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  766. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  767. if (self.canResponseDocumentAction() == false) {
  768. return
  769. }
  770. if let document = self.browser.activeTabContents() as? KMMainDocument {
  771. if (document.isHome) {
  772. // document.homeViewController?.menuItemClick_mergePDF(sender)
  773. } else {
  774. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  775. }
  776. }
  777. }
  778. func menuItemClick_mergePDF(_ sender: Any) {
  779. if (self.canResponseDocumentAction() == false) {
  780. return
  781. }
  782. if let document = self.browser.activeTabContents() as? KMMainDocument {
  783. if (document.isHome) {
  784. document.homeViewController?.menuItemClick_mergePDF(sender)
  785. } else {
  786. document.mainViewController?.menuItemClick_mergePDF(sender)
  787. }
  788. }
  789. }
  790. func menuItemClick_Compress(_ sender: Any) {
  791. if (self.canResponseDocumentAction() == false) {
  792. return
  793. }
  794. if let document = self.browser.activeTabContents() as? KMMainDocument {
  795. if (document.isHome) {
  796. document.homeViewController?.menuItemClick_Compress(sender)
  797. } else {
  798. document.mainViewController?.menuItemClick_Compress(sender)
  799. }
  800. }
  801. }
  802. func menuItemAction_ConvertToWord(_ sender: Any) {
  803. if (self.canResponseDocumentAction() == false) {
  804. return
  805. }
  806. if let document = self.browser.activeTabContents() as? KMMainDocument {
  807. if (document.isHome) {
  808. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  809. } else {
  810. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  811. }
  812. }
  813. }
  814. func menuItemAction_ConvertToExcel(_ sender: Any) {
  815. if (self.canResponseDocumentAction() == false) {
  816. return
  817. }
  818. if let document = self.browser.activeTabContents() as? KMMainDocument {
  819. if (document.isHome) {
  820. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  821. } else {
  822. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  823. }
  824. }
  825. }
  826. func menuItemAction_ConvertToPPT(_ sender: Any) {
  827. if (self.canResponseDocumentAction() == false) {
  828. return
  829. }
  830. if let document = self.browser.activeTabContents() as? KMMainDocument {
  831. if (document.isHome) {
  832. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  833. } else {
  834. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  835. }
  836. }
  837. }
  838. func menuItemAction_ConvertToRTF(_ sender: Any) {
  839. if (self.canResponseDocumentAction() == false) {
  840. return
  841. }
  842. if let document = self.browser.activeTabContents() as? KMMainDocument {
  843. if (document.isHome) {
  844. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  845. } else {
  846. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  847. }
  848. }
  849. }
  850. func menuItemAction_ConvertToHTML(_ sender: Any) {
  851. if (self.canResponseDocumentAction() == false) {
  852. return
  853. }
  854. if let document = self.browser.activeTabContents() as? KMMainDocument {
  855. if (document.isHome) {
  856. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  857. } else {
  858. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  859. }
  860. }
  861. }
  862. func menuItemAction_ConvertToText(_ sender: Any) {
  863. if (self.canResponseDocumentAction() == false) {
  864. return
  865. }
  866. if let document = self.browser.activeTabContents() as? KMMainDocument {
  867. if (document.isHome) {
  868. document.homeViewController?.menuItemAction_ConvertToText(sender)
  869. } else {
  870. document.mainViewController?.menuItemAction_ConvertToText(sender)
  871. }
  872. }
  873. }
  874. func menuItemAction_ConvertToCSV(_ sender: Any) {
  875. if (self.canResponseDocumentAction() == false) {
  876. return
  877. }
  878. if let document = self.browser.activeTabContents() as? KMMainDocument {
  879. if (document.isHome) {
  880. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  881. } else {
  882. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  883. }
  884. }
  885. }
  886. func menuItemAction_ConvertToImage(_ sender: Any) {
  887. if (self.canResponseDocumentAction() == false) {
  888. return
  889. }
  890. if let document = self.browser.activeTabContents() as? KMMainDocument {
  891. if (document.isHome) {
  892. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  893. } else {
  894. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  895. }
  896. }
  897. }
  898. func menuItemClick_SettingPassword(_ sender: Any) {
  899. if (self.canResponseDocumentAction() == false) {
  900. return
  901. }
  902. if let document = self.browser.activeTabContents() as? KMMainDocument {
  903. if (document.isHome) {
  904. document.homeViewController?.menuItemClick_SettingPassword(sender)
  905. } else {
  906. document.mainViewController?.menuItemClick_SettingPassword(sender)
  907. }
  908. }
  909. }
  910. func menuItemClick_RemovePassword(_ sender: Any) {
  911. if (self.canResponseDocumentAction() == false) {
  912. return
  913. }
  914. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  915. document.mainViewController?.menuItemClick_RemovePassword(sender)
  916. }
  917. }
  918. func menuItemAction_closeWindow(_ sender: Any) {
  919. if (self.canResponseDocumentAction() == false) {
  920. return
  921. }
  922. if let document = self.browser.activeTabContents() as? KMMainDocument {
  923. if (document.isHome) {
  924. document.homeViewController?.menuItemAction_closeWindow(sender)
  925. } else {
  926. document.mainViewController?.menuItemAction_closeWindow(sender)
  927. }
  928. }
  929. }
  930. func menuItemAction_closeAllWindows(_ sender: Any) {
  931. if (self.canResponseDocumentAction() == false) {
  932. return
  933. }
  934. if let document = self.browser.activeTabContents() as? KMMainDocument {
  935. if (document.isHome) {
  936. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  937. } else {
  938. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  939. }
  940. }
  941. }
  942. func menuItemAction_closeTagPage(_ sender: Any) {
  943. if (self.canResponseDocumentAction() == false) {
  944. return
  945. }
  946. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  947. document.mainViewController?.menuItemAction_closeTagPage(sender)
  948. }
  949. }
  950. func menuItemAction_showInFinder(_ sender: Any) {
  951. if (self.canResponseDocumentAction() == false) {
  952. return
  953. }
  954. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  955. document.mainViewController?.menuItemAction_showInFinder(sender)
  956. }
  957. }
  958. func menuItemAction_property(_ sender: Any) {
  959. if (self.canResponseDocumentAction() == false) {
  960. return
  961. }
  962. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  963. document.mainViewController?.menuItemAction_property(sender)
  964. }
  965. }
  966. func menuItemAction_print(_ sender: Any) {
  967. if (self.canResponseDocumentAction() == false) {
  968. return
  969. }
  970. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  971. document.mainViewController?.menuItemAction_print(sender)
  972. }
  973. }
  974. }
  975. // MARK: - KMSystemViewMenuProtocol
  976. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  977. func menuItemAction_adjustWidth(_ sender: Any) {
  978. if (self.canResponseDocumentAction() == false) {
  979. return
  980. }
  981. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  982. document.mainViewController?.menuItemAction_adjustWidth(sender)
  983. }
  984. }
  985. func menuItemAction_adjustPage(_ sender: Any) {
  986. if (self.canResponseDocumentAction() == false) {
  987. return
  988. }
  989. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  990. document.mainViewController?.menuItemAction_adjustPage(sender)
  991. }
  992. }
  993. func menuItemAction_size(_ sender: Any) {
  994. if (self.canResponseDocumentAction() == false) {
  995. return
  996. }
  997. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  998. document.mainViewController?.menuItemAction_size(sender)
  999. }
  1000. }
  1001. func menuItemAction_zoomOut(_ sender: Any) {
  1002. if (self.canResponseDocumentAction() == false) {
  1003. return
  1004. }
  1005. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1006. document.mainViewController?.menuItemAction_zoomOut(sender)
  1007. }
  1008. }
  1009. func menuItemAction_zoomIn(_ sender: Any) {
  1010. if (self.canResponseDocumentAction() == false) {
  1011. return
  1012. }
  1013. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1014. document.mainViewController?.menuItemAction_zoomIn(sender)
  1015. }
  1016. }
  1017. func menuItemAction_singlePage(_ sender: Any) {
  1018. if (self.canResponseDocumentAction() == false) {
  1019. return
  1020. }
  1021. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1022. document.mainViewController?.menuItemAction_singlePage(sender)
  1023. }
  1024. }
  1025. func menuItemAction_singlePageContinue(_ sender: Any) {
  1026. if (self.canResponseDocumentAction() == false) {
  1027. return
  1028. }
  1029. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1030. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1031. }
  1032. }
  1033. func menuItemAction_doublePage(_ sender: Any) {
  1034. if (self.canResponseDocumentAction() == false) {
  1035. return
  1036. }
  1037. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1038. document.mainViewController?.menuItemAction_doublePage(sender)
  1039. }
  1040. }
  1041. func menuItemAction_doublePageContinue(_ sender: Any) {
  1042. if (self.canResponseDocumentAction() == false) {
  1043. return
  1044. }
  1045. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1046. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1047. }
  1048. }
  1049. func menuItemAction_bookMode(_ sender: Any) {
  1050. if (self.canResponseDocumentAction() == false) {
  1051. return
  1052. }
  1053. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1054. document.mainViewController?.menuItemAction_bookMode(sender)
  1055. }
  1056. }
  1057. func menuItemAction_readMode(_ sender: Any) {
  1058. if (self.canResponseDocumentAction() == false) {
  1059. return
  1060. }
  1061. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1062. document.mainViewController?.menuItemAction_readMode(sender)
  1063. }
  1064. }
  1065. func menuItemAction_showSplitPage(_ sender: Any) {
  1066. if (self.canResponseDocumentAction() == false) {
  1067. return
  1068. }
  1069. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1070. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1071. }
  1072. }
  1073. func menuItemAction_rotateLeft(_ sender: Any) {
  1074. if (self.canResponseDocumentAction() == false) {
  1075. return
  1076. }
  1077. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1078. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1079. }
  1080. }
  1081. func menuItemAction_rotateRight(_ sender: Any) {
  1082. if (self.canResponseDocumentAction() == false) {
  1083. return
  1084. }
  1085. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1086. document.mainViewController?.menuItemAction_rotateRight(sender)
  1087. }
  1088. }
  1089. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1090. if (self.canResponseDocumentAction() == false) {
  1091. return
  1092. }
  1093. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1094. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1095. }
  1096. }
  1097. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1098. if (self.canResponseDocumentAction() == false) {
  1099. return
  1100. }
  1101. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1102. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1103. }
  1104. }
  1105. func menuItemAction_view_readMode(_ sender: Any) {
  1106. if (self.canResponseDocumentAction() == false) {
  1107. return
  1108. }
  1109. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1110. document.mainViewController?.menuItemAction_view_readMode(sender)
  1111. }
  1112. }
  1113. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1114. if (self.canResponseDocumentAction() == false) {
  1115. return
  1116. }
  1117. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1118. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1119. }
  1120. }
  1121. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1122. if (self.canResponseDocumentAction() == false) {
  1123. return
  1124. }
  1125. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1126. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1127. }
  1128. }
  1129. func menuItemAction_thumai(_ sender: Any) {
  1130. if (self.canResponseDocumentAction() == false) {
  1131. return
  1132. }
  1133. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1134. document.mainViewController?.menuItemAction_thumai(sender)
  1135. }
  1136. }
  1137. func menuItemAction_outline(_ sender: Any) {
  1138. if (self.canResponseDocumentAction() == false) {
  1139. return
  1140. }
  1141. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1142. document.mainViewController?.menuItemAction_outline(sender)
  1143. }
  1144. }
  1145. func menuItemAction_bookmark(_ sender: Any) {
  1146. if (self.canResponseDocumentAction() == false) {
  1147. return
  1148. }
  1149. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1150. document.mainViewController?.menuItemAction_bookmark(sender)
  1151. }
  1152. }
  1153. func menuItemAction_annotation(_ sender: Any) {
  1154. if (self.canResponseDocumentAction() == false) {
  1155. return
  1156. }
  1157. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1158. document.mainViewController?.menuItemAction_annotation(sender)
  1159. }
  1160. }
  1161. func menuItemAction_search(_ sender: Any) {
  1162. if (self.canResponseDocumentAction() == false) {
  1163. return
  1164. }
  1165. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1166. document.mainViewController?.menuItemAction_search(sender)
  1167. }
  1168. }
  1169. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1170. if (self.canResponseDocumentAction() == false) {
  1171. return
  1172. }
  1173. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1174. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1175. }
  1176. }
  1177. }
  1178. // MARK: - KMSystemEditMenuProtocol
  1179. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1180. func menuItemAction_find(_ 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?.menuItemAction_find(sender)
  1186. }
  1187. }
  1188. }
  1189. // MARK: - Annotation Menu
  1190. extension KMBrowserWindowController {
  1191. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1192. if (self.canResponseDocumentAction() == false) {
  1193. return
  1194. }
  1195. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1196. document.mainViewController?.menuItemAction_highlight(sender)
  1197. }
  1198. }
  1199. @IBAction func menuItemAction_underline(_ sender: Any) {
  1200. if (self.canResponseDocumentAction() == false) {
  1201. return
  1202. }
  1203. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1204. document.mainViewController?.menuItemAction_underline(sender)
  1205. }
  1206. }
  1207. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1208. if (self.canResponseDocumentAction() == false) {
  1209. return
  1210. }
  1211. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1212. document.mainViewController?.menuItemAction_deleteLine(sender)
  1213. }
  1214. }
  1215. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1216. if (self.canResponseDocumentAction() == false) {
  1217. return
  1218. }
  1219. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1220. document.mainViewController?.menuItemAction_freehand(sender)
  1221. }
  1222. }
  1223. @IBAction func menuItemAction_text(_ sender: Any) {
  1224. if (self.canResponseDocumentAction() == false) {
  1225. return
  1226. }
  1227. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1228. document.mainViewController?.menuItemAction_text(sender)
  1229. }
  1230. }
  1231. @IBAction func menuItemAction_note(_ 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_note(sender)
  1237. }
  1238. }
  1239. @IBAction func menuItemAction_squre(_ sender: Any) {
  1240. if (self.canResponseDocumentAction() == false) {
  1241. return
  1242. }
  1243. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1244. document.mainViewController?.menuItemAction_squre(sender)
  1245. }
  1246. }
  1247. @IBAction func menuItemAction_circle(_ sender: Any) {
  1248. if (self.canResponseDocumentAction() == false) {
  1249. return
  1250. }
  1251. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1252. document.mainViewController?.menuItemAction_circle(sender)
  1253. }
  1254. }
  1255. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1256. if (self.canResponseDocumentAction() == false) {
  1257. return
  1258. }
  1259. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1260. document.mainViewController?.menuItemAction_arrow(sender)
  1261. }
  1262. }
  1263. @IBAction func menuItemAction_line(_ sender: Any) {
  1264. if (self.canResponseDocumentAction() == false) {
  1265. return
  1266. }
  1267. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1268. document.mainViewController?.menuItemAction_line(sender)
  1269. }
  1270. }
  1271. // link
  1272. @IBAction func menuItemAction_link(_ sender: Any) {
  1273. if (self.canResponseDocumentAction() == false) {
  1274. return
  1275. }
  1276. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1277. document.mainViewController?.menuItemAction_link(sender)
  1278. }
  1279. }
  1280. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1281. if (self.canResponseDocumentAction() == false) {
  1282. return
  1283. }
  1284. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1285. document.mainViewController?.menuItemAction_linkPage(sender)
  1286. }
  1287. }
  1288. // stamp
  1289. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1290. if (self.canResponseDocumentAction() == false) {
  1291. return
  1292. }
  1293. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1294. document.mainViewController?.menuItemAction_stamp(sender)
  1295. }
  1296. }
  1297. @IBAction func menuItemAction_signure(_ sender: Any) {
  1298. if (self.canResponseDocumentAction() == false) {
  1299. return
  1300. }
  1301. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1302. document.mainViewController?.menuItemAction_signure(sender)
  1303. }
  1304. }
  1305. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1306. if (self.canResponseDocumentAction() == false) {
  1307. return
  1308. }
  1309. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1310. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1311. }
  1312. }
  1313. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1314. if (self.canResponseDocumentAction() == false) {
  1315. return
  1316. }
  1317. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1318. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1319. }
  1320. }
  1321. }
  1322. // MARK: - KMSystemPDFMenuProtocol
  1323. extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
  1324. @IBAction func changeDisplayMode(_ sender: Any?) {
  1325. if (self.canResponseDocumentAction() == false) {
  1326. return
  1327. }
  1328. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1329. document.mainViewController?.changeDisplayMode(sender)
  1330. }
  1331. }
  1332. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  1333. if (self.canResponseDocumentAction() == false) {
  1334. return
  1335. }
  1336. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1337. document.mainViewController?.toggleDisplayAsBook(sender)
  1338. }
  1339. }
  1340. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  1341. if (self.canResponseDocumentAction() == false) {
  1342. return
  1343. }
  1344. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1345. document.mainViewController?.toggleDisplayPageBreaks(sender)
  1346. }
  1347. }
  1348. @IBAction func changeDisplayBox(_ sender: Any?) {
  1349. if (self.canResponseDocumentAction() == false) {
  1350. return
  1351. }
  1352. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1353. document.mainViewController?.changeDisplayBox(sender)
  1354. }
  1355. }
  1356. @IBAction func toggleAutoScale(_ sender: Any?) {
  1357. if (self.canResponseDocumentAction() == false) {
  1358. return
  1359. }
  1360. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1361. document.mainViewController?.toggleAutoScale(sender)
  1362. }
  1363. }
  1364. @IBAction func doZoomToActualSize(_ sender: Any?) {
  1365. if (self.canResponseDocumentAction() == false) {
  1366. return
  1367. }
  1368. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1369. document.mainViewController?.doZoomToActualSize(sender)
  1370. }
  1371. }
  1372. @IBAction func doZoomToFit(_ sender: Any?) {
  1373. if (self.canResponseDocumentAction() == false) {
  1374. return
  1375. }
  1376. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1377. document.mainViewController?.doZoomToFit(sender)
  1378. }
  1379. }
  1380. @IBAction func doZoomIn(_ sender: Any?) {
  1381. if (self.canResponseDocumentAction() == false) {
  1382. return
  1383. }
  1384. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1385. document.mainViewController?.doZoomIn(sender)
  1386. }
  1387. }
  1388. @IBAction func doZoomOut(_ sender: Any?) {
  1389. if (self.canResponseDocumentAction() == false) {
  1390. return
  1391. }
  1392. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1393. document.mainViewController?.doZoomOut(sender)
  1394. }
  1395. }
  1396. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  1397. if (self.canResponseDocumentAction() == false) {
  1398. return
  1399. }
  1400. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1401. document.mainViewController?.doMarqueeZoomTool(sender)
  1402. }
  1403. }
  1404. @IBAction func highlightFormFiled(_ sender: Any?) {
  1405. if (self.canResponseDocumentAction() == false) {
  1406. return
  1407. }
  1408. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1409. document.mainViewController?.highlightFormFiled(sender)
  1410. }
  1411. }
  1412. }
  1413. // MARK: - KMSystemGotoMenuProtocol
  1414. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1415. func menuItemAction_nextPage(_ sender: Any) {
  1416. if (self.canResponseDocumentAction() == false) {
  1417. return
  1418. }
  1419. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1420. document.mainViewController?.menuItemAction_nextPage(sender)
  1421. }
  1422. }
  1423. func menuItemAction_forwardPage(_ sender: Any) {
  1424. if (self.canResponseDocumentAction() == false) {
  1425. return
  1426. }
  1427. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1428. document.mainViewController?.menuItemAction_forwardPage(sender)
  1429. }
  1430. }
  1431. func menuItemAction_firstPage(_ sender: Any) {
  1432. if (self.canResponseDocumentAction() == false) {
  1433. return
  1434. }
  1435. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1436. document.mainViewController?.menuItemAction_firstPage(sender)
  1437. }
  1438. }
  1439. func menuItemAction_lastPage(_ sender: Any) {
  1440. if (self.canResponseDocumentAction() == false) {
  1441. return
  1442. }
  1443. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1444. document.mainViewController?.menuItemAction_lastPage(sender)
  1445. }
  1446. }
  1447. func menuItemAction_forward(_ sender: Any) {
  1448. if (self.canResponseDocumentAction() == false) {
  1449. return
  1450. }
  1451. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1452. document.mainViewController?.menuItemAction_forward(sender)
  1453. }
  1454. }
  1455. func menuItemAction_goback(_ sender: Any) {
  1456. if (self.canResponseDocumentAction() == false) {
  1457. return
  1458. }
  1459. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1460. document.mainViewController?.menuItemAction_goback(sender)
  1461. }
  1462. }
  1463. func menuItemAction_gotoPage(_ sender: Any) {
  1464. if (self.canResponseDocumentAction() == false) {
  1465. return
  1466. }
  1467. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1468. document.mainViewController?.menuItemAction_gotoPage(sender)
  1469. }
  1470. }
  1471. @IBAction func goToMarkedPage(_ sender: Any?) {
  1472. if (self.canResponseDocumentAction() == false) {
  1473. return
  1474. }
  1475. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1476. document.mainViewController?.goToMarkedPage(sender)
  1477. }
  1478. }
  1479. @IBAction func markPage(_ sender: Any?) {
  1480. if (self.canResponseDocumentAction() == false) {
  1481. return
  1482. }
  1483. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1484. document.mainViewController?.markPage(sender)
  1485. }
  1486. }
  1487. }
  1488. // MARK: - KMSystemToolMenuProtocol
  1489. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1490. @IBAction func getInfo(_ 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?.getInfo(sender)
  1496. }
  1497. }
  1498. func orderFrontNotesPanel(_ sender: Any?) {
  1499. let windowC = KMNotesPanelController.shared
  1500. if let win = windowC.window {
  1501. if win.isVisible {
  1502. win.orderOut(sender)
  1503. } else {
  1504. win.orderFront(sender)
  1505. }
  1506. }
  1507. }
  1508. func menuItemAction_scrolTool(_ sender: Any) {
  1509. if (self.canResponseDocumentAction() == false) {
  1510. return
  1511. }
  1512. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1513. document.mainViewController?.menuItemAction_scrolTool(sender)
  1514. }
  1515. }
  1516. func menuItemAction_zoomOutTool(_ sender: Any) {
  1517. if (self.canResponseDocumentAction() == false) {
  1518. return
  1519. }
  1520. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1521. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1522. }
  1523. }
  1524. func menuItemAction_selectTool(_ sender: Any) {
  1525. if (self.canResponseDocumentAction() == false) {
  1526. return
  1527. }
  1528. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1529. document.mainViewController?.menuItemAction_selectTool(sender)
  1530. }
  1531. }
  1532. @IBAction func changeToolMode(_ sender: Any?) {
  1533. if (self.canResponseDocumentAction() == false) {
  1534. return
  1535. }
  1536. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1537. if (document.isHome) {
  1538. } else {
  1539. document.mainViewController?.changeToolMode(sender)
  1540. }
  1541. }
  1542. }
  1543. @IBAction func compression(_ sender: Any?) {
  1544. if (self.canResponseDocumentAction() == false) {
  1545. return
  1546. }
  1547. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1548. if (document.isHome) {
  1549. } else {
  1550. document.mainViewController?.compression(sender)
  1551. }
  1552. }
  1553. }
  1554. @IBAction func merge(_ sender: Any?) {
  1555. if (self.canResponseDocumentAction() == false) {
  1556. return
  1557. }
  1558. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1559. if (document.isHome) {
  1560. } else {
  1561. document.mainViewController?.merge(sender)
  1562. }
  1563. }
  1564. }
  1565. @IBAction func convert(_ sender: Any?) {
  1566. if (self.canResponseDocumentAction() == false) {
  1567. return
  1568. }
  1569. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1570. if (document.isHome) {
  1571. } else {
  1572. document.mainViewController?.convert(sender)
  1573. }
  1574. }
  1575. }
  1576. @IBAction func imageToPDF(_ sender: Any?) {
  1577. if (self.canResponseDocumentAction() == false) {
  1578. return
  1579. }
  1580. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1581. if (document.isHome) {
  1582. } else {
  1583. document.mainViewController?.imageToPDF(sender)
  1584. }
  1585. }
  1586. }
  1587. @IBAction func ocr(_ sender: Any?) {
  1588. if (self.canResponseDocumentAction() == false) {
  1589. return
  1590. }
  1591. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1592. if (document.isHome) {
  1593. } else {
  1594. document.mainViewController?.ocr(sender)
  1595. }
  1596. }
  1597. }
  1598. @IBAction func extractImage(_ sender: Any?) {
  1599. if (self.canResponseDocumentAction() == false) {
  1600. return
  1601. }
  1602. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1603. if (document.isHome) {
  1604. } else {
  1605. document.mainViewController?.extractImage(sender)
  1606. }
  1607. }
  1608. }
  1609. @IBAction func pageEdit(_ sender: Any?) {
  1610. if (self.canResponseDocumentAction() == false) {
  1611. return
  1612. }
  1613. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1614. if (document.isHome) {
  1615. } else {
  1616. document.mainViewController?.pageEdit(sender)
  1617. }
  1618. }
  1619. }
  1620. @IBAction func textEditAction(_ sender: Any?) {
  1621. if (self.canResponseDocumentAction() == false) {
  1622. return
  1623. }
  1624. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1625. if (document.isHome) {
  1626. } else {
  1627. document.mainViewController?.textEditAction(sender)
  1628. }
  1629. }
  1630. }
  1631. @IBAction func security(_ sender: Any?) {
  1632. if (self.canResponseDocumentAction() == false) {
  1633. return
  1634. }
  1635. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1636. if (document.isHome) {
  1637. } else {
  1638. document.mainViewController?.security(sender)
  1639. }
  1640. }
  1641. }
  1642. @IBAction func decryption(_ sender: Any?) {
  1643. if (self.canResponseDocumentAction() == false) {
  1644. return
  1645. }
  1646. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1647. if (document.isHome) {
  1648. } else {
  1649. document.mainViewController?.decryption(sender)
  1650. }
  1651. }
  1652. }
  1653. @IBAction func cropAll(_ sender: Any?) {
  1654. if (self.canResponseDocumentAction() == false) {
  1655. return
  1656. }
  1657. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1658. if (document.isHome) {
  1659. } else {
  1660. document.mainViewController?.cropAll(sender)
  1661. }
  1662. }
  1663. }
  1664. @IBAction func crop(_ sender: Any?) {
  1665. if (self.canResponseDocumentAction() == false) {
  1666. return
  1667. }
  1668. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1669. if (document.isHome) {
  1670. } else {
  1671. document.mainViewController?.crop(sender)
  1672. }
  1673. }
  1674. }
  1675. @IBAction func autoCropAll(_ sender: Any?) {
  1676. if (self.canResponseDocumentAction() == false) {
  1677. return
  1678. }
  1679. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1680. if (document.isHome) {
  1681. } else {
  1682. document.mainViewController?.autoCropAll(sender)
  1683. }
  1684. }
  1685. }
  1686. @IBAction func smartAutoCropAll(_ sender: Any?) {
  1687. if (self.canResponseDocumentAction() == false) {
  1688. return
  1689. }
  1690. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1691. if (document.isHome) {
  1692. } else {
  1693. document.mainViewController?.smartAutoCropAll(sender)
  1694. }
  1695. }
  1696. }
  1697. @IBAction func cropOptionsModel(_ sender: Any?) {
  1698. if (self.canResponseDocumentAction() == false) {
  1699. return
  1700. }
  1701. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1702. if (document.isHome) {
  1703. } else {
  1704. // document.mainViewController?.cropOptionsModel(sender)
  1705. }
  1706. }
  1707. }
  1708. @IBAction func selectToolModel(_ sender: Any?) {
  1709. if (self.canResponseDocumentAction() == false) {
  1710. return
  1711. }
  1712. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1713. if (document.isHome) {
  1714. } else {
  1715. document.mainViewController?.selectToolModel(sender)
  1716. }
  1717. }
  1718. }
  1719. @IBAction func takeSnapshot(_ sender: Any?) {
  1720. if (self.canResponseDocumentAction() == false) {
  1721. return
  1722. }
  1723. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1724. if (document.isHome) {
  1725. } else {
  1726. document.mainViewController?.takeSnapshot(sender)
  1727. }
  1728. }
  1729. }
  1730. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  1731. if (self.canResponseDocumentAction() == false) {
  1732. return
  1733. }
  1734. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1735. if (document.isHome) {
  1736. } else {
  1737. document.mainViewController?.takeSnapshotSelectContent(sender)
  1738. }
  1739. }
  1740. }
  1741. @IBAction func changeAnnotationMode(_ sender: Any?) {
  1742. if (self.canResponseDocumentAction() == false) {
  1743. return
  1744. }
  1745. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1746. if (document.isHome) {
  1747. } else {
  1748. document.mainViewController?.changeAnnotationMode(sender)
  1749. }
  1750. }
  1751. }
  1752. @IBAction func addBackground(_ sender: Any?) {
  1753. if (self.canResponseDocumentAction() == false) {
  1754. return
  1755. }
  1756. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1757. if (document.isHome) {
  1758. } else {
  1759. document.mainViewController?.addBackground(sender)
  1760. }
  1761. }
  1762. }
  1763. @IBAction func removeBackground(_ sender: Any?) {
  1764. if (self.canResponseDocumentAction() == false) {
  1765. return
  1766. }
  1767. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1768. if (document.isHome) {
  1769. } else {
  1770. document.mainViewController?.removeBackground(sender)
  1771. }
  1772. }
  1773. }
  1774. @IBAction func addWatermark(_ sender: Any?) {
  1775. if (self.canResponseDocumentAction() == false) {
  1776. return
  1777. }
  1778. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1779. if (document.isHome) {
  1780. } else {
  1781. document.mainViewController?.addWatermark(sender)
  1782. }
  1783. }
  1784. }
  1785. @IBAction func editWatermark(_ sender: Any?) {
  1786. KMPrint("editWatermark ...")
  1787. }
  1788. @IBAction func batchAddWatermark(_ sender: Any?) {
  1789. if (self.canResponseDocumentAction() == false) {
  1790. return
  1791. }
  1792. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1793. if (document.isHome) {
  1794. } else {
  1795. document.mainViewController?.batchAddWatermark(sender)
  1796. }
  1797. }
  1798. }
  1799. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  1800. if (self.canResponseDocumentAction() == false) {
  1801. return
  1802. }
  1803. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1804. if (document.isHome) {
  1805. } else {
  1806. document.mainViewController?.batchRemoveWatermark(sender)
  1807. }
  1808. }
  1809. }
  1810. @IBAction func removeWatermark(_ sender: Any?) {
  1811. if (self.canResponseDocumentAction() == false) {
  1812. return
  1813. }
  1814. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1815. if (document.isHome) {
  1816. } else {
  1817. document.mainViewController?.removeWatermark(sender)
  1818. }
  1819. }
  1820. }
  1821. @IBAction func templateWatermark(_ sender: Any?) {
  1822. if (self.canResponseDocumentAction() == false) {
  1823. return
  1824. }
  1825. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1826. if (document.isHome) {
  1827. } else {
  1828. document.mainViewController?.templateWatermark(sender)
  1829. }
  1830. }
  1831. }
  1832. @IBAction func batchAddBackground(_ sender: Any?) {
  1833. if (self.canResponseDocumentAction() == false) {
  1834. return
  1835. }
  1836. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1837. if (document.isHome) {
  1838. } else {
  1839. document.mainViewController?.batchAddBackground(sender)
  1840. }
  1841. }
  1842. }
  1843. @IBAction func batchRemoveBackground(_ sender: Any?) {
  1844. if (self.canResponseDocumentAction() == false) {
  1845. return
  1846. }
  1847. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1848. if (document.isHome) {
  1849. } else {
  1850. document.mainViewController?.batchRemoveBackground(sender)
  1851. }
  1852. }
  1853. }
  1854. @IBAction func templateBackground(_ sender: Any?) {
  1855. if (self.canResponseDocumentAction() == false) {
  1856. return
  1857. }
  1858. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1859. if (document.isHome) {
  1860. } else {
  1861. document.mainViewController?.templateBackground(sender)
  1862. }
  1863. }
  1864. }
  1865. @IBAction func addHeaderFooter(_ sender: Any?) {
  1866. if (self.canResponseDocumentAction() == false) {
  1867. return
  1868. }
  1869. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1870. if (document.isHome) {
  1871. } else {
  1872. document.mainViewController?.addHeaderFooter(sender)
  1873. }
  1874. }
  1875. }
  1876. @IBAction func removeHeaderFooter(_ sender: Any?) {
  1877. if (self.canResponseDocumentAction() == false) {
  1878. return
  1879. }
  1880. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1881. if (document.isHome) {
  1882. } else {
  1883. document.mainViewController?.removeHeaderFooter(sender)
  1884. }
  1885. }
  1886. }
  1887. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  1888. if (self.canResponseDocumentAction() == false) {
  1889. return
  1890. }
  1891. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1892. if (document.isHome) {
  1893. } else {
  1894. document.mainViewController?.batchAddHeaderFooter(sender)
  1895. }
  1896. }
  1897. }
  1898. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  1899. if (self.canResponseDocumentAction() == false) {
  1900. return
  1901. }
  1902. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1903. if (document.isHome) {
  1904. } else {
  1905. document.mainViewController?.batchRemoveHeaderFooter(sender)
  1906. }
  1907. }
  1908. }
  1909. @IBAction func templateHeaderFooter(_ sender: Any?) {
  1910. if (self.canResponseDocumentAction() == false) {
  1911. return
  1912. }
  1913. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1914. if (document.isHome) {
  1915. } else {
  1916. document.mainViewController?.templateHeaderFooter(sender)
  1917. }
  1918. }
  1919. }
  1920. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  1921. if (self.canResponseDocumentAction() == false) {
  1922. return
  1923. }
  1924. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1925. if (document.isHome) {
  1926. } else {
  1927. document.mainViewController?.addHeaderFooterBates(sender)
  1928. }
  1929. }
  1930. }
  1931. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  1932. if (self.canResponseDocumentAction() == false) {
  1933. return
  1934. }
  1935. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1936. if (document.isHome) {
  1937. } else {
  1938. document.mainViewController?.removeHeaderFooterBates(sender)
  1939. }
  1940. }
  1941. }
  1942. @IBAction func batchAddBates(_ sender: Any?) {
  1943. if (self.canResponseDocumentAction() == false) {
  1944. return
  1945. }
  1946. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1947. if (document.isHome) {
  1948. } else {
  1949. document.mainViewController?.batchAddBates(sender)
  1950. }
  1951. }
  1952. }
  1953. @IBAction func batchRemoveBates(_ sender: Any?) {
  1954. if (self.canResponseDocumentAction() == false) {
  1955. return
  1956. }
  1957. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1958. if (document.isHome) {
  1959. } else {
  1960. document.mainViewController?.batchRemoveBates(sender)
  1961. }
  1962. }
  1963. }
  1964. @IBAction func templateBates(_ sender: Any?) {
  1965. if (self.canResponseDocumentAction() == false) {
  1966. return
  1967. }
  1968. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1969. if (document.isHome) {
  1970. } else {
  1971. document.mainViewController?.templateBates(sender)
  1972. }
  1973. }
  1974. }
  1975. @IBAction func togglePoster(_ sender: Any?) {
  1976. if (self.canResponseDocumentAction() == false) {
  1977. return
  1978. }
  1979. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1980. if (document.isHome) {
  1981. } else {
  1982. document.mainViewController?.togglePoster(sender)
  1983. }
  1984. }
  1985. }
  1986. @IBAction func toggleMultiple(_ sender: Any?) {
  1987. if (self.canResponseDocumentAction() == false) {
  1988. return
  1989. }
  1990. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1991. if (document.isHome) {
  1992. } else {
  1993. document.mainViewController?.toggleMultiple(sender)
  1994. }
  1995. }
  1996. }
  1997. @IBAction func toggleBooklet(_ sender: Any?) {
  1998. if (self.canResponseDocumentAction() == false) {
  1999. return
  2000. }
  2001. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2002. if (document.isHome) {
  2003. } else {
  2004. document.mainViewController?.toggleBooklet(sender)
  2005. }
  2006. }
  2007. }
  2008. @IBAction func rotateRight(_ sender: Any?) {
  2009. if (self.canResponseDocumentAction() == false) {
  2010. return
  2011. }
  2012. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2013. if (document.isHome) {
  2014. } else {
  2015. document.mainViewController?.rotateRight(sender)
  2016. }
  2017. }
  2018. }
  2019. @IBAction func rotateLeft(_ sender: Any?) {
  2020. if (self.canResponseDocumentAction() == false) {
  2021. return
  2022. }
  2023. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2024. if (document.isHome) {
  2025. } else {
  2026. document.mainViewController?.rotateLeft(sender)
  2027. }
  2028. }
  2029. }
  2030. @IBAction func rotateAllRight(_ sender: Any?) {
  2031. if (self.canResponseDocumentAction() == false) {
  2032. return
  2033. }
  2034. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2035. if (document.isHome) {
  2036. } else {
  2037. document.mainViewController?.rotateAllRight(sender)
  2038. }
  2039. }
  2040. }
  2041. @IBAction func rotateAllLeft(_ sender: Any?) {
  2042. if (self.canResponseDocumentAction() == false) {
  2043. return
  2044. }
  2045. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2046. if (document.isHome) {
  2047. } else {
  2048. document.mainViewController?.rotateAllLeft(sender)
  2049. }
  2050. }
  2051. }
  2052. @IBAction func autoSelectContent(_ sender: Any?) {
  2053. if (self.canResponseDocumentAction() == false) {
  2054. return
  2055. }
  2056. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2057. if (document.isHome) {
  2058. } else {
  2059. document.mainViewController?.autoSelectContent(sender)
  2060. }
  2061. }
  2062. }
  2063. }
  2064. // MARK: - KMSystemWindowMenuRrotocol
  2065. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  2066. func menuItemAction_showForwardTagPage(_ sender: Any) {
  2067. if (self.canResponseDocumentAction() == false) {
  2068. return
  2069. }
  2070. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2071. if (document.isHome) {
  2072. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  2073. } else {
  2074. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  2075. }
  2076. }
  2077. }
  2078. func menuItemAction_showNextTagPage(_ sender: Any) {
  2079. if (self.canResponseDocumentAction() == false) {
  2080. return
  2081. }
  2082. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2083. if (document.isHome) {
  2084. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  2085. } else {
  2086. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  2087. }
  2088. }
  2089. }
  2090. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  2091. if (self.canResponseDocumentAction() == false) {
  2092. return
  2093. }
  2094. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2095. if (document.isHome) {
  2096. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2097. } else {
  2098. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2099. }
  2100. }
  2101. }
  2102. func menuItemAction_mergeAllWindow(_ sender: Any) {
  2103. if (self.canResponseDocumentAction() == false) {
  2104. return
  2105. }
  2106. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2107. if (document.isHome) {
  2108. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  2109. } else {
  2110. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  2111. }
  2112. }
  2113. }
  2114. }
  2115. // MARK: - Analytics (埋点)
  2116. extension KMBrowserWindowController {
  2117. func trackEvent_upgrade() -> Void {
  2118. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  2119. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  2120. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  2121. }
  2122. }