KMBrowserWindowController.swift 112 KB

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