Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Text File if File Does Not Exist #963

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/wsh/cmd/wshcmd-view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 19 additions & 2 deletions frontend/app/view/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}` };
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down