Skip to content

Commit c07955c

Browse files
austincondifflukepistrolpkasilananashiliRayZhao1998
authored
Tab Improvements (#128)
* Improved overall tab style to feel more native to macOS * Fixed lint error * More lint error fixes * More lint error fixes * More liner error fixes * Create CONTRIBUTING.md * Update CONTRIBUTING.md * Update CONTRIBUTING.md * Update CONTRIBUTING.md * Fix "Welcome to CodeEdit" Main Menu item (#106) * Fix data format (#105) * Allow opening of `public.item` instead of `public.source-code` * Handle errors * Message Preview when opening the non coding file (#102) * Cleaned up the typography for Welcome Screen * Added support for more code editor themes * Revert "Added support for more code editor themes" This reverts commit 8139217. * Revert "Cleaned up the typography for Welcome Screen" This reverts commit 78b748b. * Update the error message to be more informative when trying to open files that are not code related * Added language translations for editor error and support for the Afrikaans Language * Fixed localization changes in Russian and Belarusian * Updated the editor error string to be short and sweet * Update to editor error for file types. * Change document types priority, prioritize workspace over source code file to fix #110 * Fix multiple welcome window * Fix version localization key (#120) * Improved overall tab style to feel more native to macOS * Fixed lint error * More lint error fixes * Replicating aesthetic and behavior of standard tabs. Removed wrapper component so that code is more straightforward. * Update WorkspaceCodeFileView.swift Resolved conflicts * Fixed lint errors and animations * Added PressActionsModifier file to project * Added PressActionsModifier.swift * Fixed lint error * Fixed lint error Co-authored-by: Luke <[email protected]> Co-authored-by: Pavel Kasila <[email protected]> Co-authored-by: Nanashi Li <[email protected]> Co-authored-by: Ziyuan Zhao <[email protected]>
1 parent adc8036 commit c07955c

File tree

10 files changed

+219
-161
lines changed

10 files changed

+219
-161
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
28CE5EA027E6493D0065D29C /* StatusBar in Frameworks */ = {isa = PBXBuildFile; productRef = 28CE5E9F27E6493D0065D29C /* StatusBar */; };
3333
28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */; };
3434
2B7A583527E4BA0100D25D4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468438427DC76E200F8E88E /* AppDelegate.swift */; };
35-
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345F667427DF6C180069BD69 /* FileTabRow.swift */; };
3635
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE19BD27E0469C00F152CE /* BlurView.swift */; };
3736
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C403B8E27E20F8000788241 /* WorkspaceClient */; };
3837
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */ = {isa = PBXBuildFile; productRef = 5CF38A5D27E48E6C0096A0F7 /* CodeFile */; };
3938
B658FB3427DA9E1000EA4DBD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3327DA9E1000EA4DBD /* Assets.xcassets */; };
4039
B658FB3727DA9E1000EA4DBD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3627DA9E1000EA4DBD /* Preview Assets.xcassets */; };
4140
B65E614627E6765D00255275 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = B65E614527E6765D00255275 /* Introspect */; };
41+
B673FDAD27E8296A00795864 /* PressActionsModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = B673FDAC27E8296A00795864 /* PressActionsModifier.swift */; };
4242
D70F5E2C27E4E8CF004EE4B9 /* WelcomeModule in Frameworks */ = {isa = PBXBuildFile; productRef = D70F5E2B27E4E8CF004EE4B9 /* WelcomeModule */; };
4343
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */; };
4444
D7211D4727E06BFE008F2ED7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D7211D4927E06BFE008F2ED7 /* Localizable.strings */; };
@@ -93,7 +93,6 @@
9393
289978EC27E4E97E00BB0357 /* FileIconStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileIconStyle.swift; sourceTree = "<group>"; };
9494
28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarTop.swift; sourceTree = "<group>"; };
9595
28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarBottom.swift; sourceTree = "<group>"; };
96-
345F667427DF6C180069BD69 /* FileTabRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTabRow.swift; sourceTree = "<group>"; };
9796
34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
9897
5E3C6A3427E72AE000A7CA0D /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
9998
70F2E28327E848720002BA81 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
@@ -104,6 +103,7 @@
104103
B658FB3827DA9E1000EA4DBD /* CodeEdit.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CodeEdit.entitlements; sourceTree = "<group>"; };
105104
B658FB3D27DA9E1000EA4DBD /* CodeEditTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodeEditTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
106105
B658FB4727DA9E1000EA4DBD /* CodeEditUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodeEditUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
106+
B673FDAC27E8296A00795864 /* PressActionsModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PressActionsModifier.swift; sourceTree = "<group>"; };
107107
D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Localized+Ex.swift"; sourceTree = "<group>"; };
108108
D7211D4827E06BFE008F2ED7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
109109
D7211D4A27E06C01008F2ED7 /* sr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -213,14 +213,6 @@
213213
path = TabBar;
214214
sourceTree = "<group>";
215215
};
216-
345F667327DF6BCC0069BD69 /* Rows */ = {
217-
isa = PBXGroup;
218-
children = (
219-
345F667427DF6C180069BD69 /* FileTabRow.swift */,
220-
);
221-
path = Rows;
222-
sourceTree = "<group>";
223-
};
224216
34EE19BC27E0467F00F152CE /* CustomViews */ = {
225217
isa = PBXGroup;
226218
children = (
@@ -263,11 +255,11 @@
263255
D72E1A8127E3B0A300EB11B9 /* Welcome */,
264256
043C321227E31FE8006AE443 /* Documents */,
265257
0468438427DC76E200F8E88E /* AppDelegate.swift */,
258+
B673FDAC27E8296A00795864 /* PressActionsModifier.swift */,
266259
B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */,
267260
2875A46E27E3BE63007805F8 /* Breadcrumbs */,
268261
287776EA27E350A100D46668 /* SideBar */,
269262
287776EB27E350BA00D46668 /* TabBar */,
270-
345F667327DF6BCC0069BD69 /* Rows */,
271263
04F2BF1027DBB3AF0024EAB1 /* Settings */,
272264
34EE19BC27E0467F00F152CE /* CustomViews */,
273265
D7211D4427E066D4008F2ED7 /* Localization */,
@@ -504,6 +496,7 @@
504496
04540D5B27DD08C300E91B77 /* SettingsView.swift in Sources */,
505497
D72E1A8927E44D7C00EB11B9 /* WelcomeWindowView.swift in Sources */,
506498
04540D5C27DD08C300E91B77 /* GeneralSettingsView.swift in Sources */,
499+
B673FDAD27E8296A00795864 /* PressActionsModifier.swift in Sources */,
507500
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */,
508501
04660F6427E3ACAF00477777 /* Appearances.swift in Sources */,
509502
04540D5E27DD08C300E91B77 /* WorkspaceView.swift in Sources */,
@@ -523,7 +516,6 @@
523516
D72E1A8327E3B0D400EB11B9 /* WelcomeView.swift in Sources */,
524517
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
525518
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */,
526-
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */,
527519
28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */,
528520
0485EB2327E7791400138301 /* QuickOpenPreviewView.swift in Sources */,
529521
);

CodeEdit/CustomViews/BlurView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct BlurView: NSViewRepresentable {
1616
let visualEffectView = NSVisualEffectView()
1717
visualEffectView.material = material
1818
visualEffectView.blendingMode = blendingMode
19-
visualEffectView.state = NSVisualEffectView.State.active
19+
visualEffectView.state = NSVisualEffectView.State.followsWindowActiveState
2020
return visualEffectView
2121
}
2222

CodeEdit/Documents/WorkspaceCodeFileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct WorkspaceCodeFileView: View {
2323
.safeAreaInset(edge: .top, spacing: 0) {
2424
VStack(spacing: 0) {
2525
TabBar(windowController: windowController, workspace: workspace)
26-
CustomDivider()
26+
TabBarDivider()
2727
BreadcrumbsView(item, workspace: workspace)
2828
}
2929
}

CodeEdit/Documents/WorkspaceDocument.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
2121
@Published var sortFoldersOnTop: Bool = true
2222
@Published var fileItems: [WorkspaceClient.FileItem] = []
2323

24+
var selected: WorkspaceClient.FileItem? {
25+
guard let selectedId = selectedId else { return nil }
26+
return fileItems.first(where: { $0.id == selectedId })
27+
}
2428
var quickOpenState: QuickOpenState?
25-
2629
var openedCodeFiles: [WorkspaceClient.FileItem: CodeFileDocument] = [:]
2730
private var cancellables = Set<AnyCancellable>()
2831

@@ -48,6 +51,26 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
4851
selectedId = openFileItems[idx - 1].id
4952
}
5053
}
54+
func closeFileTabs<Items>(items: Items) where Items: Collection, Items.Element == WorkspaceClient.FileItem {
55+
// TODO: Could potentially be optimized
56+
for item in items {
57+
closeFileTab(item: item)
58+
}
59+
}
60+
61+
func closeFileTab(where predicate: (WorkspaceClient.FileItem) -> Bool) {
62+
closeFileTabs(items: openFileItems.filter(predicate))
63+
}
64+
65+
func closeFileTabs(after item: WorkspaceClient.FileItem) {
66+
guard let startIdx = openFileItems.firstIndex(where: { $0.id == item.id }) else {
67+
assert(false, "Expected file item to be present in openFileItems")
68+
return
69+
}
70+
71+
let range = openFileItems[(startIdx+1)...]
72+
closeFileTabs(items: range)
73+
}
5174

5275
func openFile(item: WorkspaceClient.FileItem) {
5376
do {

CodeEdit/PressActionsModifier.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Created by Gabriel Theodoropoulos on 1/11/20.
3+
//
4+
5+
import SwiftUI
6+
7+
struct PressActions: ViewModifier {
8+
var onPress: () -> Void
9+
var onRelease: () -> Void
10+
func body(content: Content) -> some View {
11+
content
12+
.simultaneousGesture(
13+
DragGesture(minimumDistance: 0)
14+
.onChanged({ _ in
15+
onPress()
16+
})
17+
.onEnded({ _ in
18+
onRelease()
19+
})
20+
)
21+
}
22+
}
23+
24+
extension View {
25+
func pressAction(onPress: @escaping (() -> Void), onRelease: @escaping (() -> Void)) -> some View {
26+
modifier(PressActions(onPress: {
27+
onPress()
28+
}, onRelease: {
29+
onRelease()
30+
}))
31+
}
32+
}

CodeEdit/Rows/FileTabRow.swift

Lines changed: 0 additions & 77 deletions
This file was deleted.

CodeEdit/SideBar/SideBarItem.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import WorkspaceClient
1010
import CodeFile
1111

1212
struct SideBarItem: View {
13-
1413
@AppStorage(FileIconStyle.storageKey) var iconStyle: FileIconStyle = .default
1514

1615
var item: WorkspaceClient.FileItem

CodeEdit/TabBar/TabBar.swift

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99
import WorkspaceClient
1010

11-
struct CustomDivider: View {
11+
struct TabBarDivider: View {
1212
@Environment(\.colorScheme) var colorScheme
1313
let height: CGFloat = 1
1414

@@ -22,68 +22,36 @@ struct CustomDivider: View {
2222
}
2323

2424
struct TabBar: View {
25+
@Environment(\.colorScheme) var colorScheme
2526
var windowController: NSWindowController
2627
@ObservedObject var workspace: WorkspaceDocument
2728
var tabBarHeight = 28.0
2829
var body: some View {
2930
VStack(spacing: 0.0) {
30-
ScrollView(.horizontal, showsIndicators: false) {
31-
ScrollViewReader { value in
32-
HStack(alignment: .center, spacing: 0.0) {
33-
ForEach(workspace.openFileItems, id: \.id) { item in
34-
let isActive = workspace.selectedId == item.id
35-
36-
Button(
37-
action: { workspace.selectedId = item.id },
38-
label: {
39-
if isActive {
40-
TabBarItem(
41-
item: item,
42-
windowController: windowController,
43-
workspace: workspace
44-
)
45-
.background(
46-
BlurView(
47-
material: NSVisualEffectView.Material.titlebar,
48-
blendingMode: NSVisualEffectView.BlendingMode.withinWindow
49-
)
50-
)
51-
} else {
52-
TabBarItem(
53-
item: item,
54-
windowController: windowController,
55-
workspace: workspace
56-
)
57-
}
58-
}
59-
)
60-
.animation(.easeOut(duration: 0.2), value: workspace.openFileItems)
61-
.buttonStyle(.plain)
62-
.id(item.id)
63-
.keyboardShortcut(
64-
self.getTabId(fileName: item.fileName),
65-
modifiers: [.command]
66-
)
31+
ZStack(alignment: .top) {
32+
Rectangle()
33+
.fill(Color(nsColor: .black).opacity(colorScheme == .dark ? 0.45 : 0.05))
34+
.frame(height: 28)
35+
ScrollView(.horizontal, showsIndicators: false) {
36+
ScrollViewReader { value in
37+
HStack(alignment: .center, spacing: -1) {
38+
ForEach(workspace.openFileItems, id: \.id) { item in
39+
TabBarItem(
40+
item: item,
41+
windowController: windowController,
42+
workspace: workspace
43+
)
44+
}
45+
}
46+
.onAppear {
47+
value.scrollTo(self.workspace.selectedId)
6748
}
68-
}
69-
.onAppear {
70-
value.scrollTo(self.workspace.selectedId)
7149
}
7250
}
51+
.padding(.leading, -1)
7352
}
7453
}
75-
.background(BlurView(material: NSVisualEffectView.Material.windowBackground,
54+
.background(BlurView(material: NSVisualEffectView.Material.titlebar,
7655
blendingMode: NSVisualEffectView.BlendingMode.withinWindow))
7756
}
78-
79-
func getTabId(fileName: String) -> KeyEquivalent {
80-
for counter in 0..<9 where workspace.openFileItems.count > counter &&
81-
workspace.openFileItems[counter].fileName == fileName {
82-
return KeyEquivalent.init(
83-
Character.init("\(counter + 1)")
84-
)
85-
}
86-
87-
return "0"
88-
}
8957
}

0 commit comments

Comments
 (0)