From 37f4efccea426c06f34cd2cb13699c5a3db9d539 Mon Sep 17 00:00:00 2001 From: Jason Laster Date: Wed, 23 Mar 2016 07:22:00 +0100 Subject: [PATCH] Bug 900763 - "edit conditional breakpoint". r=jlong This patch updates the Source Editor contextmenu's UX. Prior to the patch, the menu would show the option "Add conditional breakpoint" even when there was a conditional breakpoint. Now, that option reads "Edit conditional breakpoint". --- .../debugger/content/views/sources-view.js | 27 +++++++++++++++++++ devtools/client/debugger/debugger-view.js | 2 +- devtools/client/debugger/debugger.xul | 4 +++ devtools/client/locales/en-US/debugger.dtd | 5 ++++ devtools/client/sourceeditor/editor.js | 2 ++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/devtools/client/debugger/content/views/sources-view.js b/devtools/client/debugger/content/views/sources-view.js index 20517b3c77bf..365599f3d699 100644 --- a/devtools/client/debugger/content/views/sources-view.js +++ b/devtools/client/debugger/content/views/sources-view.js @@ -63,6 +63,7 @@ function SourcesView(controller, DebuggerView) { this._onConditionalPopupShown = this._onConditionalPopupShown.bind(this); this._onConditionalPopupHiding = this._onConditionalPopupHiding.bind(this); this._onConditionalTextboxKeyPress = this._onConditionalTextboxKeyPress.bind(this); + this._onEditorContextMenuOpen = this._onEditorContextMenuOpen.bind(this); this._onCopyUrlCommand = this._onCopyUrlCommand.bind(this); this._onNewTabCommand = this._onNewTabCommand.bind(this); } @@ -134,6 +135,8 @@ SourcesView.prototype = Heritage.extend(WidgetMethods, { return (a in KNOWN_SOURCE_GROUPS) ? 1 : -1; }; + this.DebuggerView.editor.on("popupOpen", this._onEditorContextMenuOpen); + this._addCommands(); }, @@ -151,6 +154,7 @@ SourcesView.prototype = Heritage.extend(WidgetMethods, { this._cbTextbox.removeEventListener("keypress", this._onConditionalTextboxKeyPress, false); this._copyUrlMenuItem.removeEventListener("command", this._onCopyUrlCommand, false); this._newTabMenuItem.removeEventListener("command", this._onNewTabCommand, false); + this.DebuggerView.editor.off("popupOpen", this._onEditorContextMenuOpen, false); }, empty: function() { @@ -1077,6 +1081,29 @@ SourcesView.prototype = Heritage.extend(WidgetMethods, { this.actions.blackbox(getSelectedSource(this.getState()), false); }), + /** + * The source editor's contextmenu handler. + * - Toggles "Add Conditional Breakpoint" and "Edit Conditional Breakpoint" items + */ + _onEditorContextMenuOpen: function(message, ev, popup) { + let actor = this.selectedValue; + let line = this.DebuggerView.editor.getCursor().line + 1; + let location = { actor, line }; + + let breakpoint = getBreakpoint(this.getState(), location); + let addConditionalBreakpointMenuItem = popup.querySelector("#se-dbg-cMenu-addConditionalBreakpoint"); + let editConditionalBreakpointMenuItem = popup.querySelector("#se-dbg-cMenu-editConditionalBreakpoint"); + + if (breakpoint && !!breakpoint.condition) { + editConditionalBreakpointMenuItem.removeAttribute("hidden"); + addConditionalBreakpointMenuItem.setAttribute("hidden", true); + } + else { + addConditionalBreakpointMenuItem.removeAttribute("hidden"); + editConditionalBreakpointMenuItem.setAttribute("hidden", true); + } + }, + /** * The click listener for a breakpoint container. */ diff --git a/devtools/client/debugger/debugger-view.js b/devtools/client/debugger/debugger-view.js index e1cabb875be4..e4b33f7663ad 100644 --- a/devtools/client/debugger/debugger-view.js +++ b/devtools/client/debugger/debugger-view.js @@ -67,6 +67,7 @@ var DebuggerView = { this._startup = deferred.promise; this._initializePanes(); + this._initializeEditor(deferred.resolve); this.Toolbar.initialize(); this.Options.initialize(); this.Filtering.initialize(); @@ -80,7 +81,6 @@ var DebuggerView = { this.GlobalSearch.initialize(); this._initializeVariablesView(); - this._initializeEditor(deferred.resolve); this._editorSource = {}; document.title = L10N.getStr("DebuggerWindowTitle"); diff --git a/devtools/client/debugger/debugger.xul b/devtools/client/debugger/debugger.xul index 06b964184a7c..1fb2da2e29a5 100644 --- a/devtools/client/debugger/debugger.xul +++ b/devtools/client/debugger/debugger.xul @@ -54,6 +54,10 @@ label="&debuggerUI.seMenuCondBreak;" key="addConditionalBreakpointKey" command="addConditionalBreakpointCommand"/> + + + + + diff --git a/devtools/client/sourceeditor/editor.js b/devtools/client/sourceeditor/editor.js index 62ce48884966..7e9f21717503 100644 --- a/devtools/client/sourceeditor/editor.js +++ b/devtools/client/sourceeditor/editor.js @@ -337,6 +337,8 @@ Editor.prototype = { if (typeof popup == "string") { popup = el.ownerDocument.getElementById(this.config.contextMenu); } + + this.emit("popupOpen", ev, popup); popup.openPopupAtScreen(ev.screenX, ev.screenY, true); }, false);