Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- BigQuery datasets can be switched from the toolbar, the Cmd+K switcher, and the File menu, including creating and dropping datasets. (#509)
- `.psql` and `.pgsql` files now open in the SQL editor like `.sql`: Finder double-click, the open and save panels, and linked SQL folders all accept them. (#1641)

### Changed

Expand Down
11 changes: 9 additions & 2 deletions TablePro/Core/Services/Infrastructure/SQLFileService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import UniformTypeIdentifiers
enum SQLFileService {
private static let logger = Logger(subsystem: "com.TablePro", category: "SQLFileService")

static let supportedExtensions: Set<String> = ["sql", "psql", "pgsql"]

private static var allowedContentTypes: [UTType] {
let types = Set(supportedExtensions.compactMap { UTType(filenameExtension: $0) })
return types.isEmpty ? [.plainText] : Array(types)
}

/// Reads a SQL file from disk.
static func readFile(url: URL) async throws -> String {
try await Task.detached {
Expand All @@ -34,7 +41,7 @@ enum SQLFileService {
@MainActor
static func showOpenPanel() async -> [URL]? {
let panel = NSOpenPanel()
panel.allowedContentTypes = [UTType(filenameExtension: "sql") ?? .plainText]
panel.allowedContentTypes = allowedContentTypes
panel.allowsMultipleSelection = true
panel.message = String(localized: "Select SQL files to open")
let response = await panel.begin()
Expand All @@ -46,7 +53,7 @@ enum SQLFileService {
@MainActor
static func showSavePanel(suggestedName: String = "query.sql") async -> URL? {
let panel = NSSavePanel()
panel.allowedContentTypes = [UTType(filenameExtension: "sql") ?? .plainText]
panel.allowedContentTypes = allowedContentTypes
panel.canCreateDirectories = true
panel.nameFieldStringValue = suggestedName
panel.message = String(localized: "Save SQL file")
Expand Down
2 changes: 1 addition & 1 deletion TablePro/Core/Services/Infrastructure/URLClassifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal enum URLClassifier {
if ext == "tablepro" {
return .success(.openConnectionShare(url))
}
if ext == "sql" {
if SQLFileService.supportedExtensions.contains(ext) {
return .success(.openSQLFile(url))
}
if PluginManager.shared.allInspectorFileExtensions.contains(ext) {
Expand Down
2 changes: 1 addition & 1 deletion TablePro/Core/Services/SQL/SQLFolderWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ internal final class SQLFolderWatcher {
var indexed: [LinkedSQLIndex.IndexedFile] = []

for case let url as URL in enumerator {
guard url.pathExtension.lowercased() == "sql" else { continue }
guard SQLFileService.supportedExtensions.contains(url.pathExtension.lowercased()) else { continue }

let resourceValues = try? url.resourceValues(forKeys: [
.isRegularFileKey, .contentModificationDateKey, .fileSizeKey
Expand Down
4 changes: 4 additions & 0 deletions TablePro/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<key>CFBundleTypeExtensions</key>
<array>
<string>sql</string>
<string>psql</string>
<string>pgsql</string>
Comment on lines +17 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route the newly associated extensions

With these extensions advertised in CFBundleDocumentTypes, Finder will now deliver .psql/.pgsql files to AppDelegate.application(_:open:), but the launch path still classifies SQL files only when URLClassifier.classifyFile sees ext == "sql" (TablePro/Core/Services/Infrastructure/URLClassifier.swift). In that double-click/Open With scenario the new extensions are logged as unrecognized and never reach .openSQLFile, so the advertised association does not actually open them in the editor.

Useful? React with 👍 / 👎.

</array>
<key>CFBundleTypeIconSystemGenerated</key>
<true/>
Expand Down Expand Up @@ -154,6 +156,8 @@
<key>public.filename-extension</key>
<array>
<string>sql</string>
<string>psql</string>
<string>pgsql</string>
</array>
</dict>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct URLClassifierTests {
#expect(intent == nil)
}

@Test("SQL file routes to openSQLFile")
func routesSQLFile() {
let sqlURL = URL(fileURLWithPath: "/tmp/query.sql")
@Test("SQL file routes to openSQLFile", arguments: ["sql", "psql", "pgsql", "PSQL"])
func routesSQLFile(ext: String) {
let sqlURL = URL(fileURLWithPath: "/tmp/query.\(ext)")
let intent = URLClassifier.classify(sqlURL)
guard case .some(.success(.openSQLFile(let routed))) = intent else {
Issue.record("Expected .openSQLFile, got \(String(describing: intent))")
Expand Down
Loading