mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Inspector View
Inspector Views for macOS and iOS
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// InspectorPlatformModifier.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 18/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct InspectorPlatformModifier: ViewModifier {
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@Binding var shouldUpdate: Bool
|
||||
|
||||
@ViewBuilder func body(content: Content) -> some View {
|
||||
|
||||
#if os(macOS)
|
||||
content
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.frame(width: 300)
|
||||
.padding()
|
||||
#else
|
||||
NavigationView {
|
||||
content
|
||||
.navigationBarTitle("Inspector", displayMode: .inline)
|
||||
.navigationBarItems(
|
||||
leading:
|
||||
Button("Cancel", action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}),
|
||||
trailing:
|
||||
Button("Confirm", action: {
|
||||
shouldUpdate = true
|
||||
})
|
||||
)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
182
Multiplatform/Shared/Inspector/InspectorView.swift
Normal file
182
Multiplatform/Shared/Inspector/InspectorView.swift
Normal file
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// InspectorView.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 18/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import RSCore
|
||||
import Account
|
||||
|
||||
struct InspectorView: View {
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@StateObject private var feedIconImageLoader = FeedIconImageLoader()
|
||||
@State private var editedName: String = ""
|
||||
@State private var shouldUpdate: Bool = false
|
||||
var sidebarItem: SidebarItem
|
||||
|
||||
@ViewBuilder
|
||||
var body: some View {
|
||||
switch sidebarItem.representedType {
|
||||
case .webFeed:
|
||||
WebFeedInspectorView
|
||||
.modifier(InspectorPlatformModifier(shouldUpdate: $shouldUpdate))
|
||||
case .folder:
|
||||
FolderInspectorView
|
||||
.modifier(InspectorPlatformModifier(shouldUpdate: $shouldUpdate))
|
||||
case .account:
|
||||
AccountInspectorView
|
||||
.modifier(InspectorPlatformModifier(shouldUpdate: $shouldUpdate))
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
var WebFeedInspectorView: some View {
|
||||
Form {
|
||||
Section(header: Text("Name").bold()) {
|
||||
HStack(alignment: .center) {
|
||||
if let image = feedIconImageLoader.image {
|
||||
IconImageView(iconImage: image)
|
||||
.frame(width: 30, height: 30)
|
||||
}
|
||||
TextField("", text: $editedName)
|
||||
}
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
Divider()
|
||||
#endif
|
||||
|
||||
Section(header: Text("Home Page URL").bold()) {
|
||||
Text((sidebarItem.feed as? WebFeed)?.homePageURL ?? "")
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
Divider()
|
||||
#endif
|
||||
|
||||
Section(header: Text("Feed URL").bold()) {
|
||||
Text((sidebarItem.feed as? WebFeed)?.url ?? "")
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel", action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
})
|
||||
Button("Confirm", action: {
|
||||
shouldUpdate = true
|
||||
})
|
||||
}.padding(.top)
|
||||
#endif
|
||||
}
|
||||
.onAppear {
|
||||
editedName = sidebarItem.nameForDisplay
|
||||
feedIconImageLoader.loadImage(for: sidebarItem.feed!)
|
||||
}.onChange(of: shouldUpdate) { value in
|
||||
if value == true {
|
||||
if editedName.trimmingWhitespace.count > 0 {
|
||||
(sidebarItem.feed as? WebFeed)?.editedName = editedName
|
||||
} else {
|
||||
(sidebarItem.feed as? WebFeed)?.editedName = nil
|
||||
}
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
var FolderInspectorView: some View {
|
||||
|
||||
Form {
|
||||
Section(header: Text("Name").bold()) {
|
||||
HStack(alignment: .center) {
|
||||
if let image = feedIconImageLoader.image {
|
||||
IconImageView(iconImage: image)
|
||||
.frame(width: 30, height: 30)
|
||||
}
|
||||
TextField("", text: $editedName)
|
||||
}
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel", action: {
|
||||
(sidebarItem.feed as? Folder)?.name = nil
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
})
|
||||
Button("Confirm", action: {
|
||||
shouldUpdate = true
|
||||
})
|
||||
}.padding(.top)
|
||||
#endif
|
||||
|
||||
}
|
||||
.onAppear {
|
||||
editedName = sidebarItem.nameForDisplay
|
||||
feedIconImageLoader.loadImage(for: sidebarItem.feed!)
|
||||
}
|
||||
.onChange(of: shouldUpdate) { value in
|
||||
if value == true {
|
||||
if editedName.trimmingWhitespace.count > 0 {
|
||||
(sidebarItem.feed as? Folder)?.name = editedName
|
||||
} else {
|
||||
(sidebarItem.feed as? Folder)?.name = nil
|
||||
}
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
var AccountInspectorView: some View {
|
||||
Form {
|
||||
Section(header: Text("Name").bold()) {
|
||||
HStack(alignment: .center) {
|
||||
if let image = (sidebarItem.represented as? Account)?.smallIcon?.image {
|
||||
Image(rsImage: image)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 30, height: 30)
|
||||
}
|
||||
TextField("", text: $editedName)
|
||||
}
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel", action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
})
|
||||
Button("Confirm", action: {
|
||||
shouldUpdate = true
|
||||
})
|
||||
}.padding(.top)
|
||||
#endif
|
||||
}
|
||||
.onAppear {
|
||||
editedName = sidebarItem.nameForDisplay
|
||||
}.onChange(of: shouldUpdate) { value in
|
||||
if value == true {
|
||||
if editedName.trimmingWhitespace.count > 0 {
|
||||
(sidebarItem.represented as? Account)?.name = editedName
|
||||
} else {
|
||||
(sidebarItem.represented as? Account)?.name = nil
|
||||
}
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,15 @@ import SwiftUI
|
||||
|
||||
struct SidebarContextMenu: View {
|
||||
|
||||
@Binding var showInspector: Bool
|
||||
var sidebarItem: SidebarItem
|
||||
|
||||
|
||||
@ViewBuilder var body: some View {
|
||||
|
||||
if sidebarItem.representedType == .account {
|
||||
Button {
|
||||
showInspector = true
|
||||
} label: {
|
||||
Text("Get Info")
|
||||
#if os(iOS)
|
||||
@@ -43,6 +46,7 @@ struct SidebarContextMenu: View {
|
||||
|
||||
if sidebarItem.representedType == .webFeed {
|
||||
Button {
|
||||
showInspector = true
|
||||
} label: {
|
||||
Text("Get Info")
|
||||
#if os(iOS)
|
||||
@@ -106,6 +110,7 @@ struct SidebarContextMenu: View {
|
||||
}
|
||||
Divider()
|
||||
Button {
|
||||
showInspector = true
|
||||
} label: {
|
||||
Text("Rename")
|
||||
#if os(iOS)
|
||||
|
||||
@@ -12,13 +12,14 @@ import Account
|
||||
struct SidebarItemView: View {
|
||||
|
||||
@StateObject var feedIconImageLoader = FeedIconImageLoader()
|
||||
@State private var showInspector: Bool = false
|
||||
var sidebarItem: SidebarItem
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
if let image = feedIconImageLoader.image {
|
||||
IconImageView(iconImage: image)
|
||||
.frame(width: 20, height: 20, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
|
||||
.frame(width: 20, height: 20, alignment: .center)
|
||||
}
|
||||
Text(verbatim: sidebarItem.nameForDisplay)
|
||||
Spacer()
|
||||
@@ -37,7 +38,10 @@ struct SidebarItemView: View {
|
||||
feedIconImageLoader.loadImage(for: feed)
|
||||
}
|
||||
}.contextMenu {
|
||||
SidebarContextMenu(sidebarItem: sidebarItem)
|
||||
SidebarContextMenu(showInspector: $showInspector, sidebarItem: sidebarItem)
|
||||
}
|
||||
.sheet(isPresented: $showInspector, onDismiss: { showInspector = false}) {
|
||||
InspectorView(sidebarItem: sidebarItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +190,8 @@ struct SidebarView: View {
|
||||
|
||||
@ViewBuilder var body: some View {
|
||||
#if os(macOS)
|
||||
SidebarItemView(sidebarItem: sidebarItem).tag(sidebarItem.feed!.feedID!)
|
||||
SidebarItemView(sidebarItem: sidebarItem)
|
||||
.tag(sidebarItem.feed!.feedID!)
|
||||
#else
|
||||
ZStack {
|
||||
SidebarItemView(sidebarItem: sidebarItem)
|
||||
|
||||
Reference in New Issue
Block a user