Skip to content

Commit 8602124

Browse files
committed
Move webview commands to own file
1 parent 427b3bb commit 8602124

3 files changed

Lines changed: 86 additions & 77 deletions

File tree

src/vs/workbench/parts/html/browser/webview.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { ContextKeyExpr, } from 'vs/platform/contextkey/common/contextkey';
88
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
99

1010
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
11-
import { KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED, ShowWebViewEditorFindTermCommand, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, HideWebViewEditorFindCommand, ShowWebViewEditorFindWidgetAction } from './webviewEditor';
11+
import { KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './webviewEditor';
1212
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
1313
import { Registry } from 'vs/platform/registry/common/platform';
14+
import { ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindTermCommand, HideWebViewEditorFindCommand } from './webviewCommands';
1415

1516

1617
const category = 'Webview';
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
8+
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
9+
import { Command, ICommandOptions } from 'vs/editor/browser/editorExtensions';
10+
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
11+
import { Action } from 'vs/base/common/actions';
12+
import { TPromise } from 'vs/base/common/winjs.base';
13+
import { WebviewEditor } from './webviewEditor';
14+
15+
export class ShowWebViewEditorFindWidgetAction extends Action {
16+
public static readonly ID = 'editor.action.webvieweditor.showFind';
17+
public static readonly LABEL = nls.localize('editor.action.webvieweditor.showFind', "Focus Find Widget");
18+
19+
public constructor(
20+
id: string,
21+
label: string,
22+
@IWorkbenchEditorService private workbenchEditorService: IWorkbenchEditorService
23+
) {
24+
super(id, label);
25+
}
26+
27+
public run(): TPromise<any> {
28+
const webViewEditor = this.getWebViewEditor();
29+
if (webViewEditor) {
30+
webViewEditor.showFind();
31+
}
32+
return null;
33+
}
34+
35+
private getWebViewEditor(): WebviewEditor {
36+
const activeEditor = this.workbenchEditorService.getActiveEditor() as WebviewEditor;
37+
if (activeEditor.isWebviewEditor) {
38+
return activeEditor;
39+
}
40+
return null;
41+
}
42+
}
43+
44+
export class HideWebViewEditorFindCommand extends Command {
45+
public runCommand(accessor: ServicesAccessor, args: any): void {
46+
const webViewEditor = this.getWebViewEditor(accessor);
47+
if (webViewEditor) {
48+
webViewEditor.hideFind();
49+
}
50+
}
51+
52+
private getWebViewEditor(accessor: ServicesAccessor): WebviewEditor {
53+
const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor() as WebviewEditor;
54+
if (activeEditor.isWebviewEditor) {
55+
return activeEditor;
56+
}
57+
return null;
58+
}
59+
}
60+
61+
export class ShowWebViewEditorFindTermCommand extends Command {
62+
constructor(opts: ICommandOptions, private _next: boolean) {
63+
super(opts);
64+
}
65+
66+
public runCommand(accessor: ServicesAccessor, args: any): void {
67+
const webViewEditor = this.getWebViewEditor(accessor);
68+
if (webViewEditor) {
69+
if (this._next) {
70+
webViewEditor.showNextFindTerm();
71+
} else {
72+
webViewEditor.showPreviousFindTerm();
73+
}
74+
}
75+
}
76+
77+
private getWebViewEditor(accessor: ServicesAccessor): WebviewEditor {
78+
const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor() as WebviewEditor;
79+
if (activeEditor.isWebviewEditor) {
80+
return activeEditor;
81+
}
82+
return null;
83+
}
84+
}

src/vs/workbench/parts/html/browser/webviewEditor.ts

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as nls from 'vs/nls';
76
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
87
import { IThemeService } from 'vs/platform/theme/common/themeService';
98
import { BaseWebviewEditor } from 'vs/workbench/browser/parts/editor/webviewEditor';
109
import { IStorageService } from 'vs/platform/storage/common/storage';
1110

12-
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
13-
import { Command, ICommandOptions } from 'vs/editor/browser/editorExtensions';
14-
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
1511
import { IContextKey, RawContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1612

1713
import { Webview } from './webview';
1814
import { Builder } from 'vs/base/browser/builder';
19-
import { Action } from 'vs/base/common/actions';
20-
import { TPromise } from 'vs/base/common/winjs.base';
2115

2216
/** A context key that is set when a webview editor has focus. */
2317
export const KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS = new RawContextKey<boolean>('webviewEditorFocus', false);
@@ -93,73 +87,3 @@ export abstract class WebviewEditor extends BaseWebviewEditor {
9387
protected abstract createEditor(parent: Builder): void;
9488
}
9589

96-
export class ShowWebViewEditorFindWidgetAction extends Action {
97-
public static readonly ID = 'editor.action.webvieweditor.showFind';
98-
public static readonly LABEL = nls.localize('editor.action.webvieweditor.showFind', "Focus Find Widget");
99-
100-
public constructor(
101-
id: string,
102-
label: string,
103-
@IWorkbenchEditorService private workbenchEditorService: IWorkbenchEditorService
104-
) {
105-
super(id, label);
106-
}
107-
108-
public run(): TPromise<any> {
109-
const webViewEditor = this.getWebViewEditor();
110-
if (webViewEditor) {
111-
webViewEditor.showFind();
112-
}
113-
return null;
114-
}
115-
116-
private getWebViewEditor(): WebviewEditor {
117-
const activeEditor = this.workbenchEditorService.getActiveEditor() as WebviewEditor;
118-
if (activeEditor.isWebviewEditor) {
119-
return activeEditor;
120-
}
121-
return null;
122-
}
123-
}
124-
125-
export class HideWebViewEditorFindCommand extends Command {
126-
public runCommand(accessor: ServicesAccessor, args: any): void {
127-
const webViewEditor = this.getWebViewEditor(accessor);
128-
if (webViewEditor) {
129-
webViewEditor.hideFind();
130-
}
131-
}
132-
133-
private getWebViewEditor(accessor: ServicesAccessor): WebviewEditor {
134-
const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor() as WebviewEditor;
135-
if (activeEditor.isWebviewEditor) {
136-
return activeEditor;
137-
}
138-
return null;
139-
}
140-
}
141-
142-
export class ShowWebViewEditorFindTermCommand extends Command {
143-
constructor(opts: ICommandOptions, private _next: boolean) {
144-
super(opts);
145-
}
146-
147-
public runCommand(accessor: ServicesAccessor, args: any): void {
148-
const webViewEditor = this.getWebViewEditor(accessor);
149-
if (webViewEditor) {
150-
if (this._next) {
151-
webViewEditor.showNextFindTerm();
152-
} else {
153-
webViewEditor.showPreviousFindTerm();
154-
}
155-
}
156-
}
157-
158-
private getWebViewEditor(accessor: ServicesAccessor): WebviewEditor {
159-
const activeEditor = accessor.get(IWorkbenchEditorService).getActiveEditor() as WebviewEditor;
160-
if (activeEditor.isWebviewEditor) {
161-
return activeEditor;
162-
}
163-
return null;
164-
}
165-
}

0 commit comments

Comments
 (0)