Merge pull request 'fix: import every dropped .json (aggregate counts) + 5 MB size guard (#39)' (#45) from fix/39-drop-import-all into main
This commit was merged in pull request #45.
This commit is contained in:
@@ -57,6 +57,10 @@ from PySide6.QtWidgets import (
|
|||||||
|
|
||||||
import bcc_core as core
|
import bcc_core as core
|
||||||
|
|
||||||
|
# A full ~/.claude.json with history can be huge; parsing happens on the UI
|
||||||
|
# thread during drag-and-drop import, so skip anything larger than this.
|
||||||
|
MAX_DROP_IMPORT_BYTES = 5 * 1024 * 1024 # 5 MB
|
||||||
|
|
||||||
# --- One-line rebrand: change this to recolor the whole app --------------- #
|
# --- One-line rebrand: change this to recolor the whole app --------------- #
|
||||||
ACCENT = "#f97316" # warm orange
|
ACCENT = "#f97316" # warm orange
|
||||||
ACCENT_DIM = "#c2570b"
|
ACCENT_DIM = "#c2570b"
|
||||||
@@ -2402,29 +2406,44 @@ class MainWindow(QMainWindow):
|
|||||||
e.acceptProposedAction()
|
e.acceptProposedAction()
|
||||||
|
|
||||||
def dropEvent(self, e):
|
def dropEvent(self, e):
|
||||||
|
total_added, total_replaced, files_imported = 0, 0, 0
|
||||||
|
undo_pushed = False
|
||||||
for u in e.mimeData().urls():
|
for u in e.mimeData().urls():
|
||||||
path = u.toLocalFile()
|
path = u.toLocalFile()
|
||||||
if not path.endswith(".json"):
|
if not path.endswith(".json"):
|
||||||
continue
|
continue
|
||||||
text = Path(path).read_text(encoding="utf-8")
|
p = Path(path)
|
||||||
|
if p.stat().st_size > MAX_DROP_IMPORT_BYTES:
|
||||||
|
QMessageBox.warning(
|
||||||
|
self,
|
||||||
|
"File too large",
|
||||||
|
f"{p.name}:\nFile exceeds the 5 MB import limit and was skipped.",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
text = p.read_text(encoding="utf-8")
|
||||||
try:
|
try:
|
||||||
servers = core.parse_pasted_json(text)
|
servers = core.parse_pasted_json(text)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
QMessageBox.warning(self, "Couldn't import", f"{Path(path).name}:\n{ex}")
|
QMessageBox.warning(self, "Couldn't import", f"{p.name}:\n{ex}")
|
||||||
continue
|
continue
|
||||||
self._push_undo()
|
if not undo_pushed:
|
||||||
|
self._push_undo()
|
||||||
|
undo_pushed = True
|
||||||
added, replaced = 0, 0
|
added, replaced = 0, 0
|
||||||
for name, data in servers.items():
|
for name, data in servers.items():
|
||||||
a, r = self._import_server(name, data)
|
a, r = self._import_server(name, data)
|
||||||
added += int(a)
|
added += int(a)
|
||||||
replaced += int(r)
|
replaced += int(r)
|
||||||
|
total_added += added
|
||||||
|
total_replaced += replaced
|
||||||
|
files_imported += 1
|
||||||
|
if files_imported:
|
||||||
self._refresh_tables(select_index=len(self.servers) - 1)
|
self._refresh_tables(select_index=len(self.servers) - 1)
|
||||||
self._mark_dirty()
|
self._mark_dirty()
|
||||||
self.status.setText(
|
self.status.setText(
|
||||||
f"Imported {added} added, {replaced} replaced from {Path(path).name}. "
|
f"Imported {total_added} added, {total_replaced} replaced from "
|
||||||
"Review and Save."
|
f"{files_imported} file(s). Review and Save."
|
||||||
)
|
)
|
||||||
break
|
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
if self.dirty and not self._confirm_discard():
|
if self.dirty and not self._confirm_discard():
|
||||||
|
|||||||
Reference in New Issue
Block a user