chore: readonly and navigation booleans
This commit is contained in:
@ -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">
|
||||||
|
|||||||
@ -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,16 +429,28 @@ export const ProjectExplorer = ({
|
|||||||
applicationProjectDirectory
|
applicationProjectDirectory
|
||||||
)
|
)
|
||||||
|
|
||||||
// create a file if it is fake and navigate to that file!
|
|
||||||
if (row.isFake) {
|
if (row.isFake) {
|
||||||
systemIOActor.send({
|
// create a file if it is fake and navigate to that file!
|
||||||
type: SystemIOMachineEvents.importFileFromURL,
|
if (file && canNavigate) {
|
||||||
data: {
|
systemIOActor.send({
|
||||||
requestedCode: '',
|
type: SystemIOMachineEvents.importFileFromURL,
|
||||||
requestedProjectName: project.name,
|
data: {
|
||||||
requestedFileNameWithExtension: pathRelativeToParent,
|
requestedCode: '',
|
||||||
},
|
requestedProjectName: project.name,
|
||||||
})
|
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
|
||||||
|
|||||||
@ -229,16 +229,20 @@ export const sidebarPanes: SidebarPane[] = [
|
|||||||
onClose={props.onClose}
|
onClose={props.onClose}
|
||||||
/>
|
/>
|
||||||
{theProject && file ? (
|
{theProject && file ? (
|
||||||
<ProjectExplorer
|
<div className={'w-full h-full flex flex-col'}>
|
||||||
project={theProject}
|
<ProjectExplorer
|
||||||
file={file}
|
project={theProject}
|
||||||
createFilePressed={createFilePressed}
|
file={file}
|
||||||
createFolderPressed={createFolderPressed}
|
createFilePressed={createFilePressed}
|
||||||
refreshExplorerPressed={refreshExplorerPressed}
|
createFolderPressed={createFolderPressed}
|
||||||
collapsePressed={collapsePressed}
|
refreshExplorerPressed={refreshExplorerPressed}
|
||||||
onRowClicked={onRowClicked}
|
collapsePressed={collapsePressed}
|
||||||
onRowEnter={onRowClicked}
|
onRowClicked={onRowClicked}
|
||||||
></ProjectExplorer>
|
onRowEnter={onRowClicked}
|
||||||
|
canNavigate={true}
|
||||||
|
readOnly={false}
|
||||||
|
></ProjectExplorer>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div></div>
|
<div></div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user