KMBrowserWindowController.swift 78 KB

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