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 all 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
73 changes: 21 additions & 52 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" : "cc28ae52c8083c313b650784706e339b727646d9",
"version" : "0.6.6"
}
},
{
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
18 changes: 18 additions & 0 deletions CodeEdit/Features/CodeFile/CodeFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation
import SwiftUI
import UniformTypeIdentifiers
import QuickLookUI
import CodeEditTextView
import CodeEditLanguages

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

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

/// Document-specific overriden indent option.
@Published
var indentOption: SettingsData.TextEditingSettings.IndentOption?

/// Document-specific overriden tab width.
@Published
var defaultTabWidth: Int?

/// Document-specific overriden line wrap preference.
@Published
var wrapLines: Bool?

/*
This is the main type of the document.
For example, if the file is end with '.png', it will be an image,
Expand Down
47 changes: 23 additions & 24 deletions CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CodeFileView: View {
private var codeFile: CodeFileDocument

@AppSettings(\.textEditing.defaultTabWidth) var defaultTabWidth
@AppSettings(\.textEditing.indentOption) var settingsIndentOption
@AppSettings(\.textEditing.indentOption) var indentOption
@AppSettings(\.textEditing.lineHeightMultiple) var lineHeightMultiple
@AppSettings(\.textEditing.wrapLinesToEditorWidth) var wrapLinesToEditorWidth
@AppSettings(\.textEditing.font) var settingsFont
Expand Down Expand Up @@ -90,17 +90,6 @@ struct CodeFileView: View {
}
}()

// Tab is a placeholder value, is overriden immediately in `init`.
@State
private var indentOption: IndentOption = {
switch Settings[\.textEditing].indentOption.indentType {
case .tab:
return .tab
case .spaces:
return .spaces(count: Settings[\.textEditing].indentOption.spaceCount)
}
}()

@Environment(\.edgeInsets)
private var edgeInsets

Expand All @@ -113,17 +102,18 @@ struct CodeFileView: View {
language: getLanguage(),
theme: selectedTheme.editor.editorTheme,
font: font,
tabWidth: defaultTabWidth,
indentOption: indentOption,
tabWidth: codeFile.defaultTabWidth ?? defaultTabWidth,
indentOption: (codeFile.indentOption ?? indentOption).textViewOption(),
lineHeight: lineHeightMultiple,
wrapLines: wrapLinesToEditorWidth,
wrapLines: codeFile.wrapLines ?? wrapLinesToEditorWidth,
cursorPosition: $codeFile.cursorPosition,
useThemeBackground: useThemeBackground,
contentInsets: edgeInsets.nsEdgeInsets,
isEditable: isEditable,
letterSpacing: letterSpacing,
bracketPairHighlight: bracketPairHighlight
)

.id(codeFile.fileURL)
.background {
if colorScheme == .dark {
Expand Down Expand Up @@ -152,21 +142,17 @@ struct CodeFileView: View {
.onChange(of: bracketHighlight) { _ in
bracketPairHighlight = getBracketPairHighlight()
}
.onChange(of: settingsIndentOption) { option in
switch option.indentType {
case .tab:
self.indentOption = .tab
case .spaces:
self.indentOption = .spaces(count: option.spaceCount)
}
}
}

private func getLanguage() -> CodeLanguage {
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 All @@ -186,3 +172,16 @@ struct CodeFileView: View {
}
}
}

// This extension is kept here because it should not be used elsewhere in the app and may cause confusion
// due to the similar type name from the CETV module.
private extension SettingsData.TextEditingSettings.IndentOption {
func textViewOption() -> IndentOption {
switch self.indentType {
case .spaces:
return IndentOption.spaces(count: spaceCount)
case .tab:
return IndentOption.tab
}
}
}
24 changes: 6 additions & 18 deletions CodeEdit/Features/InspectorSidebar/InspectorSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +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.

Loading