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

Tab Improvements #128

Merged
merged 26 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0993639
Improved overall tab style to feel more native to macOS
austincondiff Mar 19, 2022
85f29ee
Fixed lint error
austincondiff Mar 19, 2022
2163976
More lint error fixes
austincondiff Mar 19, 2022
5effe0f
More lint error fixes
austincondiff Mar 19, 2022
0240e50
More liner error fixes
austincondiff Mar 19, 2022
72797ec
Create CONTRIBUTING.md
lukepistrol Mar 19, 2022
9ef2fda
Update CONTRIBUTING.md
lukepistrol Mar 19, 2022
5b8f063
Update CONTRIBUTING.md
lukepistrol Mar 19, 2022
6f5347d
Update CONTRIBUTING.md
lukepistrol Mar 19, 2022
b340d99
Fix "Welcome to CodeEdit" Main Menu item (#106)
pkasila Mar 19, 2022
c5a2cb5
Fix data format (#105)
pkasila Mar 19, 2022
0b22e11
Message Preview when opening the non coding file (#102)
nanashili Mar 19, 2022
90507d9
Change document types priority, prioritize workspace over source code…
pkasila Mar 20, 2022
1cdfff6
Fix multiple welcome window
RayZhao1998 Mar 20, 2022
978aae2
Fix version localization key (#120)
pkasila Mar 20, 2022
f2f2db6
Improved overall tab style to feel more native to macOS
austincondiff Mar 19, 2022
ce4fd99
Fixed lint error
austincondiff Mar 19, 2022
5fa1de7
More lint error fixes
austincondiff Mar 19, 2022
ee5fd18
Replicating aesthetic and behavior of standard tabs. Removed wrapper …
austincondiff Mar 20, 2022
b5df269
Merge remote-tracking branch 'refs/remotes/origin/main'
austincondiff Mar 20, 2022
cf3420b
Update WorkspaceCodeFileView.swift
austincondiff Mar 20, 2022
e9c3c8f
Fixed lint errors and animations
austincondiff Mar 21, 2022
e307354
Added PressActionsModifier file to project
austincondiff Mar 21, 2022
b37110d
Added PressActionsModifier.swift
austincondiff Mar 21, 2022
556553d
Fixed lint error
austincondiff Mar 21, 2022
2c5e533
Fixed lint error
austincondiff Mar 21, 2022
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
16 changes: 4 additions & 12 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
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 */; };
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 */; };
B65E614627E6765D00255275 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = B65E614527E6765D00255275 /* Introspect */; };
B673FDAD27E8296A00795864 /* PressActionsModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B673FDAC27E8296A00795864 /* PressActionsModifier.swift */; };
D70F5E2C27E4E8CF004EE4B9 /* WelcomeModule in Frameworks */ = {isa = PBXBuildFile; productRef = D70F5E2B27E4E8CF004EE4B9 /* WelcomeModule */; };
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */; };
D7211D4727E06BFE008F2ED7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D7211D4927E06BFE008F2ED7 /* Localizable.strings */; };
Expand Down Expand Up @@ -92,7 +92,6 @@
289978EC27E4E97E00BB0357 /* FileIconStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileIconStyle.swift; sourceTree = "<group>"; };
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>"; };
34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
5E3C6A3427E72AE000A7CA0D /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodeEdit.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -102,6 +101,7 @@
B658FB3827DA9E1000EA4DBD /* CodeEdit.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CodeEdit.entitlements; sourceTree = "<group>"; };
B658FB3D27DA9E1000EA4DBD /* CodeEditTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodeEditTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B658FB4727DA9E1000EA4DBD /* CodeEditUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodeEditUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B673FDAC27E8296A00795864 /* PressActionsModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PressActionsModifier.swift; sourceTree = "<group>"; };
D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Localized+Ex.swift"; sourceTree = "<group>"; };
D7211D4827E06BFE008F2ED7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
D7211D4A27E06C01008F2ED7 /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -211,14 +211,6 @@
path = TabBar;
sourceTree = "<group>";
};
345F667327DF6BCC0069BD69 /* Rows */ = {
isa = PBXGroup;
children = (
345F667427DF6C180069BD69 /* FileTabRow.swift */,
);
path = Rows;
sourceTree = "<group>";
};
34EE19BC27E0467F00F152CE /* CustomViews */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -261,11 +253,11 @@
D72E1A8127E3B0A300EB11B9 /* Welcome */,
043C321227E31FE8006AE443 /* Documents */,
0468438427DC76E200F8E88E /* AppDelegate.swift */,
B673FDAC27E8296A00795864 /* PressActionsModifier.swift */,
B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */,
2875A46E27E3BE63007805F8 /* Breadcrumbs */,
287776EA27E350A100D46668 /* SideBar */,
287776EB27E350BA00D46668 /* TabBar */,
345F667327DF6BCC0069BD69 /* Rows */,
04F2BF1027DBB3AF0024EAB1 /* Settings */,
34EE19BC27E0467F00F152CE /* CustomViews */,
D7211D4427E066D4008F2ED7 /* Localization */,
Expand Down Expand Up @@ -500,6 +492,7 @@
04540D5B27DD08C300E91B77 /* SettingsView.swift in Sources */,
D72E1A8927E44D7C00EB11B9 /* WelcomeWindowView.swift in Sources */,
04540D5C27DD08C300E91B77 /* GeneralSettingsView.swift in Sources */,
B673FDAD27E8296A00795864 /* PressActionsModifier.swift in Sources */,
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */,
04660F6427E3ACAF00477777 /* Appearances.swift in Sources */,
04540D5E27DD08C300E91B77 /* WorkspaceView.swift in Sources */,
Expand All @@ -519,7 +512,6 @@
D72E1A8327E3B0D400EB11B9 /* WelcomeView.swift in Sources */,
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */,
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */,
28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */,
0485EB2327E7791400138301 /* QuickOpenPreviewView.swift in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/CustomViews/BlurView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct BlurView: NSViewRepresentable {
let visualEffectView = NSVisualEffectView()
visualEffectView.material = material
visualEffectView.blendingMode = blendingMode
visualEffectView.state = NSVisualEffectView.State.active
visualEffectView.state = NSVisualEffectView.State.followsWindowActiveState
return visualEffectView
}

Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Documents/WorkspaceCodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct WorkspaceCodeFileView: View {
.safeAreaInset(edge: .top, spacing: 0) {
VStack(spacing: 0) {
TabBar(windowController: windowController, workspace: workspace)
CustomDivider()
TabBarDivider()
BreadcrumbsView(item, workspace: workspace)
}
}
Expand Down
25 changes: 24 additions & 1 deletion CodeEdit/Documents/WorkspaceDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
@Published var sortFoldersOnTop: Bool = true
@Published var fileItems: [WorkspaceClient.FileItem] = []

var selected: WorkspaceClient.FileItem? {
guard let selectedId = selectedId else { return nil }
return fileItems.first(where: { $0.id == selectedId })
}
var quickOpenState: QuickOpenState?

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

Expand All @@ -48,6 +51,26 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
selectedId = openFileItems[idx - 1].id
}
}
func closeFileTabs<Items>(items: Items) where Items: Collection, Items.Element == WorkspaceClient.FileItem {
// TODO: Could potentially be optimized
for item in items {
closeFileTab(item: item)
}
}

func closeFileTab(where predicate: (WorkspaceClient.FileItem) -> Bool) {
closeFileTabs(items: openFileItems.filter(predicate))
}

func closeFileTabs(after item: WorkspaceClient.FileItem) {
guard let startIdx = openFileItems.firstIndex(where: { $0.id == item.id }) else {
assert(false, "Expected file item to be present in openFileItems")
return
}

let range = openFileItems[(startIdx+1)...]
closeFileTabs(items: range)
}

func openFile(item: WorkspaceClient.FileItem) {
do {
Expand Down
32 changes: 32 additions & 0 deletions CodeEdit/PressActionsModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Gabriel Theodoropoulos on 1/11/20.
//

import SwiftUI

struct PressActions: ViewModifier {
var onPress: () -> Void
var onRelease: () -> Void
func body(content: Content) -> some View {
content
.simultaneousGesture(
DragGesture(minimumDistance: 0)
.onChanged({ _ in
onPress()
})
.onEnded({ _ in
onRelease()
})
)
}
}

extension View {
func pressAction(onPress: @escaping (() -> Void), onRelease: @escaping (() -> Void)) -> some View {
modifier(PressActions(onPress: {
onPress()
}, onRelease: {
onRelease()
}))
}
}
77 changes: 0 additions & 77 deletions CodeEdit/Rows/FileTabRow.swift

This file was deleted.

1 change: 0 additions & 1 deletion CodeEdit/SideBar/SideBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import WorkspaceClient
import CodeFile

struct SideBarItem: View {

@AppStorage(FileIconStyle.storageKey) var iconStyle: FileIconStyle = .default

var item: WorkspaceClient.FileItem
Expand Down
74 changes: 21 additions & 53 deletions CodeEdit/TabBar/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI
import WorkspaceClient

struct CustomDivider: View {
struct TabBarDivider: View {
@Environment(\.colorScheme) var colorScheme
let height: CGFloat = 1

Expand All @@ -22,68 +22,36 @@ struct CustomDivider: View {
}

struct TabBar: View {
@Environment(\.colorScheme) var colorScheme
var windowController: NSWindowController
@ObservedObject var workspace: WorkspaceDocument
var tabBarHeight = 28.0
var body: some View {
VStack(spacing: 0.0) {
ScrollView(.horizontal, showsIndicators: false) {
ScrollViewReader { value in
HStack(alignment: .center, spacing: 0.0) {
ForEach(workspace.openFileItems, id: \.id) { item in
let isActive = workspace.selectedId == item.id

Button(
action: { workspace.selectedId = item.id },
label: {
if isActive {
TabBarItem(
item: item,
windowController: windowController,
workspace: workspace
)
.background(
BlurView(
material: NSVisualEffectView.Material.titlebar,
blendingMode: NSVisualEffectView.BlendingMode.withinWindow
)
)
} else {
TabBarItem(
item: item,
windowController: windowController,
workspace: workspace
)
}
}
)
.animation(.easeOut(duration: 0.2), value: workspace.openFileItems)
.buttonStyle(.plain)
.id(item.id)
.keyboardShortcut(
self.getTabId(fileName: item.fileName),
modifiers: [.command]
)
ZStack(alignment: .top) {
Rectangle()
.fill(Color(nsColor: .black).opacity(colorScheme == .dark ? 0.45 : 0.05))
.frame(height: 28)
ScrollView(.horizontal, showsIndicators: false) {
ScrollViewReader { value in
HStack(alignment: .center, spacing: -1) {
ForEach(workspace.openFileItems, id: \.id) { item in
TabBarItem(
item: item,
windowController: windowController,
workspace: workspace
)
}
}
.onAppear {
value.scrollTo(self.workspace.selectedId)
}
}
.onAppear {
value.scrollTo(self.workspace.selectedId)
}
}
.padding(.leading, -1)
}
}
.background(BlurView(material: NSVisualEffectView.Material.windowBackground,
.background(BlurView(material: NSVisualEffectView.Material.titlebar,
blendingMode: NSVisualEffectView.BlendingMode.withinWindow))
}

func getTabId(fileName: String) -> KeyEquivalent {
for counter in 0..<9 where workspace.openFileItems.count > counter &&
workspace.openFileItems[counter].fileName == fileName {
return KeyEquivalent.init(
Character.init("\(counter + 1)")
)
}

return "0"
}
}
Loading