Merging changesets 1030 through 1034 to the Beta 3 tag

This commit is contained in:
Dan Stillman 2007-01-03 12:25:40 +00:00
parent 592296338f
commit 7036f13a10
9 changed files with 219 additions and 24 deletions

View File

@ -23,7 +23,12 @@
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="note-editor">
<resources>
<stylesheet src="chrome://zotero/skin/bindings/noteeditor.css"/>
</resources>
<implementation>
<field name="itemRef">null</field>
<property name="item" onget="return this.itemRef;">
@ -103,8 +108,7 @@
</body>
</method>
</implementation>
<handlers>
</handlers>
<content>
<xul:vbox xbl:inherits="flex">
<xul:label id="citeLabel"/>

View File

@ -301,8 +301,6 @@
<parameter name="clear"/>
<body>
<![CDATA[
Zotero.debug(clear);
var textbox = this.id('tags-search');
var t = textbox.inputField;

View File

@ -39,6 +39,10 @@ function onLoad()
var id = params['id'];
var collectionID = params['coll'];
if (params['abstract']) {
noteEditor.setAttribute('abstract', true);
}
if(id && id != '' && id != 'undefined')
{
var ref = Zotero.Items.get(id);

View File

@ -322,7 +322,6 @@ var ZoteroPane = new function()
// If showing, set scope to items in current view
// and focus filter textbox
if (collapsed) {
tagSelector.init();
_setTagScope();
tagSelector.focusTextbox();
}
@ -355,7 +354,8 @@ var ZoteroPane = new function()
function _setTagScope() {
var itemgroup = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
var tagSelector = document.getElementById('zotero-tag-selector');
if (tagSelector.getAttribute('collapsed') == 'false') {
if (!tagSelector.getAttribute('collapsed') ||
tagSelector.getAttribute('collapsed') == 'false') {
Zotero.debug('Updating tag selector with current tags');
tagSelector.scope = itemgroup.getChildTags();
}
@ -406,6 +406,7 @@ var ZoteroPane = new function()
{
document.getElementById('zotero-view-note-button').removeAttribute('sourceID');
}
document.getElementById('zotero-note-editor').setAttribute('abstract', item.ref.isAbstract());
document.getElementById('zotero-item-pane-content').selectedIndex = 2;
}
else if(item.isAttachment())
@ -438,10 +439,44 @@ var ZoteroPane = new function()
// For the time being, use a silly little popup
label.className = 'zotero-clicky';
label.onclick = function(event){
var newTitle = prompt(Zotero.getString('itemFields.title') + ':', val);
if (newTitle && newTitle != val)
{
item.ref.setField('title', newTitle);
var nsIPS = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var newTitle = { value: val };
var checkState = { value: false };
while (true) {
var result = nsIPS.prompt(window,
Zotero.getString('pane.item.attachments.rename.title'),
'', newTitle,
Zotero.getString('pane.item.attachments.rename.renameAssociatedFile'),
checkState);
if (!result || !newTitle.value) {
return;
}
if (checkState.value) {
var renamed = item.ref.renameAttachmentFile(newTitle.value);
if (renamed == -1) {
var confirmed = confirm(newTitle.value + ' exists. Overwrite existing file?');
if (confirmed) {
item.ref.renameAttachmentFile(newTitle.value, true);
break;
}
continue;
}
else if (renamed == -2 || !renamed) {
alert(Zotero.getString('pane.item.attachments.rename.error'));
return;
}
}
break;
}
if (newTitle.value != val) {
item.ref.setField('title', newTitle.value);
item.ref.save();
}
}
@ -1180,7 +1215,15 @@ var ZoteroPane = new function()
function openNoteWindow(id, parent)
{
window.open('chrome://zotero/content/note.xul?v=1'+(id ? '&id='+id : '')+(parent ? '&coll='+parent : ''),'','chrome,resizable,centerscreen');
if (id) {
var item = Zotero.Items.get(id)
}
if (item) {
var isAbstract = item.isAbstract();
}
window.open('chrome://zotero/content/note.xul?v=1' + (id ? '&id=' + id : '')
+ (parent ? '&coll=' + parent : '') + (isAbstract ? '&abstract=1' : ''),
'', 'chrome,resizable,centerscreen');
}

View File

@ -33,6 +33,7 @@ Zotero.Attachments = new function(){
this.linkFromURL = linkFromURL;
this.linkFromDocument = linkFromDocument;
this.importFromDocument = importFromDocument;
this.getPath = getPath;
var self = this;
@ -491,6 +492,18 @@ Zotero.Attachments = new function(){
}
function getPath(file, linkMode) {
if (linkMode == self.LINK_MODE_IMPORTED_URL ||
linkMode == self.LINK_MODE_IMPORTED_FILE) {
var storageDir = Zotero.getStorageDirectory();
storageDir.QueryInterface(Components.interfaces.nsILocalFile);
return file.getRelativeDescriptor(storageDir);
}
return file.persistentDescriptor;
}
function _getFileNameFromURL(url, mimeType){
var nsIURL = Components.classes["@mozilla.org/network/standard-url;1"]
.createInstance(Components.interfaces.nsIURL);
@ -533,16 +546,8 @@ Zotero.Attachments = new function(){
* Returns the itemID of the new attachment
**/
function _addToDB(file, url, title, linkMode, mimeType, charsetID, sourceItemID, itemID){
if (file){
if (linkMode==self.LINK_MODE_IMPORTED_URL ||
linkMode==self.LINK_MODE_IMPORTED_FILE){
var storageDir = Zotero.getStorageDirectory();
storageDir.QueryInterface(Components.interfaces.nsILocalFile);
var path = file.getRelativeDescriptor(storageDir);
}
else {
var path = file.persistentDescriptor;
}
if (file) {
var path = getPath(file, linkMode);
}
Zotero.DB.beginTransaction();

View File

@ -1188,8 +1188,12 @@ Zotero.Item.prototype.getNotes = function(){
* Return true if a note item is an abstract, false otherwise
*/
Zotero.Item.prototype.isAbstract = function() {
if (this.isAttachment()) {
return false;
}
if (!this.isNote()) {
throw ("getAbstract() can only be called on note items");
throw ("isAbstract() can only be called on note items");
}
if (!this.getID()) {
@ -1249,6 +1253,9 @@ Zotero.Item.prototype.setAbstract = function(set) {
var sql = "UPDATE itemNotes SET isAbstract=? WHERE itemID=?";
Zotero.DB.valueQuery(sql, [set ? 1 : null, this.getID()]);
this.removeAllRelated();
this.removeAllTags();
Zotero.DB.commitTransaction();
this._noteIsAbstract = !!set;
@ -1416,6 +1423,46 @@ Zotero.Item.prototype.getFile = function(row){
}
/*
* Rename file associated with an attachment
*
* -1 Destination file exists -- use _force_ to overwrite
* -2 Error renaming
* false Attachment file not found or other error
*/
Zotero.Item.prototype.renameAttachmentFile = function(newName, force) {
var file = this.getFile();
if (!file) {
return false;
}
try {
var dest = file.parent;
dest.append(newName);
if (force) {
dest.remove(null);
}
else if (dest.exists()) {
return -1;
}
file.moveTo(file.parent, newName);
var linkMode = this.getAttachmentLinkMode();
var path = Zotero.Attachments.getPath(file, linkMode);
var sql = "UPDATE itemAttachments SET path=? WHERE itemID=?";
Zotero.DB.query(sql, [path, this.getID()]);
return true;
}
catch (e) {
return -2;
}
}
/*
* Return a file:/// URL path to files and snapshots
*/
@ -1531,6 +1578,10 @@ Zotero.Item.prototype.addTag = function(tag){
throw ('Cannot add tag to unsaved item in Item.addTag()');
}
if (this.isAbstract()) {
throw ('Cannot add tag to abstract note');
}
if (!tag){
Zotero.debug('Not saving empty tag in Item.addTag()', 2);
return false;
@ -1559,6 +1610,10 @@ Zotero.Item.prototype.addTagByID = function(tagID) {
throw ('Cannot add tag to unsaved item in Item.addTagByID()');
}
if (this.isAbstract()) {
throw ('Cannot add tag to abstract note');
}
if (!tagID) {
Zotero.debug('Not saving nonexistent tag in Item.addTagByID()', 2);
return false;
@ -1644,6 +1699,18 @@ Zotero.Item.prototype.removeTag = function(tagID){
Zotero.Notifier.trigger('modify', 'item', this.getID());
}
Zotero.Item.prototype.removeAllTags = function(){
if (!this.getID()) {
throw ('Cannot remove tags on unsaved item');
}
Zotero.DB.beginTransaction();
Zotero.DB.query("DELETE FROM itemTags WHERE itemID=?", this.getID());
Zotero.Tags.purge();
Zotero.DB.commitTransaction();
Zotero.Notifier.trigger('modify', 'item', this.getID());
}
//
// Methods dealing with See Also links
@ -1656,6 +1723,10 @@ Zotero.Item.prototype.addSeeAlso = function(itemID){
return false;
}
if (this.isAbstract()) {
throw ('Cannot add Related item to abstract note');
}
Zotero.DB.beginTransaction();
if (!Zotero.Items.get(itemID)){
@ -1682,6 +1753,10 @@ Zotero.Item.prototype.addSeeAlso = function(itemID){
}
Zotero.Item.prototype.removeSeeAlso = function(itemID){
if (!this.getID()) {
throw ('Cannot remove related item of unsaved item');
}
Zotero.DB.beginTransaction();
var sql = "DELETE FROM itemSeeAlso WHERE itemID=? AND linkedItemID=?";
Zotero.DB.query(sql, [this.getID(), itemID]);
@ -1691,6 +1766,22 @@ Zotero.Item.prototype.removeSeeAlso = function(itemID){
Zotero.Notifier.trigger('modify', 'item', [this.getID(), itemID]);
}
Zotero.Item.prototype.removeAllRelated = function() {
if (!this.getID()) {
throw ('Cannot remove related items of unsaved item');
}
Zotero.DB.beginTransaction();
var relateds = this.getSeeAlso();
Zotero.DB.query("DELETE FROM itemSeeAlso WHERE itemID=?", this.getID());
Zotero.DB.query("DELETE FROM itemSeeAlso WHERE linkedItemID=?", this.getID());
Zotero.DB.commitTransaction();
if (relateds) {
Zotero.Notifier.trigger('modify', 'item', relateds);
}
}
Zotero.Item.prototype.getSeeAlso = function(){
// Check both ways, using a UNION to take advantage of indexes
var sql ="SELECT linkedItemID FROM itemSeeAlso WHERE itemID=?1 UNION "

View File

@ -579,9 +579,9 @@ Zotero.ItemTreeView.prototype.sort = function()
}
if(order)
this._dataItems.sort(oppositeSort);
else
this._dataItems.sort(doSort);
else
this._dataItems.sort(oppositeSort);
this._refreshHashMap();
@ -671,6 +671,8 @@ Zotero.ItemTreeView.prototype.deleteSelection = function(eraseChildren, force)
Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
this.selection.selectEventsSuppressed = true;
var savedSelection = this.saveSelection();
var savedOpenState = this.saveOpenState();
var savedFirstRow = this.saveFirstRow();
switch (type) {
case 'search':
@ -688,6 +690,8 @@ Zotero.ItemTreeView.prototype.setFilter = function(type, data) {
this.sort();
this.rememberOpenState(savedOpenState);
this.rememberFirstRow(savedFirstRow);
this.rememberSelection(savedSelection);
this.selection.selectEventsSuppressed = false;
this._treebox.invalidate();
@ -790,6 +794,45 @@ Zotero.ItemTreeView.prototype.rememberSelection = function(selection)
}
}
Zotero.ItemTreeView.prototype.saveOpenState = function() {
var ids = [];
for (var i=0, len=this.rowCount; i<len; i++) {
if (this.isContainer(i) && this.isContainerOpen(i)) {
ids.push(this._getItemAtRow(i).ref.getID());
}
}
return ids;
}
Zotero.ItemTreeView.prototype.rememberOpenState = function(ids) {
for each(var id in ids) {
var row = this._itemRowMap[id];
if (!row || !this.isContainer(row) || this.isContainerOpen(row)) {
continue;
}
this.toggleOpenState(row);
}
}
Zotero.ItemTreeView.prototype.saveFirstRow = function() {
var row = this._treebox.getFirstVisibleRow();
if (row) {
return this._getItemAtRow(row).ref.getID();
}
return false;
}
Zotero.ItemTreeView.prototype.rememberFirstRow = function(firstRow) {
if (firstRow && this._itemRowMap[firstRow]) {
this._treebox.scrollToRow(this._itemRowMap[firstRow]);
}
}
/*
* Returns an array of item ids of visible items in current sort order
*/

View File

@ -51,6 +51,9 @@ pane.item.notes.delete.confirm = Are you sure you want to delete this note?
pane.item.notes.count.zero = %S notes:
pane.item.notes.count.singular = %S note:
pane.item.notes.count.plural = %S notes:
pane.item.attachments.rename.title = New title:
pane.item.attachments.rename.renameAssociatedFile = Rename associated file
pane.item.attachments.rename.error = An error occurred while renaming the file.
pane.item.attachments.view.link = View Page
pane.item.attachments.view.snapshot = View Snapshot
pane.item.attachments.view.file = View File

View File

@ -0,0 +1,4 @@
noteeditor[abstract="true"] #links
{
display: none;
}