diff --git a/gui.py b/gui.py index b9d449e..31d17e4 100644 --- a/gui.py +++ b/gui.py @@ -1349,10 +1349,24 @@ class App: def _rebuild_disc_list(self): if not dpg.does_item_exist("disc_scroll"): return + + def _toggle_read(s, a, idx): + # Save edit box content before switching to read mode + tag = f"disc_content_{idx}" + if dpg.does_item_exist(tag) and not self.disc_entries[idx].get("read_mode", False): + self.disc_entries[idx]["content"] = dpg.get_value(tag) + self.disc_entries[idx]["read_mode"] = not self.disc_entries[idx].get("read_mode", False) + self._rebuild_disc_list() + dpg.delete_item("disc_scroll", children_only=True) for i, entry in enumerate(self.disc_entries): collapsed = entry.get("collapsed", False) + read_mode = entry.get("read_mode", False) ts_str = entry.get("ts", "") + + preview = entry["content"].replace("\n", " ")[:60] + if len(entry["content"]) > 60: + preview += "..." with dpg.group(parent="disc_scroll"): with dpg.group(horizontal=True): @@ -1369,6 +1383,12 @@ class App: width=120, callback=self._make_disc_role_cb(i), ) + if not collapsed: + dpg.add_button( + label="[Edit]" if read_mode else "[Read]", + user_data=i, + callback=_toggle_read + ) if ts_str: dpg.add_text(ts_str, color=(120, 120, 100)) if collapsed: @@ -1379,30 +1399,29 @@ class App: ) dpg.add_button( label="[+ Max]", - user_data=f"disc_content_{i}", - callback=lambda s, a, u, idx=i: _show_text_viewer(f"Entry #{idx+1}", dpg.get_value(u) if dpg.does_item_exist(u) else "") + callback=lambda s, a, u, idx=i: _show_text_viewer(f"Entry #{idx+1}", self.disc_entries[idx]["content"]) ) dpg.add_button( label="Del", width=36, callback=self._make_disc_remove_cb(i), ) - - if collapsed: - with dpg.group(horizontal=True): - dpg.add_spacer(width=28) # Indent text past the expand/collapse button - dpg.add_text(entry["content"], wrap=0, color=(200, 200, 200)) + dpg.add_text(preview, color=(160, 160, 150)) with dpg.group(tag=f"disc_body_{i}", show=not collapsed): - dpg.add_input_text( - tag=f"disc_content_{i}", - default_value=entry["content"], - multiline=True, - width=-1, - height=100, - callback=self._make_disc_content_cb(i), - on_enter=False, - ) + if read_mode: + with dpg.child_window(height=150, border=True): + dpg.add_text(entry["content"], wrap=0, color=(200, 200, 200)) + else: + dpg.add_input_text( + tag=f"disc_content_{i}", + default_value=entry["content"], + multiline=True, + width=-1, + height=150, + callback=self._make_disc_content_cb(i), + on_enter=False, + ) dpg.add_separator() def _make_disc_role_cb(self, idx: int):