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
5 changes: 5 additions & 0 deletions TablePro/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ struct ContentView: View {
AppState.shared.supportsDatabaseSwitching = true
}
}
.onChange(of: sessionState?.toolbarState.safeModeLevel) { _, newLevel in
if let level = newLevel {
AppState.shared.safeModeLevel = level
}
}
}

// MARK: - View Components
Expand Down
2 changes: 1 addition & 1 deletion TablePro/Views/Main/Child/MainEditorContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ struct MainEditorContentView: View {
changeManager: currentChangeManager,
resultVersion: tab.resultVersion,
metadataVersion: tab.metadataVersion,
isEditable: tab.isEditable && !tab.isView && !connection.safeModeLevel.blocksAllWrites,
isEditable: tab.isEditable && !tab.isView && !coordinator.safeModeLevel.blocksAllWrites,
onRefresh: onRefresh,
onCellEdit: onCellEdit,
onUndo: { [binding = _selectedRowIndices, coordinator] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension MainContentCoordinator {
let sqlPreview = statements.map(\.sql).joined(separator: "\n")
let window = await MainActor.run { NSApp.keyWindow }
let permission = await SafeModeGuard.checkPermission(
level: connection.safeModeLevel,
level: safeModeLevel,
isWriteOperation: true,
sql: sqlPreview,
operationDescription: String(localized: "Save Sidebar Changes"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension MainContentCoordinator {
// MARK: - Row Operations

func addNewRow(selectedRowIndices: inout Set<Int>, editingCell: inout CellPosition?) {
guard !connection.safeModeLevel.blocksAllWrites,
guard !safeModeLevel.blocksAllWrites,
let tabIndex = tabManager.selectedTabIndex,
tabIndex < tabManager.tabs.count else { return }

Expand All @@ -31,7 +31,7 @@ extension MainContentCoordinator {
}

func deleteSelectedRows(indices: Set<Int>, selectedRowIndices: inout Set<Int>) {
guard !connection.safeModeLevel.blocksAllWrites,
guard !safeModeLevel.blocksAllWrites,
let tabIndex = tabManager.selectedTabIndex,
tabIndex < tabManager.tabs.count,
tabManager.tabs[tabIndex].isEditable,
Expand All @@ -53,7 +53,7 @@ extension MainContentCoordinator {
}

func duplicateSelectedRow(index: Int, selectedRowIndices: inout Set<Int>, editingCell: inout CellPosition?) {
guard !connection.safeModeLevel.blocksAllWrites,
guard !safeModeLevel.blocksAllWrites,
let tabIndex = tabManager.selectedTabIndex,
tabIndex < tabManager.tabs.count else { return }

Expand Down Expand Up @@ -154,7 +154,7 @@ extension MainContentCoordinator {
}

func pasteRows(selectedRowIndices: inout Set<Int>, editingCell: inout CellPosition?) {
guard !connection.safeModeLevel.blocksAllWrites,
guard !safeModeLevel.blocksAllWrites,
let index = tabManager.selectedTabIndex else { return }

var tab = tabManager.tabs[index]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension MainContentCoordinator {
pendingDeletes: inout Set<String>,
tableOperationOptions: inout [String: TableOperationOptions]
) {
guard !connection.safeModeLevel.blocksAllWrites else {
guard !safeModeLevel.blocksAllWrites else {
if let index = tabManager.selectedTabIndex {
tabManager.tabs[index].errorMessage = "Cannot save changes: connection is read-only"
}
Expand Down Expand Up @@ -60,7 +60,7 @@ extension MainContentCoordinator {
return
}

let level = connection.safeModeLevel
let level = safeModeLevel
if level.requiresConfirmation {
let sqlPreview = allStatements.map(\.sql).joined(separator: "\n")
// Snapshot inout values before clearing — needed for executeCommitStatements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension MainContentCoordinator {
// MARK: - View Operations

func createView() {
guard !connection.safeModeLevel.blocksAllWrites else { return }
guard !safeModeLevel.blocksAllWrites else { return }

let driver = DatabaseManager.shared.driver(for: connection.id)
let template = driver?.createViewTemplate()
Expand Down Expand Up @@ -63,7 +63,7 @@ extension MainContentCoordinator {
}

func openImportDialog() {
guard !connection.safeModeLevel.blocksAllWrites else { return }
guard !safeModeLevel.blocksAllWrites else { return }
guard PluginManager.shared.supportsImport(for: connection.type) else {
AlertHelper.showErrorSheet(
title: String(localized: "Import Not Supported"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension MainContentView {

/// Determine if sidebar should be in editable mode
var isSidebarEditable: Bool {
guard !coordinator.connection.safeModeLevel.blocksAllWrites,
guard !coordinator.safeModeLevel.blocksAllWrites,
let tab = coordinator.tabManager.selectedTab,
tab.tabType == .table || tab.tableName != nil,
!selectedRowIndices.isEmpty else {
Expand Down
9 changes: 6 additions & 3 deletions TablePro/Views/Main/MainContentCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ final class MainContentCoordinator {

let connection: DatabaseConnection
var connectionId: UUID { connection.id }
/// Live safe mode level — reads from toolbar state (user-editable),
/// not from the immutable connection snapshot.
var safeModeLevel: SafeModeLevel { toolbarState.safeModeLevel }
let tabManager: QueryTabManager
let changeManager: DataChangeManager
let filterStateManager: FilterStateManager
Expand Down Expand Up @@ -508,7 +511,7 @@ final class MainContentCoordinator {
guard !statements.isEmpty else { return }

// Safe mode enforcement for query execution
let level = connection.safeModeLevel
let level = safeModeLevel

if level == .readOnly {
let writeStatements = statements.filter { isWriteQuery($0) }
Expand Down Expand Up @@ -584,7 +587,7 @@ final class MainContentCoordinator {
let sql = tabManager.tabs[index].query
guard !sql.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return }

let level = connection.safeModeLevel
let level = safeModeLevel
if level.appliesToAllQueries && level.requiresConfirmation,
tabManager.tabs[index].lastExecutedAt == nil
{
Expand Down Expand Up @@ -688,7 +691,7 @@ final class MainContentCoordinator {
let statements = SQLStatementScanner.allStatements(in: trimmed)
guard let stmt = statements.first else { return }

let level = connection.safeModeLevel
let level = safeModeLevel
let needsConfirmation = level.appliesToAllQueries && level.requiresConfirmation

// Multi-variant EXPLAIN: use plugin-declared variants if available
Expand Down
Loading