KMBrowserWindowController.swift 112 KB

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