mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
Open Text File if File Does Not Exist (#963)
This will open new files as empty text files for editing.
This commit is contained in:
parent
28f189bccd
commit
76ccd83c5c
@ -58,9 +58,14 @@ func viewRun(cmd *cobra.Command, args []string) {
|
|||||||
WriteStderr("[error] getting absolute path: %v\n", err)
|
WriteStderr("[error] getting absolute path: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = os.Stat(absFile)
|
absParent, err := filepath.Abs(filepath.Dir(fileArg))
|
||||||
|
if err != nil {
|
||||||
|
WriteStderr("[error] getting absolute path of parent dir: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = os.Stat(absParent)
|
||||||
if err == fs.ErrNotExist {
|
if err == fs.ErrNotExist {
|
||||||
WriteStderr("[error] file does not exist: %q\n", absFile)
|
WriteStderr("[error] parent directory does not exist: %q\n", absParent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -432,9 +432,14 @@ export class PreviewModel implements ViewModel {
|
|||||||
const fileInfo = await getFn(this.statFile);
|
const fileInfo = await getFn(this.statFile);
|
||||||
const fileName = await getFn(this.statFilePath);
|
const fileName = await getFn(this.statFilePath);
|
||||||
const editMode = getFn(this.editMode);
|
const editMode = getFn(this.editMode);
|
||||||
|
const parentFileInfo = await this.getParentInfo(fileInfo);
|
||||||
|
console.log(parentFileInfo);
|
||||||
|
|
||||||
|
if (parentFileInfo?.notfound ?? false) {
|
||||||
|
return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` };
|
||||||
|
}
|
||||||
if (fileInfo?.notfound) {
|
if (fileInfo?.notfound) {
|
||||||
return { errorStr: `File Not Found: ${fileInfo.path}` };
|
return { specializedView: "codeedit" };
|
||||||
}
|
}
|
||||||
if (mimeType == null) {
|
if (mimeType == null) {
|
||||||
return { errorStr: `Unable to determine mimetype for: ${fileInfo.path}` };
|
return { errorStr: `Unable to determine mimetype for: ${fileInfo.path}` };
|
||||||
@ -492,6 +497,18 @@ export class PreviewModel implements ViewModel {
|
|||||||
services.ObjectService.UpdateObjectMeta(blockOref, updateMeta);
|
services.ObjectService.UpdateObjectMeta(blockOref, updateMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getParentInfo(fileInfo: FileInfo): Promise<FileInfo | undefined> {
|
||||||
|
const conn = globalStore.get(this.connection);
|
||||||
|
try {
|
||||||
|
const parentFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], {
|
||||||
|
route: makeConnRoute(conn),
|
||||||
|
});
|
||||||
|
return parentFileInfo;
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async goParentDirectory() {
|
async goParentDirectory() {
|
||||||
const fileInfo = await globalStore.get(this.statFile);
|
const fileInfo = await globalStore.get(this.statFile);
|
||||||
if (fileInfo == null) {
|
if (fileInfo == null) {
|
||||||
@ -500,7 +517,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
}
|
}
|
||||||
const conn = globalStore.get(this.connection);
|
const conn = globalStore.get(this.connection);
|
||||||
try {
|
try {
|
||||||
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.dir, ".."], {
|
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], {
|
||||||
route: makeConnRoute(conn),
|
route: makeConnRoute(conn),
|
||||||
});
|
});
|
||||||
console.log(newFileInfo.path);
|
console.log(newFileInfo.path);
|
||||||
|
Loading…
Reference in New Issue
Block a user