debug: 'Add Log Point...' context menu action

#45128
This commit is contained in:
isidor 2018-03-16 10:50:40 +01:00
parent 1a24638ff3
commit 08ba13246f
3 changed files with 29 additions and 25 deletions

View file

@ -15,7 +15,7 @@ import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/zoneWidget';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IDebugService, IBreakpoint } from 'vs/workbench/parts/debug/common/debug';
import { IDebugService, IBreakpoint, BreakpointWidgetContext as Context } from 'vs/workbench/parts/debug/common/debug';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { once } from 'vs/base/common/functional';
import { attachInputBoxStyler, attachSelectBoxStyler } from 'vs/platform/theme/common/styler';
@ -23,23 +23,16 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
const $ = dom.$;
enum Context {
CONDITION = 0,
HIT_COUNT = 1,
LOG_MESSAGE = 2
}
export class BreakpointWidget extends ZoneWidget {
private inputBox: InputBox;
private toDispose: lifecycle.IDisposable[];
private context: Context;
private conditionInput = '';
private hitCountInput = '';
private logMessageInput = '';
private breakpoint: IBreakpoint;
constructor(editor: ICodeEditor, private lineNumber: number, private column: number,
constructor(editor: ICodeEditor, private lineNumber: number, private column: number, private context: Context,
@IContextViewService private contextViewService: IContextViewService,
@IDebugService private debugService: IDebugService,
@IThemeService private themeService: IThemeService
@ -50,6 +43,16 @@ export class BreakpointWidget extends ZoneWidget {
const uri = this.editor.getModel().uri;
this.breakpoint = this.debugService.getModel().getBreakpoints().filter(bp => bp.lineNumber === this.lineNumber && bp.column === this.column && bp.uri.toString() === uri.toString()).pop();
if (this.context === undefined) {
if (this.breakpoint && !this.breakpoint.condition && !this.breakpoint.hitCondition && this.breakpoint.logMessage) {
this.context = Context.LOG_MESSAGE;
} else if (this.breakpoint && !this.breakpoint.condition && this.breakpoint.hitCondition) {
this.context = Context.HIT_COUNT;
} else {
this.context = Context.CONDITION;
}
}
this.toDispose.push(this.debugService.getModel().onDidChangeBreakpoints(e => {
if (this.breakpoint && e.removed && e.removed.indexOf(this.breakpoint) >= 0) {
this.dispose();
@ -106,18 +109,7 @@ export class BreakpointWidget extends ZoneWidget {
protected _fillContainer(container: HTMLElement): void {
this.setCssClass('breakpoint-widget');
let selected: number;
if (this.breakpoint && !this.breakpoint.condition && !this.breakpoint.hitCondition && this.breakpoint.logMessage) {
this.context = Context.LOG_MESSAGE;
selected = 2;
} else if (this.breakpoint && !this.breakpoint.condition && this.breakpoint.hitCondition) {
this.context = Context.HIT_COUNT;
selected = 1;
} else {
this.context = Context.CONDITION;
selected = 0;
}
const selectBox = new SelectBox([nls.localize('expression', "Expression"), nls.localize('hitCount', "Hit Count"), nls.localize('logMessage', "Log Message")], selected, this.contextViewService);
const selectBox = new SelectBox([nls.localize('expression', "Expression"), nls.localize('hitCount', "Hit Count"), nls.localize('logMessage', "Log Message")], this.context, this.contextViewService);
this.toDispose.push(attachSelectBoxStyler(selectBox, this.themeService));
selectBox.render(dom.append(container, $('.breakpoint-select-container')));
selectBox.onDidSelect(e => {

View file

@ -662,9 +662,14 @@ export interface IDebugService {
}
// Editor interfaces
export enum BreakpointWidgetContext {
CONDITION = 0,
HIT_COUNT = 1,
LOG_MESSAGE = 2
}
export interface IDebugEditorContribution extends IEditorContribution {
showHover(range: Range, focus: boolean): TPromise<void>;
showBreakpointWidget(lineNumber: number, column: number): void;
showBreakpointWidget(lineNumber: number, column: number, context?: BreakpointWidgetContext): void;
closeBreakpointWidget(): void;
addLaunchConfiguration(): TPromise<any>;
}

View file

@ -31,7 +31,7 @@ import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/c
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { DebugHoverWidget } from 'vs/workbench/parts/debug/electron-browser/debugHover';
import { RemoveBreakpointAction, EditConditionalBreakpointAction, EnableBreakpointAction, DisableBreakpointAction, AddConditionalBreakpointAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { IDebugEditorContribution, IDebugService, State, IBreakpoint, EDITOR_CONTRIBUTION_ID, CONTEXT_BREAKPOINT_WIDGET_VISIBLE, IStackFrame, IDebugConfiguration, IExpression, IExceptionInfo } from 'vs/workbench/parts/debug/common/debug';
import { IDebugEditorContribution, IDebugService, State, IBreakpoint, EDITOR_CONTRIBUTION_ID, CONTEXT_BREAKPOINT_WIDGET_VISIBLE, IStackFrame, IDebugConfiguration, IExpression, IExceptionInfo, BreakpointWidgetContext } from 'vs/workbench/parts/debug/common/debug';
import { BreakpointWidget } from 'vs/workbench/parts/debug/browser/breakpointWidget';
import { ExceptionWidget } from 'vs/workbench/parts/debug/browser/exceptionWidget';
import { FloatingClickWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
@ -135,6 +135,13 @@ export class DebugEditorContribution implements IDebugEditorContribution {
() => this.debugService.addBreakpoints(uri, [{ lineNumber }])
));
actions.push(new AddConditionalBreakpointAction(AddConditionalBreakpointAction.ID, AddConditionalBreakpointAction.LABEL, this.editor, lineNumber, this.debugService, this.keybindingService));
actions.push(new Action(
'addLogPoint',
nls.localize('addLogPoint', "Add Log Point..."),
null,
true,
() => TPromise.as(this.editor.getContribution<IDebugEditorContribution>(EDITOR_CONTRIBUTION_ID).showBreakpointWidget(lineNumber, undefined, BreakpointWidgetContext.LOG_MESSAGE))
));
}
return TPromise.as(actions);
@ -346,12 +353,12 @@ export class DebugEditorContribution implements IDebugEditorContribution {
// end hover business
// breakpoint widget
public showBreakpointWidget(lineNumber: number, column: number): void {
public showBreakpointWidget(lineNumber: number, column: number, context?: BreakpointWidgetContext): void {
if (this.breakpointWidget) {
this.breakpointWidget.dispose();
}
this.breakpointWidget = this.instantiationService.createInstance(BreakpointWidget, this.editor, lineNumber, column);
this.breakpointWidget = this.instantiationService.createInstance(BreakpointWidget, this.editor, lineNumber, column, context);
this.breakpointWidget.show({ lineNumber, column: 1 }, 2);
this.breakpointWidgetVisible.set(true);
}