KMBrowserWindowController.swift 112 KB

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