Skip to content

Commit

Permalink
Undo merge
Browse files Browse the repository at this point in the history
  • Loading branch information
FastestMolasses committed Sep 11, 2023
1 parent 2612387 commit ac2d8b0
Show file tree
Hide file tree
Showing 107 changed files with 915 additions and 770 deletions.
392 changes: 235 additions & 157 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum FileItemCodingKeys: String, CodingKey {
}

/// An object containing all necessary information and actions for a specific file in the workspace
final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, TabBarItemRepresentable {
final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, EditorTabRepresentable {

/// The id of the ``FileSystemClient/FileSystemClient/FileItem``.
///
Expand Down Expand Up @@ -54,8 +54,8 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, TabBar
/// Returns the Git status of a file as ``GitType``
var gitStatus: GitType?

/// Returns the `id` in ``TabBarItemID`` enum form
var tabID: TabBarItemID { .codeEditor(id) }
/// Returns the `id` in ``EditorTabID`` enum form
var tabID: EditorTabID { .codeEditor(id) }

/// Returns a boolean that is true if ``children`` is not `nil`
var isFolder: Bool { url.hasDirectoryPath }
Expand Down
3 changes: 3 additions & 0 deletions CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ struct AreaTabBar<Tab: AreaTab>: View {
)
.background(makeTabItemGeometryReader(tab: icon))
.simultaneousGesture(makeAreaTabDragGesture(tab: icon))
.opacity(draggingItem?.imageName == icon.systemImage &&
hasChangedLocation &&
drugItemLocation != nil ? 0.0 : 1.0)
}
if position == .side {
Spacer()
Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct CodeFileView: View {
@Environment(\.edgeInsets)
private var edgeInsets

@EnvironmentObject private var tabgroup: TabGroupData
@EnvironmentObject private var editor: Editor

var body: some View {
CodeEditTextView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
let navigatorViewModel = NavigatorSidebarViewModel()
navigatorSidebarViewModel = navigatorViewModel

let settingsView = SettingsInjector {
NavigatorSidebarView(workspace: workspace, viewModel: navigatorViewModel)
let navigatorView = SettingsInjector {
NavigatorAreaView(workspace: workspace, viewModel: navigatorViewModel)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
.environmentObject(workspace.editorManager)
}

let navigator = NSSplitViewItem(
Expand All @@ -102,8 +102,8 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
WindowObserver(window: window!) {
WorkspaceView()
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
.environmentObject(workspace.debugAreaModel)
.environmentObject(workspace.editorManager)
.environmentObject(workspace.utilityAreaModel)
}
}

Expand All @@ -114,9 +114,9 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
splitVC.addSplitViewItem(mainContent)

let inspectorView = SettingsInjector {
InspectorSidebarView()
InspectorAreaView()
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
.environmentObject(workspace.editorManager)
}

let inspector = NSSplitViewItem(viewController: NSHostingController(rootView: inspectorView))
Expand Down Expand Up @@ -236,12 +236,12 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
}

private func getSelectedCodeFile() -> CodeFileDocument? {
workspace?.tabManager.activeTabGroup.selected?.fileDocument
workspace?.editorManager.activeEditor.selectedTab?.fileDocument
}

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

@IBAction func openCommandPalette(_ sender: Any) {
Expand Down Expand Up @@ -284,7 +284,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
let contentView = QuickOpenView(state: state) {
panel.close()
} openFile: { file in
workspace.tabManager.openTab(item: file)
workspace.editorManager.openTab(item: file)
}

panel.contentView = NSHostingView(rootView: SettingsInjector { contentView })
Expand All @@ -295,18 +295,18 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
}

@IBAction func closeCurrentTab(_ sender: Any) {
if (workspace?.tabManager.activeTabGroup.tabs ?? []).isEmpty {
self.closeActiveTabGroup(self)
if (workspace?.editorManager.activeEditor.tabs ?? []).isEmpty {
self.closeActiveEditor(self)
} else {
workspace?.tabManager.activeTabGroup.closeCurrentTab()
workspace?.editorManager.activeEditor.closeSelectedTab()
}
}

@IBAction func closeActiveTabGroup(_ sender: Any) {
if workspace?.tabManager.tabGroups.findSomeTabGroup(except: workspace?.tabManager.activeTabGroup) == nil {
@IBAction func closeActiveEditor(_ sender: Any) {
if workspace?.editorManager.editorLayout.findSomeEditor(except: workspace?.editorManager.activeEditor) == nil {
NSApp.sendAction(#selector(NSWindow.close), to: nil, from: nil)
} else {
workspace?.tabManager.activeTabGroup.close()
workspace?.editorManager.activeEditor.close()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions CodeEdit/Features/Documents/Views/WorkspaceCodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UniformTypeIdentifiers

struct WorkspaceCodeFileView: View {

@EnvironmentObject private var tabManager: TabManager
@EnvironmentObject private var editorManager: EditorManager

@EnvironmentObject private var tabgroup: TabGroupData
@EnvironmentObject private var editor: Editor

var file: CEWorkspaceFile

Expand Down
16 changes: 8 additions & 8 deletions CodeEdit/Features/Documents/WorkspaceDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {

var workspaceFileManager: CEWorkspaceFileManager?

var tabManager = TabManager()
var editorManager = EditorManager()

private var workspaceState: [String: Any] {
get {
Expand All @@ -35,7 +35,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
didSet { workspaceFileManager?.notifyObservers() }
}

var debugAreaModel = DebugAreaViewModel()
var utilityAreaModel = UtilityAreaViewModel()
var searchState: SearchState?
var quickOpenViewModel: QuickOpenViewModel?
var commandsPaletteState: CommandPaletteViewModel?
Expand Down Expand Up @@ -122,8 +122,8 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
self.quickOpenViewModel = .init(fileURL: url)
self.commandsPaletteState = .init()

tabManager.restoreFromState(self)
debugAreaModel.restoreFromState(self)
editorManager.restoreFromState(self)
utilityAreaModel.restoreFromState(self)
}

override func read(from url: URL, ofType typeName: String) throws {
Expand All @@ -135,8 +135,8 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
// MARK: Close Workspace

override func close() {
tabManager.saveRestorationState(self)
debugAreaModel.saveRestorationState(self)
editorManager.saveRestorationState(self)
utilityAreaModel.saveRestorationState(self)
super.close()
}

Expand Down Expand Up @@ -174,7 +174,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
return
}
// Save unsaved changes before closing
let editedCodeFiles = tabManager.tabGroups
let editedCodeFiles = editorManager.editorLayout
.gatherOpenFiles()
.compactMap(\.fileDocument)
.filter(\.isDocumentEdited)
Expand Down Expand Up @@ -203,7 +203,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
implementation,
to: (@convention(c)(Any, Selector, Any, Bool, UnsafeMutableRawPointer?) -> Void).self
)
let areAllOpenedCodeFilesClean = tabManager.tabGroups.gatherOpenFiles()
let areAllOpenedCodeFilesClean = editorManager.editorLayout.gatherOpenFiles()
.compactMap(\.fileDocument)
.allSatisfy { !$0.isDocumentEdited }
function(object, shouldCloseSelector, self, areAllOpenedCodeFilesClean, contextInfo)
Expand Down
6 changes: 3 additions & 3 deletions CodeEdit/Features/Documents/WorkspaceStateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//

enum WorkspaceStateKey: String {
case debugAreaCollapsed
case debugAreaMaximized
case debugAreaHeight
case utilityAreaCollapsed
case utilityAreaMaximized
case utilityAreaHeight
case openTabs
case workspaceWindowSize
case splitViewWidth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TabGroupData.swift
// Editor.swift
// CodeEdit
//
// Created by Wouter Hennen on 16/02/2023.
Expand All @@ -9,7 +9,7 @@ import Foundation
import OrderedCollections
import DequeModule

final class TabGroupData: ObservableObject, Identifiable {
final class Editor: ObservableObject, Identifiable {
typealias Tab = CEWorkspaceFile

/// Set of open tabs.
Expand All @@ -19,14 +19,14 @@ final class TabGroupData: ObservableObject, Identifiable {

if tabs.count > oldValue.count {
// Amount of tabs grew, so set the first new as selected.
selected = change.first
selectedTab = change.first
} else {
// Selected file was removed
if let selected, change.contains(selected) {
if let oldIndex = oldValue.firstIndex(of: selected), oldIndex - 1 < tabs.count, !tabs.isEmpty {
self.selected = tabs[max(0, oldIndex-1)]
if let selectedTab, change.contains(selectedTab) {
if let oldIndex = oldValue.firstIndex(of: selectedTab), oldIndex - 1 < tabs.count, !tabs.isEmpty {
self.selectedTab = tabs[max(0, oldIndex-1)]
} else {
self.selected = nil
self.selectedTab = nil
}
}
}
Expand All @@ -39,21 +39,21 @@ final class TabGroupData: ObservableObject, Identifiable {
let tab = history[historyOffset]

if !tabs.contains(tab) {
if let selected {
openTab(item: tab, at: tabs.firstIndex(of: selected), fromHistory: true)
if let selectedTab {
openTab(item: tab, at: tabs.firstIndex(of: selectedTab), fromHistory: true)
} else {
openTab(item: tab, fromHistory: true)
}
}
selected = tab
selectedTab = tab
}
}

/// History of tab switching.
@Published var history: Deque<Tab> = []

/// Currently selected tab.
@Published var selected: Tab?
@Published var selectedTab: Tab?

@Published var temporaryTab: Tab?

Expand All @@ -63,21 +63,26 @@ final class TabGroupData: ObservableObject, Identifiable {

init(
files: OrderedSet<Tab> = [],
selected: Tab? = nil,
selectedTab: Tab? = nil,
parent: SplitViewData? = nil
) {
self.tabs = []
self.parent = parent
files.forEach { openTab(item: $0) }
self.selected = selected ?? files.first
self.selectedTab = selectedTab ?? files.first
}

/// Closes the tabgroup.
/// Closes the editor.
func close() {
parent?.closeTabGroup(with: id)
parent?.closeEditor(with: id)
}

/// Closes a tab in the tabgroup.
/// Gets the editor layout.
func getEditorLayout() -> EditorLayout? {
return parent?.getEditorLayout(with: id)
}

/// Closes a tab in the editor.
/// This will also write any changes to the file on disk and will add the tab to the tab history.
/// - Parameter item: the tab to close.
func closeTab(item: Tab) {
Expand All @@ -86,12 +91,12 @@ final class TabGroupData: ObservableObject, Identifiable {
}

historyOffset = 0
if item != selected {
if item != selectedTab {
history.prepend(item)
}
tabs.remove(item)
if let selected {
history.prepend(selected)
if let selectedTab {
history.prepend(selectedTab)
}

guard let file = item.fileDocument else { return }
Expand All @@ -115,23 +120,23 @@ final class TabGroupData: ObservableObject, Identifiable {
}

/// Closes the currently opened tab in the tab group.
func closeCurrentTab() {
guard let selectedTab = selected else {
func closeSelectedTab() {
guard let tab = selectedTab else {
return
}

closeTab(item: selectedTab)
closeTab(item: tab)
}

/// Opens a tab in the tabgroup.
/// Opens a tab in the editor.
/// If a tab for the item already exists, it is used instead.
/// - Parameters:
/// - item: the tab to open.
/// - asTemporary: indicates whether the tab should be opened as a temporary tab or a permanent tab.
func openTab(item: Tab, asTemporary: Bool) {
// Item is already opened in a tab.
guard !tabs.contains(item) || !asTemporary else {
selected = item
selectedTab = item
history.prepend(item)
return
}
Expand All @@ -142,7 +147,7 @@ final class TabGroupData: ObservableObject, Identifiable {
history.prepend(item)
tabs.remove(tab)
tabs.insert(item, at: index)
self.selected = item
self.selectedTab = item
temporaryTab = item
}

Expand All @@ -167,7 +172,7 @@ final class TabGroupData: ObservableObject, Identifiable {
}
}

/// Opens a tab in the tabgroup.
/// Opens a tab in the editor.
/// - Parameters:
/// - item: The tab to open.
/// - index: Index where the tab needs to be added. If nil, it is added to the back.
Expand All @@ -178,7 +183,7 @@ final class TabGroupData: ObservableObject, Identifiable {
} else {
tabs.append(item)
}
selected = item
selectedTab = item
if !fromHistory {
history.removeFirst(historyOffset)
history.prepend(item)
Expand Down Expand Up @@ -231,8 +236,8 @@ final class TabGroupData: ObservableObject, Identifiable {
}
}

extension TabGroupData: Equatable, Hashable {
static func == (lhs: TabGroupData, rhs: TabGroupData) -> Bool {
extension Editor: Equatable, Hashable {
static func == (lhs: Editor, rhs: Editor) -> Bool {
lhs.id == rhs.id
}

Expand Down
Loading

0 comments on commit ac2d8b0

Please sign in to comment.