Skip to content

Custom(izable) Navigator Sidebar Implementation #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 51 additions & 39 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import WorkspaceClient
import Search

struct SidebarSearch: View {
struct FindNavigator: View {
@ObservedObject var state: WorkspaceDocument.SearchState
@State private var searchText: String = ""

Expand All @@ -24,8 +24,8 @@ struct SidebarSearch: View {
var body: some View {
VStack {
VStack {
SearchModeSelector()
SearchBar(state: state, title: "", text: $searchText)
FindNavigatorModeSelector()
FindNavigatorSearchBar(state: state, title: "", text: $searchText)
HStack {
Spacer()
}
Expand All @@ -39,7 +39,7 @@ struct SidebarSearch: View {
.font(.system(size: 10))
}
Divider()
SearchResultList(state: state)
FindNavigatorResultList(state: state)
}
.onSubmit {
state.search(searchText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI
import Search

struct SearchModeSelector: View {
struct FindNavigatorModeSelector: View {
@State var selectedMode: [SearchModeModel] = [
.Find,
.Text,
Expand Down Expand Up @@ -115,6 +115,6 @@ extension View {

struct SearchModeSelector_Previews: PreviewProvider {
static var previews: some View {
SearchModeSelector()
FindNavigatorModeSelector()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import WorkspaceClient
import Search

struct SearchResultFileItem: View {
struct FindNavigatorResultFileItem: View {
@ObservedObject var state: WorkspaceDocument.SearchState
@State var isExpanded: Bool = true
var fileItem: WorkspaceClient.FileItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import WorkspaceClient
import Search

struct SearchResultList: View {
struct FindNavigatorResultList: View {
@ObservedObject var state: WorkspaceDocument.SearchState
@State var selectedResult: SearchResultModel?

Expand All @@ -24,7 +24,7 @@ struct SearchResultList: View {
var body: some View {
List(selection: $selectedResult) {
ForEach(foundFiles, id: \.self) { (foundFile: SearchResultModel) in
SearchResultFileItem(
FindNavigatorResultFileItem(
state: state,
fileItem: foundFile.file, results: getResultWith(foundFile.file)) {
state.workspace.openFile(item: foundFile.file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

struct SearchBar: View {
struct FindNavigatorSearchBar: View {
@ObservedObject var state: WorkspaceDocument.SearchState
let title: String
@Binding var text: String
Expand Down Expand Up @@ -45,7 +45,11 @@ struct SearchBar: View {
struct SearchBar_Previews: PreviewProvider {
static var previews: some View {
HStack {
SearchBar(state: .init(WorkspaceDocument.init()), title: "placeholder", text: .constant("value"))
FindNavigatorSearchBar(
state: .init(WorkspaceDocument.init()),
title: "placeholder",
text: .constant("value")
)
}
.padding()
}
Expand Down
35 changes: 35 additions & 0 deletions CodeEdit/NavigatorSidebar/LeadingSidebar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// SideBar.swift
// CodeEdit
//
// Created by Lukas Pistrol on 17.03.22.
//

import SwiftUI
import WorkspaceClient

struct LeadingSidebar: View {
@ObservedObject var workspace: WorkspaceDocument
var windowController: NSWindowController
@State private var selection: Int = 0

var body: some View {
ZStack {
switch selection {
case 0:
ProjectNavigator(workspace: workspace, windowController: windowController)
case 2:
FindNavigator(state: workspace.searchState ?? .init(workspace))
default:
VStack { Spacer() }
}
}
.safeAreaInset(edge: .top) {
LeadingSidebarToolbarTop(selection: $selection)
.padding(.bottom, -8)
}
.safeAreaInset(edge: .bottom) {
LeadingSidebarToolbarBottom(workspace: workspace)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import SwiftUI

struct NavigatorSidebarToolbarBottom: View {
struct LeadingSidebarToolbarBottom: View {
@Environment(\.controlActiveState) var activeState

@ObservedObject var workspace: WorkspaceDocument

Expand Down Expand Up @@ -37,6 +38,7 @@ struct NavigatorSidebarToolbarBottom: View {
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.frame(maxWidth: 30)
.opacity(activeState == .inactive ? 0.45 : 1)
}

private var sortButton: some View {
Expand All @@ -51,5 +53,6 @@ struct NavigatorSidebarToolbarBottom: View {
}
.menuStyle(.borderlessButton)
.frame(maxWidth: 30)
.opacity(activeState == .inactive ? 0.45 : 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import SwiftUI

struct NavigatorSidebarToolbarTop: View {
struct LeadingSidebarToolbarTop: View {
@Environment(\.controlActiveState) var activeState

@Binding var selection: Int

var body: some View {
Expand Down Expand Up @@ -42,13 +44,14 @@ struct NavigatorSidebarToolbarTop: View {
.foregroundColor(id == selection ? .accentColor : .secondary)
.frame(width: 25, height: 25, alignment: .center)
.contentShape(Rectangle())
.opacity(activeState == .inactive ? 0.45 : 1)
}
.buttonStyle(.plain)
}
}

struct NavigatorSidebarToolbar_Previews: PreviewProvider {
static var previews: some View {
NavigatorSidebarToolbarTop(selection: .constant(0))
LeadingSidebarToolbarTop(selection: .constant(0))
}
}
47 changes: 0 additions & 47 deletions CodeEdit/NavigatorSidebar/NavigatorSidebar.swift

This file was deleted.

132 changes: 0 additions & 132 deletions CodeEdit/NavigatorSidebar/NavigatorSidebarItem.swift

This file was deleted.

Loading