Skip to content

Commit

Permalink
Merge pull request #645 from subdan/feature-export-transcript
Browse files Browse the repository at this point in the history
Export Transcript
  • Loading branch information
insidegui authored Oct 7, 2020
2 parents 6f8c392 + 2172f1f commit 7b40c04
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
18 changes: 18 additions & 0 deletions WWDC/SessionTranscriptViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ final class SessionTranscriptViewController: NSViewController {
tableView.delegate = self

searchController.didSelectOpenInNewWindow = { [weak self] in self?.detachWindow() }
searchController.didSelectExportTranscript = { [weak self] in self?.exportTranscript() }
}

override func viewDidLoad() {
Expand Down Expand Up @@ -224,6 +225,23 @@ final class SessionTranscriptViewController: NSViewController {
scrollView.contentInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}

private func exportTranscript() {
guard let sessionName = viewModel?.session.title,
let transcript = viewModel?.session.transcriptText,
let transcriptData = transcript.data(using: .utf8) else { return }

let panel = NSSavePanel()
panel.nameFieldStringValue = "\(sessionName).txt"
panel.begin { response in
switch (response, panel.url) {
case (.OK, let url?):
FileManager.default.createFile(atPath: url.path, contents: transcriptData, attributes: nil)
default:
break
}
}
}

// MARK: - Detached presentation

Expand Down
35 changes: 33 additions & 2 deletions WWDC/TranscriptSearchController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class TranscriptSearchController: NSViewController {
}

var didSelectOpenInNewWindow: () -> Void = { }
var didSelectExportTranscript: () -> Void = { }

private(set) var searchTerm = BehaviorRelay<String?>(value: nil)

Expand All @@ -49,6 +50,32 @@ final class TranscriptSearchController: NSViewController {

return b
}()

private lazy var exportButton: NSView = {
let b = PUIButton(frame: .zero)

b.image = #imageLiteral(resourceName: "share")
b.target = self
b.action = #selector(exportTranscript)
b.toolTip = "Export Transcript"
b.setContentHuggingPriority(.defaultHigh, for: .horizontal)
b.translatesAutoresizingMaskIntoConstraints = false

let container = NSView()
container.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(b)

NSLayoutConstraint.activate([
b.widthAnchor.constraint(equalToConstant: 14),
b.heightAnchor.constraint(equalToConstant: 18),
container.widthAnchor.constraint(equalToConstant: 14),
container.heightAnchor.constraint(equalToConstant: 22),
b.centerXAnchor.constraint(equalTo: container.centerXAnchor),
b.centerYAnchor.constraint(equalTo: container.centerYAnchor, constant: -2)
])

return container
}()

private lazy var searchField: NSSearchField = {
let f = NSSearchField()
Expand All @@ -60,10 +87,10 @@ final class TranscriptSearchController: NSViewController {
}()

private lazy var stackView: NSStackView = {
let v = NSStackView(views: [self.searchField, self.detachButton])
let v = NSStackView(views: [self.searchField, self.exportButton, self.detachButton])

v.orientation = .horizontal
v.spacing = 6
v.spacing = 8
v.translatesAutoresizingMaskIntoConstraints = false

return v
Expand Down Expand Up @@ -131,4 +158,8 @@ final class TranscriptSearchController: NSViewController {
searchTerm.accept(pasteboardTerm)
}

@objc private func exportTranscript() {
didSelectExportTranscript()
}

}

0 comments on commit 7b40c04

Please sign in to comment.