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

feat: added code editor #50

Merged
merged 1 commit into from
Mar 18, 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
27 changes: 7 additions & 20 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
0439FEF527DD104500528317 /* WorkspaceEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0439FEF427DD104500528317 /* WorkspaceEditorView.swift */; };
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */; };
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043C321527E3201F006AE443 /* WorkspaceDocument.swift */; };
043C321827E32246006AE443 /* CodeFileEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043C321727E32246006AE443 /* CodeFileEditor.swift */; };
043C321A27E32295006AE443 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 043C321927E32295006AE443 /* MainMenu.xib */; };
04540D5B27DD08C300E91B77 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F2BF0E27DBB28E0024EAB1 /* SettingsView.swift */; };
04540D5C27DD08C300E91B77 /* GeneralSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F2BF1127DBB3C10024EAB1 /* GeneralSettingsView.swift */; };
Expand All @@ -31,6 +29,7 @@
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345F667427DF6C180069BD69 /* FileTabRow.swift */; };
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE19BD27E0469C00F152CE /* BlurView.swift */; };
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C403B8E27E20F8000788241 /* WorkspaceClient */; };
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */ = {isa = PBXBuildFile; productRef = 5CF38A5D27E48E6C0096A0F7 /* CodeFile */; };
B658FB3427DA9E1000EA4DBD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3327DA9E1000EA4DBD /* Assets.xcassets */; };
B658FB3727DA9E1000EA4DBD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3627DA9E1000EA4DBD /* Preview Assets.xcassets */; };
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */; };
Expand All @@ -55,12 +54,9 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0439FEF427DD104500528317 /* WorkspaceEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceEditorView.swift; sourceTree = "<group>"; };
043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditDocumentController.swift; sourceTree = "<group>"; };
043C321527E3201F006AE443 /* WorkspaceDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceDocument.swift; sourceTree = "<group>"; };
043C321727E32246006AE443 /* CodeFileEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeFileEditor.swift; sourceTree = "<group>"; };
043C321927E32295006AE443 /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
043DF9C127DD045800CA0FC3 /* EditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorView.swift; sourceTree = "<group>"; };
04660F6027E3A68A00477777 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
04660F6327E3ACAF00477777 /* Appearances.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appearances.swift; sourceTree = "<group>"; };
04660F6527E3ACEF00477777 /* ReopenBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReopenBehavior.swift; sourceTree = "<group>"; };
Expand All @@ -76,7 +72,6 @@
28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarTop.swift; sourceTree = "<group>"; };
28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarBottom.swift; sourceTree = "<group>"; };
345F667427DF6C180069BD69 /* FileTabRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTabRow.swift; sourceTree = "<group>"; };
348313FB27DC8C070016D42C /* CodeFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeFile.swift; sourceTree = "<group>"; };
34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodeEdit.app; sourceTree = BUILT_PRODUCTS_DIR; };
B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceView.swift; sourceTree = "<group>"; };
Expand All @@ -96,6 +91,7 @@
buildActionMask = 2147483647;
files = (
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */,
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -116,20 +112,9 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
0439FEF327DD100800528317 /* Editor */ = {
isa = PBXGroup;
children = (
043DF9C127DD045800CA0FC3 /* EditorView.swift */,
0439FEF427DD104500528317 /* WorkspaceEditorView.swift */,
043C321727E32246006AE443 /* CodeFileEditor.swift */,
);
path = Editor;
sourceTree = "<group>";
};
043C321227E31FE8006AE443 /* Documents */ = {
isa = PBXGroup;
children = (
348313FB27DC8C070016D42C /* CodeFile.swift */,
043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */,
043C321527E3201F006AE443 /* WorkspaceDocument.swift */,
);
Expand Down Expand Up @@ -237,7 +222,6 @@
287776EA27E350A100D46668 /* SideBar */,
287776EB27E350BA00D46668 /* TabBar */,
345F667327DF6BCC0069BD69 /* Rows */,
0439FEF327DD100800528317 /* Editor */,
04F2BF1027DBB3AF0024EAB1 /* Settings */,
34EE19BC27E0467F00F152CE /* CustomViews */,
D7211D4427E066D4008F2ED7 /* Localization */,
Expand Down Expand Up @@ -284,6 +268,7 @@
name = CodeEdit;
packageProductDependencies = (
5C403B8E27E20F8000788241 /* WorkspaceClient */,
5CF38A5D27E48E6C0096A0F7 /* CodeFile */,
);
productName = CodeEdit;
productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */;
Expand Down Expand Up @@ -409,15 +394,13 @@
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */,
04660F6427E3ACAF00477777 /* Appearances.swift in Sources */,
04540D5E27DD08C300E91B77 /* WorkspaceView.swift in Sources */,
04540D5F27DD08C300E91B77 /* EditorView.swift in Sources */,
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */,
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */,
287776E927E34BC700D46668 /* TabBar.swift in Sources */,
286620A527E4AB6900E18C2B /* BreadcrumbsComponent.swift in Sources */,
287776EF27E3515300D46668 /* TabBarItem.swift in Sources */,
287776E727E3413200D46668 /* SideBar.swift in Sources */,
287776ED27E350D800D46668 /* SideBarItem.swift in Sources */,
04540D6127DD08C300E91B77 /* CodeFile.swift in Sources */,
04660F6627E3ACEF00477777 /* ReopenBehavior.swift in Sources */,
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */,
Expand Down Expand Up @@ -791,6 +774,10 @@
isa = XCSwiftPackageProductDependency;
productName = WorkspaceClient;
};
5CF38A5D27E48E6C0096A0F7 /* CodeFile */ = {
isa = XCSwiftPackageProductDependency;
productName = CodeFile;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = B658FB2427DA9E0F00EA4DBD /* Project object */;
Expand Down
78 changes: 78 additions & 0 deletions CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B658FB2B27DA9E0F00EA4DBD"
BuildableName = "CodeEdit.app"
BlueprintName = "CodeEdit"
ReferencedContainer = "container:CodeEdit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B658FB2B27DA9E0F00EA4DBD"
BuildableName = "CodeEdit.app"
BlueprintName = "CodeEdit"
ReferencedContainer = "container:CodeEdit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B658FB2B27DA9E0F00EA4DBD"
BuildableName = "CodeEdit.app"
BlueprintName = "CodeEdit"
ReferencedContainer = "container:CodeEdit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
34 changes: 34 additions & 0 deletions CodeEdit.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"object": {
"pins": [
{
"package": "CodeEditor",
"repositoryURL": "https://github.com/ZeeZide/CodeEditor.git",
"state": {
"branch": null,
"revision": "5856fac22b0a2174dbdea212784567c8c9cd1129",
"version": "1.2.0"
}
},
{
"package": "Highlightr",
"repositoryURL": "https://github.com/raspu/Highlightr",
"state": {
"branch": null,
"revision": "93199b9e434f04bda956a613af8f571933f9f037",
"version": "2.1.2"
}
},
{
"package": "SnapshotTesting",
"repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state": {
"branch": null,
"revision": "f8a9c997c3c1dab4e216a8ec9014e23144cbab37",
"version": "1.9.0"
}
}
]
},
"version": 1
}
4 changes: 3 additions & 1 deletion CodeEdit/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import WorkspaceClient
import CodeEditorView

struct WorkspaceView: View {
@State private var directoryURL: URL?
Expand Down Expand Up @@ -57,7 +58,8 @@ struct WorkspaceView: View {
ZStack {
if let selectedId = selectedId {
if let selectedItem = try? workspaceClient.getFileItem(selectedId) {
WorkspaceEditorView(item: selectedItem)
CodeEditorView(fileURL: selectedItem.url)
.padding(.top, 31.0)
}
}

Expand Down
4 changes: 1 addition & 3 deletions CodeEdit/Documents/CodeEditDocumentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import Cocoa

class CodeEditDocumentController: NSDocumentController {
override func openDocument(_ sender: Any?) {
print("Opening")

override func openDocument(_ sender: Any?) {
let dialog = NSOpenPanel()

dialog.title = "Open Workspace or File"
Expand Down
50 changes: 0 additions & 50 deletions CodeEdit/Documents/CodeFile.swift

This file was deleted.

19 changes: 8 additions & 11 deletions CodeEdit/Documents/WorkspaceDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AppKit
import SwiftUI
import WorkspaceClient
import Combine
import CodeFile

@objc(WorkspaceDocument)
class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
Expand All @@ -19,13 +20,13 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
@Published var openFileItems: [WorkspaceClient.FileItem] = []
@Published var sortFoldersOnTop: Bool = true
@Published var fileItems: [WorkspaceClient.FileItem] = []
var openedCodeFiles: [WorkspaceClient.FileItem : CodeFile] = [:]

var openedCodeFiles: [WorkspaceClient.FileItem : CodeFileDocument] = [:]
var folderURL: URL?
private var cancellable: AnyCancellable?
private var cancellables = Set<AnyCancellable>()

deinit {
cancellable?.cancel()
cancellable = nil
cancellables.forEach { $0.cancel() }
}

func closeFileTab(item: WorkspaceClient.FileItem) {
Expand All @@ -48,7 +49,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {

func openFile(item: WorkspaceClient.FileItem) {
do {
let codeFile = try CodeFile(for: item.url, withContentsOf: item.url, ofType: "public.source-code")
let codeFile = try CodeFileDocument(for: item.url, withContentsOf: item.url, ofType: "public.source-code")

if !openFileItems.contains(item) {
openFileItems.append(item)
Expand Down Expand Up @@ -97,15 +98,10 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
folderURL: url,
ignoredFilesAndFolders: ignoredFilesAndDirectory
)
cancellable = workspaceClient?
workspaceClient?
.getFiles
.sink { [weak self] files in
guard let self = self else { return }

// defer {
// // this sorts the array alphabetically
// self.fileItems = self.fileItems.sorted()
// }

guard !self.fileItems.isEmpty else {
self.fileItems = files
Expand All @@ -126,6 +122,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
}
}
}
.store(in: &cancellables)
}

override func write(to url: URL, ofType typeName: String) throws {}
Expand Down
22 changes: 0 additions & 22 deletions CodeEdit/Editor/CodeFileEditor.swift

This file was deleted.

Loading