Files
DBClient/app/config/recent_files.py
T
nngoandClaude Sonnet 4.6 972166e62a feat: shortcuts dialog, tab context menus, smart status bar, recent files
- ShortcutsDialog: grouped tree of all keyboard shortcuts (Help menu)
- Workspace tab context menu: Rename, Close, Close Others, Close to Right
- SQL query tab context menu: Rename, Duplicate, Close, Close Others
- Smart status bar: right-side connection indicator + selected cell preview
- File → Open SQL File (Ctrl+O), Save (Ctrl+S), Save As, Open Recent
- Recent files persisted to ~/.dbclient/recent_files.json (last 10)
- TableViewer.cell_selected signal wired to status bar cell preview
- EditorTab._filepath tracks the file associated with each query tab

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 17:00:31 -04:00

40 lines
1.1 KiB
Python

"""Persistent list of recently opened SQL files (~/.dbclient/recent_files.json)."""
import json
from pathlib import Path
_RECENT_FILE = Path.home() / ".dbclient" / "recent_files.json"
_MAX = 10
def load_recent() -> list[str]:
"""Return up to _MAX recent file paths that still exist on disk."""
if not _RECENT_FILE.exists():
return []
try:
with open(_RECENT_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
return [p for p in data if isinstance(p, str) and Path(p).exists()][:_MAX]
except Exception:
return []
def add_recent(path: str) -> None:
"""Prepend path to the recent list, deduplicating and capping at _MAX."""
recent = load_recent()
recent = [p for p in recent if p != path]
recent.insert(0, path)
_save(recent[:_MAX])
def clear_recent() -> None:
_save([])
def _save(data: list) -> None:
_RECENT_FILE.parent.mkdir(parents=True, exist_ok=True)
try:
with open(_RECENT_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
except Exception:
pass