KMBrowserWindowController.swift 114 KB

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