v0.6.1
Fix gui_schemes
This commit is contained in:
+69
-17
@@ -16,7 +16,7 @@ from .diagram_schemes import (
|
||||
claim_user_scheme_if_diverged,
|
||||
ensure_user_schemes,
|
||||
get_schemes,
|
||||
load_schemes_from_path,
|
||||
load_schemes_report,
|
||||
reload_schemes,
|
||||
save_schemes,
|
||||
user_schemes_path,
|
||||
@@ -263,7 +263,9 @@ class Md2GostApp:
|
||||
self._last_md = ""
|
||||
self._schemes: dict[str, DiagramScheme] = {}
|
||||
self._scheme_ids: list[str] = []
|
||||
self._scheme_file_keys: set[str] = set()
|
||||
self._scheme_selecting = False
|
||||
self._schemes_unreadable: str | None = None
|
||||
self._debug_next = False
|
||||
|
||||
self._win_files: tk.Toplevel | None = None
|
||||
@@ -1336,12 +1338,23 @@ class Md2GostApp:
|
||||
if not hasattr(self, "_scheme_list"):
|
||||
return
|
||||
path = ensure_user_schemes()
|
||||
self._schemes = load_schemes_from_path(path)
|
||||
self._schemes, err = load_schemes_report(path)
|
||||
self._schemes_unreadable = err
|
||||
self._scheme_file_keys = set() if err else set(self._schemes)
|
||||
self._scheme_ids = sorted(self._schemes.keys())
|
||||
self._scheme_list.delete(0, tk.END)
|
||||
for sid in self._scheme_ids:
|
||||
title = self._schemes[sid].title or sid
|
||||
self._scheme_list.insert(tk.END, title)
|
||||
if err:
|
||||
self._clear_scheme_form()
|
||||
self._scheme_fence_hint.configure(
|
||||
text=f"Файл не разобран и не изменён: {err}"
|
||||
)
|
||||
self._append_log(
|
||||
f"Файл схем не прочитан, он не перезаписан: {path} ({err})"
|
||||
)
|
||||
return
|
||||
if not self._scheme_ids:
|
||||
self._clear_scheme_form()
|
||||
return
|
||||
@@ -1352,6 +1365,22 @@ class Md2GostApp:
|
||||
self._scheme_list.see(idx)
|
||||
self._fill_scheme_form(self._schemes[target])
|
||||
|
||||
def _persist_schemes(self, select_id: str | None = None) -> str | None:
|
||||
"""Write self._schemes to disk. Refuses to overwrite a file that did not parse."""
|
||||
if self._schemes_unreadable:
|
||||
messagebox.showerror(
|
||||
"md2gost",
|
||||
"Файл схем не разобран, поэтому он не перезаписан.\n"
|
||||
f"{self._schemes_unreadable}",
|
||||
)
|
||||
return None
|
||||
path = user_schemes_path()
|
||||
removed = set(self._scheme_file_keys) - set(self._schemes)
|
||||
save_schemes(self._schemes, path, removed_ids=removed)
|
||||
reload_schemes()
|
||||
self._reload_schemes_ui(select_id=select_id)
|
||||
return str(path)
|
||||
|
||||
def _clear_scheme_form(self) -> None:
|
||||
self._scheme_selecting = True
|
||||
self._sch_id.set("")
|
||||
@@ -1396,6 +1425,9 @@ class Md2GostApp:
|
||||
return None
|
||||
includes_raw = self._text_get(self._sch_includes)
|
||||
includes = [ln.strip() for ln in includes_raw.splitlines() if ln.strip()]
|
||||
theme = ""
|
||||
if old_id and old_id in self._schemes:
|
||||
theme = self._schemes[old_id].theme
|
||||
return DiagramScheme(
|
||||
id=sid,
|
||||
title=self._sch_title.get().strip() or sid,
|
||||
@@ -1406,6 +1438,7 @@ class Md2GostApp:
|
||||
includes=includes,
|
||||
prefix=self._text_get(self._sch_prefix),
|
||||
postfix=self._text_get(self._sch_postfix),
|
||||
theme=theme,
|
||||
)
|
||||
|
||||
def _scheme_commit_current(self) -> str | None:
|
||||
@@ -1422,6 +1455,15 @@ class Md2GostApp:
|
||||
return scheme.id
|
||||
|
||||
def _scheme_add(self) -> None:
|
||||
if self._schemes_unreadable:
|
||||
messagebox.showerror(
|
||||
"md2gost",
|
||||
"Файл схем не разобран, новая схема не записана.\n"
|
||||
f"{self._schemes_unreadable}",
|
||||
)
|
||||
return
|
||||
if self._scheme_ids and self._scheme_commit_current() is None:
|
||||
return
|
||||
n = 1
|
||||
while f"custom{n}" in self._schemes:
|
||||
n += 1
|
||||
@@ -1437,13 +1479,24 @@ class Md2GostApp:
|
||||
prefix="@startuml\n",
|
||||
postfix="\n@enduml",
|
||||
)
|
||||
self._reload_schemes_ui(select_id=sid)
|
||||
path = self._persist_schemes(select_id=sid)
|
||||
if path:
|
||||
self._append_log(f"Схема добавлена: {sid} ({path})")
|
||||
|
||||
def _scheme_dup(self) -> None:
|
||||
sel = self._scheme_list.curselection()
|
||||
if not sel:
|
||||
if not self._scheme_list.curselection():
|
||||
return
|
||||
src = self._schemes[self._scheme_ids[sel[0]]]
|
||||
if self._schemes_unreadable:
|
||||
messagebox.showerror(
|
||||
"md2gost",
|
||||
"Файл схем не разобран, копия не записана.\n"
|
||||
f"{self._schemes_unreadable}",
|
||||
)
|
||||
return
|
||||
src_id = self._scheme_commit_current()
|
||||
if src_id is None:
|
||||
return
|
||||
src = self._schemes[src_id]
|
||||
n = 1
|
||||
while f"{src.id}_copy{n}" in self._schemes:
|
||||
n += 1
|
||||
@@ -1452,7 +1505,7 @@ class Md2GostApp:
|
||||
id=sid,
|
||||
title=src.title,
|
||||
version=src.version,
|
||||
author=src.author,
|
||||
author="",
|
||||
docs=src.docs,
|
||||
ai_prompt=src.ai_prompt,
|
||||
includes=list(src.includes),
|
||||
@@ -1460,7 +1513,9 @@ class Md2GostApp:
|
||||
postfix=src.postfix,
|
||||
theme=src.theme,
|
||||
)
|
||||
self._reload_schemes_ui(select_id=sid)
|
||||
path = self._persist_schemes(select_id=sid)
|
||||
if path:
|
||||
self._append_log(f"Схема скопирована: {sid} ({path})")
|
||||
|
||||
def _scheme_del(self) -> None:
|
||||
sel = self._scheme_list.curselection()
|
||||
@@ -1470,20 +1525,17 @@ class Md2GostApp:
|
||||
if not messagebox.askyesno("md2gost", f"Удалить схему «{sid}» из файла пользователя?"):
|
||||
return
|
||||
del self._schemes[sid]
|
||||
path = user_schemes_path()
|
||||
save_schemes(self._schemes, path)
|
||||
reload_schemes()
|
||||
self._reload_schemes_ui()
|
||||
self._append_log(f"Схема удалена: {sid}")
|
||||
path = self._persist_schemes()
|
||||
if path:
|
||||
self._append_log(f"Схема удалена: {sid}")
|
||||
|
||||
def _scheme_save_all(self) -> None:
|
||||
sid = self._scheme_commit_current()
|
||||
if sid is None and self._scheme_ids:
|
||||
return
|
||||
path = user_schemes_path()
|
||||
save_schemes(self._schemes, path)
|
||||
reload_schemes()
|
||||
self._reload_schemes_ui(select_id=sid)
|
||||
path = self._persist_schemes(select_id=sid)
|
||||
if not path:
|
||||
return
|
||||
self._append_log(f"Схемы сохранены: {path}")
|
||||
messagebox.showinfo("md2gost", f"Сохранено:\n{path}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user