refactor(gui_2): migrate CustomSlice read sites (Phase 10 batch 3)
Phase 10 (batch 3): CustomSlice
Before: 8 .get('tag'/'comment') sites in src/gui_2.py
After: 0
Delta: -8
Migrates CustomSlice read sites:
1. gui_2.py:4054,4060,4096-4097 (files & media tree editor)
2. gui_2.py:5958,5964,5985-5986 (text viewer slice editor)
Pattern:
cs = CustomSlice.from_dict(slc) if isinstance(slc, dict) else slc
cs.tag (was slc.get('tag', ''))
cs.comment (was slc.get('comment', ''))
Mutation sites REMAIN as dict subscripts (the underlying list is
list[dict] per models.FileItem.custom_slices).
Tests: 16/16 pass.
This commit is contained in:
+14
-8
@@ -4051,13 +4051,15 @@ def render_ast_inspector_modal(app: App) -> None:
|
||||
tags = app.controller.project.get("context_tags", ["auto-ast", "bug", "feature", "important"])
|
||||
for idx, slc in enumerate(f_item.custom_slices):
|
||||
imgui.push_id(f"slc_row_{idx}"); imgui.text(f"#{idx+1}: L{slc['start_line']}-{slc['end_line']}"); imgui.same_line()
|
||||
current_tag = slc.get('tag', '')
|
||||
from src.type_aliases import CustomSlice as _CS
|
||||
cs = _CS.from_dict(slc) if isinstance(slc, dict) else slc
|
||||
current_tag = cs.tag
|
||||
if current_tag not in tags and current_tag: tags.append(current_tag)
|
||||
tag_idx = tags.index(current_tag) if current_tag in tags else 0
|
||||
imgui.set_next_item_width(100)
|
||||
ch_tag, new_tag_idx = imgui.combo("##Tag", tag_idx, tags)
|
||||
if ch_tag: slc['tag'] = tags[new_tag_idx]
|
||||
imgui.same_line(); imgui.set_next_item_width(-30); changed_comm, new_comm = imgui.input_text("##Note", slc.get('comment', ''))
|
||||
imgui.same_line(); imgui.set_next_item_width(-30); changed_comm, new_comm = imgui.input_text("##Note", cs.comment)
|
||||
if changed_comm: slc['comment'] = new_comm
|
||||
imgui.same_line()
|
||||
if imgui.button("X"): to_remove = idx
|
||||
@@ -4093,8 +4095,9 @@ def render_ast_inspector_modal(app: App) -> None:
|
||||
|
||||
# 2. Slice Highlight
|
||||
if hasattr(f_item, 'custom_slices'):
|
||||
is_auto = any(slc['start_line'] <= line_num <= slc['end_line'] for slc in f_item.custom_slices if slc.get('tag') == 'auto-ast')
|
||||
is_man = any(slc['start_line'] <= line_num <= slc['end_line'] for slc in f_item.custom_slices if slc.get('tag') != 'auto-ast')
|
||||
from src.type_aliases import CustomSlice as _CS
|
||||
is_auto = any(_CS.from_dict(slc).start_line <= line_num <= _CS.from_dict(slc).end_line for slc in f_item.custom_slices if _CS.from_dict(slc).tag == 'auto-ast')
|
||||
is_man = any(_CS.from_dict(slc).start_line <= line_num <= _CS.from_dict(slc).end_line for slc in f_item.custom_slices if _CS.from_dict(slc).tag != 'auto-ast')
|
||||
if is_man: draw_list.add_rect_filled(pos, imgui.ImVec2(pos.x + avail_width, pos.y + line_height), imgui.get_color_u32(theme.get_color("slice_manual", alpha=0.2)))
|
||||
elif is_auto and mode == 'hide': draw_list.add_rect_filled(pos, imgui.ImVec2(pos.x + avail_width, pos.y + line_height), imgui.get_color_u32(theme.get_color("slice_auto", alpha=0.1)))
|
||||
|
||||
@@ -5955,13 +5958,15 @@ def render_text_viewer_window(app: App) -> None:
|
||||
tags = app.controller.project.get("context_tags", ["auto-ast", "bug", "feature", "important"])
|
||||
for idx, slc in enumerate(app.ui_editing_slices_file.custom_slices):
|
||||
imgui.push_id(f"slc_row_{idx}"); imgui.text(f"Slice {idx+1}: {slc['start_line']}-{slc['end_line']}"); imgui.same_line()
|
||||
current_tag = slc.get('tag', '')
|
||||
from src.type_aliases import CustomSlice as _CS2
|
||||
cs = _CS2.from_dict(slc) if isinstance(slc, dict) else slc
|
||||
current_tag = cs.tag
|
||||
if current_tag not in tags and current_tag: tags.append(current_tag)
|
||||
tag_idx = tags.index(current_tag) if current_tag in tags else 0
|
||||
imgui.set_next_item_width(100)
|
||||
ch_tag, new_tag_idx = imgui.combo("##Tag", tag_idx, tags)
|
||||
if ch_tag: slc['tag'] = tags[new_tag_idx]
|
||||
imgui.same_line(); imgui.set_next_item_width(-30); changed_comm, new_comm = imgui.input_text("##Note", slc.get('comment', ''))
|
||||
imgui.same_line(); imgui.set_next_item_width(-30); changed_comm, new_comm = imgui.input_text("##Note", cs.comment)
|
||||
if changed_comm: slc['comment'] = new_comm
|
||||
imgui.same_line()
|
||||
if imgui.button("X"): to_remove = idx
|
||||
@@ -5982,8 +5987,9 @@ def render_text_viewer_window(app: App) -> None:
|
||||
for i, line_text in enumerate(lines):
|
||||
line_num = i + 1; pos = imgui.get_cursor_screen_pos(); line_height = imgui.get_text_line_height()
|
||||
|
||||
is_auto_sliced = any(slc['start_line'] <= line_num <= slc['end_line'] for slc in app.ui_editing_slices_file.custom_slices if slc.get('tag') == 'auto-ast')
|
||||
is_manual_sliced = any(slc['start_line'] <= line_num <= slc['end_line'] for slc in app.ui_editing_slices_file.custom_slices if slc.get('tag') != 'auto-ast')
|
||||
from src.type_aliases import CustomSlice as _CS3
|
||||
is_auto_sliced = any(_CS3.from_dict(slc).start_line <= line_num <= _CS3.from_dict(slc).end_line for slc in app.ui_editing_slices_file.custom_slices if _CS3.from_dict(slc).tag == 'auto-ast')
|
||||
is_manual_sliced = any(_CS3.from_dict(slc).start_line <= line_num <= _CS3.from_dict(slc).end_line for slc in app.ui_editing_slices_file.custom_slices if _CS3.from_dict(slc).tag != 'auto-ast')
|
||||
|
||||
if is_manual_sliced: draw_list.add_rect_filled(pos, imgui.ImVec2(pos.x + imgui.get_content_region_avail().x, pos.y + line_height), imgui.get_color_u32(theme.get_color("slice_manual", alpha=0.2)))
|
||||
elif is_auto_sliced: draw_list.add_rect_filled(pos, imgui.ImVec2(pos.x + imgui.get_content_region_avail().x, pos.y + line_height), imgui.get_color_u32(theme.get_color("slice_auto", alpha=0.15)))
|
||||
|
||||
Reference in New Issue
Block a user