KMBrowserWindowController.swift 79 KB

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