ui-setup #8

Merged
meulilivio merged 3 commits from ui-setup into main 2026-04-10 00:06:04 +02:00
5 changed files with 29 additions and 22 deletions

View File

@ -119,7 +119,7 @@ class FileManager:
if not Path(new_name).suffix == file_type:
new_name = Path(new_name).with_suffix(file_type) # Ensure the file extension remains the same
old_file_path = (self.base_path / Path(old_relative_path)).resolve()
old_file_path = (Path(old_relative_path)).resolve()
new_file_path = old_file_path.parent / new_name
if not str(old_file_path).startswith(str(self.base_path.resolve())) or not str(new_file_path).startswith(str(self.base_path.resolve())):
@ -134,7 +134,7 @@ class FileManager:
return False
def delete_file(self, relative_path):
file_path = (self.base_path / relative_path).resolve()
file_path = (relative_path).resolve()
if not str(file_path).startswith(str(self.base_path.resolve())):
st.error(f"Access denied: {relative_path}")

View File

@ -23,13 +23,10 @@ def main():
init_state()
render_sidebar()
show_editor = st.session_state.get("show_Editor", False)
show_chat = st.session_state.get("show_Chat", False)
if show_editor:
if st.session_state.get("radio_interface_options") == "Code Editor":
render_editor()
if show_chat:
elif st.session_state.get("radio_interface_options") == "Chat with AI Assistant":
render_chat()
if __name__ == "__main__":

View File

@ -50,12 +50,16 @@ def render_editor():
active_index = st.session_state.open_files.index(st.session_state.active_file)
except (ValueError, KeyError):
active_index = 0
st.session_state.active_tab = active_index
tab_names = [Path(f).name for f in st.session_state.open_files]
tabs = st.tabs(tab_names)
for idx, file_path in enumerate(st.session_state.open_files):
with tabs[idx]:
if idx == st.session_state.active_tab:
st.session_state.active_file = file_path
if file_path not in st.session_state.files_content:
st.session_state.files_content[file_path] = fm.read_file(Path(file_path))
@ -69,11 +73,6 @@ def render_editor():
key=f"code_editor_{file_path}",
auto_update=True,
height=400,
# tab_size=4,
# font_size=14,
# show_gutter=True,
# show_print_margin=False,
# wrap=True
)
if code != st.session_state.files_content[file_path]:
@ -98,8 +97,8 @@ def render_editor():
if st.session_state.open_files
else None
)
st.rerun() # Refresh the page to update the UI
with cols[2]:
if st.button("Rename File", key=f"rename_{file_path}"):
new_name = st.text_input("New File Name", key=f"new_name_{file_path}")
@ -118,6 +117,13 @@ def render_editor():
try:
fm.delete_file(file_path)
st.success(f"File '{Path(file_path).name}' deleted successfully!")
st.session_state.open_files.remove(file_path)
del st.session_state.files_content[file_path]
st.session_state.active_file = (
st.session_state.open_files[0]
if st.session_state.open_files
else None
)
st.rerun()
except Exception as e:
st.error(f"Error deleting file: {e}")

View File

@ -67,8 +67,16 @@ def render_filetree_arborist(tree):
def render_sidebar():
st.sidebar.title("Navigation")
file_explorer_section = st.sidebar.container()
navigation_section = st.sidebar.container()
file_explorer_section = st.sidebar.container()
with navigation_section:
st.radio(
"Options",
["Chat with AI Assistant", "Code Editor"],
key=f"radio_interface_options")
st.markdown("---")
with file_explorer_section:
st.subheader("File Explorer")
@ -162,13 +170,6 @@ def render_sidebar():
st.success(f"{action} created!")
st.rerun()
st.sidebar.markdown("---")
with navigation_section:
st.sidebar.subheader("Options")
st.sidebar.checkbox("Code Editor", key="show_Editor")
st.sidebar.checkbox("Chat with AI Assistant", key="show_Chat")
return
if __name__ == "__main__":

View File

@ -22,6 +22,9 @@ def init_state():
if "active_file" not in st.session_state:
st.session_state.active_file = None
if "active_tab" not in st.session_state:
st.session_state.active_tab = 0
if "is_editing" not in st.session_state:
st.session_state.is_editing = False