Addresses #329, Method for going to URL separate from View button

URL label is now clickable -- has cursor feedback on hover but still needs a visual indicator of some sort

Other changes:

- Can now load snapshots and pages in new tab/window by using the standard Firefox modifier keys while clicking the View button or the URL field
- View button in metadata pane now displays "View" or "View Snapshot" as appropriate
- Better detection of invalid snapshots when deciding whether to use "View" or "View Snapshot"
- Non-HTML snapshots viewed via the View button are loaded using the standard attachment logic rather than just window.loadURI()
- Added green Go arrows to standalone attachment view/show buttons

Method changes:

- ZoteroPane.loadURI(uri, event, data) - (new) Load URI with standard Firefox mod key support; passing an object with 'attachmentID' property triggers annotation mode
- ZoteroPane.viewAttachment(attachmentID, event) - (new)
- ZoteroPane.viewSelectedAttachment(event) - Now takes event param
- Zotero_Browser.annotateThisPage(id) changed to annotatePage(id, [browser]) to handle background tab loading
This commit is contained in:
Dan Stillman 2007-02-11 12:07:22 +00:00
parent fb40565b8c
commit f1c98f4450
9 changed files with 188 additions and 79 deletions

View File

@ -39,7 +39,7 @@
var Zotero_Browser = new function() {
this.init = init;
this.scrapeThisPage = scrapeThisPage;
this.annotateThisPage = annotateThisPage;
this.annotatePage = annotatePage;
this.toggleMode = toggleMode;
this.chromeLoad = chromeLoad;
this.chromeUnload = chromeUnload;
@ -56,7 +56,6 @@ var Zotero_Browser = new function() {
this.statusImage = null;
var _scrapePopupShowing = false;
var _annotateNextLoad = false;
var _browserData = new Object();
var _blacklist = [
@ -119,8 +118,13 @@ var Zotero_Browser = new function() {
/*
* flags a page for annotation
*/
function annotateThisPage(id) {
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
function annotatePage(id, browser) {
if (browser) {
var tab = _getTabObject(browser);
}
else {
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
}
tab.annotateNextLoad = true;
tab.annotateID = id;
}

View File

@ -58,6 +58,7 @@ var ZoteroItemPane = new function()
this.ensureElementIsVisible = ensureElementIsVisible;
this.loadPane = loadPane;
this.changeTypeTo = changeTypeTo;
this.onViewClick = onViewClick;
this.onOpenURLClick = onOpenURLClick;
this.addCreatorRow = addCreatorRow;
this.switchCreatorMode = switchCreatorMode;
@ -171,32 +172,59 @@ var ZoteroItemPane = new function()
// Enable/disable "View =>" button
testView: try
{
var validURI = false;
var viewButton = document.getElementById('zotero-go-to-url');
viewButton.removeAttribute('viewSnapshot');
viewButton.removeAttribute('viewURL');
viewButton.setAttribute('label',
Zotero.getString('pane.item.goToURL.online.label'));
viewButton.setAttribute('tooltiptext',
Zotero.getString('pane.item.goToURL.online.tooltip'));
var spec = false, validURI = false;
var uri = Components.classes["@mozilla.org/network/standard-url;1"].
createInstance(Components.interfaces.nsIURI);
// First try to find a snapshot matching the item's URL field
var snapID = _itemBeingEdited.getBestSnapshot();
if (snapID)
{
var spec = Zotero.Items.get(snapID).getLocalFileURL();
}
else
{
var spec = _itemBeingEdited.getField('url');
if (snapID) {
spec = Zotero.Items.get(snapID).getLocalFileURL();
uri.spec = spec;
if (!uri.scheme || uri.scheme != 'file') {
snapID = false;
spec = false;
}
}
if (!spec)
{
// If that fails, try the URL field itself
if (!spec) {
spec = _itemBeingEdited.getField('url');
uri.spec = spec;
if (!(uri.scheme && (uri.host || uri.scheme == 'file'))) {
spec = false;
}
}
if (!spec) {
break testView;
}
var uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(spec, null, null);
validURI = uri.scheme && (uri.host || uri.scheme=='file');
validURI = true;
document.getElementById('zotero-tb-go-to-url').setAttribute('viewURL', spec);
if (snapID) {
viewButton.setAttribute('label',
Zotero.getString('pane.item.goToURL.snapshot.label'));
viewButton.setAttribute('tooltiptext',
Zotero.getString('pane.item.goToURL.snapshot.tooltip'));
viewButton.setAttribute('viewSnapshot', snapID);
}
else {
viewButton.setAttribute('viewURL', spec);
}
}
catch (e){}
document.getElementById('zotero-tb-go-to-url').setAttribute('disabled', !validURI);
catch (e){Zotero.debug(e);}
viewButton.setAttribute('disabled', !validURI);
// Enable/disable "Locate =>" (OpenURL) button
switch (_itemBeingEdited.getType())
@ -212,7 +240,7 @@ var ZoteroItemPane = new function()
default:
var openURL = false;
}
document.getElementById('zotero-tb-openurl').setAttribute('disabled', !openURL);
document.getElementById('zotero-openurl').setAttribute('disabled', !openURL);
// Clear and rebuild creator type menu
while(_creatorTypeMenu.hasChildNodes())
@ -273,8 +301,17 @@ var ZoteroItemPane = new function()
);
var label = document.createElement("label");
label.setAttribute('fieldname', fieldNames[i]);
label.setAttribute("value", Zotero.ItemFields.getLocalizedString(_itemBeingEdited.getType(), fieldNames[i]) + ":");
label.setAttribute("onclick","this.nextSibling.blur();");
if (fieldNames[i] == 'url' && val) {
label.setAttribute("isButton", true);
label.setAttribute("onclick", "ZoteroPane.loadURI(this.nextSibling.value, event)");
label.setAttribute("tooltiptext", Zotero.getString('pane.item.goToURL.online.tooltip'));
}
else {
label.setAttribute("onclick","this.nextSibling.blur();");
}
addDynamicRow(label,valueElement);
}
@ -482,12 +519,21 @@ var ZoteroItemPane = new function()
}
}
function onOpenURLClick()
function onViewClick(button, event) {
if (button.getAttribute('viewURL')) {
ZoteroPane.loadURI(button.getAttribute('viewURL'), event);
}
else if (button.getAttribute('viewSnapshot')) {
ZoteroPane.viewAttachment(button.getAttribute('viewSnapshot'), event);
}
}
function onOpenURLClick(event)
{
var url = Zotero.OpenURL.resolve(_itemBeingEdited);
if (url)
{
window.loadURI(Zotero.OpenURL.resolve(_itemBeingEdited));
ZoteroPane.loadURI(url, event);
}
}

View File

@ -39,15 +39,14 @@
ZoteroItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],
'typeID', typeID, otherFields)"/>
</popupset>
<hbox align="center">
<button id="zotero-tb-go-to-url" label="&zotero.toolbar.goToURL.label;"
<hbox id="zotero-editpane-go-buttons" align="center">
<button id="zotero-go-to-url"
onfocus="ZoteroItemPane.ensureElementIsVisible(this)"
tooltiptext="&zotero.toolbar.goToURL.tooltip;" flex="1"
oncommand="window.loadURI(this.getAttribute('viewURL'))" disabled="false"/>
<button id="zotero-tb-openurl" label="&zotero.toolbar.openURL.label;"
tooltiptext="&zotero.toolbar.openURL.tooltip;" flex="1"
oncommand="ZoteroItemPane.onViewClick(this, event)" disabled="false"/>
<button id="zotero-openurl" label="&zotero.toolbar.openURL.label;"
tooltiptext="&zotero.toolbar.openURL.tooltip;"
onfocus="ZoteroItemPane.ensureElementIsVisible(this)"
oncommand="ZoteroItemPane.onOpenURLClick();"/>
oncommand="ZoteroItemPane.onOpenURLClick(event);"/>
</hbox>
<hbox align="center">
<menulist id="zotero-editpane-type-menu" oncommand="ZoteroItemPane.changeTypeTo(this.value, this)" flex="1"

View File

@ -63,6 +63,7 @@ var ZoteroPane = new function()
this.buildCollectionContextMenu = buildCollectionContextMenu;
this.buildItemContextMenu = buildItemContextMenu;
this.onDoubleClick = onDoubleClick;
this.loadURI = loadURI;
this.setItemsPaneMessage = setItemsPaneMessage;
this.clearItemsPaneMessage = clearItemsPaneMessage;
this.contextPopupShowing = contextPopupShowing;
@ -73,6 +74,7 @@ var ZoteroPane = new function()
this.addItemFromPage = addItemFromPage;
this.addAttachmentFromDialog = addAttachmentFromDialog;
this.addAttachmentFromPage = addAttachmentFromPage;
this.viewAttachment = viewAttachment;
this.viewSelectedAttachment = viewSelectedAttachment;
this.showSelectedAttachmentInFilesystem = showSelectedAttachmentInFilesystem;
@ -1204,7 +1206,7 @@ var ZoteroPane = new function()
document.getElementById('zotero-view-note-button').doCommand();
}
else if (item && item.isAttachment()) {
this.viewSelectedAttachment();
this.viewSelectedAttachment(event);
}
}
}
@ -1212,6 +1214,52 @@ var ZoteroPane = new function()
}
/*
* Loads a URL following the standard modifier key behavior
* (e.g. meta-click == new background tab, meta-shift-click == new front tab,
* shift-click == new window, no modifier == frontmost tab
*/
function loadURI(uri, event, data) {
// Open in new tab
if (event.metaKey) {
var tab = gBrowser.addTab(uri);
var browser = gBrowser.getBrowserForTab(tab);
if (data && data.attachmentID) {
Zotero_Browser.annotatePage(data.attachmentID, browser);
// In case the page has already loaded, update
Zotero_Browser.updateStatus();
}
if (event.shiftKey) {
gBrowser.selectedTab = tab;
}
}
else if (event.shiftKey) {
window.open(uri, "zotero-loaded-page",
"menubar=yes,location=yes,toolbar=yes,personalbar=yes,resizable=yes,scrollbars=yes,status=yes");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var newWindow = wm.getMostRecentWindow("navigator:browser");
var browser = newWindow.getBrowser();
if (data && data.attachmentID) {
newWindow.Zotero_Browser.annotatePage(data.attachmentID);
// In case the page has already loaded, update
newWindow.Zotero_Browser.updateStatus();
}
}
else {
if (data && data.attachmentID) {
// Enable annotation
Zotero_Browser.annotatePage(data.attachmentID);
}
window.loadURI(uri);
}
}
function setItemsPaneMessage(msg) {
document.getElementById('zotero-items-pane-content').selectedIndex = 1;
var elem = document.getElementById('zotero-items-pane-message');
@ -1440,48 +1488,51 @@ var ZoteroPane = new function()
}
function viewSelectedAttachment()
function viewAttachment(itemID, event) {
var attachment = Zotero.Items.get(itemID);
if (!attachment.isAttachment()) {
throw ("Item " + itemID + " is not an attachment in ZoteroPane.viewAttachment()");
}
if (attachment.getAttachmentLinkMode() == Zotero.Attachments.LINK_MODE_LINKED_URL) {
this.loadURI(attachment.getField('url'), event);
return;
}
var file = attachment.getFile();
if (file) {
var mimeType = attachment.getAttachmentMimeType();
if (mimeType) {
var ext = Zotero.File.getExtension(file);
var internal = Zotero.MIME.hasInternalHandler(mimeType, ext);
}
var fileURL = attachment.getLocalFileURL();
if (internal || Zotero.MIME.fileHasInternalHandler(file)) {
this.loadURI(fileURL, event, { attachmentID: itemID});
}
else {
// Some platforms don't have nsILocalFile.launch, so we just load it and
// let the Firefox external helper app window handle it
try {
file.launch();
}
catch (e) {
window.loadURI(fileURL, event);
}
}
}
else {
alert(Zotero.getString('pane.item.attachments.fileNotFound'));
}
}
function viewSelectedAttachment(event)
{
if (this.itemsView && this.itemsView.selection.count == 1) {
var attachment = this.getSelectedItems()[0];
if(attachment.getAttachmentLinkMode() != Zotero.Attachments.LINK_MODE_LINKED_URL)
{
var file = attachment.getFile();
if (file){
var mimeType = attachment.getAttachmentMimeType();
if (mimeType) {
var ext = Zotero.File.getExtension(file);
var internal = Zotero.MIME.hasInternalHandler(mimeType, ext);
}
var fileURL = attachment.getLocalFileURL();
if (internal || Zotero.MIME.fileHasInternalHandler(file))
{
// enable annotation
Zotero_Browser.annotateThisPage(attachment.getID());
window.loadURI(fileURL);
}
else {
// Some platforms don't have nsILocalFile.launch, so we just load it and
// let the Firefox external helper app window handle it
try {
file.launch();
}
catch (e) {
window.loadURI(fileURL);
}
}
}
else {
alert(Zotero.getString('pane.item.attachments.fileNotFound'));
}
}
else
{
window.loadURI(attachment.getField('url'));
}
this.viewAttachment(this.getSelectedItems(true)[0], event);
}
}

View File

@ -284,11 +284,11 @@
<vbox id="zotero-view-attachment" flex="1">
<label id="zotero-attachment-label"/>
<hbox>
<button id="zotero-attachment-view" flex="1" oncommand="ZoteroPane.viewSelectedAttachment();"/>
<button id="zotero-attachment-view" flex="1" oncommand="ZoteroPane.viewSelectedAttachment(event);"/>
<button id="zotero-attachment-show" label="&zotero.item.attachment.file.show;" flex="1" oncommand="ZoteroPane.showSelectedAttachmentInFilesystem()"/>
</hbox>
<vbox>
<label id="zotero-attachment-url" class="text-link" crop="end" onclick="window.loadURI(this.value)"/>
<label id="zotero-attachment-url" class="text-link" crop="end" onclick="ZoteroPane.loadURI(this.value, event)"/>
<label id="zotero-attachment-accessed"/>
</vbox>
<noteeditor id="zotero-attachment-note-editor" notitle="1" flex="1"/>

View File

@ -44,8 +44,6 @@
<!ENTITY zotero.toolbar.advancedSearch "Advanced Search">
<!ENTITY zotero.toolbar.search.label "Search:">
<!ENTITY zotero.toolbar.fullscreen.tooltip "Toggle Fullscreen Mode">
<!ENTITY zotero.toolbar.goToURL.label "View">
<!ENTITY zotero.toolbar.goToURL.tooltip "Go to this item online">
<!ENTITY zotero.toolbar.openURL.label "Locate">
<!ENTITY zotero.toolbar.openURL.tooltip "Find through your local library">

View File

@ -48,6 +48,10 @@ pane.items.menu.generateReport.multiple = Generate Report from Selected Items...
pane.item.selected.zero = No items selected
pane.item.selected.multiple = %S items selected
pane.item.goToURL.online.label = View
pane.item.goToURL.online.tooltip = Go to this item online
pane.item.goToURL.snapshot.label = View Snapshot
pane.item.goToURL.snapshot.tooltip = View snapshot for this item
pane.item.changeType.title = Are you sure you want to change the item type?
pane.item.changeType.message = The following fields will be lost:
pane.item.defaultFirstName = first

View File

@ -30,6 +30,11 @@
font-weight: bold;
}
#zotero-editpane-dynamic-fields row label:first-child[isButton=true]:hover
{
cursor: pointer;
}
#zotero-editpane-dynamic-fields row label
{
-moz-user-focus: ignore;

View File

@ -250,13 +250,15 @@
list-style-image: url('chrome://zotero/skin/search-cancel-active.png');
}
#zotero-tb-go-to-url, #zotero-tb-openurl
#zotero-go-to-url, #zotero-openurl,
#zotero-attachment-view, #zotero-attachment-show
{
list-style-image: url('chrome://zotero/skin/toolbar-go-arrow.png');
-moz-box-direction: reverse;
-moz-box-flex: 1;
}
#zotero-tb-go-to-url[disabled=true], #zotero-tb-openurl[disabled=true]
#zotero-go-to-url[disabled=true], #zotero-openurl[disabled=true]
{
list-style-image: url('chrome://zotero/skin/toolbar-go-arrow-disabled.png');
}