Title: [185720] trunk/Source/WebInspectorUI
Revision
185720
Author
[email protected]
Date
2015-06-18 13:44:01 -0700 (Thu, 18 Jun 2015)

Log Message

Web Inspector: Ability to Copy entire CSS Rule from Styles Sidebar
https://bugs.webkit.org/show_bug.cgi?id=138812

Patch by Devin Rousso <[email protected]> on 2015-06-18
Reviewed by Timothy Hatcher.

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Views/CSSStyleDeclarationSection.js:
(WebInspector.CSSStyleDeclarationSection): Right clicking on the header of a rule will replcae the default context menu to allow copying of the entire rule to the clipboard.
(WebInspector.CSSStyleDeclarationSection.prototype._handleContextMenuEvent): Creates a new context menu to copy the entire CSS rule.
(WebInspector.CSSStyleDeclarationSection.prototype._generateCSSRuleString): Generates a string representing the formatted CSS rule.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (185719 => 185720)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-06-18 20:29:37 UTC (rev 185719)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-06-18 20:44:01 UTC (rev 185720)
@@ -1,3 +1,16 @@
+2015-06-18  Devin Rousso  <[email protected]>
+
+        Web Inspector: Ability to Copy entire CSS Rule from Styles Sidebar
+        https://bugs.webkit.org/show_bug.cgi?id=138812
+
+        Reviewed by Timothy Hatcher.
+
+        * Localizations/en.lproj/localizedStrings.js:
+        * UserInterface/Views/CSSStyleDeclarationSection.js:
+        (WebInspector.CSSStyleDeclarationSection): Right clicking on the header of a rule will replcae the default context menu to allow copying of the entire rule to the clipboard.
+        (WebInspector.CSSStyleDeclarationSection.prototype._handleContextMenuEvent): Creates a new context menu to copy the entire CSS rule.
+        (WebInspector.CSSStyleDeclarationSection.prototype._generateCSSRuleString): Generates a string representing the formatted CSS rule.
+
 2015-06-18  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Improve a few more node preview types

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (185719 => 185720)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2015-06-18 20:29:37 UTC (rev 185719)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2015-06-18 20:44:01 UTC (rev 185720)
@@ -127,7 +127,8 @@
 localizedStrings["Cookies"] = "Cookies";
 localizedStrings["Copy Path to Property"] = "Copy Path to Property";
 localizedStrings["Copy Row"] = "Copy Row";
-localizedStrings["Copy as HTML"] = "Copy as HTML";
+localizedStrings["Copy gs["New TaCopy = "New Tab";
+localizedStrCopy as HTML"] = "Copy as HTML";
 localizedStrings["Could not fetch properties. Object may no longer exist."] = "Could not fetch properties. Object may no longer exist.";
 localizedStrings["Create a new tab"] = "Create a new tab";
 localizedStrings["Data"] = "Data";

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js (185719 => 185720)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2015-06-18 20:29:37 UTC (rev 185719)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2015-06-18 20:44:01 UTC (rev 185720)
@@ -106,6 +106,8 @@
     }
 
     this.refresh();
+
+    this._headerElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this));
 };
 
 WebInspector.CSSStyleDeclarationSection.LockedStyleClassName = "locked";
@@ -290,6 +292,57 @@
 
     // Private
 
+    _handleContextMenuEvent: function(event)
+    {
+        if (window.getSelection().toString().length)
+            return;
+
+        var contextMenu = new WebInspector.ContextMenu(event);
+
+        contextMenu.appendItem(WebInspector.UIString("Copy Rule"), function() {
+            InspectorFrontendHost.copyText(this._generateCSSRuleString());
+        }.bind(this));
+
+        contextMenu.show();
+    },
+
+    _generateCSSRuleString: function()
+    {
+        var numMediaQueries = 0;
+        var styleText = "";
+
+        if (this._style.ownerRule) {
+            var mediaList = this._style.ownerRule.mediaList;
+            if (mediaList.length) {
+                numMediaQueries = mediaList.length;
+
+                for (var i = numMediaQueries - 1; i >= 0; --i)
+                    styleText += "    ".repeat(numMediaQueries - i - 1) + "@media " + mediaList[i].text + " {\n";
+            }
+
+            styleText += "    ".repeat(numMediaQueries) + this._style.ownerRule.selectorText;
+        } else
+            styleText += this._selectorElement.textContent;
+
+        styleText += " {\n";
+
+        for (var property of this._style.properties) {
+            styleText += "    ".repeat(numMediaQueries + 1) + property.text.trim();
+
+            if (!styleText.endsWith(";"))
+                styleText += ";";
+
+            styleText += "\n";
+        }
+
+        for (var i = numMediaQueries; i > 0; --i)
+            styleText += "    ".repeat(i) + "}\n";
+
+        styleText += "}";
+
+        return styleText;
+    },
+
     _commitSelector: function(mutations)
     {
         console.assert(this._style.ownerRule);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to