(feat) add file manager tab

This commit is contained in:
cardosofede
2023-08-04 18:40:10 +02:00
parent 09b6c0f134
commit f4300bb9eb

View File

@@ -1,44 +1,40 @@
import streamlit as st
from streamlit_elements import elements, mui, lazy, sync, event
from types import SimpleNamespace
import streamlit as st
from streamlit_elements import elements, mui, lazy, sync, event
from streamlit_elements import elements, mui
from ui_components.bots_file_explorer import BotsFileExplorer
from ui_components.dashboard import Dashboard
from ui_components.file_explorer import FileExplorer
from ui_components.editor import Editor
from utils.st_utils import initialize_st_page
initialize_st_page(title="File Manager", icon="🗂️", initial_sidebar_state="expanded")
if "editor_tabs" not in st.session_state:
st.session_state.editor_tabs = {}
initialize_st_page(title="File Manager", icon="🗂️", initial_sidebar_state="collapsed")
# TODO: Use this to save the current file selected
if "selected_file" not in st.session_state:
st.session_state.selected_file = ""
if "w" not in st.session_state:
if "fe_board" not in st.session_state:
board = Dashboard()
w = SimpleNamespace(
fe_board = SimpleNamespace(
dashboard=board,
file_explorer=FileExplorer(board, 0, 0, 3, 7),
file_explorer=BotsFileExplorer(board, 0, 0, 3, 7),
editor=Editor(board, 4, 0, 9, 7),
)
st.session_state.w = w
st.session_state.fe_board = fe_board
else:
w = st.session_state.w
fe_board = st.session_state.fe_board
for tab_name, content in st.session_state.editor_tabs.items():
if tab_name not in w.editor._tabs:
w.editor.add_tab(tab_name, content["content"], content["language"], content["file_path"])
# Add new tabs
for tab_name, content in fe_board.file_explorer.tabs.items():
if tab_name not in fe_board.editor.tabs:
fe_board.editor.add_tab(tab_name, content["content"], content["language"])
with elements("bot_config"):
with mui.Paper(style={"padding": "2rem"}, variant="outlined"):
mui.Typography("Select a file and click ✏️ to edit it or 🗑️ to delete it. Click 💾 to save your changes.", variant="body1", sx={"margin-bottom": "2rem"})
event.Hotkey("ctrl+s", sync(), bindInputs=True, overrideDefault=True)
with w.dashboard():
w.file_explorer()
w.editor()
# Remove deleted tabs
for tab_name in list(fe_board.editor.tabs.keys()):
if tab_name not in fe_board.file_explorer.tabs:
fe_board.editor.remove_tab(tab_name)
with elements("file_manager"):
with mui.Paper(elevation=3, style={"padding": "2rem"}, spacing=[2, 2], container=True):
with fe_board.dashboard():
fe_board.file_explorer()
fe_board.editor()