delete unused sidebarfunctions
This commit is contained in:
parent
3e8bab87cb
commit
e5e06da35b
@ -110,106 +110,6 @@ def _add_folder_dialog(parent_path: str = ""):
|
|||||||
if cancel:
|
if cancel:
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
|
|
||||||
@st.dialog("Rename File")
|
|
||||||
def _rename_file_dialog(relative_file_path: str, file_name: str):
|
|
||||||
"""
|
|
||||||
Dialog to rename a file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
relative_file_path (str): The current relative path (without base path) to the file to rename, including the file name.
|
|
||||||
file_name (str): The current name of the file, including the extension.
|
|
||||||
"""
|
|
||||||
st.write(f"Current name: **{file_name}**")
|
|
||||||
|
|
||||||
with st.form("rename_file_form"):
|
|
||||||
new_name = st.text_input(
|
|
||||||
"New name:",
|
|
||||||
value=Path(relative_file_path).stem
|
|
||||||
)
|
|
||||||
|
|
||||||
col1, col2 = st.columns(2)
|
|
||||||
|
|
||||||
with col1:
|
|
||||||
submitted = st.form_submit_button(
|
|
||||||
"Confirm",
|
|
||||||
type="primary",
|
|
||||||
use_container_width=True
|
|
||||||
)
|
|
||||||
|
|
||||||
with col2:
|
|
||||||
cancel = st.form_submit_button(
|
|
||||||
"Cancel",
|
|
||||||
use_container_width=True
|
|
||||||
)
|
|
||||||
|
|
||||||
if submitted:
|
|
||||||
if not new_name.strip():
|
|
||||||
st.warning("Please enter a name.")
|
|
||||||
elif "/" in new_name or "\\" in new_name or "." in new_name:
|
|
||||||
st.warning("Name must not contain slashes.")
|
|
||||||
else:
|
|
||||||
if fm.rename_file(relative_file_path, new_name.strip()):
|
|
||||||
absolute_file_path = str(Path(fm.base_path / relative_file_path))
|
|
||||||
ext = Path(absolute_file_path).suffix
|
|
||||||
new_file_path = str(
|
|
||||||
Path(absolute_file_path).parent / (Path(new_name.strip()).stem + ext)
|
|
||||||
)
|
|
||||||
|
|
||||||
if absolute_file_path in st.session_state.open_files:
|
|
||||||
i = st.session_state.open_files.index(absolute_file_path)
|
|
||||||
st.session_state.open_files[i] = new_file_path
|
|
||||||
|
|
||||||
if absolute_file_path in st.session_state.files_content:
|
|
||||||
st.session_state.files_content[new_file_path] = \
|
|
||||||
st.session_state.files_content.pop(absolute_file_path)
|
|
||||||
|
|
||||||
if st.session_state.active_file == absolute_file_path:
|
|
||||||
st.session_state.active_file = new_file_path
|
|
||||||
|
|
||||||
st.rerun()
|
|
||||||
else:
|
|
||||||
st.error("Rename failed. Check that the file still exists.")
|
|
||||||
st.error(f"Attempted to rename: {relative_file_path} to {new_name.strip()}")
|
|
||||||
|
|
||||||
if cancel:
|
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
|
|
||||||
@st.dialog("Delete File")
|
|
||||||
def _delete_file_dialog(relative_file_path: str, file_name: str):
|
|
||||||
"""Confirmation dialog before permanently deleting a file.
|
|
||||||
|
|
||||||
After a successful delete the file is also removed from the editor's
|
|
||||||
open-files list and content cache so it cannot be saved back to disk.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
relative_file_path: Workspace-relative path to the file (used by FileManager).
|
|
||||||
file_name: Display name shown in the warning message.
|
|
||||||
"""
|
|
||||||
st.warning(f"Delete **{file_name}**? This cannot be undone.")
|
|
||||||
|
|
||||||
col1, col2 = st.columns(2)
|
|
||||||
with col1:
|
|
||||||
if st.button("Delete", type="primary", use_container_width=True):
|
|
||||||
if fm.delete_file(relative_file_path):
|
|
||||||
abs_file_path = str(Path(fm.base_path) / relative_file_path)
|
|
||||||
st.session_state.open_files.remove(abs_file_path)
|
|
||||||
st.session_state.files_content.pop(abs_file_path, None)
|
|
||||||
# Fall back to the first remaining open file, or None if all tabs are closed.
|
|
||||||
if st.session_state.active_file == abs_file_path:
|
|
||||||
st.session_state.active_file = (
|
|
||||||
st.session_state.open_files[0]
|
|
||||||
if st.session_state.open_files else None
|
|
||||||
)
|
|
||||||
st.rerun()
|
|
||||||
else:
|
|
||||||
st.error("Delete failed. Check that the file still exists.")
|
|
||||||
with col2:
|
|
||||||
if st.button("Cancel", use_container_width=True):
|
|
||||||
st.rerun()
|
|
||||||
|
|
||||||
|
|
||||||
# ── File tree ─────────────────────────────────────────────────────────────────
|
# ── File tree ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def build_arborist_tree(tree, parent_path=Path()):
|
def build_arborist_tree(tree, parent_path=Path()):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user