How to copy&paste SAPUI5 controls by pressing Ctrl+C and Ctrl.V?

二次信任 提交于 2019-12-11 18:32:11

问题


I implemented a copy&paste handling in SAPUI5 in an own control that worked till SAPUI5 version 1.54.x since 1.56.x it seems no longer working - especially in combination with drag&drop handling.

My code looked like this (in an own control):

sap.ui.define([
    "sap/m/VBox",
    "sap/m/VBoxRenderer"
], function (VBox, VBoxRenderer) {
    "use strict";
    var MyBox = VBox.extend("my.domain.controls.VBox",
    {
        metadata : {
            properties : {
            },
            aggregations : {
            },
            events: {
                copy : { parameters : {} },
                paste : { parameters : {} }
            }
        },
        init : function () {
            this._bExcludeFromTabChain = false;
            VBox.prototype.init.apply(this, arguments);         
        },
        renderer : function (oRM, oControl) {
            oRM.write("<div");
            oRM.writeControlData(oControl);
            oRM.addClass("MyBox");
            oRM.writeAttribute("tabindex", "0"); // allows selection
            oRM.writeClasses();
            oRM.write(">");
            VBoxRenderer.render.apply(this, [oRM, oControl]);
            oRM.write("</div>");
        }
    });
    MyBox.prototype.onAfterRendering = function() {
        this.$().on("copy", jQuery.proxy(this.handleCopy, this));
        this.$().on("paste", jQuery.proxy(this.handlePaste, this));
    };
    MyBox.prototype.onBeforeRendering = function() {
        this.$().off("copy", this.handleCopy);
        this.$().off("paste", this.handlePaste);
    };
    MyBox.prototype.exit = function() {
        this.$().off("copy", this.handleCopy);
        this.$().off("paste", this.handlePaste);
    };
    MyBox.prototype.handleCopy = function() {
        this.fireEvent("copy", {});
    };
    MyBox.prototype.handlePaste = function() {
        this.fireEvent("paste", {});
    };
    MyBox.prototype.getAccessibilityInfo = function() {
        return {
            children: this.getItems(),
            focusable: true 
        };
    };
    return MyBox;
});

Is there a different way to handle Ctrl+C and Ctrl+V? I am not intersted in using the operating system clipboard I just intersted in geting the event.

As mentioned if I switch on drag&drop handling (in a control where this one is used as well) it looks like the jQuery copy/paste event does not reach my control.

来源:https://stackoverflow.com/questions/55809131/how-to-copypaste-sapui5-controls-by-pressing-ctrlc-and-ctrl-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!