Readonly files are not renamable now!

This commit is contained in:
muzam1l
2022-08-04 18:54:20 +05:30
parent ef4f95ca3e
commit 1f5a9731bb
2 changed files with 26 additions and 16 deletions

View File

@@ -24,13 +24,19 @@ import { saveAllFiles } from "../state/actions/saveFile";
import { Tab, Tabs } from "./Tabs";
import { renameFile } from "../state/actions/createNewFile";
const validateWritability = (editor: monaco.editor.IStandaloneCodeEditor) => {
const currPath = editor.getModel()?.uri.path;
if (apiHeaderFiles.find(h => currPath?.endsWith(h))) {
editor.updateOptions({ readOnly: true });
} else {
editor.updateOptions({ readOnly: false });
const checkWritable = (filename?: string): boolean => {
if (apiHeaderFiles.find(file => file === filename)) {
return 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[] } = {};
@@ -138,7 +144,7 @@ const HooksEditor = () => {
}}
>
{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>
);

View File

@@ -31,6 +31,7 @@ type Nullable<T> = T | null | undefined | false;
interface TabProps {
header: string;
children?: ReactNode;
renameDisabled?: boolean
}
// TODO customize messages shown
@@ -211,14 +212,17 @@ export const Tabs = ({
key: "close",
onSelect: () => handleCloseTab(idx),
};
const renameOption = (idx: number): Nullable<ContentMenuOption> =>
onRenameTab && {
type: "text",
label: "Rename",
key: "rename",
onSelect: () => setRenamingTab(idx),
};
const renameOption = (idx: number, tab: TabProps): Nullable<ContentMenuOption> => {
return (
onRenameTab && !tab.renameDisabled && {
type: "text",
label: "Rename",
key: "rename",
onSelect: () => setRenamingTab(idx),
}
);
}
return (
<>
{!headless && (
@@ -236,7 +240,7 @@ export const Tabs = ({
<ContextMenu
key={tab.header}
options={
[closeOption(idx), renameOption(idx)].filter(
[closeOption(idx), renameOption(idx, tab)].filter(
Boolean
) as ContentMenuOption[]
}