From ab6b0541d6fbf26c1d7033c7801b76b0ec0508ec Mon Sep 17 00:00:00 2001 From: Serena Date: Thu, 7 Mar 2024 15:41:30 +0300 Subject: [PATCH] Add option to export raw data --- Samra/UI/PastFilesListViewController.swift | 3 +++ .../Rendition/RenditionInformationView.swift | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Samra/UI/PastFilesListViewController.swift b/Samra/UI/PastFilesListViewController.swift index f5d6e1c..c4b86ac 100644 --- a/Samra/UI/PastFilesListViewController.swift +++ b/Samra/UI/PastFilesListViewController.swift @@ -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]) @@ -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), ]) diff --git a/Samra/UI/Rendition/RenditionInformationView.swift b/Samra/UI/Rendition/RenditionInformationView.swift index 522fa78..fdd5cb6 100644 --- a/Samra/UI/Rendition/RenditionInformationView.swift +++ b/Samra/UI/Rendition/RenditionInformationView.swift @@ -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):