Skip to content

Commit

Permalink
Revert "Revert "Revert "Merge branch 'TabBar-Actions-2' into main"""
Browse files Browse the repository at this point in the history
This reverts commit f4bb6f2.
  • Loading branch information
KaiTheRedNinja committed Aug 8, 2022
1 parent f4bb6f2 commit 473dbed
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 87 deletions.
21 changes: 2 additions & 19 deletions AuroraEditor/Base/Git/Models/ChangedFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,16 @@
import Foundation
import SwiftUI

public struct ChangedFile: Codable, Hashable, Identifiable, TabBarItemRepresentable {

public var tabID: TabBarItemID { .codeEditor(id) }

public var title: String {
fileLink.lastPathComponent
}

public var icon: Image {
Image(systemName: systemImage)
}

public struct ChangedFile: Codable, Hashable, Identifiable {
/// ID of the changed file
public var id: String
public var id = UUID()

/// Change type is to tell us whether the type is a new file, modified or deleted
public let changeType: GitType?

/// Link of the file
public let fileLink: URL

public init(fileLink: URL, changeType: GitType) {
self.fileLink = fileLink
self.changeType = changeType
id = fileLink.relativeString
}

/// Use it like this
/// ```swift
/// Image(systemName: item.systemImage)
Expand Down
4 changes: 2 additions & 2 deletions AuroraEditor/Base/Git/Models/Client/GitClientInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct GitClient {
public var cloneRepository: (String) -> AnyPublisher<CloneProgressResult, GitClientError>
/// Displays paths that have differences between the index file and the current HEAD commit,
/// paths that have differences between the working tree and the index file, and paths in the working tree
public var getChangedFiles: () throws -> [FileItem]
public var getChangedFiles: () throws -> [ChangedFile]
/// Get commit history
/// - Parameters:
/// - entries: number of commits we want to fetch. Will use max if nil
Expand All @@ -33,7 +33,7 @@ public struct GitClient {
checkoutBranch: @escaping (String) throws -> Void,
pull: @escaping () throws -> Void,
cloneRepository: @escaping (String) -> AnyPublisher<CloneProgressResult, GitClientError>,
getChangedFiles: @escaping () throws -> [FileItem],
getChangedFiles: @escaping () throws -> [ChangedFile],
getCommitHistory: @escaping (_ entries: Int?, _ fileLocalPath: String?) throws -> [Commit],
discardFileChanges: @escaping (String) throws -> Void,
discardProjectChanges: @escaping () throws -> Void,
Expand Down
10 changes: 5 additions & 5 deletions AuroraEditor/Base/Git/Models/Client/GitClientLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public extension GitClient {
}
}

func getChangedFiles() throws -> [FileItem] {
func getChangedFiles() throws -> [ChangedFile] {
let output = try shellClient.run(
"cd \(directoryURL.relativePath.escapedWhiteSpaces());git status -s --porcelain -u"
)
Expand All @@ -72,19 +72,19 @@ public extension GitClient {
}
return try output
.split(whereSeparator: \.isNewline)
.map { line -> FileItem in
.map { line -> ChangedFile in
let paramData = line.trimmingCharacters(in: .whitespacesAndNewlines)
let parameters = paramData.components(separatedBy: " ")
// swiftlint:disable:next line_length
guard let url = URL(string: "\(directoryURL.relativePath)\(parameters[safe: 1] ?? String(describing: URLError.badURL))") else {
guard let url = URL(string: parameters[safe: 1] ?? String(describing: URLError.badURL)) else {
throw GitClientError.failedToDecodeURL
}

var gitType: GitType {
.init(rawValue: parameters[safe: 0] ?? "") ?? GitType.unknown
}

return FileItem(url: url, changeType: gitType)
return ChangedFile(changeType: gitType,
fileLink: url)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class SourceControlModel: ObservableObject {

/// A list of changed files
@Published
public var changed: [FileItem]
public var changed: [ChangedFile]

private var cancellables = Set<AnyCancellable>()

Expand Down Expand Up @@ -60,9 +60,9 @@ public final class SourceControlModel: ObservableObject {
}
}

public func discardFileChanges(file: FileItem) {
public func discardFileChanges(file: ChangedFile) {
do {
try gitClient.discardFileChanges(file.url.path)
try gitClient.discardFileChanges(file.fileLink.path)
} catch {
Log.error("Failed to discard changes")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import SwiftUI
struct ChangedFileItemView: View {

@State
var changedFile: FileItem
var changedFile: ChangedFile

@Binding
var selection: FileItem.ID?
var selection: ChangedFile.ID?

var body: some View {
HStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ChangesView: View {
private var prefs: AppPreferencesModel = .shared

@State
var selectedFile: FileItem.ID?
var selectedFile: ChangedFile.ID?

/// Initialize with GitClient
/// - Parameter gitClient: a GitClient
Expand Down Expand Up @@ -78,11 +78,11 @@ struct ChangesView: View {
}

@ViewBuilder
private func contextMenu(file: FileItem) -> some View {
private func contextMenu(file: ChangedFile) -> some View {
VStack {
Group {
Button("View in Finder") {
file.showInFinder()
file.showInFinder(workspaceURL: model.workspaceURL)
}
Button("Reveal in Project Navigator") {}
.disabled(true) // TODO: Implementation Needed
Expand Down
50 changes: 7 additions & 43 deletions AuroraEditor/Base/TabBar/UI/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ struct TabBar: View {
@ObservedObject
private var workspace: WorkspaceDocument

@ObservedObject
private var sourceControlModel: SourceControlModel

@StateObject
private var prefs: AppPreferencesModel = .shared

// TabBar(windowController: windowController, workspace: workspace)
init(windowController: NSWindowController, workspace: WorkspaceDocument) {
self.windowController = windowController
self.workspace = workspace
self.sourceControlModel = .init(workspaceURL: workspace.fileURL!)
}

@State
Expand Down Expand Up @@ -176,46 +172,14 @@ struct TabBar: View {

private var leadingAccessories: some View {
HStack(spacing: 2) {
Menu {
Menu {
ForEach(sourceControlModel.changed) { item in
Button {

} label: {
Image(systemName: item.systemImage)
.foregroundColor(item.iconColor)
Text(item.fileName)
}
}

Divider()

Button {

} label: {
Text("Clear Menu")
}
} label: {
Text("Recent Files")
}

Menu {
ForEach(sourceControlModel.changed) { item in
Button {
workspace.openTab(item: item)
} label: {
Image(systemName: item.systemImage)
.foregroundColor(item.iconColor)
Text(item.fileName)
}
}
} label: {
Text("Locally Modified Files")
}
} label: {
Image(systemName: "square.grid.2x2")
}
TabBarAccessoryIcon(
icon: .init(systemName: "square.grid.2x2"),
action: { /* TODO */ }
)
.font(Font.system(size: 14, weight: .light, design: .default))
.foregroundColor(.secondary)
.buttonStyle(.plain)
.help("Navigate to Related Items")

Divider()
.padding(.vertical, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public extension WorkspaceClient {
case id
case url
case children
case changeType
}

/// An object containing all necessary information and actions for a specific file in the workspace
Expand Down Expand Up @@ -78,15 +77,13 @@ public extension WorkspaceClient {
id = try values.decode(String.self, forKey: .id)
url = try values.decode(URL.self, forKey: .url)
children = try values.decode([FileItem]?.self, forKey: .children)
changeType = try values.decode(GitType.self, forKey: .changeType)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: FileItemCodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(url, forKey: .url)
try container.encode(children, forKey: .children)
try container.encode(changeType, forKey: .changeType)
}

/// The id of the ``WorkspaceClient/WorkspaceClient/FileItem``.
Expand All @@ -108,8 +105,6 @@ public extension WorkspaceClient {
/// If the item already is the top-level ``WorkspaceClient/WorkspaceClient/FileItem`` this returns `nil`.
public weak var parent: FileItem?

public let changeType: GitType?

/// A boolean that is true if ``children`` is not `nil`
public var isFolder: Bool {
children != nil
Expand Down Expand Up @@ -182,10 +177,6 @@ public extension WorkspaceClient {
FileIcon.iconColor(fileType: fileType)
}

public var changeTypeValue: String {
changeType?.description ?? ""
}

// MARK: Statics
/// The default `FileManager` instance
public static let fileManger = FileManager.default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import SwiftUI

public typealias FileItem = WorkspaceClient.FileItem
typealias FileItem = WorkspaceClient.FileItem

extension FileItem {
/// This function allows creation of folders in the main directory or sub-folders
Expand Down

0 comments on commit 473dbed

Please sign in to comment.