Skip to content

Commit

Permalink
Merge pull request #31 from unsignedapps/feature/flag-key-clipboard
Browse files Browse the repository at this point in the history
Added the flag key to the FlagDetailView
  • Loading branch information
bok- authored Jul 30, 2020
2 parents 35db3ce + 3d3ca29 commit 3b382c1
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
25 changes: 23 additions & 2 deletions Sources/Vexillographer/FlagDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Rob Amos on 29/6/20.
//

// swiftlint:disable multiple_closures_with_trailing_closure

#if os(iOS) || os(macOS)

import SwiftUI
Expand Down Expand Up @@ -47,8 +49,27 @@ struct FlagDetailView<Value, RootGroup>: View where Value: FlagValue, RootGroup:

var content: some View {
Form {
Section(header: Text("Description")) {
Text(self.flag.info.description)
Section(header: Text("Flag Details")) {
HStack {
Text("Key").font(.headline)
Spacer()
Text(self.flag.info.key)
}
.contextMenu {
Button(action: { self.flag.info.key.copyToPasteboard() }) {
Text("Copy key to clipboard")
}
}

VStack(alignment: .leading, spacing: 8) {
Text("Description").font(.headline)
Text(self.flag.info.description)
}
.contextMenu {
Button(action: { self.flag.info.description.copyToPasteboard() }) {
Text("Copy description to clipboard")
}
}
}

Section(header: Text("Current Source")) {
Expand Down
10 changes: 9 additions & 1 deletion Sources/Vexillographer/FlagGroupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Rob Amos on 16/6/20.
//

// swiftlint:disable multiple_closures_with_trailing_closure

#if os(iOS) || os(macOS)

import SwiftUI
Expand Down Expand Up @@ -45,9 +47,15 @@ struct UnfurledFlagGroupView<Group, Root>: View where Group: FlagContainer, Root

var content: some View {
Form {
Section(header: Text("Description")) {
VStack(alignment: .leading, spacing: 8) {
Text("Description").font(.headline)
Text(self.group.info.description)
}
.contextMenu {
Button(action: { self.group.info.description.copyToPasteboard() }) {
Text("Copy description to clipboard")
}
}
Section(header: Text("Flags")) {
ForEach(self.group.allItems(), id: \.id) { item in
item.unfurledView
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vexillographer/Unfurling/UnfurledFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct UnfurledFlag<Value, RootGroup>: UnfurledFlagItem, Identifiable where Valu
// MARK: - Initialisation

init (name: String, flag: Flag<Value>, manager: FlagValueManager<RootGroup>) {
self.info = UnfurledFlagInfo(info: flag.info, defaultName: name)
self.info = UnfurledFlagInfo(key: flag.key, info: flag.info, defaultName: name)
self.flag = flag
self.manager = manager
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Vexillographer/Unfurling/UnfurledFlagGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct UnfurledFlagGroup<Group, Root>: UnfurledFlagItem, Identifiable where Grou
// MARK: - Initialisation

init (name: String, group: FlagGroup<Group>, manager: FlagValueManager<Root>) {
self.info = UnfurledFlagInfo(info: group.info, defaultName: name)
self.info = UnfurledFlagInfo(key: "", info: group.info, defaultName: name)
self.group = group
self.manager = manager
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/Vexillographer/Unfurling/UnfurledFlagInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ struct UnfurledFlagInfo {

// MARK: - Properties

/// The flag's key
let key: String

/// The name of the unfurled flag or flag group
let name: String

Expand All @@ -22,7 +25,8 @@ struct UnfurledFlagInfo {

// MARK: - Initialisation

init (info: FlagInfo, defaultName: String) {
init (key: String, info: FlagInfo, defaultName: String) {
self.key = key
self.name = info.name ?? defaultName
self.description = info.description
}
Expand Down
28 changes: 28 additions & 0 deletions Sources/Vexillographer/Utilities/Pasteboard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Pasteboard.swift
// Vexil: Vexillographer
//
// Created by Rob Amos on 30/7/20.
//

#if os(iOS)

import UIKit

extension String {
func copyToPasteboard () {
UIPasteboard.general.string = self
}
}

#elseif os(macOS)

import Cocoa

extension String {
func copyToPasteboard () {
NSPasteboard.general.setString(self, forType: .string)
}
}

#endif

0 comments on commit 3b382c1

Please sign in to comment.