From 3e1ad2e3a0f75232b4d57fae0edcb681f47a6023 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 18:43:11 +0100 Subject: [PATCH 01/18] basic implementation of the status bar (non interactive) --- CodeEdit.xcodeproj/project.pbxproj | 15 +++- CodeEdit/SideBar/SideBarItem.swift | 4 + .../Modules/StatusBar/src/StatusBar.swift | 86 +++++++++++++++++++ CodeEditModules/Package.swift | 8 +- 4 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 CodeEditModules/Modules/StatusBar/src/StatusBar.swift diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index 15858e2ff..b0d3f62c5 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 287776EF27E3515300D46668 /* TabBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287776EE27E3515300D46668 /* TabBarItem.swift */; }; 289978ED27E4E97E00BB0357 /* FileIconStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 289978EC27E4E97E00BB0357 /* FileIconStyle.swift */; }; 28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */; }; + 28CE5EA027E6493D0065D29C /* StatusBar in Frameworks */ = {isa = PBXBuildFile; productRef = 28CE5E9F27E6493D0065D29C /* StatusBar */; }; 28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */; }; 2B7A583527E4BA0100D25D4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468438427DC76E200F8E88E /* AppDelegate.swift */; }; 345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345F667427DF6C180069BD69 /* FileTabRow.swift */; }; @@ -104,6 +105,7 @@ files = ( 5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */, D70F5E2C27E4E8CF004EE4B9 /* WelcomeModule in Frameworks */, + 28CE5EA027E6493D0065D29C /* StatusBar in Frameworks */, 5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -298,6 +300,7 @@ 5C403B8E27E20F8000788241 /* WorkspaceClient */, 5CF38A5D27E48E6C0096A0F7 /* CodeFile */, D70F5E2B27E4E8CF004EE4B9 /* WelcomeModule */, + 28CE5E9F27E6493D0065D29C /* StatusBar */, ); productName = CodeEdit; productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */; @@ -653,12 +656,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = F992DREF6G; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -684,12 +687,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = F992DREF6G; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -847,6 +850,10 @@ /* End XCConfigurationList section */ /* Begin XCSwiftPackageProductDependency section */ + 28CE5E9F27E6493D0065D29C /* StatusBar */ = { + isa = XCSwiftPackageProductDependency; + productName = StatusBar; + }; 5C403B8E27E20F8000788241 /* WorkspaceClient */ = { isa = XCSwiftPackageProductDependency; productName = WorkspaceClient; diff --git a/CodeEdit/SideBar/SideBarItem.swift b/CodeEdit/SideBar/SideBarItem.swift index a18c87177..54e1c8a84 100644 --- a/CodeEdit/SideBar/SideBarItem.swift +++ b/CodeEdit/SideBar/SideBarItem.swift @@ -8,6 +8,7 @@ import SwiftUI import WorkspaceClient import CodeFile +import StatusBar struct SideBarItem: View { @@ -39,6 +40,9 @@ struct SideBarItem: View { BreadcrumbsView(item, workspace: workspace) } } + .safeAreaInset(edge: .bottom) { + StatusBarView(errors: 0, warnings: 0) + } } else { Text("File cannot be opened") } diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift new file mode 100644 index 000000000..a9b20f612 --- /dev/null +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -0,0 +1,86 @@ +// +// StatusBar.swift +// +// +// Created by Lukas Pistrol on 19.03.22. +// + +import SwiftUI + +public struct StatusBarView: View { + + public init(errors: Int, warnings: Int) { + self.errors = errors + self.warnings = warnings + } + + private var errors: Int + private var warnings: Int + private var branches: [String] = ["master", "new-feature"] + + @State private var selectedBranch: Int = 0 + @State private var isExpanded: Bool = false + + public var body: some View { + ZStack { + Rectangle() + .foregroundStyle(.bar) + HStack { + labelButton(errors.formatted(), image: "xmark.octagon") + labelButton(warnings.formatted(), image: "exclamationmark.triangle") + branchPicker + Spacer() + expandButton + } + .padding(.horizontal, 10) + } + .overlay(alignment: .top) { + Divider() + } + .frame(height: 32) + .padding(.top, -8) + } + + private func labelButton(_ text: String, image: String) -> some View { + Button {} label: { + HStack(spacing: 4) { + Image(systemName: image) + .font(.headline) + Text(text) + } + } + .buttonStyle(.borderless) + } + + private var branchPicker: some View { + Menu(branches[selectedBranch]) { + ForEach(branches.indices, id: \.self) { branch in + Button { selectedBranch = branch } label: { + Text(branches[branch]) + .foregroundColor(.black) + } + } + } + .menuStyle(.borderlessButton) + .fixedSize() + } + + private var expandButton: some View { + Button { + isExpanded.toggle() + } label: { + Image(systemName: "rectangle.bottomthird.inset.filled") + .imageScale(.large) + } + .tint(isExpanded ? .accentColor : .secondary) + .buttonStyle(.borderless) + } +} + +struct SwiftUIView_Previews: PreviewProvider { + static var previews: some View { + StatusBarView(errors: 0, warnings: 0) + .previewLayout(.fixed(width: 1336, height: 32)) + .preferredColorScheme(.dark) + } +} diff --git a/CodeEditModules/Package.swift b/CodeEditModules/Package.swift index 9fd0635b2..9f3853879 100644 --- a/CodeEditModules/Package.swift +++ b/CodeEditModules/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "CodeEditModules", defaultLocalization: "en", platforms: [ - .macOS(.v11) + .macOS(.v12) ], products: [ .library( @@ -17,7 +17,8 @@ let package = Package( name: "CodeFile", targets: ["CodeFile"] ), - .library(name: "WelcomeModule", targets: ["WelcomeModule"]) + .library(name: "WelcomeModule", targets: ["WelcomeModule"]), + .library(name: "StatusBar", targets: ["StatusBar"]) ], dependencies: [ .package( @@ -68,6 +69,7 @@ let package = Package( "SnapshotTesting" ], path: "Modules/WelcomeModule/Tests" - ) + ), + .target(name: "StatusBar", path: "Modules/StatusBar/src") ] ) From 267c8f2379f533f3d91bc17359fc41d15ef6e332 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 18:59:25 +0100 Subject: [PATCH 02/18] removed Dev-Team --- CodeEdit.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index b0d3f62c5..5d7801b85 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -656,12 +656,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = F992DREF6G; + DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -687,12 +687,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = F992DREF6G; + DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; From 3ce8570ededd84013e5998084d864c2302425add Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 19:14:01 +0100 Subject: [PATCH 03/18] Bump `CodeEditModules` platform version to `.v12` --- CodeEditModules/Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeEditModules/Package.swift b/CodeEditModules/Package.swift index 9fd0635b2..09f71f15b 100644 --- a/CodeEditModules/Package.swift +++ b/CodeEditModules/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "CodeEditModules", defaultLocalization: "en", platforms: [ - .macOS(.v11) + .macOS(.v12) ], products: [ .library( From 9768017f4558ba2111ac36d2baaff3ae67dbc80d Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 19:27:56 +0100 Subject: [PATCH 04/18] Update Test Action to `macos-12` --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5d7efdb05..cb8dbed6a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ on: jobs: test: name: Testing CodeEdit - runs-on: macOS-latest + runs-on: macOS-12 steps: - name: Checkout repository uses: actions/checkout@v1 From a433b3fd0afd18cb148fbc581a0f5c01d51ead59 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 19:35:15 +0100 Subject: [PATCH 05/18] Update Test Action to `macos-12` --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cb8dbed6a..917338025 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ on: jobs: test: name: Testing CodeEdit - runs-on: macOS-12 + runs-on: macos-12 steps: - name: Checkout repository uses: actions/checkout@v1 From 8d8c1d9957448b6d0f6767923d07888831ee06e0 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 19:59:02 +0100 Subject: [PATCH 06/18] Revert "Update Test Action to `macos-12`" This reverts commit a433b3fd0afd18cb148fbc581a0f5c01d51ead59. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 917338025..cb8dbed6a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ on: jobs: test: name: Testing CodeEdit - runs-on: macos-12 + runs-on: macOS-12 steps: - name: Checkout repository uses: actions/checkout@v1 From e8901997f40793f09730c8fb770a8465c5c5f549 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 19:59:12 +0100 Subject: [PATCH 07/18] Revert "Update Test Action to `macos-12`" This reverts commit 9768017f4558ba2111ac36d2baaff3ae67dbc80d. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cb8dbed6a..5d7efdb05 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ on: jobs: test: name: Testing CodeEdit - runs-on: macOS-12 + runs-on: macOS-latest steps: - name: Checkout repository uses: actions/checkout@v1 From 708bfbcfe61f09e052d8c262179774acc670060f Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 19:59:22 +0100 Subject: [PATCH 08/18] Revert "Bump `CodeEditModules` platform version to `.v12`" This reverts commit 3ce8570ededd84013e5998084d864c2302425add. --- CodeEditModules/Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeEditModules/Package.swift b/CodeEditModules/Package.swift index 09f71f15b..9fd0635b2 100644 --- a/CodeEditModules/Package.swift +++ b/CodeEditModules/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "CodeEditModules", defaultLocalization: "en", platforms: [ - .macOS(.v12) + .macOS(.v11) ], products: [ .library( From 0db53fcfd9b769b391ff1dfcb6b15773a0cd2726 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 01:25:53 +0100 Subject: [PATCH 09/18] added missing items --- .../Modules/StatusBar/src/StatusBar.swift | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index a9b20f612..ccbf79c95 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -18,18 +18,29 @@ public struct StatusBarView: View { private var warnings: Int private var branches: [String] = ["master", "new-feature"] + // TODO: Create a View Model for this @State private var selectedBranch: Int = 0 @State private var isExpanded: Bool = false + @State private var reloading: Bool = false + @State private var line: Int = 1 + @State private var col: Int = 1 public var body: some View { ZStack { Rectangle() .foregroundStyle(.bar) - HStack { + HStack(spacing: 14) { + HStack(spacing: 8) { labelButton(errors.formatted(), image: "xmark.octagon") labelButton(warnings.formatted(), image: "exclamationmark.triangle") + } branchPicker + reloadButton Spacer() + cursorLocationLabel + indentSelector + encodingSelector + lineEndSelector expandButton } .padding(.horizontal, 10) @@ -50,6 +61,7 @@ public struct StatusBarView: View { } } .buttonStyle(.borderless) + .foregroundStyle(.primary) } private var branchPicker: some View { @@ -57,7 +69,6 @@ public struct StatusBarView: View { ForEach(branches.indices, id: \.self) { branch in Button { selectedBranch = branch } label: { Text(branches[branch]) - .foregroundColor(.black) } } } @@ -65,6 +76,60 @@ public struct StatusBarView: View { .fixedSize() } + private var reloadButton: some View { + Button { + reloading = true + // Just for looks for now. In future we'll call a function like + // `reloadFileStatus()` here which will set/unset `reloading` + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + self.reloading = false + } + } label: { + Image(systemName: "arrow.triangle.2.circlepath") + .imageScale(.large) + .rotationEffect(.degrees(reloading ? 360 : 0)) + .animation(animation, value: reloading) + .opacity(reloading ? 1 : 0) + // A bit of a hacky solution to prevent spinning counterclockwise once `reloading` changes to `false` + .overlay { + Image(systemName: "arrow.triangle.2.circlepath") + .imageScale(.large) + .opacity(reloading ? 0 : 1) + } + + } + .buttonStyle(.borderless) + .foregroundStyle(.primary) + } + + private var animation: Animation { + // 10x speed when not reloading to make invisible ccw spin go fast in case button is pressed multiple times. + .linear.speed(reloading ? 0.5 : 10) + } + + private var cursorLocationLabel: some View { + Text("Ln \(line), Col \(col)") + .foregroundStyle(.primary) + } + + private var indentSelector: some View { + Menu("2 Spaces") {} + .menuStyle(.borderlessButton) + .fixedSize() + } + + private var encodingSelector: some View { + Menu("UTF 8") {} + .menuStyle(.borderlessButton) + .fixedSize() + } + + private var lineEndSelector: some View { + Menu("LF") {} + .menuStyle(.borderlessButton) + .fixedSize() + } + private var expandButton: some View { Button { isExpanded.toggle() @@ -81,6 +146,6 @@ struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { StatusBarView(errors: 0, warnings: 0) .previewLayout(.fixed(width: 1336, height: 32)) - .preferredColorScheme(.dark) + .preferredColorScheme(.light) } } From de189f7f9441d4deb55a28af87ea2409cb409fd3 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 18:43:11 +0100 Subject: [PATCH 10/18] basic implementation of the status bar (non interactive) --- CodeEdit.xcodeproj/project.pbxproj | 15 +++- CodeEdit/SideBar/SideBarItem.swift | 4 + .../Modules/StatusBar/src/StatusBar.swift | 86 +++++++++++++++++++ CodeEditModules/Package.swift | 8 +- 4 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 CodeEditModules/Modules/StatusBar/src/StatusBar.swift diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index 723038b1c..9e11dedd0 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 287776EF27E3515300D46668 /* TabBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287776EE27E3515300D46668 /* TabBarItem.swift */; }; 289978ED27E4E97E00BB0357 /* FileIconStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 289978EC27E4E97E00BB0357 /* FileIconStyle.swift */; }; 28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */; }; + 28CE5EA027E6493D0065D29C /* StatusBar in Frameworks */ = {isa = PBXBuildFile; productRef = 28CE5E9F27E6493D0065D29C /* StatusBar */; }; 28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */; }; 2B7A583527E4BA0100D25D4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468438427DC76E200F8E88E /* AppDelegate.swift */; }; 345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345F667427DF6C180069BD69 /* FileTabRow.swift */; }; @@ -107,6 +108,7 @@ 5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */, B65E614627E6765D00255275 /* Introspect in Frameworks */, D70F5E2C27E4E8CF004EE4B9 /* WelcomeModule in Frameworks */, + 28CE5EA027E6493D0065D29C /* StatusBar in Frameworks */, 5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -302,6 +304,7 @@ 5CF38A5D27E48E6C0096A0F7 /* CodeFile */, D70F5E2B27E4E8CF004EE4B9 /* WelcomeModule */, B65E614527E6765D00255275 /* Introspect */, + 28CE5E9F27E6493D0065D29C /* StatusBar */, ); productName = CodeEdit; productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */; @@ -662,12 +665,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = F992DREF6G; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -693,12 +696,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = F992DREF6G; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -867,6 +870,10 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 28CE5E9F27E6493D0065D29C /* StatusBar */ = { + isa = XCSwiftPackageProductDependency; + productName = StatusBar; + }; 5C403B8E27E20F8000788241 /* WorkspaceClient */ = { isa = XCSwiftPackageProductDependency; productName = WorkspaceClient; diff --git a/CodeEdit/SideBar/SideBarItem.swift b/CodeEdit/SideBar/SideBarItem.swift index 670852921..897ef803b 100644 --- a/CodeEdit/SideBar/SideBarItem.swift +++ b/CodeEdit/SideBar/SideBarItem.swift @@ -8,6 +8,7 @@ import SwiftUI import WorkspaceClient import CodeFile +import StatusBar struct SideBarItem: View { @@ -40,6 +41,9 @@ struct SideBarItem: View { BreadcrumbsView(item, workspace: workspace) } } + .safeAreaInset(edge: .bottom) { + StatusBarView(errors: 0, warnings: 0) + } } else { Text("CodeEdit cannot open this file because its file type is not supported.") } diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift new file mode 100644 index 000000000..a9b20f612 --- /dev/null +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -0,0 +1,86 @@ +// +// StatusBar.swift +// +// +// Created by Lukas Pistrol on 19.03.22. +// + +import SwiftUI + +public struct StatusBarView: View { + + public init(errors: Int, warnings: Int) { + self.errors = errors + self.warnings = warnings + } + + private var errors: Int + private var warnings: Int + private var branches: [String] = ["master", "new-feature"] + + @State private var selectedBranch: Int = 0 + @State private var isExpanded: Bool = false + + public var body: some View { + ZStack { + Rectangle() + .foregroundStyle(.bar) + HStack { + labelButton(errors.formatted(), image: "xmark.octagon") + labelButton(warnings.formatted(), image: "exclamationmark.triangle") + branchPicker + Spacer() + expandButton + } + .padding(.horizontal, 10) + } + .overlay(alignment: .top) { + Divider() + } + .frame(height: 32) + .padding(.top, -8) + } + + private func labelButton(_ text: String, image: String) -> some View { + Button {} label: { + HStack(spacing: 4) { + Image(systemName: image) + .font(.headline) + Text(text) + } + } + .buttonStyle(.borderless) + } + + private var branchPicker: some View { + Menu(branches[selectedBranch]) { + ForEach(branches.indices, id: \.self) { branch in + Button { selectedBranch = branch } label: { + Text(branches[branch]) + .foregroundColor(.black) + } + } + } + .menuStyle(.borderlessButton) + .fixedSize() + } + + private var expandButton: some View { + Button { + isExpanded.toggle() + } label: { + Image(systemName: "rectangle.bottomthird.inset.filled") + .imageScale(.large) + } + .tint(isExpanded ? .accentColor : .secondary) + .buttonStyle(.borderless) + } +} + +struct SwiftUIView_Previews: PreviewProvider { + static var previews: some View { + StatusBarView(errors: 0, warnings: 0) + .previewLayout(.fixed(width: 1336, height: 32)) + .preferredColorScheme(.dark) + } +} diff --git a/CodeEditModules/Package.swift b/CodeEditModules/Package.swift index f193d3954..3ede9287e 100644 --- a/CodeEditModules/Package.swift +++ b/CodeEditModules/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "CodeEditModules", defaultLocalization: "en", platforms: [ - .macOS(.v11) + .macOS(.v12) ], products: [ .library( @@ -17,7 +17,8 @@ let package = Package( name: "CodeFile", targets: ["CodeFile"] ), - .library(name: "WelcomeModule", targets: ["WelcomeModule"]) + .library(name: "WelcomeModule", targets: ["WelcomeModule"]), + .library(name: "StatusBar", targets: ["StatusBar"]) ], dependencies: [ .package( @@ -71,6 +72,7 @@ let package = Package( "SnapshotTesting" ], path: "Modules/WelcomeModule/Tests" - ) + ), + .target(name: "StatusBar", path: "Modules/StatusBar/src") ] ) From 4225031fa016bfeeb7a112ed56f698c31942e050 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 19 Mar 2022 18:59:25 +0100 Subject: [PATCH 11/18] removed Dev-Team --- CodeEdit.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index 9e11dedd0..379f795b7 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -665,12 +665,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = F992DREF6G; + DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -696,12 +696,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIconDev; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = CodeEdit/CodeEdit.entitlements; - CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"CodeEdit/Preview Content\""; - DEVELOPMENT_TEAM = F992DREF6G; + DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; From 4977f76d288fea77a43f276877c0188b022daf66 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 01:25:53 +0100 Subject: [PATCH 12/18] added missing items --- .../Modules/StatusBar/src/StatusBar.swift | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index a9b20f612..ccbf79c95 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -18,18 +18,29 @@ public struct StatusBarView: View { private var warnings: Int private var branches: [String] = ["master", "new-feature"] + // TODO: Create a View Model for this @State private var selectedBranch: Int = 0 @State private var isExpanded: Bool = false + @State private var reloading: Bool = false + @State private var line: Int = 1 + @State private var col: Int = 1 public var body: some View { ZStack { Rectangle() .foregroundStyle(.bar) - HStack { + HStack(spacing: 14) { + HStack(spacing: 8) { labelButton(errors.formatted(), image: "xmark.octagon") labelButton(warnings.formatted(), image: "exclamationmark.triangle") + } branchPicker + reloadButton Spacer() + cursorLocationLabel + indentSelector + encodingSelector + lineEndSelector expandButton } .padding(.horizontal, 10) @@ -50,6 +61,7 @@ public struct StatusBarView: View { } } .buttonStyle(.borderless) + .foregroundStyle(.primary) } private var branchPicker: some View { @@ -57,7 +69,6 @@ public struct StatusBarView: View { ForEach(branches.indices, id: \.self) { branch in Button { selectedBranch = branch } label: { Text(branches[branch]) - .foregroundColor(.black) } } } @@ -65,6 +76,60 @@ public struct StatusBarView: View { .fixedSize() } + private var reloadButton: some View { + Button { + reloading = true + // Just for looks for now. In future we'll call a function like + // `reloadFileStatus()` here which will set/unset `reloading` + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + self.reloading = false + } + } label: { + Image(systemName: "arrow.triangle.2.circlepath") + .imageScale(.large) + .rotationEffect(.degrees(reloading ? 360 : 0)) + .animation(animation, value: reloading) + .opacity(reloading ? 1 : 0) + // A bit of a hacky solution to prevent spinning counterclockwise once `reloading` changes to `false` + .overlay { + Image(systemName: "arrow.triangle.2.circlepath") + .imageScale(.large) + .opacity(reloading ? 0 : 1) + } + + } + .buttonStyle(.borderless) + .foregroundStyle(.primary) + } + + private var animation: Animation { + // 10x speed when not reloading to make invisible ccw spin go fast in case button is pressed multiple times. + .linear.speed(reloading ? 0.5 : 10) + } + + private var cursorLocationLabel: some View { + Text("Ln \(line), Col \(col)") + .foregroundStyle(.primary) + } + + private var indentSelector: some View { + Menu("2 Spaces") {} + .menuStyle(.borderlessButton) + .fixedSize() + } + + private var encodingSelector: some View { + Menu("UTF 8") {} + .menuStyle(.borderlessButton) + .fixedSize() + } + + private var lineEndSelector: some View { + Menu("LF") {} + .menuStyle(.borderlessButton) + .fixedSize() + } + private var expandButton: some View { Button { isExpanded.toggle() @@ -81,6 +146,6 @@ struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { StatusBarView(errors: 0, warnings: 0) .previewLayout(.fixed(width: 1336, height: 32)) - .preferredColorScheme(.dark) + .preferredColorScheme(.light) } } From a4260549074aca783cfdea35b4abb6d71bb128c5 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 11:49:24 +0100 Subject: [PATCH 13/18] fixed indentation in `Package.swift` --- CodeEditModules/Package.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/CodeEditModules/Package.swift b/CodeEditModules/Package.swift index 3ede9287e..58b4bcec8 100644 --- a/CodeEditModules/Package.swift +++ b/CodeEditModules/Package.swift @@ -17,8 +17,14 @@ let package = Package( name: "CodeFile", targets: ["CodeFile"] ), - .library(name: "WelcomeModule", targets: ["WelcomeModule"]), - .library(name: "StatusBar", targets: ["StatusBar"]) + .library( + name: "WelcomeModule", + targets: ["WelcomeModule"] + ), + .library( + name: "StatusBar", + targets: ["StatusBar"] + ) ], dependencies: [ .package( @@ -73,6 +79,9 @@ let package = Package( ], path: "Modules/WelcomeModule/Tests" ), - .target(name: "StatusBar", path: "Modules/StatusBar/src") + .target( + name: "StatusBar", + path: "Modules/StatusBar/src" + ) ] ) From 975727c5ff4633fb1c0b6dc3868b8b51cd9266dd Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 12:09:15 +0100 Subject: [PATCH 14/18] Added boilerplate view model --- CodeEdit/SideBar/SideBarItem.swift | 2 +- .../Modules/StatusBar/src/StatusBar.swift | 54 ++++++++----------- .../StatusBar/src/StatusBarModel.swift | 27 ++++++++++ 3 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift diff --git a/CodeEdit/SideBar/SideBarItem.swift b/CodeEdit/SideBar/SideBarItem.swift index 897ef803b..53accca17 100644 --- a/CodeEdit/SideBar/SideBarItem.swift +++ b/CodeEdit/SideBar/SideBarItem.swift @@ -42,7 +42,7 @@ struct SideBarItem: View { } } .safeAreaInset(edge: .bottom) { - StatusBarView(errors: 0, warnings: 0) + StatusBarView() } } else { Text("CodeEdit cannot open this file because its file type is not supported.") diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index ccbf79c95..e888d5307 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -9,21 +9,11 @@ import SwiftUI public struct StatusBarView: View { - public init(errors: Int, warnings: Int) { - self.errors = errors - self.warnings = warnings - } - - private var errors: Int - private var warnings: Int - private var branches: [String] = ["master", "new-feature"] + @ObservedObject private var model: StatusBarModel - // TODO: Create a View Model for this - @State private var selectedBranch: Int = 0 - @State private var isExpanded: Bool = false - @State private var reloading: Bool = false - @State private var line: Int = 1 - @State private var col: Int = 1 + public init() { + self.model = .init() + } public var body: some View { ZStack { @@ -31,8 +21,8 @@ public struct StatusBarView: View { .foregroundStyle(.bar) HStack(spacing: 14) { HStack(spacing: 8) { - labelButton(errors.formatted(), image: "xmark.octagon") - labelButton(warnings.formatted(), image: "exclamationmark.triangle") + labelButton(model.errorCount.formatted(), image: "xmark.octagon") + labelButton(model.warningCount.formatted(), image: "exclamationmark.triangle") } branchPicker reloadButton @@ -49,7 +39,7 @@ public struct StatusBarView: View { Divider() } .frame(height: 32) - .padding(.top, -8) + .padding(.top, -8) // removes weird light gray bar above when in light mode } private func labelButton(_ text: String, image: String) -> some View { @@ -65,10 +55,10 @@ public struct StatusBarView: View { } private var branchPicker: some View { - Menu(branches[selectedBranch]) { - ForEach(branches.indices, id: \.self) { branch in - Button { selectedBranch = branch } label: { - Text(branches[branch]) + Menu(model.branches[model.selectedBranch]) { + ForEach(model.branches.indices, id: \.self) { branch in + Button { model.selectedBranch = branch } label: { + Text(model.branches[branch]) } } } @@ -78,23 +68,23 @@ public struct StatusBarView: View { private var reloadButton: some View { Button { - reloading = true + model.isReloading = true // Just for looks for now. In future we'll call a function like // `reloadFileStatus()` here which will set/unset `reloading` DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - self.reloading = false + self.model.isReloading = false } } label: { Image(systemName: "arrow.triangle.2.circlepath") .imageScale(.large) - .rotationEffect(.degrees(reloading ? 360 : 0)) - .animation(animation, value: reloading) - .opacity(reloading ? 1 : 0) + .rotationEffect(.degrees(model.isReloading ? 360 : 0)) + .animation(animation, value: model.isReloading) + .opacity(model.isReloading ? 1 : 0) // A bit of a hacky solution to prevent spinning counterclockwise once `reloading` changes to `false` .overlay { Image(systemName: "arrow.triangle.2.circlepath") .imageScale(.large) - .opacity(reloading ? 0 : 1) + .opacity(model.isReloading ? 0 : 1) } } @@ -104,11 +94,11 @@ public struct StatusBarView: View { private var animation: Animation { // 10x speed when not reloading to make invisible ccw spin go fast in case button is pressed multiple times. - .linear.speed(reloading ? 0.5 : 10) + .linear.speed(model.isReloading ? 0.5 : 10) } private var cursorLocationLabel: some View { - Text("Ln \(line), Col \(col)") + Text("Ln \(model.currentLine), Col \(model.currentCol)") .foregroundStyle(.primary) } @@ -132,19 +122,19 @@ public struct StatusBarView: View { private var expandButton: some View { Button { - isExpanded.toggle() + model.isExpanded.toggle() } label: { Image(systemName: "rectangle.bottomthird.inset.filled") .imageScale(.large) } - .tint(isExpanded ? .accentColor : .secondary) + .tint(model.isExpanded ? .accentColor : .primary) .buttonStyle(.borderless) } } struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { - StatusBarView(errors: 0, warnings: 0) + StatusBarView() .previewLayout(.fixed(width: 1336, height: 32)) .preferredColorScheme(.light) } diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift b/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift new file mode 100644 index 000000000..18104b573 --- /dev/null +++ b/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift @@ -0,0 +1,27 @@ +// +// StatusBarModel.swift +// +// +// Created by Lukas Pistrol on 20.03.22. +// + +import Foundation + +public class StatusBarModel: ObservableObject { + + // TODO: Implement logic for updating values + @Published public var errorCount: Int = 0 // Implementation missing + @Published public var warningCount: Int = 0 // Implementation missing + + @Published public var branches: [String] = ["main"] // Implementation missing + @Published public var selectedBranch: Int = 0 // Implementation missing + + @Published public var isReloading: Bool = false // Implementation missing + + @Published public var currentLine: Int = 1 // Implementation missing + @Published public var currentCol: Int = 1 // Implementation missing + + @Published public var isExpanded: Bool = false // Implementation missing + + public init() {} +} From 2dbcf3cd192ad04081e338b022e5d6c478979ea5 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 12:20:43 +0100 Subject: [PATCH 15/18] added comments for future implementation --- .../Modules/StatusBar/src/StatusBar.swift | 22 ++++++++++++++----- .../StatusBar/src/StatusBarModel.swift | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index e888d5307..bd3bd2fe7 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -39,11 +39,13 @@ public struct StatusBarView: View { Divider() } .frame(height: 32) - .padding(.top, -8) // removes weird light gray bar above when in light mode + .padding(.top, -8) // removes weird light gray bar above when in light mode (comment out to make it look normal in preview) } private func labelButton(_ text: String, image: String) -> some View { - Button {} label: { + Button { + // show errors/warnings + } label: { HStack(spacing: 4) { Image(systemName: image) .font(.headline) @@ -59,6 +61,7 @@ public struct StatusBarView: View { ForEach(model.branches.indices, id: \.self) { branch in Button { model.selectedBranch = branch } label: { Text(model.branches[branch]) + // checkout branch } } } @@ -67,6 +70,7 @@ public struct StatusBarView: View { } private var reloadButton: some View { + // Temporary Button { model.isReloading = true // Just for looks for now. In future we'll call a function like @@ -92,6 +96,7 @@ public struct StatusBarView: View { .foregroundStyle(.primary) } + // Temporary private var animation: Animation { // 10x speed when not reloading to make invisible ccw spin go fast in case button is pressed multiple times. .linear.speed(model.isReloading ? 0.5 : 10) @@ -103,19 +108,25 @@ public struct StatusBarView: View { } private var indentSelector: some View { - Menu("2 Spaces") {} + Menu("2 Spaces") { + // 2 spaces, 4 spaces, ... + } .menuStyle(.borderlessButton) .fixedSize() } private var encodingSelector: some View { - Menu("UTF 8") {} + Menu("UTF 8") { + // UTF 8, ASCII, ... + } .menuStyle(.borderlessButton) .fixedSize() } private var lineEndSelector: some View { - Menu("LF") {} + Menu("LF") { + // LF, CRLF + } .menuStyle(.borderlessButton) .fixedSize() } @@ -123,6 +134,7 @@ public struct StatusBarView: View { private var expandButton: some View { Button { model.isExpanded.toggle() + // Show/hide terminal window } label: { Image(systemName: "rectangle.bottomthird.inset.filled") .imageScale(.large) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift b/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift index 18104b573..457fe3c99 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBarModel.swift @@ -23,5 +23,7 @@ public class StatusBarModel: ObservableObject { @Published public var isExpanded: Bool = false // Implementation missing + // TODO: Add @Published vars for indentation, encoding, linebreak + public init() {} } From 5263af0ce89626a102db6f21eb09c212b0d9d7db Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 12:23:16 +0100 Subject: [PATCH 16/18] fixed lint error --- CodeEditModules/Modules/StatusBar/src/StatusBar.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index bd3bd2fe7..08f4d457a 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -39,7 +39,8 @@ public struct StatusBarView: View { Divider() } .frame(height: 32) - .padding(.top, -8) // removes weird light gray bar above when in light mode (comment out to make it look normal in preview) + // removes weird light gray bar above when in light mode + .padding(.top, -8) // (comment out to make it look normal in preview) } private func labelButton(_ text: String, image: String) -> some View { From 4c3678b5dd2fd27eb0160a3886ab77a047a5276c Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 14:28:30 +0100 Subject: [PATCH 17/18] added placeholder terminal view + drag gesture --- .../Modules/StatusBar/src/StatusBar.swift | 110 +++++++++++++++++- 1 file changed, 104 insertions(+), 6 deletions(-) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index 08f4d457a..7083da73b 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -16,6 +16,28 @@ public struct StatusBarView: View { } public var body: some View { + VStack(spacing: 0) { + bar + if model.isExpanded { + terminal + } + } + // removes weird light gray bar above when in light mode + .padding(.top, -8) // (comment out to make it look normal in preview) + } + + private var dragGesture: some Gesture { + DragGesture() + .onChanged { value in + let newHeight = max(0, min(height - value.translation.height, 350)) + if newHeight-1 > height || newHeight+1 < height { + height = newHeight + } + model.isExpanded = height < 1 ? false : true + } + } + + private var bar: some View { ZStack { Rectangle() .foregroundStyle(.bar) @@ -39,9 +61,23 @@ public struct StatusBarView: View { Divider() } .frame(height: 32) - // removes weird light gray bar above when in light mode - .padding(.top, -8) // (comment out to make it look normal in preview) - } + .gesture(dragGesture) + .onHover { hovering in + if hovering { + NSCursor.resizeUpDown.push() + } else { + NSCursor.pop() + } + } + } + + @State private var height: Double = 300 + + private var terminal: some View { + Rectangle() + .foregroundColor(Color(red: 0.163, green: 0.163, blue: 0.188, opacity: 1.000)) + .frame(minHeight: 0, idealHeight: height, maxHeight: height) + } private func labelButton(_ text: String, image: String) -> some View { Button { @@ -55,6 +91,13 @@ public struct StatusBarView: View { } .buttonStyle(.borderless) .foregroundStyle(.primary) + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } private var branchPicker: some View { @@ -68,6 +111,13 @@ public struct StatusBarView: View { } .menuStyle(.borderlessButton) .fixedSize() + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } private var reloadButton: some View { @@ -95,6 +145,13 @@ public struct StatusBarView: View { } .buttonStyle(.borderless) .foregroundStyle(.primary) + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } // Temporary @@ -106,6 +163,13 @@ public struct StatusBarView: View { private var cursorLocationLabel: some View { Text("Ln \(model.currentLine), Col \(model.currentCol)") .foregroundStyle(.primary) + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } private var indentSelector: some View { @@ -114,6 +178,13 @@ public struct StatusBarView: View { } .menuStyle(.borderlessButton) .fixedSize() + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } private var encodingSelector: some View { @@ -122,6 +193,13 @@ public struct StatusBarView: View { } .menuStyle(.borderlessButton) .fixedSize() + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } private var lineEndSelector: some View { @@ -130,11 +208,21 @@ public struct StatusBarView: View { } .menuStyle(.borderlessButton) .fixedSize() + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } private var expandButton: some View { Button { model.isExpanded.toggle() + if model.isExpanded && height < 1 { + height = 300 + } // Show/hide terminal window } label: { Image(systemName: "rectangle.bottomthird.inset.filled") @@ -142,13 +230,23 @@ public struct StatusBarView: View { } .tint(model.isExpanded ? .accentColor : .primary) .buttonStyle(.borderless) + .onHover { hovering in + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } } } struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { - StatusBarView() - .previewLayout(.fixed(width: 1336, height: 32)) - .preferredColorScheme(.light) + ZStack(alignment: .bottom) { + Color.white + StatusBarView() + .previewLayout(.fixed(width: 1.336, height: 500.0)) + .preferredColorScheme(.light) + } } } From 45e7102e082c474364a05ec015ea0f3959c87e23 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 20 Mar 2022 16:23:54 +0100 Subject: [PATCH 18/18] added `@available(macOS 12, *)` as workaround until we can bump `CodeEditModules` to `.v12` --- CodeEditModules/Modules/StatusBar/src/StatusBar.swift | 4 +++- CodeEditModules/Package.swift | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift index 7083da73b..e2f5a970a 100644 --- a/CodeEditModules/Modules/StatusBar/src/StatusBar.swift +++ b/CodeEditModules/Modules/StatusBar/src/StatusBar.swift @@ -7,6 +7,7 @@ import SwiftUI +@available(macOS 12, *) public struct StatusBarView: View { @ObservedObject private var model: StatusBarModel @@ -29,7 +30,7 @@ public struct StatusBarView: View { private var dragGesture: some Gesture { DragGesture() .onChanged { value in - let newHeight = max(0, min(height - value.translation.height, 350)) + let newHeight = max(0, min(height - value.translation.height, 500)) if newHeight-1 > height || newHeight+1 < height { height = newHeight } @@ -240,6 +241,7 @@ public struct StatusBarView: View { } } +@available(macOS 12, *) struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { ZStack(alignment: .bottom) { diff --git a/CodeEditModules/Package.swift b/CodeEditModules/Package.swift index 58b4bcec8..fc39fed2f 100644 --- a/CodeEditModules/Package.swift +++ b/CodeEditModules/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "CodeEditModules", defaultLocalization: "en", platforms: [ - .macOS(.v12) + .macOS(.v11) ], products: [ .library(