⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 185720 in webkit


Ignore:
Timestamp:
Jun 18, 2015, 1:44:01 PM (11 years ago)
Author:
commit-queue@webkit.org
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 <Devin Rousso> 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.

Location:
trunk/Source/WebInspectorUI
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r185716 r185720  
     12015-06-18  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Ability to Copy entire CSS Rule from Styles Sidebar
     4        https://bugs.webkit.org/show_bug.cgi?id=138812
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * Localizations/en.lproj/localizedStrings.js:
     9        * UserInterface/Views/CSSStyleDeclarationSection.js:
     10        (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.
     11        (WebInspector.CSSStyleDeclarationSection.prototype._handleContextMenuEvent): Creates a new context menu to copy the entire CSS rule.
     12        (WebInspector.CSSStyleDeclarationSection.prototype._generateCSSRuleString): Generates a string representing the formatted CSS rule.
     13
    1142015-06-18  Joseph Pecoraro  <pecoraro@apple.com>
    215
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r185255 r185720  
    128128localizedStrings["Copy Path to Property"] = "Copy Path to Property";
    129129localizedStrings["Copy Row"] = "Copy Row";
    130 localizedStrings["Copy as HTML"] = "Copy as HTML";
     130localizedStrings["Copy gs["New TaCopy = "New Tab";
     131localizedStrCopy as HTML"] = "Copy as HTML";
    131132localizedStrings["Could not fetch properties. Object may no longer exist."] = "Could not fetch properties. Object may no longer exist.";
    132133localizedStrings["Create a new tab"] = "Create a new tab";
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js

    r185279 r185720  
    107107
    108108    this.refresh();
     109
     110    this._headerElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this));
    109111};
    110112
     
    291293    // Private
    292294
     295    _handleContextMenuEvent: function(event)
     296    {
     297        if (window.getSelection().toString().length)
     298            return;
     299
     300        var contextMenu = new WebInspector.ContextMenu(event);
     301
     302        contextMenu.appendItem(WebInspector.UIString("Copy Rule"), function() {
     303            InspectorFrontendHost.copyText(this._generateCSSRuleString());
     304        }.bind(this));
     305
     306        contextMenu.show();
     307    },
     308
     309    _generateCSSRuleString: function()
     310    {
     311        var numMediaQueries = 0;
     312        var styleText = "";
     313
     314        if (this._style.ownerRule) {
     315            var mediaList = this._style.ownerRule.mediaList;
     316            if (mediaList.length) {
     317                numMediaQueries = mediaList.length;
     318
     319                for (var i = numMediaQueries - 1; i >= 0; --i)
     320                    styleText += "    ".repeat(numMediaQueries - i - 1) + "@media " + mediaList[i].text + " {\n";
     321            }
     322
     323            styleText += "    ".repeat(numMediaQueries) + this._style.ownerRule.selectorText;
     324        } else
     325            styleText += this._selectorElement.textContent;
     326
     327        styleText += " {\n";
     328
     329        for (var property of this._style.properties) {
     330            styleText += "    ".repeat(numMediaQueries + 1) + property.text.trim();
     331
     332            if (!styleText.endsWith(";"))
     333                styleText += ";";
     334
     335            styleText += "\n";
     336        }
     337
     338        for (var i = numMediaQueries; i > 0; --i)
     339            styleText += "    ".repeat(i) + "}\n";
     340
     341        styleText += "}";
     342
     343        return styleText;
     344    },
     345
    293346    _commitSelector: function(mutations)
    294347    {
Note: See TracChangeset for help on using the changeset viewer.