Files
Pulse/Sources/PulseUI/Features/Console/ConsoleMessageListView-macos.swift
T
2021-11-08 16:45:55 -05:00

62 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 20202021 Alexander Grebenyuk (github.com/kean).
#if os(macOS)
import SwiftUI
import PulseCore
import CoreData
import Combine
import AppKit
struct ConsoleMessageListView: View {
@ObservedObject private var model: ConsoleViewModel
init(model: ConsoleViewModel) {
self.model = model
}
var body: some View {
ZStack {
let factory = ConsoleRowFactory(context: model.context, showInConsole: nil)
NotList(model: model.list, makeRowView: factory.makeRowView, onSelectRow: model.selectEntityAt, onDoubleClickRow: {
openMessage(model.list.elements[$0])
}, isEmphasizedRow: {
model.matches.isEmpty || model.isMatch(model.list.elements[$0])
})
NavigationLink(destination: ConsoleDetailsRouter(model: model.details), isActive: .constant(true)) { EmptyView() }
.hidden()
}
}
private func openMessage(_ message: LoggerMessageEntity) {
ExternalEvents.open = AnyView(
model.details.makeDetailsRouter(for: message)
.frame(minWidth: 500, idealWidth: 700, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, minHeight: 500, idealHeight: 800, maxHeight: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
)
guard let url = URL(string: "com-github-kean-pulse://open-details") else { return }
NSWorkspace.shared.open(url)
}
}
struct ConsoleDetailsRouter: View {
@ObservedObject var model: ConsoleDetailsRouterViewModel
var body: some View {
if let selectedEntity = model.selectedEntity {
model.makeDetailsRouter(for: selectedEntity)
.frame(minWidth: 480)
} else {
Text("No Selection")
.font(.title)
.foregroundColor(.secondary)
.toolbar(content: {
Spacer()
})
}
}
}
#endif