KMBrowserWindowController.swift 111 KB

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