Skip to content
Merged
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
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,27 @@
}
},
"keybindings": [
{
"command": "java.view.package.revealFileInOS",
"key": "ctrl+alt+r",
"win": "shift+alt+r",
"mac": "cmd+alt+r",
"when": "java:projectManagerActivated && focusedView == javaProjectExplorer"
},
{
"command": "java.view.package.copyFilePath",
"key": "ctrl+alt+c",
"win": "shift+alt+c",
"mac": "cmd+alt+c",
"when": "java:projectManagerActivated && focusedView == javaProjectExplorer"
},
{
"command": "java.view.package.copyRelativeFilePath",
"key": "ctrl+shift+alt+c",
"win": "ctrl+k ctrl+shift+c",
"mac": "cmd+shift+alt+c",
"when": "java:projectManagerActivated && focusedView == javaProjectExplorer"
},
{
"command": "java.view.package.renameFile",
"key": "F2",
Expand Down
11 changes: 3 additions & 8 deletions src/explorerCommands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@

import { Uri, window, workspace } from "vscode";
import { DataNode } from "../views/dataNode";
import { ExplorerNode } from "../views/explorerNode";
import { isMutable } from "./utility";

const confirmMessage = "Move to Recycle Bin";

export async function deleteFiles(node: DataNode, selectedNode: ExplorerNode): Promise<void> {
// if command not invoked by context menu, use selected node in explorer
if (!node) {
node = selectedNode as DataNode;
if (!isMutable(node)) {
return;
}
export async function deleteFiles(node: DataNode): Promise<void> {
if (!isMutable(node) || !node.uri) {
return;
}

const children = await node.getChildren();
Expand Down
13 changes: 4 additions & 9 deletions src/explorerCommands/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import * as path from "path";
import { Uri, window, workspace, WorkspaceEdit } from "vscode";
import { NodeKind } from "../java/nodeData";
import { DataNode } from "../views/dataNode";
import { ExplorerNode } from "../views/explorerNode";
import { checkJavaQualifiedName, isMutable } from "./utility";

export async function renameFile(node: DataNode, selectedNode: ExplorerNode): Promise<void> {
// if command not invoked by context menu, use selected node in explorer
if (!node) {
node = selectedNode as DataNode;
if (!isMutable(node)) {
return;
}
export async function renameFile(node: DataNode): Promise<void> {
if (!isMutable(node) || !node.uri) {
return;
}

const oldFsPath = Uri.parse(node.uri).fsPath;
Expand Down Expand Up @@ -64,7 +59,7 @@ function getPrefillValue(node: DataNode): string {
if (nodeKind === NodeKind.PrimaryType) {
return node.name;
}
return path.basename(node.uri);
return path.basename(node.uri!);
}

function getValueSelection(uri: string): [number, number] | undefined {
Expand Down
6 changes: 6 additions & 0 deletions src/explorerCommands/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { isJavaIdentifier, isKeyword } from "../utility";
import { DataNode } from "../views/dataNode";
import { ExplorerNode } from "../views/explorerNode";

export function isMutable(node: DataNode): boolean {
// avoid modify dependency files
Expand Down Expand Up @@ -30,3 +31,8 @@ export function checkJavaQualifiedName(value: string): string {

return "";
}

export function getCmdNode(selectedNode: ExplorerNode, node?: DataNode): DataNode {
// if command not invoked by context menu, use selected node in explorer
return node ? node : selectedNode as DataNode;
}
6 changes: 0 additions & 6 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
}));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_CLASS, (node: DataNode) => newJavaClass(node)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_PACKAGE, (node: DataNode) => newPackage(node)));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: INodeData) =>
commands.executeCommand("revealFileInOS", Uri.parse(node.uri))));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node: INodeData) =>
commands.executeCommand("copyFilePath", Uri.parse(node.uri))));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node: INodeData) =>
commands.executeCommand("copyRelativeFilePath", Uri.parse(node.uri))));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OPEN_FILE, (uri) =>
commands.executeCommand(Commands.VSCODE_OPEN, Uri.parse(uri), { preserveFocus: true })));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_OUTLINE, (uri, range) =>
Expand Down
37 changes: 33 additions & 4 deletions src/views/dependencyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Commands } from "../commands";
import { Build } from "../constants";
import { deleteFiles } from "../explorerCommands/delete";
import { renameFile } from "../explorerCommands/rename";
import { getCmdNode } from "../explorerCommands/utility";
import { isStandardServerReady } from "../extension";
import { Jdtls } from "../java/jdtls";
import { INodeData } from "../java/nodeData";
Expand Down Expand Up @@ -84,15 +85,43 @@ export class DependencyExplorer implements Disposable {
}),
);

// register keybinding commands
context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_RENAME_FILE, (node: DataNode) => {
renameFile(node, this._dependencyViewer.selection[0]);
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: DataNode) => {
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
if (cmdNode.uri) {
commands.executeCommand("revealFileInOS", Uri.parse(cmdNode.uri));
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node?: DataNode) => {
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
if (cmdNode.uri) {
commands.executeCommand("copyFilePath", Uri.parse(cmdNode.uri));
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node?: DataNode) => {
const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node);
if (cmdNode.uri) {
commands.executeCommand("copyRelativeFilePath", Uri.parse(cmdNode.uri));
}
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_RENAME_FILE, (node?: DataNode) => {
renameFile(getCmdNode(this._dependencyViewer.selection[0], node));
}),
);

context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_MOVE_FILE_TO_TRASH, (node: DataNode) => {
deleteFiles(node, this._dependencyViewer.selection[0]);
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_MOVE_FILE_TO_TRASH, (node?: DataNode) => {
deleteFiles(getCmdNode(this._dependencyViewer.selection[0], node));
}),
);
}
Expand Down