XUL 文本框的自定义 onsynctopreference

发布于 2024-10-09 12:39:29 字数 1773 浏览 6 评论 0原文

我想在我的 Firefox 扩展中启用自定义快捷方式。这个想法是,用户只需关注文本框,按下组合键,它就会显示在文本框中并保存到首选项中。但是,我无法让它发挥作用。有了这个 XUL,

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://mozapps/skin/pref/pref.css" type="text/css"?>

<!DOCTYPE window SYSTEM "chrome://nextplease/locale/nextplease.dtd">
<prefwindow id="nextpleaseprefs" title="&options.title;" buttons="accept, cancel"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <prefpane id="nextplease.general" label="&options.general.title;" image="chrome://nextplease/skin/Sound Mixer.png">
        <preferences>
            <preference id="nextkey" name="nextplease.nextkey" type="int"/>
        </preferences>
        <vbox flex="1">
            <hbox align="center">
                <label value="&options.general.nextKey;" />
                <textbox id="nextkey" flex="1" editable="false" 
                         onkeyup="return nextplease.handleKeySelection(this, event);" 
                         preference-editable="true" preference="nextkey" 
                         onsynctopreference="alert('syncing'); return nextplease.syncKeySelector(this);"/>
            </hbox>
        </vbox>
    </prefpane>

    <script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseCommon.js" />
    <script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseOptions.js" />
</prefwindow>

onkeyup 中的事件就可以工作了。但是,当我单击“确定”按钮时,我没有看到“正在同步”警报。为什么 onsynctopreference 不起作用?文本框是否不可能具有自定义 onsynctopreference 属性?

I wanted to enable custom shortcuts in my Firefox extension. The idea is that the user just focuses on a textbox, presses key combination, and it's shown in the textbox and saved to a preference. However, I couldn't get it to work. With this XUL

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://mozapps/skin/pref/pref.css" type="text/css"?>

<!DOCTYPE window SYSTEM "chrome://nextplease/locale/nextplease.dtd">
<prefwindow id="nextpleaseprefs" title="&options.title;" buttons="accept, cancel"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <prefpane id="nextplease.general" label="&options.general.title;" image="chrome://nextplease/skin/Sound Mixer.png">
        <preferences>
            <preference id="nextkey" name="nextplease.nextkey" type="int"/>
        </preferences>
        <vbox flex="1">
            <hbox align="center">
                <label value="&options.general.nextKey;" />
                <textbox id="nextkey" flex="1" editable="false" 
                         onkeyup="return nextplease.handleKeySelection(this, event);" 
                         preference-editable="true" preference="nextkey" 
                         onsynctopreference="alert('syncing'); return nextplease.syncKeySelector(this);"/>
            </hbox>
        </vbox>
    </prefpane>

    <script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseCommon.js" />
    <script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseOptions.js" />
</prefwindow>

the event in onkeyup works. But when I click the OK button, I don't see a "syncing" alert. Why isn't onsynctopreference working? Is it impossible to have custom onsynctopreference attribute for a textbox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2024-10-16 12:39:29

问题似乎很简单,首选项仅在 input 事件(也许还有其他一些事件)上同步,但在 keyup 上不同步。

It seems the problem was simply that preferences are only synchronized on input event (and maybe some others), but not on keyup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文