KMBrowserWindowController.swift 111 KB

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