2020-09-28 19:20:06 +00:00
|
|
|
//
|
|
|
|
// ToolBar.swift
|
|
|
|
// Gemini-iOS
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/28/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import BrowserCore
|
|
|
|
|
|
|
|
struct ToolBar: View {
|
|
|
|
@ObservedObject var navigator: NavigationManager
|
2020-10-01 00:28:08 +00:00
|
|
|
@Binding var showShareSheet: Bool
|
2020-09-28 19:20:06 +00:00
|
|
|
@State private var showPreferencesSheet = false
|
|
|
|
|
|
|
|
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(spacing: 4) {
|
|
|
|
Rectangle()
|
|
|
|
.frame(height: 1)
|
|
|
|
.foregroundColor(Color(white: colorScheme == .dark ? 0.25 : 0.75))
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
// use a group because this exceeds the 10 view limit :/
|
|
|
|
Group {
|
|
|
|
Spacer()
|
|
|
|
|
2020-12-19 20:19:32 +00:00
|
|
|
Button(action: navigator.goBack) {
|
2020-09-28 19:20:06 +00:00
|
|
|
Image(systemName: "arrow.left")
|
|
|
|
.font(.system(size: 24))
|
|
|
|
}
|
2020-09-30 22:10:36 +00:00
|
|
|
.accessibility(label: Text("Back"))
|
2020-09-30 22:14:38 +00:00
|
|
|
.hoverEffect(.highlight)
|
2020-09-30 03:36:24 +00:00
|
|
|
.contextMenu {
|
|
|
|
ForEach(Array(navigator.backStack.suffix(5).enumerated()), id: \.1) { (index, url) in
|
|
|
|
Button {
|
|
|
|
navigator.back(count: min(5, navigator.backStack.count) - index)
|
|
|
|
} label: {
|
|
|
|
Text(verbatim: urlForDisplay(url))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 19:20:06 +00:00
|
|
|
.disabled(navigator.backStack.isEmpty)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2020-12-19 20:19:32 +00:00
|
|
|
Button(action: navigator.goForward) {
|
2020-09-28 19:20:06 +00:00
|
|
|
Image(systemName: "arrow.right")
|
|
|
|
.font(.system(size: 24))
|
|
|
|
}
|
2020-09-30 22:10:36 +00:00
|
|
|
.accessibility(label: Text("Forward"))
|
2020-09-30 22:14:38 +00:00
|
|
|
.hoverEffect(.highlight)
|
2020-09-30 03:36:24 +00:00
|
|
|
.contextMenu {
|
|
|
|
ForEach(navigator.forwardStack.prefix(5).enumerated().reversed(), id: \.1) { (index, url) in
|
|
|
|
Button {
|
|
|
|
navigator.forward(count: index + 1)
|
|
|
|
} label: {
|
|
|
|
Text(verbatim: urlForDisplay(url))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 19:20:06 +00:00
|
|
|
.disabled(navigator.forwardStack.isEmpty)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Button(action: navigator.reload) {
|
|
|
|
Image(systemName: "arrow.clockwise")
|
|
|
|
.font(.system(size: 24))
|
|
|
|
}
|
2020-09-30 22:10:36 +00:00
|
|
|
.accessibility(label: Text("Reload"))
|
2020-09-30 22:14:38 +00:00
|
|
|
.hoverEffect(.highlight)
|
2020-09-28 19:20:06 +00:00
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2020-10-01 00:28:08 +00:00
|
|
|
Button {
|
|
|
|
showShareSheet = true
|
|
|
|
} label: {
|
2020-09-28 19:20:06 +00:00
|
|
|
Image(systemName: "square.and.arrow.up")
|
|
|
|
.font(.system(size: 24))
|
|
|
|
}
|
2020-09-30 22:10:36 +00:00
|
|
|
.accessibility(label: Text("Share"))
|
2020-09-30 22:14:38 +00:00
|
|
|
.hoverEffect(.highlight)
|
2020-09-28 19:20:06 +00:00
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Button(action: {
|
|
|
|
showPreferencesSheet = true
|
|
|
|
}, label: {
|
|
|
|
Image(systemName: "gear")
|
|
|
|
.font(.system(size: 24))
|
|
|
|
})
|
2020-09-30 22:10:36 +00:00
|
|
|
.accessibility(label: Text("Preferences"))
|
2020-09-30 22:14:38 +00:00
|
|
|
.hoverEffect(.highlight)
|
2020-09-28 19:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
2020-09-28 19:49:02 +00:00
|
|
|
|
2020-09-28 19:20:06 +00:00
|
|
|
}
|
2020-09-29 19:28:33 +00:00
|
|
|
.padding(.bottom, 4)
|
2020-09-28 19:20:06 +00:00
|
|
|
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.bottom))
|
|
|
|
.sheet(isPresented: $showPreferencesSheet, content: {
|
2020-10-01 00:28:08 +00:00
|
|
|
PreferencesView()
|
2020-09-28 19:20:06 +00:00
|
|
|
})
|
|
|
|
}
|
2020-09-30 03:36:24 +00:00
|
|
|
|
|
|
|
private func urlForDisplay(_ url: URL) -> String {
|
|
|
|
var str = url.host!
|
|
|
|
if let port = url.port,
|
|
|
|
url.scheme != "gemini" || port != 1965 {
|
|
|
|
str += ":\(port)"
|
|
|
|
}
|
|
|
|
str += url.path
|
|
|
|
return str
|
|
|
|
}
|
2020-09-28 19:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ToolBar_Previews: PreviewProvider {
|
2020-10-01 00:28:08 +00:00
|
|
|
@State private static var showShareSheet = false
|
|
|
|
|
2020-09-28 19:20:06 +00:00
|
|
|
static var previews: some View {
|
2020-10-01 00:28:08 +00:00
|
|
|
ToolBar(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), showShareSheet: $showShareSheet)
|
2020-09-28 19:20:06 +00:00
|
|
|
}
|
|
|
|
}
|