<commit_before>/*
 * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 *  
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window, Mustache, less, setTimeout */

define(function (require, exports, module) {
    "use strict";
    
    // Modules
    var webfont                 = require("webfont"),
        parser                  = require("cssFontParser"),
        ewfBrowseDialogHtml     = require("text!htmlContent/ewf-browse-dialog.html"),
        ewfIncludeDialogHtml    = require("text!htmlContent/ewf-include-dialog.html"),
        ewfHowtoDialogHtml      = require("text!htmlContent/ewf-howto-dialog.html"),
        ewfToolbarHtml          = require("text!htmlContent/ewf-toolbar.html"),
        ewfCodeHintAdditionHtml = require("text!htmlContent/ewf-codehint-addition.html"),
        Strings                 = require("strings");

    var AppInit                 = brackets.getModule("utils/AppInit"),
        ExtensionUtils          = brackets.getModule("utils/ExtensionUtils"),
        StringUtils             = brackets.getModule("utils/StringUtils"),
        DocumentManager         = brackets.getModule("document/DocumentManager"),
        EditorManager           = brackets.getModule("editor/EditorManager"),
        EditorUtils             = brackets.getModule("editor/EditorUtils"),
        PreferencesManager      = brackets.getModule("preferences/PreferencesManager"),
        CodeHintManager         = brackets.getModule("editor/CodeHintManager"),
        CommandManager          = brackets.getModule("command/CommandManager"),
        Commands                = brackets.getModule("command/Commands"),
        Dialogs                 = brackets.getModule("widgets/Dialogs"),
        Menus                   = brackets.getModule("command/Menus");
    
    // DOM elements and HTML
    var $toolbarIcon = null;
    // Because of the way pop ups work, we need to create a new code hint addition every time 
    // we have a new popup. But, we only need to render the HTML once.
    var codeHintAdditionHtmlString = Mustache.render(ewfCodeHintAdditionHtml, Strings);
    
    var Paths = {
        ROOT : require.toUrl('./')
    };
    
    // Commands & Prefs Strings
    var COMMAND_BROWSE_FONTS = "edgewebfonts.browsefonts";
    var COMMAND_GENERATE_INCLUDE = "edgewebfonts.generateinclude";
    var PREFERENCES_CLIENT_ID = "com.adobe.edgewebfonts";
    var PREFERENCES_FONT_HISTORY_KEY = "ewf-font-history";
    
    // Local variables
    var lastFontSelected = null;
    var lastTwentyFonts = [];
    var prefs = {};
    var whitespaceRegExp = new RegExp("\\s");
    
    function _documentIsCSS(doc) {
        return doc && EditorUtils.getModeFromFileExtension(doc.file.fullPath) === "css";
    }
    
    /** Adds an option to browse EWF to the bottom of the code hint list
     *
     *  TODO: Add an API to either CodeHintManager or PopUpManager so that we
     *  can add UI in a much cleaner way. Once we do that, clean up the
     *  LESS so that we aren't overriding core brackets LESS (e.g. to change
     *  the code hint border).
     *
     *  NOTE: It is **required** that we have a CSS rule that causes the DOM elements
     *  here to be hidden when the menu does *not* have the "open" class applied.
     *  This is because PopUpManager checks whether a popup is closed by checking if 
     *  it has any visible children. PopUps don't always get removed from the DOM right 
     *  when they're closed. If we don't have this rule we get infinite recursion in PopUpManager.
     *
     *  TODO: Write a unit test to check the code hint menu dom structure. This way, 
     *  if the code hint UI gets reorganized, the unit test will catch it. 
     */
    function _augmentCodeHintUI() {

        function repositionAddition(list, addition) {
            var menuListPosition = list.position();
            addition.css("position", "absolute");
            addition.css("top", menuListPosition.top + list.height());
            addition.css("left", menuListPosition.left);
            addition.css("width", list.width());
            addition.css("max-width", list.width());
        }

        var $menu = $(".dropdown.codehint-menu.open");

        if ($menu.length > 0) {
            var $menuList = $menu.find(".dropdown-menu");
            if ($menuList.length > 0) { // we're actually displaying a code hint
                // Since this dropdown menu has an addition, we need to add a class that
                // removes the rounded corners on the bottom
                $menuList.addClass("has-addition");
                
                var $codeHintAddition = $menu.find(".ewf-codehint-addition");
                
                // If this is a new popup, we won't have a code hint addition yet (new popup), 
                // so create it first
                if ($codeHintAddition.length === 0) {
                    $codeHintAddition = $(codeHintAdditionHtmlString);
                    repositionAddition($menuList, $codeHintAddition);
                    $menuList.after($codeHintAddition);
                    $codeHintAddition.find('a').on('click', function () {
                        CommandManager.execute(COMMAND_BROWSE_FONTS);
                        return false; // don't actually follow link
                    });
                } else {
                    // This method only gets called when the pop up has changed in some way<commit_msg>rename helper function parameters to reflect their jQuery type<commit_after>/*
 * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the 
 * Software is furnished to do so, subject to the following conditions:
 *  
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window, Mustache, less, setTimeout */

define(function (require, exports, module) {
    "use strict";
    
    // Modules
    var webfont                 = require("webfont"),
        parser                  = require("cssFontParser"),
        ewfBrowseDialogHtml     = require("text!htmlContent/ewf-browse-dialog.html"),
        ewfIncludeDialogHtml    = require("text!htmlContent/ewf-include-dialog.html"),
        ewfHowtoDialogHtml      = require("text!htmlContent/ewf-howto-dialog.html"),
        ewfToolbarHtml          = require("text!htmlContent/ewf-toolbar.html"),
        ewfCodeHintAdditionHtml = require("text!htmlContent/ewf-codehint-addition.html"),
        Strings                 = require("strings");

    var AppInit                 = brackets.getModule("utils/AppInit"),
        ExtensionUtils          = brackets.getModule("utils/ExtensionUtils"),
        StringUtils             = brackets.getModule("utils/StringUtils"),
        DocumentManager         = brackets.getModule("document/DocumentManager"),
        EditorManager           = brackets.getModule("editor/EditorManager"),
        EditorUtils             = brackets.getModule("editor/EditorUtils"),
        PreferencesManager      = brackets.getModule("preferences/PreferencesManager"),
        CodeHintManager         = brackets.getModule("editor/CodeHintManager"),
        CommandManager          = brackets.getModule("command/CommandManager"),
        Commands                = brackets.getModule("command/Commands"),
        Dialogs                 = brackets.getModule("widgets/Dialogs"),
        Menus                   = brackets.getModule("command/Menus");
    
    // DOM elements and HTML
    var $toolbarIcon = null;
    // Because of the way pop ups work, we need to create a new code hint addition every time 
    // we have a new popup. But, we only need to render the HTML once.
    var codeHintAdditionHtmlString = Mustache.render(ewfCodeHintAdditionHtml, Strings);
    
    var Paths = {
        ROOT : require.toUrl('./')
    };
    
    // Commands & Prefs Strings
    var COMMAND_BROWSE_FONTS = "edgewebfonts.browsefonts";
    var COMMAND_GENERATE_INCLUDE = "edgewebfonts.generateinclude";
    var PREFERENCES_CLIENT_ID = "com.adobe.edgewebfonts";
    var PREFERENCES_FONT_HISTORY_KEY = "ewf-font-history";
    
    // Local variables
    var lastFontSelected = null;
    var lastTwentyFonts = [];
    var prefs = {};
    var whitespaceRegExp = new RegExp("\\s");
    
    function _documentIsCSS(doc) {
        return doc && EditorUtils.getModeFromFileExtension(doc.file.fullPath) === "css";
    }
    
    /** Adds an option to browse EWF to the bottom of the code hint list
     *
     *  TODO: Add an API to either CodeHintManager or PopUpManager so that we
     *  can add UI in a much cleaner way. Once we do that, clean up the
     *  LESS so that we aren't overriding core brackets LESS (e.g. to change
     *  the code hint border).
     *
     *  NOTE: It is **required** that we have a CSS rule that causes the DOM elements
     *  here to be hidden when the menu does *not* have the "open" class applied.
     *  This is because PopUpManager checks whether a popup is closed by checking if 
     *  it has any visible children. PopUps don't always get removed from the DOM right 
     *  when they're closed. If we don't have this rule we get infinite recursion in PopUpManager.
     *
     *  TODO: Write a unit test to check the code hint menu dom structure. This way, 
     *  if the code hint UI gets reorganized, the unit test will catch it. 
     */
    function _augmentCodeHintUI() {

        function repositionAddition($list, $addition) {
            var menuListPosition = $list.position();
            $addition.css("position", "absolute");
            $addition.css("top", menuListPosition.top + $list.height());
            $addition.css("left", menuListPosition.left);
            $addition.css("width", $list.width());
            $addition.css("max-width", $list.width());
        }

        var $menu = $(".dropdown.codehint-menu.open");

        if ($menu.length > 0) {
            var $menuList = $menu.find(".dropdown-menu");
            if ($menuList.length > 0) { // we're actually displaying a code hint
                // Since this dropdown menu has an addition, we need to add a class that
                // removes the rounded corners on the bottom
                $menuList.addClass("has-addition");
                
                var $codeHintAddition = $menu.find(".ewf-codehint-addition");
                
                // If this is a new popup, we won't have a code hint addition yet (new popup), 
                // so create it first
                if ($codeHintAddition.length === 0) {
                    $codeHintAddition = $(codeHintAdditionHtmlString);
                    repositionAddition($menuList, $codeHintAddition);
                    $menuList.after($codeHintAddition);
                    $codeHintAddition.find('a').on('click', function () {
                        CommandManager.execute(COMMAND_BROWSE_FONTS);
                        return false; // don't actually follow link
                    });
                } else {
                    // This method only gets called when the pop up has changed in some way
{'fraction_non_alphanumeric': 0.09150573325286662, 'fraction_numerical': 0.0015087507543753772, 'mean_word_length': 2.4018475750577366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '427408', 'n_tokens_mistral': 3635, 'n_tokens_neox': 3337, 'n_words': 1191}