MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / createNew

Function createNew

src/lib/openFolder.js:668–710  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

666 }
667
668 async function createNew() {
669 const msg =
670 action === "new file"
671 ? strings["enter file name"]
672 : strings["enter folder name"];
673
674 let newName = await prompt(msg, "", "text", {
675 match: config.FILE_NAME_REGEX,
676 required: true,
677 });
678
679 newName = helpers.fixFilename(newName);
680 if (!newName) return;
681 startLoading();
682 try {
683 const isNestedPath = newName.split("/").filter(Boolean).length > 1;
684 let newUrl;
685
686 if (action === "new file") {
687 newUrl = await helpers.createFileStructure(url, newName);
688 } else {
689 newUrl = await helpers.createFileStructure(url, newName, false);
690 }
691 if (!newUrl.created) return;
692
693 if (isNestedPath) {
694 await refreshOpenFolder(url);
695 await FileList.refresh();
696 toast(strings.success);
697 return;
698 }
699
700 newName = Url.basename(newUrl.uri);
701 appendEntryToOpenFolder(url, newUrl.uri, newUrl.type);
702
703 FileList.append(url, newUrl.uri);
704 toast(strings.success);
705 } catch (error) {
706 helpers.error(error);
707 } finally {
708 stopLoading();
709 }
710 }
711
712 async function paste() {
713 if (clipBoard.url == null) {

Callers 1

execOperationFunction · 0.85

Calls 9

refreshOpenFolderFunction · 0.85
appendEntryToOpenFolderFunction · 0.85
refreshMethod · 0.80
basenameMethod · 0.80
appendMethod · 0.80
promptFunction · 0.70
startLoadingFunction · 0.70
stopLoadingFunction · 0.70
errorMethod · 0.45

Tested by

no test coverage detected