0

我正在开发 gnome shell 的扩展。我的扩展需要一个滑块到状态区域的指示器。我在设置它时遇到了一些问题,我在这个稍微过时的参考上编写了我的代码,主要问题是源代码中缺少“PopupSliderMenuItem”。所以我做了一些研究,发现它被删除了。此提交有更多信息。

所以我试图在提交时遵循这个(更新的)代码:

this._slider = new Slider.Slider(0);
this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
this._slider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));

this.item = new PopupMenu.PopupBaseMenuItem({ activate: false });
this.item.addActor(this._slider.actor, { expand: true });

我将此代码重构到我的项目中,它看起来像这样:

this.slider = new Slider.Slider(0.5);
this.slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
this.slider.connect('drag-end', Lang.bind(this, this._setNewColorTemperature));

this.sliderContainer = new PopupMenu.PopupBaseMenuItem();
this.sliderContainer.addActor(this.slider.actor, { expand: true });
this.menu.addMenuItem(this.sliderContainer);

第一个块在 gnome-shell 源代码上(它设置音量滑块)。我的代码(第二个块)在“addActor”行中抛出了这个异常:

Gjs-Message: JS LOG: Extension ****censored**** had error: TypeError: sliderContainer.addActor is not a function

任何人都知道为什么会发生此错误?最奇怪的是,PopupBaseMenuItem 类的源代码有我正在调用的函数。

如果您需要任何其他信息,我很乐意提供。

4

1 回答 1

2

在仔细查看源代码后,我发现设置演员的正确方法是通过 .actor 属性。

所以我的代码现在看起来像这样(并且它正在工作):

this.slider = new Slider.Slider(0.5);
this.slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
this.slider.connect('drag-end', Lang.bind(this, this._setNewColorTemperature));

this.sliderContainer = new PopupMenu.PopupBaseMenuItem();
this.sliderContainer.actor = this.slider.actor;
this.menu.addMenuItem(this.sliderContainer);
于 2016-04-09T20:32:03.737 回答