Skip to content

Commit

Permalink
Renamed TabBarTab (previously TabBarItem) to EditorTab, TabBar to Edi…
Browse files Browse the repository at this point in the history
…torTabBar, PathBar to EditorPathBar. Organized files throughout project.
  • Loading branch information
austincondiff committed Sep 7, 2023
1 parent f9bbf73 commit 8cac820
Show file tree
Hide file tree
Showing 55 changed files with 214 additions and 134 deletions.
246 changes: 163 additions & 83 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, TabBarTabRepresentable {
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 ``TabBarTabID`` enum form
var tabID: TabBarTabID { .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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI
import Combine

struct PathBarComponent: View {
struct EditorPathBarComponent: View {

private let fileItem: CEWorkspaceFile
private let tappedOpenFile: (CEWorkspaceFile) -> Void
Expand Down Expand Up @@ -43,7 +43,7 @@ struct PathBarComponent: View {
var body: some View {
NSPopUpButtonView(selection: $selection) {
let button = NSPopUpButton()
button.menu = PathBarMenu(fileItems: siblings, tappedOpenFile: tappedOpenFile)
button.menu = EditorPathBarMenu(fileItems: siblings, tappedOpenFile: tappedOpenFile)
button.font = .systemFont(ofSize: NSFont.systemFontSize(for: .small))
button.isBordered = false
(button.cell as? NSPopUpButtonCell)?.arrowPosition = .noArrow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// PathBarMenu.swift
// EditorPathBarMenu.swift
// CodeEditModules/PathBar
//
// Created by Ziyuan Zhao on 2022/3/29.
//

import AppKit

final class PathBarMenu: NSMenu, NSMenuDelegate {
final class EditorPathBarMenu: NSMenu, NSMenuDelegate {
private let fileItems: [CEWorkspaceFile]
private let tappedOpenFile: (CEWorkspaceFile) -> Void

Expand Down Expand Up @@ -44,9 +44,9 @@ final class PathBarMenu: NSMenu, NSMenuDelegate {
}
}

private func generateSubmenu(_ fileItem: CEWorkspaceFile) -> PathBarMenu? {
private func generateSubmenu(_ fileItem: CEWorkspaceFile) -> EditorPathBarMenu? {
if let children = fileItem.children {
let menu = PathBarMenu(
let menu = EditorPathBarMenu(
fileItems: children,
tappedOpenFile: tappedOpenFile
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// PathBarView.swift
// EditorPathBarView.swift
// CodeEditModules/PathBar
//
// Created by Lukas Pistrol on 17.03.22.
//

import SwiftUI

struct PathBarView: View {
struct EditorPathBarView: View {

private let file: CEWorkspaceFile
private let tappedOpenFile: (CEWorkspaceFile) -> Void
Expand Down Expand Up @@ -50,7 +50,7 @@ struct PathBarView: View {
if fileItem.parent != nil {
chevron
}
PathBarComponent(fileItem: fileItem, tappedOpenFile: tappedOpenFile)
EditorPathBarComponent(fileItem: fileItem, tappedOpenFile: tappedOpenFile)
.padding(.leading, 2.5)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// TabBarTabBackground.swift
// EditorTabBackground.swift
// CodeEdit
//
// Created by Austin Condiff on 1/17/23.
//

import SwiftUI

struct TabBarTabBackground: View {
struct EditorTabBackground: View {
var isActive: Bool
var isPressing: Bool
var isDragging: Bool
Expand Down Expand Up @@ -61,8 +61,8 @@ struct TabBarTabBackground: View {
}
}

struct TabBarTabBackground_Previews: PreviewProvider {
struct EditorTabBackground_Previews: PreviewProvider {
static var previews: some View {
TabBarTabBackground(isActive: false, isPressing: false, isDragging: false)
EditorTabBackground(isActive: false, isPressing: false, isDragging: false)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// TabBarTabButtonStyle.swift
// EditorTabButtonStyle.swift
// CodeEdit
//
// Created by Khan Winter on 6/4/22.
//

import SwiftUI

struct TabBarTabButtonStyle: ButtonStyle {
struct EditorTabButtonStyle: ButtonStyle {
@Environment(\.colorScheme)
var colorScheme

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// TabBarTabCloseButton.swift
// EditorTabCloseButton.swift
// CodeEdit
//
// Created by Austin Condiff on 1/17/23.
//

import SwiftUI

struct TabBarTabCloseButton: View {
struct EditorTabCloseButton: View {
var isActive: Bool
var isHoveringTab: Bool
var isDragging: Bool
Expand Down Expand Up @@ -91,11 +91,11 @@ struct TabBarTabCloseButton: View {
}
}

struct TabBarTabCloseButton_Previews: PreviewProvider {
struct EditorTabCloseButton_Previews: PreviewProvider {
@State static var closeButtonGestureActive = true

static var previews: some View {
TabBarTabCloseButton(
EditorTabCloseButton(
isActive: false,
isHoveringTab: false,
isDragging: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// TabBarTabView.swift
// EditorTabView.swift
// CodeEdit
//
// Created by Lukas Pistrol on 17.03.22.
//

import SwiftUI

struct TabBarTabView: View {
struct EditorTabView: View {

@Environment(\.colorScheme)
private var colorScheme
Expand Down Expand Up @@ -176,7 +176,7 @@ struct TabBarTabView: View {
.hidden()
}
// Close Button
TabBarTabCloseButton(
EditorTabCloseButton(
isActive: isActive,
isHoveringTab: isHovering,
isDragging: draggingTabId != nil || onDragTabId != nil,
Expand Down Expand Up @@ -242,7 +242,7 @@ struct TabBarTabView: View {
}
.background {
if tabBarStyle == .xcode {
TabBarTabBackground(isActive: isActive, isPressing: isPressing, isDragging: isDragging)
EditorTabBackground(isActive: isActive, isPressing: isPressing, isDragging: isDragging)
.animation(.easeInOut(duration: 0.08), value: isHovering)
} else {
if isFullscreen && isActive {
Expand All @@ -269,7 +269,7 @@ struct TabBarTabView: View {
// return .init(object: NSString(string: "\(item.tabID)"))
// })
}
.buttonStyle(TabBarTabButtonStyle(isPressing: $isPressing))
.buttonStyle(EditorTabButtonStyle(isPressing: $isPressing))
.simultaneousGesture(
TapGesture(count: 2)
.onEnded { _ in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TabBarTabID.swift
// EditorTabID.swift
//
//
// Created by Pavel Kasila on 30.04.22.
Expand All @@ -8,7 +8,7 @@
import Foundation

/// Enum to represent item's ID to tab bar
enum TabBarTabID: Codable, Identifiable, Hashable {
enum EditorTabID: Codable, Identifiable, Hashable {
var id: String {
switch self {
case .codeEditor(let path):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// TabBarTabRepresentable.swift
// EditorTabRepresentable.swift
//
//
// Created by Pavel Kasila on 30.04.22.
//

import SwiftUI

/// Protocol for data passed to TabBarTabView to conform to
protocol TabBarTabRepresentable {
/// Protocol for data passed to EditorTabView to conform to
protocol EditorTabRepresentable {
/// Unique tab identifier
var tabID: TabBarTabID { get }
var tabID: EditorTabID { get }
/// String to be shown as tab's title
var name: String { get }
/// Image to be shown as tab's icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
// It has the gesture implementation and its animations.
// I am now also disabling `file_length` rule because the dragging algorithm (with UX) is complex.
// swiftlint:disable file_length type_body_length
// - TODO: TabBarTabView drop-outside event handler.
// - TODO: EditorTabView drop-outside event handler.
struct TabBarView: View {

typealias TabID = CEWorkspaceFile.ID
Expand Down Expand Up @@ -320,7 +320,7 @@ struct TabBarView: View {
) {
ForEach(Array(openedTabs.enumerated()), id: \.element) { index, id in
if let item = editor.tabs.first(where: { $0.id == id }) {
TabBarTabView(
EditorTabView(
expectedWidth: expectedTabWidth,
item: item,
index: index,
Expand All @@ -345,7 +345,7 @@ struct TabBarView: View {
// Detect the drop action of each tab.
.onDrop(
of: [.utf8PlainText], // TODO: Make a unique type for it.
delegate: TabBarTabOnDropDelegate(
delegate: EditorTabOnDropDelegate(
currentTabId: id,
openedTabs: $openedTabs,
onDragTabId: $onDragTabId,
Expand Down Expand Up @@ -632,7 +632,7 @@ struct TabBarView: View {
editorManager.activeEditor = newEditor
}

private struct TabBarTabOnDropDelegate: DropDelegate {
private struct EditorTabOnDropDelegate: DropDelegate {
private let currentTabId: TabID
@Binding private var openedTabs: [TabID]
@Binding private var onDragTabId: TabID?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct EditorView: View {
WorkspaceCodeFileView(file: selected)
.focusedObject(editor)
.transformEnvironment(\.edgeInsets) { insets in
insets.top += TabBarView.height + PathBarView.height + 1 + 1
insets.top += TabBarView.height + EditorPathBarView.height + 1 + 1
}
} else {
VStack {
Expand Down Expand Up @@ -49,7 +49,7 @@ struct EditorView: View {

Divider()
if let file = editor.selectedTab {
PathBarView(file: file) { [weak editor] newFile in
EditorPathBarView(file: file) { [weak editor] newFile in
if let index = editor?.tabs.firstIndex(of: file) {
editor?.openTab(item: newFile, at: index)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ extension ProjectNavigatorViewController: NSOutlineViewDelegate {
/// - id: the id of the item item
/// - collection: the array to search for
/// - forcesReveal: The boolean to indicates whether or not it should force to reveal the selected file.
private func select(by id: TabBarTabID, from collection: [CEWorkspaceFile], forcesReveal: Bool) {
private func select(by id: EditorTabID, from collection: [CEWorkspaceFile], forcesReveal: Bool) {
guard let item = collection.find(by: id) else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Array where Element == CEWorkspaceFile {
/// Search for the `CEWorkspaceFile` element that matches the specified `tabID`.
/// - Parameter tabID: A `tabID` to search for.
/// - Returns: The `CEWorkspaceFile` element with a matching `tabID` if available.
func find(by tabID: TabBarTabID) -> CEWorkspaceFile? {
func find(by tabID: EditorTabID) -> CEWorkspaceFile? {
guard let item = first(where: { $0.tabID == tabID }) else {
for element in self {
if let item = element.children?.find(by: tabID) {
Expand Down
12 changes: 6 additions & 6 deletions Documentation.docc/App Window/Adding New Tab Type.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ This article is about how to add a new tab type to `TabBar`
## Overview

First of all, each data type to be represented as tab in the UI should conform to
``TabBarTabRepresentable`` protocol. For example, this is how it is done for
``EditorTabRepresentable`` protocol. For example, this is how it is done for
`FileItem`:

```swift
final class FileItem: Identifiable, Codable, TabBarTabRepresentable {
public var tabID: TabBarTabID {
final class FileItem: Identifiable, Codable, EditorTabRepresentable {
public var tabID: EditorTabID {
.codeEditor(id)
}

Expand All @@ -34,7 +34,7 @@ final class FileItem: Identifiable, Codable, TabBarTabRepresentable {

Each new tab type must have new identifier case, for example:
```swift
public enum TabBarTabID: Codable, Identifiable, Hashable {
public enum EditorTabID: Codable, Identifiable, Hashable {
public var id: String {
switch self {
...
Expand All @@ -51,8 +51,8 @@ public enum TabBarTabID: Codable, Identifiable, Hashable {
### Opening and closing new tab types

Tabs are opened using ``WorkspaceDocument/openTab(item:)`` method. It does a set of common
things for all tabs. But also it calls a private method based on the ``TabBarTabID`` of the
item. The private method for your ``TabBarTabRepresentable`` MUST persist this item
things for all tabs. But also it calls a private method based on the ``EditorTabID`` of the
item. The private method for your ``EditorTabRepresentable`` MUST persist this item
somewhere (I recommend persisting them in ``WorkspaceSelectionState``).

The same is for closing tabs using ``WorkspaceDocument/closeTab(item:)`` method.
Expand Down
8 changes: 4 additions & 4 deletions Documentation.docc/App Window/TabBarView.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

### Model

- ``TabBarTabID``
- ``TabBarTabRepresentable``
- ``EditorTabID``
- ``EditorTabRepresentable``

### Components

- ``TabBarTabView``
- ``EditorTabView``
- ``TabBarContextMenu``
- ``TabBarTabButtonStyle``
- ``EditorTabButtonStyle``
- ``TabDivider``
- ``TabBarTopDivider``
- ``TabBarBottomDivider``
Expand Down

0 comments on commit 8cac820

Please sign in to comment.