Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
ed13435
Semi working version of splitview
Wouter01 Feb 20, 2023
0136853
added custom splitview + some debug views
Wouter01 Feb 23, 2023
345ae0e
Add even splitting on new tabs
thecoolwinter Feb 23, 2023
2f29821
removed unused variable in SplitViewController
Wouter01 Feb 24, 2023
db68394
Merge branch 'main' into splitview
Wouter01 Feb 24, 2023
221841b
Added tab selection logic
Wouter01 Feb 24, 2023
88daa71
partially fixed edgeinsets
Wouter01 Feb 24, 2023
9015e32
Fixed top toolbar edgeinsets
Wouter01 Feb 24, 2023
080039a
Moved isBelowToolbar to environment
Wouter01 Feb 24, 2023
e98c802
Partial support for statusbarview (expanded wip)
Wouter01 Feb 24, 2023
bea430e
Fixed terminal view
Wouter01 Feb 27, 2023
6eaf8c5
fixed some things regarding splitview
Wouter01 Mar 1, 2023
2c266bd
added filter bar to terminal view
Wouter01 Mar 1, 2023
f23e8ea
Fixed small issues
Wouter01 Mar 1, 2023
4ae956c
statusbarview height fixes
Wouter01 Mar 1, 2023
4fbb872
Removed excess background
Wouter01 Mar 1, 2023
db08422
Focus fixes
Wouter01 Mar 1, 2023
5c81da8
size fixes for statusbar
Wouter01 Mar 1, 2023
76dad92
small fix
Wouter01 Mar 1, 2023
38787f1
Added ability to close splitview
Wouter01 Mar 1, 2023
f273443
Fixed some logic regarding closing splitviews
Wouter01 Mar 2, 2023
5d4266e
Refactored tabs management
Wouter01 Mar 3, 2023
f7c700f
removed unused function
Wouter01 Mar 3, 2023
c1dcda0
Merge branch 'main' into splitview
Wouter01 Mar 3, 2023
4e5a9e2
Cleaned up code
Wouter01 Mar 3, 2023
8f44c07
Moved over code from workspacedocument
Wouter01 Mar 4, 2023
31f15a8
Further cleaned up code
Wouter01 Mar 4, 2023
e645c30
Fixed references to selectionState
Wouter01 Mar 4, 2023
07d5a33
Removed references to selectionstate
Wouter01 Mar 4, 2023
699429a
Removed commented out functions
Wouter01 Mar 4, 2023
1422d7f
Bugfixes
Wouter01 Mar 4, 2023
62fa64a
small fixes
Wouter01 Mar 4, 2023
3e04a94
renamed variables
Wouter01 Mar 4, 2023
430c5a6
Removed unneeded Task
Wouter01 Mar 4, 2023
7dc906e
Fixed issue with NSSplitView
Wouter01 Mar 4, 2023
c29cbc4
Added functionality to split button
Wouter01 Mar 4, 2023
f0c55a8
Fixed issue with breadcrumbsview
Wouter01 Mar 4, 2023
d568f29
breadcrumbs are grayed out when out of focus
Wouter01 Mar 5, 2023
b456694
Added forward/backward functionality
Wouter01 Mar 5, 2023
6d17cbc
small cleanup
Wouter01 Mar 5, 2023
520d967
Added custom move buttonstyle
Wouter01 Mar 5, 2023
aefd004
Fixed some logic, removed animations
Wouter01 Mar 5, 2023
0cbd085
renamed split buttons
Wouter01 Mar 5, 2023
1352f19
Fixed abug where the app would freeze if file contents are empty
Wouter01 Mar 5, 2023
7d46414
Fixed temporary tabs
Wouter01 Mar 5, 2023
9a98b2f
Fixed force unwrap crash
Wouter01 Mar 5, 2023
0ad3190
removed prints
Wouter01 Mar 5, 2023
7c20ebc
Removed TODOs
Wouter01 Mar 5, 2023
d119168
Merge branch 'main' into splitview
Wouter01 Mar 5, 2023
0dbe98f
fixed warnings
Wouter01 Mar 5, 2023
de91764
Added docs
Wouter01 Mar 5, 2023
2cd5670
Reorganised some files
Wouter01 Mar 5, 2023
a5c6d6a
Fixed scrolling to active tab
Wouter01 Mar 5, 2023
1c08816
Fixed warning
Wouter01 Mar 5, 2023
584b13c
Fixed tabbar scroll glitch
Wouter01 Mar 5, 2023
2bc1cf2
fixed tabbarview active state
Wouter01 Mar 6, 2023
0495ff8
renamed WorkspaceSplitViewData to SplitViewData
Wouter01 Mar 6, 2023
ddf9e63
adds splitview flattening
Wouter01 Mar 6, 2023
b8c23f3
Fixed warning
Wouter01 Mar 6, 2023
c5471fe
Removed unused dependency
Wouter01 Mar 6, 2023
58f7712
Changed representation of temporary tab
Wouter01 Mar 6, 2023
2b6674e
Fixed some issues regarding tabbarview
Wouter01 Mar 6, 2023
53a1f5a
Fixed animation
Wouter01 Mar 6, 2023
c1a3f87
Removed splitview button animation
Wouter01 Mar 6, 2023
6ae26e8
fixed text coloring in light mode
Wouter01 Mar 6, 2023
7915d65
improvements to tabbar and breadcrumbs in light mode
Wouter01 Mar 6, 2023
b0d37dd
New splitted editor now has focus by default
Wouter01 Mar 6, 2023
5392ac4
Empty tabgroup can get focus
Wouter01 Mar 6, 2023
dd1a35f
Fixed memory leak
Wouter01 Mar 6, 2023
3d3a2ad
test for improved focus
Wouter01 Mar 6, 2023
6a4f313
other fix for focus
Wouter01 Mar 6, 2023
a7da959
new try for focus
Wouter01 Mar 6, 2023
edb8945
reverted changes
Wouter01 Mar 6, 2023
7acd8bd
code style fixes
Wouter01 Mar 6, 2023
99111f8
Code style fixes
Wouter01 Mar 6, 2023
b847242
code style fix
Wouter01 Mar 6, 2023
b58551a
Code style fixes
Wouter01 Mar 6, 2023
6059020
Added docs
Wouter01 Mar 6, 2023
b742551
Fixed scroll to active tab on editor width change
Wouter01 Mar 6, 2023
120e3a7
Fixed warnings
Wouter01 Mar 6, 2023
8362f49
Fix for focus
Wouter01 Mar 7, 2023
7fd8849
Fixed issues regarding tabbarview
Wouter01 Mar 8, 2023
be9de5c
Fixed minor issues
Wouter01 Mar 8, 2023
3854686
Fixed focus issue for history buttons
Wouter01 Mar 8, 2023
31aa3c2
removed transparent titlebar for native tab style
Wouter01 Mar 8, 2023
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
119 changes: 108 additions & 11 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ final class AppPreferencesModel: ObservableObject {
var preferences: AppPreferences {
didSet {
try? savePreferences()
objectWillChange.send()
}
}

Expand Down
34 changes: 20 additions & 14 deletions CodeEdit/Features/Breadcrumbs/Views/BreadcrumbsComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Combine

struct BreadcrumbsComponent: View {

Expand Down Expand Up @@ -59,14 +60,19 @@ struct BreadcrumbsComponent: View {
}

struct NSPopUpButtonView<ItemType>: NSViewRepresentable where ItemType: Equatable {
@Binding var selection: ItemType
@Binding
var selection: ItemType

var popupCreator: () -> NSPopUpButton

typealias NSViewType = NSPopUpButton

func makeNSView(context: NSViewRepresentableContext<NSPopUpButtonView>) -> NSPopUpButton {
let newPopupButton = popupCreator()
setPopUpFromSelection(newPopupButton, selection: selection)
if let menu = newPopupButton.menu {
context.coordinator.registerForChanges(in: menu)
}
return newPopupButton
}

Expand All @@ -89,24 +95,24 @@ struct BreadcrumbsComponent: View {
}

class Coordinator: NSObject {
var parent: NSPopUpButtonView!
var parent: NSPopUpButtonView

var cancellable: AnyCancellable?

init(_ parent: NSPopUpButtonView) {
super.init()
self.parent = parent
NotificationCenter.default.addObserver(
self,
selector: #selector(dropdownItemSelected),
name: NSMenu.didSendActionNotification,
object: nil
)
super.init()
}

@objc func dropdownItemSelected(_ notification: NSNotification) {
let menuItem = (notification.userInfo?["MenuItem"])! as? NSMenuItem
if let selection = menuItem?.representedObject as? ItemType {
parent.selection = selection
}
func registerForChanges(in menu: NSMenu) {
cancellable = NotificationCenter.default
.publisher(for: NSMenu.didSendActionNotification, object: menu)
.sink { notification in
if let menuItem = notification.userInfo?["MenuItem"] as? NSMenuItem,
let selection = menuItem as? ItemType {
self.parent.selection = selection
}
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions CodeEdit/Features/Breadcrumbs/Views/BreadcrumbsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ struct BreadcrumbsView: View {
@Environment(\.colorScheme)
private var colorScheme

@Environment(\.isActiveTabGroup)
private var isActiveTabGroup

@Environment(\.controlActiveState)
private var activeState

static let height = 27.0

init(
file: WorkspaceClient.FileItem,
tappedOpenFile: @escaping (WorkspaceClient.FileItem) -> Void
Expand Down Expand Up @@ -51,8 +56,10 @@ struct BreadcrumbsView: View {
}
.padding(.horizontal, 10)
}
.frame(height: 27, alignment: .center)
.background(EffectView(.headerView).frame(height: 27))
.frame(height: Self.height, alignment: .center)
.opacity(activeState == .inactive ? 0.8 : 1.0)
.grayscale(isActiveTabGroup ? 0.0 : 1.0)
.background(EffectView(.headerView).frame(height: Self.height))
}

private var chevron: some View {
Expand Down
12 changes: 10 additions & 2 deletions CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ struct CodeFileView: View {
return AppPreferencesModel.shared.preferences.textEditing.font.current()
}()

@Environment(\.edgeInsets)
private var edgeInsets

@EnvironmentObject
private var tabgroup: TabGroupData

var body: some View {
CodeEditTextView(
$codeFile.content,
Expand All @@ -70,7 +76,8 @@ struct CodeFileView: View {
lineHeight: $prefs.preferences.textEditing.lineHeightMultiple,
wrapLines: $prefs.preferences.textEditing.wrapLinesToEditorWidth,
cursorPosition: codeFile.$cursorPosition,
useThemeBackground: prefs.preferences.theme.useThemeBackground
useThemeBackground: prefs.preferences.theme.useThemeBackground,
contentInsets: edgeInsets.nsEdgeInsets
)
.id(codeFile.fileURL)
.background {
Expand All @@ -90,7 +97,8 @@ struct CodeFileView: View {
}
}
.disabled(!editable)
.frame(maxHeight: .infinity)
// minHeight zero fixes a bug where the app would freeze if the contents of the file are empty.
.frame(minHeight: .zero, maxHeight: .infinity)
.onChange(of: ThemeModel.shared.selectedTheme) { newValue in
guard let theme = newValue else { return }
self.selectedTheme = theme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate {
let splitVC = CodeEditSplitViewController(workspace: workspace, feedbackPerformer: feedbackPerformer)

let navigatorView = NavigatorSidebarView(workspace: workspace)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)

let navigator = NSSplitViewItem(
sidebarWithViewController: NSHostingController(rootView: navigatorView)
)
Expand All @@ -80,7 +83,9 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate {
splitVC.addSplitViewItem(navigator)

let workspaceView = WindowObserver(window: window!) {
WorkspaceView(workspace: workspace)
WorkspaceView()
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
}

let mainContent = NSSplitViewItem(
Expand All @@ -90,6 +95,9 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate {
splitVC.addSplitViewItem(mainContent)

let inspectorView = InspectorSidebarView(workspace: workspace)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)

let inspector = NSSplitViewItem(
viewController: NSHostingController(rootView: inspectorView)
)
Expand All @@ -113,12 +121,10 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate {
if prefs.preferences.general.tabBarStyle == .native {
// Set titlebar background as transparent by default in order to
// style the toolbar background in native tab bar style.
self.window?.titlebarAppearsTransparent = true
self.window?.titlebarSeparatorStyle = .none
} else {
// In xcode tab bar style, we use default toolbar background with
// line separator.
self.window?.titlebarAppearsTransparent = false
self.window?.titlebarSeparatorStyle = .automatic
}
self.window?.toolbar = toolbar
Expand Down Expand Up @@ -234,17 +240,12 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate {
}

private func getSelectedCodeFile() -> CodeFileDocument? {
guard let id = workspace?.selectionState.selectedId else { return nil }
guard let item = workspace?.selectionState.openFileItems.first(where: { item in
item.tabID == id
}) else { return nil }
guard let file = workspace?.selectionState.openedCodeFiles[item] else { return nil }
return file
workspace?.tabManager.activeTabGroup.selected?.fileDocument
}

@IBAction func saveDocument(_ sender: Any) {
getSelectedCodeFile()?.save(sender)
workspace?.convertTemporaryTab()
workspace?.tabManager.activeTabGroup.temporaryTab = nil
}

@IBAction func openCommandPalette(_ sender: Any) {
Expand Down Expand Up @@ -283,11 +284,13 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate {
} else {
let panel = OverlayPanel()
self.quickOpenPanel = panel
let contentView = QuickOpenView(
state: state,
onClose: { panel.close() },
openFile: workspace.openTab(item:)
)

let contentView = QuickOpenView(state: state) {
panel.close()
} openFile: { file in
workspace.tabManager.openTab(item: file)
}

panel.contentView = NSHostingView(rootView: contentView)
window?.addChildWindow(panel, ordered: .above)
panel.makeKeyAndOrderFront(self)
Expand Down
57 changes: 22 additions & 35 deletions CodeEdit/Features/Documents/Views/WorkspaceCodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,37 @@ import SwiftUI
import UniformTypeIdentifiers

struct WorkspaceCodeFileView: View {

@EnvironmentObject
private var tabManager: TabManager

@EnvironmentObject
private var workspace: WorkspaceDocument
private var tabgroup: TabGroupData

var file: WorkspaceClient.FileItem

@StateObject
private var prefs: AppPreferencesModel = .shared

@ViewBuilder
var codeView: some View {
ZStack {
if let item = workspace.selectionState.openFileItems.first(where: { file in
if file.tabID == workspace.selectionState.selectedId {
print("Item loaded is: ", file.url)
if let document = file.fileDocument {
Group {
switch document.typeOfFile {
case .some(.text), .some(.data):
CodeFileView(codeFile: document)
default:
otherFileView(document, for: file)
}
return file.tabID == workspace.selectionState.selectedId
}) {
if let fileItem = workspace.selectionState.openedCodeFiles[item] {
if fileItem.typeOfFile == .text || fileItem.typeOfFile == .data {
codeFileView(fileItem, for: item)
} else {
otherFileView(fileItem, for: item)
}
}
} else {
Text("No Editor")
.font(.system(size: 17))
.foregroundColor(.secondary)
.frame(minHeight: 0)
.clipped()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

@ViewBuilder
private func codeFileView(
_ codeFile: CodeFileDocument,
for item: WorkspaceClient.FileItem
) -> some View {
VStack(spacing: 0) {
BreadcrumbsView(file: item, tappedOpenFile: workspace.openTab(item:))
Divider()
CodeFileView(codeFile: codeFile)
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
Spacer()
VStack(spacing: 10) {
ProgressView()
Text("Opening \(file.fileName)...")
}
Spacer()
}
}

Expand All @@ -60,8 +49,6 @@ struct WorkspaceCodeFileView: View {
for item: WorkspaceClient.FileItem
) -> some View {
VStack(spacing: 0) {
BreadcrumbsView(file: item, tappedOpenFile: workspace.openTab(item:))
Divider()

if let url = otherFile.previewItemURL,
let image = NSImage(contentsOf: url),
Expand Down
65 changes: 0 additions & 65 deletions CodeEdit/Features/Documents/WorkspaceDocument+Selection.swift

This file was deleted.

Loading