KMBrowserWindowController.swift 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016
  1. //
  2. // KMBrowserWindowController.swift
  3. // PDF Reader Pro
  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. var rightMessageVC: KMVerificationMessageViewController!
  17. var rightToolbarItemView: NSView!
  18. private var homeVC: KMHomeViewController?
  19. // 记录当前显示模式
  20. // var _mwcFlags: MwcFlags = MwcFlags()
  21. deinit {
  22. KMPrint("KMBrowserWindowController deinit...")
  23. // self.removeObserverForAppearanceChange()
  24. DistributedNotificationCenter.default().removeObserver(self)
  25. NotificationCenter.default.removeObserver(self)
  26. }
  27. override func loadWindow() {
  28. super.loadWindow()
  29. // self.window?.titlebarAppearsTransparent = true
  30. }
  31. override func windowDidLoad() {
  32. super.windowDidLoad()
  33. NSImage.makeTextAlignImages()
  34. window?.backgroundColor = NSColor.km_init(hex: "#DFE1E5")
  35. self.window?.appearance = NSApp.appearance
  36. self.window?.titlebarAppearsTransparent = true
  37. // self.window?.standardWindowButton(.closeButton)?.superview?.needsLayout = true
  38. // window?.setFrameAutosaveName("")
  39. rightTabStripView_.delete = self
  40. homeRightTabStripView_.delete = self
  41. rightTabStripView_.updateView()
  42. fileUploadPanel.delete = self
  43. homeRightTabStripView_.homeRightSearchField.delegate = self
  44. isMultiTabMode = true
  45. // self.addObserverForAppearanceChange()
  46. refreshToolBar(homeToolState: .Home)
  47. NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
  48. NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
  49. DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
  50. // if (KMWelcomeWindowController.welcomeHasShow() == false) {
  51. // //AI 版本禁掉首次开启帮助文档
  52. //// KMTools.openQuickStartStudy()
  53. //
  54. // DispatchQueue.main.async {
  55. // let welcome = KMWelcomeWindowController()
  56. // self.km_beginSheet(windowC: welcome)
  57. // welcome.itemClick = { [weak self] idx, param in
  58. // if (idx == 1) { // 关闭
  59. // self?.km_endSheet()
  60. // } else if (idx == 2) { // 以后提醒
  61. // self?.km_endSheet()
  62. // } else if (idx == 3) { // 注册
  63. // self?.km_endSheet()
  64. //
  65. // guard let window_ = self?.window else {
  66. // return
  67. // }
  68. // _ = KMLoginWindowController.show(window: window_, .Batch, .register)
  69. // }
  70. // }
  71. // }
  72. // }
  73. updateViewColor()
  74. var tabbingMode = NSWindow.TabbingMode.automatic
  75. let openDocumentType = KMPreference.shared.openDocumentType
  76. if openDocumentType == .inSameWindow {
  77. tabbingMode = .preferred
  78. } else if openDocumentType == .newWindow {
  79. tabbingMode = .disallowed
  80. }
  81. #if VERSION_FREE
  82. if IAPProductsManager.default().isAvailableAllFunction() == false {
  83. tabbingMode = .disallowed
  84. }
  85. #endif
  86. // self.window?.tabbingMode = tabbingMode
  87. }
  88. @objc func closeAction() {
  89. self.window?.performClose(nil)
  90. }
  91. override func windowShouldClose(_ sender: NSWindow) -> Bool {
  92. if self.browser.tabStripModel.count() > 1 {
  93. self.browser.windowDidBeginToClose()
  94. return false
  95. }
  96. return true
  97. }
  98. override func windowWillClose(_ notification: Notification) {
  99. // iRate.sharedInstance().appLaunched()
  100. }
  101. override func layoutSubviews() {
  102. super.layoutSubviews()
  103. // if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
  104. // button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  105. // }
  106. // if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
  107. // button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  108. // }
  109. // if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
  110. // button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
  111. // }
  112. }
  113. // MARK: Dark&Light
  114. // func addObserverForAppearanceChange() -> Void {
  115. // window?.contentView?.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
  116. // }
  117. // func removeObserverForAppearanceChange() -> Void {
  118. // window?.contentView?.removeObserver(self, forKeyPath: "effectiveAppearance")
  119. // }
  120. // override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  121. // if keyPath == "effectiveAppearance" {
  122. // self.updateViewColor()
  123. // }
  124. // }
  125. @objc private func _themeChanged(_ sender: Notification) {
  126. if let data = self.window?.appearance?.name, data == .darkAqua {
  127. self.window?.appearance = .init(named: .aqua)
  128. } else {
  129. self.window?.appearance = .init(named: .darkAqua)
  130. }
  131. self.window?.contentView?.appearance = self.window?.appearance ?? .init(named: .aqua)
  132. self.interfaceThemeDidChanged(self.window?.appearance?.name ?? .aqua)
  133. }
  134. override func updateViewColor() {
  135. super.updateViewColor()
  136. window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
  137. }
  138. // MARK: Public Methods
  139. func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
  140. modeType = toolState
  141. let document = browser.activeTabContents()
  142. if document != nil {
  143. if document!.isHome {
  144. homeRightTabStripView_.isHidden = modeType == .Home
  145. } else {
  146. self.homeRightStripView.isHidden = true
  147. }
  148. } else {
  149. self.homeRightStripView.isHidden = true
  150. }
  151. homeRightTabStripView_.homeRefreshButton.isEnabled = true
  152. homeRightTabStripView_.homeUploadButton.isEnabled = true
  153. filterType = 0
  154. rightTabStripView_.sortPopUpButton.removeAllItems()
  155. rightTabStripView_.filterPopUpButton.removeAllItems()
  156. rightTabStripView_.updateView()
  157. }
  158. override var hasToolbar: Bool {
  159. get {
  160. return false
  161. }
  162. }
  163. var km_browser: KMBrowser? {
  164. get {
  165. return self.browser as? KMBrowser
  166. }
  167. }
  168. // MARK: Private Methods
  169. func openDocumentWindow() -> Void {
  170. // let panel = NSOpenPanel()
  171. // panel.allowsMultipleSelection = false
  172. // panel.allowedFileTypes = ["pdf"]
  173. // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
  174. // if response == .OK {
  175. // let openPath = panel.url?.path
  176. // let selectDocument = self.selectTabContents(path: openPath!)
  177. // if selectDocument != nil {
  178. // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
  179. // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
  180. // return
  181. // }
  182. // if !panel.url!.path.isPDFValid() {
  183. // let alert = NSAlert()
  184. // alert.alertStyle = .critical
  185. // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
  186. // alert.runModal()
  187. // return
  188. // }
  189. // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
  190. // print("openDocumentWindow")
  191. // }
  192. // }
  193. // }
  194. // MARK TODO: + 号开启
  195. // self.browser.addHomeTabContents()
  196. self.tabStripView?.addTabButton?.layer?.backgroundColor = .clear
  197. self.km_browser?.addNewTabContents()
  198. }
  199. // override func openDocument(_ sender: Any!) {
  200. // self.openDocumentWindow()
  201. // }
  202. func selectTabContents(path filePath: String) -> KMMainDocument? {
  203. let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
  204. var selectDocument: KMMainDocument?
  205. if document != nil {
  206. if document!.isKind(of: KMMainDocument.self) {
  207. selectDocument = document as! KMMainDocument
  208. }
  209. }
  210. return selectDocument
  211. }
  212. // MARK: Getter
  213. override var rightStripView: NSView! {
  214. get {
  215. if self.rightToolbarItemView == nil {
  216. self.rightToolbarItemView = NSView.init(frame: CGRectMake(0, 10, 184, 40))
  217. self.rightToolbarItemView.wantsLayer = true
  218. if self.rightMessageVC == nil {
  219. self.rightMessageVC = KMVerificationMessageViewController.init()
  220. }
  221. self.rightMessageVC.frameUpdateHandle = { [weak self] rect in
  222. var superRect = self?.rightToolbarItemView?.frame
  223. superRect?.size.width = (self?.rightMessageVC.view.frame.size.width)! + 8
  224. self?.rightToolbarItemView.frame = superRect!;
  225. }
  226. var rect = self.rightMessageVC.view.frame;
  227. rect.origin.x = CGRectGetWidth(self.rightToolbarItemView.frame) - rect.size.width - 8
  228. rect.origin.y = (CGRectGetHeight(self.rightToolbarItemView.frame) - rect.size.height)/2
  229. self.rightMessageVC.view.frame = rect
  230. self.rightMessageVC.view.autoresizingMask = [ .maxXMargin]
  231. self.rightToolbarItemView.addSubview(self.rightMessageVC.view)
  232. }
  233. return self.rightToolbarItemView
  234. }
  235. }
  236. override var homeRightStripView: NSView! {
  237. get {
  238. return homeRightTabStripView_
  239. }
  240. }
  241. // MARK: Button Action
  242. func commandDispatch(_ sender: Any) -> Void {
  243. var needShowChooseWindow = false
  244. //#if VERSION_FREE
  245. //#if VERSION_DMG
  246. if (!IAPProductsManager.default().isAvailableAllFunction()) {
  247. needShowChooseWindow = true
  248. }
  249. //#endif
  250. if needShowChooseWindow {
  251. let preferenceNoteShow = UserDefaults.standard.bool(forKey: KMTabbingHintShowFlag)
  252. if preferenceNoteShow {
  253. menuItemAction_newTagPageToNewWindow("")
  254. } else {
  255. let window = NSWindow.currentWindow()
  256. let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
  257. tabbingWin.selectCallBack = { continueOrNot in
  258. window.km_quick_endSheet()
  259. if continueOrNot {
  260. self.menuItemAction_newTagPageToNewWindow("")
  261. } else {
  262. }
  263. }
  264. window.km_beginSheet(windowC: tabbingWin)
  265. }
  266. } else {
  267. openDocumentWindow()
  268. }
  269. }
  270. func closeAllTabs(_ sender: Any) -> Void {
  271. if self.browser != nil {
  272. self.browser.closeAllTabs()
  273. }
  274. }
  275. func openNewWindow(_ sender: Any) -> Void {
  276. if let noti = sender as? NSNotification, noti.object is CTTabController {
  277. if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
  278. return
  279. }
  280. }
  281. if self.browser != nil {
  282. let activeInt = self.browser.activeTabIndex()
  283. let activeTab = self.browser.activeTabContents()
  284. self.browser.closeTab(at: activeInt, makeHistory: false)
  285. let browser: KMBrowser = KMBrowser.init()
  286. browser.windowController = KMBrowserWindowController.init(browser: browser)
  287. browser.addHomeTabContents()
  288. browser.windowController.showWindow(self)
  289. // browser.add(activeTab, inForeground: false)
  290. // browser.selectTab(at: 1)
  291. if activeTab?.fileURL == nil {
  292. return
  293. }
  294. let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
  295. let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
  296. KMMainDocument().tryToUnlockDocument(pdfDoc!)
  297. if ((pdfDoc?.isLocked)! == true) {
  298. KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
  299. if result == .cancel { /// 关闭
  300. return
  301. }
  302. /// 解密成功
  303. var selectDocument: KMMainDocument? = nil
  304. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  305. selectDocument = (document as! KMMainDocument)
  306. }
  307. if selectDocument != nil {
  308. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  309. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  310. if (selectDocument?.browser.window.isVisible)! as Bool {
  311. selectDocument?.browser.window.orderFront(nil)
  312. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  313. selectDocument?.browser.window.orderFront(nil)
  314. }
  315. } else {
  316. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, _, error in
  317. if (error == nil) {
  318. (document as! KMMainDocument).mainViewController?.password = password
  319. }
  320. }
  321. }
  322. }
  323. } else {
  324. var selectDocument: KMMainDocument? = nil
  325. if ((document?.isKind(of: KMMainDocument.self)) != nil) {
  326. selectDocument = (document as! KMMainDocument)
  327. }
  328. if selectDocument != nil {
  329. let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
  330. selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
  331. if (selectDocument?.browser.window.isVisible)! as Bool {
  332. selectDocument?.browser.window.orderFront(nil)
  333. } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
  334. selectDocument?.browser.window.orderFront(nil)
  335. }
  336. } else {
  337. NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
  338. }
  339. }
  340. }
  341. }
  342. }
  343. func canMergeAllWindow() -> Bool {
  344. return self.fetchBrowserWindowControllers().count > 0
  345. }
  346. fileprivate func fetchBrowserWindowControllers() -> [KMBrowserWindowController] {
  347. var windowArray: [KMBrowserWindowController] = []
  348. for window in NSApp.windows {
  349. guard let windowController = window.windowController, windowController is KMBrowserWindowController else {
  350. continue
  351. }
  352. if let _tabScripC = (windowController as? KMBrowserWindowController)?.tabStripController, _tabScripC.viewsCount() <= 1 {
  353. continue
  354. }
  355. if (window.isVisible && (windowController.isEqual(to: self) == false)) {
  356. windowArray.append(windowController as! KMBrowserWindowController)
  357. }
  358. }
  359. return windowArray
  360. }
  361. func mergeAllWindow(_ sender: Any) {
  362. let windowArray = self.fetchBrowserWindowControllers()
  363. if (windowArray.count <= 0) {
  364. return
  365. }
  366. for windowC in windowArray {
  367. // 拼接窗口 [拼接窗口里的标签,除了home标签]
  368. self.append(windowC, toTabView: NSView())
  369. if let browser = windowC.browser {
  370. if (browser.tabCount() <= 1 && browser.activeTabContents().isHome) {
  371. windowC.close()
  372. }
  373. }
  374. }
  375. }
  376. override func tabDidSelect(_ notification: Notification!) {
  377. super.tabDidSelect(notification)
  378. if let _userInfo = notification.userInfo, let _newContents = _userInfo[CTTabNewContentsUserInfoKey] as? KMMainDocument {
  379. _newContents.addWindowController(self)
  380. }
  381. }
  382. override func layoutTabContentArea(_ frame: NSRect) {
  383. super.layoutTabContentArea(frame)
  384. self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
  385. }
  386. override func openDocument(_ sender: Any!) {
  387. guard let _window = self.window else {
  388. KMPrint("openDocument error: window is nil.", beep: true)
  389. return
  390. }
  391. NSOpenPanel.km_open_multi_success(_window) { panel in
  392. panel.allowedFileTypes = KMTools.imageExtensions + KMTools.pdfExtensions
  393. } completion: { urls in
  394. var imageUrls: [URL] = []
  395. for url in urls {
  396. if KMTools.isPDFType(url.pathExtension.lowercased()) {
  397. NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
  398. }
  399. } else {
  400. imageUrls.append(url)
  401. }
  402. }
  403. if imageUrls.isEmpty == false {
  404. NSApplication.ShowImageToPDFWindow(urls: imageUrls)
  405. }
  406. }
  407. }
  408. }
  409. // MARK: - KMInterfaceThemeChangedProtocol
  410. extension KMBrowserWindowController: KMInterfaceThemeChangedProtocol {
  411. func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  412. Task { @MainActor in
  413. self.updateViewColor()
  414. let selector = #selector(interfaceThemeDidChanged)
  415. let mainWindow = self.window
  416. var responder = mainWindow?.firstResponder
  417. while (responder != nil) {
  418. // KMPrint("res: \(responder)")
  419. //
  420. if self.isEqual(to: responder) {
  421. responder = responder?.nextResponder
  422. continue
  423. }
  424. if let res = responder?.responds(to: selector), res {
  425. responder?.perform(selector, with: appearance)
  426. }
  427. responder = responder!.nextResponder
  428. }
  429. }
  430. }
  431. }
  432. // MARK: - KMToolbarRightViewDelegate
  433. extension KMBrowserWindowController: KMToolbarRightViewDelegate {
  434. func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
  435. self.trackEvent_upgrade()
  436. // KMComparativeTableViewController.show(window: self.window!, .upgrade)
  437. DispatchQueue.main.async {
  438. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  439. }
  440. }
  441. func userInfoButtonAction(_ sender: NSButton) {
  442. if KMLightMemberManager.manager.isLogin() {
  443. Task { @MainActor in
  444. if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
  445. KMAccountInfoWindowController.show(window: self.window!)
  446. } else {
  447. KMLoginWindowController.show(window: self.window!)
  448. }
  449. }
  450. } else {
  451. KMLoginWindowController.show(window: self.window!)
  452. }
  453. }
  454. func homeRefreshButtonAction(_ sender: NSButton?) {
  455. self.layoutSubviews()
  456. }
  457. func homeUploadButtonAction(_ sender: NSButton) {
  458. }
  459. func homeMenuSortAction(_ sender: NSPopUpButton) {
  460. }
  461. func homeMenuFilterAction(_ sender: NSPopUpButton) {
  462. }
  463. }
  464. // MARK: - KMUploadFileDelegate
  465. extension KMBrowserWindowController: KMUploadFileDelegate {
  466. // override func cancelOperation(_ sender: Any?) {
  467. //
  468. // }
  469. }
  470. // MARK: - NSSearchFieldDelegate
  471. extension KMBrowserWindowController: NSSearchFieldDelegate {
  472. func controlTextDidChange(_ obj: Notification) {
  473. }
  474. func controlTextDidEndEditing(_ obj: Notification) {
  475. }
  476. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  477. var result = false
  478. return result
  479. }
  480. }
  481. // MARK: -
  482. // MARK: Menu Actions
  483. extension KMBrowserWindowController {
  484. func canResponseDocumentAction() -> Bool {
  485. if (self.browser == nil) {
  486. return false
  487. }
  488. guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
  489. return false
  490. }
  491. return true
  492. }
  493. }
  494. // MARK: -
  495. // MARK: File Menu
  496. extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
  497. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  498. if (self.browser == nil) {
  499. return false
  500. }
  501. guard let action = menuItem.action else {
  502. return false
  503. }
  504. guard let document = self.browser.activeTabContents() as? KMMainDocument else {
  505. return false
  506. }
  507. if (KMSystemMenu.isFileSelector(sel: action)) {
  508. if (document.isHome) {
  509. if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
  510. menuItem.action == KMSystemMenu.File.propertySelector ||
  511. menuItem.action == KMSystemMenu.File.showInFinderSelector ||
  512. menuItem.action == KMSystemMenu.File.printSelector ||
  513. menuItem.action == KMSystemMenu.File.saveAsFlattenedPDFSelector) {
  514. return false
  515. }
  516. return document.homeViewController!.validateMenuItem(menuItem)
  517. } else {
  518. return document.mainViewController!.validateMenuItem(menuItem)
  519. }
  520. }
  521. if (KMSystemMenu.isEditSelector(sel: action)) {
  522. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  523. }
  524. if (KMSystemMenu.isViewSelector(sel: action)) {
  525. if action == KMSystemMenu.Edit.changeFontSelector {
  526. return true
  527. } else {
  528. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  529. }
  530. }
  531. if (KMSystemMenu.isAnnotationSelector(sel: action)) {
  532. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  533. }
  534. if (KMSystemMenu.isPDFSelector(sel: action)) {
  535. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  536. }
  537. if (KMSystemMenu.isGotoSelector(sel: action)) {
  538. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  539. }
  540. if (KMSystemMenu.isToolSelector(sel: action)) {
  541. if action == KMSystemMenu.Tool.orderFrontNotesPanelSelector {
  542. if KMNotesPanelController.sharedControllerExists() {
  543. if let data = KMNotesPanelController.shared.window?.isVisible, data {
  544. menuItem.title = NSLocalizedString("Hide Note Type", comment: "Menu item title")
  545. } else {
  546. menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
  547. }
  548. } else {
  549. menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
  550. }
  551. return true
  552. } else {
  553. return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
  554. }
  555. }
  556. if (KMSystemMenu.isWindowSelector(sel: action)) {
  557. return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
  558. }
  559. if action == #selector(redactAction) {
  560. return document.isHome ? false : true
  561. }
  562. return true
  563. }
  564. }
  565. extension KMBrowserWindowController {
  566. @IBAction func menuItemAction_openFile(_ sender: Any) {
  567. super.openDocument(sender)
  568. }
  569. @IBAction func importFromFile(_ sender: Any) {
  570. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  571. if (document.isHome) {
  572. document.homeViewController?.importFromFile(sender)
  573. } else {
  574. self.homeVC = KMHomeViewController()
  575. self.homeVC?.importFromFile(sender)
  576. }
  577. }
  578. @IBAction func openBlankPage(_ sender: Any) {
  579. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  580. if (document.isHome) {
  581. document.homeViewController?.openBlankPage()
  582. } else {
  583. self.homeVC = KMHomeViewController()
  584. self.homeVC?.openBlankPage()
  585. }
  586. }
  587. @IBAction func importFromScanner(_ sender: Any) {
  588. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  589. if (document.isHome) {
  590. document.homeViewController?.importFromScanner()
  591. } else {
  592. self.homeVC = KMHomeViewController()
  593. self.homeVC?.importFromScanner()
  594. }
  595. }
  596. @IBAction func menuItemAction_newTab(_ sender: Any) {
  597. self.openDocumentWindow()
  598. }
  599. @IBAction func pasteAsPlainText(_ sender: Any?) {
  600. KMPrint("pasteAsPlainText")
  601. }
  602. @IBAction func deselectAll(_ sender: Any?) {
  603. KMPrint("deselectAll")
  604. }
  605. @IBAction func searchPDF(_ sender: Any?) {
  606. KMPrint("searchPDF")
  607. if let document = self.browser.activeTabContents() as? KMMainDocument {
  608. if (document.isHome) {
  609. // document.homeViewController?.menuItemClick_mergePDF(sender)
  610. } else {
  611. document.mainViewController?.leftSideViewController.showSearchMode("")
  612. }
  613. }
  614. }
  615. @IBAction func changeColor(_ sender: Any?) {
  616. KMPrint("changeColor ...")
  617. }
  618. @IBAction func changeAttributes(_ sender: Any?) {
  619. KMPrint("changeAttributes ...")
  620. }
  621. @IBAction func alignLeft(_ sender: Any?) {
  622. KMPrint("alignLeft ...")
  623. }
  624. @IBAction func alignRight(_ sender: Any?) {
  625. KMPrint("alignRight ...")
  626. }
  627. @IBAction func alignCenter(_ sender: Any?) {
  628. KMPrint("alignCenter ...")
  629. }
  630. @IBAction func createNewNote(_ sender: Any?) {
  631. KMPrint("createNewNote ...")
  632. }
  633. @IBAction func toggleHideNotes(_ sender: Any?) {
  634. KMPrint("toggleHideNotes ...")
  635. }
  636. @IBAction func changeDisplaySinglePages(_ sender: Any?) {
  637. KMPrint("changeDisplaySinglePages ...")
  638. }
  639. @IBAction func changeDisplayContinuous(_ sender: Any?) {
  640. KMPrint("changeDisplayContinuous ...")
  641. }
  642. @IBAction func doGoToNextPage(_ sender: Any?) {
  643. KMPrint("doGoToNextPage ...")
  644. }
  645. @IBAction func doGoToPreviousPage(_ sender: Any?) {
  646. KMPrint("doGoToPreviousPage ...")
  647. }
  648. @IBAction func doGoToFirstPage(_ sender: Any?) {
  649. KMPrint("doGoToFirstPage ...")
  650. }
  651. @IBAction func doGoToLastPage(_ sender: Any?) {
  652. KMPrint("doGoToLastPage ...")
  653. }
  654. @IBAction func allGoToNextPage(_ sender: Any?) {
  655. KMPrint("allGoToNextPage ...")
  656. }
  657. @IBAction func allGoToPreviousPage(_ sender: Any?) {
  658. KMPrint("allGoToPreviousPage ...")
  659. }
  660. @IBAction func allGoToFirstPage(_ sender: Any?) {
  661. KMPrint("allGoToFirstPage ...")
  662. }
  663. @IBAction func allGoToLastPage(_ sender: Any?) {
  664. KMPrint("allGoToLastPage ...")
  665. }
  666. @IBAction func doGoToPage(_ sender: Any?) {
  667. KMPrint("doGoToPage ...")
  668. }
  669. @IBAction func doGoBack(_ sender: Any?) {
  670. KMPrint("doGoBack ...")
  671. }
  672. @IBAction func doGoForward(_ sender: Any?) {
  673. KMPrint("doGoForward ...")
  674. }
  675. @IBAction func doZoomToPhysicalSize(_ sender: Any?) {
  676. KMPrint("doZoomToPhysicalSize ...")
  677. }
  678. @IBAction func alternateZoomToFit(_ sender: Any?) {
  679. KMPrint("alternateZoomToFit ...")
  680. }
  681. @IBAction func doZoomToSelection(_ sender: Any?) {
  682. KMPrint("doZoomToSelection ...")
  683. }
  684. @IBAction func doAutoScale(_ sender: Any?) {
  685. KMPrint("doAutoScale ...")
  686. }
  687. // @IBAction func delete(_ sender: Any?) {
  688. // KMPrint("delete ...")
  689. // }
  690. // @IBAction func paste(_ sender: Any?) {
  691. // KMPrint("paste ...")
  692. // }
  693. @IBAction func alternatePaste(_ sender: Any?) {
  694. KMPrint("alternatePaste ...")
  695. }
  696. @IBAction func copy(_ sender: Any?) {
  697. KMPrint("copy ...")
  698. }
  699. @IBAction func cut(_ sender: Any?) {
  700. KMPrint("cut ...")
  701. }
  702. @IBAction func toggleFullscreen(_ sender: Any?) {
  703. KMPrint("toggleFullscreen ...")
  704. }
  705. @IBAction func toggleRightSidePane(_ sender: Any?) {
  706. KMPrint("toggleRightSidePane ...")
  707. }
  708. @IBAction func changeRightSidePaneState(_ sender: Any?) {
  709. KMPrint("changeRightSidePaneState ...")
  710. }
  711. @IBAction func changeFindPaneState(_ sender: Any?) {
  712. KMPrint("changeFindPaneState ...")
  713. }
  714. @IBAction func toggleSplitPDF(_ sender: Any?) {
  715. KMPrint("toggleSplitPDF ...")
  716. }
  717. @IBAction func search(_ sender: Any?) {
  718. KMPrint("search ...")
  719. }
  720. @IBAction func searchNotes(_ sender: Any?) {
  721. KMPrint("searchNotes ...")
  722. }
  723. @IBAction func password(_ sender: Any?) {
  724. KMPrint("password ...")
  725. }
  726. @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
  727. KMPrint("toggleCaseInsensitiveSearch ...")
  728. }
  729. @IBAction func toggleWholeWordSearch(_ sender: Any?) {
  730. KMPrint("toggleWholeWordSearch ...")
  731. }
  732. @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
  733. KMPrint("toggleCaseInsensitiveNoteSearch ...")
  734. }
  735. @IBAction func performFindPanelAction(_ sender: NSMenuItem) {
  736. KMPrint("performFindPanelAction ...")
  737. var forward = true
  738. var findString: String?
  739. switch sender.tag {
  740. case 1:
  741. if let document = self.browser.activeTabContents() as? KMMainDocument {
  742. if document.isHome == false {
  743. document.mainViewController?.toolbarController.showFindBar()
  744. }
  745. }
  746. case 3:
  747. if let document = self.browser.activeTabContents() as? KMMainDocument {
  748. if document.isHome == false {
  749. document.mainViewController?.toolbarController.showFindString(forward: false)
  750. }
  751. }
  752. case 2:
  753. if let document = self.browser.activeTabContents() as? KMMainDocument {
  754. if document.isHome == false {
  755. document.mainViewController?.toolbarController.showFindString(forward: true)
  756. }
  757. }
  758. case 7:
  759. if let document = self.browser.activeTabContents() as? KMMainDocument {
  760. if document.isHome == false {
  761. document.mainViewController?.toolbarController.showAllAction()
  762. }
  763. }
  764. default: break
  765. }
  766. }
  767. @IBAction func scrollUp(_ sender: Any?) {
  768. KMPrint("scrollUp ...")
  769. }
  770. @IBAction func scrollDown(_ sender: Any?) {
  771. KMPrint("scrollDown ...")
  772. }
  773. @IBAction func scrollRight(_ sender: Any?) {
  774. KMPrint("scrollRight ...")
  775. }
  776. @IBAction func scrollLeft(_ sender: Any?) {
  777. KMPrint("scrollLeft ...")
  778. }
  779. @IBAction func selectSelectedNote(_ sender: Any?) {
  780. KMPrint("selectSelectedNote ...")
  781. }
  782. @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
  783. KMPrint("goToSelectedOutlineItem ...")
  784. }
  785. @IBAction func goToSelectedFindResults(_ sender: Any?) {
  786. KMPrint("goToSelectedFindResults ...")
  787. }
  788. @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
  789. KMPrint("toggleSelectedSnapshots ...")
  790. }
  791. @IBAction func selfSignProfile(_ sender: Any?) {
  792. KMPrint("selfSignProfile ...")
  793. }
  794. @IBAction func link(_ sender: Any?) {
  795. KMPrint("link ...")
  796. }
  797. @IBAction func insertPage(_ sender: Any?) {
  798. KMPrint("insertPage ...")
  799. }
  800. @IBAction func split(_ sender: Any?) {
  801. KMPrint("split ...")
  802. }
  803. @IBAction func comparison(_ sender: Any?) {
  804. KMPrint("comparison ...")
  805. }
  806. @IBAction func contentComparison(_ sender: Any?) {
  807. KMPrint("contentComparison ...")
  808. }
  809. @IBAction func coverageComparison(_ sender: Any?) {
  810. KMPrint("coverageComparison ...")
  811. }
  812. @IBAction func readMode(_ sender: Any?) {
  813. KMPrint("readMode ...")
  814. }
  815. @IBAction func changeFormType(_ sender: Any?) {
  816. KMPrint("changeFormType ...")
  817. }
  818. @IBAction func changeSelfSignType(_ sender: Any?) {
  819. KMPrint("changeSelfSignType ...")
  820. }
  821. @IBAction func clearAllForm(_ sender: Any?) {
  822. KMPrint("clearAllForm ...")
  823. }
  824. @IBAction func thumbnailSizeScaling(_ sender: Any?) {
  825. KMPrint("thumbnailSizeScaling ...")
  826. }
  827. @IBAction func redactAction(_ sender: Any?) {
  828. if (self.canResponseDocumentAction() == false) {
  829. return
  830. }
  831. if let document = self.browser.activeTabContents() as? KMMainDocument {
  832. if document.isHome == false {
  833. document.mainViewController?.menuItemAction_redact(sender)
  834. }
  835. }
  836. }
  837. }
  838. // MARK: - KMSystemFileMenuProtocol
  839. extension KMBrowserWindowController: KMSystemFileMenuProtocol {
  840. func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  841. if (self.canResponseDocumentAction() == false) {
  842. return
  843. }
  844. if let document = self.browser.activeTabContents() as? KMMainDocument {
  845. if (document.isHome) {
  846. // document.homeViewController?.menuItemClick_mergePDF(sender)
  847. } else {
  848. document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
  849. }
  850. }
  851. }
  852. func menuItemClick_mergePDF(_ sender: Any) {
  853. if (self.canResponseDocumentAction() == false) {
  854. return
  855. }
  856. if let document = self.browser.activeTabContents() as? KMMainDocument {
  857. if (document.isHome) {
  858. document.homeViewController?.menuItemClick_mergePDF(sender)
  859. } else {
  860. document.mainViewController?.menuItemClick_mergePDF(sender)
  861. }
  862. }
  863. }
  864. func menuItemClick_Compress(_ sender: Any) {
  865. if (self.canResponseDocumentAction() == false) {
  866. return
  867. }
  868. if let document = self.browser.activeTabContents() as? KMMainDocument {
  869. if (document.isHome) {
  870. document.homeViewController?.menuItemClick_Compress(sender)
  871. } else {
  872. document.mainViewController?.menuItemClick_Compress(sender)
  873. }
  874. }
  875. }
  876. func menuItemAction_ConvertToWord(_ sender: Any) {
  877. if (self.canResponseDocumentAction() == false) {
  878. return
  879. }
  880. if let document = self.browser.activeTabContents() as? KMMainDocument {
  881. if (document.isHome) {
  882. document.homeViewController?.menuItemAction_ConvertToWord(sender)
  883. } else {
  884. document.mainViewController?.menuItemAction_ConvertToWord(sender)
  885. }
  886. }
  887. }
  888. func menuItemAction_ConvertToExcel(_ sender: Any) {
  889. if (self.canResponseDocumentAction() == false) {
  890. return
  891. }
  892. if let document = self.browser.activeTabContents() as? KMMainDocument {
  893. if (document.isHome) {
  894. document.homeViewController?.menuItemAction_ConvertToExcel(sender)
  895. } else {
  896. document.mainViewController?.menuItemAction_ConvertToExcel(sender)
  897. }
  898. }
  899. }
  900. func menuItemAction_ConvertToPPT(_ sender: Any) {
  901. if (self.canResponseDocumentAction() == false) {
  902. return
  903. }
  904. if let document = self.browser.activeTabContents() as? KMMainDocument {
  905. if (document.isHome) {
  906. document.homeViewController?.menuItemAction_ConvertToPPT(sender)
  907. } else {
  908. document.mainViewController?.menuItemAction_ConvertToPPT(sender)
  909. }
  910. }
  911. }
  912. func menuItemAction_ConvertToRTF(_ sender: Any) {
  913. if (self.canResponseDocumentAction() == false) {
  914. return
  915. }
  916. if let document = self.browser.activeTabContents() as? KMMainDocument {
  917. if (document.isHome) {
  918. document.homeViewController?.menuItemAction_ConvertToRTF(sender)
  919. } else {
  920. document.mainViewController?.menuItemAction_ConvertToRTF(sender)
  921. }
  922. }
  923. }
  924. func menuItemAction_ConvertToHTML(_ sender: Any) {
  925. if (self.canResponseDocumentAction() == false) {
  926. return
  927. }
  928. if let document = self.browser.activeTabContents() as? KMMainDocument {
  929. if (document.isHome) {
  930. document.homeViewController?.menuItemAction_ConvertToHTML(sender)
  931. } else {
  932. document.mainViewController?.menuItemAction_ConvertToHTML(sender)
  933. }
  934. }
  935. }
  936. func menuItemAction_ConvertToText(_ sender: Any) {
  937. if (self.canResponseDocumentAction() == false) {
  938. return
  939. }
  940. if let document = self.browser.activeTabContents() as? KMMainDocument {
  941. if (document.isHome) {
  942. document.homeViewController?.menuItemAction_ConvertToText(sender)
  943. } else {
  944. document.mainViewController?.menuItemAction_ConvertToText(sender)
  945. }
  946. }
  947. }
  948. func menuItemAction_ConvertToCSV(_ sender: Any) {
  949. if (self.canResponseDocumentAction() == false) {
  950. return
  951. }
  952. if let document = self.browser.activeTabContents() as? KMMainDocument {
  953. if (document.isHome) {
  954. document.homeViewController?.menuItemAction_ConvertToCSV(sender)
  955. } else {
  956. document.mainViewController?.menuItemAction_ConvertToCSV(sender)
  957. }
  958. }
  959. }
  960. func menuItemAction_ConvertToImage(_ sender: Any) {
  961. if (self.canResponseDocumentAction() == false) {
  962. return
  963. }
  964. if let document = self.browser.activeTabContents() as? KMMainDocument {
  965. if (document.isHome) {
  966. document.homeViewController?.menuItemAction_ConvertToImage(sender)
  967. } else {
  968. document.mainViewController?.menuItemAction_ConvertToImage(sender)
  969. }
  970. }
  971. }
  972. func menuItemClick_SettingPassword(_ sender: Any) {
  973. if (self.canResponseDocumentAction() == false) {
  974. return
  975. }
  976. if let document = self.browser.activeTabContents() as? KMMainDocument {
  977. if (document.isHome) {
  978. document.homeViewController?.menuItemClick_SettingPassword(sender)
  979. } else {
  980. document.mainViewController?.menuItemClick_SettingPassword(sender)
  981. }
  982. }
  983. }
  984. func menuItemClick_RemovePassword(_ sender: Any) {
  985. if (self.canResponseDocumentAction() == false) {
  986. return
  987. }
  988. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  989. document.mainViewController?.menuItemClick_RemovePassword(sender)
  990. }
  991. }
  992. func menuItemAction_closeWindow(_ sender: Any) {
  993. if (self.canResponseDocumentAction() == false) {
  994. return
  995. }
  996. if let document = self.browser.activeTabContents() as? KMMainDocument {
  997. if (document.isHome) {
  998. document.homeViewController?.menuItemAction_closeWindow(sender)
  999. } else {
  1000. document.mainViewController?.menuItemAction_closeWindow(sender)
  1001. }
  1002. }
  1003. }
  1004. func menuItemAction_closeAllWindows(_ sender: Any) {
  1005. if (self.canResponseDocumentAction() == false) {
  1006. return
  1007. }
  1008. if let document = self.browser.activeTabContents() as? KMMainDocument {
  1009. if (document.isHome) {
  1010. document.homeViewController?.menuItemAction_closeAllWindows(sender)
  1011. } else {
  1012. document.mainViewController?.menuItemAction_closeAllWindows(sender)
  1013. }
  1014. }
  1015. }
  1016. func menuItemAction_closeTagPage(_ sender: Any) {
  1017. if (self.canResponseDocumentAction() == false) {
  1018. return
  1019. }
  1020. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1021. document.mainViewController?.menuItemAction_closeTagPage(sender)
  1022. }
  1023. }
  1024. func menuItemAction_showInFinder(_ sender: Any) {
  1025. if (self.canResponseDocumentAction() == false) {
  1026. return
  1027. }
  1028. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1029. document.mainViewController?.menuItemAction_showInFinder(sender)
  1030. }
  1031. }
  1032. func menuItemAction_property(_ sender: Any) {
  1033. if (self.canResponseDocumentAction() == false) {
  1034. return
  1035. }
  1036. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1037. document.mainViewController?.menuItemAction_property(sender)
  1038. }
  1039. }
  1040. func menuItemAction_print(_ sender: Any) {
  1041. if (self.canResponseDocumentAction() == false) {
  1042. return
  1043. }
  1044. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1045. document.mainViewController?.menuItemAction_print(sender)
  1046. }
  1047. }
  1048. func isEncapsulatedPostScriptData(_ data: Data) -> Bool {
  1049. let epsHeaderData = Data(bytes: [69, 80, 83, 70, 45], count: 5)
  1050. let rg: Range = (14..<20)
  1051. return (data.count >= 20 && (data.range(of: epsHeaderData, options: .anchored, in: rg) != nil))
  1052. }
  1053. func convertTIFFDataToPDF(_ tiffData: Data) -> Data? {
  1054. guard let imsrc = CGImageSourceCreateWithData(tiffData as CFData, [kCGImageSourceTypeIdentifierHint: kUTTypeTIFF] as CFDictionary), CGImageSourceGetCount(imsrc) > 0, let cgImage = CGImageSourceCreateImageAtIndex(imsrc, 0, nil) else { return nil }
  1055. let pdfData = NSMutableData(capacity: tiffData.count)
  1056. let consumer = CGDataConsumer(data: pdfData! as CFMutableData)!
  1057. var rect = CGRect(x: 0, y: 0, width: CGFloat(cgImage.width), height: CGFloat(cgImage.height))
  1058. let ctxt = CGContext(consumer: consumer, mediaBox: &rect, nil)
  1059. ctxt!.beginPDFPage(nil)
  1060. ctxt!.draw(cgImage, in: rect)
  1061. ctxt!.endPDFPage()
  1062. ctxt!.flush()
  1063. return pdfData as? Data
  1064. }
  1065. func openDocumentWithImageFromPasteboard(_ pboard: NSPasteboard, error outError: AutoreleasingUnsafeMutablePointer<NSError?>?) -> Any? {
  1066. var document: CPDFDocument? = nil
  1067. var data: Data? = nil
  1068. if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.pdf.rawValue]) {
  1069. // pboard.types
  1070. data = pboard.data(forType: NSPasteboard.PasteboardType.pdf)
  1071. } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.postScript.rawValue]) {
  1072. // pboard.types
  1073. data = pboard.data(forType: NSPasteboard.PasteboardType.postScript)
  1074. } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.tiff.rawValue]) {
  1075. // pboard.types
  1076. data = convertTIFFDataToPDF(pboard.data(forType: NSPasteboard.PasteboardType.tiff) ?? Data())
  1077. } else {
  1078. let images = pboard.readObjects(forClasses: [NSImage.self], options: [:])
  1079. let strings = pboard.readObjects(forClasses: [NSAttributedString.self], options: [:])
  1080. if images?.count ?? 0 > 0 {
  1081. data = convertTIFFDataToPDF((images![0] as AnyObject).tiffRepresentation!)
  1082. } else if strings?.count ?? 0 > 0 {
  1083. data = KMOCTool.convertStringsToPDF(withString: strings ?? [""]) // convertStringsToPDF(strings!)
  1084. }
  1085. }
  1086. if let data = data {
  1087. _ = NSDocumentController.shared
  1088. document = CPDFDocument(data: data)
  1089. let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
  1090. let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
  1091. let filePath = savePath.deletingLastPathComponent
  1092. if FileManager.default.fileExists(atPath: filePath) == false {
  1093. try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
  1094. }
  1095. document?.write(to: URL(fileURLWithPath: savePath))
  1096. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
  1097. if error != nil {
  1098. NSApp.presentError(error!)
  1099. } else {
  1100. if document is KMMainDocument {
  1101. let newDocument = document
  1102. (newDocument as! KMMainDocument).isNewCreated = true
  1103. }
  1104. }
  1105. }
  1106. } else if let outError = outError {
  1107. outError.pointee = NSError(domain: "SKDocumentErrorDomain", code: 3, userInfo: [NSLocalizedDescriptionKey: NSLocalizedString("Unable to load data from clipboard", comment: "Error description")])
  1108. }
  1109. return document
  1110. }
  1111. func openDocument(withURLFromPasteboard pboard: NSPasteboard, showNotes: Bool, error outError: inout NSError?) -> Any? {
  1112. let theURLs = NSURL.readURLs(from: pboard)
  1113. let url = theURLs?.count ?? 0 > 0 ? theURLs?[0] : nil
  1114. let theURL: NSURL? = url as? NSURL
  1115. var documentC = NSDocumentController.shared
  1116. var document: NSDocument? = nil
  1117. if (theURL as AnyObject).isFileURL == true {
  1118. var _: NSError? = nil
  1119. let type = try? documentC.typeForContents(of: theURL as! URL)//ForContents(ofURL: theURL, error: &error)
  1120. if showNotes == false || NSDocument.readableTypes.contains(type ?? "") {
  1121. documentC.openDocument(withContentsOf: theURL as! URL, display: true, completionHandler: { resultDocument, success, err in
  1122. document = resultDocument
  1123. })//openDocument(withContentsOfURL: theURL, display: true, error: &outError)
  1124. } else if NSDocument.readableTypes.contains(type ?? "") {
  1125. for doc in documentC.documents {
  1126. let sel = NSSelectorFromString("sourceFileURL")
  1127. if doc.responds(to: sel) && doc.fileURL == theURL as? URL {
  1128. document = doc
  1129. break
  1130. }
  1131. }
  1132. if let document: NSDocument = document {
  1133. document.showWindows()
  1134. } else {
  1135. var data: Data? = nil
  1136. // if NSWorkspace.shared.type(type ?? "", conformsToType: KMPDFBundleDocumentType) {
  1137. // let skimFileURL = FileManager.default.exte
  1138. // data = skimFileURL != nil ? try? Data(contentsOf: skimFileURL!) : nil
  1139. // } else {
  1140. // data = SKNExtendedAttributeManager.shared().extendedAttributeNamed(SKIM_NOTES_KEY, atPath: theURL.path, traverseLink: true, error: &error)
  1141. // }
  1142. // let documentNew: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  1143. if let document = try? documentC.makeUntitledDocument(ofType: KMNotesDocumentType) {
  1144. document.fileURL = URL(fileURLWithPath: theURL?.path ?? "")
  1145. // if data == nil || document.read(fromData: data!, ofType: SKNotesDocumentType, error: &error) {
  1146. documentC.addDocument(document)
  1147. document.makeWindowControllers()
  1148. document.showWindows()
  1149. // } else {
  1150. // document = nil
  1151. // if let error = error {
  1152. // outError = error
  1153. // }
  1154. // }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. // else if showNotes == false && theURL != nil {
  1160. // document = SKDownloadController.shared().addDownload(for: theURL!)
  1161. // } else if outError != nil {
  1162. // outError = NSError.readPasteboardError(withLocalizedDescription: NSLocalizedString("Unable to load data from clipboard", comment: "Error description"))
  1163. // }
  1164. return document
  1165. }
  1166. @IBAction func newDocumentFromClipboard(_ sender: Any?) {
  1167. KMPrint("newDocumentFromClipboard")
  1168. var error: NSError?
  1169. let pboard = NSPasteboard.general
  1170. var document = openDocumentWithImageFromPasteboard(pboard, error: &error)
  1171. if document == nil{
  1172. document = openDocument(withURLFromPasteboard: pboard, showNotes: false, error: &error)
  1173. }
  1174. }
  1175. @IBAction func newDocumentFromImage(_ sender: Any?) {
  1176. KMPrint("importFromWebPage")
  1177. createPDFFromImage()
  1178. }
  1179. @IBAction func importFromWebPage(_ sender: Any?) {
  1180. let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
  1181. if (document.isHome) {
  1182. document.homeViewController?.importFromWebPage()
  1183. } else {
  1184. self.homeVC = KMHomeViewController()
  1185. self.homeVC?.importFromWebPage()
  1186. }
  1187. }
  1188. @IBAction func screenShot_SelectArea(_ sender: Any?) {
  1189. KMScreenShotHandler.beginScreenshot_SelectRectWithCompleteHandler { ima in
  1190. if let image = ima {
  1191. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1192. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1193. let newDocument = CPDFDocument()
  1194. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1195. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1196. if writeSuccess ?? false {
  1197. self.savePdf(savePath)
  1198. // try? FileManager.default.removeItem(atPath: savePath)
  1199. } else {
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. @IBAction func screenShot_Window(_ sender: Any?) {
  1206. KMPrint("screenShot_Window")
  1207. KMScreenShotHandler.beginScreenShot_SelectWindowCompleteHandler { ima in
  1208. if let image = ima {
  1209. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1210. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1211. let newDocument = CPDFDocument()
  1212. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1213. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1214. if writeSuccess == true {
  1215. self.savePdf(savePath)
  1216. // try? FileManager.default.removeItem(atPath: savePath)
  1217. } else {
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  1224. KMPrint("screenShot_FullScreenDelay")
  1225. KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(3) { ima in
  1226. if let image = ima {
  1227. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1228. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1229. let newDocument = CPDFDocument()
  1230. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1231. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1232. if writeSuccess == true {
  1233. self.savePdf(savePath)
  1234. // try? FileManager.default.removeItem(atPath: savePath)
  1235. } else {
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  1242. KMPrint("screenShot_FullScreen")
  1243. KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(0) { ima in
  1244. if let image = ima {
  1245. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1246. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1247. let newDocument = CPDFDocument()
  1248. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1249. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1250. if writeSuccess == true {
  1251. self.savePdf(savePath)
  1252. // try? FileManager.default.removeItem(atPath: savePath)
  1253. } else {
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. // MARK: - KMSystemViewMenuProtocol
  1261. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  1262. func createPDFFromImage() {
  1263. let openPanel = NSOpenPanel()
  1264. openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
  1265. openPanel.allowsMultipleSelection = true
  1266. openPanel.message = NSLocalizedString("Select images to create a new document. To select multiple files press cmd ⌘ button on keyboard and click on the target files one by one.", comment: "")
  1267. openPanel.beginSheetModal(for: NSApp.mainWindow!) { response in
  1268. if response == .OK {
  1269. self.creatPdfFromImg(urls: openPanel.urls)
  1270. }
  1271. }
  1272. }
  1273. func creatPdfFromImg(urls: Array<URL>) {
  1274. // let savePath = self.newDocumentTempSavePath("convertToPDF.pdf")
  1275. let pdf = CPDFDocument()
  1276. // var isSucceed = true
  1277. let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
  1278. let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
  1279. let filePath = savePath.deletingLastPathComponent
  1280. if FileManager.default.fileExists(atPath: filePath) == false {
  1281. try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
  1282. }
  1283. for fileURL in urls {
  1284. if let imag = NSImage(contentsOfFile: fileURL.path ) {
  1285. _ = pdf?.km_insertPage(imag.size, withImage: fileURL.path , at: pdf?.pageCount ?? 0)
  1286. pdf?.write(to: URL(fileURLWithPath: savePath))
  1287. }
  1288. }
  1289. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
  1290. if error != nil {
  1291. NSApp.presentError(error!)
  1292. } else {
  1293. if document is KMMainDocument {
  1294. let newDocument = document
  1295. (newDocument as! KMMainDocument).isNewCreated = true
  1296. }
  1297. }
  1298. // self.homeContentView?.reloadData()
  1299. }
  1300. }
  1301. func createPdfWithParam() {
  1302. let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
  1303. let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
  1304. let filePath = savePath.deletingLastPathComponent
  1305. if FileManager.default.fileExists(atPath: filePath) == false {
  1306. try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
  1307. }
  1308. let pdfDocument = CPDFDocument()
  1309. pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
  1310. pdfDocument?.write(to: URL(fileURLWithPath: savePath))
  1311. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
  1312. if error != nil {
  1313. NSApp.presentError(error!)
  1314. } else {
  1315. if document is KMMainDocument {
  1316. let newDocument = document
  1317. (newDocument as! KMMainDocument).isNewCreated = true
  1318. }
  1319. }
  1320. // self.homeContentView?.reloadData()
  1321. }
  1322. }
  1323. func savePdf(_ filePath: String) -> Void {
  1324. let docVc = KMDocumentController.shared
  1325. docVc.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
  1326. if error != nil {
  1327. NSApp.presentError(error!)
  1328. } else {
  1329. if document is KMMainDocument {
  1330. let newDocument = document
  1331. (newDocument as! KMMainDocument).isNewCreated = true
  1332. }
  1333. }
  1334. }
  1335. }
  1336. func newDocumentTempSavePath(_ fileName: String) -> String {
  1337. let searchPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last
  1338. let append1 = searchPath?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!)
  1339. let append2 = append1!.stringByAppendingPathComponent(String(format: "%@", fileName))
  1340. return append2
  1341. }
  1342. func fetchUniquePath(_ originalPath: String) -> String {
  1343. var path = originalPath
  1344. let dManager = FileManager.default
  1345. if !dManager.fileExists(atPath: path) {
  1346. if path.extension.count < 1 {
  1347. path = path.stringByAppendingPathExtension("pdf")
  1348. }
  1349. return path
  1350. } else {
  1351. let originalFullFileName = path.lastPathComponent
  1352. let originalFileName = path.lastPathComponent.deletingPathExtension
  1353. let originalExtension = path.extension
  1354. let startIndex: Int = 0
  1355. let endIndex: Int = startIndex + originalPath.count - originalFullFileName.count - 1
  1356. let fileLocatePath = originalPath.substring(to: endIndex)
  1357. var i = 1
  1358. while (1 != 0) {
  1359. var newName = String(format: "%@%ld", originalFileName, i)
  1360. newName = newName.stringByAppendingPathExtension(originalExtension)
  1361. let newPath = fileLocatePath.stringByAppendingPathComponent(newName)
  1362. if !dManager.fileExists(atPath: newPath) {
  1363. return newPath
  1364. } else {
  1365. i+=1
  1366. continue
  1367. }
  1368. }
  1369. }
  1370. }
  1371. func menuItemAction_adjustWidth(_ sender: Any) {
  1372. if (self.canResponseDocumentAction() == false) {
  1373. return
  1374. }
  1375. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1376. document.mainViewController?.menuItemAction_adjustWidth(sender)
  1377. }
  1378. }
  1379. func menuItemAction_adjustPage(_ sender: Any) {
  1380. if (self.canResponseDocumentAction() == false) {
  1381. return
  1382. }
  1383. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1384. document.mainViewController?.menuItemAction_adjustPage(sender)
  1385. }
  1386. }
  1387. func menuItemAction_size(_ sender: Any) {
  1388. if (self.canResponseDocumentAction() == false) {
  1389. return
  1390. }
  1391. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1392. document.mainViewController?.menuItemAction_size(sender)
  1393. }
  1394. }
  1395. func menuItemAction_zoomOut(_ sender: Any) {
  1396. if (self.canResponseDocumentAction() == false) {
  1397. return
  1398. }
  1399. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1400. document.mainViewController?.menuItemAction_zoomOut(sender)
  1401. }
  1402. }
  1403. func menuItemAction_zoomIn(_ sender: Any) {
  1404. if (self.canResponseDocumentAction() == false) {
  1405. return
  1406. }
  1407. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1408. document.mainViewController?.menuItemAction_zoomIn(sender)
  1409. }
  1410. }
  1411. func menuItemAction_singlePage(_ sender: Any) {
  1412. if (self.canResponseDocumentAction() == false) {
  1413. return
  1414. }
  1415. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1416. document.mainViewController?.menuItemAction_singlePage(sender)
  1417. }
  1418. }
  1419. func menuItemAction_singlePageContinue(_ sender: Any) {
  1420. if (self.canResponseDocumentAction() == false) {
  1421. return
  1422. }
  1423. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1424. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1425. }
  1426. }
  1427. func menuItemAction_doublePage(_ sender: Any) {
  1428. if (self.canResponseDocumentAction() == false) {
  1429. return
  1430. }
  1431. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1432. document.mainViewController?.menuItemAction_doublePage(sender)
  1433. }
  1434. }
  1435. func menuItemAction_doublePageContinue(_ sender: Any) {
  1436. if (self.canResponseDocumentAction() == false) {
  1437. return
  1438. }
  1439. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1440. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1441. }
  1442. }
  1443. func menuItemAction_bookMode(_ sender: Any) {
  1444. if (self.canResponseDocumentAction() == false) {
  1445. return
  1446. }
  1447. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1448. document.mainViewController?.menuItemAction_bookMode(sender)
  1449. }
  1450. }
  1451. func menuItemAction_readMode(_ sender: Any) {
  1452. if (self.canResponseDocumentAction() == false) {
  1453. return
  1454. }
  1455. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1456. document.mainViewController?.menuItemAction_readMode(sender)
  1457. }
  1458. }
  1459. func menuItemAction_showSplitPage(_ sender: Any) {
  1460. if (self.canResponseDocumentAction() == false) {
  1461. return
  1462. }
  1463. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1464. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1465. }
  1466. }
  1467. func menuItemAction_rotateLeft(_ sender: Any) {
  1468. if (self.canResponseDocumentAction() == false) {
  1469. return
  1470. }
  1471. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1472. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1473. }
  1474. }
  1475. func menuItemAction_rotateRight(_ sender: Any) {
  1476. if (self.canResponseDocumentAction() == false) {
  1477. return
  1478. }
  1479. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1480. document.mainViewController?.menuItemAction_rotateRight(sender)
  1481. }
  1482. }
  1483. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1484. if (self.canResponseDocumentAction() == false) {
  1485. return
  1486. }
  1487. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1488. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1489. }
  1490. }
  1491. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1492. if (self.canResponseDocumentAction() == false) {
  1493. return
  1494. }
  1495. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1496. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1497. }
  1498. }
  1499. func menuItemAction_view_readMode(_ sender: Any) {
  1500. if (self.canResponseDocumentAction() == false) {
  1501. return
  1502. }
  1503. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1504. document.mainViewController?.menuItemAction_view_readMode(sender)
  1505. }
  1506. }
  1507. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1508. if (self.canResponseDocumentAction() == false) {
  1509. return
  1510. }
  1511. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1512. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1513. }
  1514. }
  1515. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1516. if (self.canResponseDocumentAction() == false) {
  1517. return
  1518. }
  1519. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1520. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1521. }
  1522. }
  1523. func menuItemAction_thumai(_ sender: Any) {
  1524. if (self.canResponseDocumentAction() == false) {
  1525. return
  1526. }
  1527. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1528. document.mainViewController?.menuItemAction_thumai(sender)
  1529. }
  1530. }
  1531. func menuItemAction_outline(_ sender: Any) {
  1532. if (self.canResponseDocumentAction() == false) {
  1533. return
  1534. }
  1535. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1536. document.mainViewController?.menuItemAction_outline(sender)
  1537. }
  1538. }
  1539. func menuItemAction_bookmark(_ sender: Any) {
  1540. if (self.canResponseDocumentAction() == false) {
  1541. return
  1542. }
  1543. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1544. document.mainViewController?.menuItemAction_bookmark(sender)
  1545. }
  1546. }
  1547. func menuItemAction_annotation(_ sender: Any) {
  1548. if (self.canResponseDocumentAction() == false) {
  1549. return
  1550. }
  1551. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1552. document.mainViewController?.menuItemAction_annotation(sender)
  1553. }
  1554. }
  1555. func menuItemAction_search(_ sender: Any) {
  1556. if (self.canResponseDocumentAction() == false) {
  1557. return
  1558. }
  1559. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1560. document.mainViewController?.menuItemAction_search(sender)
  1561. }
  1562. }
  1563. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1564. if (self.canResponseDocumentAction() == false) {
  1565. return
  1566. }
  1567. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1568. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1569. }
  1570. }
  1571. @IBAction func togglePresentation(_ sender: Any?) {
  1572. if (self.canResponseDocumentAction() == false) {
  1573. return
  1574. }
  1575. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1576. document.mainViewController?.togglePresentation(sender)
  1577. }
  1578. }
  1579. @IBAction func chooseTransition(_ sender: Any?) {
  1580. if (self.canResponseDocumentAction() == false) {
  1581. return
  1582. }
  1583. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1584. document.mainViewController?.chooseTransition(sender)
  1585. }
  1586. }
  1587. @IBAction func toggleAutoFlow(_ sender: Any?) {
  1588. if (self.canResponseDocumentAction() == false) {
  1589. return
  1590. }
  1591. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1592. document.mainViewController?.toggleAutoFlow(sender)
  1593. }
  1594. }
  1595. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  1596. if (self.canResponseDocumentAction() == false) {
  1597. return
  1598. }
  1599. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1600. document.mainViewController?.chooseAutoFlowSetting(sender)
  1601. }
  1602. }
  1603. @IBAction func toggleReadingBar(_ sender: Any?) {
  1604. if (self.canResponseDocumentAction() == false) {
  1605. return
  1606. }
  1607. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1608. document.mainViewController?.toggleReadingBar(sender)
  1609. }
  1610. }
  1611. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  1612. if (self.canResponseDocumentAction() == false) {
  1613. return
  1614. }
  1615. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1616. document.mainViewController?.toggleLeftSidePane(sender)
  1617. }
  1618. }
  1619. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  1620. if (self.canResponseDocumentAction() == false) {
  1621. return
  1622. }
  1623. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1624. document.mainViewController?.changeLeftSidePaneState(sender)
  1625. }
  1626. }
  1627. @IBAction func splitViewAction(_ sender: Any?) {
  1628. if (self.canResponseDocumentAction() == false) {
  1629. return
  1630. }
  1631. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1632. document.mainViewController?.splitViewAction(sender)
  1633. }
  1634. }
  1635. @IBAction func themesColor(_ sender: Any?) {
  1636. if (self.canResponseDocumentAction() == false) {
  1637. return
  1638. }
  1639. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1640. document.mainViewController?.themesColor(sender)
  1641. }
  1642. }
  1643. @IBAction func toggleStatusBar(_ sender: Any?) {
  1644. if (self.canResponseDocumentAction() == false) {
  1645. return
  1646. }
  1647. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1648. document.mainViewController?.toggleStatusBar(sender)
  1649. }
  1650. }
  1651. @IBAction func toggleToolbarShow(_ sender: Any?) {
  1652. if (self.canResponseDocumentAction() == false) {
  1653. return
  1654. }
  1655. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1656. document.mainViewController?.toggleToolbarShow(sender)
  1657. }
  1658. }
  1659. }
  1660. // MARK: - KMSystemEditMenuProtocol
  1661. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1662. func menuItemAction_find(_ sender: Any) {
  1663. if (self.canResponseDocumentAction() == false) {
  1664. return
  1665. }
  1666. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1667. document.mainViewController?.menuItemAction_find(sender)
  1668. }
  1669. }
  1670. @IBAction func changeFont(_ sender: Any?) {
  1671. KMPrint("changeFont ...")
  1672. }
  1673. }
  1674. // MARK: - Annotation Menu
  1675. extension KMBrowserWindowController {
  1676. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1677. if (self.canResponseDocumentAction() == false) {
  1678. return
  1679. }
  1680. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1681. document.mainViewController?.menuItemAction_highlight(sender)
  1682. }
  1683. }
  1684. @IBAction func menuItemAction_underline(_ sender: Any) {
  1685. if (self.canResponseDocumentAction() == false) {
  1686. return
  1687. }
  1688. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1689. document.mainViewController?.menuItemAction_underline(sender)
  1690. }
  1691. }
  1692. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1693. if (self.canResponseDocumentAction() == false) {
  1694. return
  1695. }
  1696. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1697. document.mainViewController?.menuItemAction_deleteLine(sender)
  1698. }
  1699. }
  1700. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1701. if (self.canResponseDocumentAction() == false) {
  1702. return
  1703. }
  1704. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1705. document.mainViewController?.menuItemAction_freehand(sender)
  1706. }
  1707. }
  1708. @IBAction func menuItemAction_text(_ sender: Any) {
  1709. if (self.canResponseDocumentAction() == false) {
  1710. return
  1711. }
  1712. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1713. document.mainViewController?.menuItemAction_text(sender)
  1714. }
  1715. }
  1716. @IBAction func menuItemAction_note(_ sender: Any) {
  1717. if (self.canResponseDocumentAction() == false) {
  1718. return
  1719. }
  1720. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1721. document.mainViewController?.menuItemAction_note(sender)
  1722. }
  1723. }
  1724. @IBAction func menuItemAction_squre(_ sender: Any) {
  1725. if (self.canResponseDocumentAction() == false) {
  1726. return
  1727. }
  1728. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1729. document.mainViewController?.menuItemAction_squre(sender)
  1730. }
  1731. }
  1732. @IBAction func menuItemAction_circle(_ sender: Any) {
  1733. if (self.canResponseDocumentAction() == false) {
  1734. return
  1735. }
  1736. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1737. document.mainViewController?.menuItemAction_circle(sender)
  1738. }
  1739. }
  1740. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1741. if (self.canResponseDocumentAction() == false) {
  1742. return
  1743. }
  1744. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1745. document.mainViewController?.menuItemAction_arrow(sender)
  1746. }
  1747. }
  1748. @IBAction func menuItemAction_line(_ sender: Any) {
  1749. if (self.canResponseDocumentAction() == false) {
  1750. return
  1751. }
  1752. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1753. document.mainViewController?.menuItemAction_line(sender)
  1754. }
  1755. }
  1756. // link
  1757. @IBAction func menuItemAction_link(_ sender: Any) {
  1758. if (self.canResponseDocumentAction() == false) {
  1759. return
  1760. }
  1761. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1762. document.mainViewController?.menuItemAction_link(sender)
  1763. }
  1764. }
  1765. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1766. if (self.canResponseDocumentAction() == false) {
  1767. return
  1768. }
  1769. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1770. document.mainViewController?.menuItemAction_linkPage(sender)
  1771. }
  1772. }
  1773. // stamp
  1774. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1775. if (self.canResponseDocumentAction() == false) {
  1776. return
  1777. }
  1778. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1779. document.mainViewController?.menuItemAction_stamp(sender)
  1780. }
  1781. }
  1782. @IBAction func notesLink(_ sender: Any?) {
  1783. if (self.canResponseDocumentAction() == false) {
  1784. return
  1785. }
  1786. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1787. document.mainViewController?.notesLink(sender)
  1788. }
  1789. }
  1790. @IBAction func notesStamp(_ sender: Any?) {
  1791. if (self.canResponseDocumentAction() == false) {
  1792. return
  1793. }
  1794. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1795. document.mainViewController?.notesStamp(sender)
  1796. }
  1797. }
  1798. @IBAction func menuItemAction_signure(_ sender: Any) {
  1799. if (self.canResponseDocumentAction() == false) {
  1800. return
  1801. }
  1802. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1803. document.mainViewController?.menuItemAction_signure(sender)
  1804. }
  1805. }
  1806. @IBAction func image(_ sender: Any?) {
  1807. if (self.canResponseDocumentAction() == false) {
  1808. return
  1809. }
  1810. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1811. document.mainViewController?.image(sender)
  1812. }
  1813. }
  1814. @IBAction func table(_ sender: Any?) {
  1815. if (self.canResponseDocumentAction() == false) {
  1816. return
  1817. }
  1818. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1819. document.mainViewController?.table(sender)
  1820. }
  1821. }
  1822. @IBAction func addForm(_ sender: Any?) {
  1823. if (self.canResponseDocumentAction() == false) {
  1824. return
  1825. }
  1826. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1827. document.mainViewController?.addForm(sender)
  1828. }
  1829. }
  1830. @IBAction func editNote(_ sender: Any?) {
  1831. if (self.canResponseDocumentAction() == false) {
  1832. return
  1833. }
  1834. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1835. document.mainViewController?.editNote(sender)
  1836. }
  1837. }
  1838. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1839. if (self.canResponseDocumentAction() == false) {
  1840. return
  1841. }
  1842. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1843. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1844. }
  1845. }
  1846. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1847. if (self.canResponseDocumentAction() == false) {
  1848. return
  1849. }
  1850. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1851. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1852. }
  1853. }
  1854. }
  1855. // MARK: - KMSystemPDFMenuProtocol
  1856. extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
  1857. @IBAction func changeDisplayMode(_ sender: Any?) {
  1858. if (self.canResponseDocumentAction() == false) {
  1859. return
  1860. }
  1861. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1862. document.mainViewController?.changeDisplayMode(sender)
  1863. }
  1864. }
  1865. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  1866. if (self.canResponseDocumentAction() == false) {
  1867. return
  1868. }
  1869. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1870. document.mainViewController?.toggleDisplayAsBook(sender)
  1871. }
  1872. }
  1873. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  1874. if (self.canResponseDocumentAction() == false) {
  1875. return
  1876. }
  1877. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1878. document.mainViewController?.toggleDisplayPageBreaks(sender)
  1879. }
  1880. }
  1881. @IBAction func changeDisplayBox(_ sender: Any?) {
  1882. if (self.canResponseDocumentAction() == false) {
  1883. return
  1884. }
  1885. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1886. document.mainViewController?.changeDisplayBox(sender)
  1887. }
  1888. }
  1889. @IBAction func toggleAutoScale(_ sender: Any?) {
  1890. if (self.canResponseDocumentAction() == false) {
  1891. return
  1892. }
  1893. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1894. document.mainViewController?.toggleAutoScale(sender)
  1895. }
  1896. }
  1897. @IBAction func doZoomToActualSize(_ sender: Any?) {
  1898. if (self.canResponseDocumentAction() == false) {
  1899. return
  1900. }
  1901. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1902. document.mainViewController?.doZoomToActualSize(sender)
  1903. }
  1904. }
  1905. @IBAction func doZoomToFit(_ sender: Any?) {
  1906. if (self.canResponseDocumentAction() == false) {
  1907. return
  1908. }
  1909. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1910. document.mainViewController?.doZoomToFit(sender)
  1911. }
  1912. }
  1913. @IBAction func doZoomIn(_ sender: Any?) {
  1914. if (self.canResponseDocumentAction() == false) {
  1915. return
  1916. }
  1917. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1918. document.mainViewController?.doZoomIn(sender)
  1919. }
  1920. }
  1921. @IBAction func doZoomOut(_ sender: Any?) {
  1922. if (self.canResponseDocumentAction() == false) {
  1923. return
  1924. }
  1925. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1926. document.mainViewController?.doZoomOut(sender)
  1927. }
  1928. }
  1929. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  1930. if (self.canResponseDocumentAction() == false) {
  1931. return
  1932. }
  1933. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1934. document.mainViewController?.doMarqueeZoomTool(sender)
  1935. }
  1936. }
  1937. @IBAction func highlightFormFiled(_ sender: Any?) {
  1938. if (self.canResponseDocumentAction() == false) {
  1939. return
  1940. }
  1941. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1942. document.mainViewController?.highlightFormFiled(sender)
  1943. }
  1944. }
  1945. @IBAction func highlightLinks(_ sender: Any?) {
  1946. if (self.canResponseDocumentAction() == false) {
  1947. return
  1948. }
  1949. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1950. document.mainViewController?.highlightLinks(sender)
  1951. }
  1952. }
  1953. @IBAction func resetForm(_ sender: Any?) {
  1954. if (self.canResponseDocumentAction() == false) {
  1955. return
  1956. }
  1957. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1958. document.mainViewController?.resetForm(sender)
  1959. }
  1960. }
  1961. @IBAction func removeAllAnnotation(_ sender: Any?) {
  1962. if (self.canResponseDocumentAction() == false) {
  1963. return
  1964. }
  1965. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1966. document.mainViewController?.removeAllAnnotation(sender)
  1967. }
  1968. }
  1969. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  1970. if (self.canResponseDocumentAction() == false) {
  1971. return
  1972. }
  1973. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1974. document.mainViewController?.savePDFSettingToDefaults(sender)
  1975. }
  1976. }
  1977. }
  1978. // MARK: - KMSystemGotoMenuProtocol
  1979. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1980. func menuItemAction_nextPage(_ sender: Any) {
  1981. if (self.canResponseDocumentAction() == false) {
  1982. return
  1983. }
  1984. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1985. document.mainViewController?.menuItemAction_nextPage(sender)
  1986. }
  1987. }
  1988. func menuItemAction_forwardPage(_ sender: Any) {
  1989. if (self.canResponseDocumentAction() == false) {
  1990. return
  1991. }
  1992. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1993. document.mainViewController?.menuItemAction_forwardPage(sender)
  1994. }
  1995. }
  1996. func menuItemAction_firstPage(_ sender: Any) {
  1997. if (self.canResponseDocumentAction() == false) {
  1998. return
  1999. }
  2000. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2001. document.mainViewController?.menuItemAction_firstPage(sender)
  2002. }
  2003. }
  2004. func menuItemAction_lastPage(_ sender: Any) {
  2005. if (self.canResponseDocumentAction() == false) {
  2006. return
  2007. }
  2008. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2009. document.mainViewController?.menuItemAction_lastPage(sender)
  2010. }
  2011. }
  2012. func menuItemAction_forward(_ sender: Any) {
  2013. if (self.canResponseDocumentAction() == false) {
  2014. return
  2015. }
  2016. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2017. document.mainViewController?.menuItemAction_forward(sender)
  2018. }
  2019. }
  2020. func menuItemAction_goback(_ sender: Any) {
  2021. if (self.canResponseDocumentAction() == false) {
  2022. return
  2023. }
  2024. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2025. document.mainViewController?.menuItemAction_goback(sender)
  2026. }
  2027. }
  2028. func menuItemAction_gotoPage(_ sender: Any) {
  2029. if (self.canResponseDocumentAction() == false) {
  2030. return
  2031. }
  2032. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2033. document.mainViewController?.menuItemAction_gotoPage(sender)
  2034. }
  2035. }
  2036. @IBAction func goToMarkedPage(_ sender: Any?) {
  2037. if (self.canResponseDocumentAction() == false) {
  2038. return
  2039. }
  2040. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2041. document.mainViewController?.goToMarkedPage(sender)
  2042. }
  2043. }
  2044. @IBAction func markPage(_ sender: Any?) {
  2045. if (self.canResponseDocumentAction() == false) {
  2046. return
  2047. }
  2048. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2049. document.mainViewController?.markPage(sender)
  2050. }
  2051. }
  2052. }
  2053. // MARK: - KMSystemToolMenuProtocol
  2054. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  2055. @IBAction func getInfo(_ sender: Any?) {
  2056. if (self.canResponseDocumentAction() == false) {
  2057. return
  2058. }
  2059. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2060. document.mainViewController?.getInfo(sender)
  2061. }
  2062. }
  2063. func orderFrontNotesPanel(_ sender: Any?) {
  2064. let windowC = KMNotesPanelController.shared
  2065. if let win = windowC.window {
  2066. if win.isVisible {
  2067. win.orderOut(sender)
  2068. } else {
  2069. win.orderFront(sender)
  2070. }
  2071. }
  2072. }
  2073. func menuItemAction_scrolTool(_ sender: Any) {
  2074. if (self.canResponseDocumentAction() == false) {
  2075. return
  2076. }
  2077. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2078. document.mainViewController?.menuItemAction_scrolTool(sender)
  2079. }
  2080. }
  2081. func menuItemAction_zoomOutTool(_ sender: Any) {
  2082. if (self.canResponseDocumentAction() == false) {
  2083. return
  2084. }
  2085. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2086. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  2087. }
  2088. }
  2089. func menuItemAction_selectTool(_ sender: Any) {
  2090. if (self.canResponseDocumentAction() == false) {
  2091. return
  2092. }
  2093. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2094. document.mainViewController?.menuItemAction_selectTool(sender)
  2095. }
  2096. }
  2097. @IBAction func changeToolMode(_ sender: Any?) {
  2098. if (self.canResponseDocumentAction() == false) {
  2099. return
  2100. }
  2101. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2102. if (document.isHome) {
  2103. } else {
  2104. document.mainViewController?.changeToolMode(sender)
  2105. }
  2106. }
  2107. }
  2108. @IBAction func compression(_ sender: Any?) {
  2109. if (self.canResponseDocumentAction() == false) {
  2110. return
  2111. }
  2112. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2113. if (document.isHome) {
  2114. } else {
  2115. document.mainViewController?.compression(sender)
  2116. }
  2117. }
  2118. }
  2119. @IBAction func merge(_ sender: Any?) {
  2120. if (self.canResponseDocumentAction() == false) {
  2121. return
  2122. }
  2123. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2124. if (document.isHome) {
  2125. } else {
  2126. document.mainViewController?.merge(sender)
  2127. }
  2128. }
  2129. }
  2130. @IBAction func convert(_ sender: Any?) {
  2131. if (self.canResponseDocumentAction() == false) {
  2132. return
  2133. }
  2134. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2135. if (document.isHome) {
  2136. } else {
  2137. document.mainViewController?.convert(sender)
  2138. }
  2139. }
  2140. }
  2141. @IBAction func imageToPDF(_ sender: Any?) {
  2142. if (self.canResponseDocumentAction() == false) {
  2143. return
  2144. }
  2145. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2146. if (document.isHome) {
  2147. } else {
  2148. document.mainViewController?.imageToPDF(sender)
  2149. }
  2150. }
  2151. }
  2152. @IBAction func ocr(_ sender: Any?) {
  2153. if (self.canResponseDocumentAction() == false) {
  2154. return
  2155. }
  2156. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2157. if (document.isHome) {
  2158. } else {
  2159. document.mainViewController?.ocr(sender)
  2160. }
  2161. }
  2162. }
  2163. @IBAction func extractImage(_ sender: Any?) {
  2164. if (self.canResponseDocumentAction() == false) {
  2165. return
  2166. }
  2167. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2168. if (document.isHome) {
  2169. } else {
  2170. document.mainViewController?.extractImage(sender)
  2171. }
  2172. }
  2173. }
  2174. @IBAction func pageEdit(_ sender: Any?) {
  2175. if (self.canResponseDocumentAction() == false) {
  2176. return
  2177. }
  2178. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2179. if (document.isHome) {
  2180. } else {
  2181. document.mainViewController?.pageEdit(sender)
  2182. }
  2183. }
  2184. }
  2185. @IBAction func textEditAction(_ sender: Any?) {
  2186. if (self.canResponseDocumentAction() == false) {
  2187. return
  2188. }
  2189. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2190. if (document.isHome) {
  2191. } else {
  2192. document.mainViewController?.textEditAction(sender)
  2193. }
  2194. }
  2195. }
  2196. @IBAction func security(_ sender: Any?) {
  2197. if (self.canResponseDocumentAction() == false) {
  2198. return
  2199. }
  2200. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2201. if (document.isHome) {
  2202. } else {
  2203. document.mainViewController?.security(sender)
  2204. }
  2205. }
  2206. }
  2207. @IBAction func decryption(_ sender: Any?) {
  2208. if (self.canResponseDocumentAction() == false) {
  2209. return
  2210. }
  2211. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2212. if (document.isHome) {
  2213. } else {
  2214. document.mainViewController?.decryption(sender)
  2215. }
  2216. }
  2217. }
  2218. @IBAction func cropAll(_ sender: Any?) {
  2219. if (self.canResponseDocumentAction() == false) {
  2220. return
  2221. }
  2222. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2223. if (document.isHome) {
  2224. } else {
  2225. document.mainViewController?.cropAll(sender)
  2226. }
  2227. }
  2228. }
  2229. @IBAction func crop(_ sender: Any?) {
  2230. if (self.canResponseDocumentAction() == false) {
  2231. return
  2232. }
  2233. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2234. if (document.isHome) {
  2235. } else {
  2236. document.mainViewController?.crop(sender)
  2237. }
  2238. }
  2239. }
  2240. @IBAction func autoCropAll(_ sender: Any?) {
  2241. if (self.canResponseDocumentAction() == false) {
  2242. return
  2243. }
  2244. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2245. if (document.isHome) {
  2246. } else {
  2247. document.mainViewController?.autoCropAll(sender)
  2248. }
  2249. }
  2250. }
  2251. @IBAction func smartAutoCropAll(_ sender: Any?) {
  2252. if (self.canResponseDocumentAction() == false) {
  2253. return
  2254. }
  2255. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2256. if (document.isHome) {
  2257. } else {
  2258. document.mainViewController?.smartAutoCropAll(sender)
  2259. }
  2260. }
  2261. }
  2262. @IBAction func cropOptionsModel(_ sender: Any?) {
  2263. if (self.canResponseDocumentAction() == false) {
  2264. return
  2265. }
  2266. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2267. if (document.isHome) {
  2268. } else {
  2269. // document.mainViewController?.cropOptionsModel(sender)
  2270. }
  2271. }
  2272. }
  2273. @IBAction func selectToolModel(_ sender: Any?) {
  2274. if (self.canResponseDocumentAction() == false) {
  2275. return
  2276. }
  2277. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2278. if (document.isHome) {
  2279. } else {
  2280. document.mainViewController?.selectToolModel(sender)
  2281. }
  2282. }
  2283. }
  2284. @IBAction func takeSnapshot(_ sender: Any?) {
  2285. if (self.canResponseDocumentAction() == false) {
  2286. return
  2287. }
  2288. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2289. if (document.isHome) {
  2290. } else {
  2291. document.mainViewController?.takeSnapshot(sender)
  2292. }
  2293. }
  2294. }
  2295. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  2296. if (self.canResponseDocumentAction() == false) {
  2297. return
  2298. }
  2299. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2300. if (document.isHome) {
  2301. } else {
  2302. document.mainViewController?.takeSnapshotSelectContent(sender)
  2303. }
  2304. }
  2305. }
  2306. @IBAction func changeAnnotationMode(_ sender: Any?) {
  2307. if (self.canResponseDocumentAction() == false) {
  2308. return
  2309. }
  2310. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2311. if (document.isHome) {
  2312. } else {
  2313. document.mainViewController?.changeAnnotationMode(sender)
  2314. }
  2315. }
  2316. }
  2317. @IBAction func addBackground(_ sender: Any?) {
  2318. if (self.canResponseDocumentAction() == false) {
  2319. return
  2320. }
  2321. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2322. if (document.isHome) {
  2323. } else {
  2324. document.mainViewController?.addBackground(sender)
  2325. }
  2326. }
  2327. }
  2328. @IBAction func removeBackground(_ sender: Any?) {
  2329. if (self.canResponseDocumentAction() == false) {
  2330. return
  2331. }
  2332. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2333. if (document.isHome) {
  2334. } else {
  2335. document.mainViewController?.removeBackground(sender)
  2336. }
  2337. }
  2338. }
  2339. @IBAction func addWatermark(_ sender: Any?) {
  2340. if (self.canResponseDocumentAction() == false) {
  2341. return
  2342. }
  2343. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2344. if (document.isHome) {
  2345. } else {
  2346. document.mainViewController?.addWatermark(sender)
  2347. }
  2348. }
  2349. }
  2350. @IBAction func editWatermark(_ sender: Any?) {
  2351. KMPrint("editWatermark ...")
  2352. }
  2353. @IBAction func batchAddWatermark(_ sender: Any?) {
  2354. if (self.canResponseDocumentAction() == false) {
  2355. return
  2356. }
  2357. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2358. if (document.isHome) {
  2359. } else {
  2360. document.mainViewController?.batchAddWatermark(sender)
  2361. }
  2362. }
  2363. }
  2364. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  2365. if (self.canResponseDocumentAction() == false) {
  2366. return
  2367. }
  2368. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2369. if (document.isHome) {
  2370. } else {
  2371. document.mainViewController?.batchRemoveWatermark(sender)
  2372. }
  2373. }
  2374. }
  2375. @IBAction func removeWatermark(_ sender: Any?) {
  2376. if (self.canResponseDocumentAction() == false) {
  2377. return
  2378. }
  2379. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2380. if (document.isHome) {
  2381. } else {
  2382. document.mainViewController?.removeWatermark(sender)
  2383. }
  2384. }
  2385. }
  2386. @IBAction func templateWatermark(_ sender: Any?) {
  2387. if (self.canResponseDocumentAction() == false) {
  2388. return
  2389. }
  2390. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2391. if (document.isHome) {
  2392. } else {
  2393. document.mainViewController?.templateWatermark(sender)
  2394. }
  2395. }
  2396. }
  2397. @IBAction func batchAddBackground(_ sender: Any?) {
  2398. if (self.canResponseDocumentAction() == false) {
  2399. return
  2400. }
  2401. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2402. if (document.isHome) {
  2403. } else {
  2404. document.mainViewController?.batchAddBackground(sender)
  2405. }
  2406. }
  2407. }
  2408. @IBAction func batchRemoveBackground(_ sender: Any?) {
  2409. if (self.canResponseDocumentAction() == false) {
  2410. return
  2411. }
  2412. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2413. if (document.isHome) {
  2414. } else {
  2415. document.mainViewController?.batchRemoveBackground(sender)
  2416. }
  2417. }
  2418. }
  2419. @IBAction func templateBackground(_ sender: Any?) {
  2420. if (self.canResponseDocumentAction() == false) {
  2421. return
  2422. }
  2423. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2424. if (document.isHome) {
  2425. } else {
  2426. document.mainViewController?.templateBackground(sender)
  2427. }
  2428. }
  2429. }
  2430. @IBAction func addHeaderFooter(_ sender: Any?) {
  2431. if (self.canResponseDocumentAction() == false) {
  2432. return
  2433. }
  2434. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2435. if (document.isHome) {
  2436. } else {
  2437. document.mainViewController?.addHeaderFooter(sender)
  2438. }
  2439. }
  2440. }
  2441. @IBAction func removeHeaderFooter(_ sender: Any?) {
  2442. if (self.canResponseDocumentAction() == false) {
  2443. return
  2444. }
  2445. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2446. if (document.isHome) {
  2447. } else {
  2448. document.mainViewController?.removeHeaderFooter(sender)
  2449. }
  2450. }
  2451. }
  2452. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  2453. if (self.canResponseDocumentAction() == false) {
  2454. return
  2455. }
  2456. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2457. if (document.isHome) {
  2458. } else {
  2459. document.mainViewController?.batchAddHeaderFooter(sender)
  2460. }
  2461. }
  2462. }
  2463. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  2464. if (self.canResponseDocumentAction() == false) {
  2465. return
  2466. }
  2467. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2468. if (document.isHome) {
  2469. } else {
  2470. document.mainViewController?.batchRemoveHeaderFooter(sender)
  2471. }
  2472. }
  2473. }
  2474. @IBAction func templateHeaderFooter(_ sender: Any?) {
  2475. if (self.canResponseDocumentAction() == false) {
  2476. return
  2477. }
  2478. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2479. if (document.isHome) {
  2480. } else {
  2481. document.mainViewController?.templateHeaderFooter(sender)
  2482. }
  2483. }
  2484. }
  2485. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  2486. if (self.canResponseDocumentAction() == false) {
  2487. return
  2488. }
  2489. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2490. if (document.isHome) {
  2491. } else {
  2492. document.mainViewController?.addHeaderFooterBates(sender)
  2493. }
  2494. }
  2495. }
  2496. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  2497. if (self.canResponseDocumentAction() == false) {
  2498. return
  2499. }
  2500. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2501. if (document.isHome) {
  2502. } else {
  2503. document.mainViewController?.removeHeaderFooterBates(sender)
  2504. }
  2505. }
  2506. }
  2507. @IBAction func batchAddBates(_ sender: Any?) {
  2508. if (self.canResponseDocumentAction() == false) {
  2509. return
  2510. }
  2511. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2512. if (document.isHome) {
  2513. } else {
  2514. document.mainViewController?.batchAddBates(sender)
  2515. }
  2516. }
  2517. }
  2518. @IBAction func batchRemoveBates(_ sender: Any?) {
  2519. if (self.canResponseDocumentAction() == false) {
  2520. return
  2521. }
  2522. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2523. if (document.isHome) {
  2524. } else {
  2525. document.mainViewController?.batchRemoveBates(sender)
  2526. }
  2527. }
  2528. }
  2529. @IBAction func templateBates(_ sender: Any?) {
  2530. if (self.canResponseDocumentAction() == false) {
  2531. return
  2532. }
  2533. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2534. if (document.isHome) {
  2535. } else {
  2536. document.mainViewController?.templateBates(sender)
  2537. }
  2538. }
  2539. }
  2540. @IBAction func togglePoster(_ sender: Any?) {
  2541. if (self.canResponseDocumentAction() == false) {
  2542. return
  2543. }
  2544. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2545. if (document.isHome) {
  2546. } else {
  2547. document.mainViewController?.togglePoster(sender)
  2548. }
  2549. }
  2550. }
  2551. @IBAction func toggleMultiple(_ sender: Any?) {
  2552. if (self.canResponseDocumentAction() == false) {
  2553. return
  2554. }
  2555. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2556. if (document.isHome) {
  2557. } else {
  2558. document.mainViewController?.toggleMultiple(sender)
  2559. }
  2560. }
  2561. }
  2562. @IBAction func toggleBooklet(_ sender: Any?) {
  2563. if (self.canResponseDocumentAction() == false) {
  2564. return
  2565. }
  2566. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2567. if (document.isHome) {
  2568. } else {
  2569. document.mainViewController?.toggleBooklet(sender)
  2570. }
  2571. }
  2572. }
  2573. @IBAction func rotateRight(_ sender: Any?) {
  2574. if (self.canResponseDocumentAction() == false) {
  2575. return
  2576. }
  2577. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2578. if (document.isHome) {
  2579. } else {
  2580. document.mainViewController?.rotateRight(sender)
  2581. }
  2582. }
  2583. }
  2584. @IBAction func rotateLeft(_ sender: Any?) {
  2585. if (self.canResponseDocumentAction() == false) {
  2586. return
  2587. }
  2588. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2589. if (document.isHome) {
  2590. } else {
  2591. document.mainViewController?.rotateLeft(sender)
  2592. }
  2593. }
  2594. }
  2595. @IBAction func rotateAllRight(_ sender: Any?) {
  2596. if (self.canResponseDocumentAction() == false) {
  2597. return
  2598. }
  2599. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2600. if (document.isHome) {
  2601. } else {
  2602. document.mainViewController?.rotateAllRight(sender)
  2603. }
  2604. }
  2605. }
  2606. @IBAction func rotateAllLeft(_ sender: Any?) {
  2607. if (self.canResponseDocumentAction() == false) {
  2608. return
  2609. }
  2610. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2611. if (document.isHome) {
  2612. } else {
  2613. document.mainViewController?.rotateAllLeft(sender)
  2614. }
  2615. }
  2616. }
  2617. @IBAction func autoSelectContent(_ sender: Any?) {
  2618. if (self.canResponseDocumentAction() == false) {
  2619. return
  2620. }
  2621. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2622. if (document.isHome) {
  2623. } else {
  2624. document.mainViewController?.autoSelectContent(sender)
  2625. }
  2626. }
  2627. }
  2628. }
  2629. // MARK: - KMSystemWindowMenuRrotocol
  2630. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  2631. func menuItemAction_showForwardTagPage(_ sender: Any) {
  2632. if (self.canResponseDocumentAction() == false) {
  2633. return
  2634. }
  2635. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2636. if (document.isHome) {
  2637. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  2638. } else {
  2639. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  2640. }
  2641. }
  2642. }
  2643. func menuItemAction_showNextTagPage(_ sender: Any) {
  2644. if (self.canResponseDocumentAction() == false) {
  2645. return
  2646. }
  2647. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2648. if (document.isHome) {
  2649. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  2650. } else {
  2651. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  2652. }
  2653. }
  2654. }
  2655. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  2656. if (self.canResponseDocumentAction() == false) {
  2657. return
  2658. }
  2659. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2660. if (document.isHome) {
  2661. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2662. } else {
  2663. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2664. }
  2665. }
  2666. }
  2667. func menuItemAction_mergeAllWindow(_ sender: Any) {
  2668. if (self.canResponseDocumentAction() == false) {
  2669. return
  2670. }
  2671. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2672. if (document.isHome) {
  2673. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  2674. } else {
  2675. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  2676. }
  2677. }
  2678. }
  2679. @IBAction func performFit(_ sender: Any?) {
  2680. if (self.canResponseDocumentAction() == false) {
  2681. return
  2682. }
  2683. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2684. if (document.isHome) {
  2685. } else {
  2686. document.mainViewController?.performFit(sender)
  2687. }
  2688. }
  2689. }
  2690. }
  2691. // MARK: - Analytics (埋点)
  2692. extension KMBrowserWindowController {
  2693. func trackEvent_upgrade() -> Void {
  2694. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  2695. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  2696. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  2697. }
  2698. }