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

Source Control Navigator: Added support for viewing file changes #627

Merged
merged 2 commits into from
May 21, 2022
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
68 changes: 68 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
04C3256C28034FC800C8DA2D /* CodeEditKit in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 04C3256A28034FC800C8DA2D /* CodeEditKit */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
200412EF280F3EAC00BCAF5C /* NoCommitHistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 200412EE280F3EAC00BCAF5C /* NoCommitHistoryView.swift */; };
2004A3832808468600FD9696 /* Feedback in Frameworks */ = {isa = PBXBuildFile; productRef = 2004A3822808468600FD9696 /* Feedback */; };
201169D72837B2E300F92B46 /* SourceControlNavigatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169D62837B2E300F92B46 /* SourceControlNavigatorView.swift */; };
201169D92837B31200F92B46 /* SourceControlSearchToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169D82837B31200F92B46 /* SourceControlSearchToolbar.swift */; };
201169DB2837B34000F92B46 /* ChangedFileItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169DA2837B34000F92B46 /* ChangedFileItemView.swift */; };
201169DD2837B3AC00F92B46 /* SourceControlToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169DC2837B3AC00F92B46 /* SourceControlToolbarBottom.swift */; };
201169E22837B3D800F92B46 /* ChangesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169E12837B3D800F92B46 /* ChangesView.swift */; };
201169E52837B40300F92B46 /* RepositoriesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169E42837B40300F92B46 /* RepositoriesView.swift */; };
201169E72837B5CA00F92B46 /* SourceControlModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169E62837B5CA00F92B46 /* SourceControlModel.swift */; };
2040F0B1280AE96100411B6F /* CodeEditUtils in Frameworks */ = {isa = PBXBuildFile; productRef = 2040F0B0280AE96100411B6F /* CodeEditUtils */; };
2072FA13280D74ED00C7F8D4 /* HistoryInspectorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2072FA12280D74ED00C7F8D4 /* HistoryInspectorModel.swift */; };
2072FA16280D83A500C7F8D4 /* FileTypeList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2072FA15280D83A500C7F8D4 /* FileTypeList.swift */; };
Expand Down Expand Up @@ -163,6 +170,13 @@
04C3254E2800AA4700C8DA2D /* ExtensionInstallationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionInstallationView.swift; sourceTree = "<group>"; };
04C325502800AC7400C8DA2D /* ExtensionInstallationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionInstallationViewModel.swift; sourceTree = "<group>"; };
200412EE280F3EAC00BCAF5C /* NoCommitHistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoCommitHistoryView.swift; sourceTree = "<group>"; };
201169D62837B2E300F92B46 /* SourceControlNavigatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorView.swift; sourceTree = "<group>"; };
201169D82837B31200F92B46 /* SourceControlSearchToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlSearchToolbar.swift; sourceTree = "<group>"; };
201169DA2837B34000F92B46 /* ChangedFileItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangedFileItemView.swift; sourceTree = "<group>"; };
201169DC2837B3AC00F92B46 /* SourceControlToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlToolbarBottom.swift; sourceTree = "<group>"; };
201169E12837B3D800F92B46 /* ChangesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangesView.swift; sourceTree = "<group>"; };
201169E42837B40300F92B46 /* RepositoriesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepositoriesView.swift; sourceTree = "<group>"; };
201169E62837B5CA00F92B46 /* SourceControlModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlModel.swift; sourceTree = "<group>"; };
2072FA12280D74ED00C7F8D4 /* HistoryInspectorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryInspectorModel.swift; sourceTree = "<group>"; };
2072FA15280D83A500C7F8D4 /* FileTypeList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTypeList.swift; sourceTree = "<group>"; };
2072FA17280D871200C7F8D4 /* TextEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEncoding.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -309,6 +323,52 @@
path = ExtensionNavigator;
sourceTree = "<group>";
};
201169D52837B29600F92B46 /* SourceControlNavigator */ = {
isa = PBXGroup;
children = (
201169DF2837B3CB00F92B46 /* Model */,
201169DE2837B3C700F92B46 /* Views */,
201169D62837B2E300F92B46 /* SourceControlNavigatorView.swift */,
201169D82837B31200F92B46 /* SourceControlSearchToolbar.swift */,
201169DC2837B3AC00F92B46 /* SourceControlToolbarBottom.swift */,
);
path = SourceControlNavigator;
sourceTree = "<group>";
};
201169DE2837B3C700F92B46 /* Views */ = {
isa = PBXGroup;
children = (
201169E32837B3EF00F92B46 /* Repositories */,
201169E02837B3D100F92B46 /* Changes */,
);
path = Views;
sourceTree = "<group>";
};
201169DF2837B3CB00F92B46 /* Model */ = {
isa = PBXGroup;
children = (
201169E62837B5CA00F92B46 /* SourceControlModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
201169E02837B3D100F92B46 /* Changes */ = {
isa = PBXGroup;
children = (
201169E12837B3D800F92B46 /* ChangesView.swift */,
201169DA2837B34000F92B46 /* ChangedFileItemView.swift */,
);
path = Changes;
sourceTree = "<group>";
};
201169E32837B3EF00F92B46 /* Repositories */ = {
isa = PBXGroup;
children = (
201169E42837B40300F92B46 /* RepositoriesView.swift */,
);
path = Repositories;
sourceTree = "<group>";
};
2072FA14280D838800C7F8D4 /* Lists */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -388,6 +448,7 @@
287776EA27E350A100D46668 /* NavigatorSidebar */ = {
isa = PBXGroup;
children = (
201169D52837B29600F92B46 /* SourceControlNavigator */,
0483E34E27FDB15F00354AC0 /* ExtensionNavigator */,
286471AC27ED52950039369D /* ProjectNavigator */,
D7012EE627E757660001E1EF /* FindNavigator */,
Expand Down Expand Up @@ -816,26 +877,32 @@
buildActionMask = 2147483647;
files = (
2072FA13280D74ED00C7F8D4 /* HistoryInspectorModel.swift in Sources */,
201169E52837B40300F92B46 /* RepositoriesView.swift in Sources */,
DE513F52281B672D002260B9 /* TabBarAccessory.swift in Sources */,
2813F93927ECC4C300E305E4 /* NavigatorSidebar.swift in Sources */,
DE513F54281DE5D0002260B9 /* TabBarXcode.swift in Sources */,
20EBB50D280C383700F3A5DA /* LanguageType.swift in Sources */,
2813F93827ECC4AA00E305E4 /* FindNavigatorResultList.swift in Sources */,
201169D92837B31200F92B46 /* SourceControlSearchToolbar.swift in Sources */,
0483E35027FDB17700354AC0 /* ExtensionNavigator.swift in Sources */,
201169DB2837B34000F92B46 /* ChangedFileItemView.swift in Sources */,
2B7A583527E4BA0100D25D4E /* AppDelegate.swift in Sources */,
D7012EE827E757850001E1EF /* FindNavigator.swift in Sources */,
D7E201AE27E8B3C000CB86D0 /* String+Ranges.swift in Sources */,
20EBB50F280C389300F3A5DA /* FileInspectorModel.swift in Sources */,
0463E51327FCC1FB00806D5C /* CodeEditTargetsAPI.swift in Sources */,
201169DD2837B3AC00F92B46 /* SourceControlToolbarBottom.swift in Sources */,
04C3254D27FF331B00C8DA2D /* ExtensionNavigatorItem.swift in Sources */,
D7E201B027E8C07300CB86D0 /* FindNavigatorSearchBar.swift in Sources */,
2072FA1C280D874000C7F8D4 /* IndentUsing.swift in Sources */,
B6EE989227E887C600CDD8AB /* InspectorSidebarToolbar.swift in Sources */,
201169E72837B5CA00F92B46 /* SourceControlModel.swift in Sources */,
28B8F884280FFE4600596236 /* NSTableView+Background.swift in Sources */,
200412EF280F3EAC00BCAF5C /* NoCommitHistoryView.swift in Sources */,
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */,
20EBB503280C327C00F3A5DA /* HistoryInspector.swift in Sources */,
2072FA1A280D872600C7F8D4 /* LineEndings.swift in Sources */,
201169E22837B3D800F92B46 /* ChangesView.swift in Sources */,
20EBB507280C32D300F3A5DA /* QuickHelpInspector.swift in Sources */,
DE6405A62817734700881FDF /* TabBarNative.swift in Sources */,
04C3255C2801F86900C8DA2D /* OutlineMenu.swift in Sources */,
Expand All @@ -861,6 +928,7 @@
2072FA16280D83A500C7F8D4 /* FileTypeList.swift in Sources */,
04C3254F2800AA4700C8DA2D /* ExtensionInstallationView.swift in Sources */,
B6EE989027E8879A00CDD8AB /* InspectorSidebar.swift in Sources */,
201169D72837B2E300F92B46 /* SourceControlNavigatorView.swift in Sources */,
20D839AB280DEB2900B27357 /* NoSelectionView.swift in Sources */,
20EBB505280C329800F3A5DA /* HistoryItem.swift in Sources */,
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
</dict>
</array>
<key>GitHash</key>
<string>8aca261a483dd996548d0090ba604c04126321d4</string>
<string>c15197302b622989e87c6006cebe747daa3980c8</string>
</dict>
</plist>
25 changes: 22 additions & 3 deletions CodeEdit/NavigatorSidebar/NavigatorSidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct NavigatorSidebar: View {
@State
private var selection: Int = 0

private let toolbarPadding: Double = -8.0

init(workspace: WorkspaceDocument, windowController: NSWindowController) {
self.workspace = workspace
self.windowController = windowController
Expand All @@ -27,6 +29,8 @@ struct NavigatorSidebar: View {
switch selection {
case 0:
ProjectNavigator(workspace: workspace, windowController: windowController)
case 1:
SourceControlNavigatorView(workspace: workspace)
case 2:
FindNavigator(state: workspace.searchState ?? .init(workspace))
case 7:
Expand All @@ -38,11 +42,26 @@ struct NavigatorSidebar: View {
}
.safeAreaInset(edge: .top) {
NavigatorSidebarToolbarTop(selection: $selection)
.padding(.bottom, -8)
.padding(.bottom, toolbarPadding)
}
.safeAreaInset(edge: .bottom) {
NavigatorSidebarToolbarBottom(workspace: workspace)
.padding(.top, -8)
switch selection {
case 0:
NavigatorSidebarToolbarBottom(workspace: workspace)
.padding(.top, toolbarPadding)
case 1:
SourceControlToolbarBottom()
.padding(.top, toolbarPadding)
case 2:
NavigatorSidebarToolbarBottom(workspace: workspace)
.padding(.top, toolbarPadding)
case 7:
NavigatorSidebarToolbarBottom(workspace: workspace)
.padding(.top, toolbarPadding)
default:
NavigatorSidebarToolbarBottom(workspace: workspace)
.padding(.top, toolbarPadding)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ extension OutlineViewController: NSOutlineViewDelegate {
case .showAll:
return item.fileName(typeHidden: false)
case .showOnly:
return item.fileName(typeHidden: !shownFileExtensions.extensions.contains(item.fileType))
return item.fileName(typeHidden: !shownFileExtensions.extensions.contains(item.fileType.rawValue))
case .hideOnly:
return item.fileName(typeHidden: hiddenFileExtensions.extensions.contains(item.fileType))
return item.fileName(typeHidden: hiddenFileExtensions.extensions.contains(item.fileType.rawValue))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// SourceControlModel.swift
// CodeEdit
//
// Created by Nanashi Li on 2022/05/20.
//

import Foundation
import Git

/// This model handle the fetching and adding of changes etc... for the
/// Source Control Navigator
public final class SourceControlModel: ObservableObject {

/// A GitClient instance
let gitClient: GitClient

/// The base URL of the workspace
let workspaceURL: URL

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

/// Initialize with a GitClient
/// - Parameter workspaceURL: the current workspace URL we also need this to open files in finder
///
public init(workspaceURL: URL) {
self.workspaceURL = workspaceURL
gitClient = GitClient.default(
directoryURL: workspaceURL,
shellClient: Current.shellClient
)
do {
changed = try gitClient.getChangedFiles()
} catch {
changed = []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SourceControlNavigatorView.swift
// CodeEdit
//
// Created by Nanashi Li on 2022/05/20.
//

import SwiftUI
import CodeEditUI

struct SourceControlNavigatorView: View {

@ObservedObject
private var workspace: WorkspaceDocument

@State
private var selectedSection: Int = 0

init(workspace: WorkspaceDocument) {
self.workspace = workspace
}

var body: some View {
VStack {
SegmentedControl($selectedSection,
options: ["Changes", "Repositories"],
prominent: true)
.frame(maxWidth: .infinity)
.frame(height: 27)
.padding(.horizontal, 8)
.padding(.bottom, 2)
.overlay(alignment: .bottom) {
Divider()
}

if selectedSection == 0 {
if let urlString = workspace.fileURL {
ChangesView(workspaceURL: urlString)
}
}

if selectedSection == 1 {
RepositoriesView()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// SourceControlSearchToolbar.swift
// CodeEdit
//
// Created by Nanashi Li on 2022/05/20.
//

import SwiftUI
import CodeEditUI

struct SourceControlSearchToolbar: View {

@Environment(\.colorScheme)
var colorScheme

@Environment(\.controlActiveState)
private var controlActive

@State
private var text = ""

var body: some View {
HStack {
Image(systemName: "line.3.horizontal.decrease.circle")
.foregroundColor(.secondary)
textField
if !text.isEmpty { clearButton }
}
.padding(.horizontal, 5)
.padding(.vertical, 3)
.background(.ultraThinMaterial)
.clipShape(RoundedRectangle(cornerRadius: 6))
.overlay(RoundedRectangle(cornerRadius: 6).stroke(Color.gray, lineWidth: 0.5).cornerRadius(6))
}

private var textField: some View {
TextField("Filter", text: $text)
.disableAutocorrection(true)
.textFieldStyle(PlainTextFieldStyle())
}

private var clearButton: some View {
Button {
self.text = ""
} label: {
Image(systemName: "xmark.circle.fill")
}
.foregroundColor(.secondary)
.buttonStyle(PlainButtonStyle())
}
}

struct SourceControlSearchToolbar_Previews: PreviewProvider {
static var previews: some View {
SourceControlSearchToolbar()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SourceControlToolbarBottom.swift
// CodeEdit
//
// Created by Nanashi Li on 2022/05/20.
//

import SwiftUI

struct SourceControlToolbarBottom: View {
var body: some View {
HStack(spacing: 0) {
sourceControlMenu
SourceControlSearchToolbar()
}
.frame(height: 29, alignment: .center)
.frame(maxWidth: .infinity)
.padding(.horizontal, 4)
.overlay(alignment: .top) {
Divider()
}
}

private var sourceControlMenu: some View {
Menu {
Button("Discard Changes...") {}
.disabled(true) // TODO: Implementation Needed
Button("Stash Changes...") {}
.disabled(true) // TODO: Implementation Needed
Button("Commit...") {}
.disabled(true) // TODO: Implementation Needed
Button("Create Pull Request...") {}
.disabled(true) // TODO: Implementation Needed
} label: {
Image(systemName: "ellipsis.circle")
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.frame(maxWidth: 30)
}
}

struct SourceControlToolbarBottom_Previews: PreviewProvider {
static var previews: some View {
SourceControlToolbarBottom()
}
}
Loading