Skip to content

Structure View Refactor & Keyboard Handling Migration#24

Merged
datlechin merged 2 commits intomainfrom
feat/structure-view-refactor
Jan 19, 2026
Merged

Structure View Refactor & Keyboard Handling Migration#24
datlechin merged 2 commits intomainfrom
feat/structure-view-refactor

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

Complete refactor of the Structure View to match the data grid UX and migrate keyboard handling to native responder chain patterns.

Structure View Refactor

  • DataGridView Integration: Replace custom table views with DataGridView for consistent UX across data and structure tabs
  • Change Tracking: Add StructureChangeManager with O(1) lookups, mirroring DataChangeManager architecture
  • Visual Feedback: Yellow highlights for modifications, green for insertions, red for deletions
  • Copy/Paste: Full support with custom pasteboard type to avoid conflicts with data grid
  • Undo/Redo: Implemented with StructureUndoManager
  • Schema Operations: SQL generation and execution for ALTER TABLE, CREATE INDEX, etc.

Keyboard Handling Migration

  • Responder Chain: Replace custom ESC key system with native cancelOperation(_:)
  • Standard Selectors: Use interpretKeyEvents for delete, copy, paste, undo, redo
  • KeyCode Enum: Replace magic numbers with readable key codes
  • Cleanup: Remove 5 EscapeKey* files (1,000+ lines of custom code eliminated)

Alert System Improvements

  • AlertHelper Utility: Centralized alert dialogs with consistent styling
  • Native NSAlert: Better modal behavior than SwiftUI .alert()
  • Removed Components: MainContentAlerts.swift, InlineErrorBanner.swift

Performance Enhancements

  • Granular Reloading: DataGridView now reloads only changed rows (was full table reload)
  • Visual State Caching: Both DataChangeManager and StructureChangeManager cache row states
  • Optimized Schema Loading: Pre-load all table columns (was limited to 5 tables)
  • Settings Updates: Reload only visible rows for date format changes (was full table)

Bug Fixes

  • Fix duplicate refresh alerts when Structure View has unsaved changes
  • Fix copy/paste breaking after save (custom pasteboard type prevents conflicts)
  • Remove 30+ debug print statements cluttering console output
  • Add proper save confirmations before destructive operations

Testing

  • ✅ Structure View: Copy/paste columns, indexes, foreign keys
  • ✅ Keyboard shortcuts: Cmd+C/V/Z/Shift+Z, Delete, ESC
  • ✅ Visual states: Yellow/green/red highlights for changes
  • ✅ Save changes: ALTER TABLE generation and execution
  • ✅ Refresh handling: Confirms before discarding unsaved changes
  • ✅ DataGrid: Granular reloading for cell edits (performance improvement)
  • ✅ Settings: Date format changes reload visible rows only
  • ✅ Build: No warnings or errors

Architecture Notes

Change Manager Pattern

Both DataChangeManager and StructureChangeManager now follow the same O(1) pattern:

private(set) var pendingChanges: [Identifier: Change] = [:]  // O(1) lookups
private var visualStateCache: [Int: RowVisualState] = [:]     // Cached states

Responder Chain Pattern

Keyboard shortcuts now use Apple's standard responder chain:

Menu → NSApp.sendAction(#selector(copy:)) → First Responder → View handles

Custom Pasteboard Type

Structure View uses com.tablepro.structure to avoid conflicts with data grid's tab-separated format.

Files Changed

Modified: 35 files
Deleted: 6 files (EscapeKey system, old alert components)
Added: 9 files (StructureChangeManager, SchemaModels, AlertHelper, etc.)

Breaking Changes

None - all changes are internal refactoring with no API changes.

…ation

## Structure View Refactor
- Replace custom table views with DataGridView for consistent UX
- Add StructureChangeManager for O(1) change tracking (mirrors DataChangeManager)
- Implement copy/paste/undo/redo using responder chain pattern
- Add visual feedback for changes (yellow=modified, green=inserted, red=deleted)
- Support schema previews and SQL generation for ALTER TABLE operations

## Keyboard Handling Migration
- Replace custom ESC key system with native responder chain (cancelOperation)
- Use interpretKeyEvents for standard shortcuts (delete, copy, paste, undo)
- Add KeyCode enum for readable key event handling
- Remove EscapeKey* files (no longer needed)

## Alert System Consolidation
- Create AlertHelper utility for consistent alert dialogs
- Replace SwiftUI .alert() with native NSAlert for better modal behavior
- Remove MainContentAlerts.swift (replaced by inline confirmations)
- Remove InlineErrorBanner (errors now shown as modal alerts)

## Performance Improvements
- Add granular DataGridView reloading (only reload changed rows)
- Implement visual state caching in change managers
- Pre-load all table columns in SQLSchemaProvider (was limited to 5)
- Remove unnecessary deep copying in QueryExecutionService

## Bug Fixes
- Fix duplicate refresh alerts (Structure View now handles own notifications)
- Fix date format settings requiring full reload (now reloads visible rows only)
- Add AnyChangeManager protocol wrapper for unified data/structure change tracking
- Remove debug print statements from StructureChangeManager, SQLSchemaProvider, DatabaseManager

## Files Changed
- Modified: 35 files
- Deleted: 6 files (EscapeKey system, InlineErrorBanner, MainContentAlerts)
- Added: 9 files (StructureChangeManager, SchemaModels, AlertHelper, etc.)
@datlechin
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex review is not enabled for this repo. Please contact the admins of this repo to enable Codex.

@datlechin datlechin merged commit e9087fe into main Jan 19, 2026
@datlechin datlechin deleted the feat/structure-view-refactor branch January 19, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant