From 0e461a382257979037e8927e5f6b468635b0a7fe Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Mon, 13 Apr 2026 09:57:23 -0500 Subject: feat: add power user actions Implements: https://todo.sr.ht/~ccleberg/hutch/52 Implements: https://todo.sr.ht/~ccleberg/hutch/53 Implements: https://todo.sr.ht/~ccleberg/hutch/54 --- Hutch/Views/Repositories/RepositoryRowView.swift | 45 +++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'Hutch/Views/Repositories/RepositoryRowView.swift') diff --git a/Hutch/Views/Repositories/RepositoryRowView.swift b/Hutch/Views/Repositories/RepositoryRowView.swift index 814ea76..0da6cbc 100644 --- a/Hutch/Views/Repositories/RepositoryRowView.swift +++ b/Hutch/Views/Repositories/RepositoryRowView.swift @@ -1,7 +1,9 @@ import SwiftUI -import UIKit struct RepositoryRowView: View { + @Environment(AppState.self) private var appState + @Environment(\.openURL) private var openURL + let repository: RepositorySummary let buildStatus: RepositoryBuildStatus @@ -56,34 +58,45 @@ struct RepositoryRowView: View { } .padding(.vertical, 2) .contextMenu { + if let url = SRHTWebURL.repository(repository) { + Button { + openURL(url) + } label: { + Label("Open in Browser", systemImage: "safari") + } + } + + Button { + if let url = SRHTWebURL.repository(repository)?.absoluteString { + appState.copyToPasteboard(url, label: "repository URL") + } + } label: { + Label("Copy URL", systemImage: "doc.on.doc") + } + Button { - UIPasteboard.general.string = httpsCloneURL(for: repository) + if let url = SRHTWebURL.httpsCloneURL(repository) { + appState.copyToPasteboard(url, label: "HTTPS clone URL") + } } label: { Label("Copy HTTPS URL", systemImage: "doc.on.doc") } Button { - UIPasteboard.general.string = sshCloneURL(for: repository) + appState.copyToPasteboard(SRHTWebURL.sshCloneURL(repository), label: "SSH clone URL") } label: { Label("Copy SSH URL", systemImage: "terminal") } + + Button { + appState.copyToPasteboard(repository.rid, label: "repository RID") + } label: { + Label("Copy RID", systemImage: "number") + } } } } -private func httpsCloneURL(for repository: RepositorySummary) -> String { - let host = "\(repository.service.rawValue).sr.ht" - let owner = repository.owner.canonicalName - return "https://\(host)/\(owner)/\(repository.name)" -} - -private func sshCloneURL(for repository: RepositorySummary) -> String { - let host = "\(repository.service.rawValue).sr.ht" - let user = repository.service == .hg ? "hg" : "git" - let owner = repository.owner.canonicalName - return "\(user)@\(host):\(owner)/\(repository.name)" -} - private struct RepositoryBuildStatusIndicator: View { let status: RepositoryBuildStatus -- cgit v1.2.3