KMBrowserWindowController.swift 82 KB

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