Skip to content
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

[chore] Rename tabgroup to editor and more #1418

Merged
158 changes: 79 additions & 79 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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 @@ -80,9 +80,9 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
let splitVC = CodeEditSplitViewController(workspace: workspace, feedbackPerformer: feedbackPerformer)

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

let navigator = NSSplitViewItem(sidebarWithViewController: NSHostingController(rootView: navigatorView))
Expand All @@ -96,8 +96,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 @@ -108,9 +108,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 @@ -230,12 +230,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 @@ -278,7 +278,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 @@ -289,18 +289,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,26 +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)
}

/// Gets the tabgroup.
func getTabGroup() -> TabGroup? {
return parent?.getTabGroup(with: id)
/// Gets the editor layout.
func getEditorLayout() -> EditorLayout? {
return parent?.getEditorLayout(with: id)
}

/// Closes a tab in the tabgroup.
/// 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 @@ -91,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 @@ -120,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 @@ -147,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 @@ -172,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 @@ -183,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 @@ -236,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