rename&delet
This commit is contained in:
parent
3aa4c6749b
commit
7769a0e185
@ -119,7 +119,7 @@ class FileManager:
|
|||||||
if not Path(new_name).suffix == file_type:
|
if not Path(new_name).suffix == file_type:
|
||||||
new_name = Path(new_name).with_suffix(file_type) # Ensure the file extension remains the same
|
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
|
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())):
|
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
|
return False
|
||||||
|
|
||||||
def delete_file(self, relative_path):
|
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())):
|
if not str(file_path).startswith(str(self.base_path.resolve())):
|
||||||
st.error(f"Access denied: {relative_path}")
|
st.error(f"Access denied: {relative_path}")
|
||||||
|
|||||||
@ -50,12 +50,16 @@ def render_editor():
|
|||||||
active_index = st.session_state.open_files.index(st.session_state.active_file)
|
active_index = st.session_state.open_files.index(st.session_state.active_file)
|
||||||
except (ValueError, KeyError):
|
except (ValueError, KeyError):
|
||||||
active_index = 0
|
active_index = 0
|
||||||
|
|
||||||
|
st.session_state.active_tab = active_index
|
||||||
|
|
||||||
tab_names = [Path(f).name for f in st.session_state.open_files]
|
tab_names = [Path(f).name for f in st.session_state.open_files]
|
||||||
tabs = st.tabs(tab_names)
|
tabs = st.tabs(tab_names)
|
||||||
|
|
||||||
for idx, file_path in enumerate(st.session_state.open_files):
|
for idx, file_path in enumerate(st.session_state.open_files):
|
||||||
with tabs[idx]:
|
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:
|
if file_path not in st.session_state.files_content:
|
||||||
st.session_state.files_content[file_path] = fm.read_file(Path(file_path))
|
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}",
|
key=f"code_editor_{file_path}",
|
||||||
auto_update=True,
|
auto_update=True,
|
||||||
height=400,
|
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]:
|
if code != st.session_state.files_content[file_path]:
|
||||||
@ -98,8 +97,8 @@ def render_editor():
|
|||||||
if st.session_state.open_files
|
if st.session_state.open_files
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
st.rerun() # Refresh the page to update the UI
|
st.rerun() # Refresh the page to update the UI
|
||||||
|
|
||||||
with cols[2]:
|
with cols[2]:
|
||||||
if st.button("Rename File", key=f"rename_{file_path}"):
|
if st.button("Rename File", key=f"rename_{file_path}"):
|
||||||
new_name = st.text_input("New File Name", key=f"new_name_{file_path}")
|
new_name = st.text_input("New File Name", key=f"new_name_{file_path}")
|
||||||
@ -118,6 +117,13 @@ def render_editor():
|
|||||||
try:
|
try:
|
||||||
fm.delete_file(file_path)
|
fm.delete_file(file_path)
|
||||||
st.success(f"File '{Path(file_path).name}' deleted successfully!")
|
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()
|
st.rerun()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error deleting file: {e}")
|
st.error(f"Error deleting file: {e}")
|
||||||
|
|||||||
@ -71,9 +71,8 @@ def render_sidebar():
|
|||||||
file_explorer_section = st.sidebar.container()
|
file_explorer_section = st.sidebar.container()
|
||||||
|
|
||||||
with navigation_section:
|
with navigation_section:
|
||||||
st.subheader("Options")
|
|
||||||
st.radio(
|
st.radio(
|
||||||
"Action",
|
"Options",
|
||||||
["Chat with AI Assistant", "Code Editor"],
|
["Chat with AI Assistant", "Code Editor"],
|
||||||
key=f"radio_interface_options")
|
key=f"radio_interface_options")
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,9 @@ def init_state():
|
|||||||
|
|
||||||
if "active_file" not in st.session_state:
|
if "active_file" not in st.session_state:
|
||||||
st.session_state.active_file = None
|
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:
|
if "is_editing" not in st.session_state:
|
||||||
st.session_state.is_editing = False
|
st.session_state.is_editing = False
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user