KMBrowserWindowController.swift 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232
  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 changeToolMode(_ sender: Any?) {
  669. KMPrint("changeToolMode ...")
  670. }
  671. @IBAction func toggleFullscreen(_ sender: Any?) {
  672. KMPrint("toggleFullscreen ...")
  673. }
  674. @IBAction func toggleRightSidePane(_ sender: Any?) {
  675. KMPrint("toggleRightSidePane ...")
  676. }
  677. @IBAction func performFit(_ sender: Any?) {
  678. KMPrint("performFit ...")
  679. }
  680. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  681. KMPrint("changeRightSidePaneState ...")
  682. }
  683. @IBAction func changeFindPaneState(_ sender: Any?) {
  684. KMPrint("changeFindPaneState ...")
  685. }
  686. @IBAction func toggleSplitPDF(_ sender: Any?) {
  687. KMPrint("toggleSplitPDF ...")
  688. }
  689. @IBAction func search(_ sender: Any?) {
  690. KMPrint("search ...")
  691. }
  692. @IBAction func searchNotes(_ sender: Any?) {
  693. KMPrint("searchNotes ...")
  694. }
  695. @IBAction func password(_ sender: Any?) {
  696. KMPrint("password ...")
  697. }
  698. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  699. KMPrint("savePDFSettingToDefaults ...")
  700. }
  701. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  702. KMPrint("toggleCaseInsensitiveSearch ...")
  703. }
  704. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  705. KMPrint("toggleWholeWordSearch ...")
  706. }
  707. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  708. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  709. }
  710. @IBAction func performFindPanelAction(_ sender: Any?) {
  711. KMPrint("performFindPanelAction ...")
  712. }
  713. @IBAction func scrollUp(_ sender: Any?) {
  714. KMPrint("scrollUp ...")
  715. }
  716. @IBAction func scrollDown(_ sender: Any?) {
  717. KMPrint("scrollDown ...")
  718. }
  719. @IBAction func scrollRight(_ sender: Any?) {
  720. KMPrint("scrollRight ...")
  721. }
  722. @IBAction func scrollLeft(_ sender: Any?) {
  723. KMPrint("scrollLeft ...")
  724. }
  725. @IBAction func selectSelectedNote(_ sender: Any?) {
  726. KMPrint("selectSelectedNote ...")
  727. }
  728. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  729. KMPrint("goToSelectedOutlineItem ...")
  730. }
  731. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  732. KMPrint("goToSelectedFindResults ...")
  733. }
  734. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  735. KMPrint("toggleSelectedSnapshots ...")
  736. }
  737. @IBAction func selfSignProfile(_ sender: Any?) {
  738. KMPrint("selfSignProfile ...")
  739. }
  740. @IBAction func highlightFormFiled(_ sender: Any?) {
  741. KMPrint("highlightFormFiled ...")
  742. }
  743. @IBAction func highlightLinks(_ sender: Any?) {
  744. KMPrint("highlightLinks ...")
  745. }
  746. @IBAction func resetForm(_ sender: Any?) {
  747. KMPrint("resetForm ...")
  748. }
  749. @IBAction func removeAllAnnotation(_ sender: Any?) {
  750. KMPrint("removeAllAnnotation ...")
  751. }
  752. @IBAction func link(_ sender: Any?) {
  753. KMPrint("link ...")
  754. }
  755. @IBAction func pageEdit(_ sender: Any?) {
  756. KMPrint("pageEdit ...")
  757. }
  758. @IBAction func ocr(_ sender: Any?) {
  759. KMPrint("ocr ...")
  760. }
  761. @IBAction func insertPage(_ sender: Any?) {
  762. KMPrint("insertPage ...")
  763. }
  764. @IBAction func split(_ sender: Any?) {
  765. KMPrint("split ...")
  766. }
  767. @IBAction func comparison(_ sender: Any?) {
  768. KMPrint("comparison ...")
  769. }
  770. @IBAction func contentComparison(_ sender: Any?) {
  771. KMPrint("contentComparison ...")
  772. }
  773. @IBAction func coverageComparison(_ sender: Any?) {
  774. KMPrint("coverageComparison ...")
  775. }
  776. @IBAction func readMode(_ sender: Any?) {
  777. KMPrint("readMode ...")
  778. }
  779. @IBAction func changeFormType(_ sender: Any?) {
  780. KMPrint("changeFormType ...")
  781. }
  782. @IBAction func changeSelfSignType(_ sender: Any?) {
  783. KMPrint("changeSelfSignType ...")
  784. }
  785. @IBAction func clearAllForm(_ sender: Any?) {
  786. KMPrint("clearAllForm ...")
  787. }
  788. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  789. KMPrint("thumbnailSizeScaling ...")
  790. }
  791. @IBAction func textEditAction(_ sender: Any?) {
  792. KMPrint("textEditAction ...")
  793. }
  794. @IBAction func redactAction(_ sender: Any?) {
  795. if (self.canResponseDocumentAction() == false) {
  796. return
  797. }
  798. if let document = self.browser.activeTabContents() as? KMMainDocument {
  799. if document.isHome == false {
  800. document.mainViewController?.menuItemAction_redact(sender)
  801. }
  802. }
  803. }
  804. }
  805. // MARK: - KMSystemFileMenuProtocol
  806. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  807. func menuItemClick_saveAsFlattenedPDF(_ 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_saveAsFlattenedPDF(sender)
  816. }
  817. }
  818. }
  819. func menuItemClick_mergePDF(_ 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_mergePDF(sender)
  826. } else {
  827. document.mainViewController?.menuItemClick_mergePDF(sender)
  828. }
  829. }
  830. }
  831. func menuItemClick_Compress(_ 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?.menuItemClick_Compress(sender)
  838. } else {
  839. document.mainViewController?.menuItemClick_Compress(sender)
  840. }
  841. }
  842. }
  843. func menuItemAction_ConvertToWord(_ 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_ConvertToWord(sender)
  850. } else {
  851. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  852. }
  853. }
  854. }
  855. func menuItemAction_ConvertToExcel(_ 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_ConvertToExcel(sender)
  862. } else {
  863. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  864. }
  865. }
  866. }
  867. func menuItemAction_ConvertToPPT(_ 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_ConvertToPPT(sender)
  874. } else {
  875. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  876. }
  877. }
  878. }
  879. func menuItemAction_ConvertToRTF(_ 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_ConvertToRTF(sender)
  886. } else {
  887. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  888. }
  889. }
  890. }
  891. func menuItemAction_ConvertToHTML(_ 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_ConvertToHTML(sender)
  898. } else {
  899. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  900. }
  901. }
  902. }
  903. func menuItemAction_ConvertToText(_ 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_ConvertToText(sender)
  910. } else {
  911. document.mainViewController?.menuItemAction_ConvertToText(sender)
  912. }
  913. }
  914. }
  915. func menuItemAction_ConvertToCSV(_ 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_ConvertToCSV(sender)
  922. } else {
  923. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  924. }
  925. }
  926. }
  927. func menuItemAction_ConvertToImage(_ 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?.menuItemAction_ConvertToImage(sender)
  934. } else {
  935. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  936. }
  937. }
  938. }
  939. func menuItemClick_SettingPassword(_ sender: Any) {
  940. if (self.canResponseDocumentAction() == false) {
  941. return
  942. }
  943. if let document = self.browser.activeTabContents() as? KMMainDocument {
  944. if (document.isHome) {
  945. document.homeViewController?.menuItemClick_SettingPassword(sender)
  946. } else {
  947. document.mainViewController?.menuItemClick_SettingPassword(sender)
  948. }
  949. }
  950. }
  951. func menuItemClick_RemovePassword(_ sender: Any) {
  952. if (self.canResponseDocumentAction() == false) {
  953. return
  954. }
  955. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  956. document.mainViewController?.menuItemClick_RemovePassword(sender)
  957. }
  958. }
  959. func menuItemAction_closeWindow(_ 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_closeWindow(sender)
  966. } else {
  967. document.mainViewController?.menuItemAction_closeWindow(sender)
  968. }
  969. }
  970. }
  971. func menuItemAction_closeAllWindows(_ sender: Any) {
  972. if (self.canResponseDocumentAction() == false) {
  973. return
  974. }
  975. if let document = self.browser.activeTabContents() as? KMMainDocument {
  976. if (document.isHome) {
  977. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  978. } else {
  979. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  980. }
  981. }
  982. }
  983. func menuItemAction_closeTagPage(_ sender: Any) {
  984. if (self.canResponseDocumentAction() == false) {
  985. return
  986. }
  987. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  988. document.mainViewController?.menuItemAction_closeTagPage(sender)
  989. }
  990. }
  991. func menuItemAction_showInFinder(_ sender: Any) {
  992. if (self.canResponseDocumentAction() == false) {
  993. return
  994. }
  995. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  996. document.mainViewController?.menuItemAction_showInFinder(sender)
  997. }
  998. }
  999. func menuItemAction_property(_ sender: Any) {
  1000. if (self.canResponseDocumentAction() == false) {
  1001. return
  1002. }
  1003. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1004. document.mainViewController?.menuItemAction_property(sender)
  1005. }
  1006. }
  1007. func menuItemAction_print(_ sender: Any) {
  1008. if (self.canResponseDocumentAction() == false) {
  1009. return
  1010. }
  1011. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1012. document.mainViewController?.menuItemAction_print(sender)
  1013. }
  1014. }
  1015. }
  1016. // MARK: - KMSystemViewMenuProtocol
  1017. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  1018. func menuItemAction_adjustWidth(_ sender: Any) {
  1019. if (self.canResponseDocumentAction() == false) {
  1020. return
  1021. }
  1022. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1023. document.mainViewController?.menuItemAction_adjustWidth(sender)
  1024. }
  1025. }
  1026. func menuItemAction_adjustPage(_ sender: Any) {
  1027. if (self.canResponseDocumentAction() == false) {
  1028. return
  1029. }
  1030. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1031. document.mainViewController?.menuItemAction_adjustPage(sender)
  1032. }
  1033. }
  1034. func menuItemAction_size(_ sender: Any) {
  1035. if (self.canResponseDocumentAction() == false) {
  1036. return
  1037. }
  1038. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1039. document.mainViewController?.menuItemAction_size(sender)
  1040. }
  1041. }
  1042. func menuItemAction_zoomOut(_ sender: Any) {
  1043. if (self.canResponseDocumentAction() == false) {
  1044. return
  1045. }
  1046. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1047. document.mainViewController?.menuItemAction_zoomOut(sender)
  1048. }
  1049. }
  1050. func menuItemAction_zoomIn(_ sender: Any) {
  1051. if (self.canResponseDocumentAction() == false) {
  1052. return
  1053. }
  1054. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1055. document.mainViewController?.menuItemAction_zoomIn(sender)
  1056. }
  1057. }
  1058. func menuItemAction_singlePage(_ sender: Any) {
  1059. if (self.canResponseDocumentAction() == false) {
  1060. return
  1061. }
  1062. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1063. document.mainViewController?.menuItemAction_singlePage(sender)
  1064. }
  1065. }
  1066. func menuItemAction_singlePageContinue(_ sender: Any) {
  1067. if (self.canResponseDocumentAction() == false) {
  1068. return
  1069. }
  1070. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1071. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1072. }
  1073. }
  1074. func menuItemAction_doublePage(_ sender: Any) {
  1075. if (self.canResponseDocumentAction() == false) {
  1076. return
  1077. }
  1078. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1079. document.mainViewController?.menuItemAction_doublePage(sender)
  1080. }
  1081. }
  1082. func menuItemAction_doublePageContinue(_ sender: Any) {
  1083. if (self.canResponseDocumentAction() == false) {
  1084. return
  1085. }
  1086. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1087. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1088. }
  1089. }
  1090. func menuItemAction_bookMode(_ sender: Any) {
  1091. if (self.canResponseDocumentAction() == false) {
  1092. return
  1093. }
  1094. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1095. document.mainViewController?.menuItemAction_bookMode(sender)
  1096. }
  1097. }
  1098. func menuItemAction_readMode(_ sender: Any) {
  1099. if (self.canResponseDocumentAction() == false) {
  1100. return
  1101. }
  1102. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1103. document.mainViewController?.menuItemAction_readMode(sender)
  1104. }
  1105. }
  1106. func menuItemAction_showSplitPage(_ sender: Any) {
  1107. if (self.canResponseDocumentAction() == false) {
  1108. return
  1109. }
  1110. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1111. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1112. }
  1113. }
  1114. func menuItemAction_rotateLeft(_ sender: Any) {
  1115. if (self.canResponseDocumentAction() == false) {
  1116. return
  1117. }
  1118. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1119. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1120. }
  1121. }
  1122. func menuItemAction_rotateRight(_ sender: Any) {
  1123. if (self.canResponseDocumentAction() == false) {
  1124. return
  1125. }
  1126. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1127. document.mainViewController?.menuItemAction_rotateRight(sender)
  1128. }
  1129. }
  1130. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1131. if (self.canResponseDocumentAction() == false) {
  1132. return
  1133. }
  1134. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1135. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1136. }
  1137. }
  1138. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1139. if (self.canResponseDocumentAction() == false) {
  1140. return
  1141. }
  1142. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1143. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1144. }
  1145. }
  1146. func menuItemAction_view_readMode(_ sender: Any) {
  1147. if (self.canResponseDocumentAction() == false) {
  1148. return
  1149. }
  1150. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1151. document.mainViewController?.menuItemAction_view_readMode(sender)
  1152. }
  1153. }
  1154. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1155. if (self.canResponseDocumentAction() == false) {
  1156. return
  1157. }
  1158. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1159. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1160. }
  1161. }
  1162. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1163. if (self.canResponseDocumentAction() == false) {
  1164. return
  1165. }
  1166. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1167. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1168. }
  1169. }
  1170. func menuItemAction_thumai(_ sender: Any) {
  1171. if (self.canResponseDocumentAction() == false) {
  1172. return
  1173. }
  1174. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1175. document.mainViewController?.menuItemAction_thumai(sender)
  1176. }
  1177. }
  1178. func menuItemAction_outline(_ sender: Any) {
  1179. if (self.canResponseDocumentAction() == false) {
  1180. return
  1181. }
  1182. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1183. document.mainViewController?.menuItemAction_outline(sender)
  1184. }
  1185. }
  1186. func menuItemAction_bookmark(_ sender: Any) {
  1187. if (self.canResponseDocumentAction() == false) {
  1188. return
  1189. }
  1190. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1191. document.mainViewController?.menuItemAction_bookmark(sender)
  1192. }
  1193. }
  1194. func menuItemAction_annotation(_ sender: Any) {
  1195. if (self.canResponseDocumentAction() == false) {
  1196. return
  1197. }
  1198. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1199. document.mainViewController?.menuItemAction_annotation(sender)
  1200. }
  1201. }
  1202. func menuItemAction_search(_ sender: Any) {
  1203. if (self.canResponseDocumentAction() == false) {
  1204. return
  1205. }
  1206. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1207. document.mainViewController?.menuItemAction_search(sender)
  1208. }
  1209. }
  1210. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1211. if (self.canResponseDocumentAction() == false) {
  1212. return
  1213. }
  1214. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1215. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1216. }
  1217. }
  1218. }
  1219. // MARK: - KMSystemEditMenuProtocol
  1220. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1221. func menuItemAction_find(_ sender: Any) {
  1222. if (self.canResponseDocumentAction() == false) {
  1223. return
  1224. }
  1225. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1226. document.mainViewController?.menuItemAction_find(sender)
  1227. }
  1228. }
  1229. }
  1230. // MARK: - Annotation Menu
  1231. extension KMBrowserWindowController {
  1232. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1233. if (self.canResponseDocumentAction() == false) {
  1234. return
  1235. }
  1236. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1237. document.mainViewController?.menuItemAction_highlight(sender)
  1238. }
  1239. }
  1240. @IBAction func menuItemAction_underline(_ sender: Any) {
  1241. if (self.canResponseDocumentAction() == false) {
  1242. return
  1243. }
  1244. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1245. document.mainViewController?.menuItemAction_underline(sender)
  1246. }
  1247. }
  1248. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1249. if (self.canResponseDocumentAction() == false) {
  1250. return
  1251. }
  1252. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1253. document.mainViewController?.menuItemAction_deleteLine(sender)
  1254. }
  1255. }
  1256. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1257. if (self.canResponseDocumentAction() == false) {
  1258. return
  1259. }
  1260. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1261. document.mainViewController?.menuItemAction_freehand(sender)
  1262. }
  1263. }
  1264. @IBAction func menuItemAction_text(_ sender: Any) {
  1265. if (self.canResponseDocumentAction() == false) {
  1266. return
  1267. }
  1268. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1269. document.mainViewController?.menuItemAction_text(sender)
  1270. }
  1271. }
  1272. @IBAction func menuItemAction_note(_ sender: Any) {
  1273. if (self.canResponseDocumentAction() == false) {
  1274. return
  1275. }
  1276. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1277. document.mainViewController?.menuItemAction_note(sender)
  1278. }
  1279. }
  1280. @IBAction func menuItemAction_squre(_ sender: Any) {
  1281. if (self.canResponseDocumentAction() == false) {
  1282. return
  1283. }
  1284. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1285. document.mainViewController?.menuItemAction_squre(sender)
  1286. }
  1287. }
  1288. @IBAction func menuItemAction_circle(_ sender: Any) {
  1289. if (self.canResponseDocumentAction() == false) {
  1290. return
  1291. }
  1292. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1293. document.mainViewController?.menuItemAction_circle(sender)
  1294. }
  1295. }
  1296. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1297. if (self.canResponseDocumentAction() == false) {
  1298. return
  1299. }
  1300. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1301. document.mainViewController?.menuItemAction_arrow(sender)
  1302. }
  1303. }
  1304. @IBAction func menuItemAction_line(_ sender: Any) {
  1305. if (self.canResponseDocumentAction() == false) {
  1306. return
  1307. }
  1308. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1309. document.mainViewController?.menuItemAction_line(sender)
  1310. }
  1311. }
  1312. // link
  1313. @IBAction func menuItemAction_link(_ sender: Any) {
  1314. if (self.canResponseDocumentAction() == false) {
  1315. return
  1316. }
  1317. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1318. document.mainViewController?.menuItemAction_link(sender)
  1319. }
  1320. }
  1321. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1322. if (self.canResponseDocumentAction() == false) {
  1323. return
  1324. }
  1325. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1326. document.mainViewController?.menuItemAction_linkPage(sender)
  1327. }
  1328. }
  1329. // stamp
  1330. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1331. if (self.canResponseDocumentAction() == false) {
  1332. return
  1333. }
  1334. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1335. document.mainViewController?.menuItemAction_stamp(sender)
  1336. }
  1337. }
  1338. @IBAction func menuItemAction_signure(_ sender: Any) {
  1339. if (self.canResponseDocumentAction() == false) {
  1340. return
  1341. }
  1342. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1343. document.mainViewController?.menuItemAction_signure(sender)
  1344. }
  1345. }
  1346. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1347. if (self.canResponseDocumentAction() == false) {
  1348. return
  1349. }
  1350. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1351. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1352. }
  1353. }
  1354. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1355. if (self.canResponseDocumentAction() == false) {
  1356. return
  1357. }
  1358. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1359. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1360. }
  1361. }
  1362. }
  1363. // MARK: - KMSystemGotoMenuProtocol
  1364. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1365. func menuItemAction_nextPage(_ sender: Any) {
  1366. if (self.canResponseDocumentAction() == false) {
  1367. return
  1368. }
  1369. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1370. document.mainViewController?.menuItemAction_nextPage(sender)
  1371. }
  1372. }
  1373. func menuItemAction_forwardPage(_ sender: Any) {
  1374. if (self.canResponseDocumentAction() == false) {
  1375. return
  1376. }
  1377. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1378. document.mainViewController?.menuItemAction_forwardPage(sender)
  1379. }
  1380. }
  1381. func menuItemAction_firstPage(_ sender: Any) {
  1382. if (self.canResponseDocumentAction() == false) {
  1383. return
  1384. }
  1385. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1386. document.mainViewController?.menuItemAction_firstPage(sender)
  1387. }
  1388. }
  1389. func menuItemAction_lastPage(_ sender: Any) {
  1390. if (self.canResponseDocumentAction() == false) {
  1391. return
  1392. }
  1393. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1394. document.mainViewController?.menuItemAction_lastPage(sender)
  1395. }
  1396. }
  1397. func menuItemAction_forward(_ sender: Any) {
  1398. if (self.canResponseDocumentAction() == false) {
  1399. return
  1400. }
  1401. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1402. document.mainViewController?.menuItemAction_forward(sender)
  1403. }
  1404. }
  1405. func menuItemAction_goback(_ sender: Any) {
  1406. if (self.canResponseDocumentAction() == false) {
  1407. return
  1408. }
  1409. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1410. document.mainViewController?.menuItemAction_goback(sender)
  1411. }
  1412. }
  1413. func menuItemAction_gotoPage(_ sender: Any) {
  1414. if (self.canResponseDocumentAction() == false) {
  1415. return
  1416. }
  1417. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1418. document.mainViewController?.menuItemAction_gotoPage(sender)
  1419. }
  1420. }
  1421. }
  1422. // MARK: - KMSystemToolMenuProtocol
  1423. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  1424. func menuItemAction_scrolTool(_ sender: Any) {
  1425. if (self.canResponseDocumentAction() == false) {
  1426. return
  1427. }
  1428. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1429. document.mainViewController?.menuItemAction_scrolTool(sender)
  1430. }
  1431. }
  1432. func menuItemAction_zoomOutTool(_ sender: Any) {
  1433. if (self.canResponseDocumentAction() == false) {
  1434. return
  1435. }
  1436. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1437. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  1438. }
  1439. }
  1440. func menuItemAction_selectTool(_ sender: Any) {
  1441. if (self.canResponseDocumentAction() == false) {
  1442. return
  1443. }
  1444. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1445. document.mainViewController?.menuItemAction_selectTool(sender)
  1446. }
  1447. }
  1448. @IBAction func compression(_ sender: Any?) {
  1449. if (self.canResponseDocumentAction() == false) {
  1450. return
  1451. }
  1452. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1453. if (document.isHome) {
  1454. } else {
  1455. document.mainViewController?.compression(sender)
  1456. }
  1457. }
  1458. }
  1459. @IBAction func merge(_ sender: Any?) {
  1460. if (self.canResponseDocumentAction() == false) {
  1461. return
  1462. }
  1463. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1464. if (document.isHome) {
  1465. } else {
  1466. document.mainViewController?.merge(sender)
  1467. }
  1468. }
  1469. }
  1470. @IBAction func convert(_ sender: Any?) {
  1471. if (self.canResponseDocumentAction() == false) {
  1472. return
  1473. }
  1474. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1475. if (document.isHome) {
  1476. } else {
  1477. document.mainViewController?.convert(sender)
  1478. }
  1479. }
  1480. }
  1481. @IBAction func imageToPDF(_ sender: Any?) {
  1482. if (self.canResponseDocumentAction() == false) {
  1483. return
  1484. }
  1485. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1486. if (document.isHome) {
  1487. } else {
  1488. document.mainViewController?.imageToPDF(sender)
  1489. }
  1490. }
  1491. }
  1492. @IBAction func extractImage(_ sender: Any?) {
  1493. if (self.canResponseDocumentAction() == false) {
  1494. return
  1495. }
  1496. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1497. if (document.isHome) {
  1498. } else {
  1499. document.mainViewController?.extractImage(sender)
  1500. }
  1501. }
  1502. }
  1503. @IBAction func security(_ sender: Any?) {
  1504. if (self.canResponseDocumentAction() == false) {
  1505. return
  1506. }
  1507. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1508. if (document.isHome) {
  1509. } else {
  1510. document.mainViewController?.security(sender)
  1511. }
  1512. }
  1513. }
  1514. @IBAction func decryption(_ sender: Any?) {
  1515. if (self.canResponseDocumentAction() == false) {
  1516. return
  1517. }
  1518. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1519. if (document.isHome) {
  1520. } else {
  1521. document.mainViewController?.decryption(sender)
  1522. }
  1523. }
  1524. }
  1525. @IBAction func cropAll(_ sender: Any?) {
  1526. if (self.canResponseDocumentAction() == false) {
  1527. return
  1528. }
  1529. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1530. if (document.isHome) {
  1531. } else {
  1532. document.mainViewController?.cropAll(sender)
  1533. }
  1534. }
  1535. }
  1536. @IBAction func crop(_ sender: Any?) {
  1537. if (self.canResponseDocumentAction() == false) {
  1538. return
  1539. }
  1540. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1541. if (document.isHome) {
  1542. } else {
  1543. document.mainViewController?.crop(sender)
  1544. }
  1545. }
  1546. }
  1547. @IBAction func autoCropAll(_ sender: Any?) {
  1548. if (self.canResponseDocumentAction() == false) {
  1549. return
  1550. }
  1551. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1552. if (document.isHome) {
  1553. } else {
  1554. document.mainViewController?.autoCropAll(sender)
  1555. }
  1556. }
  1557. }
  1558. @IBAction func smartAutoCropAll(_ sender: Any?) {
  1559. if (self.canResponseDocumentAction() == false) {
  1560. return
  1561. }
  1562. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1563. if (document.isHome) {
  1564. } else {
  1565. document.mainViewController?.smartAutoCropAll(sender)
  1566. }
  1567. }
  1568. }
  1569. @IBAction func cropOptionsModel(_ sender: Any?) {
  1570. if (self.canResponseDocumentAction() == false) {
  1571. return
  1572. }
  1573. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1574. if (document.isHome) {
  1575. } else {
  1576. // document.mainViewController?.cropOptionsModel(sender)
  1577. }
  1578. }
  1579. }
  1580. @IBAction func selectToolModel(_ sender: Any?) {
  1581. if (self.canResponseDocumentAction() == false) {
  1582. return
  1583. }
  1584. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1585. if (document.isHome) {
  1586. } else {
  1587. document.mainViewController?.selectToolModel(sender)
  1588. }
  1589. }
  1590. }
  1591. @IBAction func takeSnapshot(_ sender: Any?) {
  1592. if (self.canResponseDocumentAction() == false) {
  1593. return
  1594. }
  1595. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1596. if (document.isHome) {
  1597. } else {
  1598. document.mainViewController?.takeSnapshot(sender)
  1599. }
  1600. }
  1601. }
  1602. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  1603. if (self.canResponseDocumentAction() == false) {
  1604. return
  1605. }
  1606. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1607. if (document.isHome) {
  1608. } else {
  1609. document.mainViewController?.takeSnapshotSelectContent(sender)
  1610. }
  1611. }
  1612. }
  1613. @IBAction func changeAnnotationMode(_ sender: Any?) {
  1614. if (self.canResponseDocumentAction() == false) {
  1615. return
  1616. }
  1617. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1618. if (document.isHome) {
  1619. } else {
  1620. document.mainViewController?.changeAnnotationMode(sender)
  1621. }
  1622. }
  1623. }
  1624. @IBAction func addBackground(_ sender: Any?) {
  1625. if (self.canResponseDocumentAction() == false) {
  1626. return
  1627. }
  1628. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1629. if (document.isHome) {
  1630. } else {
  1631. document.mainViewController?.addBackground(sender)
  1632. }
  1633. }
  1634. }
  1635. @IBAction func removeBackground(_ sender: Any?) {
  1636. if (self.canResponseDocumentAction() == false) {
  1637. return
  1638. }
  1639. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1640. if (document.isHome) {
  1641. } else {
  1642. document.mainViewController?.removeBackground(sender)
  1643. }
  1644. }
  1645. }
  1646. @IBAction func addWatermark(_ sender: Any?) {
  1647. if (self.canResponseDocumentAction() == false) {
  1648. return
  1649. }
  1650. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1651. if (document.isHome) {
  1652. } else {
  1653. document.mainViewController?.addWatermark(sender)
  1654. }
  1655. }
  1656. }
  1657. @IBAction func editWatermark(_ sender: Any?) {
  1658. KMPrint("editWatermark ...")
  1659. }
  1660. @IBAction func batchAddWatermark(_ sender: Any?) {
  1661. if (self.canResponseDocumentAction() == false) {
  1662. return
  1663. }
  1664. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1665. if (document.isHome) {
  1666. } else {
  1667. document.mainViewController?.batchAddWatermark(sender)
  1668. }
  1669. }
  1670. }
  1671. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  1672. if (self.canResponseDocumentAction() == false) {
  1673. return
  1674. }
  1675. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1676. if (document.isHome) {
  1677. } else {
  1678. document.mainViewController?.batchRemoveWatermark(sender)
  1679. }
  1680. }
  1681. }
  1682. @IBAction func removeWatermark(_ sender: Any?) {
  1683. if (self.canResponseDocumentAction() == false) {
  1684. return
  1685. }
  1686. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1687. if (document.isHome) {
  1688. } else {
  1689. document.mainViewController?.removeWatermark(sender)
  1690. }
  1691. }
  1692. }
  1693. @IBAction func templateWatermark(_ sender: Any?) {
  1694. if (self.canResponseDocumentAction() == false) {
  1695. return
  1696. }
  1697. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1698. if (document.isHome) {
  1699. } else {
  1700. document.mainViewController?.templateWatermark(sender)
  1701. }
  1702. }
  1703. }
  1704. @IBAction func batchAddBackground(_ sender: Any?) {
  1705. if (self.canResponseDocumentAction() == false) {
  1706. return
  1707. }
  1708. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1709. if (document.isHome) {
  1710. } else {
  1711. document.mainViewController?.batchAddBackground(sender)
  1712. }
  1713. }
  1714. }
  1715. @IBAction func batchRemoveBackground(_ sender: Any?) {
  1716. if (self.canResponseDocumentAction() == false) {
  1717. return
  1718. }
  1719. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1720. if (document.isHome) {
  1721. } else {
  1722. document.mainViewController?.batchRemoveBackground(sender)
  1723. }
  1724. }
  1725. }
  1726. @IBAction func templateBackground(_ sender: Any?) {
  1727. if (self.canResponseDocumentAction() == false) {
  1728. return
  1729. }
  1730. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1731. if (document.isHome) {
  1732. } else {
  1733. document.mainViewController?.templateBackground(sender)
  1734. }
  1735. }
  1736. }
  1737. @IBAction func addHeaderFooter(_ sender: Any?) {
  1738. if (self.canResponseDocumentAction() == false) {
  1739. return
  1740. }
  1741. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1742. if (document.isHome) {
  1743. } else {
  1744. document.mainViewController?.addHeaderFooter(sender)
  1745. }
  1746. }
  1747. }
  1748. @IBAction func removeHeaderFooter(_ sender: Any?) {
  1749. if (self.canResponseDocumentAction() == false) {
  1750. return
  1751. }
  1752. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1753. if (document.isHome) {
  1754. } else {
  1755. document.mainViewController?.removeHeaderFooter(sender)
  1756. }
  1757. }
  1758. }
  1759. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  1760. if (self.canResponseDocumentAction() == false) {
  1761. return
  1762. }
  1763. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1764. if (document.isHome) {
  1765. } else {
  1766. document.mainViewController?.batchAddHeaderFooter(sender)
  1767. }
  1768. }
  1769. }
  1770. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  1771. if (self.canResponseDocumentAction() == false) {
  1772. return
  1773. }
  1774. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1775. if (document.isHome) {
  1776. } else {
  1777. document.mainViewController?.batchRemoveHeaderFooter(sender)
  1778. }
  1779. }
  1780. }
  1781. @IBAction func templateHeaderFooter(_ sender: Any?) {
  1782. if (self.canResponseDocumentAction() == false) {
  1783. return
  1784. }
  1785. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1786. if (document.isHome) {
  1787. } else {
  1788. document.mainViewController?.templateHeaderFooter(sender)
  1789. }
  1790. }
  1791. }
  1792. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  1793. if (self.canResponseDocumentAction() == false) {
  1794. return
  1795. }
  1796. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1797. if (document.isHome) {
  1798. } else {
  1799. document.mainViewController?.addHeaderFooterBates(sender)
  1800. }
  1801. }
  1802. }
  1803. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  1804. if (self.canResponseDocumentAction() == false) {
  1805. return
  1806. }
  1807. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1808. if (document.isHome) {
  1809. } else {
  1810. document.mainViewController?.removeHeaderFooterBates(sender)
  1811. }
  1812. }
  1813. }
  1814. @IBAction func batchAddBates(_ sender: Any?) {
  1815. if (self.canResponseDocumentAction() == false) {
  1816. return
  1817. }
  1818. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1819. if (document.isHome) {
  1820. } else {
  1821. document.mainViewController?.batchAddBates(sender)
  1822. }
  1823. }
  1824. }
  1825. @IBAction func batchRemoveBates(_ sender: Any?) {
  1826. if (self.canResponseDocumentAction() == false) {
  1827. return
  1828. }
  1829. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1830. if (document.isHome) {
  1831. } else {
  1832. document.mainViewController?.batchRemoveBates(sender)
  1833. }
  1834. }
  1835. }
  1836. @IBAction func templateBates(_ sender: Any?) {
  1837. if (self.canResponseDocumentAction() == false) {
  1838. return
  1839. }
  1840. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1841. if (document.isHome) {
  1842. } else {
  1843. document.mainViewController?.templateBates(sender)
  1844. }
  1845. }
  1846. }
  1847. @IBAction func togglePoster(_ sender: Any?) {
  1848. if (self.canResponseDocumentAction() == false) {
  1849. return
  1850. }
  1851. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1852. if (document.isHome) {
  1853. } else {
  1854. document.mainViewController?.togglePoster(sender)
  1855. }
  1856. }
  1857. }
  1858. @IBAction func toggleMultiple(_ sender: Any?) {
  1859. if (self.canResponseDocumentAction() == false) {
  1860. return
  1861. }
  1862. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1863. if (document.isHome) {
  1864. } else {
  1865. document.mainViewController?.toggleMultiple(sender)
  1866. }
  1867. }
  1868. }
  1869. @IBAction func toggleBooklet(_ sender: Any?) {
  1870. if (self.canResponseDocumentAction() == false) {
  1871. return
  1872. }
  1873. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1874. if (document.isHome) {
  1875. } else {
  1876. document.mainViewController?.toggleBooklet(sender)
  1877. }
  1878. }
  1879. }
  1880. @IBAction func rotateRight(_ sender: Any?) {
  1881. if (self.canResponseDocumentAction() == false) {
  1882. return
  1883. }
  1884. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1885. if (document.isHome) {
  1886. } else {
  1887. document.mainViewController?.rotateRight(sender)
  1888. }
  1889. }
  1890. }
  1891. @IBAction func rotateLeft(_ sender: Any?) {
  1892. if (self.canResponseDocumentAction() == false) {
  1893. return
  1894. }
  1895. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1896. if (document.isHome) {
  1897. } else {
  1898. document.mainViewController?.rotateLeft(sender)
  1899. }
  1900. }
  1901. }
  1902. @IBAction func rotateAllRight(_ sender: Any?) {
  1903. if (self.canResponseDocumentAction() == false) {
  1904. return
  1905. }
  1906. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1907. if (document.isHome) {
  1908. } else {
  1909. document.mainViewController?.rotateAllRight(sender)
  1910. }
  1911. }
  1912. }
  1913. @IBAction func rotateAllLeft(_ sender: Any?) {
  1914. if (self.canResponseDocumentAction() == false) {
  1915. return
  1916. }
  1917. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1918. if (document.isHome) {
  1919. } else {
  1920. document.mainViewController?.rotateAllLeft(sender)
  1921. }
  1922. }
  1923. }
  1924. @IBAction func autoSelectContent(_ sender: Any?) {
  1925. if (self.canResponseDocumentAction() == false) {
  1926. return
  1927. }
  1928. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1929. if (document.isHome) {
  1930. } else {
  1931. document.mainViewController?.autoSelectContent(sender)
  1932. }
  1933. }
  1934. }
  1935. }
  1936. // MARK: - KMSystemWindowMenuRrotocol
  1937. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  1938. func menuItemAction_showForwardTagPage(_ sender: Any) {
  1939. if (self.canResponseDocumentAction() == false) {
  1940. return
  1941. }
  1942. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1943. if (document.isHome) {
  1944. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  1945. } else {
  1946. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  1947. }
  1948. }
  1949. }
  1950. func menuItemAction_showNextTagPage(_ sender: Any) {
  1951. if (self.canResponseDocumentAction() == false) {
  1952. return
  1953. }
  1954. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1955. if (document.isHome) {
  1956. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  1957. } else {
  1958. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  1959. }
  1960. }
  1961. }
  1962. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  1963. if (self.canResponseDocumentAction() == false) {
  1964. return
  1965. }
  1966. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1967. if (document.isHome) {
  1968. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1969. } else {
  1970. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  1971. }
  1972. }
  1973. }
  1974. func menuItemAction_mergeAllWindow(_ sender: Any) {
  1975. if (self.canResponseDocumentAction() == false) {
  1976. return
  1977. }
  1978. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1979. if (document.isHome) {
  1980. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  1981. } else {
  1982. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  1983. }
  1984. }
  1985. }
  1986. }
  1987. // MARK: - Analytics (埋点)
  1988. extension KMBrowserWindowController {
  1989. func trackEvent_upgrade() -> Void {
  1990. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  1991. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  1992. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  1993. }
  1994. }