diff --git a/package.json b/package.json index 0ced562..d09c79a 100644 --- a/package.json +++ b/package.json @@ -36,15 +36,12 @@ "main": "./out/extension", "contributes": { "views": { - "explorer": [ - { - "id": "mysql", - "name": "MySQL" - } - ] + "explorer": [{ + "id": "mysql", + "name": "MySQL" + }] }, - "commands": [ - { + "commands": [{ "command": "mysql.refresh", "title": "Refresh", "category": "MySQL" @@ -77,32 +74,35 @@ "command": "mysql.selectTop1000", "title": "Select Top 1000", "category": "MySQL" - } - ], - "keybindings": [ + }, { - "command": "mysql.runQuery", - "key": "ctrl+alt+e", - "when": "editorLangId == sql" + "command": "mysql.copyToClipboard", + "title": "Copy To Clipboard", + "category": "MySQL" + }, + { + "command": "mysql.pasteToActiveEditor", + "title": "Paste To Active Editor", + "category": "MySQL" } ], + "keybindings": [{ + "command": "mysql.runQuery", + "key": "ctrl+alt+e", + "when": "editorLangId == sql" + }], "menus": { - "editor/context": [ - { - "command": "mysql.runQuery", - "when": "editorLangId == sql", - "group": "navigation" - } - ], - "view/title": [ - { - "command": "mysql.addConnection", - "when": "view == mysql", - "group": "navigation@1" - } - ], - "view/item/context": [ - { + "editor/context": [{ + "command": "mysql.runQuery", + "when": "editorLangId == sql", + "group": "navigation" + }], + "view/title": [{ + "command": "mysql.addConnection", + "when": "view == mysql", + "group": "navigation@1" + }], + "view/item/context": [{ "command": "mysql.newQuery", "when": "view == mysql && viewItem == connection", "group": "mysql@1" @@ -136,6 +136,16 @@ "command": "mysql.refresh", "when": "view == mysql && viewItem == table", "group": "mysql@1" + }, + { + "command": "mysql.copyToClipboard", + "when": "view == mysql && viewItem != connection", + "group": "mysql@3" + }, + { + "command": "mysql.pasteToActiveEditor", + "when": "view == mysql && viewItem != connection", + "group": "mysql@3" } ] }, @@ -178,4 +188,4 @@ "mysql": "^2.15.0", "uuid": "^3.1.0" } -} +} \ No newline at end of file diff --git a/src/common/utility.ts b/src/common/utility.ts index b9681d3..147b8ac 100644 --- a/src/common/utility.ts +++ b/src/common/utility.ts @@ -65,7 +65,7 @@ export class Utility { if (rows.some(((row) => Array.isArray(row)))) { rows.forEach((row, index) => { if (Array.isArray(row)) { - Utility.showQueryResult(row, "Results " + (index + 1)); + Utility.showQueryResult(row, "Results " + (index + 1)); } else { OutputChannel.appendLine(JSON.stringify(row)); } @@ -104,6 +104,18 @@ export class Utility { return mysql.createConnection(newConnectionOptions); } + public static copyToClipboard(text: string) { + vscode.env.clipboard.writeText(text); + } + + public static pasteToActiveEditor(text: string) { + const activeEditor = vscode.window.activeTextEditor; + + if (activeEditor) { + activeEditor.insertSnippet(new vscode.SnippetString(text)); + } + } + private static getPreviewUri(data) { const uri = vscode.Uri.parse("sqlresult://mysql/data"); diff --git a/src/extension.ts b/src/extension.ts index 1410ff6..bcef954 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import * as vscode from "vscode"; import { AppInsightsClient } from "./common/appInsightsClient"; import { Utility } from "./common/utility"; +import { ColumnNode } from "./model/columnNode"; import { ConnectionNode } from "./model/connectionNode"; import { DatabaseNode } from "./model/databaseNode"; import { INode } from "./model/INode"; @@ -38,6 +39,14 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.commands.registerCommand("mysql.selectTop1000", (tableNode: TableNode) => { tableNode.selectTop1000(); })); + + context.subscriptions.push(vscode.commands.registerCommand("mysql.copyToClipboard", (node: (TableNode | DatabaseNode | ColumnNode)) => { + node.copyToClipboard(); + })); + + context.subscriptions.push(vscode.commands.registerCommand("mysql.pasteToActiveEditor", (node: (TableNode | DatabaseNode | ColumnNode)) => { + node.pasteToActiveEditor(); + })); } export function deactivate() { diff --git a/src/model/columnNode.ts b/src/model/columnNode.ts index 74822f3..4388948 100644 --- a/src/model/columnNode.ts +++ b/src/model/columnNode.ts @@ -25,4 +25,12 @@ export class ColumnNode implements INode { public async getChildren(): Promise { return []; } + + public copyToClipboard() { + Utility.copyToClipboard(this.column.COLUMN_NAME); + } + + public pasteToActiveEditor() { + Utility.pasteToActiveEditor(this.column.COLUMN_NAME); + } } diff --git a/src/model/databaseNode.ts b/src/model/databaseNode.ts index 94b5d1f..a31dd2b 100644 --- a/src/model/databaseNode.ts +++ b/src/model/databaseNode.ts @@ -58,4 +58,12 @@ export class DatabaseNode implements INode { certPath: this.certPath, }; } + + public copyToClipboard() { + Utility.copyToClipboard(this.database); + } + + public pasteToActiveEditor() { + Utility.pasteToActiveEditor(this.database); + } } diff --git a/src/model/tableNode.ts b/src/model/tableNode.ts index e543b2e..e709302 100644 --- a/src/model/tableNode.ts +++ b/src/model/tableNode.ts @@ -62,4 +62,12 @@ export class TableNode implements INode { Utility.runQuery(sql, connection); } + + public copyToClipboard() { + Utility.copyToClipboard(this.table); + } + + public pasteToActiveEditor() { + Utility.pasteToActiveEditor(this.table); + } }