Show address bar icon on all web pages in Firefox

The icon now will save using a translator if possible and otherwise fall back
to creating a web page item. This also removes the "Create Web Page Item from
Current Page" button.

Let's see how this feels. (Pushing it to the beta so more people can try it.) I
think we ultimately should do this, but my main concern with this
implementation is that it's just too distracting, since the icon disappears and
reappears on every page. A persistent, possibly monochrome icon that was just
sometimes disabled (as is the case for the Firefox bookmark toolbar icon) might
be better.

Regardless of the approach, there are some follow-up tweaks that should be made:

- The same thing in the connectors
- Context-menu options
- Different icons and descriptions for different file types (PDF, image)?
- Adjust guidance text? Have separate guidance panels for web vs. translation?
This commit is contained in:
Dan Stillman 2015-02-17 03:43:45 -05:00
parent 47a062c9a8
commit aaeb2cec9d
3 changed files with 57 additions and 9 deletions

View file

@ -40,7 +40,6 @@
var Zotero_Browser = new function() {
this.init = init;
this.scrapeThisPage = scrapeThisPage;
this.annotatePage = annotatePage;
this.toggleMode = toggleMode;
this.toggleCollapsed = toggleCollapsed;
@ -155,13 +154,25 @@ var Zotero_Browser = new function() {
* Scrapes a page (called when the capture icon is clicked
* @return void
*/
function scrapeThisPage(translator) {
this.scrapeThisPage = function (translator, event) {
// Perform translation
var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser);
if(tab.page.translators && tab.page.translators.length) {
tab.page.translate.setTranslator(translator || tab.page.translators[0]);
Zotero_Browser.performTranslation(tab.page.translate);
}
else {
// Keep in sync with cmd_zotero_newItemFromCurrentPage
//
// DEBUG: Possible to just trigger command directly with event? Assigning it to the
// command property of the icon doesn't seem to work, and neither does goDoCommand()
// from chrome://global/content/globalOverlay.js. Getting the command by id and
// running doCommand() works but doesn't pass the event.
ZoteroPane.addItemFromPage(
'temporaryPDFHack',
(event && event.shiftKey) ? !Zotero.Prefs.get('automaticSnapshots') : null
);
}
}
/*
@ -449,6 +460,11 @@ var Zotero_Browser = new function() {
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
var translators = tab.page.translators;
// Don't show context menu for web page items, for now
// TODO: Show with/without snapshots option?
if (!translators) return;
for(var i=0, n=translators.length; i<n; i++) {
let translator = translators[i];
@ -460,7 +476,7 @@ var Zotero_Browser = new function() {
: Zotero.ItemTypes.getImageSrc(translator.itemType)));
menuitem.setAttribute("class", "menuitem-iconic");
menuitem.addEventListener("command", function(e) {
scrapeThisPage(translator);
scrapeThisPage(translator, e);
}, false);
popup.appendChild(menuitem);
}
@ -719,7 +735,14 @@ Zotero_Browser.Tab.prototype.clear = function() {
* detects translators for this browser object
*/
Zotero_Browser.Tab.prototype.detectTranslators = function(rootDoc, doc) {
if(doc instanceof HTMLDocument && doc.documentURI.substr(0, 6) != "about:") {
this.page.saveEnabled = true;
if (doc instanceof HTMLDocument) {
if (doc.documentURI.startsWith("about:")) {
this.page.saveEnabled = false;
return;
}
// get translators
var me = this;
@ -790,6 +813,10 @@ Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) {
* current page, or false if the page cannot be scraped
*/
Zotero_Browser.Tab.prototype.getCaptureIcon = function() {
if (!this.page.saveEnabled) {
return false;
}
if(this.page.translators && this.page.translators.length) {
var itemType = this.page.translators[0].itemType;
return (itemType === "multiple"
@ -797,10 +824,15 @@ Zotero_Browser.Tab.prototype.getCaptureIcon = function() {
: Zotero.ItemTypes.getImageSrc(itemType));
}
return false;
// TODO: Show icons for images, PDFs, etc.?
return "chrome://zotero/skin/treeitem-webpage.png";
}
Zotero_Browser.Tab.prototype.getCaptureTooltip = function() {
if (!this.page.saveEnabled) {
return '';
}
if (this.page.translators && this.page.translators.length) {
var arr = [Zotero.getString('ingester.saveToZotero')];
if (this.page.translators[0].itemType == 'multiple') {
@ -809,7 +841,22 @@ Zotero_Browser.Tab.prototype.getCaptureTooltip = function() {
arr.push (' ' , '(' + this.page.translators[0].label + ')');
return Zotero.localeJoin(arr, '');
}
return '';
// TODO: Different captions for images, PDFs, etc.?
return Zotero.getString('ingester.saveToZotero')
+ " (" + Zotero.getString('itemTypes.webpage') + ")";
}
Zotero_Browser.Tab.prototype.getCaptureCommand = function () {
if (!this.page.saveEnabled) {
return '';
}
if (this.page.translators && this.page.translators.length) {
return '';
}
return 'cmd_zotero_newItemFromCurrentPage';
}
@ -867,6 +914,7 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
this.page.translate = translate;
this.page.translators = translators;
this.page.document = translate.document;
this.page.saveEnabled = true;
this.page.translate.clearHandlers("select");
this.page.translate.setHandler("select", this._selectItems);

View file

@ -77,7 +77,7 @@
<menupopup id="zotero-status-image-context" onpopupshowing="Zotero_Browser.onStatusPopupShowing(event)"/>
</popupset>
<image src="chrome://zotero/skin/treeitem-book.png" id="zotero-status-image"
onclick="if(event.button === 0) Zotero_Browser.scrapeThisPage()" context="zotero-status-image-context"
onclick="if(event.button === 0) Zotero_Browser.scrapeThisPage(null, event)" context="zotero-status-image-context"
position="1" hidden="true"/>
<zoteroguidancepanel id="zotero-status-image-guidance" about="saveIcon" for="zotero-status-image" x="8"/>
</hbox>

View file

@ -60,6 +60,7 @@
<command id="cmd_zotero_newCollection" oncommand="ZoteroPane_Local.newCollection()"/>
<command id="cmd_zotero_newSavedSearch" oncommand="ZoteroPane_Local.newSearch()"/>
<command id="cmd_zotero_newStandaloneNote" oncommand="ZoteroPane_Local.newNote(event.shiftKey);"/>
<!-- Keep in sync with browser.js::scrapeThisPage(), until that calls this directly -->
<command id="cmd_zotero_newItemFromCurrentPage" oncommand="ZoteroPane.addItemFromPage('temporaryPDFHack', event.shiftKey ? !Zotero.Prefs.get('automaticSnapshots') : null)"/>
</commandset>
@ -139,7 +140,6 @@
</menu>
</menupopup>
</toolbarbutton>
<toolbarbutton id="zotero-tb-item-from-page" class="zotero-tb-button standalone-no-display" tooltiptext="&zotero.toolbar.newItemFromPage.label;" command="cmd_zotero_newItemFromCurrentPage"/>
<toolbarbutton id="zotero-tb-lookup" class="zotero-tb-button" tooltiptext="&zotero.toolbar.lookup.label;" type="panel">
<panel id="zotero-lookup-panel" type="arrow" onpopupshown="Zotero_Lookup.onShowing()"
onpopuphidden="Zotero_Lookup.onHidden(event)">