Skip to content

Commit

Permalink
Working SimpleFind Service, isolation - pre- cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cleidigh authored and rebornix committed Aug 26, 2017
1 parent c586e52 commit bd8f5eb
Show file tree
Hide file tree
Showing 17 changed files with 637 additions and 109 deletions.
236 changes: 236 additions & 0 deletions src/vs/editor/contrib/find/browser/simpleFindWidget.contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// import * as nls from 'vs/nls';
import { Command } from 'vs/editor/common/editorCommonExtensions';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
// import { Widget } from 'vs/base/browser/ui/widget';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
// import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';

// import * as dom from 'vs/base/browser/dom';
// import { FindInput } from 'vs/base/browser/ui/findinput/findInput';
// import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
// import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
// 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 { HistoryNavigator } from 'vs/base/common/history';
// import { SimpleButton } from './findWidget';
// import { Delayer } from 'vs/base/common/async';

import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ISimpleFindWidgetService, KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE } from 'vs/editor/contrib/find/browser/simpleFindWidgetService';
import { SimpleFindWidget, KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED } from 'vs/editor/contrib/find/browser/simpleFindWidget';


/*
export abstract class SimpleFindAction extends Action {
// public abstract runCommand(accessor: ServicesAccessor, args: any): void;
protected getSimpleFindWidget(accessor: ServicesAccessor): SimpleFindWidget {
const activeSimpleFindWidget = accessor.get(ISimpleFindWidgetService).getActiveSimpleFindWidget() as SimpleFindWidget;
// if (activeEditor.isWebviewEditor) { // return activeEditor;
// }
return activeSimpleFindWidget;
}
protected getFocusedSimpleFindWidgetInput(accessor: ServicesAccessor): SimpleFindWidget {
const activeSimpleFindWidgetInput = accessor.get(ISimpleFindWidgetService).getFocusedSimpleFindWidgetInput() as SimpleFindWidget;
if (activeSimpleFindWidgetInput) { // return activeEditor;
console.debug('active focused input');
return activeSimpleFindWidgetInput;
}
return null;
}
}
*/
export abstract class SimpleFindCommand extends Command {

public abstract runCommand(accessor: ServicesAccessor, args: any): void;

protected getSimpleFindWidget(accessor: ServicesAccessor): SimpleFindWidget {
const activeSimpleFindWidget = accessor.get(ISimpleFindWidgetService).getActiveSimpleFindWidget() as SimpleFindWidget;
// if (activeEditor.isWebviewEditor) { // return activeEditor;
// }
return activeSimpleFindWidget;
}

protected getFocusedSimpleFindWidgetInput(accessor: ServicesAccessor): SimpleFindWidget {
const activeSimpleFindWidgetInput = accessor.get(ISimpleFindWidgetService).getFocusedSimpleFindWidgetInput() as SimpleFindWidget;
if (activeSimpleFindWidgetInput) { // return activeEditor;
console.debug('active focused input');
return activeSimpleFindWidgetInput;
}
return null;
}
}


class HistoryNextSimpleFindCommand extends SimpleFindCommand {
public runCommand(accessor: ServicesAccessor, args: any): void {
console.debug('command');
const simpleFindWidget = this.getFocusedSimpleFindWidgetInput(accessor);

if (simpleFindWidget) {
console.debug('next simple service');
simpleFindWidget.showNextFindTerm();
}
}
}
const historyNextSimpleFindCommand = new HistoryNextSimpleFindCommand({
id: 'editor.action.simplefind.nextHistory',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED,
kbOpts: {
// primary: KeyMod.CtrlCmd | KeyCode.F11,
primary: KeyMod.Alt | KeyCode.DownArrow,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(historyNextSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

class HistoryPreviousSimpleFindCommand extends SimpleFindCommand {
public runCommand(accessor: ServicesAccessor, args: any): void {
const simpleFindWidget = this.getFocusedSimpleFindWidgetInput(accessor);

if (simpleFindWidget) {
console.debug('previous simple service');
simpleFindWidget.showPreviousFindTerm();
}
}
}
const historyPreviousSimpleFindCommand = new HistoryPreviousSimpleFindCommand({
id: 'editor.action.simplefind.previousHistory',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED,
kbOpts: {
primary: KeyMod.Alt | KeyCode.UpArrow,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(historyPreviousSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

export class HideWidgetSimpleFindCommand extends SimpleFindCommand {
public static ID = 'editor.action.simplefind.hide';

public runCommand(accessor: ServicesAccessor, args: any): void {
console.debug('test command');
// accessor.get(ISimpleFindWidgetService).getSimpleFindWidgetCount();
accessor.get(ISimpleFindWidgetService).hide();

// }
}
}
const hideWidgetSimpleFindCommand = new HideWidgetSimpleFindCommand({
id: 'editor.action.simplefind.hide',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE,
kbOpts: {
primary: KeyCode.Escape,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(hideWidgetSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

export class ShowWidgetSimpleFindCommand extends SimpleFindCommand {
public static ID = 'editor.action.simplefind.show';

public runCommand(accessor: ServicesAccessor, args: any): void {
console.debug('test command');
// accessor.get(ISimpleFindWidgetService).getSimpleFindWidgetCount();
accessor.get(ISimpleFindWidgetService).show();

// }
}
}
const showWidgetSimpleFindCommand = new ShowWidgetSimpleFindCommand({
id: 'editor.action.simplefind.show',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE,
kbOpts: {
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(showWidgetSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

export class FindNextSimpleFindCommand extends SimpleFindCommand {
public static ID = 'editor.action.simplefind.nextMatch';

public runCommand(accessor: ServicesAccessor, args: any): void {

accessor.get(ISimpleFindWidgetService).find(false);
}
}
const findNextSimpleFindCommand = new FindNextSimpleFindCommand({
id: 'editor.action.simplefind.nextMatch',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE,
kbOpts: {
primary: KeyCode.F3,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(findNextSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

export class FindPreviousSimpleFindCommand extends SimpleFindCommand {
public static ID = 'editor.action.simplefind.previousMatch';

public runCommand(accessor: ServicesAccessor, args: any): void {
accessor.get(ISimpleFindWidgetService).find(true);
}
}
const findPreviousSimpleFindCommand = new FindPreviousSimpleFindCommand({
id: 'editor.action.simplefind.previousMatch',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE,
kbOpts: {
primary: KeyMod.Shift | KeyCode.F3,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(findPreviousSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

// cleidigh test
class TestSimpleFindCommand extends SimpleFindCommand {
public runCommand(accessor: ServicesAccessor, args: any): void {
console.debug('test command');
accessor.get(ISimpleFindWidgetService).find(false);

}
}
const testSimpleFindCommand = new TestSimpleFindCommand({
id: 'editor.action.simplefind.test',
precondition: KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE,
kbOpts: {
primary: KeyMod.CtrlCmd | KeyCode.F12,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule(testSimpleFindCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

/*
export class PreviousMatchSimpleFindAction extends SimpleFindAction {
public static ID = 'workbench.action.simpleFind.previousMatch';
public static LABEL = nls.localize('workbench.action.simpleFind.previousMatchFindWidget', "Terminal: Find Previous Match");
constructor(
id: string, label: string,
@ISimpleFindWidgetService private _simpleFindWidgetService: ISimpleFindWidgetService
) {
super(id, label);
}
public run(): TPromise<any> {
console.debug('previous action');
return TPromise.as(this._simpleFindWidgetService.find(true));
}
}
const category = nls.localize('simpleFindCategory', "SimpleFind");
let actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PreviousMatchSimpleFindAction, PreviousMatchSimpleFindAction.ID, PreviousMatchSimpleFindAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.F11,
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G, secondary: [KeyMod.Shift | KeyCode.F3] }
}, KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE), 'Find Previous', category);
*/
48 changes: 47 additions & 1 deletion src/vs/editor/contrib/find/browser/simpleFindWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,37 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import * as dom from 'vs/base/browser/dom';
import { FindInput } from 'vs/base/browser/ui/findinput/findInput';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
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 { HistoryNavigator } from 'vs/base/common/history';
import { SimpleButton } from './findWidget';
import { Delayer } from 'vs/base/common/async';
import { ISimpleFindWidgetService } from 'vs/editor/contrib/find/browser/simpleFindWidgetService';


export const KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED = new RawContextKey<boolean>('simpleFindWidgetInputFocused', undefined);

const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
const NLS_PREVIOUS_MATCH_BTN_LABEL = nls.localize('label.previousMatchButton', "Previous match");
const NLS_NEXT_MATCH_BTN_LABEL = nls.localize('label.nextMatchButton', "Next match");
const NLS_CLOSE_BTN_LABEL = nls.localize('label.closeButton', "Close");

interface ISimpleFindWidgetRegistry {
inputId: number;
// simpleFindWidget: SimpleFindWidget;
simpleFindWidgetPtr: Object;
findInputDOMNode: HTMLElement;
}

export abstract class SimpleFindWidget extends Widget {

protected _findInput: FindInput;
protected _domNode: HTMLElement;
protected _isVisible: boolean;
// protected _activeContextKey: IContextKey<boolean>;

protected _focusTracker: dom.IFocusTracker;

protected _findInputFocusTracker: dom.IFocusTracker;
Expand All @@ -35,8 +49,13 @@ export abstract class SimpleFindWidget extends Widget {
protected _findHistory: HistoryNavigator<string>;
protected _updateHistoryDelayer: Delayer<void>;

private static _count: number = 0;
// private static _simpleFindWidgetRegistry: ISimpleFindWidgetRegistry[] = [];

constructor(
@IContextViewService private _contextViewService: IContextViewService,
@IContextKeyService private _contextKeyService: IContextKeyService,
@ISimpleFindWidgetService private _simpleFindWidgetService: ISimpleFindWidgetService,
private animate: boolean = true
) {
super();
Expand All @@ -45,9 +64,26 @@ export abstract class SimpleFindWidget extends Widget {
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
}));

SimpleFindWidget._count++;

// var accessor: ServicesAccessor;
// const simpleFindWidgetService = accessor.get(ISimpleFindWidgetService) instanceof SimpleFindWidgetService;
// console.debug('Test ' + simpleFindWidgetService.getFindInputDOM());
// .getActiveSimpleFindWidget() as SimpleFindWidget;
console.debug('SFW ' + SimpleFindWidget._count);
// var simpleFindWidgetRegistryEntry: ISimpleFindWidgetRegistry;
// simpleFindWidgetRegistryEntry.inputId = SimpleFindWidget._count;
// simpleFindWidgetRegistryEntry.simpleFindWidget = this;
// simpleFindWidgetRegistryEntry.findInputDOMNode = this._findInput.domNode;

// SimpleFindWidget._simpleFindWidgetRegistry.push(simpleFindWidgetRegistryEntry);

this._findHistory = new HistoryNavigator<string>();

this._updateHistoryDelayer = new Delayer<void>(500);

this._findInputFocused = KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED.bindTo(this._contextKeyService);

this.oninput(this._findInput.domNode, (e) => {
this.onInputChanged();
this._delayedUpdateHistory();
Expand Down Expand Up @@ -129,10 +165,14 @@ export abstract class SimpleFindWidget extends Widget {

private _onFindInputFocusTrackerFocus() {
this._findInputFocused.set(true);
this._simpleFindWidgetService.setFocusedSimpleFindWidgetInput(this);
console.debug('find focused');
}

private _onFindInputFocusTrackerBlur() {
this._findInputFocused.reset();
this._simpleFindWidgetService.setFocusedSimpleFindWidgetInput(null);
console.debug('find blur');
}

protected get inputValue() {
Expand Down Expand Up @@ -218,8 +258,14 @@ export abstract class SimpleFindWidget extends Widget {
this._findInput.setValue(previous);
}
}

public baseFind(previous: boolean) {
this.find(previous);
}

}


// theming
registerThemingParticipant((theme, collector) => {
const findWidgetBGColor = theme.getColor(editorWidgetBackground);
Expand Down
Loading

0 comments on commit bd8f5eb

Please sign in to comment.