KMBrowserWindowController.swift 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  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. }
  56. @objc func closeAction() {
  57. self.window?.performClose(nil)
  58. }
  59. override func windowShouldClose(_ sender: NSWindow) -> Bool {
  60. if self.browser.tabStripModel.count() > 1 {
  61. self.browser.windowDidBeginToClose()
  62. return false
  63. }
  64. return true
  65. }
  66. override func layoutSubviews() {
  67. super.layoutSubviews()
  68. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
  69. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  70. }
  71. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
  72. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  73. }
  74. if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
  75. button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  76. }
  77. }
  78. // MARK: Dark&Light
  79. func addObserverForAppearanceChange() -> Void {
  80. window?.contentView!.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
  81. }
  82. func removeObserverForAppearanceChange() -> Void {
  83. window?.contentView!.removeObserver(self, forKeyPath: "effectiveAppearance")
  84. }
  85. override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  86. if keyPath == "effectiveAppearance" {
  87. updateViewColor()
  88. }
  89. }
  90. override func updateViewColor() {
  91. super.updateViewColor()
  92. window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
  93. }
  94. // MARK: Public Methods
  95. func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
  96. modeType = toolState
  97. let document = browser.activeTabContents()
  98. if document != nil {
  99. if document!.isHome {
  100. homeRightTabStripView_.isHidden = modeType == .Home
  101. } else {
  102. self.homeRightStripView.isHidden = true
  103. }
  104. } else {
  105. self.homeRightStripView.isHidden = true
  106. }
  107. homeRightTabStripView_.homeRefreshButton.isEnabled = true
  108. homeRightTabStripView_.homeUploadButton.isEnabled = true
  109. filterType = 0
  110. rightTabStripView_.sortPopUpButton.removeAllItems()
  111. rightTabStripView_.filterPopUpButton.removeAllItems()
  112. rightTabStripView_.updateView()
  113. }
  114. override var hasToolbar: Bool {
  115. get {
  116. return false
  117. }
  118. }
  119. var km_browser: KMBrowser? {
  120. get {
  121. return self.browser as? KMBrowser
  122. }
  123. }
  124. // MARK: Private Methods
  125. func openDocumentWindow() -> Void {
  126. // let panel = NSOpenPanel()
  127. // panel.allowsMultipleSelection = false
  128. // panel.allowedFileTypes = ["pdf"]
  129. // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  130. // if response == .OK {
  131. // let openPath = panel.url?.path
  132. // let selectDocument = self.selectTabContents(path: openPath!)
  133. // if selectDocument != nil {
  134. // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
  135. // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
  136. // return
  137. // }
  138. // if !panel.url!.path.isPDFValid() {
  139. // let alert = NSAlert()
  140. // alert.alertStyle = .critical
  141. // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  142. // alert.runModal()
  143. // return
  144. // }
  145. // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
  146. // print("openDocumentWindow")
  147. // }
  148. // }
  149. // }
  150. // MARK TODO: + 号开启
  151. // self.browser.addHomeTabContents()
  152. self.tabStripView?.addTabButton?.layer?.backgroundColor = .clear
  153. self.km_browser?.addNewTabContents()
  154. }
  155. // override func openDocument(_ sender: Any!) {
  156. // self.openDocumentWindow()
  157. // }
  158. func selectTabContents(path filePath: String) -> KMMainDocument? {
  159. let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
  160. var selectDocument: KMMainDocument?
  161. if document != nil {
  162. if document!.isKind(of: KMMainDocument.self) {
  163. selectDocument = document as! KMMainDocument
  164. }
  165. }
  166. return selectDocument
  167. }
  168. // MARK: Getter
  169. override var rightStripView: NSView! {
  170. get {
  171. return rightTabStripView_
  172. }
  173. }
  174. override var homeRightStripView: NSView! {
  175. get {
  176. return homeRightTabStripView_
  177. }
  178. }
  179. // MARK: Button Action
  180. func commandDispatch(_ sender: Any) -> Void {
  181. openDocumentWindow()
  182. }
  183. func closeAllTabs(_ sender: Any) -> Void {
  184. if self.browser != nil {
  185. self.browser.closeAllTabs()
  186. }
  187. }
  188. func openNewWindow(_ sender: Any) -> Void {
  189. if let noti = sender as? NSNotification, noti.object is CTTabController {
  190. if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
  191. return
  192. }
  193. }
  194. if self.browser != nil {
  195. let activeInt = self.browser.activeTabIndex()
  196. let activeTab = self.browser.activeTabContents()
  197. self.browser.closeTab(at: activeInt, makeHistory: false)
  198. let browser: KMBrowser = KMBrowser.init()
  199. browser.windowController = KMBrowserWindowController.init(browser: browser)
  200. browser.addHomeTabContents()
  201. browser.windowController.showWindow(self)
  202. // browser.add(activeTab, inForeground: false)
  203. // browser.selectTab(at: 1)
  204. if activeTab?.fileURL == nil {
  205. return
  206. }
  207. let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
  208. let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
  209. KMMainDocument().tryToUnlockDocument(pdfDoc!)
  210. if ((pdfDoc?.isLocked)! == true) {
  211. KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
  212. if result == .cancel { /// 关闭
  213. return
  214. }
  215. /// 解密成功
  216. var selectDocument: KMMainDocument? = nil
  217. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  218. selectDocument = (document as! KMMainDocument)
  219. }
  220. if selectDocument != nil {
  221. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  222. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  223. if (selectDocument?.browser.window.isVisible)! as Bool {
  224. selectDocument?.browser.window.orderFront(nil)
  225. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  226. selectDocument?.browser.window.orderFront(nil)
  227. }
  228. } else {
  229. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, _, error in
  230. if (error == nil) {
  231. (document as! KMMainDocument).mainViewController?.password = password
  232. }
  233. }
  234. }
  235. }
  236. } else {
  237. var selectDocument: KMMainDocument? = nil
  238. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  239. selectDocument = (document as! KMMainDocument)
  240. }
  241. if selectDocument != nil {
  242. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  243. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  244. if (selectDocument?.browser.window.isVisible)! as Bool {
  245. selectDocument?.browser.window.orderFront(nil)
  246. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  247. selectDocument?.browser.window.orderFront(nil)
  248. }
  249. } else {
  250. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
  251. }
  252. }
  253. }
  254. }
  255. }
  256. func canMergeAllWindow() -> Bool {
  257. return self.fetchBrowserWindowControllers().count > 0
  258. }
  259. fileprivate func fetchBrowserWindowControllers() -> [KMBrowserWindowController] {
  260. var windowArray: [KMBrowserWindowController] = []
  261. for window in NSApp.windows {
  262. guard let windowController = window.windowController, windowController is KMBrowserWindowController else {
  263. continue
  264. }
  265. if let _tabScripC = (windowController as? KMBrowserWindowController)?.tabStripController, _tabScripC.viewsCount() <= 1 {
  266. continue
  267. }
  268. if (window.isVisible && (windowController.isEqual(to: self) == false)) {
  269. windowArray.append(windowController as! KMBrowserWindowController)
  270. }
  271. }
  272. return windowArray
  273. }
  274. func mergeAllWindow(_ sender: Any) {
  275. let windowArray = self.fetchBrowserWindowControllers()
  276. if (windowArray.count <= 0) {
  277. return
  278. }
  279. for windowC in windowArray {
  280. // 拼接窗口 [拼接窗口里的标签,除了home标签]
  281. self.append(windowC, toTabView: NSView())
  282. if let browser = windowC.browser {
  283. if (browser.tabCount() <= 1 && browser.activeTabContents().isHome) {
  284. windowC.close()
  285. }
  286. }
  287. }
  288. }
  289. override func tabDidSelect(_ notification: Notification!) {
  290. super.tabDidSelect(notification)
  291. if let _userInfo = notification.userInfo, let _newContents = _userInfo[CTTabNewContentsUserInfoKey] as? KMMainDocument {
  292. _newContents.addWindowController(self)
  293. }
  294. }
  295. override func layoutTabContentArea(_ frame: NSRect) {
  296. super.layoutTabContentArea(frame)
  297. self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
  298. }
  299. override func openDocument(_ sender: Any!) {
  300. guard let _window = self.window else {
  301. return
  302. }
  303. NSOpenPanel.km_open_pdf_multi_success(_window, panel: nil) { urls in
  304. for url in urls {
  305. NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
  306. }
  307. }
  308. }
  309. }
  310. }
  311. // MARK: - KMToolbarRightViewDelegate
  312. extension KMBrowserWindowController: KMToolbarRightViewDelegate {
  313. func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
  314. self.trackEvent_upgrade()
  315. KMComparativeTableViewController.show(window: self.window!, .upgrade)
  316. }
  317. func userInfoButtonAction(_ sender: NSButton) {
  318. if KMLightMemberManager.manager.isLogin() {
  319. Task { @MainActor in
  320. if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
  321. KMAccountInfoWindowController.show(window: self.window!)
  322. } else {
  323. KMLoginWindowController.show(window: self.window!)
  324. }
  325. }
  326. } else {
  327. KMLoginWindowController.show(window: self.window!)
  328. }
  329. }
  330. func homeRefreshButtonAction(_ sender: NSButton?) {
  331. self.layoutSubviews()
  332. }
  333. func homeUploadButtonAction(_ sender: NSButton) {
  334. }
  335. func homeMenuSortAction(_ sender: NSPopUpButton) {
  336. }
  337. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  338. }
  339. }
  340. // MARK: - KMUploadFileDelegate
  341. extension KMBrowserWindowController: KMUploadFileDelegate {
  342. // override func cancelOperation(_ sender: Any?) {
  343. //
  344. // }
  345. }
  346. // MARK: - NSSearchFieldDelegate
  347. extension KMBrowserWindowController: NSSearchFieldDelegate {
  348. func controlTextDidChange(_ obj: Notification) {
  349. }
  350. func controlTextDidEndEditing(_ obj: Notification) {
  351. }
  352. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  353. var result = false
  354. return result
  355. }
  356. }
  357. // MARK: -
  358. // MARK: Menu Actions
  359. extension KMBrowserWindowController {
  360. func canResponseDocumentAction() -> Bool {
  361. if (self.browser == nil) {
  362. return false
  363. }
  364. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  365. return false
  366. }
  367. return true
  368. }
  369. }
  370. // MARK: -
  371. // MARK: File Menu
  372. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  373. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  374. if (self.browser == nil) {
  375. return false
  376. }
  377. guard let action = menuItem.action else {
  378. return false
  379. }
  380. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  381. return false
  382. }
  383. if (KMSystemMenu.isFileSelector(sel: action)) {
  384. if (document.isHome) {
  385. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  386. menuItem.action == KMSystemMenu.File.propertySelector ||
  387. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  388. menuItem.action == KMSystemMenu.File.printSelector ||
  389. menuItem.action == KMSystemMenu.File.saveAsFlattenedPDFSelector) {
  390. return false
  391. }
  392. return document.homeViewController!.validateMenuItem(menuItem)
  393. } else {
  394. return document.mainViewController!.validateMenuItem(menuItem)
  395. }
  396. }
  397. if (KMSystemMenu.isEditSelector(sel: action)) {
  398. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  399. }
  400. if (KMSystemMenu.isViewSelector(sel: action)) {
  401. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  402. }
  403. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  404. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  405. }
  406. if (KMSystemMenu.isGotoSelector(sel: action)) {
  407. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  408. }
  409. if (KMSystemMenu.isToolSelector(sel: action)) {
  410. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  411. }
  412. if (KMSystemMenu.isWindowSelector(sel: action)) {
  413. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  414. }
  415. if action == #selector(redactAction) {
  416. return document.isHome ? false : true
  417. }
  418. return true
  419. }
  420. }
  421. extension KMBrowserWindowController {
  422. @IBAction func menuItemAction_openFile(_ sender: Any) {
  423. super.openDocument(sender)
  424. }
  425. @IBAction func importFromFile(_ sender: Any) {
  426. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  427. if (document.isHome) {
  428. document.homeViewController?.importFromFile(sender)
  429. } else {
  430. self.homeVC = KMHomeViewController()
  431. self.homeVC?.importFromFile(sender)
  432. }
  433. }
  434. @IBAction func openBlankPage(_ sender: Any) {
  435. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  436. if (document.isHome) {
  437. document.homeViewController?.openBlankPage()
  438. } else {
  439. self.homeVC = KMHomeViewController()
  440. self.homeVC?.openBlankPage()
  441. }
  442. }
  443. @IBAction func importFromScanner(_ sender: Any) {
  444. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  445. if (document.isHome) {
  446. document.homeViewController?.importFromScanner()
  447. } else {
  448. self.homeVC = KMHomeViewController()
  449. self.homeVC?.importFromScanner()
  450. }
  451. }
  452. @IBAction func menuItemAction_newTab(_ sender: Any) {
  453. self.openDocumentWindow()
  454. }
  455. /// New
  456. @IBAction func newDocumentFromClipboard(_ sender: Any?) {
  457. KMPrint("newDocumentFromClipboard")
  458. }
  459. @IBAction func newDocumentFromImage(_ sender: Any?) {
  460. KMPrint("importFromWebPage")
  461. }
  462. @IBAction func importFromWebPage(_ sender: Any?) {
  463. KMPrint("importFromWebPage")
  464. }
  465. /// screenShot
  466. @IBAction func screenShot_SelectArea(_ sender: Any?) {
  467. KMPrint("screenShot_SelectArea")
  468. }
  469. @IBAction func screenShot_Window(_ sender: Any?) {
  470. KMPrint("screenShot_Window")
  471. }
  472. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  473. KMPrint("screenShot_FullScreenDelay")
  474. }
  475. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  476. KMPrint("screenShot_FullScreen")
  477. }
  478. @IBAction func pasteAsPlainText(_ sender: Any?) {
  479. KMPrint("pasteAsPlainText")
  480. }
  481. @IBAction func deselectAll(_ sender: Any?) {
  482. KMPrint("deselectAll")
  483. }
  484. @IBAction func searchPDF(_ sender: Any?) {
  485. KMPrint("searchPDF")
  486. }
  487. @IBAction func notesLink(_ sender: Any?) {
  488. KMPrint("notesLink")
  489. }
  490. @IBAction func notesStamp(_ sender: Any?) {
  491. KMPrint("notesStamp")
  492. }
  493. @IBAction func table(_ sender: Any?) {
  494. KMPrint("table ...")
  495. }
  496. @IBAction func image(_ sender: Any?) {
  497. KMPrint("image ...")
  498. }
  499. @IBAction func addForm(_ sender: Any?) {
  500. KMPrint("addForm ...")
  501. }
  502. @IBAction func editNote(_ sender: Any?) {
  503. KMPrint("editNote ...")
  504. }
  505. @IBAction func togglePresentation(_ sender: Any?) {
  506. KMPrint("togglePresentation ...")
  507. }
  508. @IBAction func chooseTransition(_ sender: Any?) {
  509. KMPrint("chooseTransition ...")
  510. }
  511. @IBAction func toggleAutoFlow(_ sender: Any?) {
  512. KMPrint("toggleAutoFlow ...")
  513. }
  514. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  515. KMPrint("chooseAutoFlowSetting ...")
  516. }
  517. @IBAction func toggleReadingBar(_ sender: Any?) {
  518. KMPrint("toggleReadingBar ...")
  519. }
  520. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  521. KMPrint("toggleLeftSidePane ...")
  522. }
  523. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  524. KMPrint("changeLeftSidePaneState ...")
  525. }
  526. @IBAction func splitViewAction(_ sender: Any?) {
  527. KMPrint("splitViewAction ...")
  528. }
  529. @IBAction func themesColor(_ sender: Any?) {
  530. KMPrint("themesColor ...")
  531. }
  532. @IBAction func toggleStatusBar(_ sender: Any?) {
  533. KMPrint("toggleStatusBar ...")
  534. }
  535. @IBAction func toggleToolbarShow(_ sender: Any?) {
  536. KMPrint("toggleToolbarShow ...")
  537. }
  538. @IBAction func changeDisplayMode(_ sender: Any?) {
  539. KMPrint("changeDisplayMode ...")
  540. }
  541. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  542. KMPrint("toggleDisplayAsBook ...")
  543. }
  544. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  545. KMPrint("toggleDisplayPageBreaks ...")
  546. }
  547. @IBAction func changeDisplayBox(_ sender: Any?) {
  548. KMPrint("changeDisplayBox ...")
  549. }
  550. @IBAction func changeColor(_ sender: Any?) {
  551. KMPrint("changeColor ...")
  552. }
  553. @IBAction func changeFont(_ sender: Any?) {
  554. KMPrint("changeFont ...")
  555. }
  556. @IBAction func changeAttributes(_ sender: Any?) {
  557. KMPrint("changeAttributes ...")
  558. }
  559. @IBAction func alignLeft(_ sender: Any?) {
  560. KMPrint("alignLeft ...")
  561. }
  562. @IBAction func alignRight(_ sender: Any?) {
  563. KMPrint("alignRight ...")
  564. }
  565. @IBAction func alignCenter(_ sender: Any?) {
  566. KMPrint("alignCenter ...")
  567. }
  568. @IBAction func createNewNote(_ sender: Any?) {
  569. KMPrint("createNewNote ...")
  570. }
  571. @IBAction func toggleHideNotes(_ sender: Any?) {
  572. KMPrint("toggleHideNotes ...")
  573. }
  574. @IBAction func changeDisplaySinglePages(_ sender: Any?) {
  575. KMPrint("changeDisplaySinglePages ...")
  576. }
  577. @IBAction func changeDisplayContinuous(_ sender: Any?) {
  578. KMPrint("changeDisplayContinuous ...")
  579. }
  580. @IBAction func doGoToNextPage(_ sender: Any?) {
  581. KMPrint("doGoToNextPage ...")
  582. }
  583. @IBAction func doGoToPreviousPage(_ sender: Any?) {
  584. KMPrint("doGoToPreviousPage ...")
  585. }
  586. @IBAction func doGoToFirstPage(_ sender: Any?) {
  587. KMPrint("doGoToFirstPage ...")
  588. }
  589. @IBAction func doGoToLastPage(_ sender: Any?) {
  590. KMPrint("doGoToLastPage ...")
  591. }
  592. @IBAction func allGoToNextPage(_ sender: Any?) {
  593. KMPrint("allGoToNextPage ...")
  594. }
  595. @IBAction func allGoToPreviousPage(_ sender: Any?) {
  596. KMPrint("allGoToPreviousPage ...")
  597. }
  598. @IBAction func allGoToFirstPage(_ sender: Any?) {
  599. KMPrint("allGoToFirstPage ...")
  600. }
  601. @IBAction func allGoToLastPage(_ sender: Any?) {
  602. KMPrint("allGoToLastPage ...")
  603. }
  604. @IBAction func doGoToPage(_ sender: Any?) {
  605. KMPrint("doGoToPage ...")
  606. }
  607. @IBAction func doGoBack(_ sender: Any?) {
  608. KMPrint("doGoBack ...")
  609. }
  610. @IBAction func doGoForward(_ sender: Any?) {
  611. KMPrint("doGoForward ...")
  612. }
  613. @IBAction func goToMarkedPage(_ sender: Any?) {
  614. KMPrint("goToMarkedPage ...")
  615. }
  616. @IBAction func markPage(_ sender: Any?) {
  617. KMPrint("markPage ...")
  618. }
  619. @IBAction func doZoomIn(_ sender: Any?) {
  620. KMPrint("doZoomIn ...")
  621. }
  622. @IBAction func doZoomOut(_ sender: Any?) {
  623. KMPrint("doZoomOut ...")
  624. }
  625. @IBAction func doZoomToActualSize(_ sender: Any?) {
  626. KMPrint("doZoomToActualSize ...")
  627. }
  628. @IBAction func doZoomToPhysicalSize(_ sender: Any?) {
  629. KMPrint("doZoomToPhysicalSize ...")
  630. }
  631. @IBAction func doZoomToFit(_ sender: Any?) {
  632. KMPrint("doZoomToFit ...")
  633. }
  634. @IBAction func alternateZoomToFit(_ sender: Any?) {
  635. KMPrint("alternateZoomToFit ...")
  636. }
  637. @IBAction func doZoomToSelection(_ sender: Any?) {
  638. KMPrint("doZoomToSelection ...")
  639. }
  640. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  641. KMPrint("doMarqueeZoomTool ...")
  642. }
  643. @IBAction func doAutoScale(_ sender: Any?) {
  644. KMPrint("doAutoScale ...")
  645. }
  646. @IBAction func toggleAutoScale(_ sender: Any?) {
  647. KMPrint("toggleAutoScale ...")
  648. }
  649. @IBAction func getInfo(_ sender: Any?) {
  650. KMPrint("getInfo ...")
  651. }
  652. // @IBAction func delete(_ sender: Any?) {
  653. // KMPrint("delete ...")
  654. // }
  655. // @IBAction func paste(_ sender: Any?) {
  656. // KMPrint("paste ...")
  657. // }
  658. @IBAction func alternatePaste(_ sender: Any?) {
  659. KMPrint("alternatePaste ...")
  660. }
  661. @IBAction func copy(_ sender: Any?) {
  662. KMPrint("copy ...")
  663. }
  664. @IBAction func cut(_ sender: Any?) {
  665. KMPrint("cut ...")
  666. }
  667. @IBAction func changeToolMode(_ sender: Any?) {
  668. KMPrint("changeToolMode ...")
  669. }
  670. @IBAction func toggleFullscreen(_ sender: Any?) {
  671. KMPrint("toggleFullscreen ...")
  672. }
  673. @IBAction func toggleRightSidePane(_ sender: Any?) {
  674. KMPrint("toggleRightSidePane ...")
  675. }
  676. @IBAction func performFit(_ sender: Any?) {
  677. KMPrint("performFit ...")
  678. }
  679. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  680. KMPrint("changeRightSidePaneState ...")
  681. }
  682. @IBAction func changeFindPaneState(_ sender: Any?) {
  683. KMPrint("changeFindPaneState ...")
  684. }
  685. @IBAction func toggleSplitPDF(_ sender: Any?) {
  686. KMPrint("toggleSplitPDF ...")
  687. }
  688. @IBAction func search(_ sender: Any?) {
  689. KMPrint("search ...")
  690. }
  691. @IBAction func searchNotes(_ sender: Any?) {
  692. KMPrint("searchNotes ...")
  693. }
  694. @IBAction func password(_ sender: Any?) {
  695. KMPrint("password ...")
  696. }
  697. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  698. KMPrint("savePDFSettingToDefaults ...")
  699. }
  700. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  701. KMPrint("toggleCaseInsensitiveSearch ...")
  702. }
  703. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  704. KMPrint("toggleWholeWordSearch ...")
  705. }
  706. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  707. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  708. }
  709. @IBAction func performFindPanelAction(_ sender: Any?) {
  710. KMPrint("performFindPanelAction ...")
  711. }
  712. @IBAction func scrollUp(_ sender: Any?) {
  713. KMPrint("scrollUp ...")
  714. }
  715. @IBAction func scrollDown(_ sender: Any?) {
  716. KMPrint("scrollDown ...")
  717. }
  718. @IBAction func scrollRight(_ sender: Any?) {
  719. KMPrint("scrollRight ...")
  720. }
  721. @IBAction func scrollLeft(_ sender: Any?) {
  722. KMPrint("scrollLeft ...")
  723. }
  724. @IBAction func selectSelectedNote(_ sender: Any?) {
  725. KMPrint("selectSelectedNote ...")
  726. }
  727. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  728. KMPrint("goToSelectedOutlineItem ...")
  729. }
  730. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  731. KMPrint("goToSelectedFindResults ...")
  732. }
  733. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  734. KMPrint("toggleSelectedSnapshots ...")
  735. }
  736. @IBAction func selfSignProfile(_ sender: Any?) {
  737. KMPrint("selfSignProfile ...")
  738. }
  739. @IBAction func highlightFormFiled(_ sender: Any?) {
  740. KMPrint("highlightFormFiled ...")
  741. }
  742. @IBAction func highlightLinks(_ sender: Any?) {
  743. KMPrint("highlightLinks ...")
  744. }
  745. @IBAction func resetForm(_ sender: Any?) {
  746. KMPrint("resetForm ...")
  747. }
  748. @IBAction func removeAllAnnotation(_ sender: Any?) {
  749. KMPrint("removeAllAnnotation ...")
  750. }
  751. @IBAction func link(_ sender: Any?) {
  752. KMPrint("link ...")
  753. }
  754. @IBAction func pageEdit(_ sender: Any?) {
  755. KMPrint("pageEdit ...")
  756. }
  757. @IBAction func ocr(_ sender: Any?) {
  758. KMPrint("ocr ...")
  759. }
  760. @IBAction func insertPage(_ sender: Any?) {
  761. KMPrint("insertPage ...")
  762. }
  763. @IBAction func split(_ sender: Any?) {
  764. KMPrint("split ...")
  765. }
  766. @IBAction func comparison(_ sender: Any?) {
  767. KMPrint("comparison ...")
  768. }
  769. @IBAction func contentComparison(_ sender: Any?) {
  770. KMPrint("contentComparison ...")
  771. }
  772. @IBAction func coverageComparison(_ sender: Any?) {
  773. KMPrint("coverageComparison ...")
  774. }
  775. @IBAction func readMode(_ sender: Any?) {
  776. KMPrint("readMode ...")
  777. }
  778. @IBAction func changeFormType(_ sender: Any?) {
  779. KMPrint("changeFormType ...")
  780. }
  781. @IBAction func changeSelfSignType(_ sender: Any?) {
  782. KMPrint("changeSelfSignType ...")
  783. }
  784. @IBAction func clearAllForm(_ sender: Any?) {
  785. KMPrint("clearAllForm ...")
  786. }
  787. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  788. KMPrint("thumbnailSizeScaling ...")
  789. }
  790. @IBAction func textEditAction(_ sender: Any?) {
  791. KMPrint("textEditAction ...")
  792. }
  793. @IBAction func redactAction(_ sender: Any?) {
  794. if (self.canResponseDocumentAction() == false) {
  795. return
  796. }
  797. if let document = self.browser.activeTabContents() as? KMMainDocument {
  798. if document.isHome == false {
  799. document.mainViewController?.menuItemAction_redact(sender)
  800. }
  801. }
  802. }
  803. }
  804. // MARK: - KMSystemFileMenuProtocol
  805. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  806. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  807. if (self.canResponseDocumentAction() == false) {
  808. return
  809. }
  810. if let document = self.browser.activeTabContents() as? KMMainDocument {
  811. if (document.isHome) {
  812. // document.homeViewController?.menuItemClick_mergePDF(sender)
  813. } else {
  814. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  815. }
  816. }
  817. }
  818. func menuItemClick_mergePDF(_ sender: Any) {
  819. if (self.canResponseDocumentAction() == false) {
  820. return
  821. }
  822. if let document = self.browser.activeTabContents() as? KMMainDocument {
  823. if (document.isHome) {
  824. document.homeViewController?.menuItemClick_mergePDF(sender)
  825. } else {
  826. document.mainViewController?.menuItemClick_mergePDF(sender)
  827. }
  828. }
  829. }
  830. func menuItemClick_Compress(_ sender: Any) {
  831. if (self.canResponseDocumentAction() == false) {
  832. return
  833. }
  834. if let document = self.browser.activeTabContents() as? KMMainDocument {
  835. if (document.isHome) {
  836. document.homeViewController?.menuItemClick_Compress(sender)
  837. } else {
  838. document.mainViewController?.menuItemClick_Compress(sender)
  839. }
  840. }
  841. }
  842. func menuItemAction_ConvertToWord(_ sender: Any) {
  843. if (self.canResponseDocumentAction() == false) {
  844. return
  845. }
  846. if let document = self.browser.activeTabContents() as? KMMainDocument {
  847. if (document.isHome) {
  848. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  849. } else {
  850. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  851. }
  852. }
  853. }
  854. func menuItemAction_ConvertToExcel(_ sender: Any) {
  855. if (self.canResponseDocumentAction() == false) {
  856. return
  857. }
  858. if let document = self.browser.activeTabContents() as? KMMainDocument {
  859. if (document.isHome) {
  860. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  861. } else {
  862. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  863. }
  864. }
  865. }
  866. func menuItemAction_ConvertToPPT(_ sender: Any) {
  867. if (self.canResponseDocumentAction() == false) {
  868. return
  869. }
  870. if let document = self.browser.activeTabContents() as? KMMainDocument {
  871. if (document.isHome) {
  872. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  873. } else {
  874. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  875. }
  876. }
  877. }
  878. func menuItemAction_ConvertToRTF(_ sender: Any) {
  879. if (self.canResponseDocumentAction() == false) {
  880. return
  881. }
  882. if let document = self.browser.activeTabContents() as? KMMainDocument {
  883. if (document.isHome) {
  884. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  885. } else {
  886. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  887. }
  888. }
  889. }
  890. func menuItemAction_ConvertToHTML(_ sender: Any) {
  891. if (self.canResponseDocumentAction() == false) {
  892. return
  893. }
  894. if let document = self.browser.activeTabContents() as? KMMainDocument {
  895. if (document.isHome) {
  896. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  897. } else {
  898. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  899. }
  900. }
  901. }
  902. func menuItemAction_ConvertToText(_ sender: Any) {
  903. if (self.canResponseDocumentAction() == false) {
  904. return
  905. }
  906. if let document = self.browser.activeTabContents() as? KMMainDocument {
  907. if (document.isHome) {
  908. document.homeViewController?.menuItemAction_ConvertToText(sender)
  909. } else {
  910. document.mainViewController?.menuItemAction_ConvertToText(sender)
  911. }
  912. }
  913. }
  914. func menuItemAction_ConvertToCSV(_ sender: Any) {
  915. if (self.canResponseDocumentAction() == false) {
  916. return
  917. }
  918. if let document = self.browser.activeTabContents() as? KMMainDocument {
  919. if (document.isHome) {
  920. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  921. } else {
  922. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  923. }
  924. }
  925. }
  926. func menuItemAction_ConvertToImage(_ sender: Any) {
  927. if (self.canResponseDocumentAction() == false) {
  928. return
  929. }
  930. if let document = self.browser.activeTabContents() as? KMMainDocument {
  931. if (document.isHome) {
  932. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  933. } else {
  934. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  935. }
  936. }
  937. }
  938. func menuItemClick_SettingPassword(_ sender: Any) {
  939. if (self.canResponseDocumentAction() == false) {
  940. return
  941. }
  942. if let document = self.browser.activeTabContents() as? KMMainDocument {
  943. if (document.isHome) {
  944. document.homeViewController?.menuItemClick_SettingPassword(sender)
  945. } else {
  946. document.mainViewController?.menuItemClick_SettingPassword(sender)
  947. }
  948. }
  949. }
  950. func menuItemClick_RemovePassword(_ sender: Any) {
  951. if (self.canResponseDocumentAction() == false) {
  952. return
  953. }
  954. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  955. document.mainViewController?.menuItemClick_RemovePassword(sender)
  956. }
  957. }
  958. func menuItemAction_closeWindow(_ sender: Any) {
  959. if (self.canResponseDocumentAction() == false) {
  960. return
  961. }
  962. if let document = self.browser.activeTabContents() as? KMMainDocument {
  963. if (document.isHome) {
  964. document.homeViewController?.menuItemAction_closeWindow(sender)
  965. } else {
  966. document.mainViewController?.menuItemAction_closeWindow(sender)
  967. }
  968. }
  969. }
  970. func menuItemAction_closeAllWindows(_ sender: Any) {
  971. if (self.canResponseDocumentAction() == false) {
  972. return
  973. }
  974. if let document = self.browser.activeTabContents() as? KMMainDocument {
  975. if (document.isHome) {
  976. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  977. } else {
  978. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  979. }
  980. }
  981. }
  982. func menuItemAction_closeTagPage(_ 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_closeTagPage(sender)
  988. }
  989. }
  990. func menuItemAction_showInFinder(_ 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_showInFinder(sender)
  996. }
  997. }
  998. func menuItemAction_property(_ 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_property(sender)
  1004. }
  1005. }
  1006. func menuItemAction_print(_ 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_print(sender)
  1012. }
  1013. }
  1014. }
  1015. // MARK: - KMSystemViewMenuProtocol
  1016. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  1017. func menuItemAction_adjustWidth(_ sender: Any) {
  1018. if (self.canResponseDocumentAction() == false) {
  1019. return
  1020. }
  1021. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1022. document.mainViewController?.menuItemAction_adjustWidth(sender)
  1023. }
  1024. }
  1025. func menuItemAction_adjustPage(_ sender: Any) {
  1026. if (self.canResponseDocumentAction() == false) {
  1027. return
  1028. }
  1029. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1030. document.mainViewController?.menuItemAction_adjustPage(sender)
  1031. }
  1032. }
  1033. func menuItemAction_size(_ sender: Any) {
  1034. if (self.canResponseDocumentAction() == false) {
  1035. return
  1036. }
  1037. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1038. document.mainViewController?.menuItemAction_size(sender)
  1039. }
  1040. }
  1041. func menuItemAction_zoomOut(_ sender: Any) {
  1042. if (self.canResponseDocumentAction() == false) {
  1043. return
  1044. }
  1045. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1046. document.mainViewController?.menuItemAction_zoomOut(sender)
  1047. }
  1048. }
  1049. func menuItemAction_zoomIn(_ sender: Any) {
  1050. if (self.canResponseDocumentAction() == false) {
  1051. return
  1052. }
  1053. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1054. document.mainViewController?.menuItemAction_zoomIn(sender)
  1055. }
  1056. }
  1057. func menuItemAction_singlePage(_ sender: Any) {
  1058. if (self.canResponseDocumentAction() == false) {
  1059. return
  1060. }
  1061. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1062. document.mainViewController?.menuItemAction_singlePage(sender)
  1063. }
  1064. }
  1065. func menuItemAction_singlePageContinue(_ sender: Any) {
  1066. if (self.canResponseDocumentAction() == false) {
  1067. return
  1068. }
  1069. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1070. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1071. }
  1072. }
  1073. func menuItemAction_doublePage(_ sender: Any) {
  1074. if (self.canResponseDocumentAction() == false) {
  1075. return
  1076. }
  1077. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1078. document.mainViewController?.menuItemAction_doublePage(sender)
  1079. }
  1080. }
  1081. func menuItemAction_doublePageContinue(_ sender: Any) {
  1082. if (self.canResponseDocumentAction() == false) {
  1083. return
  1084. }
  1085. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1086. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1087. }
  1088. }
  1089. func menuItemAction_bookMode(_ sender: Any) {
  1090. if (self.canResponseDocumentAction() == false) {
  1091. return
  1092. }
  1093. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1094. document.mainViewController?.menuItemAction_bookMode(sender)
  1095. }
  1096. }
  1097. func menuItemAction_readMode(_ sender: Any) {
  1098. if (self.canResponseDocumentAction() == false) {
  1099. return
  1100. }
  1101. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1102. document.mainViewController?.menuItemAction_readMode(sender)
  1103. }
  1104. }
  1105. func menuItemAction_showSplitPage(_ sender: Any) {
  1106. if (self.canResponseDocumentAction() == false) {
  1107. return
  1108. }
  1109. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1110. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1111. }
  1112. }
  1113. func menuItemAction_rotateLeft(_ sender: Any) {
  1114. if (self.canResponseDocumentAction() == false) {
  1115. return
  1116. }
  1117. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1118. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1119. }
  1120. }
  1121. func menuItemAction_rotateRight(_ sender: Any) {
  1122. if (self.canResponseDocumentAction() == false) {
  1123. return
  1124. }
  1125. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1126. document.mainViewController?.menuItemAction_rotateRight(sender)
  1127. }
  1128. }
  1129. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1130. if (self.canResponseDocumentAction() == false) {
  1131. return
  1132. }
  1133. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1134. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1135. }
  1136. }
  1137. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1138. if (self.canResponseDocumentAction() == false) {
  1139. return
  1140. }
  1141. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1142. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1143. }
  1144. }
  1145. func menuItemAction_view_readMode(_ sender: Any) {
  1146. if (self.canResponseDocumentAction() == false) {
  1147. return
  1148. }
  1149. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1150. document.mainViewController?.menuItemAction_view_readMode(sender)
  1151. }
  1152. }
  1153. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1154. if (self.canResponseDocumentAction() == false) {
  1155. return
  1156. }
  1157. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1158. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1159. }
  1160. }
  1161. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1162. if (self.canResponseDocumentAction() == false) {
  1163. return
  1164. }
  1165. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1166. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1167. }
  1168. }
  1169. func menuItemAction_thumai(_ sender: Any) {
  1170. if (self.canResponseDocumentAction() == false) {
  1171. return
  1172. }
  1173. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1174. document.mainViewController?.menuItemAction_thumai(sender)
  1175. }
  1176. }
  1177. func menuItemAction_outline(_ 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_outline(sender)
  1183. }
  1184. }
  1185. func menuItemAction_bookmark(_ sender: Any) {
  1186. if (self.canResponseDocumentAction() == false) {
  1187. return
  1188. }
  1189. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1190. document.mainViewController?.menuItemAction_bookmark(sender)
  1191. }
  1192. }
  1193. func menuItemAction_annotation(_ sender: Any) {
  1194. if (self.canResponseDocumentAction() == false) {
  1195. return
  1196. }
  1197. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1198. document.mainViewController?.menuItemAction_annotation(sender)
  1199. }
  1200. }
  1201. func menuItemAction_search(_ sender: Any) {
  1202. if (self.canResponseDocumentAction() == false) {
  1203. return
  1204. }
  1205. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1206. document.mainViewController?.menuItemAction_search(sender)
  1207. }
  1208. }
  1209. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1210. if (self.canResponseDocumentAction() == false) {
  1211. return
  1212. }
  1213. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1214. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1215. }
  1216. }
  1217. }
  1218. // MARK: - KMSystemEditMenuProtocol
  1219. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1220. func menuItemAction_find(_ 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_find(sender)
  1226. }
  1227. }
  1228. }
  1229. // MARK: - Annotation Menu
  1230. extension KMBrowserWindowController {
  1231. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1232. if (self.canResponseDocumentAction() == false) {
  1233. return
  1234. }
  1235. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1236. document.mainViewController?.menuItemAction_highlight(sender)
  1237. }
  1238. }
  1239. @IBAction func menuItemAction_underline(_ sender: Any) {
  1240. if (self.canResponseDocumentAction() == false) {
  1241. return
  1242. }
  1243. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1244. document.mainViewController?.menuItemAction_underline(sender)
  1245. }
  1246. }
  1247. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1248. if (self.canResponseDocumentAction() == false) {
  1249. return
  1250. }
  1251. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1252. document.mainViewController?.menuItemAction_deleteLine(sender)
  1253. }
  1254. }
  1255. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1256. if (self.canResponseDocumentAction() == false) {
  1257. return
  1258. }
  1259. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1260. document.mainViewController?.menuItemAction_freehand(sender)
  1261. }
  1262. }
  1263. @IBAction func menuItemAction_text(_ sender: Any) {
  1264. if (self.canResponseDocumentAction() == false) {
  1265. return
  1266. }
  1267. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1268. document.mainViewController?.menuItemAction_text(sender)
  1269. }
  1270. }
  1271. @IBAction func menuItemAction_note(_ sender: Any) {
  1272. if (self.canResponseDocumentAction() == false) {
  1273. return
  1274. }
  1275. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1276. document.mainViewController?.menuItemAction_note(sender)
  1277. }
  1278. }
  1279. @IBAction func menuItemAction_squre(_ sender: Any) {
  1280. if (self.canResponseDocumentAction() == false) {
  1281. return
  1282. }
  1283. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1284. document.mainViewController?.menuItemAction_squre(sender)
  1285. }
  1286. }
  1287. @IBAction func menuItemAction_circle(_ sender: Any) {
  1288. if (self.canResponseDocumentAction() == false) {
  1289. return
  1290. }
  1291. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1292. document.mainViewController?.menuItemAction_circle(sender)
  1293. }
  1294. }
  1295. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1296. if (self.canResponseDocumentAction() == false) {
  1297. return
  1298. }
  1299. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1300. document.mainViewController?.menuItemAction_arrow(sender)
  1301. }
  1302. }
  1303. @IBAction func menuItemAction_line(_ sender: Any) {
  1304. if (self.canResponseDocumentAction() == false) {
  1305. return
  1306. }
  1307. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1308. document.mainViewController?.menuItemAction_line(sender)
  1309. }
  1310. }
  1311. // link
  1312. @IBAction func menuItemAction_link(_ sender: Any) {
  1313. if (self.canResponseDocumentAction() == false) {
  1314. return
  1315. }
  1316. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1317. document.mainViewController?.menuItemAction_link(sender)
  1318. }
  1319. }
  1320. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1321. if (self.canResponseDocumentAction() == false) {
  1322. return
  1323. }
  1324. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1325. document.mainViewController?.menuItemAction_linkPage(sender)
  1326. }
  1327. }
  1328. // stamp
  1329. @IBAction func menuItemAction_stamp(_ 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?.menuItemAction_stamp(sender)
  1335. }
  1336. }
  1337. @IBAction func menuItemAction_signure(_ 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?.menuItemAction_signure(sender)
  1343. }
  1344. }
  1345. @IBAction func menuItemAction_hiddenAllAnnotation(_ 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?.menuItemAction_hiddenAllAnnotation(sender)
  1351. }
  1352. }
  1353. @IBAction func menuItemAction_clearAllAnnotation(_ 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?.menuItemAction_clearAllAnnotation(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. }
  1421. // MARK: - KMSystemToolMenuProtocol
  1422. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1423. func menuItemAction_scrolTool(_ sender: Any) {
  1424. if (self.canResponseDocumentAction() == false) {
  1425. return
  1426. }
  1427. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1428. document.mainViewController?.menuItemAction_scrolTool(sender)
  1429. }
  1430. }
  1431. func menuItemAction_zoomOutTool(_ sender: Any) {
  1432. if (self.canResponseDocumentAction() == false) {
  1433. return
  1434. }
  1435. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1436. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1437. }
  1438. }
  1439. func menuItemAction_selectTool(_ sender: Any) {
  1440. if (self.canResponseDocumentAction() == false) {
  1441. return
  1442. }
  1443. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1444. document.mainViewController?.menuItemAction_selectTool(sender)
  1445. }
  1446. }
  1447. @IBAction func compression(_ sender: Any?) {
  1448. if (self.canResponseDocumentAction() == false) {
  1449. return
  1450. }
  1451. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1452. if (document.isHome) {
  1453. } else {
  1454. document.mainViewController?.compression(sender)
  1455. }
  1456. }
  1457. }
  1458. @IBAction func merge(_ sender: Any?) {
  1459. if (self.canResponseDocumentAction() == false) {
  1460. return
  1461. }
  1462. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1463. if (document.isHome) {
  1464. } else {
  1465. document.mainViewController?.merge(sender)
  1466. }
  1467. }
  1468. }
  1469. @IBAction func convert(_ sender: Any?) {
  1470. if (self.canResponseDocumentAction() == false) {
  1471. return
  1472. }
  1473. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1474. if (document.isHome) {
  1475. } else {
  1476. document.mainViewController?.convert(sender)
  1477. }
  1478. }
  1479. }
  1480. @IBAction func imageToPDF(_ sender: Any?) {
  1481. if (self.canResponseDocumentAction() == false) {
  1482. return
  1483. }
  1484. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1485. if (document.isHome) {
  1486. } else {
  1487. document.mainViewController?.imageToPDF(sender)
  1488. }
  1489. }
  1490. }
  1491. @IBAction func extractImage(_ sender: Any?) {
  1492. if (self.canResponseDocumentAction() == false) {
  1493. return
  1494. }
  1495. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1496. if (document.isHome) {
  1497. } else {
  1498. document.mainViewController?.extractImage(sender)
  1499. }
  1500. }
  1501. }
  1502. @IBAction func security(_ sender: Any?) {
  1503. if (self.canResponseDocumentAction() == false) {
  1504. return
  1505. }
  1506. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1507. if (document.isHome) {
  1508. } else {
  1509. document.mainViewController?.security(sender)
  1510. }
  1511. }
  1512. }
  1513. @IBAction func decryption(_ sender: Any?) {
  1514. if (self.canResponseDocumentAction() == false) {
  1515. return
  1516. }
  1517. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1518. if (document.isHome) {
  1519. } else {
  1520. document.mainViewController?.decryption(sender)
  1521. }
  1522. }
  1523. }
  1524. @IBAction func cropAll(_ sender: Any?) {
  1525. if (self.canResponseDocumentAction() == false) {
  1526. return
  1527. }
  1528. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1529. if (document.isHome) {
  1530. } else {
  1531. document.mainViewController?.cropAll(sender)
  1532. }
  1533. }
  1534. }
  1535. @IBAction func crop(_ sender: Any?) {
  1536. if (self.canResponseDocumentAction() == false) {
  1537. return
  1538. }
  1539. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1540. if (document.isHome) {
  1541. } else {
  1542. document.mainViewController?.crop(sender)
  1543. }
  1544. }
  1545. }
  1546. @IBAction func autoCropAll(_ sender: Any?) {
  1547. if (self.canResponseDocumentAction() == false) {
  1548. return
  1549. }
  1550. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1551. if (document.isHome) {
  1552. } else {
  1553. document.mainViewController?.autoCropAll(sender)
  1554. }
  1555. }
  1556. }
  1557. @IBAction func smartAutoCropAll(_ sender: Any?) {
  1558. if (self.canResponseDocumentAction() == false) {
  1559. return
  1560. }
  1561. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1562. if (document.isHome) {
  1563. } else {
  1564. document.mainViewController?.smartAutoCropAll(sender)
  1565. }
  1566. }
  1567. }
  1568. @IBAction func cropOptionsModel(_ sender: Any?) {
  1569. if (self.canResponseDocumentAction() == false) {
  1570. return
  1571. }
  1572. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1573. if (document.isHome) {
  1574. } else {
  1575. // document.mainViewController?.cropOptionsModel(sender)
  1576. }
  1577. }
  1578. }
  1579. @IBAction func selectToolModel(_ sender: Any?) {
  1580. if (self.canResponseDocumentAction() == false) {
  1581. return
  1582. }
  1583. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1584. if (document.isHome) {
  1585. } else {
  1586. document.mainViewController?.selectToolModel(sender)
  1587. }
  1588. }
  1589. }
  1590. @IBAction func takeSnapshot(_ sender: Any?) {
  1591. if (self.canResponseDocumentAction() == false) {
  1592. return
  1593. }
  1594. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1595. if (document.isHome) {
  1596. } else {
  1597. document.mainViewController?.takeSnapshot(sender)
  1598. }
  1599. }
  1600. }
  1601. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  1602. if (self.canResponseDocumentAction() == false) {
  1603. return
  1604. }
  1605. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1606. if (document.isHome) {
  1607. } else {
  1608. document.mainViewController?.takeSnapshotSelectContent(sender)
  1609. }
  1610. }
  1611. }
  1612. @IBAction func changeAnnotationMode(_ sender: Any?) {
  1613. if (self.canResponseDocumentAction() == false) {
  1614. return
  1615. }
  1616. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1617. if (document.isHome) {
  1618. } else {
  1619. document.mainViewController?.changeAnnotationMode(sender)
  1620. }
  1621. }
  1622. }
  1623. @IBAction func addBackground(_ sender: Any?) {
  1624. if (self.canResponseDocumentAction() == false) {
  1625. return
  1626. }
  1627. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1628. if (document.isHome) {
  1629. } else {
  1630. document.mainViewController?.addBackground(sender)
  1631. }
  1632. }
  1633. }
  1634. @IBAction func removeBackground(_ sender: Any?) {
  1635. if (self.canResponseDocumentAction() == false) {
  1636. return
  1637. }
  1638. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1639. if (document.isHome) {
  1640. } else {
  1641. document.mainViewController?.removeBackground(sender)
  1642. }
  1643. }
  1644. }
  1645. @IBAction func addHeaderFooter(_ sender: Any?) {
  1646. KMPrint("addHeaderFooter ...")
  1647. }
  1648. @IBAction func removeHeaderFooter(_ sender: Any?) {
  1649. KMPrint("removeHeaderFooter ...")
  1650. }
  1651. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  1652. KMPrint("addHeaderFooterBates ...")
  1653. }
  1654. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  1655. KMPrint("removeHeaderFooterBates ...")
  1656. }
  1657. @IBAction func addWatermark(_ 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?.addWatermark(sender)
  1665. }
  1666. }
  1667. }
  1668. @IBAction func editWatermark(_ sender: Any?) {
  1669. KMPrint("editWatermark ...")
  1670. }
  1671. @IBAction func batchAddWatermark(_ sender: Any?) {
  1672. if (self.canResponseDocumentAction() == false) {
  1673. return
  1674. }
  1675. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1676. if (document.isHome) {
  1677. } else {
  1678. document.mainViewController?.batchAddWatermark(sender)
  1679. }
  1680. }
  1681. }
  1682. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  1683. if (self.canResponseDocumentAction() == false) {
  1684. return
  1685. }
  1686. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1687. if (document.isHome) {
  1688. } else {
  1689. document.mainViewController?.batchRemoveWatermark(sender)
  1690. }
  1691. }
  1692. }
  1693. @IBAction func removeWatermark(_ sender: Any?) {
  1694. if (self.canResponseDocumentAction() == false) {
  1695. return
  1696. }
  1697. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1698. if (document.isHome) {
  1699. } else {
  1700. document.mainViewController?.removeWatermark(sender)
  1701. }
  1702. }
  1703. }
  1704. @IBAction func templateWatermark(_ sender: Any?) {
  1705. if (self.canResponseDocumentAction() == false) {
  1706. return
  1707. }
  1708. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1709. if (document.isHome) {
  1710. } else {
  1711. document.mainViewController?.templateWatermark(sender)
  1712. }
  1713. }
  1714. }
  1715. @IBAction func batchAddBackground(_ sender: Any?) {
  1716. if (self.canResponseDocumentAction() == false) {
  1717. return
  1718. }
  1719. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1720. if (document.isHome) {
  1721. } else {
  1722. document.mainViewController?.batchAddBackground(sender)
  1723. }
  1724. }
  1725. }
  1726. @IBAction func batchRemoveBackground(_ sender: Any?) {
  1727. if (self.canResponseDocumentAction() == false) {
  1728. return
  1729. }
  1730. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1731. if (document.isHome) {
  1732. } else {
  1733. document.mainViewController?.batchRemoveBackground(sender)
  1734. }
  1735. }
  1736. }
  1737. @IBAction func templateBackground(_ 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?.templateBackground(sender)
  1745. }
  1746. }
  1747. }
  1748. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  1749. KMPrint("batchAddHeaderFooter ...")
  1750. }
  1751. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  1752. KMPrint("batchRemoveHeaderFooter ...")
  1753. }
  1754. @IBAction func templateHeaderFooter(_ sender: Any?) {
  1755. KMPrint("templateHeaderFooter ...")
  1756. }
  1757. @IBAction func batchAddBates(_ sender: Any?) {
  1758. KMPrint("batchAddBates ...")
  1759. }
  1760. @IBAction func batchRemoveBates(_ sender: Any?) {
  1761. KMPrint("batchRemoveBates ...")
  1762. }
  1763. @IBAction func templateBates(_ sender: Any?) {
  1764. KMPrint("templateBates ...")
  1765. }
  1766. @IBAction func togglePoster(_ sender: Any?) {
  1767. if (self.canResponseDocumentAction() == false) {
  1768. return
  1769. }
  1770. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1771. if (document.isHome) {
  1772. } else {
  1773. document.mainViewController?.togglePoster(sender)
  1774. }
  1775. }
  1776. }
  1777. @IBAction func toggleMultiple(_ sender: Any?) {
  1778. if (self.canResponseDocumentAction() == false) {
  1779. return
  1780. }
  1781. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1782. if (document.isHome) {
  1783. } else {
  1784. document.mainViewController?.toggleMultiple(sender)
  1785. }
  1786. }
  1787. }
  1788. @IBAction func toggleBooklet(_ sender: Any?) {
  1789. if (self.canResponseDocumentAction() == false) {
  1790. return
  1791. }
  1792. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1793. if (document.isHome) {
  1794. } else {
  1795. document.mainViewController?.toggleBooklet(sender)
  1796. }
  1797. }
  1798. }
  1799. @IBAction func rotateRight(_ sender: Any?) {
  1800. if (self.canResponseDocumentAction() == false) {
  1801. return
  1802. }
  1803. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1804. if (document.isHome) {
  1805. } else {
  1806. document.mainViewController?.rotateRight(sender)
  1807. }
  1808. }
  1809. }
  1810. @IBAction func rotateLeft(_ sender: Any?) {
  1811. if (self.canResponseDocumentAction() == false) {
  1812. return
  1813. }
  1814. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1815. if (document.isHome) {
  1816. } else {
  1817. document.mainViewController?.rotateLeft(sender)
  1818. }
  1819. }
  1820. }
  1821. @IBAction func rotateAllRight(_ sender: Any?) {
  1822. if (self.canResponseDocumentAction() == false) {
  1823. return
  1824. }
  1825. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1826. if (document.isHome) {
  1827. } else {
  1828. document.mainViewController?.rotateAllRight(sender)
  1829. }
  1830. }
  1831. }
  1832. @IBAction func rotateAllLeft(_ sender: Any?) {
  1833. if (self.canResponseDocumentAction() == false) {
  1834. return
  1835. }
  1836. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1837. if (document.isHome) {
  1838. } else {
  1839. document.mainViewController?.rotateAllLeft(sender)
  1840. }
  1841. }
  1842. }
  1843. @IBAction func autoSelectContent(_ sender: Any?) {
  1844. if (self.canResponseDocumentAction() == false) {
  1845. return
  1846. }
  1847. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1848. if (document.isHome) {
  1849. } else {
  1850. document.mainViewController?.autoSelectContent(sender)
  1851. }
  1852. }
  1853. }
  1854. }
  1855. // MARK: - KMSystemWindowMenuRrotocol
  1856. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  1857. func menuItemAction_showForwardTagPage(_ sender: Any) {
  1858. if (self.canResponseDocumentAction() == false) {
  1859. return
  1860. }
  1861. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1862. if (document.isHome) {
  1863. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  1864. } else {
  1865. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  1866. }
  1867. }
  1868. }
  1869. func menuItemAction_showNextTagPage(_ sender: Any) {
  1870. if (self.canResponseDocumentAction() == false) {
  1871. return
  1872. }
  1873. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1874. if (document.isHome) {
  1875. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  1876. } else {
  1877. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  1878. }
  1879. }
  1880. }
  1881. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1882. if (self.canResponseDocumentAction() == false) {
  1883. return
  1884. }
  1885. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1886. if (document.isHome) {
  1887. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1888. } else {
  1889. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1890. }
  1891. }
  1892. }
  1893. func menuItemAction_mergeAllWindow(_ sender: Any) {
  1894. if (self.canResponseDocumentAction() == false) {
  1895. return
  1896. }
  1897. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1898. if (document.isHome) {
  1899. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  1900. } else {
  1901. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  1902. }
  1903. }
  1904. }
  1905. }
  1906. // MARK: - Analytics (埋点)
  1907. extension KMBrowserWindowController {
  1908. func trackEvent_upgrade() -> Void {
  1909. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  1910. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  1911. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  1912. }
  1913. }