Skip to content

Commit

Permalink
Rebuild Cached Files After Rename, Git Status Label (#1866)
Browse files Browse the repository at this point in the history
- Updates the rename method to get a new, cached, file instead of creating one unrelated to the rest of the tree.
- Removes the temporary tab when closing a tab if the tab was the temporary tab.
- Updates the git status label to use a dynamic color, so it appears white when the cell is selected.
  • Loading branch information
thecoolwinter authored Aug 31, 2024
1 parent 12a5dc9 commit 4bc7548
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Combine
import Foundation
import AppKit
import OSLog

protocol CEWorkspaceFileManagerObserver: AnyObject {
func fileManagerUpdated(updatedItems: Set<CEWorkspaceFile>)
Expand Down Expand Up @@ -38,6 +39,7 @@ protocol CEWorkspaceFileManagerObserver: AnyObject {
/// ``CEWorkspaceFileManagerObserver`` protocol. Use the ``CEWorkspaceFileManager/addObserver(_:)``
/// and ``CEWorkspaceFileManager/removeObserver(_:)`` to add or remove observers. Observers are kept as weak references.
final class CEWorkspaceFileManager {
let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "", category: "CEWorkspaceFileManager")
private(set) var fileManager: FileManager
private(set) var ignoredFilesAndFolders: Set<String>
private(set) var flattenedFileItems: [String: CEWorkspaceFile]
Expand Down Expand Up @@ -220,7 +222,12 @@ final class CEWorkspaceFileManager {
// TODO: Handle workspace root changing.
continue
case .itemCreated, .itemCloned, .itemRemoved, .itemRenamed:
try? self.rebuildFiles(fromItem: parentItem)
do {
try self.rebuildFiles(fromItem: parentItem)
} catch {
// swiftlint:disable:next line_length
self.logger.error("Failed to rebuild files for event: \(event.eventType.rawValue), path: \(event.path, privacy: .sensitive)")
}
files.insert(parentItem)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

enum FSEvent {
enum FSEvent: String {
case changeInDirectory
case rootChanged
case itemChangedOwner
Expand Down
5 changes: 3 additions & 2 deletions CodeEdit/Features/Editor/Models/Editor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ final class Editor: ObservableObject, Identifiable {
/// Remove the given file from tabs.
/// - Parameter file: The file to remove.
func removeTab(_ file: CEWorkspaceFile) {
tabs.removeAll { tab in
tab.file == file
tabs.removeAll(where: { tab in tab.file == file })
if temporaryTab?.file == file {
temporaryTab = nil
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class StandardTableViewCell: NSTableCellView {
secondaryLabel.layer?.cornerRadius = 10.0
secondaryLabel.font = .systemFont(ofSize: fontSize-2, weight: .bold)
secondaryLabel.alignment = .center
secondaryLabel.textColor = NSColor(Color.secondary)
secondaryLabel.textColor = .secondaryLabelColor
}

func createIcon() -> NSImageView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,22 @@ extension ProjectNavigatorViewController: OutlineTableViewCellDelegate {
workspace?.editorManager?.editorLayout.closeAllTabs(of: file)
}
workspace?.workspaceFileManager?.move(file: file, to: destination)
if !file.isFolder {
workspace?.editorManager?.openTab(item: .init(url: destination))
if let parent = file.parent {
do {
try workspace?.workspaceFileManager?.rebuildFiles(fromItem: parent)

// Grab the file connected to the rest of the cached file tree.
guard let newFile = workspace?.workspaceFileManager?.getFile(
destination.absoluteURL.path(percentEncoded: false)
),
!newFile.isFolder else {
return
}

workspace?.editorManager?.openTab(item: newFile)
} catch {
Self.logger.error("Failed to rebuild file item after moving: \(error)")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

import AppKit
import SwiftUI
import OSLog

/// A `NSViewController` that handles the **ProjectNavigatorView** in the **NavigatorArea**.
///
/// Adds a ``outlineView`` inside a ``scrollView`` which shows the folder structure of the
/// currently open project.
final class ProjectNavigatorViewController: NSViewController {
static let logger = Logger(
subsystem: Bundle.main.bundleIdentifier ?? "",
category: "ProjectNavigatorViewController"
)

var scrollView: NSScrollView!
var outlineView: NSOutlineView!
Expand Down

0 comments on commit 4bc7548

Please sign in to comment.