我正在玩雷鸟代码库,目的是实现内联联系人编辑。当前代码在Click树上捕获XUL事件,如果双击(events.detail == 2),则会打开配置文件编辑器。我对其进行了修改,以便开始编辑当前的treeCell,并且确实将editable=true添加到了相应的XUL文档中。更新后的代码为

var orow = {}, ocolumn = {}, opart = {};
gAbResultsTree.treeBoxObject.getCellAt(event.clientX, event.clientY,
                                       orow, ocolumn, opart);

var row = orow.value, column = ocolumn.value.index;
if (row == -1)
  return;

if (event.detail == 2)
  gAbResultsTree.startEditing(row, column);


不幸的是,当代码到达startEditing部分时,它将返回

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsITreeView.isEditable]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: chrome://global/content/bindings/tree.xml :: startEditing :: line 337" data: no]

我在这里迷路了。有更多XUL经验的人可以帮忙吗?
谢谢!

最佳答案

我试图做类似的事情,但我遇到了同样的问题。

将原始abview设置为__proto__且功能被覆盖的包装程序可以正常工作,直到将其设置为abResultsTree的视图为止。

我终于找到了(我希望)一个优雅的解决方案。

function MyAbView() {
    this.originalAbViewInstance = this.originalAbViewFactory.createInstance(null, Ci.nsIAbView);

    if (!this.proxiesGenerated) {
        // find out which interfaces are implemented by original instance, their property proxies will be generated later
        for (var ifName in Ci) {
            if (Ci[ifName] instanceof Ci.nsIJSID && this.originalAbViewInstance instanceof Ci[ifName]) {
                MyAbView.prototype.supportedInterfaces.push(Ci[ifName]);
            }
        }

        function generatePropertyProxy(name) {
            Object.defineProperty(MyAbView.prototype, name, {
                get: function() {
                    return this.originalAbViewInstance[name];
                },
                set: function(val) {
                    this.originalAbViewInstance[name] = val;
                },
                enumerable: true
            });
        }

        for (var prop in this.originalAbViewInstance) {
            if (this[prop] == undefined) {
                generatePropertyProxy(prop);
            }
        }

        MyAbView.prototype.proxiesGenerated = true;
    } else {
        for each (var interface in this.supportedInterfaces) {
            this.originalAbViewInstance.QueryInterface(interface);
        }
    }
}

MyAbView.prototype = {
    classID: null,

    _xpcom_factory: {
        createInstance: function(outer, iid) {
            return new MyAbView().QueryInterface(iid);
        }
    },

    QueryInterface: function(aIID) {
        for each (var interface in this.supportedInterfaces) {
            if (interface.equals(aIID)) {
                return this;
            }
        }

        throw Components.results.NS_ERROR_NO_INTERFACE;
    },

    originalAbViewFactory: null,
    originalAbViewInstance: null,

    proxiesGenerated: false,
    supportedInterfaces: [],

    // any overriden functions come here
};


它被实现为替代原始Abview的组件,但是可以对其进行修改以仅创建包装器。

关于javascript - XUL/Thunderbird:startEditing返回,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7918148/

10-12 14:10