From 1b5b195ce179f59f4ccaf6137577c966cd13e6dd Mon Sep 17 00:00:00 2001 From: Abe M Date: Tue, 19 Sep 2023 22:42:57 -0700 Subject: [PATCH 1/2] Fix icon draggin feature not being enabled --- CodeEdit.xcodeproj/project.pbxproj | 10 +++++++++- CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift | 1 + .../{ => ViewModels}/NavigatorSidebarViewModel.swift | 0 3 files changed, 10 insertions(+), 1 deletion(-) rename CodeEdit/Features/NavigatorArea/{ => ViewModels}/NavigatorSidebarViewModel.swift (100%) diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index ee58a7996..74e31d19e 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -1063,11 +1063,11 @@ 287776EA27E350A100D46668 /* NavigatorArea */ = { isa = PBXGroup; children = ( + 307AC4CB2ABABD9800163376 /* ViewModels */, D7012EE627E757660001E1EF /* FindNavigator */, 581550CB29FBD30400684881 /* OutlineView */, 286471AC27ED52950039369D /* ProjectNavigator */, 201169D52837B29600F92B46 /* SourceControlNavigator */, - 30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */, B67660682AA972D400CD56B0 /* Models */, B67660692AA972DC00CD56B0 /* Views */, ); @@ -1094,6 +1094,14 @@ path = OpenWithCodeEdit; sourceTree = ""; }; + 307AC4CB2ABABD9800163376 /* ViewModels */ = { + isa = PBXGroup; + children = ( + 30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */, + ); + path = ViewModels; + sourceTree = ""; + }; 3E0196712A392170002648D8 /* ShellIntegration */ = { isa = PBXGroup; children = ( diff --git a/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift b/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift index de4217537..4a6229237 100644 --- a/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift +++ b/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift @@ -83,6 +83,7 @@ struct AreaTabBar: View { y: (position == .side) ? (tabOffsets[icon] ?? 0) : 0 ) .background(makeTabItemGeometryReader(tab: icon)) + .simultaneousGesture(makeAreaTabDragGesture(tab: icon)) } if position == .side { Spacer() diff --git a/CodeEdit/Features/NavigatorArea/NavigatorSidebarViewModel.swift b/CodeEdit/Features/NavigatorArea/ViewModels/NavigatorSidebarViewModel.swift similarity index 100% rename from CodeEdit/Features/NavigatorArea/NavigatorSidebarViewModel.swift rename to CodeEdit/Features/NavigatorArea/ViewModels/NavigatorSidebarViewModel.swift From f01b2432c4d0658ad026e615ce5104cbe7b0760e Mon Sep 17 00:00:00 2001 From: Abe M Date: Sun, 24 Sep 2023 04:49:12 -0700 Subject: [PATCH 2/2] Fix visual dragging issues --- CodeEdit.xcodeproj/project.pbxproj | 12 ++++++++++++ .../Features/CodeEditUI/Views/AreaTabBar.swift | 10 +++++----- .../Controllers/CodeEditWindowController.swift | 2 +- .../ViewModels/InspectorAreaViewModel.swift | 18 ++++++++++++++++++ .../Views/InspectorAreaView.swift | 13 ++++++++----- .../ViewModels/NavigatorSidebarViewModel.swift | 3 ++- .../Views/NavigatorAreaView.swift | 6 +++--- .../Features/WindowCommands/ViewCommands.swift | 2 +- 8 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 CodeEdit/Features/InspectorArea/ViewModels/InspectorAreaViewModel.swift diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index 74e31d19e..aececcf40 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -54,6 +54,7 @@ 2B7AC06B282452FB0082A5B8 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2B7AC06A282452FB0082A5B8 /* Media.xcassets */; }; 2BE487EF28245162003F3F64 /* FinderSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE487EE28245162003F3F64 /* FinderSync.swift */; }; 2BE487F428245162003F3F64 /* OpenWithCodeEdit.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 3026F50F2AC006C80061227E /* InspectorAreaViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */; }; 30E6D0012A6E505200A58B20 /* NavigatorSidebarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */; }; 3E0196732A3921AC002648D8 /* codeedit_shell_integration.zsh in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */; }; 3E01967A2A392B45002648D8 /* codeedit_shell_integration.bash in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */; }; @@ -519,6 +520,7 @@ 2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OpenWithCodeEdit.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 2BE487EE28245162003F3F64 /* FinderSync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderSync.swift; sourceTree = ""; }; 2BE487F028245162003F3F64 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorAreaViewModel.swift; sourceTree = ""; }; 30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigatorSidebarViewModel.swift; sourceTree = ""; }; 3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.zsh; sourceTree = ""; }; 3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.bash; sourceTree = ""; }; @@ -1094,6 +1096,14 @@ path = OpenWithCodeEdit; sourceTree = ""; }; + 3026F50B2AC006A10061227E /* ViewModels */ = { + isa = PBXGroup; + children = ( + 3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */, + ); + path = ViewModels; + sourceTree = ""; + }; 307AC4CB2ABABD9800163376 /* ViewModels */ = { isa = PBXGroup; children = ( @@ -2505,6 +2515,7 @@ B6EE988E27E8877C00CDD8AB /* InspectorArea */ = { isa = PBXGroup; children = ( + 3026F50B2AC006A10061227E /* ViewModels */, B67660672AA972B000CD56B0 /* FileInspector */, B67660662AA9726F00CD56B0 /* HistoryInspector */, 20EBB50B280C382800F3A5DA /* Models */, @@ -2867,6 +2878,7 @@ 587B9E8A29301D8F00AC7927 /* GitHubIssue.swift in Sources */, EC0870F72A455F6400EB8692 /* ProjectNavigatorViewController+NSMenuDelegate.swift in Sources */, 6CAAF69429BCD78600A1F48A /* (null) in Sources */, + 3026F50F2AC006C80061227E /* InspectorAreaViewModel.swift in Sources */, 6C82D6C629C012AD00495C54 /* NSApp+openWindow.swift in Sources */, 6C14CEB028777D3C001468FE /* FindNavigatorListViewController.swift in Sources */, 587B9E7F29301D8F00AC7927 /* GitHubUserRouter.swift in Sources */, diff --git a/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift b/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift index 4a6229237..cf439e45c 100644 --- a/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift +++ b/CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift @@ -55,6 +55,7 @@ struct AreaTabBar: View { .frame(maxWidth: .infinity, maxHeight: .infinity) .animation(.default, value: items) } + .clipped() .frame(maxWidth: .infinity, idealHeight: 27) .fixedSize(horizontal: false, vertical: true) } @@ -66,6 +67,7 @@ struct AreaTabBar: View { .frame(maxWidth: .infinity, maxHeight: .infinity) .animation(.default, value: items) } + .clipped() .frame(idealWidth: 40, maxHeight: .infinity) .fixedSize(horizontal: true, vertical: false) } @@ -227,10 +229,8 @@ struct AreaTabBar: View { if isWithinBounds { let changing = swapTabWidth - 1 draggingStartLocation! += direction == .previous ? -changing : changing - withAnimation { - tabOffsets[tab]! += direction == .previous ? changing : -changing - items.swapAt(currentIndex, swapIndex) - } + tabOffsets[tab]! += direction == .previous ? changing : -changing + items.swapAt(currentIndex, swapIndex) } } // swiftlint: enable function_parameter_count @@ -276,7 +276,7 @@ struct AreaTabBar: View { Rectangle() .foregroundColor(.clear) .onAppear { - self.tabWidth[tab] = geometry.size.width + self.tabWidth[tab] = (position == .top) ? geometry.size.width : geometry.size.height self.tabLocations[tab] = geometry.frame(in: .global) } .onChange(of: geometry.frame(in: .global)) { newFrame in diff --git a/CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift b/CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift index 0281ef005..c89a1a62e 100644 --- a/CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift +++ b/CodeEdit/Features/Documents/Controllers/CodeEditWindowController.swift @@ -114,7 +114,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs splitVC.addSplitViewItem(mainContent) let inspectorView = SettingsInjector { - InspectorAreaView() + InspectorAreaView(viewModel: InspectorAreaViewModel()) .environmentObject(workspace) .environmentObject(workspace.editorManager) } diff --git a/CodeEdit/Features/InspectorArea/ViewModels/InspectorAreaViewModel.swift b/CodeEdit/Features/InspectorArea/ViewModels/InspectorAreaViewModel.swift new file mode 100644 index 000000000..a36f8f049 --- /dev/null +++ b/CodeEdit/Features/InspectorArea/ViewModels/InspectorAreaViewModel.swift @@ -0,0 +1,18 @@ +// +// InspectorAreaViewModel.swift +// CodeEdit +// +// Created by Abe Malla on 9/23/23. +// + +import Foundation + +class InspectorAreaViewModel: ObservableObject { + @Published var selectedTab: InspectorTab? = .file + /// The tab bar items in the Inspector + @Published var tabItems: [InspectorTab] = [] + + func setInspectorTab(tab newTab: InspectorTab) { + selectedTab = newTab + } +} diff --git a/CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift b/CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift index 3e83bdf38..2708e784e 100644 --- a/CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift +++ b/CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift @@ -11,6 +11,7 @@ struct InspectorAreaView: View { @EnvironmentObject private var workspace: WorkspaceDocument @ObservedObject private var extensionManager = ExtensionManager.shared + @ObservedObject public var viewModel: InspectorAreaViewModel @EnvironmentObject private var editorManager: EditorManager @@ -18,10 +19,12 @@ struct InspectorAreaView: View { var sidebarPosition: SettingsData.SidebarTabBarPosition @State private var selection: InspectorTab? = .file - @State private var items: [InspectorTab] = [.file, .gitHistory] - init() { - items += extensionManager + init(viewModel: InspectorAreaViewModel) { + self.viewModel = viewModel + + viewModel.tabItems = [.file, .gitHistory] + viewModel.tabItems += extensionManager .extensions .map { ext in ext.availableFeatures.compactMap { @@ -60,7 +63,7 @@ struct InspectorAreaView: View { if sidebarPosition == .side { HStack(spacing: 0) { Divider() - AreaTabBar(items: $items, selection: $selection, position: sidebarPosition) + AreaTabBar(items: $viewModel.tabItems, selection: $selection, position: sidebarPosition) } } } @@ -68,7 +71,7 @@ struct InspectorAreaView: View { if sidebarPosition == .top { VStack(spacing: 0) { Divider() - AreaTabBar(items: $items, selection: $selection, position: sidebarPosition) + AreaTabBar(items: $viewModel.tabItems, selection: $selection, position: sidebarPosition) Divider() } } else { diff --git a/CodeEdit/Features/NavigatorArea/ViewModels/NavigatorSidebarViewModel.swift b/CodeEdit/Features/NavigatorArea/ViewModels/NavigatorSidebarViewModel.swift index 5d9c89f9e..82199b107 100644 --- a/CodeEdit/Features/NavigatorArea/ViewModels/NavigatorSidebarViewModel.swift +++ b/CodeEdit/Features/NavigatorArea/ViewModels/NavigatorSidebarViewModel.swift @@ -9,7 +9,8 @@ import Foundation class NavigatorSidebarViewModel: ObservableObject { @Published var selectedTab: NavigatorTab? = .project - var items: [NavigatorTab] = [] + /// The tab bar items in the Navigator + @Published var tabItems: [NavigatorTab] = [] func setNavigatorTab(tab newTab: NavigatorTab) { selectedTab = newTab diff --git a/CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift b/CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift index 445890d9f..074985d38 100644 --- a/CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift +++ b/CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift @@ -19,7 +19,7 @@ struct NavigatorAreaView: View { self.workspace = workspace self.viewModel = viewModel - viewModel.items = [.project, .sourceControl, .search] + + viewModel.tabItems = [.project, .sourceControl, .search] + extensionManager .extensions .map { ext in @@ -44,7 +44,7 @@ struct NavigatorAreaView: View { .safeAreaInset(edge: .leading, spacing: 0) { if sidebarPosition == .side { HStack(spacing: 0) { - AreaTabBar(items: $viewModel.items, selection: $viewModel.selectedTab, position: sidebarPosition) + AreaTabBar(items: $viewModel.tabItems, selection: $viewModel.selectedTab, position: sidebarPosition) Divider() } } @@ -53,7 +53,7 @@ struct NavigatorAreaView: View { if sidebarPosition == .top { VStack(spacing: 0) { Divider() - AreaTabBar(items: $viewModel.items, selection: $viewModel.selectedTab, position: sidebarPosition) + AreaTabBar(items: $viewModel.tabItems, selection: $viewModel.selectedTab, position: sidebarPosition) Divider() } } else { diff --git a/CodeEdit/Features/WindowCommands/ViewCommands.swift b/CodeEdit/Features/WindowCommands/ViewCommands.swift index 0f567c6ab..dc557c77d 100644 --- a/CodeEdit/Features/WindowCommands/ViewCommands.swift +++ b/CodeEdit/Features/WindowCommands/ViewCommands.swift @@ -139,7 +139,7 @@ extension ViewCommands { var body: some View { Menu("Navigators", content: { - ForEach(Array(model.items.prefix(9).enumerated()), id: \.element) { index, tab in + ForEach(Array(model.tabItems.prefix(9).enumerated()), id: \.element) { index, tab in Button(tab.title) { model.setNavigatorTab(tab: tab) }