forked from CodeEditApp/CodeEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskDropDownView.swift
More file actions
90 lines (82 loc) · 2.9 KB
/
Copy pathTaskDropDownView.swift
File metadata and controls
90 lines (82 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// TaskDropDownView.swift
// CodeEdit
//
// Created by Tommy Ludwig on 24.06.24.
//
import SwiftUI
struct TaskDropDownView: View {
@Environment(\.colorScheme)
private var colorScheme
@ObservedObject var taskManager: TaskManager
@State private var isTaskPopOverPresented: Bool = false
@State private var isHoveringTasks: Bool = false
var body: some View {
Group {
if let selectedTask = taskManager.selectedTask {
if let selectedActiveTask = taskManager.activeTasks[selectedTask.id] {
ActiveTaskView(activeTask: selectedActiveTask)
.fixedSize()
} else {
TaskView(task: selectedTask, status: CETaskStatus.notRunning)
.fixedSize()
}
} else {
Text("Create Tasks")
}
}
.font(.subheadline)
.padding(.trailing, 11.5)
.padding(.horizontal, 2.5)
.padding(.vertical, 2.5)
.background(backgroundColor)
.onHover { hovering in
self.isHoveringTasks = hovering
}
.instantPopover(isPresented: $isTaskPopOverPresented, arrowEdge: .bottom) {
taskPopoverContent
}
.onTapGesture {
self.isTaskPopOverPresented.toggle()
}
}
private var backgroundColor: some View {
Color(nsColor: colorScheme == .dark ? .white : .black)
.opacity(isHoveringTasks || isTaskPopOverPresented ? 0.05 : 0)
.clipShape(RoundedRectangle(cornerSize: CGSize(width: 4, height: 4)))
.overlay(
HStack {
Spacer()
if isHoveringTasks || isTaskPopOverPresented {
chevronIcon
}
}
)
}
private var chevronIcon: some View {
Image(systemName: "chevron.down")
.font(.system(size: 8, weight: .bold, design: .default))
.padding(.top, 0.5)
.padding(.trailing, 2)
}
private var taskPopoverContent: some View {
VStack(alignment: .leading, spacing: 0) {
if !taskManager.availableTasks.isEmpty {
ForEach(taskManager.availableTasks, id: \.id) { task in
TasksPopoverMenuItem(taskManager: taskManager, task: task)
}
Divider()
.padding(.vertical, 5)
}
OptionMenuItemView(label: "Add Task...") {
NSApp.sendAction(#selector(CodeEditWindowController.openWorkspaceSettings(_:)), to: nil, from: nil)
}
OptionMenuItemView(label: "Manage Tasks...") {
NSApp.sendAction(#selector(CodeEditWindowController.openWorkspaceSettings(_:)), to: nil, from: nil)
}
}
.font(.subheadline)
.padding(5)
.frame(minWidth: 215)
}
}