diff --git a/gui/src/pages/Edit/AddFileButton.tsx b/gui/src/pages/Edit/AddFileButton.tsx new file mode 100644 index 000000000..93611e9f7 --- /dev/null +++ b/gui/src/pages/Edit/AddFileButton.tsx @@ -0,0 +1,79 @@ +import { useContext, useState, useRef, useEffect } from "react"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice"; +import { useDispatch } from "react-redux"; +import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; +import { addCodeToEdit } from "../../redux/slices/editModeState"; +import { Listbox } from "@headlessui/react"; + +export default function AddFileButton() { + const [showAbove, setShowAbove] = useState(false); + const buttonRef = useRef(null); + const ideMessenger = useContext(IdeMessengerContext); + const dispatch = useDispatch(); + + function onClickAddFileToCodeToEdit() { + dispatch(setShouldAddFileForEditing(true)); + } + + async function handleAddAllOpenFiles() { + const openFiles = await ideMessenger.ide.getOpenFiles(); + + for (const filepath of openFiles) { + const contents = await ideMessenger.ide.readFile(filepath); + console.log({ filepath, contents }); + dispatch(addCodeToEdit({ filepath, contents })); + } + } + + // function calculatePosition() { + // const rect = buttonRef.current?.getBoundingClientRect(); + // if (!rect) return; + // const spaceBelow = window.innerHeight - rect.bottom; + // const spaceAbove = rect.top; + // const dropdownHeight = 300; + + // setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow); + // } + + return ( + +
+ +
{ + e.preventDefault(); + e.stopPropagation(); + onClickAddFileToCodeToEdit(); + }} + > + + Add file +
+ +
+ + + + + + + Add all open files + + +
+ + ); +} diff --git a/gui/src/pages/Edit/CodeToEdit.tsx b/gui/src/pages/Edit/CodeToEdit.tsx index 7f990415b..984d724f8 100644 --- a/gui/src/pages/Edit/CodeToEdit.tsx +++ b/gui/src/pages/Edit/CodeToEdit.tsx @@ -1,13 +1,12 @@ -import { PlusIcon } from "@heroicons/react/24/outline"; import { useContext } from "react"; import { useDispatch, useSelector } from "react-redux"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { removeCodeToEdit } from "../../redux/slices/editModeState"; import { RootState } from "../../redux/store"; import CodeToEditListItem from "./CodeToEditListItem"; -import { vscEditorBackground } from "../../components"; -import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice"; + import { CodeToEdit, RangeInFileWithContents } from "core"; +import AddFileButton from "./AddFileButton"; export default function WorkingSet() { const dispatch = useDispatch(); @@ -16,8 +15,6 @@ export default function WorkingSet() { const hasCodeToEdit = editModeState.codeToEdit.length > 0; - const addFileText = hasCodeToEdit ? "Add file" : "Add a file to get started"; - const title = editModeState.codeToEdit.length === 0 ? "Code to edit" @@ -29,10 +26,6 @@ export default function WorkingSet() { dispatch(removeCodeToEdit(rif)); } - function onClickAddFileToCodeToEdit() { - dispatch(setShouldAddFileForEditing(true)); - } - function onClickFilename(code: CodeToEdit) { if ("range" in code) { ideMessenger.ide.showLines( @@ -60,14 +53,7 @@ export default function WorkingSet() {
{title} - - - - {addFileText} - +
{hasCodeToEdit && (