KMBrowserWindowController.swift 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. override func windowDidLoad() {
  17. super.windowDidLoad()
  18. window?.backgroundColor = NSColor(hex: "#DFE1E5")
  19. // window?.setFrameAutosaveName("")
  20. rightTabStripView_.delete = self
  21. homeRightTabStripView_.delete = self
  22. rightTabStripView_.updateView()
  23. fileUploadPanel.delete = self
  24. homeRightTabStripView_.homeRightSearchField.delegate = self
  25. isMultiTabMode = true
  26. addObserverForAppearanceChange()
  27. refreshToolBar(homeToolState: .Home)
  28. NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
  29. NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
  30. if (WelcomeWindowController.welcomeHasShow() == false) {
  31. KMTools.openQuickStartStudy()
  32. DispatchQueue.main.async {
  33. let welcome = WelcomeWindowController()
  34. self.window?.beginSheet(welcome.window!)
  35. welcome.itemClick = { [weak self] idx, param in
  36. if (idx == 1) { // 关闭
  37. self?.window?.endSheet((param as! NSWindowController).window!)
  38. } else if (idx == 2) { // 以后提醒
  39. self?.window?.endSheet((param as! NSWindowController).window!)
  40. } else if (idx == 3) { // 注册
  41. self?.window?.endSheet((param as! NSWindowController).window!)
  42. guard let window_ = self?.window else {
  43. return
  44. }
  45. let _ = KMLoginWindowController.show(window: window_, .Batch, .register)
  46. }
  47. }
  48. }
  49. }
  50. }
  51. override func windowShouldClose(_ sender: NSWindow) -> Bool {
  52. if self.browser.tabStripModel.count() > 1 {
  53. self.browser.windowDidBeginToClose()
  54. return false
  55. }
  56. return true
  57. }
  58. // MARK: Dark&Light
  59. func addObserverForAppearanceChange() -> Void {
  60. window?.contentView!.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
  61. }
  62. func removeObserverForAppearanceChange() -> Void {
  63. window?.contentView!.removeObserver(self, forKeyPath: "effectiveAppearance")
  64. }
  65. override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  66. if keyPath == "effectiveAppearance" {
  67. updateViewColor()
  68. }
  69. }
  70. override func updateViewColor() {
  71. super.updateViewColor()
  72. window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
  73. }
  74. // MARK: Public Methods
  75. func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
  76. modeType = toolState
  77. let document = browser.activeTabContents()
  78. if document != nil {
  79. if document!.isHome {
  80. homeRightTabStripView_.isHidden = modeType == .Home
  81. } else {
  82. self.homeRightStripView.isHidden = true
  83. }
  84. } else {
  85. self.homeRightStripView.isHidden = true
  86. }
  87. homeRightTabStripView_.homeRefreshButton.isEnabled = true
  88. homeRightTabStripView_.homeUploadButton.isEnabled = true
  89. filterType = 0
  90. rightTabStripView_.sortPopUpButton.removeAllItems()
  91. rightTabStripView_.filterPopUpButton.removeAllItems()
  92. rightTabStripView_.updateView()
  93. }
  94. override var hasToolbar: Bool {
  95. get {
  96. return false
  97. }
  98. }
  99. // MARK: Private Methods
  100. func openDocumentWindow() -> Void {
  101. // let panel = NSOpenPanel()
  102. // panel.allowsMultipleSelection = false
  103. // panel.allowedFileTypes = ["pdf"]
  104. // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  105. // if response == .OK {
  106. // let openPath = panel.url?.path
  107. // let selectDocument = self.selectTabContents(path: openPath!)
  108. // if selectDocument != nil {
  109. // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
  110. // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
  111. // return
  112. // }
  113. // if !panel.url!.path.isPDFValid() {
  114. // let alert = NSAlert()
  115. // alert.alertStyle = .critical
  116. // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  117. // alert.runModal()
  118. // return
  119. // }
  120. // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
  121. // print("openDocumentWindow")
  122. // }
  123. // }
  124. // }
  125. // MARK TODO: + 号开启
  126. self.browser.addHomeTabContents()
  127. }
  128. // override func openDocument(_ sender: Any!) {
  129. // self.openDocumentWindow()
  130. // }
  131. func selectTabContents(path filePath: String) -> KMMainDocument? {
  132. let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
  133. var selectDocument: KMMainDocument?
  134. if document != nil {
  135. if document!.isKind(of: KMMainDocument.self) {
  136. selectDocument = document as! KMMainDocument
  137. }
  138. }
  139. return selectDocument
  140. }
  141. // MARK: Getter
  142. override var rightStripView: NSView! {
  143. get {
  144. return rightTabStripView_
  145. }
  146. }
  147. override var homeRightStripView: NSView! {
  148. get {
  149. return homeRightTabStripView_
  150. }
  151. }
  152. // MARK: Button Action
  153. func commandDispatch(_ sender: Any) -> Void {
  154. openDocumentWindow()
  155. }
  156. func closeAllTabs(_ sender: Any) -> Void {
  157. if self.browser != nil {
  158. self.browser.closeAllTabs()
  159. }
  160. }
  161. func openNewWindow(_ sender: Any) -> Void {
  162. if let noti = sender as? NSNotification, noti.object is CTTabController {
  163. if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
  164. return
  165. }
  166. }
  167. if self.browser != nil {
  168. let activeInt = self.browser.activeTabIndex()
  169. let activeTab = self.browser.activeTabContents()
  170. self.browser.closeTab(at: activeInt, makeHistory: false)
  171. let browser: KMBrowser = KMBrowser.init()
  172. browser.windowController = KMBrowserWindowController.init(browser: browser)
  173. browser.addHomeTabContents()
  174. browser.windowController.showWindow(self)
  175. // browser.add(activeTab, inForeground: false)
  176. // browser.selectTab(at: 1)
  177. if activeTab?.fileURL == nil {
  178. return
  179. }
  180. let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
  181. let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
  182. KMMainDocument().tryToUnlockDocument(pdfDoc!)
  183. if ((pdfDoc?.isLocked)! == true) {
  184. KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
  185. if result == .cancel { /// 关闭
  186. return
  187. }
  188. /// 解密成功
  189. var selectDocument: KMMainDocument? = nil
  190. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  191. selectDocument = (document as! KMMainDocument)
  192. }
  193. if selectDocument != nil {
  194. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  195. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  196. if (selectDocument?.browser.window.isVisible)! as Bool {
  197. selectDocument?.browser.window.orderFront(nil)
  198. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  199. selectDocument?.browser.window.orderFront(nil)
  200. }
  201. } else {
  202. if !(activeTab?.fileURL)!.path.isPDFValid() {
  203. let alert = NSAlert()
  204. alert.alertStyle = .critical
  205. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  206. alert.runModal()
  207. return
  208. }
  209. NSDocumentController.shared.openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, documentWasAlreadyOpen, error in
  210. if error != nil {
  211. NSApp.presentError(error!)
  212. return
  213. }
  214. (document as! KMMainDocument).mainViewController?.password = password
  215. }
  216. }
  217. }
  218. } else {
  219. var selectDocument: KMMainDocument? = nil
  220. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  221. selectDocument = (document as! KMMainDocument)
  222. }
  223. if selectDocument != nil {
  224. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  225. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  226. if (selectDocument?.browser.window.isVisible)! as Bool {
  227. selectDocument?.browser.window.orderFront(nil)
  228. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  229. selectDocument?.browser.window.orderFront(nil)
  230. }
  231. } else {
  232. if !(activeTab?.fileURL)!.path.isPDFValid() {
  233. let alert = NSAlert()
  234. alert.alertStyle = .critical
  235. alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  236. alert.runModal()
  237. return
  238. }
  239. NSDocumentController.shared.openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, documentWasAlreadyOpen, error in
  240. if error != nil {
  241. NSApp.presentError(error!)
  242. return
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }
  249. // MARK: 待补充[万军]
  250. func mergeAllWindow(_ sender: Any) {
  251. }
  252. override func layoutTabContentArea(_ frame: NSRect) {
  253. super.layoutTabContentArea(frame)
  254. self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
  255. }
  256. }
  257. // MARK: - KMToolbarRightViewDelegate
  258. extension KMBrowserWindowController: KMToolbarRightViewDelegate {
  259. func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
  260. KMComparativeTableViewController.show(window: self.window!)
  261. }
  262. func userInfoButtonAction(_ sender: NSButton) {
  263. if KMLightMemberManager.manager.isLogin() {
  264. Task { @MainActor in
  265. if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
  266. KMAccountInfoWindowController.show(window: self.window!)
  267. } else {
  268. KMLoginWindowController.show(window: self.window!)
  269. }
  270. }
  271. } else {
  272. KMLoginWindowController.show(window: self.window!)
  273. }
  274. }
  275. func homeRefreshButtonAction(_ sender: NSButton?) {
  276. self.layoutSubviews()
  277. }
  278. func homeUploadButtonAction(_ sender: NSButton) {
  279. }
  280. func homeMenuSortAction(_ sender: NSPopUpButton) {
  281. }
  282. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  283. }
  284. }
  285. // MARK: - KMUploadFileDelegate
  286. extension KMBrowserWindowController: KMUploadFileDelegate {
  287. // override func cancelOperation(_ sender: Any?) {
  288. //
  289. // }
  290. }
  291. // MARK: - NSSearchFieldDelegate
  292. extension KMBrowserWindowController: NSSearchFieldDelegate {
  293. func controlTextDidChange(_ obj: Notification) {
  294. }
  295. func controlTextDidEndEditing(_ obj: Notification) {
  296. }
  297. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  298. var result = false
  299. return result
  300. }
  301. }
  302. // MARK: -
  303. // MARK: Menu Actions
  304. extension KMBrowserWindowController {
  305. func canResponseDocumentAction() -> Bool {
  306. if (self.browser == nil) {
  307. return false
  308. }
  309. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  310. return false
  311. }
  312. return true
  313. }
  314. }
  315. // MARK: -
  316. // MARK: File Menu
  317. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  318. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  319. if (self.browser == nil) {
  320. return false
  321. }
  322. guard let action = menuItem.action else {
  323. return false
  324. }
  325. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  326. return false
  327. }
  328. if (KMSystemMenu.isFileSelector(sel: action)) {
  329. if (document.isHome) {
  330. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  331. menuItem.action == KMSystemMenu.File.propertySelector ||
  332. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  333. menuItem.action == KMSystemMenu.File.printSelector) {
  334. return false
  335. }
  336. return document.homeViewController!.validateMenuItem(menuItem)
  337. } else {
  338. return document.mainViewController!.validateMenuItem(menuItem)
  339. }
  340. }
  341. if (KMSystemMenu.isEditSelector(sel: action)) {
  342. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  343. }
  344. if (KMSystemMenu.isViewSelector(sel: action)) {
  345. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  346. }
  347. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  348. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  349. }
  350. if (KMSystemMenu.isGotoSelector(sel: action)) {
  351. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  352. }
  353. if (KMSystemMenu.isToolSelector(sel: action)) {
  354. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  355. }
  356. if (KMSystemMenu.isWindowSelector(sel: action)) {
  357. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  358. }
  359. return true
  360. }
  361. }
  362. extension KMBrowserWindowController {
  363. @IBAction func menuItemAction_openFile(_ sender: Any) {
  364. super.openDocument(sender)
  365. }
  366. @IBAction func importFromFile(_ sender: Any) {
  367. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  368. document.homeViewController?.importFromFile(sender)
  369. }
  370. @IBAction func openBlankPage(_ sender: Any) {
  371. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  372. document.homeViewController?.openBlankPage(sender)
  373. }
  374. @IBAction func importFromScanner(_ sender: Any) {
  375. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  376. document.homeViewController?.importFromScanner(sender)
  377. }
  378. @IBAction func menuItemAction_newTab(_ sender: Any) {
  379. self.openDocumentWindow()
  380. }
  381. }
  382. // MARK: - KMSystemFileMenuProtocol
  383. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  384. func menuItemClick_mergePDF(_ sender: Any) {
  385. if (self.canResponseDocumentAction() == false) {
  386. return
  387. }
  388. if let document = self.browser.activeTabContents() as? KMMainDocument {
  389. if (document.isHome) {
  390. document.homeViewController?.menuItemClick_mergePDF(sender)
  391. } else {
  392. document.mainViewController?.menuItemClick_mergePDF(sender)
  393. }
  394. }
  395. }
  396. func menuItemClick_Compress(_ sender: Any) {
  397. if (self.canResponseDocumentAction() == false) {
  398. return
  399. }
  400. if let document = self.browser.activeTabContents() as? KMMainDocument {
  401. if (document.isHome) {
  402. document.homeViewController?.menuItemClick_Compress(sender)
  403. } else {
  404. document.mainViewController?.menuItemClick_Compress(sender)
  405. }
  406. }
  407. }
  408. func menuItemAction_ConvertToWord(_ sender: Any) {
  409. if (self.canResponseDocumentAction() == false) {
  410. return
  411. }
  412. if let document = self.browser.activeTabContents() as? KMMainDocument {
  413. if (document.isHome) {
  414. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  415. } else {
  416. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  417. }
  418. }
  419. }
  420. func menuItemAction_ConvertToExcel(_ sender: Any) {
  421. if (self.canResponseDocumentAction() == false) {
  422. return
  423. }
  424. if let document = self.browser.activeTabContents() as? KMMainDocument {
  425. if (document.isHome) {
  426. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  427. } else {
  428. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  429. }
  430. }
  431. }
  432. func menuItemAction_ConvertToPPT(_ sender: Any) {
  433. if (self.canResponseDocumentAction() == false) {
  434. return
  435. }
  436. if let document = self.browser.activeTabContents() as? KMMainDocument {
  437. if (document.isHome) {
  438. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  439. } else {
  440. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  441. }
  442. }
  443. }
  444. func menuItemAction_ConvertToRTF(_ sender: Any) {
  445. if (self.canResponseDocumentAction() == false) {
  446. return
  447. }
  448. if let document = self.browser.activeTabContents() as? KMMainDocument {
  449. if (document.isHome) {
  450. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  451. } else {
  452. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  453. }
  454. }
  455. }
  456. func menuItemAction_ConvertToHTML(_ sender: Any) {
  457. if (self.canResponseDocumentAction() == false) {
  458. return
  459. }
  460. if let document = self.browser.activeTabContents() as? KMMainDocument {
  461. if (document.isHome) {
  462. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  463. } else {
  464. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  465. }
  466. }
  467. }
  468. func menuItemAction_ConvertToText(_ sender: Any) {
  469. if (self.canResponseDocumentAction() == false) {
  470. return
  471. }
  472. if let document = self.browser.activeTabContents() as? KMMainDocument {
  473. if (document.isHome) {
  474. document.homeViewController?.menuItemAction_ConvertToText(sender)
  475. } else {
  476. document.mainViewController?.menuItemAction_ConvertToText(sender)
  477. }
  478. }
  479. }
  480. func menuItemAction_ConvertToCSV(_ sender: Any) {
  481. if (self.canResponseDocumentAction() == false) {
  482. return
  483. }
  484. if let document = self.browser.activeTabContents() as? KMMainDocument {
  485. if (document.isHome) {
  486. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  487. } else {
  488. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  489. }
  490. }
  491. }
  492. func menuItemAction_ConvertToImage(_ sender: Any) {
  493. if (self.canResponseDocumentAction() == false) {
  494. return
  495. }
  496. if let document = self.browser.activeTabContents() as? KMMainDocument {
  497. if (document.isHome) {
  498. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  499. } else {
  500. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  501. }
  502. }
  503. }
  504. func menuItemClick_SettingPassword(_ sender: Any) {
  505. if (self.canResponseDocumentAction() == false) {
  506. return
  507. }
  508. if let document = self.browser.activeTabContents() as? KMMainDocument {
  509. if (document.isHome) {
  510. document.homeViewController?.menuItemClick_SettingPassword(sender)
  511. } else {
  512. document.mainViewController?.menuItemClick_SettingPassword(sender)
  513. }
  514. }
  515. }
  516. func menuItemClick_RemovePassword(_ sender: Any) {
  517. if (self.canResponseDocumentAction() == false) {
  518. return
  519. }
  520. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  521. document.mainViewController?.menuItemClick_RemovePassword(sender)
  522. }
  523. }
  524. func menuItemAction_closeWindow(_ sender: Any) {
  525. if (self.canResponseDocumentAction() == false) {
  526. return
  527. }
  528. if let document = self.browser.activeTabContents() as? KMMainDocument {
  529. if (document.isHome) {
  530. document.homeViewController?.menuItemAction_closeWindow(sender)
  531. } else {
  532. document.mainViewController?.menuItemAction_closeWindow(sender)
  533. }
  534. }
  535. }
  536. func menuItemAction_closeAllWindows(_ sender: Any) {
  537. if (self.canResponseDocumentAction() == false) {
  538. return
  539. }
  540. if let document = self.browser.activeTabContents() as? KMMainDocument {
  541. if (document.isHome) {
  542. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  543. } else {
  544. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  545. }
  546. }
  547. }
  548. func menuItemAction_closeTagPage(_ sender: Any) {
  549. if (self.canResponseDocumentAction() == false) {
  550. return
  551. }
  552. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  553. document.mainViewController?.menuItemAction_closeTagPage(sender)
  554. }
  555. }
  556. func menuItemAction_showInFinder(_ sender: Any) {
  557. if (self.canResponseDocumentAction() == false) {
  558. return
  559. }
  560. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  561. document.mainViewController?.menuItemAction_showInFinder(sender)
  562. }
  563. }
  564. func menuItemAction_property(_ sender: Any) {
  565. if (self.canResponseDocumentAction() == false) {
  566. return
  567. }
  568. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  569. document.mainViewController?.menuItemAction_property(sender)
  570. }
  571. }
  572. func menuItemAction_print(_ sender: Any) {
  573. if (self.canResponseDocumentAction() == false) {
  574. return
  575. }
  576. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  577. document.mainViewController?.menuItemAction_print(sender)
  578. }
  579. }
  580. }
  581. // MARK: - KMSystemViewMenuProtocol
  582. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  583. func menuItemAction_adjustWidth(_ sender: Any) {
  584. if (self.canResponseDocumentAction() == false) {
  585. return
  586. }
  587. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  588. document.mainViewController?.menuItemAction_adjustWidth(sender)
  589. }
  590. }
  591. func menuItemAction_adjustPage(_ sender: Any) {
  592. if (self.canResponseDocumentAction() == false) {
  593. return
  594. }
  595. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  596. document.mainViewController?.menuItemAction_adjustPage(sender)
  597. }
  598. }
  599. func menuItemAction_size(_ sender: Any) {
  600. if (self.canResponseDocumentAction() == false) {
  601. return
  602. }
  603. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  604. document.mainViewController?.menuItemAction_size(sender)
  605. }
  606. }
  607. func menuItemAction_zoomOut(_ sender: Any) {
  608. if (self.canResponseDocumentAction() == false) {
  609. return
  610. }
  611. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  612. document.mainViewController?.menuItemAction_zoomOut(sender)
  613. }
  614. }
  615. func menuItemAction_zoomIn(_ sender: Any) {
  616. if (self.canResponseDocumentAction() == false) {
  617. return
  618. }
  619. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  620. document.mainViewController?.menuItemAction_zoomIn(sender)
  621. }
  622. }
  623. func menuItemAction_singlePage(_ sender: Any) {
  624. if (self.canResponseDocumentAction() == false) {
  625. return
  626. }
  627. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  628. document.mainViewController?.menuItemAction_singlePage(sender)
  629. }
  630. }
  631. func menuItemAction_singlePageContinue(_ sender: Any) {
  632. if (self.canResponseDocumentAction() == false) {
  633. return
  634. }
  635. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  636. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  637. }
  638. }
  639. func menuItemAction_doublePage(_ sender: Any) {
  640. if (self.canResponseDocumentAction() == false) {
  641. return
  642. }
  643. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  644. document.mainViewController?.menuItemAction_doublePage(sender)
  645. }
  646. }
  647. func menuItemAction_doublePageContinue(_ sender: Any) {
  648. if (self.canResponseDocumentAction() == false) {
  649. return
  650. }
  651. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  652. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  653. }
  654. }
  655. func menuItemAction_bookMode(_ sender: Any) {
  656. if (self.canResponseDocumentAction() == false) {
  657. return
  658. }
  659. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  660. document.mainViewController?.menuItemAction_bookMode(sender)
  661. }
  662. }
  663. func menuItemAction_readMode(_ sender: Any) {
  664. if (self.canResponseDocumentAction() == false) {
  665. return
  666. }
  667. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  668. document.mainViewController?.menuItemAction_readMode(sender)
  669. }
  670. }
  671. func menuItemAction_showSplitPage(_ sender: Any) {
  672. if (self.canResponseDocumentAction() == false) {
  673. return
  674. }
  675. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  676. document.mainViewController?.menuItemAction_showSplitPage(sender)
  677. }
  678. }
  679. func menuItemAction_rotateLeft(_ sender: Any) {
  680. if (self.canResponseDocumentAction() == false) {
  681. return
  682. }
  683. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  684. document.mainViewController?.menuItemAction_rotateLeft(sender)
  685. }
  686. }
  687. func menuItemAction_rotateRight(_ sender: Any) {
  688. if (self.canResponseDocumentAction() == false) {
  689. return
  690. }
  691. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  692. document.mainViewController?.menuItemAction_rotateRight(sender)
  693. }
  694. }
  695. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  696. if (self.canResponseDocumentAction() == false) {
  697. return
  698. }
  699. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  700. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  701. }
  702. }
  703. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  704. if (self.canResponseDocumentAction() == false) {
  705. return
  706. }
  707. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  708. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  709. }
  710. }
  711. func menuItemAction_view_readMode(_ sender: Any) {
  712. if (self.canResponseDocumentAction() == false) {
  713. return
  714. }
  715. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  716. document.mainViewController?.menuItemAction_view_readMode(sender)
  717. }
  718. }
  719. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  720. if (self.canResponseDocumentAction() == false) {
  721. return
  722. }
  723. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  724. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  725. }
  726. }
  727. func menuItemAction_hiddenRightSide(_ sender: Any) {
  728. if (self.canResponseDocumentAction() == false) {
  729. return
  730. }
  731. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  732. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  733. }
  734. }
  735. func menuItemAction_thumai(_ sender: Any) {
  736. if (self.canResponseDocumentAction() == false) {
  737. return
  738. }
  739. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  740. document.mainViewController?.menuItemAction_thumai(sender)
  741. }
  742. }
  743. func menuItemAction_outline(_ sender: Any) {
  744. if (self.canResponseDocumentAction() == false) {
  745. return
  746. }
  747. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  748. document.mainViewController?.menuItemAction_outline(sender)
  749. }
  750. }
  751. func menuItemAction_bookmark(_ sender: Any) {
  752. if (self.canResponseDocumentAction() == false) {
  753. return
  754. }
  755. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  756. document.mainViewController?.menuItemAction_bookmark(sender)
  757. }
  758. }
  759. func menuItemAction_annotation(_ sender: Any) {
  760. if (self.canResponseDocumentAction() == false) {
  761. return
  762. }
  763. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  764. document.mainViewController?.menuItemAction_annotation(sender)
  765. }
  766. }
  767. func menuItemAction_search(_ sender: Any) {
  768. if (self.canResponseDocumentAction() == false) {
  769. return
  770. }
  771. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  772. document.mainViewController?.menuItemAction_search(sender)
  773. }
  774. }
  775. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  776. if (self.canResponseDocumentAction() == false) {
  777. return
  778. }
  779. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  780. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  781. }
  782. }
  783. }
  784. // MARK: - KMSystemEditMenuProtocol
  785. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  786. func menuItemAction_find(_ sender: Any) {
  787. if (self.canResponseDocumentAction() == false) {
  788. return
  789. }
  790. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  791. document.mainViewController?.menuItemAction_find(sender)
  792. }
  793. }
  794. }
  795. // MARK: - Annotation Menu
  796. extension KMBrowserWindowController {
  797. @IBAction func menuItemAction_highlight(_ sender: Any) {
  798. if (self.canResponseDocumentAction() == false) {
  799. return
  800. }
  801. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  802. document.mainViewController?.menuItemAction_highlight(sender)
  803. }
  804. }
  805. @IBAction func menuItemAction_underline(_ sender: Any) {
  806. if (self.canResponseDocumentAction() == false) {
  807. return
  808. }
  809. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  810. document.mainViewController?.menuItemAction_underline(sender)
  811. }
  812. }
  813. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  814. if (self.canResponseDocumentAction() == false) {
  815. return
  816. }
  817. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  818. document.mainViewController?.menuItemAction_deleteLine(sender)
  819. }
  820. }
  821. @IBAction func menuItemAction_freehand(_ sender: Any) {
  822. if (self.canResponseDocumentAction() == false) {
  823. return
  824. }
  825. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  826. document.mainViewController?.menuItemAction_freehand(sender)
  827. }
  828. }
  829. @IBAction func menuItemAction_text(_ sender: Any) {
  830. if (self.canResponseDocumentAction() == false) {
  831. return
  832. }
  833. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  834. document.mainViewController?.menuItemAction_text(sender)
  835. }
  836. }
  837. @IBAction func menuItemAction_note(_ sender: Any) {
  838. if (self.canResponseDocumentAction() == false) {
  839. return
  840. }
  841. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  842. document.mainViewController?.menuItemAction_note(sender)
  843. }
  844. }
  845. @IBAction func menuItemAction_squre(_ sender: Any) {
  846. if (self.canResponseDocumentAction() == false) {
  847. return
  848. }
  849. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  850. document.mainViewController?.menuItemAction_squre(sender)
  851. }
  852. }
  853. @IBAction func menuItemAction_circle(_ sender: Any) {
  854. if (self.canResponseDocumentAction() == false) {
  855. return
  856. }
  857. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  858. document.mainViewController?.menuItemAction_circle(sender)
  859. }
  860. }
  861. @IBAction func menuItemAction_arrow(_ sender: Any) {
  862. if (self.canResponseDocumentAction() == false) {
  863. return
  864. }
  865. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  866. document.mainViewController?.menuItemAction_arrow(sender)
  867. }
  868. }
  869. @IBAction func menuItemAction_line(_ sender: Any) {
  870. if (self.canResponseDocumentAction() == false) {
  871. return
  872. }
  873. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  874. document.mainViewController?.menuItemAction_line(sender)
  875. }
  876. }
  877. // link
  878. @IBAction func menuItemAction_link(_ sender: Any) {
  879. if (self.canResponseDocumentAction() == false) {
  880. return
  881. }
  882. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  883. document.mainViewController?.menuItemAction_link(sender)
  884. }
  885. }
  886. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  887. if (self.canResponseDocumentAction() == false) {
  888. return
  889. }
  890. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  891. document.mainViewController?.menuItemAction_linkPage(sender)
  892. }
  893. }
  894. // stamp
  895. @IBAction func menuItemAction_stamp(_ sender: Any) {
  896. if (self.canResponseDocumentAction() == false) {
  897. return
  898. }
  899. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  900. document.mainViewController?.menuItemAction_stamp(sender)
  901. }
  902. }
  903. @IBAction func menuItemAction_signure(_ sender: Any) {
  904. if (self.canResponseDocumentAction() == false) {
  905. return
  906. }
  907. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  908. document.mainViewController?.menuItemAction_signure(sender)
  909. }
  910. }
  911. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  912. if (self.canResponseDocumentAction() == false) {
  913. return
  914. }
  915. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  916. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  917. }
  918. }
  919. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  920. if (self.canResponseDocumentAction() == false) {
  921. return
  922. }
  923. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  924. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  925. }
  926. }
  927. }
  928. // MARK: - KMSystemGotoMenuProtocol
  929. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  930. func menuItemAction_nextPage(_ sender: Any) {
  931. if (self.canResponseDocumentAction() == false) {
  932. return
  933. }
  934. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  935. document.mainViewController?.menuItemAction_nextPage(sender)
  936. }
  937. }
  938. func menuItemAction_forwardPage(_ sender: Any) {
  939. if (self.canResponseDocumentAction() == false) {
  940. return
  941. }
  942. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  943. document.mainViewController?.menuItemAction_forwardPage(sender)
  944. }
  945. }
  946. func menuItemAction_firstPage(_ sender: Any) {
  947. if (self.canResponseDocumentAction() == false) {
  948. return
  949. }
  950. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  951. document.mainViewController?.menuItemAction_firstPage(sender)
  952. }
  953. }
  954. func menuItemAction_lastPage(_ sender: Any) {
  955. if (self.canResponseDocumentAction() == false) {
  956. return
  957. }
  958. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  959. document.mainViewController?.menuItemAction_lastPage(sender)
  960. }
  961. }
  962. func menuItemAction_forward(_ sender: Any) {
  963. if (self.canResponseDocumentAction() == false) {
  964. return
  965. }
  966. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  967. document.mainViewController?.menuItemAction_forward(sender)
  968. }
  969. }
  970. func menuItemAction_goback(_ sender: Any) {
  971. if (self.canResponseDocumentAction() == false) {
  972. return
  973. }
  974. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  975. document.mainViewController?.menuItemAction_goback(sender)
  976. }
  977. }
  978. func menuItemAction_gotoPage(_ sender: Any) {
  979. if (self.canResponseDocumentAction() == false) {
  980. return
  981. }
  982. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  983. document.mainViewController?.menuItemAction_gotoPage(sender)
  984. }
  985. }
  986. }
  987. // MARK: - KMSystemToolMenuProtocol
  988. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  989. func menuItemAction_scrolTool(_ sender: Any) {
  990. if (self.canResponseDocumentAction() == false) {
  991. return
  992. }
  993. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  994. document.mainViewController?.menuItemAction_scrolTool(sender)
  995. }
  996. }
  997. func menuItemAction_zoomOutTool(_ sender: Any) {
  998. if (self.canResponseDocumentAction() == false) {
  999. return
  1000. }
  1001. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1002. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1003. }
  1004. }
  1005. func menuItemAction_selectTool(_ sender: Any) {
  1006. if (self.canResponseDocumentAction() == false) {
  1007. return
  1008. }
  1009. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1010. document.mainViewController?.menuItemAction_selectTool(sender)
  1011. }
  1012. }
  1013. }
  1014. // MARK: - KMSystemWindowMenuRrotocol
  1015. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  1016. func menuItemAction_showForwardTagPage(_ sender: Any) {
  1017. if (self.canResponseDocumentAction() == false) {
  1018. return
  1019. }
  1020. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1021. if (document.isHome) {
  1022. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  1023. } else {
  1024. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  1025. }
  1026. }
  1027. }
  1028. func menuItemAction_showNextTagPage(_ sender: Any) {
  1029. if (self.canResponseDocumentAction() == false) {
  1030. return
  1031. }
  1032. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1033. if (document.isHome) {
  1034. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  1035. } else {
  1036. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  1037. }
  1038. }
  1039. }
  1040. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1041. if (self.canResponseDocumentAction() == false) {
  1042. return
  1043. }
  1044. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1045. if (document.isHome) {
  1046. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1047. } else {
  1048. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1049. }
  1050. }
  1051. }
  1052. func menuItemAction_mergeAllWindow(_ sender: Any) {
  1053. if (self.canResponseDocumentAction() == false) {
  1054. return
  1055. }
  1056. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1057. if (document.isHome) {
  1058. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  1059. } else {
  1060. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  1061. }
  1062. }
  1063. }
  1064. }