Commit 914b43cb authored by caseq@chromium.org's avatar caseq@chromium.org

Web Inspector: add "Add to Watch" option to context menu on selection in source frame

https://bugs.webkit.org/show_bug.cgi?id=69924

Reviewed by Pavel Feldman.

- added 'Add to Watch' context menu item in scripts panel;
- include both default and custom items into a context menu if selection is present;

* inspector/front-end/ScriptsPanel.js:
(WebInspector.SourceFrameDelegateForScriptsPanel.prototype.suggestedFileName):
(WebInspector.SourceFrameDelegateForScriptsPanel.prototype.addToWatch):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.populateSelectionContextMenu):
(WebInspector.TextViewerDelegateForSourceFrame.prototype.populateSelectionContextMenu):
(WebInspector.SourceFrameDelegate.prototype.suggestedFileName):
(WebInspector.SourceFrameDelegate.prototype.addToWatch):
* inspector/front-end/TextViewer.js:
(WebInspector.TextViewer.prototype._contextMenu):
(WebInspector.TextViewerDelegate.prototype.populateSelectionContextMenu):
* inspector/front-end/WatchExpressionsSidebarPane.js:
(WebInspector.WatchExpressionsSidebarPane.prototype.addExpression):
(WebInspector.WatchExpressionsSidebarPane.prototype._addButtonClicked):
(WebInspector.WatchExpressionsSection.prototype.addExpression):
(WebInspector.WatchExpressionsSection.prototype.addNewExpressionAndEdit):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::showContextMenu):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@98233 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 639180c7
2011-10-17 Andrey Kosyakov <caseq@chromium.org>
Web Inspector: add "Add to Watch" option to context menu on selection in source frame
https://bugs.webkit.org/show_bug.cgi?id=69924
Reviewed by Pavel Feldman.
- added 'Add to Watch' context menu item in scripts panel;
- include both default and custom items into a context menu if selection is present;
* inspector/front-end/ScriptsPanel.js:
(WebInspector.SourceFrameDelegateForScriptsPanel.prototype.suggestedFileName):
(WebInspector.SourceFrameDelegateForScriptsPanel.prototype.addToWatch):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.populateSelectionContextMenu):
(WebInspector.TextViewerDelegateForSourceFrame.prototype.populateSelectionContextMenu):
(WebInspector.SourceFrameDelegate.prototype.suggestedFileName):
(WebInspector.SourceFrameDelegate.prototype.addToWatch):
* inspector/front-end/TextViewer.js:
(WebInspector.TextViewer.prototype._contextMenu):
(WebInspector.TextViewerDelegate.prototype.populateSelectionContextMenu):
* inspector/front-end/WatchExpressionsSidebarPane.js:
(WebInspector.WatchExpressionsSidebarPane.prototype.addExpression):
(WebInspector.WatchExpressionsSidebarPane.prototype._addButtonClicked):
(WebInspector.WatchExpressionsSection.prototype.addExpression):
(WebInspector.WatchExpressionsSection.prototype.addNewExpressionAndEdit):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::showContextMenu):
2011-10-21 Alexander Pavlov <apavlov@chromium.org>
Web Inspector: Audits hang on pages without img[src] elements
......
......@@ -121,6 +121,14 @@ WebInspector.JavaScriptSourceFrame.prototype = {
container.appendChild(tokens[i]);
parentElement.insertBefore(container, nextElement);
return container;
},
populateTextAreaContextMenu: function(contextMenu)
{
var selection = window.getSelection();
if (selection.type !== "Range" || selection.isCollapsed)
return;
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add to watch" : "Add to Watch"), this._delegate.addToWatch.bind(this._delegate, selection.toString()));
}
}
......
......@@ -1275,6 +1275,11 @@ WebInspector.SourceFrameDelegateForScriptsPanel.prototype = {
{
var names = this._scriptsPanel._folderAndDisplayNameForScriptURL(this._uiSourceCode.url);
return names.displayName || "untitled.js";
},
addToWatch: function(expression)
{
this._scriptsPanel.sidebarPanes.watchExpressions.addExpression(expression);
}
}
......
......@@ -829,7 +829,6 @@ WebInspector.SourceFrame.prototype = {
this._delegate.requestContent(this._initializeTextViewer.bind(this));
},
shouldShowPopover: function(element) { },
onShowPopover: function(element, showCallback) { },
......@@ -920,7 +919,9 @@ WebInspector.SourceFrameDelegate.prototype = {
setScriptSourceIsBeingEdited: function(inEditMode) { },
suggestedFileName: function() { }
suggestedFileName: function() { },
addToWatch: function() { }
}
/**
......
......@@ -293,12 +293,8 @@ WebInspector.TextViewer.prototype = {
var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
if (target)
this._delegate.populateLineGutterContextMenu(target.lineNumber, contextMenu);
else {
var selection = this._mainPanel._getSelection();
if (selection && !selection.isEmpty())
return; // Show default context menu for selection.
else
this._delegate.populateTextAreaContextMenu(contextMenu);
}
var fileName = this._delegate.suggestedFileName();
if (fileName)
......
......@@ -84,6 +84,12 @@ WebInspector.WatchExpressionsSidebarPane.prototype = {
this._refreshExpressionsIfNeeded();
},
addExpression: function(expression)
{
this.section.addExpression(expression);
this.expanded = true;
},
_refreshExpressionsIfNeeded: function()
{
if (this._requiresUpdate && this._visible) {
......@@ -97,7 +103,7 @@ WebInspector.WatchExpressionsSidebarPane.prototype = {
{
event.stopPropagation();
this.expanded = true;
this.section.addExpression();
this.section.addNewExpressionAndEdit();
},
_refreshButtonClicked: function(event)
......@@ -216,7 +222,14 @@ WebInspector.WatchExpressionsSection.prototype = {
this.expanded = (propertyCount != 0);
},
addExpression: function()
addExpression: function(expression)
{
this.watchExpressions.push(expression);
this.saveExpressions();
this.update();
},
addNewExpressionAndEdit: function()
{
this._newExpressionAdded = true;
this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatchExpression);
......
......@@ -106,6 +106,11 @@ void ContextMenuController::handleContextMenuEvent(Event* event)
showContextMenu(event);
}
static PassOwnPtr<ContextMenuItem> separatorItem()
{
return adoptPtr(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
}
void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenuProvider> menuProvider)
{
m_menuProvider = menuProvider;
......@@ -117,6 +122,10 @@ void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu
}
m_menuProvider->populateContextMenu(m_contextMenu.get());
if (m_hitTestResult.isSelected()) {
appendItem(*separatorItem(), m_contextMenu.get());
populate();
}
showContextMenu(event);
}
......@@ -429,11 +438,6 @@ void ContextMenuController::appendItem(ContextMenuItem& menuItem, ContextMenu* p
parentMenu->appendItem(menuItem);
}
static PassOwnPtr<ContextMenuItem> separatorItem()
{
return adoptPtr(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
}
void ContextMenuController::createAndAppendFontSubMenu(ContextMenuItem& fontMenuItem)
{
ContextMenu fontMenu;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment