KMBrowserWindowController.swift 81 KB

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