前回のままですと、オプションの真下にメニューが追加されてしまうので、
いろいろ場所を変更する方法をパターンで分けてみたいと思います。
その基準となるのが Firefox 自身の定義ですが、それは以下のようになります
( Firebug は省いてあります )
注目は Java Console です。Java Console も拡張機能であり、
後からオーバーレイで追加されています。
その方法として、insertafter="devToolsSeparator" が使用されており、
devToolsSeparator は直前の項目の ID です。
このようにして、既にあるID を元に、位置を決定する事ができます
<menu id="tools-menu" label="ツール" accesskey="T">
<menupopup id="menu_ToolsPopup">
<menuitem
label="Web 検索"
accesskey="S"
key="key_search"
command="Tools:Search" />
<menuseparator id="browserToolsSeparator" />
<menuitem
id="menu_openDownloads"
label="ダウンロード"
accesskey="D"
key="key_openDownloads"
command="Tools:Downloads" />
<menuitem
id="menu_openAddons"
label="アドオン"
accesskey="A"
command="Tools:Addons" />
<menuseparator id="devToolsSeparator" />
<menuitem
id="javaconsole1.6.0_07"
label="Java Console"
accesskey="j"
insertafter="devToolsSeparator"
oncommand="gJavaConsole1_6_0_07.show();" />
<menuitem
id="javascriptConsole"
label="エラーコンソール"
accesskey="C"
key="key_errorConsole"
oncommand="toJavaScriptConsole();" />
<menuitem
accesskey="I"
label="ページの情報"
command="View:PageInfo" />
<menuseparator id="sanitizeSeparator" />
<menuitem
id="sanitizeItem"
accesskey="P"
label="プライバシー情報の消去"
key="key_sanitize"
command="Tools:Sanitize" />
<menuseparator id="prefSep" />
<menuitem
id="menu_preferences"
label="オプション..."
accesskey="O"
oncommand="openPreferences();" />
</menupopup>
</menu>
このメニュー構造は、Firefox のアドレスに chrome://browser/content/browser.xul を入力して開き、
Firebug で HTML の タブから以下を探します
toolbox(navigator-toolbox)
-> toolbar(toolbar-menubar)
-> toolbaritem(menubar-items)
-> menubar(main-menubar)
セパレータを追加してオプションの下に配置する
一番簡単な方法です。通常はこれでかまわないでしょう
二つ目は、指定したサイトでしか表示しないようにします
<menupopup id="menu_ToolsPopup">
<menuseparator id="mySep" />
<menuitem id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</menupopup>
<menupopup id="menu_ToolsPopup"
onpopupshowing="
var __str = new String(window.content.location);
if ( __str.substr(0,18) == 'http://winofsql.jp' ) {
document.getElementById('mySep').style.display='';
document.getElementById('tk-hello').style.display='';
}
else {
document.getElementById('mySep').style.display='none';
document.getElementById('tk-hello').style.display='none';
}
"
>
<menuseparator id="mySep" />
<menuitem id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</menupopup>
通常メニューのかわりにボタンを使用する
あまり意味はありませんが、目立つかもしれません
<menupopup id="menu_ToolsPopup">
<menuseparator id="mySep" />
<button id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</menupopup>
ツールの右隣に新たなメニューを追加する
自分が作ったツールを次々追加するのならばこんな感じですね
<menubar id="main-menubar">
<menu id="personalMenu" label="個人用" accesskey="P" insertafter="tools-menu">
<menupopup id="menu_myToolsPopup">
<menuitem id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</menupopup>
</menu>
</menubar>
HELP の右横にそのまま実行できるメニューとして追加
いちいちポップアップしたく無い時用です
<menubar id="main-menubar">
<menuitem id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</menubar>
WEB ページの 右クリックのポップアップメニューに追加する
かなり応用をきかせたい場合の場所ですね
<popup id="contentAreaContextMenu">
<menuseparator id="mySep" />
<menuitem id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</popup>
指定した URL の場合だけ、WEB ページの 右クリックのポップアップメニューに追加する
混み入った内容だと、外部ファイルやレジストリから URLを取ってきて、
JavaScript の function で全て処理させると良いでしょう
if (event.target != this) 以降はオリジナルの処理です。
Firefox が仕様変更されると、困った事になる可能性はありますので、
readme にその旨を記述しておくべきでしょう。( その場合は削除 )
手書きブログ用だと固定で以下のようにすると良いですが、
ペンタブ使うので、右クリックよりメニューが都合いいので使いません
<popup
id="contentAreaContextMenu"
onpopupshowing="
var __str = new String(window.content.location);
if ( __str.substr(0,18) == 'http://winofsql.jp' ) {
document.getElementById('mySep').style.display='';
document.getElementById('tk-hello').style.display='';
}
else {
document.getElementById('mySep').style.display='none';
document.getElementById('tk-hello').style.display='none';
}
if (event.target != this) return true;
updateEditUIVisibility();
gContextMenu = new nsContextMenu(this, window.getBrowser());
return gContextMenu.shouldDisplay;"
>
<menuseparator id="mySep" />
<menuitem id="tk-hello" label="&tk.label;"
oncommand="tk.onMenuItemCommand(event);"/>
</popup>
|