Readonly files are not renamable now!
This commit is contained in:
@@ -24,13 +24,19 @@ import { saveAllFiles } from "../state/actions/saveFile";
|
|||||||
import { Tab, Tabs } from "./Tabs";
|
import { Tab, Tabs } from "./Tabs";
|
||||||
import { renameFile } from "../state/actions/createNewFile";
|
import { renameFile } from "../state/actions/createNewFile";
|
||||||
|
|
||||||
const validateWritability = (editor: monaco.editor.IStandaloneCodeEditor) => {
|
const checkWritable = (filename?: string): boolean => {
|
||||||
const currPath = editor.getModel()?.uri.path;
|
if (apiHeaderFiles.find(file => file === filename)) {
|
||||||
if (apiHeaderFiles.find(h => currPath?.endsWith(h))) {
|
return false;
|
||||||
editor.updateOptions({ readOnly: true });
|
|
||||||
} else {
|
|
||||||
editor.updateOptions({ readOnly: false });
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateWritability = (
|
||||||
|
editor: monaco.editor.IStandaloneCodeEditor
|
||||||
|
) => {
|
||||||
|
const filename = editor.getModel()?.uri.path.split("/").pop();
|
||||||
|
const isWritable = checkWritable(filename);
|
||||||
|
editor.updateOptions({ readOnly: !isWritable });
|
||||||
};
|
};
|
||||||
|
|
||||||
let decorations: { [key: string]: string[] } = {};
|
let decorations: { [key: string]: string[] } = {};
|
||||||
@@ -138,7 +144,7 @@ const HooksEditor = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{snap.files.map((file, index) => {
|
{snap.files.map((file, index) => {
|
||||||
return <Tab key={file.name} header={file.name} />;
|
return <Tab key={file.name} header={file.name} renameDisabled={!checkWritable(file.name)} />;
|
||||||
})}
|
})}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Nullable<T> = T | null | undefined | false;
|
|||||||
interface TabProps {
|
interface TabProps {
|
||||||
header: string;
|
header: string;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
renameDisabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO customize messages shown
|
// TODO customize messages shown
|
||||||
@@ -211,14 +212,17 @@ export const Tabs = ({
|
|||||||
key: "close",
|
key: "close",
|
||||||
onSelect: () => handleCloseTab(idx),
|
onSelect: () => handleCloseTab(idx),
|
||||||
};
|
};
|
||||||
const renameOption = (idx: number): Nullable<ContentMenuOption> =>
|
const renameOption = (idx: number, tab: TabProps): Nullable<ContentMenuOption> => {
|
||||||
onRenameTab && {
|
return (
|
||||||
type: "text",
|
onRenameTab && !tab.renameDisabled && {
|
||||||
label: "Rename",
|
type: "text",
|
||||||
key: "rename",
|
label: "Rename",
|
||||||
onSelect: () => setRenamingTab(idx),
|
key: "rename",
|
||||||
};
|
onSelect: () => setRenamingTab(idx),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!headless && (
|
{!headless && (
|
||||||
@@ -236,7 +240,7 @@ export const Tabs = ({
|
|||||||
<ContextMenu
|
<ContextMenu
|
||||||
key={tab.header}
|
key={tab.header}
|
||||||
options={
|
options={
|
||||||
[closeOption(idx), renameOption(idx)].filter(
|
[closeOption(idx), renameOption(idx, tab)].filter(
|
||||||
Boolean
|
Boolean
|
||||||
) as ContentMenuOption[]
|
) as ContentMenuOption[]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user