Skip to content

Commit 006f03e

Browse files
committed
Add hover modifier to see the full directory path and click to copy it
1 parent 7409b23 commit 006f03e

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

Lingua-App/Lingua/Lingua/Scenes/ProjectFormView/ProjectFormView.swift

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ struct ProjectFormView: View {
1818
@State private var outputPathValid = false
1919
@State private var stringsDirectoryValid = false
2020
@State private var outputSwiftCodeFileDirectoryValid = false
21-
21+
@State private var copied = false
22+
2223
var onSave: ((Project) -> Void)? = nil
2324
var onDelete: ((Project) -> Void)? = nil
2425
var onLocalize: ((Project) -> Void)? = nil
@@ -52,6 +53,19 @@ struct ProjectFormView: View {
5253
deleteButton(for: viewModel.project).padding()
5354
}
5455
.padding()
56+
.overlay {
57+
if copied {
58+
Text("Copied to clipboard!")
59+
.padding(8)
60+
.background(
61+
Color.black
62+
.opacity(0.4)
63+
)
64+
.clipShape(RoundedRectangle(cornerRadius: 6))
65+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
66+
.padding(.top, 6)
67+
}
68+
}
5569
}
5670
}
5771

@@ -104,7 +118,8 @@ private extension ProjectFormView {
104118
bookmarkDataKey: viewModel.project.bookmarkDataForDirectoryPath,
105119
directoryPath: $viewModel.project.directoryPath,
106120
isValid: $outputPathValid,
107-
onDirectorySelected: updateDirectoryPaths
121+
onDirectorySelected: updateDirectoryPaths,
122+
onDirectoryCopied: showCopiedMessage
108123
)
109124
}) {
110125
Text(.init(Lingua.ProjectForm.outputDirectoryHelp))
@@ -135,7 +150,8 @@ private extension ProjectFormView {
135150
title: Lingua.ProjectForm.stringsDirectory,
136151
bookmarkDataKey: viewModel.project.bookmarkDataForStringsDirectory,
137152
directoryPath: $viewModel.project.swiftCode.stringsDirectory,
138-
isValid: $stringsDirectoryValid
153+
isValid: $stringsDirectoryValid,
154+
onDirectoryCopied: showCopiedMessage
139155
)
140156
}) {
141157
Text(.init(Lingua.ProjectForm.lprojDirectoryHelp))
@@ -147,7 +163,8 @@ private extension ProjectFormView {
147163
title: Lingua.ProjectForm.linguaSwiftOutputDirectory,
148164
bookmarkDataKey: viewModel.project.bookmarkDataForOutputSwiftCodeFileDirectory ,
149165
directoryPath: $viewModel.project.swiftCode.outputSwiftCodeFileDirectory,
150-
isValid: $outputSwiftCodeFileDirectoryValid
166+
isValid: $outputSwiftCodeFileDirectoryValid,
167+
onDirectoryCopied: showCopiedMessage
151168
)
152169
}) {
153170
Text(.init(Lingua.ProjectForm.linguaSwiftOutputDirectoryHelp))
@@ -242,4 +259,15 @@ private extension ProjectFormView {
242259
try? firstLprojFullURL.saveBookmarkData(forKey: viewModel.project.bookmarkDataForStringsDirectory)
243260
}
244261
}
262+
263+
func showCopiedMessage() {
264+
withAnimation {
265+
copied = true
266+
}
267+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
268+
withAnimation {
269+
self.copied = false
270+
}
271+
}
272+
}
245273
}

Lingua-App/Lingua/Lingua/Utils/Components/UI/DirectoryInputField.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,46 @@ struct DirectoryInputField: View {
1313

1414
@Binding var directoryPath: String
1515
@Binding var isValid: Bool
16-
16+
@State private var isHovered = false
17+
1718
var onDirectorySelected: ((String) -> Void)? = nil
18-
19+
var onDirectoryCopied: (() -> Void)? = nil
20+
1921
var body: some View {
2022
HStack {
2123
ValidatingTextField(title: title, validation: RequiredRule(), isDisabled: true, text: $directoryPath, isValid: $isValid)
24+
.overlay {
25+
// Transparent overlay to capture tap gesture
26+
Color.clear
27+
.contentShape(Rectangle())
28+
.onTapGesture {
29+
copyPathToClipboard()
30+
onDirectoryCopied?()
31+
}
32+
}
33+
.onHover { hovering in
34+
isHovered = hovering
35+
}
2236
Button(Lingua.ProjectForm.inputDirectoryButton) {
2337
chooseDirectory()
2438
}
2539
}
2640
.padding(.vertical, 5)
41+
.background(
42+
GeometryReader { geometry in
43+
if isHovered {
44+
Text(directoryPath)
45+
.font(.caption)
46+
.padding(8)
47+
.background(Color.black.opacity(0.8))
48+
.foregroundColor(.white)
49+
.cornerRadius(8)
50+
.frame(width: geometry.size.width, alignment: .center)
51+
.offset(y: -geometry.size.height)
52+
.transition(.opacity)
53+
}
54+
}
55+
)
2756
}
2857
}
2958

@@ -53,4 +82,9 @@ private extension DirectoryInputField {
5382
directoryPath = ""
5483
}
5584
}
85+
86+
private func copyPathToClipboard() {
87+
NSPasteboard.general.clearContents()
88+
NSPasteboard.general.setString(directoryPath, forType: .string)
89+
}
5690
}

0 commit comments

Comments
 (0)