KMBrowserWindowController.swift 111 KB

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