Permalink
Browse files

Issue 6422: Add a right click option for accessing objects in the Com…

  • Loading branch information...
1 parent 007f999 commit 6fe3c3c1c66fd8ec482ff4d49ac31108c756d10f @simonlindholm simonlindholm committed May 9, 2013
@@ -1347,7 +1347,10 @@ var FirebugChrome =
obeyOmitObjectPathStack: function(value)
{
var panelStatus = this.getElementById("fbPanelStatus");
- Dom.hide(panelStatus, (value?true:false));
+ // The element does not exist immediately at start-up.
+ if (!panelStatus)
+ return;
+ Dom.hide(panelStatus, (value ? true : false));
},
getPanelStatusElements: function()
@@ -1564,9 +1567,7 @@ var FirebugChrome =
var items = [];
Events.dispatch(Firebug.uiListeners, "onContextMenu", [items, object, target,
Firebug.currentContext, panel, popup]);
-
- if (items)
- Menu.createMenuItems(popup, items);
+ Menu.createMenuItems(popup, items);
if (!popup.firstChild)
return false;
@@ -129,7 +129,8 @@ FirebugReps.Nada = domplate(Firebug.Rep,
FirebugReps.Number = domplate(Firebug.Rep,
{
- tag: OBJECTBOX("$object"),
+ tag: OBJECTBOX({"_repObject": "$object"}, "$object"),
+ tinyTag: OBJECTBOX("$object"),
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -151,9 +152,10 @@ FirebugReps.Number = domplate(Firebug.Rep,
var reSpecialWhitespace = / |[\t\n]/;
FirebugReps.SpecialWhitespaceString = domplate(Firebug.Rep,
{
- tag: PREOBJECTBOX(""$object""),
+ tag: PREOBJECTBOX({"_repObject": "$object"}, ""$object""),
- shortTag: OBJECTBOX(""$object|cropMultipleLines""),
+ shortTag: OBJECTBOX({"_repObject": "$object"}, ""$object|cropMultipleLines""),
+ tinyTag: OBJECTBOX(""$object|cropMultipleLines""),
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -167,9 +169,10 @@ FirebugReps.SpecialWhitespaceString = domplate(Firebug.Rep,
FirebugReps.String = domplate(Firebug.Rep,
{
- tag: OBJECTBOX(""$object""),
+ tag: OBJECTBOX({"_repObject": "$object"}, ""$object""),
- shortTag: OBJECTBOX(""$object|cropMultipleLines""),
+ shortTag: OBJECTBOX({"_repObject": "$object"}, ""$object|cropMultipleLines""),
+ tinyTag: OBJECTBOX(""$object|cropMultipleLines""),
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -476,7 +479,7 @@ FirebugReps.Obj = domplate(Firebug.Rep,
if (filter(t, value))
{
var rep = Firebug.getRep(value);
- var tag = rep.shortTag || rep.tag;
+ var tag = rep.tinyTag || rep.shortTag || rep.tag;
if ((t == "object" || t == "function") && value)
{
value = rep.getTitle(value);
@@ -2163,6 +2166,7 @@ FirebugReps.CompilationUnit = domplate(FirebugReps.SourceLink,
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
className: "CompilationUnit",
+ inspectable: false,
supportsObject: function(object, type)
{
@@ -12,9 +12,11 @@ define([
"firebug/lib/dom",
"firebug/chrome/firefox",
"firebug/chrome/window",
+ "firebug/chrome/menu",
"firebug/lib/system",
"firebug/lib/string",
"firebug/lib/persist",
+ "firebug/js/sourceLink",
"firebug/console/console",
"firebug/console/commandLineExposed",
"firebug/console/closureInspector",
@@ -24,8 +26,8 @@ define([
"firebug/console/commandLineHelp",
"firebug/console/commandLineInclude",
],
-function(Obj, Firebug, FirebugReps, Locale, Events, Url, Dom, Firefox, Win, System, Str, Persist,
- Console, CommandLineExposed, ClosureInspector, CommandLineAPI) {
+function(Obj, Firebug, FirebugReps, Locale, Events, Url, Dom, Firefox, Win, Menu, System, Str,
+ Persist, SourceLink, Console, CommandLineExposed, ClosureInspector, CommandLineAPI) {
"use strict";
// ********************************************************************************************* //
@@ -460,6 +462,7 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
initialize: function()
{
Firebug.Module.initialize.apply(this, arguments);
+ Firebug.registerUIListener(this);
this.setAutoCompleter();
this.commandHistory = new Firebug.CommandHistory();
@@ -525,6 +528,8 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
Events.removeEventListener(commandLine, "keyup", this.onCommandLineKeyUp, true);
Events.removeEventListener(commandLine, "keydown", this.onCommandLineKeyDown, true);
Events.removeEventListener(commandLine, "keypress", this.onCommandLineKeyPress, true);
+
+ Firebug.unregisterUIListener(this);
},
destroyContext: function(context, persistedState)
@@ -694,6 +699,65 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
Dom.collapse(Firebug.chrome.$("fbSidePanelDeck"), true);
},
+ onContextMenu: function(items, object, target, context, panel, popup)
+ {
+ if (typeof object === "boolean" || object === undefined || object === null)
+ return;
+
+ var rep = Firebug.getRep(object, context);
+ object = rep && rep.getRealObject(object, context);
+
+ if (!rep || !rep.inspectable || object instanceof SourceLink.SourceLink)
+ return;
+
+ var hasConsole = !!context.getPanel("console", true);
+
+ function useInCommandLine()
+ {
+ context.rememberedObject = object;
+
+ var panel = Firebug.chrome.getSelectedPanel();
+ if (!hasConsole)
+ Firebug.chrome.selectPanel("console");
+ else if (panel && panel.name != "console" && !Firebug.CommandLine.Popup.isVisible())
+ Firebug.CommandLine.Popup.toggle(context);
+
+ var commandLine = this.getCommandLine(context);
+
+ var valueLength = commandLine.value.length, ins = "$p";
+
+ commandLine.value += ins;
+ commandLine.focus();
+ commandLine.setSelectionRange(valueLength, valueLength + ins.length);
+
+ this.autoCompleter.hide();
+ this.update(context);
+ }
+
+ var item = {
+ label: "commandline.Use_in_Command_Line",
+ tooltiptext: "commandline.tip.Use_in_Command_Line",
+ id: "fbUseInCommandLine",
+ command: useInCommandLine.bind(this)
+ };
+
+ // Add the item before the first "Inspect in * Panel" option (or at the bottom together with
+ // a separator if there is none).
+ var before = Array.prototype.filter.call(popup.childNodes, function(node) {
+ return Str.hasPrefix(node.id, "InspectIn");
+ })[0];
+ if (!before)
+ Menu.createMenuSeparator(popup);
+ Menu.createMenuItem(popup, item, before);
+ },
+
+ getAccessorVars: function(context)
+ {
+ return {
+ "$p": context.rememberedObject
+ };
+ },
+
getCommandLine: function(context)
{
return (!this.isInOtherPanel(context) && Firebug.commandEditor) ?
@@ -25,23 +25,23 @@ var commandLineCache = new WeakMap();
// Command Line APIs
// List of command line APIs
-var commandNames = ["$", "$$", "$x", "$n", "cd", "clear", "inspect", "keys",
+var commandNames = ["$", "$$", "$n", "$x", "cd", "clear", "inspect", "keys",
"values", "debug", "undebug", "monitor", "unmonitor", "traceCalls", "untraceCalls",
"traceAll", "untraceAll", "copy" /*, "memoryProfile", "memoryProfileEnd"*/];
// List of shortcuts for some console methods
var consoleShortcuts = ["dir", "dirxml", "table"];
// List of console variables.
-var props = ["$0", "$1"];
+var props = ["$0", "$1", "$p"];
// Registered commands, name -> config object.
var userCommands = Object.create(null);
// List of command line APIs to auto-complete, kept equal to the concatenation
// of the above minus trace*.
var completionList = [
- "$", "$$", "$x", "$n", "cd", "clear", "inspect", "keys",
+ "$", "$$", "$n", "$x", "cd", "clear", "inspect", "keys",
"values", "debug", "undebug", "monitor", "unmonitor", "copy"
].concat(consoleShortcuts, props);
@@ -445,6 +445,10 @@ function updateVars(commandLine, dglobal, context)
for (var prop in vars)
commandLine[prop] = dglobal.makeDebuggeeValue(vars[prop]);
+
+ vars = Firebug.CommandLine.getAccessorVars(context);
+ for (var prop in vars)
+ commandLine[prop] = dglobal.makeDebuggeeValue(vars[prop]);
}
function removeConflictingNames(commandLine, context, contentView)
@@ -210,11 +210,10 @@ Firebug.DOMBasePanel.prototype = Obj.extend(Firebug.Panel,
supportsObject: function(object, type)
{
+ if (type == "number" || type == "string" || type == "boolean")
+ return 0;
if (object == null)
return 1000;
-
- if (typeof object === "undefined")
- return 1000;
else if (object instanceof SourceLink.SourceLink)
return 0;
else
@@ -832,6 +832,11 @@ console.multiHighlightLimitExceeded=There are too many elements in the array to
# that causes to switch to HTML rendering of the document.
commandline.disabledForXMLDocs=Firebug command line is disabled for XML pages. You can <a>switch to HTML</a> to enable it.
+# LOCALIZATION NOTE (commandline.Use_in_Command_Line): Right-click option for copying a JS value into the variable
+# $p and opening the Command Line.
+commandline.Use_in_Command_Line=Use in Command Line
+commandline.tip.Use_in_Command_Line=Focus the Command Line, and make this value available as "$p"
+
# LOCALIZATION NOTE (commandline.include.includeSuccess): For the include() function. This message is displayed
# in the Console panel when a remote script evaluation succeeded
# %S = the filename

0 comments on commit 6fe3c3c

Please sign in to comment.