提交 d1f43140 编写于 作者: I isidor

debug: cleanup how we create view controllers

上级 0dca3116
......@@ -11,6 +11,7 @@ import * as paths from 'vs/base/common/paths';
import * as async from 'vs/base/common/async';
import * as errors from 'vs/base/common/errors';
import { equalsIgnoreCase } from 'vs/base/common/strings';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { isMacintosh } from 'vs/base/common/platform';
import * as dom from 'vs/base/browser/dom';
import { IMouseEvent, DragMouseEvent } from 'vs/base/browser/mouseEvent';
......@@ -21,16 +22,17 @@ import { ITree, IAccessibilityProvider, ContextMenuEvent, IDataSource, IRenderer
import { InputBox, IInputValidationOptions } from 'vs/base/browser/ui/inputbox/inputBox';
import { DefaultController, DefaultDragAndDrop } from 'vs/base/parts/tree/browser/treeDefaults';
import { IActionProvider } from 'vs/base/parts/tree/browser/actionsRenderer';
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import * as debug from 'vs/workbench/parts/debug/common/debug';
import { Expression, Variable, FunctionBreakpoint, StackFrame, Thread, Process, Breakpoint, ExceptionBreakpoint, Model, Scope } from 'vs/workbench/parts/debug/common/debugModel';
import { ViewModel } from 'vs/workbench/parts/debug/common/debugViewModel';
import { ContinueAction, StepOverAction, PauseAction, AddFunctionBreakpointAction, ReapplyBreakpointsAction, DisableAllBreakpointsAction, RemoveBreakpointAction, ToggleEnablementAction, RenameFunctionBreakpointAction, RemoveWatchExpressionAction, AddWatchExpressionAction, EditWatchExpressionAction, RemoveAllBreakpointsAction, EnableAllBreakpointsAction, StepOutAction, StepIntoAction, SetValueAction, RemoveAllWatchExpressionsAction, ToggleBreakpointsActivatedAction, RestartFrameAction, AddToWatchExpressionsAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { CopyValueAction } from 'vs/workbench/parts/debug/electron-browser/electronDebugActions';
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
const $ = dom.$;
const booleanRegex = /^true|false$/i;
......@@ -176,10 +178,10 @@ function getSourceName(source: Source, contextService: IWorkspaceContextService)
export class BaseDebugController extends DefaultController {
constructor(
protected debugService: debug.IDebugService,
private contextMenuService: IContextMenuService,
private actionProvider: IActionProvider,
private focusOnContextMenu = true
@debug.IDebugService protected debugService: debug.IDebugService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super();
......@@ -189,6 +191,11 @@ export class BaseDebugController extends DefaultController {
this.downKeyBindingDispatcher.set(KeyCode.Delete, this.onDelete.bind(this));
this.downKeyBindingDispatcher.set(KeyMod.Shift | KeyCode.Delete, this.onDelete.bind(this));
}
if (isMacintosh) {
this.downKeyBindingDispatcher.set(KeyCode.Enter, this.onRename.bind(this));
} else {
this.downKeyBindingDispatcher.set(KeyCode.F2, this.onRename.bind(this));
}
}
public onContextMenu(tree: ITree, element: debug.IEnablement, event: ContextMenuEvent): boolean {
......@@ -199,9 +206,7 @@ export class BaseDebugController extends DefaultController {
event.preventDefault();
event.stopPropagation();
if (this.focusOnContextMenu) {
tree.setFocus(element);
}
tree.setFocus(element);
if (this.actionProvider.hasSecondaryActions(tree, element)) {
const anchor = { x: event.posx + 1, y: event.posy };
......@@ -225,6 +230,10 @@ export class BaseDebugController extends DefaultController {
protected onDelete(tree: ITree, event: IKeyboardEvent): boolean {
return false;
}
protected onRename(tree: ITree, event: IKeyboardEvent): boolean {
return false;
}
}
// call stack
......@@ -759,11 +768,6 @@ export class VariablesAccessibilityProvider implements IAccessibilityProvider {
export class VariablesController extends BaseDebugController {
constructor(debugService: debug.IDebugService, contextMenuService: IContextMenuService, actionProvider: IActionProvider) {
super(debugService, contextMenuService, actionProvider);
this.downKeyBindingDispatcher.set(KeyCode.Enter, this.setSelectedExpression.bind(this));
}
protected onLeftClick(tree: ITree, element: any, event: IMouseEvent): boolean {
// double click on primitive value: open input box to be able to set the value
if (element instanceof Variable && event.detail === 2) {
......@@ -777,7 +781,7 @@ export class VariablesController extends BaseDebugController {
return super.onLeftClick(tree, element, event);
}
protected setSelectedExpression(tree: ITree, event: KeyboardEvent): boolean {
protected onEnter(tree: ITree, event: IKeyboardEvent): boolean {
const element = tree.getFocus();
if (element instanceof Variable && !element.hasChildren) {
this.debugService.getViewModel().setSelectedExpression(element);
......@@ -995,16 +999,6 @@ export class WatchExpressionsAccessibilityProvider implements IAccessibilityProv
export class WatchExpressionsController extends BaseDebugController {
constructor(debugService: debug.IDebugService, contextMenuService: IContextMenuService, actionProvider: IActionProvider) {
super(debugService, contextMenuService, actionProvider);
if (isMacintosh) {
this.downKeyBindingDispatcher.set(KeyCode.Enter, this.onRename.bind(this));
} else {
this.downKeyBindingDispatcher.set(KeyCode.F2, this.onRename.bind(this));
}
}
protected onLeftClick(tree: ITree, element: any, event: IMouseEvent): boolean {
// double click on primitive value: open input box to be able to select and copy value.
if (element instanceof Expression && event.detail === 2) {
......@@ -1018,7 +1012,7 @@ export class WatchExpressionsController extends BaseDebugController {
return super.onLeftClick(tree, element, event);
}
protected onRename(tree: ITree, event: KeyboardEvent): boolean {
protected onRename(tree: ITree, event: IKeyboardEvent): boolean {
const element = tree.getFocus();
if (element instanceof Expression) {
const watchExpression = <Expression>element;
......@@ -1328,15 +1322,6 @@ export class BreakpointsAccessibilityProvider implements IAccessibilityProvider
export class BreakpointsController extends BaseDebugController {
constructor(debugService: debug.IDebugService, contextMenuService: IContextMenuService, actionProvider: IActionProvider) {
super(debugService, contextMenuService, actionProvider);
if (isMacintosh) {
this.downKeyBindingDispatcher.set(KeyCode.Enter, this.onRename.bind(this));
} else {
this.downKeyBindingDispatcher.set(KeyCode.F2, this.onRename.bind(this));
}
}
protected onLeftClick(tree: ITree, element: any, event: IMouseEvent): boolean {
if (element instanceof FunctionBreakpoint && event.detail === 2) {
this.debugService.getViewModel().setSelectedFunctionBreakpoint(element);
......
......@@ -86,7 +86,7 @@ export class VariablesView extends CollapsibleViewletView {
dataSource: new viewer.VariablesDataSource(),
renderer: this.instantiationService.createInstance(viewer.VariablesRenderer),
accessibilityProvider: new viewer.VariablesAccessibilityProvider(),
controller: new viewer.VariablesController(this.debugService, this.contextMenuService, new viewer.VariablesActionProvider(this.instantiationService))
controller: this.instantiationService.createInstance(viewer.VariablesController, new viewer.VariablesActionProvider(this.instantiationService))
}, {
ariaLabel: nls.localize('variablesAriaTreeLabel', "Debug Variables"),
twistiePixels
......@@ -182,7 +182,7 @@ export class WatchExpressionsView extends CollapsibleViewletView {
dataSource: new viewer.WatchExpressionsDataSource(),
renderer: this.instantiationService.createInstance(viewer.WatchExpressionsRenderer, actionProvider, this.actionRunner),
accessibilityProvider: new viewer.WatchExpressionsAccessibilityProvider(),
controller: new viewer.WatchExpressionsController(this.debugService, this.contextMenuService, actionProvider),
controller: this.instantiationService.createInstance(viewer.WatchExpressionsController, actionProvider),
dnd: this.instantiationService.createInstance(viewer.WatchExpressionsDragAndDrop)
}, {
ariaLabel: nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'watchAriaTreeLabel' }, "Debug Watch Expressions"),
......@@ -301,7 +301,7 @@ export class CallStackView extends CollapsibleViewletView {
dataSource: this.instantiationService.createInstance(viewer.CallStackDataSource),
renderer: this.instantiationService.createInstance(viewer.CallStackRenderer),
accessibilityProvider: this.instantiationService.createInstance(viewer.CallstackAccessibilityProvider),
controller: new viewer.CallStackController(this.debugService, this.contextMenuService, actionProvider)
controller: this.instantiationService.createInstance(viewer.CallStackController, actionProvider)
}, {
ariaLabel: nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'callStackAriaLabel' }, "Debug Call Stack"),
twistiePixels
......@@ -361,7 +361,7 @@ export class BreakpointsView extends AdaptiveCollapsibleViewletView {
dataSource: new viewer.BreakpointsDataSource(),
renderer: this.instantiationService.createInstance(viewer.BreakpointsRenderer, actionProvider, this.actionRunner),
accessibilityProvider: this.instantiationService.createInstance(viewer.BreakpointsAccessibilityProvider),
controller: new viewer.BreakpointsController(this.debugService, this.contextMenuService, actionProvider),
controller: this.instantiationService.createInstance(viewer.BreakpointsController, actionProvider),
sorter: {
compare(tree: ITree, element: any, otherElement: any): number {
const first = <IBreakpoint>element;
......
......@@ -143,7 +143,7 @@ export class Repl extends Panel implements IPrivateReplService {
dataSource: new ReplExpressionsDataSource(),
renderer: this.renderer,
accessibilityProvider: new ReplExpressionsAccessibilityProvider(),
controller: new ReplExpressionsController(this.debugService, this.contextMenuService, new ReplExpressionsActionProvider(this.instantiationService), this.replInput, false)
controller: this.instantiationService.createInstance(ReplExpressionsController, this.replInput, new ReplExpressionsActionProvider(this.instantiationService))
}, replTreeOptions);
if (!Repl.HISTORY) {
......
......@@ -26,6 +26,7 @@ import { AddToWatchExpressionsAction, ClearReplAction } from 'vs/workbench/parts
import { CopyAction } from 'vs/workbench/parts/debug/electron-browser/electronDebugActions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
......@@ -496,13 +497,13 @@ export class ReplExpressionsController extends BaseDebugController {
private lastSelectedString: string = null;
constructor(
debugService: IDebugService,
contextMenuService: IContextMenuService,
actionProvider: IActionProvider,
private replInput: ICodeEditor,
focusOnContextMenu = true
actionProvider: IActionProvider,
@IDebugService debugService: IDebugService,
@IContextMenuService contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(debugService, contextMenuService, actionProvider, focusOnContextMenu);
super(actionProvider, debugService, contextMenuService, contextKeyService);
}
protected onLeftClick(tree: ITree, element: any, eventish: ICancelableEvent, origin: string = 'mouse'): boolean {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册