1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+
6+ // import * as nls from 'vs/nls';
7+ import { Command } from 'vs/editor/common/editorCommonExtensions' ;
8+ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
9+ // import { Widget } from 'vs/base/browser/ui/widget';
10+ import { KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
11+ // import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
12+
13+ // import * as dom from 'vs/base/browser/dom';
14+ // import { FindInput } from 'vs/base/browser/ui/findinput/findInput';
15+ // import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
16+ // import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
17+ // import { registerThemingParticipant, ITheme } from 'vs/platform/theme/common/themeService';
18+ // import { inputBackground, inputActiveOptionBorder, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, editorWidgetBackground, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
19+ // import { HistoryNavigator } from 'vs/base/common/history';
20+ // import { SimpleButton } from './findWidget';
21+ // import { Delayer } from 'vs/base/common/async';
22+
23+ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
24+ import { ISimpleFindWidgetService , KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE } from 'vs/editor/contrib/find/browser/simpleFindWidgetService' ;
25+ import { SimpleFindWidget , KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED } from 'vs/editor/contrib/find/browser/simpleFindWidget' ;
26+
27+
28+ /*
29+ export abstract class SimpleFindAction extends Action {
30+
31+ // public abstract runCommand(accessor: ServicesAccessor, args: any): void;
32+
33+ protected getSimpleFindWidget(accessor: ServicesAccessor): SimpleFindWidget {
34+ const activeSimpleFindWidget = accessor.get(ISimpleFindWidgetService).getActiveSimpleFindWidget() as SimpleFindWidget;
35+ // if (activeEditor.isWebviewEditor) { // return activeEditor;
36+ // }
37+ return activeSimpleFindWidget;
38+ }
39+
40+ protected getFocusedSimpleFindWidgetInput(accessor: ServicesAccessor): SimpleFindWidget {
41+ const activeSimpleFindWidgetInput = accessor.get(ISimpleFindWidgetService).getFocusedSimpleFindWidgetInput() as SimpleFindWidget;
42+ if (activeSimpleFindWidgetInput) { // return activeEditor;
43+ console.debug('active focused input');
44+ return activeSimpleFindWidgetInput;
45+ }
46+ return null;
47+ }
48+ }
49+ */
50+ export abstract class SimpleFindCommand extends Command {
51+
52+ public abstract runCommand ( accessor : ServicesAccessor , args : any ) : void ;
53+
54+ protected getSimpleFindWidget ( accessor : ServicesAccessor ) : SimpleFindWidget {
55+ const activeSimpleFindWidget = accessor . get ( ISimpleFindWidgetService ) . getActiveSimpleFindWidget ( ) as SimpleFindWidget ;
56+ // if (activeEditor.isWebviewEditor) { // return activeEditor;
57+ // }
58+ return activeSimpleFindWidget ;
59+ }
60+
61+ protected getFocusedSimpleFindWidgetInput ( accessor : ServicesAccessor ) : SimpleFindWidget {
62+ const activeSimpleFindWidgetInput = accessor . get ( ISimpleFindWidgetService ) . getFocusedSimpleFindWidgetInput ( ) as SimpleFindWidget ;
63+ if ( activeSimpleFindWidgetInput ) { // return activeEditor;
64+ console . debug ( 'active focused input' ) ;
65+ return activeSimpleFindWidgetInput ;
66+ }
67+ return null ;
68+ }
69+ }
70+
71+
72+ class HistoryNextSimpleFindCommand extends SimpleFindCommand {
73+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
74+ console . debug ( 'command' ) ;
75+ const simpleFindWidget = this . getFocusedSimpleFindWidgetInput ( accessor ) ;
76+
77+ if ( simpleFindWidget ) {
78+ console . debug ( 'next simple service' ) ;
79+ simpleFindWidget . showNextFindTerm ( ) ;
80+ }
81+ }
82+ }
83+ const historyNextSimpleFindCommand = new HistoryNextSimpleFindCommand ( {
84+ id : 'editor.action.simplefind.nextHistory' ,
85+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED ,
86+ kbOpts : {
87+ // primary: KeyMod.CtrlCmd | KeyCode.F11,
88+ primary : KeyMod . Alt | KeyCode . DownArrow ,
89+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
90+ }
91+ } ) ;
92+ KeybindingsRegistry . registerCommandAndKeybindingRule ( historyNextSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
93+
94+ class HistoryPreviousSimpleFindCommand extends SimpleFindCommand {
95+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
96+ const simpleFindWidget = this . getFocusedSimpleFindWidgetInput ( accessor ) ;
97+
98+ if ( simpleFindWidget ) {
99+ console . debug ( 'previous simple service' ) ;
100+ simpleFindWidget . showPreviousFindTerm ( ) ;
101+ }
102+ }
103+ }
104+ const historyPreviousSimpleFindCommand = new HistoryPreviousSimpleFindCommand ( {
105+ id : 'editor.action.simplefind.previousHistory' ,
106+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_INPUT_FOCUSED ,
107+ kbOpts : {
108+ primary : KeyMod . Alt | KeyCode . UpArrow ,
109+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
110+ }
111+ } ) ;
112+ KeybindingsRegistry . registerCommandAndKeybindingRule ( historyPreviousSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
113+
114+ export class HideWidgetSimpleFindCommand extends SimpleFindCommand {
115+ public static ID = 'editor.action.simplefind.hide' ;
116+
117+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
118+ console . debug ( 'test command' ) ;
119+ // accessor.get(ISimpleFindWidgetService).getSimpleFindWidgetCount();
120+ accessor . get ( ISimpleFindWidgetService ) . hide ( ) ;
121+
122+ // }
123+ }
124+ }
125+ const hideWidgetSimpleFindCommand = new HideWidgetSimpleFindCommand ( {
126+ id : 'editor.action.simplefind.hide' ,
127+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE ,
128+ kbOpts : {
129+ primary : KeyCode . Escape ,
130+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
131+ }
132+ } ) ;
133+ KeybindingsRegistry . registerCommandAndKeybindingRule ( hideWidgetSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
134+
135+ export class ShowWidgetSimpleFindCommand extends SimpleFindCommand {
136+ public static ID = 'editor.action.simplefind.show' ;
137+
138+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
139+ console . debug ( 'test command' ) ;
140+ // accessor.get(ISimpleFindWidgetService).getSimpleFindWidgetCount();
141+ accessor . get ( ISimpleFindWidgetService ) . show ( ) ;
142+
143+ // }
144+ }
145+ }
146+ const showWidgetSimpleFindCommand = new ShowWidgetSimpleFindCommand ( {
147+ id : 'editor.action.simplefind.show' ,
148+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE ,
149+ kbOpts : {
150+ primary : KeyMod . CtrlCmd | KeyCode . KEY_F ,
151+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
152+ }
153+ } ) ;
154+ KeybindingsRegistry . registerCommandAndKeybindingRule ( showWidgetSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
155+
156+ export class FindNextSimpleFindCommand extends SimpleFindCommand {
157+ public static ID = 'editor.action.simplefind.nextMatch' ;
158+
159+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
160+
161+ accessor . get ( ISimpleFindWidgetService ) . find ( false ) ;
162+ }
163+ }
164+ const findNextSimpleFindCommand = new FindNextSimpleFindCommand ( {
165+ id : 'editor.action.simplefind.nextMatch' ,
166+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE ,
167+ kbOpts : {
168+ primary : KeyCode . F3 ,
169+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
170+ }
171+ } ) ;
172+ KeybindingsRegistry . registerCommandAndKeybindingRule ( findNextSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
173+
174+ export class FindPreviousSimpleFindCommand extends SimpleFindCommand {
175+ public static ID = 'editor.action.simplefind.previousMatch' ;
176+
177+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
178+ accessor . get ( ISimpleFindWidgetService ) . find ( true ) ;
179+ }
180+ }
181+ const findPreviousSimpleFindCommand = new FindPreviousSimpleFindCommand ( {
182+ id : 'editor.action.simplefind.previousMatch' ,
183+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE ,
184+ kbOpts : {
185+ primary : KeyMod . Shift | KeyCode . F3 ,
186+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
187+ }
188+ } ) ;
189+ KeybindingsRegistry . registerCommandAndKeybindingRule ( findPreviousSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
190+
191+ // cleidigh test
192+ class TestSimpleFindCommand extends SimpleFindCommand {
193+ public runCommand ( accessor : ServicesAccessor , args : any ) : void {
194+ console . debug ( 'test command' ) ;
195+ accessor . get ( ISimpleFindWidgetService ) . find ( false ) ;
196+
197+ }
198+ }
199+ const testSimpleFindCommand = new TestSimpleFindCommand ( {
200+ id : 'editor.action.simplefind.test' ,
201+ precondition : KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE ,
202+ kbOpts : {
203+ primary : KeyMod . CtrlCmd | KeyCode . F12 ,
204+ mac : { primary : KeyMod . CtrlCmd | KeyCode . KEY_G , secondary : [ KeyCode . F3 ] }
205+ }
206+ } ) ;
207+ KeybindingsRegistry . registerCommandAndKeybindingRule ( testSimpleFindCommand . toCommandAndKeybindingRule ( KeybindingsRegistry . WEIGHT . editorContrib ( ) ) ) ;
208+
209+ /*
210+
211+ export class PreviousMatchSimpleFindAction extends SimpleFindAction {
212+
213+ public static ID = 'workbench.action.simpleFind.previousMatch';
214+ public static LABEL = nls.localize('workbench.action.simpleFind.previousMatchFindWidget', "Terminal: Find Previous Match");
215+
216+ constructor(
217+ id: string, label: string,
218+ @ISimpleFindWidgetService private _simpleFindWidgetService: ISimpleFindWidgetService
219+ ) {
220+ super(id, label);
221+ }
222+
223+ public run(): TPromise<any> {
224+ console.debug('previous action');
225+ return TPromise.as(this._simpleFindWidgetService.find(true));
226+ }
227+ }
228+
229+ const category = nls.localize('simpleFindCategory', "SimpleFind");
230+ let actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
231+
232+ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PreviousMatchSimpleFindAction, PreviousMatchSimpleFindAction.ID, PreviousMatchSimpleFindAction.LABEL, {
233+ primary: KeyMod.CtrlCmd | KeyCode.F11,
234+ mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G, secondary: [KeyMod.Shift | KeyCode.F3] }
235+ }, KEYBINDING_CONTEXT_SIMPLE_FIND_WIDGET_ACTIVE), 'Find Previous', category);
236+ */
0 commit comments