<commit_before>class EditorController {
    constructor(appData) {
        console.log('EditorController.constructor');
        this.appData = appData;
        this.tree      = null;
        this.docs      = null;
        this.listeners = {};
        this.pg = null;
        this.appCtrl = null;
        EditorController.editorController = this;
    }

    init() {
        console.log('EditorController.init', this.appData);

        // tree
        this.tree = document.getElementById('tree')._obj;
        this.tree.on('doubleClick', this.listeners.doubleClick = this.onItemDoubleClick.bind(this));
        this.tree.on('select'     , this.listeners.select      = this.onItemSelect.bind(this));
        this.tree.on('open'       , this.listeners.open        = this.onItemOpen.bind(this));
        this.tree.on('delete'     , this.listeners.delete      = this.onItemDelete.bind(this));

        // docs
        this.docs = document.getElementById('docs')._obj;
        this.docs.on('tabClosingByUser', this.listeners.tabClosingByUser = this.onTabClosingByUser.bind(this));

        // appItem
        const caption = ApplicationController.prototype.getCaption(this.appData);
        const appModel = new Application(this.appData);
        appModel.init();
        console.log('appModel:', appModel);
        const appItem = this.tree.addItem(caption, 'opened');
        this.appCtrl = appItem.ctrl = new ApplicationController(appModel, appItem, this);
        appItem.ctrl.createTree();

        // view
        Helper.createReactComponent(document.getElementById('root2'), EditorView, {ctrl: this});
    }

    deinit() {
        this.tree.off('doubleClick'     , this.listeners.doubleClick);
        this.tree.off('select'          , this.listeners.select);
        this.tree.off('open'            , this.listeners.open);
        this.tree.off('delete'          , this.listeners.delete);
        this.docs.off('tabClosingByUser', this.listeners.tabClosingByUser);
    }

    onItemOpen(e) {
        if (e.item.ctrl instanceof PageLinkController) {
            this.pageLinkToPage(e.item);
        }
    }
    onItemOpen2(item) {
        console.log('EditorController.onItemOpen2', item);
    }
    async onItemSelect(e) {
        console.log('EditorController.onItemSelect');
        if (e.item.ctrl) {
            if (e.item.ctrl instanceof PageLinkController) {
                await this.pageLinkToPage(e.item);
            }
            this.fillActions(e.item.ctrl);
            this.fillPropertyGrid(e.item.ctrl);
        } else {
            this.clearActions();
            this.endEdit();
        }
    }

    onItemSelect2 = async item => {
        console.log('EditorController.onItemSelect2', item);
        if (item.ctrl) {
            this.fillActions(item.ctrl);
            this.fillPropertyGrid(item.ctrl);
        } else {
            this.clearActions();
            this.endEdit();
        }
    }
    clearActions() {
        $('#treeActionsList').children().remove();
        $('#treeActionsList').append("<li class='disabled'><a href='#'>none</a></li>");
    }

    fillPropertyGrid(ctrl) {
        const propList = ctrl.getPropList();
        this.beginEdit(propList['list'], propList['options']);
    }

    onPropertyGrid2Change = (name, value) => {
        console.log('EditorController.onPropertyGrid2Change', name, value);
        this.tree.active.ctrl.setProperty(name, value);
    }

    beginEdit(obj, options) {
        console.log('EditorController.beginEdit', obj, options);
        this.pg.setState({object: {obj, options}});
    }

    endEdit() {
        console.log('EditorController.endEdit');
        this.pg.setState({object: null});
    }

    async pageLinkToPage(item) {
        console.log('EditorController.pageLinkToPage');
        const pageLink = item.ctrl.model;

        const pageData = await QForms.doHttpRequest({
            controller: 'Page',
            action    : 'get',
            params    : Helper.encodeObject({
                fileName: pageLink.data['@attributes'].fileName
            })
        });
        const page = new Page(pageData, pageLink.parent, pageLink);
        item.ctrl = new PageController(page, item, pageLink);
        item.ctrl.createTree();
    }

    onItemDelete(e) {
        if (e.item.ctrl.tab) {
            this.docs.closeTab(e.item.ctrl.tab);
        }
        $('#treeActionsList').children().remove();
        $('#treeActionsList').append("<li class='disabled'><a href='#'>none</a></li>");
        this.endEdit();
    }

    fillActions(ctrl) {
        $('#treeActionsList').children().remove();
        ctrl.getActions().forEach((action) => {
            if (action.caption === '-') {<commit_msg>pageLinkToPage2<commit_after>class EditorController {
    constructor(appData) {
        console.log('EditorController.constructor');
        this.appData = appData;
        this.tree      = null;
        this.docs      = null;
        this.listeners = {};
        this.pg = null;
        this.appCtrl = null;
        EditorController.editorController = this;
    }

    init() {
        console.log('EditorController.init', this.appData);

        // tree
        this.tree = document.getElementById('tree')._obj;
        this.tree.on('doubleClick', this.listeners.doubleClick = this.onItemDoubleClick.bind(this));
        this.tree.on('select'     , this.listeners.select      = this.onItemSelect.bind(this));
        this.tree.on('open'       , this.listeners.open        = this.onItemOpen.bind(this));
        this.tree.on('delete'     , this.listeners.delete      = this.onItemDelete.bind(this));

        // docs
        this.docs = document.getElementById('docs')._obj;
        this.docs.on('tabClosingByUser', this.listeners.tabClosingByUser = this.onTabClosingByUser.bind(this));

        // appItem
        const caption = ApplicationController.prototype.getCaption(this.appData);
        const appModel = new Application(this.appData);
        appModel.init();
        console.log('appModel:', appModel);
        const appItem = this.tree.addItem(caption, 'opened');
        this.appCtrl = appItem.ctrl = new ApplicationController(appModel, appItem, this);
        appItem.ctrl.createTree();

        // view
        Helper.createReactComponent(document.getElementById('root2'), EditorView, {ctrl: this});
    }

    deinit() {
        this.tree.off('doubleClick'     , this.listeners.doubleClick);
        this.tree.off('select'          , this.listeners.select);
        this.tree.off('open'            , this.listeners.open);
        this.tree.off('delete'          , this.listeners.delete);
        this.docs.off('tabClosingByUser', this.listeners.tabClosingByUser);
    }

    onItemOpen(e) {
        if (e.item.ctrl instanceof PageLinkController) {
            this.pageLinkToPage(e.item);
        }
    }
    onItemOpen2(item) {
        console.log('EditorController.onItemOpen2', item);
    }
    async onItemSelect(e) {
        console.log('EditorController.onItemSelect');
        if (e.item.ctrl) {
            if (e.item.ctrl instanceof PageLinkController) {
                await this.pageLinkToPage(e.item);
            }
            this.fillActions(e.item.ctrl);
            this.fillPropertyGrid(e.item.ctrl);
        } else {
            this.clearActions();
            this.endEdit();
        }
    }

    onItemSelect2 = async item => {
        console.log('EditorController.onItemSelect2', item);
        if (item.ctrl) {
            if (item.ctrl instanceof PageLinkController) {
                await this.pageLinkToPage2(item);
            }
            this.fillActions(item.ctrl);
            this.fillPropertyGrid(item.ctrl);
        } else {
            this.clearActions();
            this.endEdit();
        }
    }
    clearActions() {
        $('#treeActionsList').children().remove();
        $('#treeActionsList').append("<li class='disabled'><a href='#'>none</a></li>");
    }

    fillPropertyGrid(ctrl) {
        const propList = ctrl.getPropList();
        this.beginEdit(propList['list'], propList['options']);
    }

    onPropertyGrid2Change = (name, value) => {
        console.log('EditorController.onPropertyGrid2Change', name, value);
        this.tree.active.ctrl.setProperty(name, value);
    }

    beginEdit(obj, options) {
        console.log('EditorController.beginEdit', obj, options);
        this.pg.setState({object: {obj, options}});
    }

    endEdit() {
        console.log('EditorController.endEdit');
        this.pg.setState({object: null});
    }

    async pageLinkToPage(item) {
        console.log('EditorController.pageLinkToPage');
        const pageLink = item.ctrl.model;

        const pageData = await QForms.doHttpRequest({
            controller: 'Page',
            action    : 'get',
            params    : Helper.encodeObject({
                fileName: pageLink.data['@attributes'].fileName
            })
        });
        const page = new Page(pageData, pageLink.parent, pageLink);
        item.ctrl = new PageController(page, item, pageLink);
        item.ctrl.createTree();
    }

    async pageLinkToPage2(item) {
        console.log('EditorController.pageLinkToPage2');
        const pageLink = item.ctrl.model;

        const pageData = await QForms.doHttpRequest({
            controller: 'Page',
            action    : 'get',
            params    : Helper.encodeObject({
                fileName: pageLink.data['@attributes'].fileName
            })
        });
        const page = new Page(pageData, pageLink.parent, pageLink);
        item.ctrl = new PageController(page, item, pageLink);
        // item.ctrl.createTree();
    }

    onItemDelete(e) {
        if (e.item.ctrl.tab) {
            this.docs.closeTab(e.item.ctrl.tab);
        }
        $('#treeActionsList').children().remove();
        $('#treeActionsList').append("<li class='disabled'><a href='#'>none</a></li>");
        this.endEdit();
    }

    fillActions(ctrl) {
        $('#treeActionsList').children().remove();
        ctrl.getActions().forEach((action) => {
            if (action.caption === '-') {
{'fraction_non_alphanumeric': 0.1427863163113535, 'fraction_numerical': 0.0017848289538919186, 'mean_word_length': 2.2121019108280255, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '5450534', 'n_tokens_mistral': 2901, 'n_tokens_neox': 2879, 'n_words': 418}