diff --git a/backend/managers/file_manager.py b/backend/managers/file_manager.py index a25e8d8..5e23e4c 100644 --- a/backend/managers/file_manager.py +++ b/backend/managers/file_manager.py @@ -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}") diff --git a/frontend/app.py b/frontend/app.py index bc1456b..181aa32 100644 --- a/frontend/app.py +++ b/frontend/app.py @@ -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__": diff --git a/frontend/editor.py b/frontend/editor.py index f959a04..42a3b39 100644 --- a/frontend/editor.py +++ b/frontend/editor.py @@ -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}") diff --git a/frontend/sidebar.py b/frontend/sidebar.py index b5482e9..bc71125 100644 --- a/frontend/sidebar.py +++ b/frontend/sidebar.py @@ -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__": diff --git a/frontend/state.py b/frontend/state.py index 5311de6..eefb71a 100644 --- a/frontend/state.py +++ b/frontend/state.py @@ -23,6 +23,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