mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +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)
|
||||
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 {
|
||||
WriteStderr("[error] file does not exist: %q\n", absFile)
|
||||
WriteStderr("[error] parent directory does not exist: %q\n", absParent)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -432,9 +432,14 @@ export class PreviewModel implements ViewModel {
|
||||
const fileInfo = await getFn(this.statFile);
|
||||
const fileName = await getFn(this.statFilePath);
|
||||
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) {
|
||||
return { errorStr: `File Not Found: ${fileInfo.path}` };
|
||||
return { specializedView: "codeedit" };
|
||||
}
|
||||
if (mimeType == null) {
|
||||
return { errorStr: `Unable to determine mimetype for: ${fileInfo.path}` };
|
||||
@ -492,6 +497,18 @@ export class PreviewModel implements ViewModel {
|
||||
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() {
|
||||
const fileInfo = await globalStore.get(this.statFile);
|
||||
if (fileInfo == null) {
|
||||
@ -500,7 +517,7 @@ export class PreviewModel implements ViewModel {
|
||||
}
|
||||
const conn = globalStore.get(this.connection);
|
||||
try {
|
||||
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.dir, ".."], {
|
||||
const newFileInfo = await RpcApi.RemoteFileJoinCommand(WindowRpcClient, [fileInfo.path, ".."], {
|
||||
route: makeConnRoute(conn),
|
||||
});
|
||||
console.log(newFileInfo.path);
|
||||
|
Loading…
Reference in New Issue
Block a user