-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source Control Navigator: Added support for viewing file changes (#627)
* Source Control Navigator: Added support for viewing file changes * Fixed Naming Conventions
- Loading branch information
Showing
20 changed files
with
678 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
CodeEdit/NavigatorSidebar/SourceControlNavigator/Model/SourceControlModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
CodeEdit/NavigatorSidebar/SourceControlNavigator/SourceControlNavigatorView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
CodeEdit/NavigatorSidebar/SourceControlNavigator/SourceControlSearchToolbar.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
CodeEdit/NavigatorSidebar/SourceControlNavigator/SourceControlToolbarBottom.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
Oops, something went wrong.