Skip to content

Commit

Permalink
Add option to export raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
NSAntoine committed Mar 7, 2024
1 parent 188052a commit ab6b054
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Samra/UI/PastFilesListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ extension PastFilesListViewController: NSTableViewDataSource, NSTableViewDelegat
subtitleText.font = .systemFont(ofSize: 11)
}

subtitleText.lineBreakMode = .byTruncatingMiddle

subtitleText.textColor = .secondaryLabelColor

let titlesStackView = NSStackView(views: [text, subtitleText])
Expand All @@ -127,6 +129,7 @@ extension PastFilesListViewController: NSTableViewDataSource, NSTableViewDelegat
cell.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: cell.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: cell.trailingAnchor),
stackView.centerYAnchor.constraint(equalTo: cell.centerYAnchor),
])

Expand Down
21 changes: 21 additions & 0 deletions Samra/UI/Rendition/RenditionInformationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ struct RenditionInformationView: View {
}

HStack {
if rendition.type == .rawData, rendition.cuiRend.responds(to: #selector(CUIThemeRendition.data)) {
Button("Export Data to...") {
guard let data = rendition.cuiRend.data() else {
NSAlert(title: "Failed to export data", message: "Unable to get data (rendition.cuiRend.data() returned null)")
.runModal()
return
}

let savePanel = NSSavePanel()
savePanel.nameFieldStringValue = rendition.name
if savePanel.runModal() == .OK, let url = savePanel.url {
do {
try data.write(to: url)
} catch {
NSAlert(title: "Error trying to write data to file \(url)", message: error.localizedDescription)
.runModal()
}
}
}
}

Button("Edit") {
switch rendition.representation {
case .color(let cgColor):
Expand Down

0 comments on commit ab6b054

Please sign in to comment.