KMBrowserWindowController.swift 112 KB

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