Skip to content

Commit

Permalink
File Explorer: Limit create actions to directories (#166)
Browse files Browse the repository at this point in the history
This limits the create file and directory actions to a context on a
directory.

Signed-off-by: Tyler Smalley <tyler@tailscale.com>
  • Loading branch information
tylersmalley committed Aug 4, 2023
1 parent bd192b6 commit 4be860d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,22 @@
{
"command": "tailscale.node.fs.createDirectory",
"group": "3_dirAction@1",
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer/"
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-dir/"
},
{
"command": "tailscale.node.fs.createFile",
"group": "3_dirAction@2",
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-child/"
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-dir/"
},
{
"command": "tailscale.node.fs.rename",
"group": "4_fileAction@1",
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-child/"
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-(dir|file)/"
},
{
"command": "tailscale.node.fs.delete",
"group": "4_fileAction@2",
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-child/"
"when": "view == node-explorer-view && viewItem =~ /^peer-file-explorer-(dir|file)/"
}
]
},
Expand Down
6 changes: 4 additions & 2 deletions src/node-explorer-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class NodeExplorerProvider implements vscode.TreeDataProvider<PeerBaseTre
const dirents = await vscode.workspace.fs.readDirectory(element.uri);
return dirents.map(([name, type]) => {
const childUri = element.uri.with({ path: `${element.uri.path}/${name}` });
return new FileExplorer(name, childUri, type, 'child');
return new FileExplorer(name, childUri, type);
});
}

Expand Down Expand Up @@ -468,7 +468,9 @@ export class FileExplorer extends vscode.TreeItem {
};
}

this.contextValue = `peer-file-explorer${context && `-${context}`}`;
const typeDesc = type === vscode.FileType.File ? 'file' : 'dir';

this.contextValue = `peer-file-explorer-${typeDesc}${context && `-${context}`}`;
}
}

Expand Down

0 comments on commit 4be860d

Please sign in to comment.