KMBrowserWindowController.swift 77 KB

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