KMBrowserWindowController.swift 80 KB

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