mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 09:35:37 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
import 'vs/css!vs/base/browser/ui/checkbox/checkbox';
|
||||
|
||||
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
import * as nls from 'vs/nls';
|
||||
import { ICheckboxStyles } from 'vs/base/browser/ui/checkbox/checkbox';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
|
||||
export interface ICheckboxSelectColumnOptions extends Slick.PluginOptions, ICheckboxStyles {
|
||||
columnId?: string;
|
||||
@@ -21,24 +21,23 @@ const defaultOptions: ICheckboxSelectColumnOptions = {
|
||||
columnId: '_checkbox_selector',
|
||||
cssClass: null,
|
||||
toolTip: nls.localize('selectDeselectAll', 'Select/Deselect All'),
|
||||
width: 30,
|
||||
inputActiveOptionBorder: Color.fromHex('#007ACC')
|
||||
width: 30
|
||||
};
|
||||
|
||||
const checkBoxTemplate = `<div style="display: flex; align-items: center; flex-direction: column">
|
||||
<div style="border-color: {0}" role="checkbox" aria-checked="{1}" aria-label="" class="custom-checkbox sql-checkbox {2}"></div>
|
||||
</div>`;
|
||||
const checkboxTemplate = `
|
||||
<div style="display: flex; align-items: center; flex-direction: column">
|
||||
<input type="checkbox" {0}>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
private _options: ICheckboxSelectColumnOptions;
|
||||
private _grid: Slick.Grid<T>;
|
||||
private _handler = new Slick.EventHandler();
|
||||
private _selectedRowsLookup = {};
|
||||
private _checkboxTemplate: string;
|
||||
|
||||
constructor(options?: Slick.PluginOptions) {
|
||||
constructor(options?: ICheckboxSelectColumnOptions) {
|
||||
this._options = mixin(options, defaultOptions, false);
|
||||
this.applyStyles();
|
||||
}
|
||||
|
||||
public init(grid: Slick.Grid<T>): void {
|
||||
@@ -74,11 +73,11 @@ export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
if (!this._options.title) {
|
||||
if (selectedRows.length && selectedRows.length === this._grid.getDataLength()) {
|
||||
this._grid.updateColumnHeader(this._options.columnId,
|
||||
strings.format(this._checkboxTemplate, 'true', 'checked'),
|
||||
strings.format(checkboxTemplate, 'checked'),
|
||||
this._options.toolTip);
|
||||
} else {
|
||||
this._grid.updateColumnHeader(this._options.columnId,
|
||||
strings.format(this._checkboxTemplate, 'true', 'unchecked'),
|
||||
strings.format(checkboxTemplate, ''),
|
||||
this._options.toolTip);
|
||||
}
|
||||
}
|
||||
@@ -94,12 +93,22 @@ export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
} else {
|
||||
let event = new StandardKeyboardEvent(e);
|
||||
if (event.equals(KeyCode.Enter)) {
|
||||
// clicking on a row select checkbox
|
||||
if (this._grid.getColumns()[args.cell].id === this._options.columnId) {
|
||||
this.toggleRowSelection(args.row);
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private handleClick(e: Event, args: Slick.OnClickEventArgs<T>): void {
|
||||
// clicking on a row select checkbox
|
||||
if (this._grid.getColumns()[args.cell].id === this._options.columnId && $(e.target).is('.custom-checkbox')) {
|
||||
if (this._grid.getColumns()[args.cell].id === this._options.columnId && $(e.target).is('input[type="checkbox"]')) {
|
||||
// if editing, try to commit
|
||||
if (this._grid.getEditorLock().isActive() && !this._grid.getEditorLock().commitCurrentEdit()) {
|
||||
e.preventDefault();
|
||||
@@ -122,7 +131,7 @@ export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
}
|
||||
|
||||
private handleHeaderClick(e: Event, args: Slick.OnHeaderClickEventArgs<T>): void {
|
||||
if (!this._options.title && args.column.id === this._options.columnId && $(e.target).is('.custom-checkbox')) {
|
||||
if (!this._options.title && args.column.id === this._options.columnId && $(e.target).is('input[type="checkbox"]')) {
|
||||
// if editing, try to commit
|
||||
if (this._grid.getEditorLock().isActive() && !this._grid.getEditorLock().commitCurrentEdit()) {
|
||||
e.preventDefault();
|
||||
@@ -130,19 +139,19 @@ export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($(e.target).is('.unchecked')) {
|
||||
if ($(e.target).is('input[checked]')) {
|
||||
let rows = [];
|
||||
for (let i = 0; i < this._grid.getDataLength(); i++) {
|
||||
rows.push(i);
|
||||
}
|
||||
this._grid.setSelectedRows(rows);
|
||||
this._grid.updateColumnHeader(this._options.columnId,
|
||||
strings.format(this._checkboxTemplate, 'true', 'checked'),
|
||||
strings.format(checkboxTemplate, 'checked'),
|
||||
this._options.toolTip);
|
||||
} else {
|
||||
this._grid.setSelectedRows([]);
|
||||
this._grid.updateColumnHeader(this._options.columnId,
|
||||
strings.format(this._checkboxTemplate, 'true', 'unchecked'), this._options.toolTip);
|
||||
strings.format(checkboxTemplate, ''), this._options.toolTip);
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
@@ -152,7 +161,7 @@ export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
public getColumnDefinition(): Slick.Column<T> {
|
||||
return {
|
||||
id: this._options.columnId,
|
||||
name: this._options.title || strings.format(this._checkboxTemplate, 'true', 'unchecked'),
|
||||
name: this._options.title || strings.format(checkboxTemplate, ''),
|
||||
toolTip: this._options.toolTip,
|
||||
field: 'sel',
|
||||
width: this._options.width,
|
||||
@@ -166,24 +175,9 @@ export class CheckboxSelectColumn<T> implements Slick.Plugin<T> {
|
||||
private checkboxSelectionFormatter(row, cell, value, columnDef: Slick.Column<T>, dataContext): string {
|
||||
if (dataContext) {
|
||||
return this._selectedRowsLookup[row]
|
||||
? strings.format(this._checkboxTemplate, 'true', 'checked')
|
||||
: strings.format(this._checkboxTemplate, 'true', 'unchecked');
|
||||
? strings.format(checkboxTemplate, 'checked')
|
||||
: strings.format(checkboxTemplate, '');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public style(styles: ICheckboxStyles): void {
|
||||
if (styles.inputActiveOptionBorder) {
|
||||
this._options.inputActiveOptionBorder = styles.inputActiveOptionBorder;
|
||||
}
|
||||
this.applyStyles();
|
||||
}
|
||||
|
||||
protected applyStyles(): void {
|
||||
this._checkboxTemplate = strings.format(checkBoxTemplate, this._options.inputActiveOptionBorder.toString(), '{0}', '{1}');
|
||||
if (this._grid) {
|
||||
this._grid.invalidateAllRows();
|
||||
this._grid.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,10 @@ export class Table<T extends Slick.SlickData> implements IThemable {
|
||||
this._grid.setColumns(columns);
|
||||
}
|
||||
|
||||
public get grid(): Slick.Grid<T> {
|
||||
return this._grid;
|
||||
}
|
||||
|
||||
setData(data: Array<T>);
|
||||
setData(data: TableDataView<T>);
|
||||
setData(data: Array<T> | TableDataView<T>) {
|
||||
@@ -204,11 +208,11 @@ export class Table<T extends Slick.SlickData> implements IThemable {
|
||||
}
|
||||
|
||||
if (styles.listFocusBackground) {
|
||||
content.push(`.monaco-table .${this._idPrefix} .slick-row .focused { background-color: ${styles.listFocusBackground}; }`);
|
||||
content.push(`.monaco-table .${this._idPrefix} .slick-row .active { background-color: ${styles.listFocusBackground}; }`);
|
||||
}
|
||||
|
||||
if (styles.listFocusForeground) {
|
||||
content.push(`.monaco-table .${this._idPrefix} .slick-row .focused { color: ${styles.listFocusForeground}; }`);
|
||||
content.push(`.monaco-table .${this._idPrefix} .slick-row .active { color: ${styles.listFocusForeground}; }`);
|
||||
}
|
||||
|
||||
if (styles.listActiveSelectionBackground) {
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
|
||||
import { Table } from './table';
|
||||
import { TableDataView } from './tableDataView';
|
||||
|
||||
import { View, Orientation, AbstractCollapsibleView, HeaderView, IViewOptions, ICollapsibleViewOptions } from 'vs/base/browser/ui/splitview/splitview';
|
||||
import { View, Orientation, AbstractCollapsibleView, HeaderView, ICollapsibleViewOptions, IViewOptions, CollapsibleState } from 'sql/base/browser/ui/splitview/splitview';
|
||||
import { $ } from 'vs/base/browser/builder';
|
||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import * as lifecycle from 'vs/base/common/lifecycle';
|
||||
|
||||
export class TableBasicView<T> extends View {
|
||||
private _table: Table<T>;
|
||||
@@ -84,6 +87,7 @@ export class TableHeaderView<T> extends HeaderView {
|
||||
export class TableCollapsibleView<T> extends AbstractCollapsibleView {
|
||||
private _table: Table<T>;
|
||||
private _container: HTMLElement;
|
||||
private _headerTabListener: lifecycle.IDisposable;
|
||||
|
||||
constructor(
|
||||
private _viewTitle: string,
|
||||
@@ -98,6 +102,29 @@ export class TableCollapsibleView<T> extends AbstractCollapsibleView {
|
||||
this._table = new Table<T>(this._container, data, columns, tableOpts);
|
||||
}
|
||||
|
||||
public render(container: HTMLElement, orientation: Orientation): void {
|
||||
super.render(container, orientation);
|
||||
this._headerTabListener = DOM.addDisposableListener(this.header, DOM.EventType.KEY_DOWN, (e) => {
|
||||
let event = new StandardKeyboardEvent(e);
|
||||
if (event.equals(KeyCode.Tab) && this.state === CollapsibleState.EXPANDED) {
|
||||
let element = this._table.getSelectedRows();
|
||||
if (!element || element.length === 0) {
|
||||
this._table.setSelectedRows([0]);
|
||||
this._table.setActiveCell(0, 1);
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this._headerTabListener) {
|
||||
this._headerTabListener.dispose();
|
||||
this._headerTabListener = null;
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public addContainerClass(className: string) {
|
||||
this._container.classList.add(className);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user