<commit_before>/*
 * gui-builder - A simple WYSIWYG HTML5 app creator
 * Copyright (c) 2011, Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
"use strict";

function loadOutline(container) {
    var defaultContainer = '#outline-panel',
        myContainer = container,contents;
    if (!myContainer) {
        myContainer = $(defaultContainer);
    }
    if (!myContainer || !myContainer.get()) {
        return false;
    }

    myContainer.append('<p id="outline_header" class="ui-helper-reset ui-widget ui-widget-header">Outline</p>')
               .addClass('ui-widget-content');
    contents = $('<div id="outline_content"></div>')
        .appendTo(myContainer);

    renderOutlineView();
    // ---------------------------------------------- //
    // Now, bind to the ADM modelUpdate to handle all //
    // additional changes                             //
    // ---------------------------------------------- //
    var $admDesign = ADM.getDesignRoot();
    $admDesign.bind("modelUpdated", admModelUpdatedCallback);
    ADM.bind("designReset", admDesignResetCallback);
    ADM.bind("selectionChanged", admSelectionChangedCallback);
    ADM.bind("activePageChanged",admActivePageChangedCallback);

    //internal event handler
    function admSelectionChangedCallback(event) {
        var node, rootNode, nodeInOutline, currentNode;
        // Make sure we show the page as selected if no node is selected
        if (event === null || event.node === null) {
            node = ADM.getDesignRoot().findNodeByUid(ADM.getSelected());
            if (node === null || node === undefined) {
                node = ADM.getActivePage();
                if (node === null || node === undefined) {
                    return false;
                }
            }
        } else {
            node = event.node;
        }

        //deative state of selected before
        $('#outline-panel').find('.ui-state-active')
            .removeClass('ui-state-active');
        $('#outline-panel').find('.ui-selected')
            .removeClass('ui-selected');

        //find this node in outline pane
        rootNode = $("#pageList");
        nodeInOutline = $(rootNode).find("#Outline-"+node.getUid()+" > a");
        $(nodeInOutline).addClass('ui-state-active')
            .addClass('ui-selected');

        currentNode = nodeInOutline;
        while (currentNode && currentNode.html() !== rootNode.html())  {
            $(currentNode).show();
            currentNode = currentNode.parent();
        }
    }

    function admActivePageChangedCallback(event) {
        renderOutlineView();
    }

    function admModelUpdatedCallback(event) {
        renderOutlineView();
    }

    function admDesignResetCallback(event) {
        renderOutlineView();<commit_msg>[Outline View] enhance check whether select set is empty<commit_after>/*
 * gui-builder - A simple WYSIWYG HTML5 app creator
 * Copyright (c) 2011, Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
"use strict";

function loadOutline(container) {
    var defaultContainer = '#outline-panel',
        myContainer = container,contents;
    if (!myContainer) {
        myContainer = $(defaultContainer);
    }
    if (!myContainer || !myContainer.get()) {
        return false;
    }

    myContainer.append('<p id="outline_header" class="ui-helper-reset ui-widget ui-widget-header">Outline</p>')
               .addClass('ui-widget-content');
    contents = $('<div id="outline_content"></div>')
        .appendTo(myContainer);

    renderOutlineView();
    // ---------------------------------------------- //
    // Now, bind to the ADM modelUpdate to handle all //
    // additional changes                             //
    // ---------------------------------------------- //
    var $admDesign = ADM.getDesignRoot();
    $admDesign.bind("modelUpdated", admModelUpdatedCallback);
    ADM.bind("designReset", admDesignResetCallback);
    ADM.bind("selectionChanged", admSelectionChangedCallback);
    ADM.bind("activePageChanged",admActivePageChangedCallback);

    //internal event handler
    function admSelectionChangedCallback(event) {
        var node, rootNode, nodeInOutline, currentNode;
        // Make sure we show the page as selected if no node is selected
        if (event === null || event.node === null) {
            node = ADM.getDesignRoot().findNodeByUid(ADM.getSelected());
            if (node === null || node === undefined) {
                node = ADM.getActivePage();
                if (node === null || node === undefined) {
                    return false;
                }
            }
        } else {
            node = event.node;
        }

        //deative state of selected before
        $('#outline-panel').find('.ui-state-active')
            .removeClass('ui-state-active');
        $('#outline-panel').find('.ui-selected')
            .removeClass('ui-selected');

        //find this node in outline pane
        rootNode = $("#pageList");
        nodeInOutline = $(rootNode).find("#Outline-"+node.getUid()+" > a");
        $(nodeInOutline).addClass('ui-state-active')
            .addClass('ui-selected');

        currentNode = nodeInOutline;
        while (currentNode.length && currentNode.html() !== rootNode.html())  {
            $(currentNode).show();
            currentNode = currentNode.parent();
        }
    }

    function admActivePageChangedCallback(event) {
        renderOutlineView();
    }

    function admModelUpdatedCallback(event) {
        renderOutlineView();
    }

    function admDesignResetCallback(event) {
        renderOutlineView();
{'fraction_non_alphanumeric': 0.16142663962136578, 'fraction_numerical': 0.0030425963488843813, 'mean_word_length': 2.137327677624602, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6298148', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1540, 'n_words': 357}