KMBrowserWindowController.swift 45 KB

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