<commit_before>/**
 * <NAME> - http://taewon.de - @hataewon
 * See LICENSE
 */

import Cocoa
import RxSwift

// MARK: - File Menu Item Actions
extension MainWindow {

  @IBAction func newTab(_ sender: Any?) {
    self.neoVimView
      .newTab()
      .subscribe()
  }

  @IBAction func openDocument(_ sender: Any?) {
    let panel = NSOpenPanel()
    panel.canChooseDirectories = true
    panel.allowsMultipleSelection = true
    panel.beginSheetModal(for: self.window) { result in
      guard result == .OK else {
        return
      }

      let urls = panel.urls
      self.neoVimView
        .allBuffers()
        .flatMapCompletable { bufs -> Completable in
          if bufs.count == 1 {
            let isTransient = bufs.first?.isTransient ?? false

            if isTransient {
              self.neoVimView.cwd = FileUtils.commonParent(of: urls)
            }
          }
          return self.neoVimView.open(urls: urls)
        }
        .subscribe()
    }
  }

  @IBAction func openQuickly(_ sender: Any?) {
    self.emit(self.uuidAction(for: .openQuickly))
  }

  @IBAction func saveDocument(_ sender: Any?) {
    self.neoVimView
      .currentBuffer()
      .observeOn(MainScheduler.instance)
      .flatMapCompletable { curBuf -> Completable in
        if curBuf.url == nil {
          self.savePanelSheet {
            self.neoVimView
              .saveCurrentTab(url: $0)
              .subscribe()
          }
          return Completable.empty()
        }

        return self.neoVimView.saveCurrentTab()
      }
      .subscribe()
  }

  @IBAction func saveDocumentAs(_ sender: Any?) {
    self.neoVimView
      .currentBuffer()
      .observeOn(MainScheduler.instance)
      .subscribe(onSuccess: { curBuf in
        self.savePanelSheet { url in
          self.neoVimView
            .saveCurrentTab(url: url)
            .andThen(
              curBuf.isDirty ? self.neoVimView.openInNewTab(urls: [url]) : self.neoVimView.openInCurrentTab(url: url)
            )
            .subscribe()
        }
      })
  }

  fileprivate func savePanelSheet(action: @escaping (URL) -> Void) {
    let panel = NSSavePanel()
    panel.beginSheetModal(for: self.window) { result in
      guard result == .OK else {<commit_msg>GH-666 Use convenience methods to suppress warning<commit_after>/**
 * <NAME> - http://taewon.de - @hataewon
 * See LICENSE
 */

import Cocoa
import RxSwift

// MARK: - File Menu Item Actions
extension MainWindow {

  @IBAction func newTab(_ sender: Any?) {
    self.neoVimView
      .newTab()
      .trigger()
  }

  @IBAction func openDocument(_ sender: Any?) {
    let panel = NSOpenPanel()
    panel.canChooseDirectories = true
    panel.allowsMultipleSelection = true
    panel.beginSheetModal(for: self.window) { result in
      guard result == .OK else {
        return
      }

      let urls = panel.urls
      self.neoVimView
        .allBuffers()
        .flatMapCompletable { bufs -> Completable in
          if bufs.count == 1 {
            let isTransient = bufs.first?.isTransient ?? false

            if isTransient {
              self.neoVimView.cwd = FileUtils.commonParent(of: urls)
            }
          }
          return self.neoVimView.open(urls: urls)
        }
        .trigger()
    }
  }

  @IBAction func openQuickly(_ sender: Any?) {
    self.emit(self.uuidAction(for: .openQuickly))
  }

  @IBAction func saveDocument(_ sender: Any?) {
    self.neoVimView
      .currentBuffer()
      .observeOn(MainScheduler.instance)
      .flatMapCompletable { curBuf -> Completable in
        if curBuf.url == nil {
          self.savePanelSheet {
            self.neoVimView
              .saveCurrentTab(url: $0)
              .trigger()
          }
          return Completable.empty()
        }

        return self.neoVimView.saveCurrentTab()
      }
      .trigger()
  }

  @IBAction func saveDocumentAs(_ sender: Any?) {
    self.neoVimView
      .currentBuffer()
      .observeOn(MainScheduler.instance)
      .value(onSuccess: { curBuf in
        self.savePanelSheet { url in
          self.neoVimView
            .saveCurrentTab(url: url)
            .andThen(
              curBuf.isDirty ? self.neoVimView.openInNewTab(urls: [url]) : self.neoVimView.openInCurrentTab(url: url)
            )
            .trigger()
        }
      })
  }

  fileprivate func savePanelSheet(action: @escaping (URL) -> Void) {
    let panel = NSSavePanel()
    panel.beginSheetModal(for: self.window) { result in
      guard result == .OK else {
{'fraction_non_alphanumeric': 0.10567296996662959, 'fraction_numerical': 0.001557285873192436, 'mean_word_length': 1.9853917662682603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2250400', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1382, 'n_words': 294}