xul 创建一个按钮

  • zm1990s
  • ziyunfei
  • ibrahim_lq

添加工具栏按钮 (定制工具栏)

在本文章中
    1. 创建一个 overlay
    2. 在工具栏添加按钮
    3. 为按键应用风格
      1. 图标大小
      2. CSS 样式表
      3. 应用样式表
    4. 常见错误
    5. 常见工具栏的 overlayed windows
    6. 更多信息

此文章解释如何使用 overlays 为工具包(firefox,Thunderbird 或 Kompozer) 添加工具栏按钮(就是浏览器右上方一系列按钮,home,下载之类的)。适用用户是拥有 XUL 和 CSS 基础知识的 扩展 开发人员。

我们假设您已经会创建基础的火狐插件,并且已经成功创建了 Hello World extension ,另外,还有一份更加完全的初学者示例指南,请查看 自定义工具栏按钮。

创建一个 overlay

The first step is to create an overlay for the document containing the toolbar you wish to enhance. Explaining overlays is beyond the scope of this tutorial -- you can read about them in the XUL Tutorial.

To overlay a document, you need to know its URI. You can find a list of URIs for the most commonly overlaid documents at the bottom of this page.

Note: Some people overlay chrome://messenger/content/mailWindowOverlay.xul. That should cause the button to appear on all windows that mailWindowOverlay.xul is applied to (i.e. Main window and View Message window). This needs to be looked into.

在工具栏添加按钮

Toolkit applications have customizable toolbars; therefore, it's common practice for extensions to add their toolbar buttons to the toolbar palette, rather than adding them directly to the toolbar. The latter is possible but is not recommended and is harder to implement.

Adding a button to the toolbar palette is very easy. Just add code like this to your overlay:

<toolbarpalette id="BrowserToolbarPalette"> <toolbarbutton id="myextension-button" class="toolbarbutton-1" label="&toolbarbutton.label;" tooltiptext="&toolbarbutton.tooltip;" oncommand="MyExtension.onToolbarButtonCommand(event);"/> </toolbarpalette>

注意:

  • The id of the palette (BrowserToolbarPalette in the example) depends on the window whose toolbar you wish to insert a button into. See below for the list of common palette IDs.
  • class="toolbarbutton-1" makes the toolbar button appear correctly in Icons and Text mode; it also adjusts padding.
  • If you need to handle middle-click, add this line after the oncommand line.
onclick="checkForMiddleClick(this, event)"
  • you can also handle middle-lick and right-click using onclick handler and check event.button in it. like this:
<toolbarpalette id="BrowserToolbarPalette"> <toolbarbutton id="myextension-button" class="toolbarbutton-1" label="&toolbarbutton.label;" tooltiptext="&toolbarbutton.tooltip;" onclick="MyExtension.onclick(event);"/> </toolbarpalette>
onclick: function(event) {switch(event.button) {case 0:// Left clickbreak;case 1:// Middle clickbreak;case 2:// Right clickbreak;}
}

To add more buttons, put more <toolbarbutton> elements inside the <toolbarpalette> element. Wrap elements other than <toolbarbutton> in<toolbaritem>.

为按键应用风格

Most toolbar buttons have an icon. To attach an image to the button we use standard Mozilla skinning facilities. If you're unfamiliar with how that works, read the skinning section of Jonah Bishop's excellent Toolbar Tutorial. Although the article covers creating an entire toolbar, rather than just a button, it has a great explanation of the techniques we'll use here.

图标大小

Toolbar buttons can have two different sizes -- big and small. This means you'll need to provide two icons for each of your toolbar buttons. The dimensions of the icons in various applications for both modes are summarized in the following table (feel free to add information about other applications):

Application (Theme name)Big icon sizeSmall icon size
Firefox 1.0 (Winstripe)24x2416x16
Thunderbird 1.0 (Qute)24x2416x16

CSS 样式表

To set the image for your toolbar button, use the following CSS rules:

/*  skin/toolbar-button.css  */#myextension-button {list-style-image: url("chrome://myextension/skin/btn_large.png");
}toolbar[iconsize="small"] #myextension-button {list-style-image: url("chrome://myextension/skin/btn_small.png");
}

应用样式表

Remember to attach the stylesheet you created to both the overlay file and the Customize Toolbar window. To attach it to the overlay, put this processing instruction (PI) at the top of the overlay file:

<?xml-stylesheet href="chrome://myextension/skin/toolbar-button.css" type="text/css"?>
Note: The CSS file with your toolbar styles needs to be included in the overlay file, as you would expect, but also in the chrome.manifest file. This is very important because the toolbar customization dialog won't work correctly without this.

To include the style on your chrome.manifest file:

style chrome://global/content/customizeToolbar.xul chrome://myextension/skin/toolbar-button.css

If you are developing for Firefox 1.0, attach it to the Customize Toolbar window (chrome://global/content/customizeToolbar.xul) usingskin/contents.rdf. The code looks like this:

<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:chrome="http://www.mozilla.org/rdf/chrome#"> <Seq about="urn:mozilla:skin:root"> <li resource="urn:mozilla:skin:classic/1.0"/> </Seq> <Description about="urn:mozilla:skin:classic/1.0"> <chrome:packages> <Seq about="urn:mozilla:skin:classic/1.0:packages"> <li resource="urn:mozilla:skin:classic/1.0:myextension"/> </Seq> </chrome:packages> </Description> <Seq about="urn:mozilla:stylesheets"> <li resource="chrome://global/content/customizeToolbar.xul"/> </Seq> <Seq about="chrome://global/content/customizeToolbar.xul"> <li>chrome://myextension/skin/toolbar-button.css</li> </Seq> </RDF>

The skin/contents.rdf file is denigrated in developing for later releases of Firefox. Extensions for Firefox/Thunderbird 1.5 and above should instead use something like this in their chrome.manifest:

skin	myextension	classic/1.0	chrome/skin/
style	chrome://global/content/customizeToolbar.xul	chrome://myextension/skin/toolbar-button.css
ia

Take note of the Packaging section in this article; you may need to include .jar references if you are delivering your extension as a .xpi file.

常见错误

This is a list of the most common mistakes made by extension authors, including both symptoms and solutions.

Problem: The whole set of default buttons is painted on the toolbar or in the Customize Toolbars window, instead of your own icon.

Caused by: Malformed or not applied stylesheet.

Solution: Check to be sure your stylesheet is correct, make sure your contents.rdf (or chrome.manifest) is correct, and be sure you didn't forget to apply the stylesheet to customizeToolbar.xul.

常见工具栏的 overlayed windows

URLApplication and affected window(s)Palette id
chrome://browser/content/browser.xulFirefox - Main windowBrowserToolbarPalette
chrome://navigator/content/navigator.xulSeaMonkey 2.0 - Browser windowBrowserToolbarPalette
chrome://messenger/content/messenger.xulThunderbird - Main windowMailToolbarPalette
chrome://messenger/content/messenger...gercompose.xulThunderbird - Compose windowMsgComposeToolbarPalette
chrome://messenger/content/addressbo...ddressbook.xulThunderbird - Address bookAddressBookToolbarPalette
chrome://editor/content/editor.xulKompozer - Main windowNvuToolbarPalette
chrome://calendar/content/calendar.xulSunbird - Main windowcalendarToolbarPalette

更多信息

  • XulPlanet.com references: <toolbarbutton><toolbaritem>.
  • How to adjust toolbarbutton's label position
  • A forum thread about adding an item to the toolbar (instead of just adding it to palette) right after an extension is installed. Note that doing this is not recommended.
  • There is another page on mdc with information about adding buttons to various windows in SeaMonkey. Includes useful information about overlays for ChatZilla.

转载于:https://www.cnblogs.com/developer-ios/p/7198121.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/268900.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MySQL预读失效_华为云MySQL新增“逻辑预读”特性,轻松解决线性预读失效问题...

随着用户对数据访问速度的日益重视,MySQL数据库在最初的设计中,采用了线性预读的方式,提前将即将使用的数据预读到Buffer pool中,来提升数据的访问速度,但在实际使用过程中,线性预读失效的问题愈来愈突出。对于存在时间比较长,变更又比较频繁,除非我们对于这张表进行重建,否则该…

Mac下的Parallel Windows忘记密码怎么办?

由于工作或是生活&#xff0c;在国内的环境下我们总有些时候要用到Windows才能完成某些任务&#xff0c;对于不经常使用Windows的用户&#xff0c;相信在虚拟机上安装一个Windows是不错的选择。小编就使用了Paralles Desktop安装了 Win 7 系统。但是在使用过程中由于不知道是Wi…

Unity shader学习之Grab Pass实现玻璃效果

GrabPass可将当前屏幕的图像绘制在一张纹理中&#xff0c;可用来实现玻璃效果。 转载请注明出处&#xff1a;http://www.cnblogs.com/jietian331/p/7201324.html shader如下&#xff1a; // Upgrade NOTE: replaced mul(UNITY_MATRIX_MVP,*) with UnityObjectToClipPos(*)Shade…

ef core mysql 生成迁移失败_EFCore + MySql codeFirst 迁移 Migration出现的问题

第二次使用Migration update-database的时候出现以下错误&#xff1a;System.NotImplementedException: The method or operation is not implemented. at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(RenameColumnOperation operation, IModel…

Rsync:一个很实用的文件同步命令

rsync是Linux系统下的文件同步和数据传输工具&#xff0c;可用于同步文件、代码发布 1.安装. yum insatll -y rsync 2.配置 打开rsync功能vim /etc/xinetd.d/rsync service rsync {disable no #把yes改成noflags IPv6socket_type streamwait n…

spring整合dubbo和springboot整合dubbo,实现服务暴露区别

spring整合dubbo的时候实现服务暴露是这么做的&#xff0c;在xml里配置 那么springboot整合dubbo的时候&#xff0c;是通过dubbo的Service 注解实现的 之前我们是通过Autowired注入一个接口 现在我们通过Reference注解引用接口

mysql 查询超过60分钟的_mysql基础级《简单查询》60分钟搞定

初学者&#xff0c;推荐大家使用----emp(雇员信息表)和dept(部门表)&#xff0c;这两张表的字段及数据内容都设计的比较经典。来吧&#xff01;先跟着我的操作&#xff0c;导入我提供的数据库脚本。导入两张表sql脚本到数据库create database testdb;use testdb;drop table if …

数据结构1-树及常用算法

&#xff08;一&#xff09;将数据库存储结构转化为内存树型结构算法 树节点定义public class TNode {public string id { get; set; }public string pid { get; set; }public string name { get; set; }public string flag { get; set; } }树定义public class Tree {TNode nod…

Error(6,35)java: 程序包 不存在,解决办法

spring boot项目&#xff0c;运行就提示找不到程序包&#xff0c;执行了maven clean install&#xff0c;maven依赖没有标红&#xff0c;但启动就报错 解决办法 检查maven依赖是否成功导入 根据报错信息&#xff0c;检查本地仓库是否有jar&#xff0c;有些jar包不会自动导入&a…

再学 GDI+[91]: TGPImage(11) - 转灰度图像

本例效果图:代码文件:unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 class(TForm)CheckBox1: TCheckBox;procedure FormCreate(Sender: TObject);procedure FormPaint(Sender: TObject);…

GUI阅读字号和触点面积设计 (可用性设计)

今天在博客园开启第一篇&#xff0c;附上我多年工作的研究总结以表诚意。 此文已收入UXPA大会文集&#xff0c;出版于四川大学出版社。 《GUI阅读字号和触点面积设计》 --可用性设计理论研究与实践案例 作者刘玲 前华为UCD中心交付经理 277169188qq.com 摘要: 本文演绎论证了当…

UEditor 插入图片大于2M提示文件大小超出范围解决办法

wordpress使用UEditor-KityFormula 编辑器时候插入图片的时候会提示附件大小超出范围等错误&#xff0c;这是因为UEditor编辑器里面有限制了图片附件大小最大不能超过2m的原因 解决办法要修改 插件 php里面的 config.json 文件 “scrawlMaxSize”: 2048000, /* 上传大小限制&am…

mysql提示太多连接_mysql数据库提示连接太多怎么办

mysql数据库提示连接太多的解决方法&#xff1a;1、登录mysql数据库&#xff0c;查看当前活动的连接线程变量值&#xff1b;2、编辑my.cnf配置文件&#xff0c;添加【[mysqld] port3306】&#xff1b;3、重启mysql服务器。解决方法&#xff1a;查看max_connections进入MySQL&am…

[MySQL FAQ]系列 -- 快速还原MyISAM表索引

作/译者&#xff1a;叶金荣&#xff08;Email: &#xff09;&#xff0c;来源&#xff1a;http://imysql.cn&#xff0c;转载请注明作/译者和出处&#xff0c;并且不能用于商业用途&#xff0c;违者必究。假设有个myisam表&#xff1a;tbl&#xff0c;为了备份方便&#xff0c;…

Android Studio 之 NDK篇

由于工作内容的关系&#xff0c;对于NDK的工作涉及比较广&#xff08;保密性&#xff0c;安全性&#xff09;&#xff0c;所以本章内容讲述一下NDK的基本使用过程。 网上也有很多这样的教程或者描述&#xff0c;但描述的并不完全 开发工具&#xff1a;Android Studio 2.1.2 ND…

避免一个用户多次登录修改版

原来的代码参见这里http://www.qiuhao.com//dispbbs.asp?boardID2&ID6228&page1 今天仔细看了这段代码,发现这段代码大有优化的余地 因为maxSessions 这个值可能会很大,我这里测试环境有3万多个,启动时要浪费半分钟左右 另外sessionId是个随机数,用1到maxSessions其实…