提交 26b30648 编写于 作者: S Sandeep Somavarapu

- Define IHistoryNavigationWidget interface

- Ability to register a context scoped history navigation widget
- context to enable / disable history navigation
上级 eb163dee
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export interface IHistoryNavigationWidget {
showPreviousValue();
showNextValue();
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ import { Widget } from 'vs/base/browser/ui/widget';
import { Color } from 'vs/base/common/color';
import { mixin } from 'vs/base/common/objects';
import { HistoryNavigator } from 'vs/base/common/history';
import { IHistoryNavigationWidget } from 'vs/base/browser/history';
const $ = dom.$;
......@@ -503,7 +504,7 @@ export interface IHistoryInputOptions extends IInputOptions {
history: string[];
}
export class HistoryInputBox extends InputBox {
export class HistoryInputBox extends InputBox implements IHistoryNavigationWidget {
private readonly history: HistoryNavigator<string>;
......@@ -522,14 +523,14 @@ export class HistoryInputBox extends InputBox {
return this.history.getHistory();
}
public showNextValue() {
public showNextValue(): void {
let next = this.history.next();
if (next) {
this.value = next;
}
}
public showPreviousValue() {
public showPreviousValue(): void {
let previous;
if (this.value.length === 0) {
previous = this.history.current();
......
......@@ -30,7 +30,7 @@ import { ITheme, registerThemingParticipant, IThemeService } from 'vs/platform/t
import { Color } from 'vs/base/common/color';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
import { editorFindRangeHighlight, editorFindMatch, editorFindMatchHighlight, contrastBorder, inputBackground, editorWidgetBackground, inputActiveOptionBorder, widgetShadow, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, errorForeground, editorWidgetBorder, editorFindMatchBorder, editorFindMatchHighlightBorder, editorFindRangeHighlightBorder, editorWidgetResizeBorder } from 'vs/platform/theme/common/colorRegistry';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
export interface IFindController {
......
......@@ -14,7 +14,7 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
import { registerThemingParticipant, ITheme } from 'vs/platform/theme/common/themeService';
import { inputBackground, inputActiveOptionBorder, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, editorWidgetBackground, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
import { SimpleButton } from './findWidget';
import { ContextScopedFindInput } from 'vs/platform/widget/browser/input';
import { ContextScopedFindInput } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IContextKeyService, ContextKeyDefinedExpr, ContextKeyExpr, ContextKeyAndExpr, ContextKeyEqualsExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { HistoryInputBox, IHistoryInputOptions } from 'vs/base/browser/ui/inputbox/inputBox';
import { FindInput, IFindInputOptions } from 'vs/base/browser/ui/findinput/findInput';
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
import { IContextScopedWidget, getContextScopedWidget, createWidgetScopedContextKeyService } from 'vs/platform/widget/common/contextScopedWidget';
import { IHistoryNavigationWidget } from 'vs/base/browser/history';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
export const HistoryNavigationWidgetContext = 'historyNavigationWidget';
export const HistoryNavigationEnablementContext = 'historyNavigationEnabled';
export interface IContextScopedHistoryNavigationWidget extends IContextScopedWidget {
historyNavigator: IHistoryNavigationWidget;
}
export function createHistoryNavigationWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IContextScopedHistoryNavigationWidget): IContextKeyService {
const scopedContextKeyService = createWidgetScopedContextKeyService(contextKeyService, widget, HistoryNavigationWidgetContext);
const enablementContext = new RawContextKey<boolean>(HistoryNavigationEnablementContext, true);
enablementContext.bindTo(scopedContextKeyService);
return scopedContextKeyService;
}
export class ContextScopedHistoryInputBox extends HistoryInputBox {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
this._register(createHistoryNavigationWidgetScopedContextKeyService(contextKeyService, <IContextScopedHistoryNavigationWidget>{ target: this.element, historyNavigator: this }));
}
}
export class ContextScopedFindInput extends FindInput {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IFindInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
this._register(createHistoryNavigationWidgetScopedContextKeyService(contextKeyService, <IContextScopedHistoryNavigationWidget>{ target: this.inputBox.element, historyNavigator: this.inputBox }));
}
}
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'history.showPrevious',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: ContextKeyExpr.and(new ContextKeyDefinedExpr(HistoryNavigationWidgetContext), new ContextKeyEqualsExpr(HistoryNavigationEnablementContext, true)),
primary: KeyCode.UpArrow,
secondary: [KeyMod.Alt | KeyCode.UpArrow],
handler: (accessor, arg2) => {
const historyInputBox: IHistoryNavigationWidget = getContextScopedWidget<IContextScopedHistoryNavigationWidget>(accessor.get(IContextKeyService), HistoryNavigationWidgetContext).historyNavigator;
historyInputBox.showPreviousValue();
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'history.showNext',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: new ContextKeyAndExpr([new ContextKeyDefinedExpr(HistoryNavigationWidgetContext), new ContextKeyEqualsExpr(HistoryNavigationEnablementContext, true)]),
primary: KeyCode.DownArrow,
secondary: [KeyMod.Alt | KeyCode.DownArrow],
handler: (accessor, arg2) => {
const historyInputBox: IHistoryNavigationWidget = getContextScopedWidget<IContextScopedHistoryNavigationWidget>(accessor.get(IContextKeyService), HistoryNavigationWidgetContext).historyNavigator;
historyInputBox.showNextValue();
}
});
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { HistoryInputBox, IHistoryInputOptions } from 'vs/base/browser/ui/inputbox/inputBox';
import { FindInput, IFindInputOptions } from 'vs/base/browser/ui/findinput/findInput';
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
import { createWidgetScopedContextKeyService, IContextScopedWidget } from 'vs/platform/widget/browser/widget';
export const HistoryInputBoxContext = 'historyInputBox';
export interface IContextScopedHistoryInputBox extends IContextScopedWidget {
historyInputbox: HistoryInputBox;
}
export class ContextScopedHistoryInputBox extends HistoryInputBox {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
this._register(createWidgetScopedContextKeyService(contextKeyService, <IContextScopedHistoryInputBox>{ target: this.element, historyInputbox: this }, HistoryInputBoxContext));
}
}
export class ContextScopedFindInput extends FindInput {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IFindInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
this._register(createWidgetScopedContextKeyService(contextKeyService, <IContextScopedHistoryInputBox>{ target: this.inputBox.element, historyInputbox: this.inputBox }, HistoryInputBoxContext));
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ContextKeyDefinedExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { HistoryInputBoxContext, IContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
import { HistoryInputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { getContextScopedWidget } from 'vs/platform/widget/browser/widget';
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'input.action.historyPrevious',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: new ContextKeyDefinedExpr(HistoryInputBoxContext),
primary: KeyCode.UpArrow,
secondary: [KeyMod.Alt | KeyCode.UpArrow],
handler: (accessor, arg2) => {
const historyInputBox: HistoryInputBox = getContextScopedWidget<IContextScopedHistoryInputBox>(accessor.get(IContextKeyService), HistoryInputBoxContext).historyInputbox;
historyInputBox.showPreviousValue();
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'input.action.historyNext',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: new ContextKeyDefinedExpr(HistoryInputBoxContext),
primary: KeyCode.DownArrow,
secondary: [KeyMod.Alt | KeyCode.DownArrow],
handler: (accessor, arg2) => {
const historyInputBox: HistoryInputBox = getContextScopedWidget<IContextScopedHistoryInputBox>(accessor.get(IContextKeyService), HistoryInputBoxContext).historyInputbox;
historyInputBox.showNextValue();
}
});
......@@ -29,7 +29,7 @@ import { badgeBackground, contrastBorder } from 'vs/platform/theme/common/colorR
import { localize } from 'vs/nls';
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
export class ToggleMarkersPanelAction extends TogglePanelAction {
......
......@@ -14,7 +14,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachInputBoxStyler, attachCheckboxStyler } from 'vs/platform/theme/common/styler';
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export interface IOptions {
......
......@@ -31,7 +31,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ISearchConfigurationProperties } from 'vs/platform/search/common/search';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
export interface ISearchWidgetOptions {
value?: string;
......
......@@ -16,7 +16,7 @@ import 'vs/workbench/services/configuration/common/configurationExtensionPoint';
import 'vs/editor/editor.all';
// Platform
import 'vs/platform/widget/browser/widget.contribution';
import 'vs/platform/widget/browser/contextScopedHistoryWidget';
// Menus/Actions
import 'vs/workbench/services/actions/electron-browser/menusExtensionPoint';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册