KMBrowserWindowController.swift 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017
  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. KMPrint("screenShot_SelectArea")
  1190. KMScreenShotHandler.beginScreenshot_SelectRectWithCompleteHandler { ima in
  1191. if let image = ima {
  1192. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1193. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1194. let newDocument = CPDFDocument()
  1195. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1196. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1197. if writeSuccess ?? false {
  1198. self.savePdf(savePath)
  1199. // try? FileManager.default.removeItem(atPath: savePath)
  1200. } else {
  1201. }
  1202. }
  1203. }
  1204. }
  1205. }
  1206. @IBAction func screenShot_Window(_ sender: Any?) {
  1207. KMPrint("screenShot_Window")
  1208. KMScreenShotHandler.beginScreenShot_SelectWindowCompleteHandler { ima in
  1209. if let image = ima {
  1210. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1211. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1212. let newDocument = CPDFDocument()
  1213. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1214. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1215. if writeSuccess == true {
  1216. self.savePdf(savePath)
  1217. // try? FileManager.default.removeItem(atPath: savePath)
  1218. } else {
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
  1225. KMPrint("screenShot_FullScreenDelay")
  1226. KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(3) { ima in
  1227. if let image = ima {
  1228. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1229. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1230. let newDocument = CPDFDocument()
  1231. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1232. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1233. if writeSuccess == true {
  1234. self.savePdf(savePath)
  1235. // try? FileManager.default.removeItem(atPath: savePath)
  1236. } else {
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. @IBAction func screenShot_FullScreen(_ sender: Any?) {
  1243. KMPrint("screenShot_FullScreen")
  1244. KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(0) { ima in
  1245. if let image = ima {
  1246. DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
  1247. let savePath = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? "") + "/" + Bundle.main.bundleIdentifier! + "/screenShot.pdf"
  1248. let newDocument = CPDFDocument()
  1249. _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
  1250. let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
  1251. if writeSuccess == true {
  1252. self.savePdf(savePath)
  1253. // try? FileManager.default.removeItem(atPath: savePath)
  1254. } else {
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. }
  1261. // MARK: - KMSystemViewMenuProtocol
  1262. extension KMBrowserWindowController: KMSystemViewMenuProtocol {
  1263. func createPDFFromImage() {
  1264. let openPanel = NSOpenPanel()
  1265. openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
  1266. openPanel.allowsMultipleSelection = true
  1267. 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: "")
  1268. openPanel.beginSheetModal(for: NSApp.mainWindow!) { response in
  1269. if response == .OK {
  1270. self.creatPdfFromImg(urls: openPanel.urls)
  1271. }
  1272. }
  1273. }
  1274. func creatPdfFromImg(urls: Array<URL>) {
  1275. // let savePath = self.newDocumentTempSavePath("convertToPDF.pdf")
  1276. let pdf = CPDFDocument()
  1277. // var isSucceed = true
  1278. let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
  1279. let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
  1280. let filePath = savePath.deletingLastPathComponent
  1281. if FileManager.default.fileExists(atPath: filePath) == false {
  1282. try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
  1283. }
  1284. for fileURL in urls {
  1285. if let imag = NSImage(contentsOfFile: fileURL.path ) {
  1286. _ = pdf?.km_insertPage(imag.size, withImage: fileURL.path , at: pdf?.pageCount ?? 0)
  1287. pdf?.write(to: URL(fileURLWithPath: savePath))
  1288. }
  1289. }
  1290. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
  1291. if error != nil {
  1292. NSApp.presentError(error!)
  1293. } else {
  1294. if document is KMMainDocument {
  1295. let newDocument = document
  1296. (newDocument as! KMMainDocument).isNewCreated = true
  1297. }
  1298. }
  1299. // self.homeContentView?.reloadData()
  1300. }
  1301. }
  1302. func createPdfWithParam() {
  1303. let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
  1304. let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
  1305. let filePath = savePath.deletingLastPathComponent
  1306. if FileManager.default.fileExists(atPath: filePath) == false {
  1307. try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
  1308. }
  1309. let pdfDocument = CPDFDocument()
  1310. pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
  1311. pdfDocument?.write(to: URL(fileURLWithPath: savePath))
  1312. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
  1313. if error != nil {
  1314. NSApp.presentError(error!)
  1315. } else {
  1316. if document is KMMainDocument {
  1317. let newDocument = document
  1318. (newDocument as! KMMainDocument).isNewCreated = true
  1319. }
  1320. }
  1321. // self.homeContentView?.reloadData()
  1322. }
  1323. }
  1324. func savePdf(_ filePath: String) -> Void {
  1325. let docVc = KMDocumentController.shared
  1326. docVc.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
  1327. if error != nil {
  1328. NSApp.presentError(error!)
  1329. } else {
  1330. if document is KMMainDocument {
  1331. let newDocument = document
  1332. (newDocument as! KMMainDocument).isNewCreated = true
  1333. }
  1334. }
  1335. }
  1336. }
  1337. func newDocumentTempSavePath(_ fileName: String) -> String {
  1338. let searchPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last
  1339. let append1 = searchPath?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!)
  1340. let append2 = append1!.stringByAppendingPathComponent(String(format: "%@", fileName))
  1341. return append2
  1342. }
  1343. func fetchUniquePath(_ originalPath: String) -> String {
  1344. var path = originalPath
  1345. let dManager = FileManager.default
  1346. if !dManager.fileExists(atPath: path) {
  1347. if path.extension.count < 1 {
  1348. path = path.stringByAppendingPathExtension("pdf")
  1349. }
  1350. return path
  1351. } else {
  1352. let originalFullFileName = path.lastPathComponent
  1353. let originalFileName = path.lastPathComponent.deletingPathExtension
  1354. let originalExtension = path.extension
  1355. let startIndex: Int = 0
  1356. let endIndex: Int = startIndex + originalPath.count - originalFullFileName.count - 1
  1357. let fileLocatePath = originalPath.substring(to: endIndex)
  1358. var i = 1
  1359. while (1 != 0) {
  1360. var newName = String(format: "%@%ld", originalFileName, i)
  1361. newName = newName.stringByAppendingPathExtension(originalExtension)
  1362. let newPath = fileLocatePath.stringByAppendingPathComponent(newName)
  1363. if !dManager.fileExists(atPath: newPath) {
  1364. return newPath
  1365. } else {
  1366. i+=1
  1367. continue
  1368. }
  1369. }
  1370. }
  1371. }
  1372. func menuItemAction_adjustWidth(_ sender: Any) {
  1373. if (self.canResponseDocumentAction() == false) {
  1374. return
  1375. }
  1376. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1377. document.mainViewController?.menuItemAction_adjustWidth(sender)
  1378. }
  1379. }
  1380. func menuItemAction_adjustPage(_ sender: Any) {
  1381. if (self.canResponseDocumentAction() == false) {
  1382. return
  1383. }
  1384. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1385. document.mainViewController?.menuItemAction_adjustPage(sender)
  1386. }
  1387. }
  1388. func menuItemAction_size(_ sender: Any) {
  1389. if (self.canResponseDocumentAction() == false) {
  1390. return
  1391. }
  1392. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1393. document.mainViewController?.menuItemAction_size(sender)
  1394. }
  1395. }
  1396. func menuItemAction_zoomOut(_ sender: Any) {
  1397. if (self.canResponseDocumentAction() == false) {
  1398. return
  1399. }
  1400. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1401. document.mainViewController?.menuItemAction_zoomOut(sender)
  1402. }
  1403. }
  1404. func menuItemAction_zoomIn(_ sender: Any) {
  1405. if (self.canResponseDocumentAction() == false) {
  1406. return
  1407. }
  1408. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1409. document.mainViewController?.menuItemAction_zoomIn(sender)
  1410. }
  1411. }
  1412. func menuItemAction_singlePage(_ sender: Any) {
  1413. if (self.canResponseDocumentAction() == false) {
  1414. return
  1415. }
  1416. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1417. document.mainViewController?.menuItemAction_singlePage(sender)
  1418. }
  1419. }
  1420. func menuItemAction_singlePageContinue(_ sender: Any) {
  1421. if (self.canResponseDocumentAction() == false) {
  1422. return
  1423. }
  1424. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1425. document.mainViewController?.menuItemAction_singlePageContinue(sender)
  1426. }
  1427. }
  1428. func menuItemAction_doublePage(_ sender: Any) {
  1429. if (self.canResponseDocumentAction() == false) {
  1430. return
  1431. }
  1432. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1433. document.mainViewController?.menuItemAction_doublePage(sender)
  1434. }
  1435. }
  1436. func menuItemAction_doublePageContinue(_ sender: Any) {
  1437. if (self.canResponseDocumentAction() == false) {
  1438. return
  1439. }
  1440. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1441. document.mainViewController?.menuItemAction_doublePageContinue(sender)
  1442. }
  1443. }
  1444. func menuItemAction_bookMode(_ sender: Any) {
  1445. if (self.canResponseDocumentAction() == false) {
  1446. return
  1447. }
  1448. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1449. document.mainViewController?.menuItemAction_bookMode(sender)
  1450. }
  1451. }
  1452. func menuItemAction_readMode(_ sender: Any) {
  1453. if (self.canResponseDocumentAction() == false) {
  1454. return
  1455. }
  1456. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1457. document.mainViewController?.menuItemAction_readMode(sender)
  1458. }
  1459. }
  1460. func menuItemAction_showSplitPage(_ sender: Any) {
  1461. if (self.canResponseDocumentAction() == false) {
  1462. return
  1463. }
  1464. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1465. document.mainViewController?.menuItemAction_showSplitPage(sender)
  1466. }
  1467. }
  1468. func menuItemAction_rotateLeft(_ sender: Any) {
  1469. if (self.canResponseDocumentAction() == false) {
  1470. return
  1471. }
  1472. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1473. document.mainViewController?.menuItemAction_rotateLeft(sender)
  1474. }
  1475. }
  1476. func menuItemAction_rotateRight(_ sender: Any) {
  1477. if (self.canResponseDocumentAction() == false) {
  1478. return
  1479. }
  1480. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1481. document.mainViewController?.menuItemAction_rotateRight(sender)
  1482. }
  1483. }
  1484. func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  1485. if (self.canResponseDocumentAction() == false) {
  1486. return
  1487. }
  1488. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1489. document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
  1490. }
  1491. }
  1492. func menuItemAction_rotateAllPageRight(_ sender: Any) {
  1493. if (self.canResponseDocumentAction() == false) {
  1494. return
  1495. }
  1496. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1497. document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
  1498. }
  1499. }
  1500. func menuItemAction_view_readMode(_ sender: Any) {
  1501. if (self.canResponseDocumentAction() == false) {
  1502. return
  1503. }
  1504. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1505. document.mainViewController?.menuItemAction_view_readMode(sender)
  1506. }
  1507. }
  1508. func menuItemAction_hiddenLeftSide(_ sender: Any) {
  1509. if (self.canResponseDocumentAction() == false) {
  1510. return
  1511. }
  1512. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1513. document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
  1514. }
  1515. }
  1516. func menuItemAction_hiddenRightSide(_ sender: Any) {
  1517. if (self.canResponseDocumentAction() == false) {
  1518. return
  1519. }
  1520. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1521. document.mainViewController?.menuItemAction_hiddenRightSide(sender)
  1522. }
  1523. }
  1524. func menuItemAction_thumai(_ sender: Any) {
  1525. if (self.canResponseDocumentAction() == false) {
  1526. return
  1527. }
  1528. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1529. document.mainViewController?.menuItemAction_thumai(sender)
  1530. }
  1531. }
  1532. func menuItemAction_outline(_ sender: Any) {
  1533. if (self.canResponseDocumentAction() == false) {
  1534. return
  1535. }
  1536. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1537. document.mainViewController?.menuItemAction_outline(sender)
  1538. }
  1539. }
  1540. func menuItemAction_bookmark(_ sender: Any) {
  1541. if (self.canResponseDocumentAction() == false) {
  1542. return
  1543. }
  1544. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1545. document.mainViewController?.menuItemAction_bookmark(sender)
  1546. }
  1547. }
  1548. func menuItemAction_annotation(_ sender: Any) {
  1549. if (self.canResponseDocumentAction() == false) {
  1550. return
  1551. }
  1552. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1553. document.mainViewController?.menuItemAction_annotation(sender)
  1554. }
  1555. }
  1556. func menuItemAction_search(_ sender: Any) {
  1557. if (self.canResponseDocumentAction() == false) {
  1558. return
  1559. }
  1560. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1561. document.mainViewController?.menuItemAction_search(sender)
  1562. }
  1563. }
  1564. func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  1565. if (self.canResponseDocumentAction() == false) {
  1566. return
  1567. }
  1568. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1569. document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
  1570. }
  1571. }
  1572. @IBAction func togglePresentation(_ sender: Any?) {
  1573. if (self.canResponseDocumentAction() == false) {
  1574. return
  1575. }
  1576. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1577. document.mainViewController?.togglePresentation(sender)
  1578. }
  1579. }
  1580. @IBAction func chooseTransition(_ sender: Any?) {
  1581. if (self.canResponseDocumentAction() == false) {
  1582. return
  1583. }
  1584. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1585. document.mainViewController?.chooseTransition(sender)
  1586. }
  1587. }
  1588. @IBAction func toggleAutoFlow(_ sender: Any?) {
  1589. if (self.canResponseDocumentAction() == false) {
  1590. return
  1591. }
  1592. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1593. document.mainViewController?.toggleAutoFlow(sender)
  1594. }
  1595. }
  1596. @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
  1597. if (self.canResponseDocumentAction() == false) {
  1598. return
  1599. }
  1600. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1601. document.mainViewController?.chooseAutoFlowSetting(sender)
  1602. }
  1603. }
  1604. @IBAction func toggleReadingBar(_ sender: Any?) {
  1605. if (self.canResponseDocumentAction() == false) {
  1606. return
  1607. }
  1608. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1609. document.mainViewController?.toggleReadingBar(sender)
  1610. }
  1611. }
  1612. @IBAction func toggleLeftSidePane(_ sender: Any?) {
  1613. if (self.canResponseDocumentAction() == false) {
  1614. return
  1615. }
  1616. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1617. document.mainViewController?.toggleLeftSidePane(sender)
  1618. }
  1619. }
  1620. @IBAction func changeLeftSidePaneState(_ sender: Any?) {
  1621. if (self.canResponseDocumentAction() == false) {
  1622. return
  1623. }
  1624. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1625. document.mainViewController?.changeLeftSidePaneState(sender)
  1626. }
  1627. }
  1628. @IBAction func splitViewAction(_ sender: Any?) {
  1629. if (self.canResponseDocumentAction() == false) {
  1630. return
  1631. }
  1632. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1633. document.mainViewController?.splitViewAction(sender)
  1634. }
  1635. }
  1636. @IBAction func themesColor(_ sender: Any?) {
  1637. if (self.canResponseDocumentAction() == false) {
  1638. return
  1639. }
  1640. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1641. document.mainViewController?.themesColor(sender)
  1642. }
  1643. }
  1644. @IBAction func toggleStatusBar(_ sender: Any?) {
  1645. if (self.canResponseDocumentAction() == false) {
  1646. return
  1647. }
  1648. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1649. document.mainViewController?.toggleStatusBar(sender)
  1650. }
  1651. }
  1652. @IBAction func toggleToolbarShow(_ sender: Any?) {
  1653. if (self.canResponseDocumentAction() == false) {
  1654. return
  1655. }
  1656. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1657. document.mainViewController?.toggleToolbarShow(sender)
  1658. }
  1659. }
  1660. }
  1661. // MARK: - KMSystemEditMenuProtocol
  1662. extension KMBrowserWindowController: KMSystemEditMenuProtocol {
  1663. func menuItemAction_find(_ sender: Any) {
  1664. if (self.canResponseDocumentAction() == false) {
  1665. return
  1666. }
  1667. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1668. document.mainViewController?.menuItemAction_find(sender)
  1669. }
  1670. }
  1671. @IBAction func changeFont(_ sender: Any?) {
  1672. KMPrint("changeFont ...")
  1673. }
  1674. }
  1675. // MARK: - Annotation Menu
  1676. extension KMBrowserWindowController {
  1677. @IBAction func menuItemAction_highlight(_ sender: Any) {
  1678. if (self.canResponseDocumentAction() == false) {
  1679. return
  1680. }
  1681. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1682. document.mainViewController?.menuItemAction_highlight(sender)
  1683. }
  1684. }
  1685. @IBAction func menuItemAction_underline(_ sender: Any) {
  1686. if (self.canResponseDocumentAction() == false) {
  1687. return
  1688. }
  1689. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1690. document.mainViewController?.menuItemAction_underline(sender)
  1691. }
  1692. }
  1693. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  1694. if (self.canResponseDocumentAction() == false) {
  1695. return
  1696. }
  1697. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1698. document.mainViewController?.menuItemAction_deleteLine(sender)
  1699. }
  1700. }
  1701. @IBAction func menuItemAction_freehand(_ sender: Any) {
  1702. if (self.canResponseDocumentAction() == false) {
  1703. return
  1704. }
  1705. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1706. document.mainViewController?.menuItemAction_freehand(sender)
  1707. }
  1708. }
  1709. @IBAction func menuItemAction_text(_ sender: Any) {
  1710. if (self.canResponseDocumentAction() == false) {
  1711. return
  1712. }
  1713. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1714. document.mainViewController?.menuItemAction_text(sender)
  1715. }
  1716. }
  1717. @IBAction func menuItemAction_note(_ sender: Any) {
  1718. if (self.canResponseDocumentAction() == false) {
  1719. return
  1720. }
  1721. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1722. document.mainViewController?.menuItemAction_note(sender)
  1723. }
  1724. }
  1725. @IBAction func menuItemAction_squre(_ sender: Any) {
  1726. if (self.canResponseDocumentAction() == false) {
  1727. return
  1728. }
  1729. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1730. document.mainViewController?.menuItemAction_squre(sender)
  1731. }
  1732. }
  1733. @IBAction func menuItemAction_circle(_ sender: Any) {
  1734. if (self.canResponseDocumentAction() == false) {
  1735. return
  1736. }
  1737. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1738. document.mainViewController?.menuItemAction_circle(sender)
  1739. }
  1740. }
  1741. @IBAction func menuItemAction_arrow(_ sender: Any) {
  1742. if (self.canResponseDocumentAction() == false) {
  1743. return
  1744. }
  1745. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1746. document.mainViewController?.menuItemAction_arrow(sender)
  1747. }
  1748. }
  1749. @IBAction func menuItemAction_line(_ sender: Any) {
  1750. if (self.canResponseDocumentAction() == false) {
  1751. return
  1752. }
  1753. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1754. document.mainViewController?.menuItemAction_line(sender)
  1755. }
  1756. }
  1757. // link
  1758. @IBAction func menuItemAction_link(_ sender: Any) {
  1759. if (self.canResponseDocumentAction() == false) {
  1760. return
  1761. }
  1762. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1763. document.mainViewController?.menuItemAction_link(sender)
  1764. }
  1765. }
  1766. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  1767. if (self.canResponseDocumentAction() == false) {
  1768. return
  1769. }
  1770. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1771. document.mainViewController?.menuItemAction_linkPage(sender)
  1772. }
  1773. }
  1774. // stamp
  1775. @IBAction func menuItemAction_stamp(_ sender: Any) {
  1776. if (self.canResponseDocumentAction() == false) {
  1777. return
  1778. }
  1779. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1780. document.mainViewController?.menuItemAction_stamp(sender)
  1781. }
  1782. }
  1783. @IBAction func notesLink(_ sender: Any?) {
  1784. if (self.canResponseDocumentAction() == false) {
  1785. return
  1786. }
  1787. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1788. document.mainViewController?.notesLink(sender)
  1789. }
  1790. }
  1791. @IBAction func notesStamp(_ sender: Any?) {
  1792. if (self.canResponseDocumentAction() == false) {
  1793. return
  1794. }
  1795. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1796. document.mainViewController?.notesStamp(sender)
  1797. }
  1798. }
  1799. @IBAction func menuItemAction_signure(_ sender: Any) {
  1800. if (self.canResponseDocumentAction() == false) {
  1801. return
  1802. }
  1803. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1804. document.mainViewController?.menuItemAction_signure(sender)
  1805. }
  1806. }
  1807. @IBAction func image(_ sender: Any?) {
  1808. if (self.canResponseDocumentAction() == false) {
  1809. return
  1810. }
  1811. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1812. document.mainViewController?.image(sender)
  1813. }
  1814. }
  1815. @IBAction func table(_ sender: Any?) {
  1816. if (self.canResponseDocumentAction() == false) {
  1817. return
  1818. }
  1819. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1820. document.mainViewController?.table(sender)
  1821. }
  1822. }
  1823. @IBAction func addForm(_ sender: Any?) {
  1824. if (self.canResponseDocumentAction() == false) {
  1825. return
  1826. }
  1827. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1828. document.mainViewController?.addForm(sender)
  1829. }
  1830. }
  1831. @IBAction func editNote(_ sender: Any?) {
  1832. if (self.canResponseDocumentAction() == false) {
  1833. return
  1834. }
  1835. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1836. document.mainViewController?.editNote(sender)
  1837. }
  1838. }
  1839. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  1840. if (self.canResponseDocumentAction() == false) {
  1841. return
  1842. }
  1843. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1844. document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
  1845. }
  1846. }
  1847. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  1848. if (self.canResponseDocumentAction() == false) {
  1849. return
  1850. }
  1851. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1852. document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
  1853. }
  1854. }
  1855. }
  1856. // MARK: - KMSystemPDFMenuProtocol
  1857. extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
  1858. @IBAction func changeDisplayMode(_ sender: Any?) {
  1859. if (self.canResponseDocumentAction() == false) {
  1860. return
  1861. }
  1862. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1863. document.mainViewController?.changeDisplayMode(sender)
  1864. }
  1865. }
  1866. @IBAction func toggleDisplayAsBook(_ sender: Any?) {
  1867. if (self.canResponseDocumentAction() == false) {
  1868. return
  1869. }
  1870. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1871. document.mainViewController?.toggleDisplayAsBook(sender)
  1872. }
  1873. }
  1874. @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
  1875. if (self.canResponseDocumentAction() == false) {
  1876. return
  1877. }
  1878. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1879. document.mainViewController?.toggleDisplayPageBreaks(sender)
  1880. }
  1881. }
  1882. @IBAction func changeDisplayBox(_ sender: Any?) {
  1883. if (self.canResponseDocumentAction() == false) {
  1884. return
  1885. }
  1886. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1887. document.mainViewController?.changeDisplayBox(sender)
  1888. }
  1889. }
  1890. @IBAction func toggleAutoScale(_ sender: Any?) {
  1891. if (self.canResponseDocumentAction() == false) {
  1892. return
  1893. }
  1894. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1895. document.mainViewController?.toggleAutoScale(sender)
  1896. }
  1897. }
  1898. @IBAction func doZoomToActualSize(_ sender: Any?) {
  1899. if (self.canResponseDocumentAction() == false) {
  1900. return
  1901. }
  1902. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1903. document.mainViewController?.doZoomToActualSize(sender)
  1904. }
  1905. }
  1906. @IBAction func doZoomToFit(_ sender: Any?) {
  1907. if (self.canResponseDocumentAction() == false) {
  1908. return
  1909. }
  1910. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1911. document.mainViewController?.doZoomToFit(sender)
  1912. }
  1913. }
  1914. @IBAction func doZoomIn(_ sender: Any?) {
  1915. if (self.canResponseDocumentAction() == false) {
  1916. return
  1917. }
  1918. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1919. document.mainViewController?.doZoomIn(sender)
  1920. }
  1921. }
  1922. @IBAction func doZoomOut(_ sender: Any?) {
  1923. if (self.canResponseDocumentAction() == false) {
  1924. return
  1925. }
  1926. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1927. document.mainViewController?.doZoomOut(sender)
  1928. }
  1929. }
  1930. @IBAction func doMarqueeZoomTool(_ sender: Any?) {
  1931. if (self.canResponseDocumentAction() == false) {
  1932. return
  1933. }
  1934. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1935. document.mainViewController?.doMarqueeZoomTool(sender)
  1936. }
  1937. }
  1938. @IBAction func highlightFormFiled(_ sender: Any?) {
  1939. if (self.canResponseDocumentAction() == false) {
  1940. return
  1941. }
  1942. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1943. document.mainViewController?.highlightFormFiled(sender)
  1944. }
  1945. }
  1946. @IBAction func highlightLinks(_ sender: Any?) {
  1947. if (self.canResponseDocumentAction() == false) {
  1948. return
  1949. }
  1950. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1951. document.mainViewController?.highlightLinks(sender)
  1952. }
  1953. }
  1954. @IBAction func resetForm(_ sender: Any?) {
  1955. if (self.canResponseDocumentAction() == false) {
  1956. return
  1957. }
  1958. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1959. document.mainViewController?.resetForm(sender)
  1960. }
  1961. }
  1962. @IBAction func removeAllAnnotation(_ sender: Any?) {
  1963. if (self.canResponseDocumentAction() == false) {
  1964. return
  1965. }
  1966. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1967. document.mainViewController?.removeAllAnnotation(sender)
  1968. }
  1969. }
  1970. @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
  1971. if (self.canResponseDocumentAction() == false) {
  1972. return
  1973. }
  1974. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1975. document.mainViewController?.savePDFSettingToDefaults(sender)
  1976. }
  1977. }
  1978. }
  1979. // MARK: - KMSystemGotoMenuProtocol
  1980. extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
  1981. func menuItemAction_nextPage(_ sender: Any) {
  1982. if (self.canResponseDocumentAction() == false) {
  1983. return
  1984. }
  1985. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1986. document.mainViewController?.menuItemAction_nextPage(sender)
  1987. }
  1988. }
  1989. func menuItemAction_forwardPage(_ sender: Any) {
  1990. if (self.canResponseDocumentAction() == false) {
  1991. return
  1992. }
  1993. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  1994. document.mainViewController?.menuItemAction_forwardPage(sender)
  1995. }
  1996. }
  1997. func menuItemAction_firstPage(_ sender: Any) {
  1998. if (self.canResponseDocumentAction() == false) {
  1999. return
  2000. }
  2001. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2002. document.mainViewController?.menuItemAction_firstPage(sender)
  2003. }
  2004. }
  2005. func menuItemAction_lastPage(_ sender: Any) {
  2006. if (self.canResponseDocumentAction() == false) {
  2007. return
  2008. }
  2009. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2010. document.mainViewController?.menuItemAction_lastPage(sender)
  2011. }
  2012. }
  2013. func menuItemAction_forward(_ sender: Any) {
  2014. if (self.canResponseDocumentAction() == false) {
  2015. return
  2016. }
  2017. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2018. document.mainViewController?.menuItemAction_forward(sender)
  2019. }
  2020. }
  2021. func menuItemAction_goback(_ sender: Any) {
  2022. if (self.canResponseDocumentAction() == false) {
  2023. return
  2024. }
  2025. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2026. document.mainViewController?.menuItemAction_goback(sender)
  2027. }
  2028. }
  2029. func menuItemAction_gotoPage(_ sender: Any) {
  2030. if (self.canResponseDocumentAction() == false) {
  2031. return
  2032. }
  2033. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2034. document.mainViewController?.menuItemAction_gotoPage(sender)
  2035. }
  2036. }
  2037. @IBAction func goToMarkedPage(_ sender: Any?) {
  2038. if (self.canResponseDocumentAction() == false) {
  2039. return
  2040. }
  2041. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2042. document.mainViewController?.goToMarkedPage(sender)
  2043. }
  2044. }
  2045. @IBAction func markPage(_ sender: Any?) {
  2046. if (self.canResponseDocumentAction() == false) {
  2047. return
  2048. }
  2049. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2050. document.mainViewController?.markPage(sender)
  2051. }
  2052. }
  2053. }
  2054. // MARK: - KMSystemToolMenuProtocol
  2055. extension KMBrowserWindowController: KMSystemToolMenuProtocol {
  2056. @IBAction func getInfo(_ sender: Any?) {
  2057. if (self.canResponseDocumentAction() == false) {
  2058. return
  2059. }
  2060. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2061. document.mainViewController?.getInfo(sender)
  2062. }
  2063. }
  2064. func orderFrontNotesPanel(_ sender: Any?) {
  2065. let windowC = KMNotesPanelController.shared
  2066. if let win = windowC.window {
  2067. if win.isVisible {
  2068. win.orderOut(sender)
  2069. } else {
  2070. win.orderFront(sender)
  2071. }
  2072. }
  2073. }
  2074. func menuItemAction_scrolTool(_ sender: Any) {
  2075. if (self.canResponseDocumentAction() == false) {
  2076. return
  2077. }
  2078. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2079. document.mainViewController?.menuItemAction_scrolTool(sender)
  2080. }
  2081. }
  2082. func menuItemAction_zoomOutTool(_ sender: Any) {
  2083. if (self.canResponseDocumentAction() == false) {
  2084. return
  2085. }
  2086. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2087. document.mainViewController?.menuItemAction_zoomOutTool(sender)
  2088. }
  2089. }
  2090. func menuItemAction_selectTool(_ sender: Any) {
  2091. if (self.canResponseDocumentAction() == false) {
  2092. return
  2093. }
  2094. if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
  2095. document.mainViewController?.menuItemAction_selectTool(sender)
  2096. }
  2097. }
  2098. @IBAction func changeToolMode(_ sender: Any?) {
  2099. if (self.canResponseDocumentAction() == false) {
  2100. return
  2101. }
  2102. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2103. if (document.isHome) {
  2104. } else {
  2105. document.mainViewController?.changeToolMode(sender)
  2106. }
  2107. }
  2108. }
  2109. @IBAction func compression(_ sender: Any?) {
  2110. if (self.canResponseDocumentAction() == false) {
  2111. return
  2112. }
  2113. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2114. if (document.isHome) {
  2115. } else {
  2116. document.mainViewController?.compression(sender)
  2117. }
  2118. }
  2119. }
  2120. @IBAction func merge(_ sender: Any?) {
  2121. if (self.canResponseDocumentAction() == false) {
  2122. return
  2123. }
  2124. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2125. if (document.isHome) {
  2126. } else {
  2127. document.mainViewController?.merge(sender)
  2128. }
  2129. }
  2130. }
  2131. @IBAction func convert(_ sender: Any?) {
  2132. if (self.canResponseDocumentAction() == false) {
  2133. return
  2134. }
  2135. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2136. if (document.isHome) {
  2137. } else {
  2138. document.mainViewController?.convert(sender)
  2139. }
  2140. }
  2141. }
  2142. @IBAction func imageToPDF(_ sender: Any?) {
  2143. if (self.canResponseDocumentAction() == false) {
  2144. return
  2145. }
  2146. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2147. if (document.isHome) {
  2148. } else {
  2149. document.mainViewController?.imageToPDF(sender)
  2150. }
  2151. }
  2152. }
  2153. @IBAction func ocr(_ sender: Any?) {
  2154. if (self.canResponseDocumentAction() == false) {
  2155. return
  2156. }
  2157. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2158. if (document.isHome) {
  2159. } else {
  2160. document.mainViewController?.ocr(sender)
  2161. }
  2162. }
  2163. }
  2164. @IBAction func extractImage(_ sender: Any?) {
  2165. if (self.canResponseDocumentAction() == false) {
  2166. return
  2167. }
  2168. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2169. if (document.isHome) {
  2170. } else {
  2171. document.mainViewController?.extractImage(sender)
  2172. }
  2173. }
  2174. }
  2175. @IBAction func pageEdit(_ sender: Any?) {
  2176. if (self.canResponseDocumentAction() == false) {
  2177. return
  2178. }
  2179. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2180. if (document.isHome) {
  2181. } else {
  2182. document.mainViewController?.pageEdit(sender)
  2183. }
  2184. }
  2185. }
  2186. @IBAction func textEditAction(_ sender: Any?) {
  2187. if (self.canResponseDocumentAction() == false) {
  2188. return
  2189. }
  2190. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2191. if (document.isHome) {
  2192. } else {
  2193. document.mainViewController?.textEditAction(sender)
  2194. }
  2195. }
  2196. }
  2197. @IBAction func security(_ sender: Any?) {
  2198. if (self.canResponseDocumentAction() == false) {
  2199. return
  2200. }
  2201. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2202. if (document.isHome) {
  2203. } else {
  2204. document.mainViewController?.security(sender)
  2205. }
  2206. }
  2207. }
  2208. @IBAction func decryption(_ sender: Any?) {
  2209. if (self.canResponseDocumentAction() == false) {
  2210. return
  2211. }
  2212. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2213. if (document.isHome) {
  2214. } else {
  2215. document.mainViewController?.decryption(sender)
  2216. }
  2217. }
  2218. }
  2219. @IBAction func cropAll(_ sender: Any?) {
  2220. if (self.canResponseDocumentAction() == false) {
  2221. return
  2222. }
  2223. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2224. if (document.isHome) {
  2225. } else {
  2226. document.mainViewController?.cropAll(sender)
  2227. }
  2228. }
  2229. }
  2230. @IBAction func crop(_ sender: Any?) {
  2231. if (self.canResponseDocumentAction() == false) {
  2232. return
  2233. }
  2234. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2235. if (document.isHome) {
  2236. } else {
  2237. document.mainViewController?.crop(sender)
  2238. }
  2239. }
  2240. }
  2241. @IBAction func autoCropAll(_ sender: Any?) {
  2242. if (self.canResponseDocumentAction() == false) {
  2243. return
  2244. }
  2245. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2246. if (document.isHome) {
  2247. } else {
  2248. document.mainViewController?.autoCropAll(sender)
  2249. }
  2250. }
  2251. }
  2252. @IBAction func smartAutoCropAll(_ sender: Any?) {
  2253. if (self.canResponseDocumentAction() == false) {
  2254. return
  2255. }
  2256. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2257. if (document.isHome) {
  2258. } else {
  2259. document.mainViewController?.smartAutoCropAll(sender)
  2260. }
  2261. }
  2262. }
  2263. @IBAction func cropOptionsModel(_ sender: Any?) {
  2264. if (self.canResponseDocumentAction() == false) {
  2265. return
  2266. }
  2267. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2268. if (document.isHome) {
  2269. } else {
  2270. // document.mainViewController?.cropOptionsModel(sender)
  2271. }
  2272. }
  2273. }
  2274. @IBAction func selectToolModel(_ sender: Any?) {
  2275. if (self.canResponseDocumentAction() == false) {
  2276. return
  2277. }
  2278. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2279. if (document.isHome) {
  2280. } else {
  2281. document.mainViewController?.selectToolModel(sender)
  2282. }
  2283. }
  2284. }
  2285. @IBAction func takeSnapshot(_ sender: Any?) {
  2286. if (self.canResponseDocumentAction() == false) {
  2287. return
  2288. }
  2289. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2290. if (document.isHome) {
  2291. } else {
  2292. document.mainViewController?.takeSnapshot(sender)
  2293. }
  2294. }
  2295. }
  2296. @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
  2297. if (self.canResponseDocumentAction() == false) {
  2298. return
  2299. }
  2300. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2301. if (document.isHome) {
  2302. } else {
  2303. document.mainViewController?.takeSnapshotSelectContent(sender)
  2304. }
  2305. }
  2306. }
  2307. @IBAction func changeAnnotationMode(_ sender: Any?) {
  2308. if (self.canResponseDocumentAction() == false) {
  2309. return
  2310. }
  2311. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2312. if (document.isHome) {
  2313. } else {
  2314. document.mainViewController?.changeAnnotationMode(sender)
  2315. }
  2316. }
  2317. }
  2318. @IBAction func addBackground(_ sender: Any?) {
  2319. if (self.canResponseDocumentAction() == false) {
  2320. return
  2321. }
  2322. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2323. if (document.isHome) {
  2324. } else {
  2325. document.mainViewController?.addBackground(sender)
  2326. }
  2327. }
  2328. }
  2329. @IBAction func removeBackground(_ sender: Any?) {
  2330. if (self.canResponseDocumentAction() == false) {
  2331. return
  2332. }
  2333. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2334. if (document.isHome) {
  2335. } else {
  2336. document.mainViewController?.removeBackground(sender)
  2337. }
  2338. }
  2339. }
  2340. @IBAction func addWatermark(_ sender: Any?) {
  2341. if (self.canResponseDocumentAction() == false) {
  2342. return
  2343. }
  2344. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2345. if (document.isHome) {
  2346. } else {
  2347. document.mainViewController?.addWatermark(sender)
  2348. }
  2349. }
  2350. }
  2351. @IBAction func editWatermark(_ sender: Any?) {
  2352. KMPrint("editWatermark ...")
  2353. }
  2354. @IBAction func batchAddWatermark(_ sender: Any?) {
  2355. if (self.canResponseDocumentAction() == false) {
  2356. return
  2357. }
  2358. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2359. if (document.isHome) {
  2360. } else {
  2361. document.mainViewController?.batchAddWatermark(sender)
  2362. }
  2363. }
  2364. }
  2365. @IBAction func batchRemoveWatermark(_ sender: Any?) {
  2366. if (self.canResponseDocumentAction() == false) {
  2367. return
  2368. }
  2369. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2370. if (document.isHome) {
  2371. } else {
  2372. document.mainViewController?.batchRemoveWatermark(sender)
  2373. }
  2374. }
  2375. }
  2376. @IBAction func removeWatermark(_ sender: Any?) {
  2377. if (self.canResponseDocumentAction() == false) {
  2378. return
  2379. }
  2380. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2381. if (document.isHome) {
  2382. } else {
  2383. document.mainViewController?.removeWatermark(sender)
  2384. }
  2385. }
  2386. }
  2387. @IBAction func templateWatermark(_ sender: Any?) {
  2388. if (self.canResponseDocumentAction() == false) {
  2389. return
  2390. }
  2391. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2392. if (document.isHome) {
  2393. } else {
  2394. document.mainViewController?.templateWatermark(sender)
  2395. }
  2396. }
  2397. }
  2398. @IBAction func batchAddBackground(_ sender: Any?) {
  2399. if (self.canResponseDocumentAction() == false) {
  2400. return
  2401. }
  2402. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2403. if (document.isHome) {
  2404. } else {
  2405. document.mainViewController?.batchAddBackground(sender)
  2406. }
  2407. }
  2408. }
  2409. @IBAction func batchRemoveBackground(_ sender: Any?) {
  2410. if (self.canResponseDocumentAction() == false) {
  2411. return
  2412. }
  2413. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2414. if (document.isHome) {
  2415. } else {
  2416. document.mainViewController?.batchRemoveBackground(sender)
  2417. }
  2418. }
  2419. }
  2420. @IBAction func templateBackground(_ sender: Any?) {
  2421. if (self.canResponseDocumentAction() == false) {
  2422. return
  2423. }
  2424. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2425. if (document.isHome) {
  2426. } else {
  2427. document.mainViewController?.templateBackground(sender)
  2428. }
  2429. }
  2430. }
  2431. @IBAction func addHeaderFooter(_ sender: Any?) {
  2432. if (self.canResponseDocumentAction() == false) {
  2433. return
  2434. }
  2435. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2436. if (document.isHome) {
  2437. } else {
  2438. document.mainViewController?.addHeaderFooter(sender)
  2439. }
  2440. }
  2441. }
  2442. @IBAction func removeHeaderFooter(_ sender: Any?) {
  2443. if (self.canResponseDocumentAction() == false) {
  2444. return
  2445. }
  2446. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2447. if (document.isHome) {
  2448. } else {
  2449. document.mainViewController?.removeHeaderFooter(sender)
  2450. }
  2451. }
  2452. }
  2453. @IBAction func batchAddHeaderFooter(_ sender: Any?) {
  2454. if (self.canResponseDocumentAction() == false) {
  2455. return
  2456. }
  2457. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2458. if (document.isHome) {
  2459. } else {
  2460. document.mainViewController?.batchAddHeaderFooter(sender)
  2461. }
  2462. }
  2463. }
  2464. @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
  2465. if (self.canResponseDocumentAction() == false) {
  2466. return
  2467. }
  2468. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2469. if (document.isHome) {
  2470. } else {
  2471. document.mainViewController?.batchRemoveHeaderFooter(sender)
  2472. }
  2473. }
  2474. }
  2475. @IBAction func templateHeaderFooter(_ sender: Any?) {
  2476. if (self.canResponseDocumentAction() == false) {
  2477. return
  2478. }
  2479. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2480. if (document.isHome) {
  2481. } else {
  2482. document.mainViewController?.templateHeaderFooter(sender)
  2483. }
  2484. }
  2485. }
  2486. @IBAction func addHeaderFooterBates(_ sender: Any?) {
  2487. if (self.canResponseDocumentAction() == false) {
  2488. return
  2489. }
  2490. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2491. if (document.isHome) {
  2492. } else {
  2493. document.mainViewController?.addHeaderFooterBates(sender)
  2494. }
  2495. }
  2496. }
  2497. @IBAction func removeHeaderFooterBates(_ sender: Any?) {
  2498. if (self.canResponseDocumentAction() == false) {
  2499. return
  2500. }
  2501. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2502. if (document.isHome) {
  2503. } else {
  2504. document.mainViewController?.removeHeaderFooterBates(sender)
  2505. }
  2506. }
  2507. }
  2508. @IBAction func batchAddBates(_ sender: Any?) {
  2509. if (self.canResponseDocumentAction() == false) {
  2510. return
  2511. }
  2512. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2513. if (document.isHome) {
  2514. } else {
  2515. document.mainViewController?.batchAddBates(sender)
  2516. }
  2517. }
  2518. }
  2519. @IBAction func batchRemoveBates(_ sender: Any?) {
  2520. if (self.canResponseDocumentAction() == false) {
  2521. return
  2522. }
  2523. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2524. if (document.isHome) {
  2525. } else {
  2526. document.mainViewController?.batchRemoveBates(sender)
  2527. }
  2528. }
  2529. }
  2530. @IBAction func templateBates(_ sender: Any?) {
  2531. if (self.canResponseDocumentAction() == false) {
  2532. return
  2533. }
  2534. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2535. if (document.isHome) {
  2536. } else {
  2537. document.mainViewController?.templateBates(sender)
  2538. }
  2539. }
  2540. }
  2541. @IBAction func togglePoster(_ sender: Any?) {
  2542. if (self.canResponseDocumentAction() == false) {
  2543. return
  2544. }
  2545. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2546. if (document.isHome) {
  2547. } else {
  2548. document.mainViewController?.togglePoster(sender)
  2549. }
  2550. }
  2551. }
  2552. @IBAction func toggleMultiple(_ sender: Any?) {
  2553. if (self.canResponseDocumentAction() == false) {
  2554. return
  2555. }
  2556. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2557. if (document.isHome) {
  2558. } else {
  2559. document.mainViewController?.toggleMultiple(sender)
  2560. }
  2561. }
  2562. }
  2563. @IBAction func toggleBooklet(_ sender: Any?) {
  2564. if (self.canResponseDocumentAction() == false) {
  2565. return
  2566. }
  2567. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2568. if (document.isHome) {
  2569. } else {
  2570. document.mainViewController?.toggleBooklet(sender)
  2571. }
  2572. }
  2573. }
  2574. @IBAction func rotateRight(_ sender: Any?) {
  2575. if (self.canResponseDocumentAction() == false) {
  2576. return
  2577. }
  2578. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2579. if (document.isHome) {
  2580. } else {
  2581. document.mainViewController?.rotateRight(sender)
  2582. }
  2583. }
  2584. }
  2585. @IBAction func rotateLeft(_ sender: Any?) {
  2586. if (self.canResponseDocumentAction() == false) {
  2587. return
  2588. }
  2589. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2590. if (document.isHome) {
  2591. } else {
  2592. document.mainViewController?.rotateLeft(sender)
  2593. }
  2594. }
  2595. }
  2596. @IBAction func rotateAllRight(_ sender: Any?) {
  2597. if (self.canResponseDocumentAction() == false) {
  2598. return
  2599. }
  2600. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2601. if (document.isHome) {
  2602. } else {
  2603. document.mainViewController?.rotateAllRight(sender)
  2604. }
  2605. }
  2606. }
  2607. @IBAction func rotateAllLeft(_ sender: Any?) {
  2608. if (self.canResponseDocumentAction() == false) {
  2609. return
  2610. }
  2611. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2612. if (document.isHome) {
  2613. } else {
  2614. document.mainViewController?.rotateAllLeft(sender)
  2615. }
  2616. }
  2617. }
  2618. @IBAction func autoSelectContent(_ sender: Any?) {
  2619. if (self.canResponseDocumentAction() == false) {
  2620. return
  2621. }
  2622. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2623. if (document.isHome) {
  2624. } else {
  2625. document.mainViewController?.autoSelectContent(sender)
  2626. }
  2627. }
  2628. }
  2629. }
  2630. // MARK: - KMSystemWindowMenuRrotocol
  2631. extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
  2632. func menuItemAction_showForwardTagPage(_ sender: Any) {
  2633. if (self.canResponseDocumentAction() == false) {
  2634. return
  2635. }
  2636. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2637. if (document.isHome) {
  2638. document.homeViewController?.menuItemAction_showForwardTagPage(sender)
  2639. } else {
  2640. document.mainViewController?.menuItemAction_showForwardTagPage(sender)
  2641. }
  2642. }
  2643. }
  2644. func menuItemAction_showNextTagPage(_ sender: Any) {
  2645. if (self.canResponseDocumentAction() == false) {
  2646. return
  2647. }
  2648. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2649. if (document.isHome) {
  2650. document.homeViewController?.menuItemAction_showNextTagPage(sender)
  2651. } else {
  2652. document.mainViewController?.menuItemAction_showNextTagPage(sender)
  2653. }
  2654. }
  2655. }
  2656. func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  2657. if (self.canResponseDocumentAction() == false) {
  2658. return
  2659. }
  2660. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2661. if (document.isHome) {
  2662. document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2663. } else {
  2664. document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
  2665. }
  2666. }
  2667. }
  2668. func menuItemAction_mergeAllWindow(_ sender: Any) {
  2669. if (self.canResponseDocumentAction() == false) {
  2670. return
  2671. }
  2672. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2673. if (document.isHome) {
  2674. document.homeViewController?.menuItemAction_mergeAllWindow(sender)
  2675. } else {
  2676. document.mainViewController?.menuItemAction_mergeAllWindow(sender)
  2677. }
  2678. }
  2679. }
  2680. @IBAction func performFit(_ sender: Any?) {
  2681. if (self.canResponseDocumentAction() == false) {
  2682. return
  2683. }
  2684. if let document = self.browser.activeTabContents() as? KMMainDocument {
  2685. if (document.isHome) {
  2686. } else {
  2687. document.mainViewController?.performFit(sender)
  2688. }
  2689. }
  2690. }
  2691. }
  2692. // MARK: - Analytics (埋点)
  2693. extension KMBrowserWindowController {
  2694. func trackEvent_upgrade() -> Void {
  2695. KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
  2696. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
  2697. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
  2698. }
  2699. }