如何在Firefox附加SDK中同时显示2个sdk / panel? [英] How to show 2 sdk/panels at the same time in Firefox Add-on SDK?

查看:132
本文介绍了如何在Firefox附加SDK中同时显示2个sdk / panel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何显示面板 with position:button 。但是,当我尝试 show()一个额外的面板时,前一个面板消失。
我不想禁用自动隐藏。但我想同时显示2个面板。



那么我怎样才能同时显示两个面板呢?

代码:

  function handleChange(state){
if(state.checked){
panelf.show({
position:{
bottom:20
}
});
panel.show({
position:button
});


$ / code $ / pre

解决方案

strong>附加SDK可防止多个 sdk /面板一次打开​​:

您不能完全按照您的要求进行操作。 sdk / panel API特别防止一次显示多个sdk / panel。这是一个sdk /面板,通过在该配置文件中加载的 all 基于附加SDK的扩展一次打开。换句话说,如果一些其他基于附加SDK的扩展打开面板,你将关闭。没有办法使用库存附加SDK代码来禁用此功能。这在 sdk / panel文档(用法部分最后一段的一部分):


打开面板将关闭已经打开的面板。

>

为了更清楚地说明这个限制是所有附加SDK扩展中的,我已经更新了文本:


打开面板将关闭由已经打开的Panel()构造函数创建的任何面板,即使该面板是由不同的附加SDK


当您使用 Panel() 构造函数附加了一个监听器通过调用一个私有函数来访问面板, setupAutoHide(this); 。部分地, setupAutoHide() 是这段代码的永久链接,就像编写这个答案时一样: 面板() setupAutoHide(本); setupAutoHide()

  //实用程序函数需要`panel`实例,并确保它将是
// //一旦显示其他面板就自动隐藏它。
var setupAutoHide = new function(){
let refs = new WeakMap();

返回函数setupAutoHide(panel){
//创建系统事件监听器,对任何面板显示作出反应,
//隐藏给定`panel`(如果不是显示的那个) 。

正如您应该能够从这段代码中的注释中所知道的那样,它是专门用来防止您希望一次显示多个sdk / panel。



显示内容的其他方法

为了提供关于如何完成用户界面所需的详细建议,我们将需要更多的信息来说明您希望使用哪两个 sdk / panels

没有描述你想要一次打开多个sdk / panel的原因,我不得不猜测。一个原因,你可能想打开一个sdk /面板,而另一个作为一个下拉面板 sdk / ui / button / toggle 是您正在使用第一个作为信息或对话框的半永久性显示。在这种情况下,您应该使用不同的UI方法来显示该信息。如何做到这一点取决于你想要你的UI的样子有多种可能性。一种可能是实施用户界面/框架

另一种可能是使用 openDialog() (或 open() )from window / utils 打开一个对话窗口。这些对话窗口是完全独立的窗口,只要你愿意,它们可以存在。如果需要的话,可以将其设计成与sdk /面板几乎相同的外观。它与当前页面或窗口的紧密结合取决于你所做的编程。


$ b

附加SDK将sdk / panels实现为 XUL弹出窗口。 Firefox中没有限制一次显示多个XUL弹出窗口。你可以在主要的Firefox DOM中自己创建这些元素,而不是使用 Panel()构造函数。 包括:将您的第一个SDK /面板作为主窗口UI的不同部分或作为内容页面的一部分;或者,下拉sdk /面板可以作为一个实际的下拉菜单来实现, < menupopup> ,可以是实际的菜单,也可以使用 < panel> 。如果你真的想要的话,你可以编写它,就像你使用 Panel()构造函数一样。但是,后面的这些可能性会绕过附加SDK,并且如果Firefox的底层结构发生变化,可能会导致附加组件需要更多的持续维护。



有太多的可能性,以至于如何实现你可能想要在你的UI覆盖这里。特别是这种情况,因为我们不知道你试图用你的UI实现什么目标。


I know how to show a panel with position:button. But, when I try to show() an additional panel, the previous panel disappears. I don't want to disable auto hide. But I want to show 2 panels at the same time.

So how do I show both at the same time?

Code:

function handleChange(state) {
    if (state.checked) {
        panelf.show({
            position: {
                bottom: 20
            }
        });
        panel.show({
            position: button
        });
    }
}

解决方案

The Add-on SDK prevents more than one sdk/panel from being open at a time:
You can not do exactly what you are wanting to do. The sdk/panel API specifically prevents more than one sdk/panel from showing at a time. That is one sdk/panel open at a time across all Add-on SDK based extensions loaded in that profile. In other words, if some other Add-on SDK based extension opens a panel, yours will close. There is no way to disable this using stock Add-on SDK code. This is explicitly stated in the sdk/panel documentation (part of the last paragraph in the Usage section):

Opening a panel will close an already opened panel.

To make it more clear that this restriction is across all Add-on SDK extensions, I have updated the text to be:

Opening a panel will close any panel created by the Panel() constructor that is already open, even if that panel was opened by a different Add-on SDK based extension.

When you create a panel using the Panel() constructor a listener is attached to the panel using a call to a private function, setupAutoHide(this);. In part, the setupAutoHide() is [permanent links for those in this paragraph to the code as it was when this answer was written: Panel(), setupAutoHide(this); setupAutoHide().]:

// Utility function takes `panel` instance and makes sure it will be
// automatically hidden as soon as other panel is shown.
var setupAutoHide = new function() {
  let refs = new WeakMap();

  return function setupAutoHide(panel) {
    // Create system event listener that reacts to any panel showing and
    // hides given `panel` if it's not the one being shown.

As you should be able to tell from the comments in this code, it is specifically designed to prevent what you desire to do (showing more than one sdk/panel at a time).

Alternate methods to show content:
To provide detailed suggestions as to how to accomplish what you desire for your user interface, we are going to need more information as to what you are wanting to do with the two sdk/panels.

Given that you have not described the reason you desire to have more than one sdk/panel open at one time, I have to guess. One reason that you might want to leave an sdk/panel open while using another as a drop-down panel to a sdk/ui/button/toggle is that you are using the first one as a semi-permanent display of information or a dialog. In such case, you should be using a different UI methodology to display that information. There are multiple possibilities of how to do that depending on what you want your UI to look like. One possibility is to implement a ui/frame.

Another possibility is to use openDialog() (or open()) from window/utils to open a dialog window. These dialog windows are completely separate windows which can exist as long as you desire. If desired, it could be styled to be nearly identical in appearance to an sdk/panel. How tightly coupled it is with the current page or window depends on the programming that you do.

The Add-on SDK implements sdk/panels as XUL popups. There is no restriction within Firefox on displaying more than one XUL popup at a time. You could create these yourself within the primary Firefox DOM rather than using the Panel() constructor.

Yet other possibilities include: implementing your first sdk/panel as a different portion of either the main window UI or as part of the content page; alternately, the drop-down sdk/panel could be implemented as a an actual drop-down menu, a <menupopup>, which can either be an actual menu, or have arbitrary content using a <panel>. If you really desired, you could code it to display exactly as if you had used the Panel() constructor. However, those latter possibilities go around the Add-on SDK and will potentially result in your add-on requiring more on-going maintenance if the underlying structure of Firefox is changed.

There are way too many possibilities as to how to implement what you might desire for your UI to cover here. This is particularly the case because we do not know what the goals are of what you are attempting to implement with your UI.

这篇关于如何在Firefox附加SDK中同时显示2个sdk / panel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆