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

Update Inspector Sidebar #1334

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
110 changes: 50 additions & 60 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditLanguages.git",
"state" : {
"revision" : "02bdf65b5536e1968c69e93ebb1c2413c7a13570",
"version" : "0.1.15"
"revision" : "aa7d922b2aa783ae6f2a1a2cb7010ae62b700e17",
"version" : "0.1.16"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditTextView",
"state" : {
"revision" : "8150e91dd81c698fde068e7cdf06a6f43d7ddd17",
"version" : "0.6.4"
"revision" : "92428aa115100b83486abf7ebb8cd61bc3472b8b",
"version" : "0.6.5"
}
},
{
Expand Down Expand Up @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/JSONRPC",
"state" : {
"revision" : "afc20d00e38674774f84edc325424a32ae3b9e01",
"version" : "0.7.0"
"revision" : "aa785ad404bdcf7ec692908b3905dd4c87e87141",
"version" : "0.7.1"
}
},
{
Expand All @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/LanguageServerProtocol",
"state" : {
"revision" : "192bcfdcf7a013da49c6fa1b95de66254ce7c614",
"version" : "0.9.1"
"revision" : "cae01173f45b0518ae5533b083edd153633af984",
"version" : "0.9.2"
}
},
{
Expand Down
28 changes: 28 additions & 0 deletions CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,34 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, TabBar
typeHidden ? url.deletingPathExtension().lastPathComponent : name
}

/// Generates a string based on user's file name preferences.
/// - Returns: A `String` suitable for display.
func labelFileName() -> String {
let prefs = Settings.shared.preferences.general
switch prefs.fileExtensionsVisibility {
case .hideAll:
return self.fileName(typeHidden: true)
case .showAll:
return self.fileName(typeHidden: false)
case .showOnly:
return self.fileName(typeHidden: !prefs.shownFileExtensions.extensions.contains(self.type.rawValue))
case .hideOnly:
return self.fileName(typeHidden: prefs.hiddenFileExtensions.extensions.contains(self.type.rawValue))
}
}

func validateFileName(for newName: String) -> Bool {
guard newName != labelFileName() else { return true }

guard !newName.isEmpty && newName.isValidFilename &&
!FileManager.default.fileExists(
atPath: self.url.deletingLastPathComponent().appendingPathComponent(newName).path
)
else { return false }

return true
}

// MARK: Statics
/// The default `FileManager` instance
static let fileManger = FileManager.default
Expand Down
5 changes: 5 additions & 0 deletions CodeEdit/Features/CodeFile/CodeFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import SwiftUI
import UniformTypeIdentifiers
import QuickLookUI
import CodeEditLanguages

enum CodeFileError: Error {
case failedToDecode
Expand All @@ -23,6 +24,10 @@ final class CodeFileDocument: NSDocument, ObservableObject, QLPreviewItem {
@Published
var content = ""

/// Used to override detected languages.
@Published
var language: CodeLanguage?

/*
This is the main type of the document.
For example, if the file is end with '.png', it will be an image,
Expand Down
7 changes: 6 additions & 1 deletion CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct CodeFileView: View {
letterSpacing: letterSpacing,
bracketPairHighlight: bracketPairHighlight
)

.id(codeFile.fileURL)
.background {
if colorScheme == .dark {
Expand Down Expand Up @@ -161,7 +162,11 @@ struct CodeFileView: View {
guard let url = codeFile.fileURL else {
return .default
}
return .detectLanguageFrom(url: url)
return codeFile.language ?? CodeLanguage.detectLanguageFrom(
url: url,
prefixBuffer: codeFile.content.getFirstLines(5),
suffixBuffer: codeFile.content.getLastLines(5)
)
}

private func getBracketPairHighlight() -> BracketPairHighlight? {
Expand Down
23 changes: 6 additions & 17 deletions CodeEdit/Features/InspectorSidebar/InspectorSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,14 @@ struct InspectorSidebarView: View {
var sidebarPosition: SettingsData.SidebarTabBarPosition

@State
private var selection: InspectorTab? = .quickhelp

var path: String? { tabManager.activeTabGroup.selected?.fileDocument?.fileURL?.path(percentEncoded: false)
}

var fileTreeAndGitHistory: [InspectorTab] {
guard let workspaceURL = workspace.fileURL, let path else {
return []
}

return [
.file(workspaceURL: workspaceURL, fileURL: path),
.gitHistory(workspaceURL: workspaceURL, fileURL: path)
]
}
private var selection: InspectorTab? = .file

private var items: [InspectorTab] {
fileTreeAndGitHistory + [InspectorTab.quickhelp] +
extensionManager
[
.file,
.gitHistory
]
+ extensionManager
.extensions
.map { ext in
ext.availableFeatures.compactMap {
Expand Down
19 changes: 6 additions & 13 deletions CodeEdit/Features/InspectorSidebar/InspectorTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import CodeEditKit
import ExtensionFoundation

enum InspectorTab: AreaTab {
case file(workspaceURL: URL, fileURL: String)
case gitHistory(workspaceURL: URL, fileURL: String)
case quickhelp
case file
case gitHistory
case uiExtension(endpoint: AppExtensionIdentity, data: ResolvedSidebar.SidebarStore)

var systemImage: String {
Expand All @@ -21,8 +20,6 @@ enum InspectorTab: AreaTab {
return "doc"
case .gitHistory:
return "clock"
case .quickhelp:
return "questionmark.circle"
case .uiExtension(_, let data):
return data.icon ?? "e.square"
}
Expand All @@ -41,21 +38,17 @@ enum InspectorTab: AreaTab {
return "File Inspector"
case .gitHistory:
return "History Inspector"
case .quickhelp:
return "Quick Help Inspector"
case .uiExtension(_, let data):
return data.help ?? data.sceneID
}
}

var body: some View {
switch self {
case let .file(workspaceURL, fileURL):
FileInspectorView(workspaceURL: workspaceURL, fileURL: fileURL)
case let .gitHistory(workspaceURL, fileURL):
HistoryInspectorView(workspaceURL: workspaceURL, fileURL: fileURL)
case .quickhelp:
QuickHelpInspectorView().padding(5)
case .file:
FileInspectorView()
case .gitHistory:
HistoryInspectorView()
case let .uiExtension(endpoint, data):
ExtensionSceneView(with: endpoint, sceneID: data.sceneID)
}
Expand Down
101 changes: 0 additions & 101 deletions CodeEdit/Features/InspectorSidebar/Models/FileInspectorModel.swift

This file was deleted.

13 changes: 0 additions & 13 deletions CodeEdit/Features/InspectorSidebar/Models/FileLocation.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,41 @@ import Foundation
final class HistoryInspectorModel: ObservableObject {

/// A GitClient instance
private(set) var gitClient: GitClient
private(set) var gitClient: GitClient?

/// The base URL of the workspace
private(set) var workspaceURL: URL
private(set) var workspaceURL: URL?

/// The base URL of the workspace
private(set) var fileURL: String
private(set) var fileURL: String?

/// The selected branch from the GitClient
@Published
var commitHistory: [GitCommit]

/// Initialize with a GitClient
/// - Parameter workspaceURL: the current workspace URL
///
init(workspaceURL: URL, fileURL: String) {
self.workspaceURL = workspaceURL
self.fileURL = fileURL
var commitHistory: [GitCommit] = []

func setWorkspace(url: URL?) {
if workspaceURL != url {
workspaceURL = url
updateCommitHistory()
}
}

func setFile(url: String?) {
if fileURL != url {
fileURL = url
updateCommitHistory()
}
}

func updateCommitHistory() {
guard let workspaceURL, let fileURL else {
commitHistory = []
return
}
gitClient = GitClient(directoryURL: workspaceURL, shellClient: currentWorld.shellClient)
do {
let commitHistory = try gitClient.getCommitHistory(entries: 40, fileLocalPath: fileURL)
self.commitHistory = commitHistory
let commitHistory = try gitClient?.getCommitHistory(entries: 40, fileLocalPath: fileURL)
self.commitHistory = commitHistory ?? []
} catch {
commitHistory = []
}
Expand Down
13 changes: 0 additions & 13 deletions CodeEdit/Features/InspectorSidebar/Models/IndentUsing.swift

This file was deleted.

13 changes: 0 additions & 13 deletions CodeEdit/Features/InspectorSidebar/Models/LanguageType.swift

This file was deleted.

Loading