Skip to content

Commit

Permalink
Tab Improvements (#128)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
5 people authored Mar 21, 2022
1 parent adc8036 commit c07955c
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 161 deletions.
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 @@ -93,7 +93,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>"; };
70F2E28327E848720002BA81 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand All @@ -104,6 +103,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 @@ -213,14 +213,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 @@ -263,11 +255,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 @@ -504,6 +496,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 @@ -523,7 +516,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

0 comments on commit c07955c

Please sign in to comment.