mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 10:38:31 -05:00
This reverts commit 5d44b6a6a7.
This commit is contained in:
@@ -18,7 +18,7 @@ import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { asArray } from 'vs/base/common/arrays';
|
||||
|
||||
export interface IActionViewItem {
|
||||
export interface IActionItem {
|
||||
actionRunner: IActionRunner;
|
||||
setActionContext(context: any): void;
|
||||
render(element: HTMLElement): void;
|
||||
@@ -28,12 +28,12 @@ export interface IActionViewItem {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export interface IBaseActionViewItemOptions {
|
||||
export interface IBaseActionItemOptions {
|
||||
draggable?: boolean;
|
||||
isMenu?: boolean;
|
||||
}
|
||||
|
||||
export class BaseActionViewItem extends Disposable implements IActionViewItem {
|
||||
export class BaseActionItem extends Disposable implements IActionItem {
|
||||
|
||||
element?: HTMLElement;
|
||||
_context: any;
|
||||
@@ -41,7 +41,7 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem {
|
||||
|
||||
private _actionRunner: IActionRunner;
|
||||
|
||||
constructor(context: any, action: IAction, protected options?: IBaseActionViewItemOptions) {
|
||||
constructor(context: any, action: IAction, protected options?: IBaseActionItemOptions) {
|
||||
super();
|
||||
|
||||
this._context = context || this;
|
||||
@@ -226,20 +226,20 @@ export class Separator extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export interface IActionViewItemOptions extends IBaseActionViewItemOptions {
|
||||
export interface IActionItemOptions extends IBaseActionItemOptions {
|
||||
icon?: boolean;
|
||||
label?: boolean;
|
||||
keybinding?: string | null;
|
||||
}
|
||||
|
||||
export class ActionViewItem extends BaseActionViewItem {
|
||||
export class ActionItem extends BaseActionItem {
|
||||
|
||||
protected label: HTMLElement;
|
||||
protected options: IActionViewItemOptions;
|
||||
protected options: IActionItemOptions;
|
||||
|
||||
private cssClass?: string;
|
||||
|
||||
constructor(context: any, action: IAction, options: IActionViewItemOptions = {}) {
|
||||
constructor(context: any, action: IAction, options: IActionItemOptions = {}) {
|
||||
super(context, action, options);
|
||||
|
||||
this.options = options;
|
||||
@@ -363,14 +363,14 @@ export interface ActionTrigger {
|
||||
keyDown: boolean;
|
||||
}
|
||||
|
||||
export interface IActionViewItemProvider {
|
||||
(action: IAction): IActionViewItem | undefined;
|
||||
export interface IActionItemProvider {
|
||||
(action: IAction): IActionItem | undefined;
|
||||
}
|
||||
|
||||
export interface IActionBarOptions {
|
||||
orientation?: ActionsOrientation;
|
||||
context?: any;
|
||||
actionViewItemProvider?: IActionViewItemProvider;
|
||||
actionItemProvider?: IActionItemProvider;
|
||||
actionRunner?: IActionRunner;
|
||||
ariaLabel?: string;
|
||||
animated?: boolean;
|
||||
@@ -386,7 +386,7 @@ const defaultOptions: IActionBarOptions = {
|
||||
}
|
||||
};
|
||||
|
||||
export interface IActionOptions extends IActionViewItemOptions {
|
||||
export interface IActionOptions extends IActionItemOptions {
|
||||
index?: number;
|
||||
}
|
||||
|
||||
@@ -397,8 +397,8 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
private _actionRunner: IActionRunner;
|
||||
private _context: any;
|
||||
|
||||
// View Items
|
||||
viewItems: IActionViewItem[];
|
||||
// Items
|
||||
items: IActionItem[];
|
||||
protected focusedItem?: number;
|
||||
private focusTracker: DOM.IFocusTracker;
|
||||
|
||||
@@ -438,7 +438,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
this._register(this._actionRunner.onDidRun(e => this._onDidRun.fire(e)));
|
||||
this._register(this._actionRunner.onDidBeforeRun(e => this._onDidBeforeRun.fire(e)));
|
||||
|
||||
this.viewItems = [];
|
||||
this.items = [];
|
||||
this.focusedItem = undefined;
|
||||
|
||||
this.domNode = document.createElement('div');
|
||||
@@ -575,7 +575,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
|
||||
set context(context: any) {
|
||||
this._context = context;
|
||||
this.viewItems.forEach(i => i.setActionContext(context));
|
||||
this.items.forEach(i => i.setActionContext(context));
|
||||
}
|
||||
|
||||
get actionRunner(): IActionRunner {
|
||||
@@ -585,7 +585,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
set actionRunner(actionRunner: IActionRunner) {
|
||||
if (actionRunner) {
|
||||
this._actionRunner = actionRunner;
|
||||
this.viewItems.forEach(item => item.actionRunner = actionRunner);
|
||||
this.items.forEach(item => item.actionRunner = actionRunner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,36 +599,36 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
let index = types.isNumber(options.index) ? options.index : null;
|
||||
|
||||
actions.forEach((action: IAction) => {
|
||||
const actionViewItemElement = document.createElement('li');
|
||||
actionViewItemElement.className = 'action-item';
|
||||
actionViewItemElement.setAttribute('role', 'presentation');
|
||||
const actionItemElement = document.createElement('li');
|
||||
actionItemElement.className = 'action-item';
|
||||
actionItemElement.setAttribute('role', 'presentation');
|
||||
|
||||
// Prevent native context menu on actions
|
||||
this._register(DOM.addDisposableListener(actionViewItemElement, DOM.EventType.CONTEXT_MENU, (e: DOM.EventLike) => {
|
||||
this._register(DOM.addDisposableListener(actionItemElement, DOM.EventType.CONTEXT_MENU, (e: DOM.EventLike) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}));
|
||||
|
||||
let item: IActionViewItem | undefined;
|
||||
let item: IActionItem | undefined;
|
||||
|
||||
if (this.options.actionViewItemProvider) {
|
||||
item = this.options.actionViewItemProvider(action);
|
||||
if (this.options.actionItemProvider) {
|
||||
item = this.options.actionItemProvider(action);
|
||||
}
|
||||
|
||||
if (!item) {
|
||||
item = new ActionViewItem(this.context, action, options);
|
||||
item = new ActionItem(this.context, action, options);
|
||||
}
|
||||
|
||||
item.actionRunner = this._actionRunner;
|
||||
item.setActionContext(this.context);
|
||||
item.render(actionViewItemElement);
|
||||
item.render(actionItemElement);
|
||||
|
||||
if (index === null || index < 0 || index >= this.actionsList.children.length) {
|
||||
this.actionsList.appendChild(actionViewItemElement);
|
||||
this.viewItems.push(item);
|
||||
this.actionsList.appendChild(actionItemElement);
|
||||
this.items.push(item);
|
||||
} else {
|
||||
this.actionsList.insertBefore(actionViewItemElement, this.actionsList.children[index]);
|
||||
this.viewItems.splice(index, 0, item);
|
||||
this.actionsList.insertBefore(actionItemElement, this.actionsList.children[index]);
|
||||
this.items.splice(index, 0, item);
|
||||
index++;
|
||||
}
|
||||
});
|
||||
@@ -657,23 +657,23 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
}
|
||||
|
||||
pull(index: number): void {
|
||||
if (index >= 0 && index < this.viewItems.length) {
|
||||
if (index >= 0 && index < this.items.length) {
|
||||
this.actionsList.removeChild(this.actionsList.childNodes[index]);
|
||||
dispose(this.viewItems.splice(index, 1));
|
||||
dispose(this.items.splice(index, 1));
|
||||
}
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.viewItems = dispose(this.viewItems);
|
||||
this.items = dispose(this.items);
|
||||
DOM.clearNode(this.actionsList);
|
||||
}
|
||||
|
||||
length(): number {
|
||||
return this.viewItems.length;
|
||||
return this.items.length;
|
||||
}
|
||||
|
||||
isEmpty(): boolean {
|
||||
return this.viewItems.length === 0;
|
||||
return this.items.length === 0;
|
||||
}
|
||||
|
||||
focus(index?: number): void;
|
||||
@@ -691,7 +691,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
|
||||
if (selectFirst && typeof this.focusedItem === 'undefined') {
|
||||
// Focus the first enabled item
|
||||
this.focusedItem = this.viewItems.length - 1;
|
||||
this.focusedItem = this.items.length - 1;
|
||||
this.focusNext();
|
||||
} else {
|
||||
if (index !== undefined) {
|
||||
@@ -704,15 +704,15 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
|
||||
protected focusNext(): void {
|
||||
if (typeof this.focusedItem === 'undefined') {
|
||||
this.focusedItem = this.viewItems.length - 1;
|
||||
this.focusedItem = this.items.length - 1;
|
||||
}
|
||||
|
||||
const startIndex = this.focusedItem;
|
||||
let item: IActionViewItem;
|
||||
let item: IActionItem;
|
||||
|
||||
do {
|
||||
this.focusedItem = (this.focusedItem + 1) % this.viewItems.length;
|
||||
item = this.viewItems[this.focusedItem];
|
||||
this.focusedItem = (this.focusedItem + 1) % this.items.length;
|
||||
item = this.items[this.focusedItem];
|
||||
} while (this.focusedItem !== startIndex && !item.isEnabled());
|
||||
|
||||
if (this.focusedItem === startIndex && !item.isEnabled()) {
|
||||
@@ -728,16 +728,16 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
}
|
||||
|
||||
const startIndex = this.focusedItem;
|
||||
let item: IActionViewItem;
|
||||
let item: IActionItem;
|
||||
|
||||
do {
|
||||
this.focusedItem = this.focusedItem - 1;
|
||||
|
||||
if (this.focusedItem < 0) {
|
||||
this.focusedItem = this.viewItems.length - 1;
|
||||
this.focusedItem = this.items.length - 1;
|
||||
}
|
||||
|
||||
item = this.viewItems[this.focusedItem];
|
||||
item = this.items[this.focusedItem];
|
||||
} while (this.focusedItem !== startIndex && !item.isEnabled());
|
||||
|
||||
if (this.focusedItem === startIndex && !item.isEnabled()) {
|
||||
@@ -752,21 +752,21 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
this.actionsList.focus();
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.viewItems.length; i++) {
|
||||
const item = this.viewItems[i];
|
||||
const actionViewItem = item;
|
||||
for (let i = 0; i < this.items.length; i++) {
|
||||
const item = this.items[i];
|
||||
const actionItem = item;
|
||||
|
||||
if (i === this.focusedItem) {
|
||||
if (types.isFunction(actionViewItem.isEnabled)) {
|
||||
if (actionViewItem.isEnabled() && types.isFunction(actionViewItem.focus)) {
|
||||
actionViewItem.focus(fromRight);
|
||||
if (types.isFunction(actionItem.isEnabled)) {
|
||||
if (actionItem.isEnabled() && types.isFunction(actionItem.focus)) {
|
||||
actionItem.focus(fromRight);
|
||||
} else {
|
||||
this.actionsList.focus();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (types.isFunction(actionViewItem.blur)) {
|
||||
actionViewItem.blur();
|
||||
if (types.isFunction(actionItem.blur)) {
|
||||
actionItem.blur();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -778,16 +778,16 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
}
|
||||
|
||||
// trigger action
|
||||
const actionViewItem = this.viewItems[this.focusedItem];
|
||||
if (actionViewItem instanceof BaseActionViewItem) {
|
||||
const context = (actionViewItem._context === null || actionViewItem._context === undefined) ? event : actionViewItem._context;
|
||||
this.run(actionViewItem._action, context);
|
||||
const actionItem = this.items[this.focusedItem];
|
||||
if (actionItem instanceof BaseActionItem) {
|
||||
const context = (actionItem._context === null || actionItem._context === undefined) ? event : actionItem._context;
|
||||
this.run(actionItem._action, context);
|
||||
}
|
||||
}
|
||||
|
||||
private cancel(): void {
|
||||
if (document.activeElement instanceof HTMLElement) {
|
||||
document.activeElement.blur(); // remove focus from focused action
|
||||
(<HTMLElement>document.activeElement).blur(); // remove focus from focused action
|
||||
}
|
||||
|
||||
this._onDidCancel.fire();
|
||||
@@ -798,8 +798,8 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
dispose(this.viewItems);
|
||||
this.viewItems = [];
|
||||
dispose(this.items);
|
||||
this.items = [];
|
||||
|
||||
DOM.removeNode(this.getContainer());
|
||||
|
||||
@@ -807,7 +807,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
||||
}
|
||||
}
|
||||
|
||||
export class SelectActionViewItem extends BaseActionViewItem {
|
||||
export class SelectActionItem extends BaseActionItem {
|
||||
protected selectBox: SelectBox;
|
||||
|
||||
constructor(ctx: any, action: IAction, options: ISelectOptionItem[], selected: number, contextViewProvider: IContextViewProvider, selectBoxOptions?: ISelectBoxOptions) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Color } from 'vs/base/common/color';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import * as objects from 'vs/base/common/objects';
|
||||
import { BaseActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
|
||||
export interface ICheckboxOpts extends ICheckboxStyles {
|
||||
@@ -28,7 +28,7 @@ const defaultOpts = {
|
||||
inputActiveOptionBorder: Color.fromHex('#007ACC')
|
||||
};
|
||||
|
||||
export class CheckboxActionViewItem extends BaseActionViewItem {
|
||||
export class CheckboxActionItem extends BaseActionItem {
|
||||
|
||||
private checkbox: Checkbox;
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
@@ -132,13 +132,13 @@ export class ContextView extends Disposable {
|
||||
|
||||
ContextView.BUBBLE_UP_EVENTS.forEach(event => {
|
||||
toDisposeOnSetContainer.push(DOM.addStandardDisposableListener(this.container!, event, (e: Event) => {
|
||||
this.onDOMEvent(e, false);
|
||||
this.onDOMEvent(e, <HTMLElement>document.activeElement, false);
|
||||
}));
|
||||
});
|
||||
|
||||
ContextView.BUBBLE_DOWN_EVENTS.forEach(event => {
|
||||
toDisposeOnSetContainer.push(DOM.addStandardDisposableListener(this.container!, event, (e: Event) => {
|
||||
this.onDOMEvent(e, true);
|
||||
this.onDOMEvent(e, <HTMLElement>document.activeElement, true);
|
||||
}, true));
|
||||
});
|
||||
|
||||
@@ -213,11 +213,13 @@ export class ContextView extends Disposable {
|
||||
height: elementPosition.height
|
||||
};
|
||||
} else {
|
||||
let realAnchor = <IAnchor>anchor;
|
||||
|
||||
around = {
|
||||
top: anchor.y,
|
||||
left: anchor.x,
|
||||
width: anchor.width || 1,
|
||||
height: anchor.height || 2
|
||||
top: realAnchor.y,
|
||||
left: realAnchor.x,
|
||||
width: realAnchor.width || 1,
|
||||
height: realAnchor.height || 2
|
||||
};
|
||||
}
|
||||
|
||||
@@ -276,7 +278,7 @@ export class ContextView extends Disposable {
|
||||
return !!this.delegate;
|
||||
}
|
||||
|
||||
private onDOMEvent(e: Event, onCapture: boolean): void {
|
||||
private onDOMEvent(e: Event, element: HTMLElement, onCapture: boolean): void {
|
||||
if (this.delegate) {
|
||||
if (this.delegate.onDOMEvent) {
|
||||
this.delegate.onDOMEvent(e, <HTMLElement>document.activeElement);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import 'vs/css!./dropdown';
|
||||
import { Gesture, EventType as GestureEventType } from 'vs/base/browser/touch';
|
||||
import { ActionRunner, IAction, IActionRunner } from 'vs/base/common/actions';
|
||||
import { BaseActionViewItem, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { BaseActionItem, IActionItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IContextViewProvider, IAnchor, AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
|
||||
import { IMenuOptions } from 'vs/base/browser/ui/menu/menu';
|
||||
@@ -247,7 +247,7 @@ export class DropdownMenu extends BaseDropdown {
|
||||
getAnchor: () => this.element,
|
||||
getActions: () => this.actions,
|
||||
getActionsContext: () => this.menuOptions ? this.menuOptions.context : null,
|
||||
getActionViewItem: action => this.menuOptions && this.menuOptions.actionViewItemProvider ? this.menuOptions.actionViewItemProvider(action) : undefined,
|
||||
getActionItem: action => this.menuOptions && this.menuOptions.actionItemProvider ? this.menuOptions.actionItemProvider(action) : undefined,
|
||||
getKeyBinding: action => this.menuOptions && this.menuOptions.getKeyBinding ? this.menuOptions.getKeyBinding(action) : undefined,
|
||||
getMenuClassName: () => this.menuClassName,
|
||||
onHide: () => this.onHide(),
|
||||
@@ -266,23 +266,23 @@ export class DropdownMenu extends BaseDropdown {
|
||||
}
|
||||
}
|
||||
|
||||
export class DropdownMenuActionViewItem extends BaseActionViewItem {
|
||||
export class DropdownMenuActionItem extends BaseActionItem {
|
||||
private menuActionsOrProvider: any;
|
||||
private dropdownMenu: DropdownMenu;
|
||||
private contextMenuProvider: IContextMenuProvider;
|
||||
private actionViewItemProvider?: IActionViewItemProvider;
|
||||
private actionItemProvider?: IActionItemProvider;
|
||||
private keybindings?: (action: IAction) => ResolvedKeybinding | undefined;
|
||||
private clazz: string | undefined;
|
||||
private anchorAlignmentProvider: (() => AnchorAlignment) | undefined;
|
||||
|
||||
constructor(action: IAction, menuActions: IAction[], contextMenuProvider: IContextMenuProvider, actionViewItemProvider: IActionViewItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding | undefined) | undefined, clazz: string | undefined, anchorAlignmentProvider?: () => AnchorAlignment);
|
||||
constructor(action: IAction, actionProvider: IActionProvider, contextMenuProvider: IContextMenuProvider, actionViewItemProvider: IActionViewItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding) | undefined, clazz: string | undefined, anchorAlignmentProvider?: () => AnchorAlignment);
|
||||
constructor(action: IAction, menuActionsOrProvider: any, contextMenuProvider: IContextMenuProvider, actionViewItemProvider: IActionViewItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding | undefined) | undefined, clazz: string | undefined, anchorAlignmentProvider?: () => AnchorAlignment) {
|
||||
constructor(action: IAction, menuActions: IAction[], contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding | undefined) | undefined, clazz: string | undefined, anchorAlignmentProvider?: () => AnchorAlignment);
|
||||
constructor(action: IAction, actionProvider: IActionProvider, contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding) | undefined, clazz: string | undefined, anchorAlignmentProvider?: () => AnchorAlignment);
|
||||
constructor(action: IAction, menuActionsOrProvider: any, contextMenuProvider: IContextMenuProvider, actionItemProvider: IActionItemProvider | undefined, actionRunner: IActionRunner, keybindings: ((action: IAction) => ResolvedKeybinding | undefined) | undefined, clazz: string | undefined, anchorAlignmentProvider?: () => AnchorAlignment) {
|
||||
super(null, action);
|
||||
|
||||
this.menuActionsOrProvider = menuActionsOrProvider;
|
||||
this.contextMenuProvider = contextMenuProvider;
|
||||
this.actionViewItemProvider = actionViewItemProvider;
|
||||
this.actionItemProvider = actionItemProvider;
|
||||
this.actionRunner = actionRunner;
|
||||
this.keybindings = keybindings;
|
||||
this.clazz = clazz;
|
||||
@@ -319,7 +319,7 @@ export class DropdownMenuActionViewItem extends BaseActionViewItem {
|
||||
this.dropdownMenu = this._register(new DropdownMenu(container, options));
|
||||
|
||||
this.dropdownMenu.menuOptions = {
|
||||
actionViewItemProvider: this.actionViewItemProvider,
|
||||
actionItemProvider: this.actionItemProvider,
|
||||
actionRunner: this.actionRunner,
|
||||
getKeyBinding: this.keybindings,
|
||||
context: this._context
|
||||
|
||||
@@ -161,7 +161,7 @@ export class InputBox extends Widget {
|
||||
let tagName = this.options.flexibleHeight ? 'textarea' : 'input';
|
||||
|
||||
let wrapper = dom.append(this.element, $('.wrapper'));
|
||||
this.input = dom.append(wrapper, $(tagName + '.input'));
|
||||
this.input = <HTMLInputElement>dom.append(wrapper, $(tagName + '.input'));
|
||||
this.input.setAttribute('autocorrect', 'off');
|
||||
this.input.setAttribute('autocapitalize', 'off');
|
||||
this.input.setAttribute('spellcheck', 'false');
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'vs/css!./menu';
|
||||
import * as nls from 'vs/nls';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { IActionRunner, IAction, Action } from 'vs/base/common/actions';
|
||||
import { ActionBar, IActionViewItemProvider, ActionsOrientation, Separator, ActionViewItem, IActionViewItemOptions, BaseActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { ActionBar, IActionItemProvider, ActionsOrientation, Separator, ActionItem, IActionItemOptions, BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { ResolvedKeybinding, KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { addClass, EventType, EventHelper, EventLike, removeTabIndexAndUpdateFocus, isAncestor, hasClass, addDisposableListener, removeClass, append, $, addClasses, removeClasses } from 'vs/base/browser/dom';
|
||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
@@ -39,7 +39,7 @@ export const MENU_ESCAPED_MNEMONIC_REGEX: RegExp = createMenuEscapedMnemonicRegE
|
||||
|
||||
export interface IMenuOptions {
|
||||
context?: any;
|
||||
actionViewItemProvider?: IActionViewItemProvider;
|
||||
actionItemProvider?: IActionItemProvider;
|
||||
actionRunner?: IActionRunner;
|
||||
getKeyBinding?: (action: IAction) => ResolvedKeybinding | undefined;
|
||||
ariaLabel?: string;
|
||||
@@ -70,7 +70,7 @@ interface ISubMenuData {
|
||||
}
|
||||
|
||||
export class Menu extends ActionBar {
|
||||
private mnemonics: Map<string, Array<BaseMenuActionViewItem>>;
|
||||
private mnemonics: Map<string, Array<MenuActionItem>>;
|
||||
private menuDisposables: IDisposable[];
|
||||
private scrollableElement: DomScrollableElement;
|
||||
private menuElement: HTMLElement;
|
||||
@@ -88,7 +88,7 @@ export class Menu extends ActionBar {
|
||||
|
||||
super(menuElement, {
|
||||
orientation: ActionsOrientation.VERTICAL,
|
||||
actionViewItemProvider: action => this.doGetActionViewItem(action, options, parentData),
|
||||
actionItemProvider: action => this.doGetActionItem(action, options, parentData),
|
||||
context: options.context,
|
||||
actionRunner: options.actionRunner,
|
||||
ariaLabel: options.ariaLabel,
|
||||
@@ -113,7 +113,7 @@ export class Menu extends ActionBar {
|
||||
const actions = this.mnemonics.get(key)!;
|
||||
|
||||
if (actions.length === 1) {
|
||||
if (actions[0] instanceof SubmenuMenuActionViewItem) {
|
||||
if (actions[0] instanceof SubmenuActionItem) {
|
||||
this.focusItemByElement(actions[0].container);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ export class Menu extends ActionBar {
|
||||
const event = new StandardKeyboardEvent(e);
|
||||
|
||||
if (event.equals(KeyCode.Home) || event.equals(KeyCode.PageUp)) {
|
||||
this.focusedItem = this.viewItems.length - 1;
|
||||
this.focusedItem = this.items.length - 1;
|
||||
this.focusNext();
|
||||
EventHelper.stop(e, true);
|
||||
} else if (event.equals(KeyCode.End) || event.equals(KeyCode.PageDown)) {
|
||||
@@ -189,7 +189,7 @@ export class Menu extends ActionBar {
|
||||
parent: this
|
||||
};
|
||||
|
||||
this.mnemonics = new Map<string, Array<BaseMenuActionViewItem>>();
|
||||
this.mnemonics = new Map<string, Array<MenuActionItem>>();
|
||||
|
||||
this.push(actions, { icon: true, label: true, isMenu: true });
|
||||
|
||||
@@ -223,7 +223,7 @@ export class Menu extends ActionBar {
|
||||
container.appendChild(this.scrollableElement.getDomNode());
|
||||
this.scrollableElement.scanDomNode();
|
||||
|
||||
this.viewItems.filter(item => !(item instanceof MenuSeparatorActionViewItem)).forEach((item: BaseMenuActionViewItem, index: number, array: any[]) => {
|
||||
this.items.filter(item => !(item instanceof MenuSeparatorActionItem)).forEach((item: MenuActionItem, index: number, array: any[]) => {
|
||||
item.updatePositionInSet(index + 1, array.length);
|
||||
});
|
||||
}
|
||||
@@ -241,9 +241,9 @@ export class Menu extends ActionBar {
|
||||
this.domNode.style.backgroundColor = bgColor;
|
||||
container.style.boxShadow = shadow;
|
||||
|
||||
if (this.viewItems) {
|
||||
this.viewItems.forEach(item => {
|
||||
if (item instanceof BaseMenuActionViewItem || item instanceof MenuSeparatorActionViewItem) {
|
||||
if (this.items) {
|
||||
this.items.forEach(item => {
|
||||
if (item instanceof MenuActionItem || item instanceof MenuSeparatorActionItem) {
|
||||
item.style(style);
|
||||
}
|
||||
});
|
||||
@@ -263,12 +263,12 @@ export class Menu extends ActionBar {
|
||||
}
|
||||
|
||||
trigger(index: number): void {
|
||||
if (index <= this.viewItems.length && index >= 0) {
|
||||
const item = this.viewItems[index];
|
||||
if (item instanceof SubmenuMenuActionViewItem) {
|
||||
if (index <= this.items.length && index >= 0) {
|
||||
const item = this.items[index];
|
||||
if (item instanceof SubmenuActionItem) {
|
||||
super.focus(index);
|
||||
item.open(true);
|
||||
} else if (item instanceof BaseMenuActionViewItem) {
|
||||
} else if (item instanceof MenuActionItem) {
|
||||
super.run(item._action, item._context);
|
||||
} else {
|
||||
return;
|
||||
@@ -295,27 +295,27 @@ export class Menu extends ActionBar {
|
||||
}
|
||||
}
|
||||
|
||||
private doGetActionViewItem(action: IAction, options: IMenuOptions, parentData: ISubMenuData): BaseActionViewItem {
|
||||
private doGetActionItem(action: IAction, options: IMenuOptions, parentData: ISubMenuData): BaseActionItem {
|
||||
if (action instanceof Separator) {
|
||||
return new MenuSeparatorActionViewItem(options.context, action, { icon: true });
|
||||
return new MenuSeparatorActionItem(options.context, action, { icon: true });
|
||||
} else if (action instanceof SubmenuAction) {
|
||||
const menuActionViewItem = new SubmenuMenuActionViewItem(action, action.entries, parentData, options);
|
||||
const menuActionItem = new SubmenuActionItem(action, action.entries, parentData, options);
|
||||
|
||||
if (options.enableMnemonics) {
|
||||
const mnemonic = menuActionViewItem.getMnemonic();
|
||||
if (mnemonic && menuActionViewItem.isEnabled()) {
|
||||
let actionViewItems: BaseMenuActionViewItem[] = [];
|
||||
const mnemonic = menuActionItem.getMnemonic();
|
||||
if (mnemonic && menuActionItem.isEnabled()) {
|
||||
let actionItems: MenuActionItem[] = [];
|
||||
if (this.mnemonics.has(mnemonic)) {
|
||||
actionViewItems = this.mnemonics.get(mnemonic)!;
|
||||
actionItems = this.mnemonics.get(mnemonic)!;
|
||||
}
|
||||
|
||||
actionViewItems.push(menuActionViewItem);
|
||||
actionItems.push(menuActionItem);
|
||||
|
||||
this.mnemonics.set(mnemonic, actionViewItems);
|
||||
this.mnemonics.set(mnemonic, actionItems);
|
||||
}
|
||||
}
|
||||
|
||||
return menuActionViewItem;
|
||||
return menuActionItem;
|
||||
} else {
|
||||
const menuItemOptions: IMenuItemOptions = { enableMnemonics: options.enableMnemonics };
|
||||
if (options.getKeyBinding) {
|
||||
@@ -329,32 +329,32 @@ export class Menu extends ActionBar {
|
||||
}
|
||||
}
|
||||
|
||||
const menuActionViewItem = new BaseMenuActionViewItem(options.context, action, menuItemOptions);
|
||||
const menuActionItem = new MenuActionItem(options.context, action, menuItemOptions);
|
||||
|
||||
if (options.enableMnemonics) {
|
||||
const mnemonic = menuActionViewItem.getMnemonic();
|
||||
if (mnemonic && menuActionViewItem.isEnabled()) {
|
||||
let actionViewItems: BaseMenuActionViewItem[] = [];
|
||||
const mnemonic = menuActionItem.getMnemonic();
|
||||
if (mnemonic && menuActionItem.isEnabled()) {
|
||||
let actionItems: MenuActionItem[] = [];
|
||||
if (this.mnemonics.has(mnemonic)) {
|
||||
actionViewItems = this.mnemonics.get(mnemonic)!;
|
||||
actionItems = this.mnemonics.get(mnemonic)!;
|
||||
}
|
||||
|
||||
actionViewItems.push(menuActionViewItem);
|
||||
actionItems.push(menuActionItem);
|
||||
|
||||
this.mnemonics.set(mnemonic, actionViewItems);
|
||||
this.mnemonics.set(mnemonic, actionItems);
|
||||
}
|
||||
}
|
||||
|
||||
return menuActionViewItem;
|
||||
return menuActionItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface IMenuItemOptions extends IActionViewItemOptions {
|
||||
interface IMenuItemOptions extends IActionItemOptions {
|
||||
enableMnemonics?: boolean;
|
||||
}
|
||||
|
||||
class BaseMenuActionViewItem extends BaseActionViewItem {
|
||||
class MenuActionItem extends BaseActionItem {
|
||||
|
||||
public container: HTMLElement;
|
||||
|
||||
@@ -562,7 +562,7 @@ class BaseMenuActionViewItem extends BaseActionViewItem {
|
||||
}
|
||||
}
|
||||
|
||||
class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
|
||||
class SubmenuActionItem extends MenuActionItem {
|
||||
private mysubmenu: Menu | null;
|
||||
private submenuContainer: HTMLElement | undefined;
|
||||
private submenuIndicator: HTMLElement;
|
||||
@@ -778,7 +778,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
|
||||
}
|
||||
}
|
||||
|
||||
class MenuSeparatorActionViewItem extends ActionViewItem {
|
||||
class MenuSeparatorActionItem extends ActionItem {
|
||||
style(style: IMenuStyles): void {
|
||||
this.label.style.borderBottomColor = style.separatorColor ? `${style.separatorColor}` : null;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ class SelectListRenderer implements IListRenderer<ISelectOptionItem, ISelectList
|
||||
|
||||
constructor() { }
|
||||
|
||||
renderTemplate(container: HTMLElement): ISelectListTemplateData {
|
||||
const data: ISelectListTemplateData = Object.create(null);
|
||||
renderTemplate(container: HTMLElement): any {
|
||||
const data = <ISelectListTemplateData>Object.create(null);
|
||||
data.disposables = [];
|
||||
data.root = container;
|
||||
data.text = dom.append(container, $('.option-text'));
|
||||
@@ -54,10 +54,10 @@ class SelectListRenderer implements IListRenderer<ISelectOptionItem, ISelectList
|
||||
}
|
||||
|
||||
renderElement(element: ISelectOptionItem, index: number, templateData: ISelectListTemplateData): void {
|
||||
const data: ISelectListTemplateData = templateData;
|
||||
const text = element.text;
|
||||
const decoratorRight = element.decoratorRight;
|
||||
const isDisabled = element.isDisabled;
|
||||
const data = <ISelectListTemplateData>templateData;
|
||||
const text = (<ISelectOptionItem>element).text;
|
||||
const decoratorRight = (<ISelectOptionItem>element).decoratorRight;
|
||||
const isDisabled = (<ISelectOptionItem>element).isDisabled;
|
||||
|
||||
data.text.textContent = text;
|
||||
data.decoratorRight.innerText = (!!decoratorRight ? decoratorRight : '');
|
||||
@@ -73,10 +73,10 @@ class SelectListRenderer implements IListRenderer<ISelectOptionItem, ISelectList
|
||||
|
||||
// pseudo-select disabled option
|
||||
if (isDisabled) {
|
||||
dom.addClass(data.root, 'option-disabled');
|
||||
dom.addClass((<HTMLElement>data.root), 'option-disabled');
|
||||
} else {
|
||||
// Make sure we do class removal from prior template rendering
|
||||
dom.removeClass(data.root, 'option-disabled');
|
||||
dom.removeClass((<HTMLElement>data.root), 'option-disabled');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,9 +836,9 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
|
||||
private renderDescriptionMarkdown(text: string): HTMLElement {
|
||||
const cleanRenderedMarkdown = (element: Node) => {
|
||||
for (let i = 0; i < element.childNodes.length; i++) {
|
||||
const child = <Element>element.childNodes.item(i);
|
||||
const child = element.childNodes.item(i);
|
||||
|
||||
const tagName = child.tagName && child.tagName.toLowerCase();
|
||||
const tagName = (<Element>child).tagName && (<Element>child).tagName.toLowerCase();
|
||||
if (tagName === 'img') {
|
||||
element.removeChild(child);
|
||||
} else {
|
||||
|
||||
@@ -234,8 +234,8 @@ export class SplitView extends Disposable {
|
||||
});
|
||||
|
||||
const sashEventMapper = this.orientation === Orientation.VERTICAL
|
||||
? (e: IBaseSashEvent) => ({ sash, start: e.startY, current: e.currentY, alt: e.altKey })
|
||||
: (e: IBaseSashEvent) => ({ sash, start: e.startX, current: e.currentX, alt: e.altKey });
|
||||
? (e: IBaseSashEvent) => ({ sash, start: e.startY, current: e.currentY, alt: e.altKey } as ISashEvent)
|
||||
: (e: IBaseSashEvent) => ({ sash, start: e.startX, current: e.currentX, alt: e.altKey } as ISashEvent);
|
||||
|
||||
const onStart = Event.map(sash.onDidStart, sashEventMapper);
|
||||
const onStartDisposable = onStart(this.onSashStart, this);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
import 'vs/css!./toolbar';
|
||||
import * as nls from 'vs/nls';
|
||||
import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
|
||||
import { ActionBar, ActionsOrientation, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { IContextMenuProvider, DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdown';
|
||||
import { ActionBar, ActionsOrientation, IActionItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { IContextMenuProvider, DropdownMenuActionItem } from 'vs/base/browser/ui/dropdown/dropdown';
|
||||
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
|
||||
@@ -17,7 +17,7 @@ export const CONTEXT = 'context.toolbar';
|
||||
|
||||
export interface IToolBarOptions {
|
||||
orientation?: ActionsOrientation;
|
||||
actionViewItemProvider?: IActionViewItemProvider;
|
||||
actionItemProvider?: IActionItemProvider;
|
||||
ariaLabel?: string;
|
||||
getKeyBinding?: (action: IAction) => ResolvedKeybinding | undefined;
|
||||
actionRunner?: IActionRunner;
|
||||
@@ -32,7 +32,7 @@ export class ToolBar extends Disposable {
|
||||
private options: IToolBarOptions;
|
||||
private actionBar: ActionBar;
|
||||
private toggleMenuAction: ToggleMenuAction;
|
||||
private toggleMenuActionViewItem?: DropdownMenuActionViewItem;
|
||||
private toggleMenuActionItem?: DropdownMenuActionItem;
|
||||
private hasSecondaryActions: boolean;
|
||||
private lookupKeybindings: boolean;
|
||||
|
||||
@@ -42,7 +42,7 @@ export class ToolBar extends Disposable {
|
||||
this.options = options;
|
||||
this.lookupKeybindings = typeof this.options.getKeyBinding === 'function';
|
||||
|
||||
this.toggleMenuAction = this._register(new ToggleMenuAction(() => this.toggleMenuActionViewItem && this.toggleMenuActionViewItem.show(), options.toggleMenuTitle));
|
||||
this.toggleMenuAction = this._register(new ToggleMenuAction(() => this.toggleMenuActionItem && this.toggleMenuActionItem.show(), options.toggleMenuTitle));
|
||||
|
||||
let element = document.createElement('div');
|
||||
element.className = 'monaco-toolbar';
|
||||
@@ -52,33 +52,33 @@ export class ToolBar extends Disposable {
|
||||
orientation: options.orientation,
|
||||
ariaLabel: options.ariaLabel,
|
||||
actionRunner: options.actionRunner,
|
||||
actionViewItemProvider: (action: Action) => {
|
||||
actionItemProvider: (action: Action) => {
|
||||
|
||||
// Return special action item for the toggle menu action
|
||||
if (action.id === ToggleMenuAction.ID) {
|
||||
|
||||
// Dispose old
|
||||
if (this.toggleMenuActionViewItem) {
|
||||
this.toggleMenuActionViewItem.dispose();
|
||||
if (this.toggleMenuActionItem) {
|
||||
this.toggleMenuActionItem.dispose();
|
||||
}
|
||||
|
||||
// Create new
|
||||
this.toggleMenuActionViewItem = new DropdownMenuActionViewItem(
|
||||
this.toggleMenuActionItem = new DropdownMenuActionItem(
|
||||
action,
|
||||
(<ToggleMenuAction>action).menuActions,
|
||||
contextMenuProvider,
|
||||
this.options.actionViewItemProvider,
|
||||
this.options.actionItemProvider,
|
||||
this.actionRunner,
|
||||
this.options.getKeyBinding,
|
||||
'toolbar-toggle-more',
|
||||
this.options.anchorAlignmentProvider
|
||||
);
|
||||
this.toggleMenuActionViewItem!.setActionContext(this.actionBar.context);
|
||||
this.toggleMenuActionItem!.setActionContext(this.actionBar.context);
|
||||
|
||||
return this.toggleMenuActionViewItem;
|
||||
return this.toggleMenuActionItem;
|
||||
}
|
||||
|
||||
return options.actionViewItemProvider ? options.actionViewItemProvider(action) : undefined;
|
||||
return options.actionItemProvider ? options.actionItemProvider(action) : undefined;
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -93,8 +93,8 @@ export class ToolBar extends Disposable {
|
||||
|
||||
set context(context: any) {
|
||||
this.actionBar.context = context;
|
||||
if (this.toggleMenuActionViewItem) {
|
||||
this.toggleMenuActionViewItem.setActionContext(context);
|
||||
if (this.toggleMenuActionItem) {
|
||||
this.toggleMenuActionItem.setActionContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,9 +156,9 @@ export class ToolBar extends Disposable {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this.toggleMenuActionViewItem) {
|
||||
this.toggleMenuActionViewItem.dispose();
|
||||
this.toggleMenuActionViewItem = undefined;
|
||||
if (this.toggleMenuActionItem) {
|
||||
this.toggleMenuActionItem.dispose();
|
||||
this.toggleMenuActionItem = undefined;
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
|
||||
Reference in New Issue
Block a user