зеркало из https://github.com/mozilla/pjs.git
provide a convenient way for adding smart keywords for web page searches by adding a context menu to form fields with HTTP-GET form actions.
This commit is contained in:
Родитель
a81c69c549
Коммит
5bef1e18e0
|
@ -160,6 +160,10 @@
|
|||
accesskey="&selectAllCmd.accesskey;"
|
||||
command="cmd_selectAll"/>
|
||||
<menuseparator id="context-sep-selectall"/>
|
||||
<menuitem id="context-keywordfield"
|
||||
label="&keywordfield.label;"
|
||||
accesskey="&keywordfield.accesskey;"
|
||||
oncommand="AddKeywordForSearchField();"/>
|
||||
<menuitem id="context-searchselect"
|
||||
accesskey="&search.accesskey;"
|
||||
oncommand="OpenSearch('internet', gContextMenu.searchSelected(), true);"/>
|
||||
|
|
|
@ -2714,6 +2714,7 @@ function nsContextMenu( xulMenu ) {
|
|||
this.target = null;
|
||||
this.menu = null;
|
||||
this.onTextInput = false;
|
||||
this.onKeywordField = false;
|
||||
this.onImage = false;
|
||||
this.onLink = false;
|
||||
this.onMailtoLink = false;
|
||||
|
@ -2826,6 +2827,7 @@ nsContextMenu.prototype = {
|
|||
this.showItem( "context-bookmarkpage", !( this.isTextSelected || this.onTextInput || this.onLink ) );
|
||||
this.showItem( "context-bookmarklink", this.onLink && !this.onMailtoLink );
|
||||
this.showItem( "context-searchselect", this.isTextSelected );
|
||||
this.showItem( "context-keywordfield", this.onTextInput && this.onKeywordField );
|
||||
this.showItem( "frame", this.inFrame );
|
||||
this.showItem( "frame-sep", this.inFrame );
|
||||
this.showItem( "context-blockimage", this.onImage);
|
||||
|
@ -2901,6 +2903,7 @@ nsContextMenu.prototype = {
|
|||
this.onImage = false;
|
||||
this.onMetaDataItem = false;
|
||||
this.onTextInput = false;
|
||||
this.onKeywordField = false;
|
||||
this.imageURL = "";
|
||||
this.onLink = false;
|
||||
this.onMathML = false;
|
||||
|
@ -2972,6 +2975,7 @@ nsContextMenu.prototype = {
|
|||
this.target.src );
|
||||
} else /* if (this.target.getAttribute( "type" ).toUpperCase() == "TEXT") */ {
|
||||
this.onTextInput = this.isTargetATextBox(this.target);
|
||||
this.onKeywordField = this.isTargetAKeywordField(this.target);
|
||||
}
|
||||
} else if ( this.target.localName.toUpperCase() == "TEXTAREA" ) {
|
||||
this.onTextInput = true;
|
||||
|
@ -3487,6 +3491,14 @@ nsContextMenu.prototype = {
|
|||
return(node.localName.toUpperCase() == "TEXTAREA");
|
||||
}
|
||||
},
|
||||
isTargetAKeywordField : function ( node )
|
||||
{
|
||||
var form = node.form;
|
||||
if (!form)
|
||||
return false;
|
||||
var method = form.method.toUpperCase();
|
||||
return (method == "GET" || method == "")
|
||||
},
|
||||
|
||||
// Determines whether or not the separator with the specified ID should be
|
||||
// shown or not by determining if there are any non-hidden items between it
|
||||
|
@ -4408,3 +4420,53 @@ var MailIntegration = {
|
|||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
function BrowserOpenExtensions(aOpenMode)
|
||||
{
|
||||
const EMTYPE = "Extension:Manager";
|
||||
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var lastEM = wm.getMostRecentWindow(EMTYPE);
|
||||
|
||||
var needToOpen = true;
|
||||
var windows = wm.getEnumerator(EMTYPE);
|
||||
while (windows.hasMoreElements()) {
|
||||
var theEM = windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindowInternal);
|
||||
if (theEM.gWindowType == aOpenMode) {
|
||||
theEM.focus();
|
||||
needToOpen = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needToOpen) {
|
||||
const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
|
||||
const EMFEATURES = "chrome,dialog=no,resizable";
|
||||
window.openDialog(EMURL, "", EMFEATURES, aOpenMode);
|
||||
}
|
||||
}
|
||||
|
||||
function AddKeywordForSearchField()
|
||||
{
|
||||
var node = document.popupNode;
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var uri = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.getService(Components.interfaces.nsIURI);
|
||||
uri.spec = node.ownerDocument.URL;
|
||||
var keywordURL = ioService.newURI(node.form.action, node.ownerDocument.characterSet, uri);
|
||||
var spec = keywordURL.spec;
|
||||
spec += "?" + escape(node.name) + "=%s";
|
||||
for (var i = 0; i < node.form.elements.length; ++i) {
|
||||
var e = node.form.elements[i];
|
||||
if (e.type.toLowerCase() == "text" || e.type.toLowerCase() == "hidden")
|
||||
spec += "&" + escape(e.name) + "=" + escape(e.value);
|
||||
}
|
||||
dump("*** SPEC = " + spec + "\n");
|
||||
openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "",
|
||||
"centerscreen,chrome,dialog,resizable,dependent",
|
||||
"", spec, null, node.ownerDocument.characterSet, null, null,
|
||||
false, "", true);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,16 +107,25 @@
|
|||
<!ENTITY toolsMenu.label "Tools">
|
||||
<!ENTITY toolsMenu.accesskey "T">
|
||||
|
||||
<!ENTITY keywordfield.label "Add a Keyword for this Search...">
|
||||
<!ENTITY keywordfield.accesskey "K">
|
||||
<!ENTITY search.label "Web Search">
|
||||
<!ENTITY search.accesskey "S">
|
||||
<!ENTITY downloads.label "Downloads">
|
||||
<!ENTITY downloads.tooltip "Display the progress of ongoing downloads">
|
||||
<!ENTITY downloads.accesskey "D">
|
||||
<!ENTITY downloads.commandkey "e">
|
||||
<!ENTITY downloads.commandkey "y">
|
||||
<!ENTITY extensions.label "Extensions">
|
||||
<!ENTITY extensions.tooltip "Show and Manage installed Extensions">
|
||||
<!ENTITY extensions.accesskey "E">
|
||||
<!ENTITY themes.label "Themes">
|
||||
<!ENTITY themes.tooltip "Change the Theme">
|
||||
<!ENTITY themes.accesskey "T">
|
||||
|
||||
<!ENTITY javaConsoleCmd.label "Java Console">
|
||||
<!ENTITY javaConsoleCmd.accesskey "J">
|
||||
|
||||
<!ENTITY javaScriptConsoleCmd.label "JavaScript Console">
|
||||
<!ENTITY javaScriptConsoleCmd.accesskey "S">
|
||||
<!ENTITY javaScriptConsoleCmd.accesskey "C">
|
||||
|
||||
<!ENTITY fileMenu.label "File">
|
||||
<!ENTITY fileMenu.accesskey "F">
|
||||
|
|
|
@ -53,6 +53,10 @@
|
|||
* be passed additional information, which gets mapped to the
|
||||
* window.arguments array:
|
||||
*
|
||||
* XXXben - it would be cleaner just to take this dialog take an
|
||||
* object so items don't need to be passed in a particular
|
||||
* order.
|
||||
*
|
||||
* window.arguments[0]: Bookmark Name. The value to be prefilled
|
||||
* into the "Name: " field (if visible).
|
||||
* window.arguments[1]: Bookmark URL: The location of the bookmark.
|
||||
|
@ -69,14 +73,24 @@
|
|||
* of objects with name, URL and charset
|
||||
* properties, one for each group member.
|
||||
* window.arguments[6]: If the bookmark should become a web panel.
|
||||
* window.arguments[7]: A suggested keyword for the bookmark. If this
|
||||
* argument is supplied, the keyword row is made
|
||||
* visible.
|
||||
* window.arguments[8]: Whether or not a keyword is required to add
|
||||
* the bookmark.
|
||||
*/
|
||||
|
||||
var gSelectedFolder;
|
||||
var gName;
|
||||
var gKeyword;
|
||||
var gKeywordRow;
|
||||
var gExpander;
|
||||
var gMenulist;
|
||||
var gBookmarksTree;
|
||||
var gGroup;
|
||||
var gKeywordRequired;
|
||||
var gSuggestedKeyword;
|
||||
var gRequiredFields = [];
|
||||
|
||||
# on windows, sizeToContent is buggy (see bug 227951), we''ll use resizeTo
|
||||
# instead and cache the bookmarks tree view size.
|
||||
|
@ -87,7 +101,10 @@ function Startup()
|
|||
sizeToContent(); //XXXpch buggy imo, we shouldn't need it
|
||||
initServices();
|
||||
initBMService();
|
||||
gName = document.getElementById("name");
|
||||
gName = document.getElementById("name");
|
||||
gRequiredFields.push(gName);
|
||||
gKeywordRow = document.getElementById("keywordRow");
|
||||
gKeyword = document.getElementById("keyword");
|
||||
gGroup = document.getElementById("addgroup");
|
||||
gExpander = document.getElementById("expander");
|
||||
gMenulist = document.getElementById("select-menu");
|
||||
|
@ -95,6 +112,12 @@ function Startup()
|
|||
gName.value = window.arguments[0];
|
||||
gName.select();
|
||||
gName.focus();
|
||||
gKeyword.value = window.arguments[7];
|
||||
gKeywordRequired = window.arguments[8];
|
||||
if (!window.arguments[7] && !gKeywordRequired)
|
||||
gKeywordRow.hidden = true;
|
||||
if (gKeywordRequired)
|
||||
gRequiredFields.push(gKeyword);
|
||||
onFieldInput();
|
||||
gSelectedFolder = RDF.GetResource(gMenulist.selectedItem.id);
|
||||
gExpander.setAttribute("tooltiptext", gExpander.getAttribute("tooltiptextdown"));
|
||||
|
@ -121,9 +144,15 @@ function Startup()
|
|||
|
||||
function onFieldInput()
|
||||
{
|
||||
const ok = document.documentElement.getButton("accept");
|
||||
ok.disabled = gName.value == "";
|
||||
}
|
||||
var ok = document.documentElement.getButton("accept");
|
||||
ok.disabled = false;
|
||||
for (var i = 0; i < gRequiredFields.length; ++i) {
|
||||
if (gRequiredFields[i].value == "") {
|
||||
ok.disabled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
|
@ -135,12 +164,12 @@ function onOK()
|
|||
const groups = window.arguments[5];
|
||||
for (var i = 0; i < groups.length; ++i) {
|
||||
url = getNormalizedURL(groups[i].url);
|
||||
BMDS.createBookmarkInContainer(groups[i].name, url, null, null,
|
||||
BMDS.createBookmarkInContainer(groups[i].name, url, gKeyword.value, null,
|
||||
groups[i].charset, rSource, -1);
|
||||
}
|
||||
} else {
|
||||
url = getNormalizedURL(window.arguments[1]);
|
||||
rSource = BMDS.createBookmark(gName.value, url, null, null, window.arguments[3]);
|
||||
rSource = BMDS.createBookmark(gName.value, url, gKeyword.value, null, window.arguments[3]);
|
||||
}
|
||||
|
||||
var selection = BookmarksUtils.getSelectionFromResource(rSource);
|
||||
|
|
|
@ -60,6 +60,10 @@
|
|||
<label value="&name.label;" accesskey="&name.accesskey;" control="name"/>
|
||||
<textbox id="name" oninput="onFieldInput();"/>
|
||||
</row>
|
||||
<row align="center" id="keywordRow">
|
||||
<label value="&keyword.label;" accesskey="&keyword.accesskey;" control="keyword"/>
|
||||
<textbox id="keyword" oninput="onFieldInput();"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label id="createinlabel" value="&createin.label;" accesskey="&createin.accesskey;" control="select-menu"/>
|
||||
<menulist id="select-menu" class="folder-icon"
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<!ENTITY newBookmark.title "Add Bookmark">
|
||||
<!ENTITY newbookmark.label "&brandShortName; will add a bookmark to this page.">
|
||||
<!ENTITY name.label "Name:">
|
||||
<!ENTITY name.accesskey "n">
|
||||
<!ENTITY name.accesskey "N">
|
||||
<!ENTITY keyword.label "Keyword:">
|
||||
<!ENTITY keyword.accesskey "K">
|
||||
<!ENTITY url.label "Location:">
|
||||
<!ENTITY url.accesskey "l">
|
||||
<!ENTITY url.accesskey "L">
|
||||
<!ENTITY button.createin.label "Create In >>">
|
||||
<!ENTITY button.createin.accesskey "c">
|
||||
<!ENTITY button.createin.accesskey "C">
|
||||
<!ENTITY button.createin2.label "Create In <<">
|
||||
<!ENTITY createin.label "Create in:">
|
||||
<!ENTITY createin.accesskey "C">
|
||||
|
|
Загрузка…
Ссылка в новой задаче