Merge [3617-3838] from branch to trunk

This commit is contained in:
Dan Stillman 2008-11-30 20:18:48 +00:00
parent 51e11b9071
commit 337b16361a
19 changed files with 659 additions and 231 deletions

View file

@ -60,9 +60,6 @@ var Zotero_Citation_Dialog = new function () {
document.getElementById("multiple-sources-button").label = Zotero.getString("citation.multipleSources");
document.getElementById("show-editor-button").label = Zotero.getString("citation.showEditor");
if(Zotero.isWin) {
document.getElementById("zotero-select-items-container").style.border = "1px solid black";
}
io = window.arguments[0].wrappedJSObject;
// find accept button
@ -135,6 +132,15 @@ var Zotero_Citation_Dialog = new function () {
_updateAccept();
}
// Center citation popups manually after a delay when using a popup, since
// popups aren't resizable and there might be persisted positions
if (Zotero.Integration.usePopup) {
document.getElementsByTagName("dialog")[0].style.border = "1px solid black";
setTimeout(function () {
window.centerWindowOnScreen();
}, 1);
}
}
/*

View file

@ -124,6 +124,15 @@ var ZoteroAdvancedSearch = new function() {
}
this.startDrag = function (event, element) {
if (Zotero.isFx2 || Zotero.isFx30) {
nsDragAndDrop.startDrag(event, element);
return;
}
element.onDragStart(event);
}
function onUnload() {
// Unregister search from Notifier
if (this.itemsView) {

View file

@ -39,7 +39,7 @@
<tree id="zotero-items-tree" flex="1" hidecolumnpicker="true" seltype="multiple"
ondblclick="ZoteroAdvancedSearch.onDblClick(event, this)"
ondraggesture="if (event.target.localName == 'treechildren') { nsDragAndDrop.startDrag(event, ZoteroAdvancedSearch.itemsView); }">
ondraggesture="if (event.target.localName == 'treechildren') { Zotero.debug('starting'); ZoteroAdvancedSearch.startDrag(event, ZoteroAdvancedSearch.itemsView); }">
<treecols>
<treecol
id="zotero-items-column-title" primary="true"

View file

@ -112,16 +112,12 @@ var Zotero_File_Interface_Bibliography = new function() {
}
document.getElementById("fields").label = Zotero.getString("integration."+formatOption+".label");
document.getElementById("fields-caption").textContent = Zotero.getString("integration."+formatOption+".caption");
if(Zotero.isWin) {
// add border on Windows
document.getElementById("zotero-doc-prefs-dialog").style.border = "1px solid black";
}
}
// Center popup manually after a delay on Windows, since window
// isn't resizable and there might be a persisted position
if (Zotero.isWin) {
// Center citation popups manually after a delay when using a popup, since
// popups aren't resizable and there might be persisted positions
if (Zotero.Integration.usePopup) {
document.getElementsByTagName("dialog")[0].style.border = "1px solid black";
setTimeout(function () {
window.centerWindowOnScreen();
}, 1);

View file

@ -39,9 +39,6 @@ var Zotero_Bibliography_Dialog = new function () {
function load() {
document.getElementById('editor').format = "Integration";
if(Zotero.isWin) {
document.getElementsByTagName("dialog")[0].style.border = "1px solid black";
}
bibEditInterface = window.arguments[0].wrappedJSObject;
itemSet = bibEditInterface.getItemSet();
@ -50,6 +47,15 @@ var Zotero_Bibliography_Dialog = new function () {
// load bibliography entires
_loadItems();
// Center citation popups manually after a delay when using a popup, since
// popups aren't resizable and there might be persisted positions
if (Zotero.Integration.usePopup) {
document.getElementsByTagName("dialog")[0].style.border = "1px solid black";
setTimeout(function () {
window.centerWindowOnScreen();
}, 1);
}
}
/*

View file

@ -1728,6 +1728,39 @@ var ZoteroPane = new function()
}
this.startDrag = function (event, element) {
if (Zotero.isFx2 || Zotero.isFx30) {
nsDragAndDrop.startDrag(event, element);
return;
}
element.onDragStart(event);
}
this.dragEnter = function (event, element) {
if (Zotero.isFx2 || Zotero.isFx30) {
return;
}
return element.onDragEnter(event);
}
this.dragOver = function (event, element) {
if (Zotero.isFx2 || Zotero.isFx30) {
return nsDragAndDrop.dragOver(event, element);
}
return element.onDragOver(event);
}
this.dragDrop = function (event, element) {
if (Zotero.isFx2 || Zotero.isFx30) {
return nsDragAndDrop.drop(event, element);
}
return element.onDrop(event);
}
/*
* Loads a URL following the standard modifier key behavior
* (e.g. meta-click == new background tab, meta-shift-click == new front tab,

View file

@ -39,8 +39,6 @@
<script src="timelineInterface.js"/>
<script src="recognizePDF.js"/>
<script src="browser.js"/>
<script src="chrome://global/content/nsDragAndDrop.js"/>
<script src="chrome://global/content/nsTransferable.js"/>
<commandset id="mainCommandSet">
<command id="cmd_zotero_search" oncommand="ZoteroPane.search();"/>
@ -150,10 +148,12 @@
<tree id="zotero-collections-tree" hidecolumnpicker="true" context="zotero-collectionmenu"
onmouseover="ZoteroPane.collectionsView.setHighlightedRows();"
ondblclick="ZoteroPane.onDoubleClick(event, this);"
onselect="ZoteroPane.onCollectionSelected();" seltype="single"
ondragdrop="nsDragAndDrop.drop(event, ZoteroPane.collectionsView)"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event, ZoteroPane.collectionsView);"
onkeypress="ZoteroPane.handleKeyPress(event, this.id)"
onselect="ZoteroPane.onCollectionSelected();" seltype="single"
ondraggesture="if (event.target.localName == 'treechildren') { ZoteroPane.startDrag(event, ZoteroPane.collectionsView); }"
ondragenter="return ZoteroPane.dragEnter(event, ZoteroPane.collectionsView)"
ondragover="return ZoteroPane.dragOver(event, ZoteroPane.collectionsView)"
ondragdrop="return ZoteroPane.dragDrop(event, ZoteroPane.collectionsView)"
flex="1">
<treecols>
<treecol
@ -213,9 +213,10 @@
onfocus="if (ZoteroPane.itemsView.rowCount &amp;&amp; !ZoteroPane.itemsView.selection.count) { ZoteroPane.itemsView.selection.select(0); }"
onkeypress="ZoteroPane.handleKeyPress(event, this.id)"
onselect="ZoteroPane.itemSelected();"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ZoteroPane.itemsView);"
ondragover="nsDragAndDrop.dragOver(event, ZoteroPane.itemsView)"
ondragdrop="nsDragAndDrop.drop(event, ZoteroPane.itemsView)"
ondraggesture="if (event.target.localName == 'treechildren') { ZoteroPane.startDrag(event, ZoteroPane.itemsView); }"
ondragenter="return ZoteroPane.dragEnter(event, ZoteroPane.itemsView)"
ondragover="return ZoteroPane.dragOver(event, ZoteroPane.itemsView)"
ondragdrop="return ZoteroPane.dragDrop(event, ZoteroPane.itemsView)"
flex="1">
<treecols>
<treecol

View file

@ -42,15 +42,6 @@ function doLoad()
collectionsView = new Zotero.CollectionTreeView();
document.getElementById('zotero-collections-tree').view = collectionsView;
// Center citation popups manually after a delay on Windows, since windows
// aren't resizable and there might be persisted positions
if (Zotero.isWin &&
window.document.documentURI != 'chrome://zotero/content/selectItemsDialog.xul') {
setTimeout(function () {
window.centerWindowOnScreen();
}, 1);
}
}
function doUnload()

View file

@ -48,6 +48,10 @@ Zotero.Attachments = new function(){
var title = file.leafName;
if (!file.isFile()) {
throw ("'" + title + "' must be a file in Zotero.Attachments.importFromFile()");
}
Zotero.DB.beginTransaction();
try {
@ -61,13 +65,10 @@ Zotero.Attachments = new function(){
// Create directory for attachment files within storage directory
var destDir = this.createDirectoryForItem(itemID);
file.copyTo(destDir, null);
// Point to copied file
var newFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
newFile.initWithFile(destDir);
var newFile = destDir.clone();
newFile.append(title);
var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile);
@ -141,13 +142,13 @@ Zotero.Attachments = new function(){
var itemID = attachmentItem.save();
attachmentItem = Zotero.Items.get(itemID)
var newFile = this.getStorageDirectory(itemID);
var newName = newFile.leafName;
var storageDir = Zotero.getStorageDirectory();
file.parent.copyTo(storageDir, newName);
var destDir = this.getStorageDirectory(itemID);
_moveOrphanedDirectory(destDir);
file.parent.copyTo(storageDir, destDir.leafName);
// Point to copied file
var newFile = destDir.clone();
newFile.append(file.leafName);
attachmentItem.attachmentPath = this.getPath(newFile, this.LINK_MODE_IMPORTED_URL);
@ -182,6 +183,8 @@ Zotero.Attachments = new function(){
Zotero.debug('Importing attachment from URL');
// Throw error on invalid URLs
//
// TODO: allow other schemes
var urlRe = /^https?:\/\/[^\s]*$/;
var matches = urlRe.exec(url);
if (!matches) {
@ -274,9 +277,7 @@ Zotero.Attachments = new function(){
// Create a new folder for this item in the storage directory
var destDir = Zotero.Attachments.createDirectoryForItem(itemID);
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithFile(destDir);
var file = destDir.clone();
file.append(fileName);
wbp.progressListener = new Zotero.WebProgressFinishListener(function(){
@ -890,9 +891,12 @@ Zotero.Attachments = new function(){
* Create directory for attachment files within storage directory
*
* @param integer itemID Item id
*
* If a directory exists with the same name, move it to orphaned-files
*/
function createDirectoryForItem(itemID) {
var dir = this.getStorageDirectory(itemID);
_moveOrphanedDirectory(dir);
if (!dir.exists()) {
dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
}
@ -1040,6 +1044,63 @@ Zotero.Attachments = new function(){
}
/**
* If directory exists and is non-empty, move it to orphaned-files directory
*
* If empty, just remove it
*/
function _moveOrphanedDirectory(dir) {
if (!dir.exists()) {
return;
}
dir = dir.clone();
var files = dir.directoryEntries;
files.QueryInterface(Components.interfaces.nsIDirectoryEnumerator);
if (!files.hasMoreElements()) {
dir.remove(false);
}
files.close();
// Create orphaned-files directory if it doesn't exist
var orphaned = Zotero.getZoteroDirectory();
orphaned.append('orphaned-files');
if (!orphaned.exists()) {
orphaned.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
}
// Find unique filename for orphaned file
var orphanTarget = orphaned.clone();
orphanTarget.append(dir.leafName);
var newName = null;
if (orphanTarget.exists()) {
try {
orphanTarget.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644);
newName = orphanTarget.leafName;
}
catch (e) {
// DEBUG: Work around createUnique() brokenness on Windows
// as of Fx3.0.3 (https://bugzilla.mozilla.org/show_bug.cgi?id=452217)
//
// We just delete the conflicting file
if (Zotero.isWin && e.name == 'NS_ERROR_FILE_ACCESS_DENIED') {
orphanTarget.remove(true);
}
else {
throw (e);
}
}
if (newName) {
orphanTarget.remove(false);
}
}
// Move target to orphaned files directory
dir.moveTo(orphaned, newName);
}
/**
* Create a new item of type 'attachment' and add to the itemAttachments table
*

View file

@ -74,8 +74,58 @@ Zotero.CollectionTreeView.prototype.setTree = function(treebox)
var matches = lastViewedFolder.match(/^(?:(C|S)([0-9]+)|L)$/);
var select = 0;
if (matches) {
if (matches[1] == 'C' && this._collectionRowMap[matches[2]]) {
select = this._collectionRowMap[matches[2]];
if (matches[1] == 'C') {
if (this._collectionRowMap[matches[2]]) {
select = this._collectionRowMap[matches[2]];
}
// Search recursively
else {
var path = [];
var failsafe = 10; // Only go up ten levels
var lastCol = matches[2];
do {
failsafe--;
var col = Zotero.Collections.get(lastCol);
if (!col) {
var msg = "Last-viewed collection not found";
Zotero.debug(msg);
path = [];
break;
}
var par = col.getParent();
if (!par) {
var msg = "Parent collection not found in "
+ "Zotero.CollectionTreeView.setTree()";
Zotero.debug(msg, 1);
Components.utils.reportError(msg);
path = [];
break;
}
lastCol = par;
path.push(lastCol);
}
while (!this._collectionRowMap[lastCol] && failsafe > 0)
if (path.length) {
for (var i=path.length-1; i>=0; i--) {
var id = path[i];
var row = this._collectionRowMap[id];
if (!row) {
var msg = "Collection not found in tree in "
+ "Zotero.CollectionTreeView.setTree()";
Zotero.debug(msg, 1);
Components.utils.reportError(msg);
break;
}
if (!this.isContainerOpen(row)) {
this.toggleOpenState(row);
if (this._collectionRowMap[matches[2]]) {
select = this._collectionRowMap[matches[2]];
break;
}
}
}
}
}
}
else if (matches[1] == 'S' && this._searchRowMap[matches[2]]) {
select = this._searchRowMap[matches[2]];
@ -622,39 +672,67 @@ Zotero.CollectionTreeCommandController.prototype.onEvent = function(evt)
///
/// Drag-and-drop functions:
/// canDrop() and drop() are for nsITreeView
/// onDragStart(), getSupportedFlavours(), and onDrop() for nsDragAndDrop.js + nsTransferable.js
/// onDragStart(), getSupportedFlavours(), and onDrop() for nsDragAndDrop.js
///
////////////////////////////////////////////////////////////////////////////////
/**
* Start a drag using nsDragAndDrop.js or HTML 5 Drag and Drop
*/
Zotero.CollectionTreeView.prototype.onDragStart = function(event, transferData, action) {
var collectionID = this._getItemAtRow(this.selection.currentIndex).ref.id;
// Use nsDragAndDrop.js interface for Firefox 2 and Firefox 3.0
var oldMethod = Zotero.isFx2 || Zotero.isFx30;
if (oldMethod) {
transferData.data = new TransferData();
transferData.data.addDataForFlavour("zotero/collection", collectionID);
}
else {
event.dataTransfer.setData("zotero/collection", collectionID);
}
}
/**
* Returns the supported drag flavors
*
* Called by nsDragAndDrop.js
*/
Zotero.CollectionTreeView.prototype.getSupportedFlavours = function () {
var flavors = new FlavourSet();
flavors.appendFlavour("zotero/collection");
flavors.appendFlavour("zotero/item");
flavors.appendFlavour("zotero/item-xml");
flavors.appendFlavour("text/x-moz-url");
flavors.appendFlavour("application/x-moz-file", "nsIFile");
return flavors;
}
/*
* Called while a drag is over the tree.
*/
Zotero.CollectionTreeView.prototype.canDrop = function(row, orient)
Zotero.CollectionTreeView.prototype.canDrop = function(row, orient, dragData)
{
// workaround... two different services call canDrop
// (nsDragAndDrop, and the tree) -- this is for the former,
// used when dragging between windows
//Zotero.debug("Row is " + row + "; orient is " + orient);
// Two different services call canDrop, nsDragAndDrop and the tree
// This is for the former, used when dragging between windows
if (typeof row == 'object') {
return false;
}
//Zotero.debug('Row is ' + row);
//Zotero.debug('Orient is ' + orient);
try
{
var dataSet = nsTransferable.get(this.getSupportedFlavours(),nsDragAndDrop.getDragData, true);
if (!dragData) {
var dragData = Zotero.DragDrop.getDragData(this);
}
catch (e)
{
//a work around a limitation in nsDragAndDrop.js -- the mDragSession is not set until the drag moves over another control.
//(this will only happen if the first drag is from the collection list)
nsDragAndDrop.mDragSession = nsDragAndDrop.mDragService.getCurrentSession();
if (!dragData) {
return false;
}
var data = dataSet.first.first;
var dataType = data.flavour.contentType;
var dataType = dragData.dataType;
var data = dragData.data;
// For dropping collections onto root level
if (orient == 1 && row == 0 && dataType == 'zotero/collection') {
@ -665,7 +743,7 @@ Zotero.CollectionTreeView.prototype.canDrop = function(row, orient)
var rowCollection = this._getItemAtRow(row).ref; //the collection we are dragging over
if (dataType == 'zotero/item') {
var ids = data.data.split(',');
var ids = data;
for each(var id in ids)
{
var item = Zotero.Items.get(id);
@ -698,15 +776,16 @@ Zotero.CollectionTreeView.prototype.canDrop = function(row, orient)
return false;
}
// Don't allow folder drag
if (dataType == 'application/x-moz-file' && data.data.isDirectory()) {
if (dataType == 'application/x-moz-file' && data[0].isDirectory()) {
return false;
}
return true;
}
else if (dataType == 'zotero/collection'
&& data.data != rowCollection.id
&& !Zotero.Collections.get(data.data).hasDescendent('collection', rowCollection.id)) {
return true;//collections cannot be dropped on themselves, nor in their children
// Collections cannot be dropped on themselves, nor in their children
&& data[0] != rowCollection.id
&& !Zotero.Collections.get(data[0]).hasDescendent('collection', rowCollection.id)) {
return true;
}
}
return false;
@ -717,25 +796,26 @@ Zotero.CollectionTreeView.prototype.canDrop = function(row, orient)
*/
Zotero.CollectionTreeView.prototype.drop = function(row, orient)
{
var dataSet = nsTransferable.get(this.getSupportedFlavours(),nsDragAndDrop.getDragData, true);
var data = dataSet.first.first;
var dataType = data.flavour.contentType;
var dragData = Zotero.DragDrop.getDragData(this);
if (!this.canDrop(row, orient)) {
if (!this.canDrop(row, orient, dragData)) {
return false;
}
var dataType = dragData.dataType;
var data = dragData.data;
if(dataType == 'zotero/collection')
{
var targetCollectionID;
if(this._getItemAtRow(row).isCollection())
targetCollectionID = this._getItemAtRow(row).ref.id;
var droppedCollection = Zotero.Collections.get(data.data);
var droppedCollection = Zotero.Collections.get(data[0]);
droppedCollection.parent = targetCollectionID;
droppedCollection.save();
}
else if (dataType == 'zotero/item') {
var ids = data.data.split(',');
var ids = data;
if (ids.length < 1) {
return;
}
@ -769,7 +849,6 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
}
Zotero.DB.commitTransaction();
return;
}
else if (dataType == 'text/x-moz-url' || dataType == 'application/x-moz-file') {
@ -782,12 +861,11 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
var unlock = Zotero.Notifier.begin(true);
try {
var dataList = dataSet.dataList;
for (var i=0, len=dataList.length; i<len; i++) {
var file = dataList[i].first.data;
for (var i=0; i<data.length; i++) {
var file = data[i];
if (dataType == 'text/x-moz-url') {
var url = file.split("\n")[0];
var url = data[i];
if (url.indexOf('file:///') == 0) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
@ -840,35 +918,38 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
}
}
/*
* Begin a drag
*/
Zotero.CollectionTreeView.prototype.onDragStart = function(evt,transferData,action)
{
transferData.data=new TransferData();
//attach ID
transferData.data.addDataForFlavour("zotero/collection",this._getItemAtRow(this.selection.currentIndex).ref.id);
}
/*
* Returns the supported drag flavors
* Called by HTML 5 Drag and Drop when dragging over the tree
*/
Zotero.CollectionTreeView.prototype.getSupportedFlavours = function ()
{
var flavors = new FlavourSet();
flavors.appendFlavour("zotero/collection");
flavors.appendFlavour("zotero/item");
flavors.appendFlavour("zotero/item-xml");
flavors.appendFlavour("text/x-moz-url");
flavors.appendFlavour("application/x-moz-file", "nsIFile");
return flavors;
Zotero.CollectionTreeView.prototype.onDragEnter = function (event) {
Zotero.debug("Storing current drag data");
Zotero.DragDrop.currentDataTransfer = event.dataTransfer;
}
/*
* Called by nsDragAndDrop.js for any sort of drop on the tree
* Called by nsDragAndDrop.js and HTML 5 Drag and Drop when dragging over the tree
*/
Zotero.CollectionTreeView.prototype.onDrop = function (evt,dropdata,session) { }
Zotero.CollectionTreeView.prototype.onDragOver = function (event, dropdata, session) {
return false;
}
/*
* Called by nsDragAndDrop.js and HTML 5 Drag and Drop when dropping onto the tree
*/
Zotero.CollectionTreeView.prototype.onDrop = function (event, dropdata, session) {
return false;
}
Zotero.CollectionTreeView.prototype.onDragExit = function (event) {
Zotero.debug("Clearing drag data");
Zotero.DragDrop.currentDataTransfer = null;
}
////////////////////////////////////////////////////////////////////////////////
///

View file

@ -776,7 +776,7 @@ Zotero.DBConnection.prototype.backupDatabase = function (suffix) {
Zotero.DBConnection.prototype.startDummyStatement = function () {
try {
if (!this._dummyConnection) {
this._debug("Opening database '" + this._dbName + " for dummy statement");
this._debug("Opening database '" + this._dbName + "' for dummy statement");
// Get the storage service
var store = Components.classes["@mozilla.org/storage/service;1"].
getService(Components.interfaces.mozIStorageService);

View file

@ -414,9 +414,13 @@ Zotero.Fulltext = new function(){
proc.init(_pdfInfo);
var args = [file.path, infoFile.path];
proc.run(true, args, args.length);
var totalPages = this.getTotalPagesFromFile(itemID);
try {
proc.run(true, args, args.length);
var totalPages = this.getTotalPagesFromFile(itemID);
}
catch (e) {
Zotero.debug("Error running pdfinfo");
}
}
else {
Zotero.debug(this.pdfInfoName + " is not available");
@ -443,7 +447,13 @@ Zotero.Fulltext = new function(){
var pagesIndexed = Math.min(maxPages, totalPages);
}
args.push(file.path, cacheFile.path);
proc.run(true, args, args.length);
try {
proc.run(true, args, args.length);
}
catch (e) {
Zotero.debug("Error running pdftotext");
return false;
}
if (!cacheFile.exists()) {
Zotero.debug("Cache file doesn't exist!");

View file

@ -37,6 +37,10 @@ Zotero.Integration = new function() {
this.handleHeader = handleHeader;
this.handleEnvelope = handleEnvelope;
this.__defineGetter__("usePopup", function () {
return !Zotero.isMac && !Zotero.Prefs.get("integration.realWindow");
});
/*
* initializes a very rudimentary web server used for SOAP RPC
*/
@ -795,10 +799,12 @@ Zotero.Integration.SOAP_Compat = new function() {
io.useBookmarks = session.prefs.fieldType;
}
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, 'chrome://zotero/content/integrationDocPrefs.xul', '',
'chrome,modal,centerscreen' + (Zotero.isWin ? ',popup' : ''), io, true);
watcher.openWindow(
null, 'chrome://zotero/content/integrationDocPrefs.xul', '',
'chrome,modal,centerscreen'
+ (Zotero.Integration.usePopup ? ',popup' : ''),
io, true
);
session.prefs.useEndnotes = io.useEndnotes;
session.prefs.fieldType = io.useBookmarks;
session.setStyle(io.style, session.prefs);
@ -1162,9 +1168,13 @@ Zotero.Integration.Session.prototype.editCitation = function(index, citation) {
}
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, 'chrome://zotero/content/addCitationDialog.xul', '',
'chrome,modal,centerscreen,resizable=yes' + (Zotero.isWin ? ',popup' : ''), io);
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(
null, 'chrome://zotero/content/addCitationDialog.xul', '',
'chrome,modal,centerscreen,resizable=yes'
+ (Zotero.Integration.usePopup ? ',popup' : ''),
io
);
if(citation && !io.citation.citationItems.length) {
io.citation = citation;
@ -1330,10 +1340,14 @@ Zotero.Integration.Session.prototype.editBibliography = function() {
this.bibliographyDataHasChanged = this.bibliographyHasChanged = true;
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, 'chrome://zotero/content/editBibliographyDialog.xul', '',
'chrome,modal,centerscreen,resizable=yes' + (Zotero.isWin ? ',popup' : ''), io, true);
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(
null, 'chrome://zotero/content/editBibliographyDialog.xul', '',
'chrome,modal,centerscreen,resizable=yes'
+ (Zotero.Integration.usePopup ? ',popup' : ''),
io,
true
);
}
/*

View file

@ -33,6 +33,8 @@
*/
Zotero.ItemTreeView = function(itemGroup, sourcesOnly)
{
this.wrappedJSObject = this;
this._initialized = false;
this._itemGroup = itemGroup;
@ -1347,6 +1349,20 @@ Zotero.ItemTreeView.prototype.rememberSelection = function(selection)
}
Zotero.ItemTreeView.prototype.selectSearchMatches = function () {
if (this._searchMode) {
var ids = [];
for (var id in this._searchItemIDs) {
ids.push(id);
}
this.rememberSelection(ids);
}
else {
this.selection.clearSelection();
}
}
Zotero.ItemTreeView.prototype.saveOpenState = function() {
var ids = [];
for (var i=0, len=this.rowCount; i<len; i++) {
@ -1521,8 +1537,14 @@ Zotero.ItemTreeCommandController.prototype.isCommandEnabled = function(cmd)
Zotero.ItemTreeCommandController.prototype.doCommand = function(cmd)
{
if(cmd == 'cmd_selectAll')
this.tree.view.selection.selectAll();
if (cmd == 'cmd_selectAll') {
if (this.tree.view.wrappedJSObject._itemGroup.isSearchMode()) {
this.tree.view.wrappedJSObject.selectSearchMatches();
}
else {
this.tree.view.selection.selectAll();
}
}
}
Zotero.ItemTreeCommandController.prototype.onEvent = function(evt)
@ -1532,16 +1554,17 @@ Zotero.ItemTreeCommandController.prototype.onEvent = function(evt)
////////////////////////////////////////////////////////////////////////////////
///
/// Drag-and-drop functions:
/// for nsDragAndDrop.js + nsTransferable.js
/// Drag-and-drop functions
///
////////////////////////////////////////////////////////////////////////////////
/*
* Begin a drag
/**
* Start a drag using nsDragAndDrop.js or HTML 5 Drag and Drop
*/
Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
{
Zotero.ItemTreeView.prototype.onDragStart = function (event, transferData, action) {
// Use nsDragAndDrop.js interface for Firefox 2 and Firefox 3.0
var oldMethod = Zotero.isFx2 || Zotero.isFx30;
// Quick implementation of dragging of XML item format
if (this.readOnly) {
var items = this.getSelectedItems();
@ -1552,30 +1575,93 @@ Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
xml.items.item += xmlNode;
}
Zotero.debug(xml.toXMLString());
transferData.data = new TransferData();
transferData.data.addDataForFlavour("zotero/item-xml", xml.toXMLString());
if (oldMethod) {
transferData.data = new TransferData();
transferData.data.addDataForFlavour("zotero/item-xml", xml.toXMLString());
}
else {
event.dataTransfer.setData("zotero/item-xml", xml.toXMLString());
}
return;
}
transferData.data = new TransferData();
transferData.data.addDataForFlavour("zotero/item", this.saveSelection());
var itemIDs = this.saveSelection();
var items = Zotero.Items.get(itemIDs);
var items = Zotero.Items.get(this.saveSelection());
if (oldMethod) {
transferData.data = new TransferData();
transferData.data.addDataForFlavour("zotero/item", itemIDs.join());
}
else {
event.dataTransfer.setData("zotero/item", itemIDs.join());
}
// If at least one file is a non-web-link attachment and can be found,
// enable dragging to file system
for (var i=0; i<items.length; i++) {
if (items[i].isAttachment() &&
items[i].attachmentLinkMode != Zotero.Attachments.LINK_MODE_LINKED_URL
// Multi-file drag
// - Doesn't work on Firefox >=3.0/Windows
if (Zotero.isFx2 || !Zotero.isWin) {
// If at least one file is a non-web-link attachment and can be found,
// enable dragging to file system
for (var i=0; i<items.length; i++) {
if (items[i].isAttachment()
&& items[i].attachmentLinkMode
!= Zotero.Attachments.LINK_MODE_LINKED_URL
&& items[i].getFile()) {
transferData.data.addDataForFlavour("application/x-moz-file-promise",
new Zotero.ItemTreeView.fileDragDataProvider(), 0, Components.interfaces.nsISupports);
break;
Zotero.debug("Adding file via x-moz-file-promise");
if (oldMethod) {
transferData.data.addDataForFlavour(
"application/x-moz-file-promise",
new Zotero.ItemTreeView.fileDragDataProvider(),
0,
Components.interfaces.nsISupports
);
}
else {
event.dataTransfer.mozSetDataAt(
"application/x-moz-file-promise",
new Zotero.ItemTreeView.fileDragDataProvider(),
0
);
}
break;
}
}
}
// Copy first file on Firefox >=3.0 Windows
else {
var index = 0;
for (var i=0; i<items.length; i++) {
if (items[i].isAttachment() &&
items[i].getAttachmentLinkMode() != Zotero.Attachments.LINK_MODE_LINKED_URL) {
var file = items[i].getFile();
if (!file) {
continue;
}
var fph = Components.classes["@mozilla.org/network/protocol;1?name=file"]
.createInstance(Components.interfaces.nsIFileProtocolHandler);
var uri = fph.getURLSpecFromFile(file);
if (oldMethod) {
transferData.data.addDataForFlavour("text/x-moz-url", uri + "\n" + file.leafName);
transferData.data.addDataForFlavour("application/x-moz-file", file);
transferData.data.addDataForFlavour("application/x-moz-file-promise-url", uri);
break;
}
else {
event.dataTransfer.mozSetDataAt("text/x-moz-url", uri + "\n" + file.leafName, index);
event.dataTransfer.mozSetDataAt("application/x-moz-file", file, index);
event.dataTransfer.mozSetDataAt("application/x-moz-file-promise-url", uri, index);
// DEBUG: possible to drag multiple files without x-moz-file-promise?
break;
index++
}
}
}
}
// Get Quick Copy format for current URL
var url = this._ownerDocument.defaultView.content.location.href;
var url = this._ownerDocument.defaultView.content ?
this._ownerDocument.defaultView.content.location.href : null;
var format = Zotero.QuickCopy.getFormatFromURL(url);
Zotero.debug("Dragging with format " + Zotero.QuickCopy.getFormattedNameFromSetting(format));
@ -1587,7 +1673,12 @@ Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
}
var text = obj.output.replace(/\r\n/g, "\n");
transferData.data.addDataForFlavour("text/unicode", text);
if (oldMethod) {
transferData.data.addDataForFlavour("text/unicode", text);
}
else {
event.dataTransfer.setData("text/plain", text);
}
}
try {
@ -1596,10 +1687,18 @@ Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
Zotero.QuickCopy.getContentFromItems(items, format, exportCallback);
}
else if (mode.indexOf('bibliography') == 0) {
var content = Zotero.QuickCopy.getContentFromItems(items, format, null, evt.shiftKey);
transferData.data.addDataForFlavour("text/unicode", content.text);
if (content.html) {
transferData.data.addDataForFlavour("text/html", content.html);
var content = Zotero.QuickCopy.getContentFromItems(items, format, null, event.shiftKey);
if (oldMethod) {
if (content.html) {
transferData.data.addDataForFlavour("text/html", content.html);
}
transferData.data.addDataForFlavour("text/unicode", content.text);
}
else {
if (content.html) {
event.dataTransfer.setData("text/html", content.html);
}
event.dataTransfer.setData("text/plain", content.text);
}
}
else {
@ -1613,6 +1712,8 @@ Zotero.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
// Implements nsIFlavorDataProvider for dragging attachment files to OS
//
// Not used on Windows in Firefox 3 or higher
Zotero.ItemTreeView.fileDragDataProvider = function() { };
Zotero.ItemTreeView.fileDragDataProvider.prototype = {
@ -1641,6 +1742,7 @@ Zotero.ItemTreeView.fileDragDataProvider.prototype = {
var items = {};
transferable.getTransferData("zotero/item", items, dataSize);
items.value.QueryInterface(Components.interfaces.nsISupportsString);
var draggedItems = Zotero.Items.get(items.value.data.split(','));
var items = [];
@ -1832,11 +1934,12 @@ Zotero.ItemTreeView.fileDragDataProvider.prototype = {
}
/*
* Called by nsDragAndDrop.js for any sort of drop on the tree
/**
* Returns the supported drag flavours
*
* Called by nsDragAndDrop.js
*/
Zotero.ItemTreeView.prototype.getSupportedFlavours = function ()
{
Zotero.ItemTreeView.prototype.getSupportedFlavours = function () {
var flavors = new FlavourSet();
flavors.appendFlavour("zotero/item");
flavors.appendFlavour("zotero/item-xml");
@ -1845,47 +1948,26 @@ Zotero.ItemTreeView.prototype.getSupportedFlavours = function ()
return flavors;
}
Zotero.ItemTreeView.prototype.canDrop = function(row, orient)
Zotero.ItemTreeView.prototype.canDrop = function(row, orient, dragData)
{
//Zotero.debug("Row is " + row + "; orient is " + orient);
if (row == -1 && orient == -1) {
return true;
}
try
{
var dataSet = nsTransferable.get(this.getSupportedFlavours(),
nsDragAndDrop.getDragData, true);
if (!dragData) {
var dragData = Zotero.DragDrop.getDragData(this);
}
catch (e)
{
// A work around a limitation in nsDragAndDrop.js -- the mDragSession
// is not set until the drag moves over another control.
// (This will only happen if the first drag is from the item list.)
nsDragAndDrop.mDragSession = nsDragAndDrop.mDragService.getCurrentSession();
if (!dragData) {
return false;
}
var dataType = dragData.dataType;
var data = dragData.data;
var data = dataSet.first.first;
var dataType = data.flavour.contentType;
//Zotero.debug("Drag data type is " + dataType);
switch (dataType) {
case 'zotero/item':
var ids = data.data.split(','); // ids of rows we are dragging in
break;
case 'text/x-moz-url':
var url = data.data.split("\n")[0];
break;
case 'application/x-moz-file':
var file = data.data;
// Don't allow folder drag
if (file.isDirectory()) {
return false;
}
break;
if (dataType == 'zotero/item') {
var ids = data;
}
// workaround... two different services call canDrop
@ -1929,9 +2011,6 @@ Zotero.ItemTreeView.prototype.canDrop = function(row, orient)
return false;
}
//Zotero.debug('row is ' + row);
//Zotero.debug('orient is ' + orient);
// Highlight the rows correctly on drag
var rowItem = this._getItemAtRow(row).ref; //the item we are dragging over
@ -1997,30 +2076,17 @@ Zotero.ItemTreeView.prototype.canDrop = function(row, orient)
*/
Zotero.ItemTreeView.prototype.drop = function(row, orient)
{
try
{
var dataSet = nsTransferable.get(this.getSupportedFlavours(),
nsDragAndDrop.getDragData, true);
}
catch (e)
{
// A work around a limitation in nsDragAndDrop.js -- the mDragSession
// is not set until the drag moves over another control.
// (This will only happen if the first drag is from the item list.)
nsDragAndDrop.mDragSession = nsDragAndDrop.mDragService.getCurrentSession();
var dataSet = nsTransferable.get(this.getSupportedFlavours(),
nsDragAndDrop.getDragData, true);
}
var dragData = Zotero.DragDrop.getDragData(this);
var data = dataSet.first.first;
var dataType = data.flavour.contentType;
if (!this.canDrop(row, orient)) {
if (!this.canDrop(row, orient, dragData)) {
return false;
}
var dataType = dragData.dataType;
var data = dragData.data;
if (dataType == 'zotero/item') {
var ids = data.data.split(','); // ids of rows we are dragging in
var ids = data;
// Dropped directly on a row
if (orient == 0)
@ -2083,12 +2149,11 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
var unlock = Zotero.Notifier.begin(true);
try {
var dataList = dataSet.dataList;
for (var i=0, len=dataList.length; i<len; i++) {
var file = dataList[i].first.data;
for (var i=0; i<data.length; i++) {
var file = data[i];
if (dataType == 'text/x-moz-url') {
var url = file.split("\n")[0];
var url = data[i];
if (url.indexOf('file:///') == 0) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
@ -2141,12 +2206,30 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
}
}
/*
* Called by nsDragAndDrop.js for any sort of drop on the tree
*/
Zotero.ItemTreeView.prototype.onDrop = function (evt,dropdata,session){ }
Zotero.ItemTreeView.prototype.onDragEnter = function (event) {
Zotero.debug("Storing current drag data");
Zotero.DragDrop.currentDataTransfer = event.dataTransfer;
}
/*
* Called by nsDragAndDrop.js and HTML 5 Drag and Drop when dragging over the tree
*/
Zotero.ItemTreeView.prototype.onDragOver = function (event, dropdata, session) {
return false;
}
/*
* Called by nsDragAndDrop.js and HTML 5 Drag and Drop when dropping onto the tree
*/
Zotero.ItemTreeView.prototype.onDrop = function (event, dropdata, session) {
return false;
}
Zotero.ItemTreeView.prototype.onDragExit = function (event) {
Zotero.debug("Clearing drag data");
Zotero.DragDrop.currentDataTransfer = null;
}
Zotero.ItemTreeView.prototype.onDragOver = function (evt,dropdata,session) { }
////////////////////////////////////////////////////////////////////////////////
///

View file

@ -31,19 +31,21 @@ Zotero.Report = new function() {
/^http:\/\/([^\.]*\.)?nytimes\.com/
];
var escapeXML = function (str) {
str = str.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ud800-\udfff\ufffe\uffff]/g, '\u2B1A');
return Zotero.Utilities.prototype.htmlSpecialChars(str);
}
function generateHTMLDetails(items, combineChildItems) {
var ZU = new Zotero.Utilities();
var escapeXML = ZU.htmlSpecialChars;
var content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ';
content += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n';
content += '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\n';
content += '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n';
content += '<title>' + Zotero.getString('report.title.default') + '</title>\n';
content += '<link rel="stylesheet" type="text/css" href="chrome://zotero/skin/report/detail.css"/>\n';
content += '<link rel="stylesheet" type="text/css" media="screen,projection" href="chrome://zotero/skin/report/detail_screen.css"/>\n';
content += '<link rel="stylesheet" type="text/css" media="print" href="chrome://zotero/skin/report/detail_print.css"/>\n';
content += '<link rel="stylesheet" type="text/css" href="zotero://report/detail.css"/>\n';
content += '<link rel="stylesheet" type="text/css" media="screen,projection" href="zotero://report/detail_screen.css"/>\n';
content += '<link rel="stylesheet" type="text/css" media="print" href="zotero://report/detail_print.css"/>\n';
content += '</head>\n\n<body>\n';
content += '<ul class="report' + (combineChildItems ? ' combineChildItems' : '') + '">\n';
@ -142,9 +144,6 @@ Zotero.Report = new function() {
function _generateMetadataTable(arr) {
var ZU = new Zotero.Utilities();
var escapeXML = ZU.htmlSpecialChars;
var table = false;
var content = '<table>\n';
@ -220,7 +219,7 @@ Zotero.Report = new function() {
continue;
}
arr[i] = ZU.trim(arr[i] + '');
arr[i] = Zotero.Utilities.prototype.trim(arr[i] + '');
// Skip empty fields
if (!arr[i]) {
@ -303,9 +302,6 @@ Zotero.Report = new function() {
function _generateTagsList(arr) {
var ZU = new Zotero.Utilities();
var escapeXML = ZU.htmlSpecialChars;
var content = '';
if (arr['tags'] && arr['tags'].length) {
var str = Zotero.getString('report.tags');
@ -321,9 +317,6 @@ Zotero.Report = new function() {
function _generateAttachmentsList(arr) {
var ZU = new Zotero.Utilities();
var escapeXML = ZU.htmlSpecialChars;
var content = '';
if (arr.attachments && arr.attachments.length) {
content += '<h3 class="attachments">' + escapeXML(Zotero.getString('itemFields.attachments')) + '</h3>\n';

View file

@ -1204,6 +1204,11 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
var uri = IOService.newURI(item.path, "", null);
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
if (file.path == '/') {
Zotero.debug("Translate: Ignoring attachment '" + item.path + "': error parsing path", 2);
return;
}
if (!file.exists()) {
// use item title if possible, or else file leaf name
var title = item.title;

View file

@ -123,6 +123,8 @@ var Zotero = new function(){
getService(Components.interfaces.nsIXULAppInfo)
this.isFx2 = appInfo.platformVersion.indexOf('1.8') === 0; // TODO: remove
this.isFx3 = appInfo.platformVersion.indexOf('1.9') === 0;
this.isFx30 = appInfo.platformVersion.indexOf('1.9.0') === 0;
this.isFx31 = appInfo.platformVersion.indexOf('1.9.1') === 0;
// OS platform
var win = Components.classes["@mozilla.org/appshell/appShellService;1"]
@ -1903,6 +1905,122 @@ Zotero.Date = new function(){
}
}
Zotero.DragDrop = {
currentDataTransfer: null,
getDragData: function (element, firstOnly) {
var dragData = {
dataType: '',
data: []
};
// Use nsDragAndDrop.js interface for Firefox 2 and Firefox 3.0
var oldMethod = Zotero.isFx2 || Zotero.isFx30;
if (oldMethod) {
try {
var dataSet = nsTransferable.get(
element.getSupportedFlavours(),
nsDragAndDrop.getDragData,
true
);
}
catch (e) {
// A work around a limitation in nsDragAndDrop.js -- the mDragSession
// is not set until the drag moves over another control.
// (This will only happen if the first drag is from the item list.)
nsDragAndDrop.mDragSession = nsDragAndDrop.mDragService.getCurrentSession();
return false;
}
var firstData = dataSet.first.first;
dragData.dataType = firstData.flavour.contentType;
var dataList = dataSet.dataList;
var len = firstOnly ? 1 : dataList.length;
//Zotero.debug("Drag data type is " + dragData.dataType);
switch (dragData.dataType) {
case 'zotero/collection':
case 'zotero/item':
var ids = firstData.data.split(','); // ids of rows we are dragging in
dragData.data = ids;
break;
case 'text/x-moz-url':
var urls = [];
for (var i=0; i<len; i++) {
var url = dataList[i].first.data.split("\n")[0];
urls.push(url);
}
dragData.data = urls;
break;
case 'application/x-moz-file':
var files = [];
for (var i=0; i<len; i++) {
var file = dataList[i].first.data;
file.QueryInterface(Components.interfaces.nsIFile);
// Don't allow folder drag
if (file.isDirectory()) {
continue;
}
files.push(file);
}
dragData.data = files;
break;
}
}
// Firefox 3.1 and higher
else {
var dt = this.currentDataTransfer;
if (!dt) {
Zotero.debug("Drag data not available");
return false;
}
var len = firstOnly ? 1 : dt.mozItemCount;
if (dt.types.contains('zotero/collection')) {
dragData.dataType = 'zotero/collection';
var ids = dt.getData('zotero/collection').split(",");
dragData.data = ids;
}
else if (dt.types.contains('zotero/item')) {
dragData.dataType = 'zotero/item';
var ids = dt.getData('zotero/item').split(",");
dragData.data = ids;
}
else if (dt.types.contains('application/x-moz-file')) {
dragData.dataType = 'application/x-moz-file';
var files = [];
for (var i=0; i<len; i++) {
var file = dt.mozGetDataAt("application/x-moz-file", i);
file.QueryInterface(Components.interfaces.nsIFile);
// Don't allow folder drag
if (file.isDirectory()) {
continue;
}
files.push(file);
}
dragData.data = files;
}
else if (dt.types.contains('text/x-moz-url')) {
dragData.dataType = 'text/x-moz-url';
var urls = [];
for (var i=0; i<len; i++) {
var url = dt.getData("application/x-moz-url", i).split("\n")[0];
urls.push(url);
}
dragData.data = urls;
}
}
return dragData;
}
}
/**
* Functions for creating and destroying hidden browser objects
**/

View file

@ -73,7 +73,7 @@ function ChromeExtensionHandler() {
var ReportExtension = new function(){
this.newChannel = newChannel;
this.__defineGetter__('loadAsChrome', function () { return true; });
this.__defineGetter__('loadAsChrome', function () { return false; });
function newChannel(uri){
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
@ -119,6 +119,22 @@ function ChromeExtensionHandler() {
break;
default:
// Proxy CSS files
if (type.match(/^detail.*\.css$/)) {
var chromeURL = 'chrome://zotero/skin/report/' + type;
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(chromeURL, null, null);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
var fileURI = chromeReg.convertChromeURL(uri);
var ph = Components.classes["@mozilla.org/network/protocol;1?name=file"]
.createInstance(Components.interfaces.nsIFileProtocolHandler);
var channel = ioService.newChannelFromURI(fileURI);
return channel;
}
// Display all items
var type = 'library';
var s = new Zotero.Search();
s.addCondition('noChildren', 'true');
@ -753,7 +769,6 @@ function ChromeExtensionHandler() {
var SelectExtensionSpec = ZOTERO_SCHEME + "://select"
this._extensions[SelectExtensionSpec] = SelectExtension;
}
@ -768,7 +783,12 @@ ChromeExtensionHandler.prototype = {
protocolFlags :
Components.interfaces.nsIProtocolHandler.URI_NORELATIVE |
Components.interfaces.nsIProtocolHandler.URI_NOAUTH |
Components.interfaces.nsIProtocolHandler.URI_IS_LOCAL_FILE,
// DEBUG: This should be URI_IS_LOCAL_FILE, and MUST be if any
// extensions that modify data are added
// - https://www.zotero.org/trac/ticket/1156
//
//Components.interfaces.nsIProtocolHandler.URI_IS_LOCAL_FILE,
Components.interfaces.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
allowPort : function(port, scheme) {
return false;

View file

@ -78,6 +78,7 @@ pref("extensions.zotero.export.quickCopy.setting", 'bibliography=http://www.zote
// Integration settings
pref("extensions.zotero.integration.port", 50001);
pref("extensions.zotero.integration.autoRegenerate", -1); // -1 = ask; 0 = no; 1 = yes
pref("extensions.zotero.integration.realWindow", false);
// Zeroconf
pref("extensions.zotero.zeroconf.server.enabled", false);