From 8f7861deac4f187bf1d168b0a6c8bf32ae4591bd Mon Sep 17 00:00:00 2001 From: Alex Ma Date: Thu, 14 May 2020 14:06:58 -0700 Subject: [PATCH] Keybinding for Show SQL Pane (#9750) * WIP registerKeybind * testing command * Moved command to query.contribution * Moved command to editData.contribution * simplified command * more simplification * Working keybind for toggle query pane added. * removed space * added option to always show sql pane * removed keybind default and changed option --- .../editData/browser/editData.contribution.ts | 33 +++++++++++++++++++ .../editData/browser/editDataEditor.ts | 7 ++++ .../queryEditor/browser/queryEditorService.ts | 3 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/contrib/editData/browser/editData.contribution.ts b/src/sql/workbench/contrib/editData/browser/editData.contribution.ts index ed21405edb..b822938fa3 100644 --- a/src/sql/workbench/contrib/editData/browser/editData.contribution.ts +++ b/src/sql/workbench/contrib/editData/browser/editData.contribution.ts @@ -5,11 +5,16 @@ import { EditDataEditor } from 'sql/workbench/contrib/editData/browser/editDataEditor'; import { EditDataInput } from 'sql/workbench/browser/editData/editDataInput'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { EditDataResultsEditor } from 'sql/workbench/contrib/editData/browser/editDataResultsEditor'; import { EditDataResultsInput } from 'sql/workbench/browser/editData/editDataResultsInput'; import { EditorDescriptor, IEditorRegistry, Extensions } from 'vs/workbench/browser/editor'; +import { IConfigurationRegistry, Extensions as ConfigExtensions } from 'vs/platform/configuration/common/configurationRegistry'; import { Registry } from 'vs/platform/registry/common/platform'; +import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; +import * as editDataActions from 'sql/workbench/contrib/editData/browser/editDataActions'; +import * as nls from 'vs/nls'; // Editor const editDataEditorDescriptor = EditorDescriptor.create( @@ -18,6 +23,20 @@ const editDataEditorDescriptor = EditorDescriptor.create( 'EditData' ); +const configurationRegistry = Registry.as(ConfigExtensions.Configuration); +configurationRegistry.registerConfiguration({ + 'id': 'showEditDataSqlPaneOnStartup', + 'title': nls.localize('showEditDataSqlPaneOnStartup', 'Show Edit Data SQL pane on startup'), + 'type': 'object', + 'properties': { + 'editor.showEditDataSqlPaneOnStartup': { + 'type': 'boolean', + 'default': false, + 'description': nls.localize('showEditDataSqlPaneOnStartup', 'Show Edit Data SQL pane on startup') + } + } +}); + Registry.as(Extensions.Editors) .registerEditor(editDataEditorDescriptor, [new SyncDescriptor(EditDataInput)]); @@ -30,3 +49,17 @@ const editDataResultsEditorDescriptor = EditorDescriptor.create( Registry.as(Extensions.Editors) .registerEditor(editDataResultsEditorDescriptor, [new SyncDescriptor(EditDataResultsInput)]); + +// Keybinding for toggling the query pane +KeybindingsRegistry.registerCommandAndKeybindingRule({ + id: editDataActions.ShowQueryPaneAction.ID, + weight: KeybindingWeight.EditorContrib, + when: undefined, + primary: undefined, + handler: accessor => { + const activeEditDataEditor = accessor.get(IEditorService).activeEditorPane; + if (activeEditDataEditor instanceof EditDataEditor) { + activeEditDataEditor.runShowQueryPane(); + } + } +}); diff --git a/src/sql/workbench/contrib/editData/browser/editDataEditor.ts b/src/sql/workbench/contrib/editData/browser/editDataEditor.ts index 2f5659e6bd..659f970ffc 100644 --- a/src/sql/workbench/contrib/editData/browser/editDataEditor.ts +++ b/src/sql/workbench/contrib/editData/browser/editDataEditor.ts @@ -680,6 +680,13 @@ export class EditDataEditor extends BaseEditor { } } + /** + * Calls the run method of this editor's showQueryPaneAction + */ + public runShowQueryPane(): void { + this._showQueryPaneAction.run(); + } + /** * Calls the run method of this editor's RunQueryAction */ diff --git a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts index bb36f26c9c..39077b7214 100644 --- a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts @@ -62,7 +62,6 @@ export class QueryEditorService implements IQueryEditorService { const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, docUri.toString()); let queryInput = this._instantiationService.createInstance(UntitledQueryEditorInput, options.description, fileInput, queryResultsInput); - if (options.open) { await this._editorService.openEditor(queryInput, { pinned: true }); } @@ -88,6 +87,8 @@ export class QueryEditorService implements IQueryEditorService { // Create an EditDataInput for editing const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString()); let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput); + // Determine whether to show edit data upon opening. + editDataInput.queryPaneEnabled = this._configurationService.getValue('editor.showEditDataSqlPaneOnStartup'); if (sqlContent) { //Setting the value of the textEditorModel to sqlContent marks editor as dirty, editDataInput handles it. m.textEditorModel.setValue(sqlContent);