Skip to content

Commit 9b20bf1

Browse files
committed
feat: add compact header action menus
1 parent e6a647d commit 9b20bf1

9 files changed

Lines changed: 227 additions & 75 deletions

File tree

‎EdgeMark/Resources/Locales/de.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"common.ok": "OK",
1818
"common.back": "Zurück",
1919
"common.search": "Suchen",
20+
"common.moreActions": "Weitere Aktionen",
2021
"common.untitled": "Unbenannt",
2122
"common.root": "Root",
2223
"common.newFolder": "Neuer Ordner",

‎EdgeMark/Resources/Locales/en.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"common.ok": "OK",
1818
"common.back": "Back",
1919
"common.search": "Search",
20+
"common.moreActions": "More Actions",
2021
"common.untitled": "Untitled",
2122
"common.root": "Root",
2223
"common.newFolder": "New Folder",

‎EdgeMark/Resources/Locales/es.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"common.ok": "Aceptar",
1818
"common.back": "Atrás",
1919
"common.search": "Buscar",
20+
"common.moreActions": "Más acciones",
2021
"common.untitled": "Sin título",
2122
"common.root": "Raíz",
2223
"common.newFolder": "Nueva carpeta",

‎EdgeMark/Resources/Locales/hi.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"common.ok": "ठीक है",
1818
"common.back": "वापस",
1919
"common.search": "सर्च",
20+
"common.moreActions": "अधिक क्रियाएँ",
2021
"common.untitled": "बिना शीर्षक",
2122
"common.root": "रूट",
2223
"common.newFolder": "नया फ़ोल्डर",

‎EdgeMark/Resources/Locales/zh-Hans.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"common.ok": "好",
1818
"common.back": "返回",
1919
"common.search": "搜索",
20+
"common.moreActions": "更多操作",
2021
"common.untitled": "无标题",
2122
"common.root": "根目录",
2223
"common.newFolder": "新建文件夹",
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import SwiftUI
2+
3+
/// A compact overflow control that reveals header actions on hover and click.
4+
/// The popover preserves the header's layout, so titles never move as actions appear.
5+
struct HeaderActionMenu<MenuContent: View>: View {
6+
let help: String
7+
private let menuContent: (@escaping () -> Void) -> MenuContent
8+
9+
@State private var isPresented = false
10+
@State private var revealTask: Task<Void, Never>?
11+
@State private var dismissTask: Task<Void, Never>?
12+
13+
init(
14+
help: String,
15+
@ViewBuilder content: @escaping (@escaping () -> Void) -> MenuContent,
16+
) {
17+
self.help = help
18+
menuContent = content
19+
}
20+
21+
var body: some View {
22+
AdaptiveIconButton(
23+
systemName: "ellipsis",
24+
help: help,
25+
isActive: isPresented,
26+
) {
27+
cancelScheduledTransitions()
28+
isPresented.toggle()
29+
}
30+
.onHover { hovering in
31+
if hovering {
32+
scheduleReveal()
33+
} else {
34+
scheduleDismiss()
35+
}
36+
}
37+
.popover(
38+
isPresented: $isPresented,
39+
attachmentAnchor: .rect(.bounds),
40+
arrowEdge: .top,
41+
) {
42+
menuContent(dismiss)
43+
.padding(6)
44+
.frame(minWidth: 190)
45+
.onHover { hovering in
46+
if hovering {
47+
dismissTask?.cancel()
48+
} else {
49+
scheduleDismiss()
50+
}
51+
}
52+
}
53+
.onDisappear(perform: cancelScheduledTransitions)
54+
}
55+
56+
private func scheduleReveal() {
57+
dismissTask?.cancel()
58+
guard !isPresented else { return }
59+
revealTask?.cancel()
60+
revealTask = Task { @MainActor in
61+
try? await Task.sleep(nanoseconds: 120_000_000)
62+
guard !Task.isCancelled else { return }
63+
isPresented = true
64+
}
65+
}
66+
67+
private func scheduleDismiss() {
68+
revealTask?.cancel()
69+
dismissTask?.cancel()
70+
dismissTask = Task { @MainActor in
71+
try? await Task.sleep(nanoseconds: 280_000_000)
72+
guard !Task.isCancelled else { return }
73+
isPresented = false
74+
}
75+
}
76+
77+
private func dismiss() {
78+
cancelScheduledTransitions()
79+
isPresented = false
80+
}
81+
82+
private func cancelScheduledTransitions() {
83+
revealTask?.cancel()
84+
dismissTask?.cancel()
85+
}
86+
}
87+
88+
/// A full-width action row used inside `HeaderActionMenu` popovers.
89+
struct HeaderActionButton: View {
90+
let title: String
91+
let systemName: String
92+
var role: ButtonRole?
93+
let action: () -> Void
94+
95+
@State private var isHovered = false
96+
97+
var body: some View {
98+
Button(role: role, action: action) {
99+
HStack(spacing: 8) {
100+
Image(systemName: systemName)
101+
.frame(width: 18)
102+
Text(title)
103+
Spacer(minLength: 16)
104+
}
105+
.foregroundStyle(foregroundColor)
106+
.padding(.horizontal, 10)
107+
.frame(maxWidth: .infinity, minHeight: 30, alignment: .leading)
108+
.contentShape(Rectangle())
109+
.background {
110+
RoundedRectangle(cornerRadius: 6, style: .continuous)
111+
.fill(.primary.opacity(isHovered ? 0.1 : 0))
112+
}
113+
}
114+
.buttonStyle(.plain)
115+
.onHover { hovering in
116+
withAnimation(.easeInOut(duration: 0.12)) {
117+
isHovered = hovering
118+
}
119+
}
120+
}
121+
122+
private var foregroundColor: Color {
123+
if role == .destructive, isHovered {
124+
return .red
125+
}
126+
return isHovered ? .primary : .secondary
127+
}
128+
}

‎EdgeMark/UI/EditorScreen.swift‎

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ struct EditorScreen: View {
145145

146146
Spacer()
147147

148-
PanelToolbarGroup {
148+
HStack(spacing: SurfaceMetrics.controlGroupSpacing) {
149149
PinButton()
150150

151-
CopyMenuButton(note: note)
152-
153-
DeleteIconButton {
154-
showDeleteConfirm = true
151+
HeaderActionMenu(help: l10n["common.moreActions"]) { dismiss in
152+
EditorActionMenuContent(
153+
note: note,
154+
dismiss: dismiss,
155+
onDelete: { showDeleteConfirm = true },
156+
)
155157
}
156158
}
157159
}
@@ -178,32 +180,43 @@ struct EditorScreen: View {
178180
}
179181
}
180182

181-
// MARK: - Copy Menu Button
183+
// MARK: - Editor Action Menu
182184

183-
/// Copy icon that opens a menu with plain text and Markdown copy options.
184-
/// If text is selected in the editor, copies the selection; otherwise copies the whole document.
185-
private struct CopyMenuButton: View {
185+
/// Editor overflow actions. If text is selected, copy actions use the selection;
186+
/// otherwise they use the whole document.
187+
private struct EditorActionMenuContent: View {
186188
let note: Note
189+
let dismiss: () -> Void
190+
let onDelete: () -> Void
187191

188192
var body: some View {
189193
let l10n = L10n.shared
190-
return AdaptiveIconMenu(
191-
systemName: "doc.on.doc",
192-
help: l10n["editor.copyNote"],
193-
) {
194-
Button(l10n["common.copyPlainText"]) {
194+
VStack(spacing: 2) {
195+
HeaderActionButton(
196+
title: l10n["common.copyPlainText"],
197+
systemName: "doc.on.doc",
198+
) {
199+
dismiss()
195200
let selected = Self.getSelectedText()
196201
let source = selected.isEmpty ? note.content : selected
197202
NSPasteboard.general.clearContents()
198203
NSPasteboard.general.setString(Note.plainText(from: source), forType: .string)
199204
}
200-
Button(l10n["common.copyMarkdown"]) {
205+
HeaderActionButton(
206+
title: l10n["common.copyMarkdown"],
207+
systemName: "doc.text",
208+
) {
209+
dismiss()
201210
let selected = Self.getSelectedText()
202211
let text = selected.isEmpty ? note.content : selected
203212
NSPasteboard.general.clearContents()
204213
NSPasteboard.general.setString(text, forType: .string)
205214
}
206-
Button(l10n["common.copyRTF"]) {
215+
HeaderActionButton(
216+
title: l10n["common.copyRTF"],
217+
systemName: "doc.richtext",
218+
) {
219+
dismiss()
207220
let selected = Self.getSelectedText()
208221
let source = selected.isEmpty ? note.content : selected
209222
let pb = NSPasteboard.general
@@ -214,6 +227,18 @@ private struct CopyMenuButton: View {
214227
pb.setString(Note.plainText(from: source), forType: .string)
215228
}
216229
}
230+
231+
Divider()
232+
.padding(.vertical, 2)
233+
234+
HeaderActionButton(
235+
title: l10n["editor.deleteNote"],
236+
systemName: "trash",
237+
role: .destructive,
238+
) {
239+
dismiss()
240+
onDelete()
241+
}
217242
}
218243
}
219244

@@ -225,22 +250,6 @@ private struct CopyMenuButton: View {
225250
}
226251
}
227252

228-
// MARK: - Delete Icon Button
229-
230-
/// Trash icon that turns red on hover.
231-
private struct DeleteIconButton: View {
232-
let action: () -> Void
233-
234-
var body: some View {
235-
AdaptiveIconButton(
236-
systemName: "trash",
237-
help: L10n.shared["editor.deleteNote"],
238-
role: .destructive,
239-
action: action,
240-
)
241-
}
242-
}
243-
244253
// MARK: - Date Label View
245254

246255
/// Icon + date text in a compact row with hover tooltip.

‎EdgeMark/UI/Navigation/HomeFolderView.swift‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,29 +239,34 @@ struct HomeFolderView: View {
239239

240240
Spacer()
241241

242-
PanelToolbarGroup {
242+
HStack(spacing: SurfaceMetrics.controlGroupSpacing) {
243243
PinButton()
244244

245-
HeaderIconButton(
246-
systemName: "magnifyingglass",
247-
help: l10n["common.search"],
248-
) {
249-
isSearching = true
250-
isSearchFieldFocused = true
251-
}
252-
253-
HeaderIconButton(
254-
systemName: "folder.badge.plus",
255-
help: l10n["common.newFolder"],
256-
) {
257-
startCreatingFolder()
258-
}
259-
260-
HeaderIconButton(
261-
systemName: "square.and.pencil",
262-
help: l10n["common.newNote"],
263-
) {
264-
createRootNote()
245+
HeaderActionMenu(help: l10n["common.moreActions"]) { dismiss in
246+
VStack(spacing: 2) {
247+
HeaderActionButton(
248+
title: l10n["common.search"],
249+
systemName: "magnifyingglass",
250+
) {
251+
dismiss()
252+
isSearching = true
253+
isSearchFieldFocused = true
254+
}
255+
HeaderActionButton(
256+
title: l10n["common.newFolder"],
257+
systemName: "folder.badge.plus",
258+
) {
259+
dismiss()
260+
startCreatingFolder()
261+
}
262+
HeaderActionButton(
263+
title: l10n["common.newNote"],
264+
systemName: "square.and.pencil",
265+
) {
266+
dismiss()
267+
createRootNote()
268+
}
269+
}
265270
}
266271
}
267272
}

0 commit comments

Comments
 (0)