chore: readonly and navigation booleans

This commit is contained in:
Kevin
2025-06-24 15:05:11 -05:00
parent ab29916bff
commit 821af16fcf
3 changed files with 55 additions and 25 deletions

View File

@ -242,7 +242,6 @@ export function App() {
.catch(reportRejection) .catch(reportRejection)
} }
}, []) }, [])
return ( return (
<div className="h-screen flex flex-col overflow-hidden select-none"> <div className="h-screen flex flex-col overflow-hidden select-none">
<div className="relative flex flex-1 flex-col"> <div className="relative flex flex-1 flex-col">

View File

@ -58,6 +58,8 @@ export const ProjectExplorer = ({
collapsePressed, collapsePressed,
onRowClicked, onRowClicked,
onRowEnter, onRowEnter,
readOnly,
canNavigate,
}: { }: {
project: Project project: Project
file: FileEntry | undefined file: FileEntry | undefined
@ -67,6 +69,8 @@ export const ProjectExplorer = ({
collapsePressed: number collapsePressed: number
onRowClicked: (row: FileExplorerEntry, domIndex: number) => void onRowClicked: (row: FileExplorerEntry, domIndex: number) => void
onRowEnter: (row: FileExplorerEntry, domIndex: number) => void onRowEnter: (row: FileExplorerEntry, domIndex: number) => void
readOnly: boolean
canNavigate: boolean
}) => { }) => {
const { errors } = useKclContext() const { errors } = useKclContext()
const settings = useSettings() const settings = useSettings()
@ -121,7 +125,7 @@ export const ProjectExplorer = ({
* If code wants to externall trigger creating a file pass in a new timestamp. * If code wants to externall trigger creating a file pass in a new timestamp.
*/ */
useEffect(() => { useEffect(() => {
if (createFilePressed <= 0) { if (createFilePressed <= 0 || readOnly) {
return return
} }
@ -136,7 +140,7 @@ export const ProjectExplorer = ({
}, [createFilePressed]) }, [createFilePressed])
useEffect(() => { useEffect(() => {
if (createFolderPressed <= 0) { if (createFolderPressed <= 0 || readOnly) {
return return
} }
const row = rowsToRenderRef.current[activeIndexRef.current] || null const row = rowsToRenderRef.current[activeIndexRef.current] || null
@ -285,7 +289,12 @@ export const ProjectExplorer = ({
isFake: false, isFake: false,
activeIndex: activeIndex, activeIndex: activeIndex,
onDelete: () => { onDelete: () => {
const shouldWeNavigate = file?.path?.startsWith(child.path) if (readOnly) {
return
}
const shouldWeNavigate =
file?.path?.startsWith(child.path) && canNavigate
if (shouldWeNavigate && file && file.path) { if (shouldWeNavigate && file && file.path) {
systemIOActor.send({ systemIOActor.send({
@ -308,6 +317,10 @@ export const ProjectExplorer = ({
window.electron.openInNewWindow(row.path) window.electron.openInNewWindow(row.path)
}, },
onRenameStart: () => { onRenameStart: () => {
if (readOnly) {
return
}
setIsRenaming(true) setIsRenaming(true)
isRenamingRef.current = true isRenamingRef.current = true
}, },
@ -353,7 +366,8 @@ export const ProjectExplorer = ({
absolutePathToParentDirectory, absolutePathToParentDirectory,
requestedName requestedName
) )
const shouldWeNavigate = file?.path?.startsWith(oldPath) const shouldWeNavigate =
file?.path?.startsWith(oldPath) && canNavigate
if (shouldWeNavigate && file && file.path) { if (shouldWeNavigate && file && file.path) {
const requestedFileNameWithExtension = const requestedFileNameWithExtension =
@ -415,8 +429,9 @@ export const ProjectExplorer = ({
applicationProjectDirectory applicationProjectDirectory
) )
// create a file if it is fake and navigate to that file!
if (row.isFake) { if (row.isFake) {
// create a file if it is fake and navigate to that file!
if (file && canNavigate) {
systemIOActor.send({ systemIOActor.send({
type: SystemIOMachineEvents.importFileFromURL, type: SystemIOMachineEvents.importFileFromURL,
data: { data: {
@ -425,6 +440,17 @@ export const ProjectExplorer = ({
requestedFileNameWithExtension: pathRelativeToParent, requestedFileNameWithExtension: pathRelativeToParent,
}, },
}) })
} else {
systemIOActor.send({
type: SystemIOMachineEvents.createBlankFile,
data: {
requestedAbsolutePath: joinOSPaths(
getParentAbsolutePath(row.path),
fileNameForcedWithOriginalExt
),
},
})
}
} else { } else {
const requestedAbsoluteFilePathWithExtension = joinOSPaths( const requestedAbsoluteFilePathWithExtension = joinOSPaths(
getParentAbsolutePath(row.path), getParentAbsolutePath(row.path),
@ -433,7 +459,8 @@ export const ProjectExplorer = ({
// If your router loader is within the file you are renaming then reroute to the new path on disk // If your router loader is within the file you are renaming then reroute to the new path on disk
// If you are renaming a file you are not loaded into, do not reload! // If you are renaming a file you are not loaded into, do not reload!
const shouldWeNavigate = const shouldWeNavigate =
requestedAbsoluteFilePathWithExtension === file?.path requestedAbsoluteFilePathWithExtension === file?.path &&
canNavigate
systemIOActor.send({ systemIOActor.send({
type: shouldWeNavigate type: shouldWeNavigate
? SystemIOMachineEvents.renameFileAndNavigateToFile ? SystemIOMachineEvents.renameFileAndNavigateToFile

View File

@ -229,6 +229,7 @@ export const sidebarPanes: SidebarPane[] = [
onClose={props.onClose} onClose={props.onClose}
/> />
{theProject && file ? ( {theProject && file ? (
<div className={'w-full h-full flex flex-col'}>
<ProjectExplorer <ProjectExplorer
project={theProject} project={theProject}
file={file} file={file}
@ -238,7 +239,10 @@ export const sidebarPanes: SidebarPane[] = [
collapsePressed={collapsePressed} collapsePressed={collapsePressed}
onRowClicked={onRowClicked} onRowClicked={onRowClicked}
onRowEnter={onRowClicked} onRowEnter={onRowClicked}
canNavigate={true}
readOnly={false}
></ProjectExplorer> ></ProjectExplorer>
</div>
) : ( ) : (
<div></div> <div></div>
)} )}