Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/WindowCommands/FileCommands.swift (Swift)

Code before:
            Button("Close Window") {
                NSApp.sendAction(#selector(NSWindow.close), to: nil, from: nil)
            }
            .keyboardShortcut("w", modifiers: [.shift, .command])

            Button("Close Workspace") {
                // TODO: Determine how this is different than the "Close Window" command and adjust accordingly
                NSApp.sendAction(#selector(NSWindow.close), to: nil, from: nil)
            }
            .keyboardShortcut("w", modifiers: [.control, .option, .command])

            if let utilityAreaViewModel {
                Button("Close Terminal") {
                    utilityAreaViewModel.removeTerminals(utilityAreaViewModel.selectedTerminals)
                }
                .keyboardShortcut(.delete)
            }

            Divider()

            Button("Save") {
                NSApp.sendAction(#selector(CodeEditWindowController.saveDocument(_:)), to: nil, from: nil)
            }
            .keyboardShortcut("s")
        }
    }

    // TODO: This logic needs to become a command, not a function bound to the MenuBar
    private func createNewFile() {
        guard let windowController = getCurrentCEWindowController() else { return }

        let fileManager = FileManager.default
        let workspaceName = windowController.workspace?.workspaceFileManager?.folderUrl.lastPathComponent

        var hashedWorkspaceName = "no-workspace".md5()
        if let workspaceName {
            hashedWorkspaceName = workspaceName.md5()
        }

        let tempStorageDir = CodeEditApp.applicationSupportURL
            .appendingPathComponent("workspaces/\(hashedWorkspaceName)", isDirectory: true)

        do {
            try createDirectoryIfNotExists(atPath: tempStorageDir.path)

            let probableNumber = try predictNextTempFileNumber(in: tempStorageDir)

            let filename = "untitled-\(probableNumber)"
            let tempFileURL = tempStorageDir.appending(path: filename)
            fileManager.createFile(atPath: tempFileURL.path(percentEncoded: false), contents: nil)
            print("Saving new file at: \(tempFileURL.path)")

Review comment (suggestion):
```suggestion
        guard let windowController = getCurrentCEWindowController(), 
        let workspaceName = windowController.workspace?.workspaceFileManager?.folderUrl.lastPathComponent else {
             return
        }
```

Code after:
            .keyboardShortcut("w", modifiers: [.shift, .command])

            Button("Close Workspace") {
                // TODO: Determine how this is different than the "Close Window" command and adjust accordingly
                NSApp.sendAction(#selector(NSWindow.close), to: nil, from: nil)
            }
            .keyboardShortcut("w", modifiers: [.control, .option, .command])

            if let utilityAreaViewModel {
                Button("Close Terminal") {
                    utilityAreaViewModel.removeTerminals(utilityAreaViewModel.selectedTerminals)
                }
                .keyboardShortcut(.delete)
            }

            Divider()

            Button("Save") {
                NSApp.sendAction(#selector(CodeEditWindowController.saveDocument(_:)), to: nil, from: nil)
            }
            .keyboardShortcut("s")
        }
    }

    private func createNewFile() {
        guard let windowController = getCurrentCEWindowController() else { return }

        let fileManager = FileManager.default
        let workspaceName = windowController.workspace?.workspaceFileManager?.folderUrl.lastPathComponent

        var hashedWorkspaceName = (workspaceName ?? "no-workspace").md5()

        let tempStorageDir = CodeEditApp.applicationSupportURL
            .appendingPathComponent("workspaces/\(hashedWorkspaceName)", isDirectory: true)

        do {
            try createDirectoryIfNotExists(atPath: tempStorageDir.path)

            let probableNumber = try predictNextTempFileNumber(in: tempStorageDir)

            let filename = "untitled-\(probableNumber)"
            let tempFileURL = tempStorageDir.appending(path: filename)
            fileManager.createFile(atPath: tempFileURL.path(percentEncoded: false), contents: nil)
            print("Saving new file at: \(tempFileURL.path)")

            let file = CEWorkspaceFile(url: tempFileURL)
            windowController.workspace?.editorManager.openTab(item: file)
        } catch {
            print(error)
            let alert = NSAlert()
            alert.messageText = "Error"