Skip to content

Commit

Permalink
Bind Delete shortcut with Delete Cluster, Topic command
Browse files Browse the repository at this point in the history
Fixes #79

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr authored and fbricon committed Jan 14, 2021
1 parent 697d130 commit 0f5b732
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to Kafka extension will be documented in this file.
- Click on empty Kafka explorer to add a new cluster. See [#76](https//github.com/jlandersen/vscode-kafka/pull/76).
- Added glob patterns to filter topics (`kafka.explorer.topics.filters`) and consumer groups (`kafka.explorer.consumers.filters`) out of the Kafka explorer. See [#74](https://github.com/jlandersen/vscode-kafka/pull/74).
- Kafka Explorer item labels can now be copied to the clipboard (supports multi selection). See [#68](https://github.com/jlandersen/vscode-kafka/issues/68).
- Selected Cluster or Topic can now be deleted via the Delete shortcut (Cmd+Backspace on Mac). See [#79](https://github.com/jlandersen/vscode-kafka/issues/79)

### Changed
- Improved the "New cluster" and "New topic" wizards: now include validation and a back button. See [#21](https://github.com/jlandersen/vscode-kafka/issues/21).
Expand Down
67 changes: 39 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"onCommand:vscode-kafka.consumer.consume",
"onCommand:vscode-kafka.consumer.list",
"onCommand:vscode-kafka.consumer.toggle",
"onCommand:vscode-kafka.explorer.copy",
"onCommand:vscode-kafka.explorer.copylabel",
"onCommand:vscode-kafka.explorer.deleteselected",
"onView:kafkaExplorer",
"onLanguage:kafka",
"onDebug"
Expand Down Expand Up @@ -66,20 +67,24 @@
},
"kafka.explorer.topics.filter": {
"type": "array",
"default": ["__consumer_offsets", "__transaction_state", "_schemas"],
"default": [
"__consumer_offsets",
"__transaction_state",
"_schemas"
],
"markdownDescription": "Glob patterns filtering topics out of the Kafka explorer. `*` matches any string, `?` matches a single character."
},
"kafka.explorer.consumers.filter": {
"type": "array",
"default": [],
"markdownDescription": "Glob patterns filtering consumer groups out of the Kafka explorer. `*` matches any string, `?` matches a single character."
},
"kafka.producers.fakerjs.enabled":{
"kafka.producers.fakerjs.enabled": {
"type": "boolean",
"default":true,
"default": true,
"markdownDescription": "Enable injection of [faker.js](https://github.com/marak/Faker.js/#api-methods)-randomized data in record templates, using the mustache syntax."
},
"kafka.producers.fakerjs.locale":{
"kafka.producers.fakerjs.locale": {
"type": "string",
"enum": [
"az",
Expand Down Expand Up @@ -184,14 +189,19 @@
"category": "Kafka"
},
{
"command": "vscode-kafka.explorer.deletecluster",
"title": "Delete Cluster",
"command": "vscode-kafka.explorer.deleteselected",
"title": "Delete",
"category": "Kafka",
"icon": {
"light": "images/light/trashcan.svg",
"dark": "images/dark/trashcan.svg"
}
},
{
"command": "vscode-kafka.explorer.deletecluster",
"title": "Delete Cluster",
"category": "Kafka"
},
{
"command": "vscode-kafka.explorer.refresh",
"title": "Refresh",
Expand Down Expand Up @@ -274,50 +284,45 @@
"when": "view == kafkaExplorer && viewItem == topics && !listMultiSelection",
"group": "inline"
},
{
"command": "vscode-kafka.explorer.deletecluster",
"when": "view == kafkaExplorer && viewItem == cluster && !listMultiSelection",
"group": "inline"
},
{
"command": "vscode-kafka.consumer.consume",
"when": "view == kafkaExplorer && viewItem == topic && !listMultiSelection",
"group":"1_kafka"
"group": "1_kafka"
},
{
"command": "vscode-kafka.explorer.dumptopicmetadata",
"when": "view == kafkaExplorer && viewItem == topic && !listMultiSelection",
"group":"1_kafka"
},
{
"command": "vscode-kafka.explorer.deletetopic",
"when": "view == kafkaExplorer && viewItem == topic && !listMultiSelection",
"group":"1_kafka"
"group": "1_kafka"
},
{
"command": "vscode-kafka.explorer.dumpclustermetadata",
"when": "view == kafkaExplorer && viewItem == broker && !listMultiSelection",
"group":"1_kafka"
"group": "1_kafka"
},
{
"command": "vscode-kafka.explorer.dumpbrokermetadata",
"when": "view == kafkaExplorer && viewItem == broker && !listMultiSelection",
"group":"1_kafka"
},
{
"command": "vscode-kafka.explorer.deletecluster",
"when": "view == kafkaExplorer && viewItem == cluster && !listMultiSelection",
"group":"1_kafka"
"group": "1_kafka"
},
{
"command": "vscode-kafka.explorer.selectcluster",
"when": "view == kafkaExplorer && viewItem == cluster && !listMultiSelection",
"group":"1_kafka"
"group": "1_kafka"
},
{
"command": "vscode-kafka.explorer.copylabel",
"when": "view == kafkaExplorer",
"group": "2_cutcopypaste"
},
{
"command": "vscode-kafka.explorer.deleteselected",
"when": "view == kafkaExplorer && viewItem =~ /^cluster$|^topic$/ && !listMultiSelection",
"group": "inline"
},
{
"command": "vscode-kafka.explorer.deleteselected",
"when": "view == kafkaExplorer && viewItem =~ /^cluster$|^topic$/ && !listMultiSelection",
"group": "3_modification"
}
],
"editor/title": [
Expand Down Expand Up @@ -345,12 +350,18 @@
}
]
},
"keybindings":[
"keybindings": [
{
"command": "vscode-kafka.explorer.copylabel",
"key": "Ctrl+C",
"mac": "Cmd+C",
"when": "focusedView == kafkaExplorer"
},
{
"command": "vscode-kafka.explorer.deleteselected",
"key": "delete",
"mac": "cmd+backspace",
"when": "focusedView == kafkaExplorer && !listMultiSelection"
}
]
},
Expand Down
29 changes: 25 additions & 4 deletions src/explorer/kafkaExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TreeView } from "vscode";
import { KafkaModel } from "./models/kafka";
import { ClusterItem } from "./models/cluster";
import { EOL } from 'os';
import { TopicItem } from "./models/topics";

const TREEVIEW_ID = 'kafkaExplorer';

Expand Down Expand Up @@ -36,7 +37,7 @@ export class KafkaExplorer implements vscode.Disposable, vscode.TreeDataProvider
this.root = null;
this.tree = vscode.window.createTreeView(TREEVIEW_ID, {
treeDataProvider: this,
canSelectMany:true
canSelectMany: true
});
}

Expand Down Expand Up @@ -125,13 +126,33 @@ export class KafkaExplorer implements vscode.Disposable, vscode.TreeDataProvider
if (nodes && nodes.length > 0) {
let output = '';
for (let i = 0; i < nodes.length; i++) {
if (i> 0) {
output+=EOL;
if (i > 0) {
output += EOL;
}
output+=nodes[i];
output += nodes[i];
}
vscode.env.clipboard.writeText(output);
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public async deleteSelectedItem(item: any, nodes: NodeBase[] | undefined): Promise<any> {
if (!nodes) {
if (item instanceof NodeBase) {
// case when user click on the Trashcan icon
nodes = [item];
} else {
// get selected tree items (command was executed via keyboard shortcut)
nodes = this.tree?.selection;
}
}
if (nodes && nodes.length > 0) {
const item = nodes[0];
if (item instanceof ClusterItem) {
vscode.commands.executeCommand('vscode-kafka.explorer.deletecluster', item);
} else if (item instanceof TopicItem) {
vscode.commands.executeCommand('vscode-kafka.explorer.deletetopic', item);
}
}
}
}
7 changes: 5 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ export function activate(context: vscode.ExtensionContext): void {
"vscode-kafka.explorer.dumpbrokermetadata",
handleErrors((broker?: BrokerItem) => dumpBrokerMetadataCommandHandler.execute(broker))));
context.subscriptions.push(vscode.commands.registerCommand(
"vscode-kafka.explorer.copylabel",
handleErrors((_item?:any, selection?: NodeBase[]) => explorer.copyLabelsToClipboard(selection))));
"vscode-kafka.explorer.copylabel",
handleErrors((_item?: any, selection?: NodeBase[]) => explorer.copyLabelsToClipboard(selection))));
context.subscriptions.push(vscode.commands.registerCommand(
"vscode-kafka.explorer.deleteselected",
handleErrors((_item?: any, selection?: NodeBase[]) => explorer.deleteSelectedItem(_item, selection))));
context.subscriptions.push(vscode.commands.registerCommand(
"vscode-kafka.consumer.consume",
handleErrors((topic?: TopicItem) => startConsumerCommandHandler.execute(topic))));
Expand Down

0 comments on commit 0f5b732

Please sign in to comment.