KMBrowserWindowController.swift 112 KB

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