2006-08-02 16:49:19 +00:00
|
|
|
/*
|
2006-08-30 06:00:44 +00:00
|
|
|
Zotero
|
2006-08-02 16:49:19 +00:00
|
|
|
Copyright (C) 2006 Center for History and New Media, George Mason University, Fairfax, VA
|
|
|
|
http://chnm.gmu.edu/
|
|
|
|
*/
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
/*
|
|
|
|
* This object contains the various functions for the interface
|
|
|
|
*/
|
2006-05-30 22:06:33 +00:00
|
|
|
var ScholarPane = new function()
|
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
var collectionsView;
|
2006-05-30 22:06:33 +00:00
|
|
|
var itemsView;
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
//Privileged methods
|
|
|
|
this.onLoad = onLoad;
|
|
|
|
this.onUnload = onUnload;
|
|
|
|
this.toggleDisplay = toggleDisplay;
|
2006-07-05 16:19:26 +00:00
|
|
|
this.fullScreen = fullScreen;
|
2006-05-30 22:06:33 +00:00
|
|
|
this.newItem = newItem;
|
2006-06-01 03:50:34 +00:00
|
|
|
this.newCollection = newCollection;
|
2006-08-09 11:43:33 +00:00
|
|
|
this.newSearch = newSearch;
|
2006-06-05 18:01:53 +00:00
|
|
|
this.onCollectionSelected = onCollectionSelected;
|
2006-05-30 22:06:33 +00:00
|
|
|
this.itemSelected = itemSelected;
|
2006-06-19 15:00:13 +00:00
|
|
|
this.deleteSelectedItem = deleteSelectedItem;
|
|
|
|
this.deleteSelectedCollection = deleteSelectedCollection;
|
2006-08-30 04:09:34 +00:00
|
|
|
this.editSelectedCollection = editSelectedCollection;
|
2006-05-30 22:06:33 +00:00
|
|
|
this.search = search;
|
2006-06-08 18:42:55 +00:00
|
|
|
this.getCollectionsView = getCollectionsView;
|
|
|
|
this.getItemsView = getItemsView;
|
2006-07-31 19:14:06 +00:00
|
|
|
this.selectItem = selectItem;
|
2006-07-24 22:12:25 +00:00
|
|
|
this.getSelectedCollection = getSelectedCollection;
|
2006-08-30 04:09:34 +00:00
|
|
|
this.getSelectedSavedSearch = getSelectedSavedSearch;
|
2006-07-26 15:09:06 +00:00
|
|
|
this.getSelectedItems = getSelectedItems;
|
2006-06-19 15:00:13 +00:00
|
|
|
this.buildCollectionContextMenu = buildCollectionContextMenu;
|
|
|
|
this.buildItemContextMenu = buildItemContextMenu;
|
2006-08-02 16:08:19 +00:00
|
|
|
this.onDoubleClick = onDoubleClick;
|
2006-06-27 22:47:17 +00:00
|
|
|
this.openNoteWindow = openNoteWindow;
|
2006-07-26 14:30:38 +00:00
|
|
|
this.newNote = newNote;
|
2006-08-12 00:18:20 +00:00
|
|
|
this.addAttachmentFromDialog = addAttachmentFromDialog;
|
|
|
|
this.addAttachmentFromPage = addAttachmentFromPage;
|
|
|
|
this.viewSelectedAttachment = viewSelectedAttachment;
|
2006-05-30 22:06:33 +00:00
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
/*
|
|
|
|
* Called when the window is open
|
|
|
|
*/
|
|
|
|
function onLoad()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-07-19 16:14:27 +00:00
|
|
|
if(Scholar.Prefs.get("scholarPaneOnTop"))
|
2006-06-28 15:15:38 +00:00
|
|
|
{
|
2006-07-19 16:14:27 +00:00
|
|
|
var oldPane = document.getElementById('scholar-pane');
|
|
|
|
var oldSplitter = document.getElementById('scholar-splitter');
|
|
|
|
var appContent = document.getElementById('appcontent');
|
|
|
|
|
|
|
|
var newPane = document.createElement('hbox');
|
|
|
|
newPane.setAttribute('id','scholar-pane');
|
|
|
|
newPane.setAttribute('collapsed',true);
|
|
|
|
newPane.setAttribute('flex','1');
|
2006-07-27 18:08:09 +00:00
|
|
|
newPane.height = oldPane.height;
|
2006-07-19 16:14:27 +00:00
|
|
|
while(oldPane.hasChildNodes())
|
|
|
|
newPane.appendChild(oldPane.firstChild);
|
|
|
|
appContent.removeChild(oldPane);
|
|
|
|
appContent.insertBefore(newPane, document.getElementById('content'));
|
|
|
|
|
|
|
|
var newSplitter = document.createElement('splitter');
|
|
|
|
newSplitter.setAttribute('id','scholar-splitter');
|
|
|
|
newSplitter.setAttribute('collapsed',true);
|
|
|
|
newSplitter.setAttribute('resizebefore','closest');
|
|
|
|
newSplitter.setAttribute('resizeafter','closest');
|
|
|
|
appContent.removeChild(oldSplitter);
|
|
|
|
appContent.insertBefore(newSplitter, document.getElementById('content'));
|
2006-07-28 16:49:19 +00:00
|
|
|
|
|
|
|
document.getElementById('tb-fullscreen').setAttribute('scholartop','true');
|
2006-06-28 15:15:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-26 14:03:54 +00:00
|
|
|
//Initialize collections view
|
|
|
|
collectionsView = new Scholar.CollectionTreeView();
|
2006-07-28 13:28:50 +00:00
|
|
|
var collectionsTree = document.getElementById('collections-tree');
|
|
|
|
collectionsTree.view = collectionsView;
|
|
|
|
collectionsTree.controllers.appendController(new Scholar.CollectionTreeCommandController(collectionsTree));
|
|
|
|
|
|
|
|
var itemsTree = document.getElementById('items-tree');
|
|
|
|
itemsTree.controllers.appendController(new Scholar.ItemTreeCommandController(itemsTree));
|
2006-07-26 14:03:54 +00:00
|
|
|
|
2006-06-20 13:59:59 +00:00
|
|
|
//Create the add menu with each item type
|
|
|
|
var addMenu = document.getElementById('tb-add').firstChild;
|
|
|
|
var itemTypes = Scholar.ItemTypes.getTypes();
|
|
|
|
for(var i = 0; i<itemTypes.length; i++)
|
|
|
|
{
|
|
|
|
var menuitem = document.createElement("menuitem");
|
|
|
|
menuitem.setAttribute("label", Scholar.getString("itemTypes."+itemTypes[i]['name']));
|
|
|
|
menuitem.setAttribute("oncommand","ScholarPane.newItem("+itemTypes[i]['id']+")");
|
|
|
|
addMenu.appendChild(menuitem);
|
|
|
|
}
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
/*
|
|
|
|
* Called when the window closes
|
|
|
|
*/
|
|
|
|
function onUnload()
|
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
collectionsView.unregister();
|
2006-06-02 15:27:52 +00:00
|
|
|
if(itemsView)
|
|
|
|
itemsView.unregister();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hides/displays the Scholar interface
|
|
|
|
*/
|
|
|
|
function toggleDisplay()
|
2006-05-31 22:01:31 +00:00
|
|
|
{
|
2006-07-19 16:14:27 +00:00
|
|
|
var visible = document.getElementById('scholar-pane').getAttribute('collapsed') == 'true';
|
2006-05-31 22:01:31 +00:00
|
|
|
|
2006-07-19 16:14:27 +00:00
|
|
|
document.getElementById('scholar-pane').setAttribute('collapsed',!visible);
|
|
|
|
document.getElementById('scholar-splitter').setAttribute('collapsed',!visible);
|
2006-07-05 16:19:26 +00:00
|
|
|
|
|
|
|
if(!visible)
|
2006-07-28 16:49:19 +00:00
|
|
|
{
|
2006-07-05 16:19:26 +00:00
|
|
|
document.getElementById('content').setAttribute('collapsed', false);
|
2006-07-28 16:49:19 +00:00
|
|
|
document.getElementById('tb-fullscreen').setAttribute('fullscreenmode', false);
|
|
|
|
}
|
2006-07-05 16:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fullScreen()
|
|
|
|
{
|
|
|
|
var visible = document.getElementById('content').getAttribute('collapsed') == 'true';
|
|
|
|
document.getElementById('content').setAttribute('collapsed', !visible);
|
2006-07-19 16:14:27 +00:00
|
|
|
document.getElementById('scholar-splitter').setAttribute('collapsed', !visible);
|
2006-07-28 16:49:19 +00:00
|
|
|
document.getElementById('tb-fullscreen').setAttribute('fullscreenmode', !visible);
|
2006-05-31 22:01:31 +00:00
|
|
|
}
|
2006-06-02 15:27:52 +00:00
|
|
|
|
|
|
|
/*
|
2006-06-17 00:57:50 +00:00
|
|
|
* Create a new item
|
2006-06-02 15:27:52 +00:00
|
|
|
*/
|
2006-05-30 22:06:33 +00:00
|
|
|
function newItem(typeID)
|
|
|
|
{
|
2006-06-19 15:00:13 +00:00
|
|
|
if(document.getElementById('tb-search').value != "")
|
|
|
|
{
|
|
|
|
document.getElementById('tb-search').value = "";
|
|
|
|
document.getElementById('tb-search').doCommand();
|
|
|
|
}
|
|
|
|
|
2006-06-17 00:57:50 +00:00
|
|
|
var item = new Scholar.Item(typeID);
|
|
|
|
item.save();
|
|
|
|
if(itemsView && itemsView._itemGroup.isCollection())
|
|
|
|
itemsView._itemGroup.ref.addItem(item.getID());
|
2006-06-19 15:00:13 +00:00
|
|
|
|
2006-06-25 04:57:52 +00:00
|
|
|
//set to Info tab
|
|
|
|
document.getElementById('scholar-view-item').selectedIndex = 0;
|
2006-08-04 14:23:44 +00:00
|
|
|
|
|
|
|
return item;
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 03:50:34 +00:00
|
|
|
function newCollection()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-06-05 17:47:36 +00:00
|
|
|
Scholar.Collections.add(Scholar.getString('pane.collections.untitled'));
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 11:43:33 +00:00
|
|
|
function newSearch()
|
|
|
|
{
|
|
|
|
var s = new Scholar.Search();
|
|
|
|
s.addCondition('title','contains','');
|
|
|
|
|
2006-08-29 11:16:31 +00:00
|
|
|
// TODO: add integer to 'Untitled' if more than one
|
2006-08-09 11:43:33 +00:00
|
|
|
var io = {dataIn: {search: s, name: 'Untitled'}, dataOut: null};
|
|
|
|
window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io);
|
|
|
|
}
|
|
|
|
|
2006-06-05 18:01:53 +00:00
|
|
|
function onCollectionSelected()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-06-02 12:59:58 +00:00
|
|
|
if(itemsView)
|
|
|
|
itemsView.unregister();
|
2006-06-06 22:43:58 +00:00
|
|
|
|
|
|
|
document.getElementById('tb-search').value = "";
|
2006-07-24 22:12:25 +00:00
|
|
|
|
2006-06-05 18:01:53 +00:00
|
|
|
if(collectionsView.selection.count == 1 && collectionsView.selection.currentIndex != -1)
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-08-09 11:43:33 +00:00
|
|
|
var itemgroup = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
|
|
|
itemgroup.setSearch('');
|
2006-06-05 13:08:16 +00:00
|
|
|
|
2006-08-09 11:43:33 +00:00
|
|
|
itemsView = new Scholar.ItemTreeView(itemgroup);
|
2006-05-30 22:06:33 +00:00
|
|
|
document.getElementById('items-tree').view = itemsView;
|
2006-08-09 11:43:33 +00:00
|
|
|
document.getElementById('tb-collection-rename').disabled = itemgroup.isLibrary();
|
2006-06-13 20:45:30 +00:00
|
|
|
itemsView.selection.clearSelection();
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-01 18:50:16 +00:00
|
|
|
document.getElementById('items-tree').view = itemsView = null;
|
2006-06-20 17:08:30 +00:00
|
|
|
document.getElementById('tb-collection-rename').disabled = true;
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemSelected()
|
|
|
|
{
|
2006-06-02 15:27:52 +00:00
|
|
|
if(itemsView && itemsView.selection.count == 1 && itemsView.selection.currentIndex != -1)
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
|
|
|
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex);
|
|
|
|
|
2006-06-27 20:37:02 +00:00
|
|
|
if(item.isNote())
|
|
|
|
{
|
2006-06-28 18:30:29 +00:00
|
|
|
var noteEditor = document.getElementById('scholar-note-editor');
|
|
|
|
noteEditor.item = null;
|
|
|
|
noteEditor.note = item.ref;
|
2006-08-02 16:08:19 +00:00
|
|
|
document.getElementById('scholar-view-note-button').setAttribute('noteID',item.ref.getID());
|
2006-07-31 19:14:06 +00:00
|
|
|
if(item.ref.getSource() != null)
|
2006-08-02 16:08:19 +00:00
|
|
|
document.getElementById('scholar-view-note-button').setAttribute('sourceID',item.ref.getSource());
|
2006-07-31 19:14:06 +00:00
|
|
|
else
|
2006-08-02 16:08:19 +00:00
|
|
|
document.getElementById('scholar-view-note-button').removeAttribute('sourceID');
|
2006-06-27 20:37:02 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 2;
|
2006-07-27 18:08:09 +00:00
|
|
|
}
|
2006-08-12 00:18:20 +00:00
|
|
|
else if(item.isAttachment())
|
2006-07-27 18:08:09 +00:00
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
document.getElementById('scholar-attachment-label').setAttribute('value',item.getField('title'));
|
|
|
|
document.getElementById('scholar-attachment-view').setAttribute('disabled', item.ref.getAttachmentLinkMode() == Scholar.Attachments.LINK_MODE_LINKED_URL);
|
|
|
|
document.getElementById('scholar-attachment-links').item = item.ref;
|
2006-07-27 18:08:09 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 3;
|
2006-06-27 20:37:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-26 17:51:18 +00:00
|
|
|
ScholarItemPane.viewItem(item.ref);
|
2006-06-27 20:37:02 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 1;
|
|
|
|
}
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-27 20:37:02 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 0;
|
2006-06-20 13:59:59 +00:00
|
|
|
|
2006-06-27 20:37:02 +00:00
|
|
|
var label = document.getElementById('scholar-view-selected-label');
|
|
|
|
|
2006-06-20 13:59:59 +00:00
|
|
|
if(itemsView && itemsView.selection.count)
|
2006-06-21 23:22:37 +00:00
|
|
|
label.value = Scholar.getString('pane.item.selected.multiple').replace('%1', itemsView.selection.count);
|
2006-06-20 13:59:59 +00:00
|
|
|
else
|
2006-06-21 23:22:37 +00:00
|
|
|
label.value = Scholar.getString('pane.item.selected.zero');
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-06-19 15:00:13 +00:00
|
|
|
function deleteSelectedItem()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-07-31 19:14:06 +00:00
|
|
|
if(itemsView && itemsView.selection.count > 0)
|
|
|
|
{
|
2006-08-04 14:36:04 +00:00
|
|
|
var eraseChildren = {value: true};
|
2006-07-31 19:14:06 +00:00
|
|
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPromptService);
|
2006-08-04 14:36:04 +00:00
|
|
|
var hasChildren;
|
|
|
|
|
2006-08-07 15:25:29 +00:00
|
|
|
if(!getSelectedCollection())
|
2006-08-04 14:36:04 +00:00
|
|
|
{
|
2006-08-07 15:25:29 +00:00
|
|
|
var start = new Object();
|
|
|
|
var end = new Object();
|
|
|
|
for (var i=0, len=itemsView.selection.getRangeCount(); i<len && !hasChildren; i++)
|
|
|
|
{
|
|
|
|
itemsView.selection.getRangeAt(i,start,end);
|
|
|
|
for (var j=start.value; j<=end.value && !hasChildren; j++)
|
2006-08-25 08:37:16 +00:00
|
|
|
if(itemsView._getItemAtRow(j).numChildren())
|
2006-08-07 15:25:29 +00:00
|
|
|
hasChildren = true;
|
|
|
|
}
|
2006-08-04 14:36:04 +00:00
|
|
|
}
|
2006-07-31 19:14:06 +00:00
|
|
|
|
2006-08-04 14:36:04 +00:00
|
|
|
if(promptService.confirmCheck(window, Scholar.getString('pane.items.delete.title'), Scholar.getString('pane.items.delete'), ( hasChildren ? Scholar.getString('pane.items.delete.attached') : ''), eraseChildren))
|
2006-07-31 19:14:06 +00:00
|
|
|
itemsView.deleteSelection(eraseChildren.value);
|
|
|
|
}
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 15:00:13 +00:00
|
|
|
function deleteSelectedCollection()
|
2006-06-02 14:11:23 +00:00
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
if(collectionsView.selection.count > 0 && confirm(Scholar.getString('pane.collections.delete')))
|
|
|
|
collectionsView.deleteSelection();
|
2006-06-02 14:11:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-30 04:09:34 +00:00
|
|
|
function editSelectedCollection()
|
2006-06-05 13:08:16 +00:00
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
if(collectionsView.selection.count > 0)
|
2006-06-05 13:08:16 +00:00
|
|
|
{
|
2006-07-24 22:12:25 +00:00
|
|
|
var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
2006-06-05 13:08:16 +00:00
|
|
|
|
2006-08-09 11:43:33 +00:00
|
|
|
if(collection.isCollection())
|
|
|
|
{
|
|
|
|
var newName = prompt(Scholar.getString('pane.collections.rename'),collection.getName());
|
|
|
|
if(newName)
|
|
|
|
collection.ref.rename(newName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var s = new Scholar.Search();
|
|
|
|
s.load(collection.ref['id']);
|
|
|
|
var io = {dataIn: {search: s, name: collection.getName()}, dataOut: null};
|
|
|
|
window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io);
|
|
|
|
if(io.dataOut)
|
2006-08-10 22:39:21 +00:00
|
|
|
onCollectionSelected(); //reload itemsView
|
2006-08-09 11:43:33 +00:00
|
|
|
}
|
2006-06-05 13:08:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-06 19:53:27 +00:00
|
|
|
|
2006-05-30 22:06:33 +00:00
|
|
|
function search()
|
|
|
|
{
|
2006-06-01 16:40:43 +00:00
|
|
|
if(itemsView)
|
2006-06-21 22:23:42 +00:00
|
|
|
{
|
2006-08-29 07:18:41 +00:00
|
|
|
var searchVal = document.getElementById('tb-search').value;
|
2006-06-21 22:23:42 +00:00
|
|
|
itemsView.searchText(searchVal);
|
|
|
|
|
2006-08-01 18:01:48 +00:00
|
|
|
document.getElementById('tb-search-cancel').hidden = searchVal == "";
|
2006-06-21 22:23:42 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 16:40:43 +00:00
|
|
|
}
|
2006-06-08 18:42:55 +00:00
|
|
|
|
|
|
|
function getCollectionsView()
|
|
|
|
{
|
|
|
|
return collectionsView;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getItemsView()
|
|
|
|
{
|
|
|
|
return itemsView;
|
2006-06-02 12:59:58 +00:00
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
|
2006-07-31 19:14:06 +00:00
|
|
|
function selectItem(id)
|
|
|
|
{
|
|
|
|
if(itemsView)
|
|
|
|
{
|
|
|
|
if(!itemsView._itemGroup.isLibrary())
|
|
|
|
{
|
|
|
|
//select the Library if the item is not in the current collection
|
|
|
|
|
|
|
|
var item = Scholar.Items.get(id);
|
|
|
|
var collectionID = itemsView._itemGroup.ref.getID();
|
|
|
|
if(!item.isRegularItem())
|
|
|
|
{
|
|
|
|
if(!Scholar.Items.get(item.getSource()).inCollection(collectionID))
|
|
|
|
collectionsView.selection.select(0);
|
|
|
|
}
|
|
|
|
else if(!item.inCollection(collectionID))
|
|
|
|
collectionsView.selection.select(0);
|
|
|
|
}
|
|
|
|
itemsView.selectItem(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-24 22:12:25 +00:00
|
|
|
function getSelectedCollection()
|
|
|
|
{
|
|
|
|
if(collectionsView.selection.count > 0 && collectionsView.selection.currentIndex != -1)
|
|
|
|
{
|
|
|
|
collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
|
|
|
if(collection && collection.isCollection())
|
|
|
|
return collection.ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 04:09:34 +00:00
|
|
|
function getSelectedSavedSearch()
|
|
|
|
{
|
|
|
|
if(collectionsView.selection.count > 0 && collectionsView.selection.currentIndex != -1)
|
|
|
|
{
|
|
|
|
collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
|
|
|
if(collection && collection.isSearch())
|
|
|
|
{
|
|
|
|
return collection.ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 15:09:06 +00:00
|
|
|
function getSelectedItems()
|
2006-07-24 22:12:25 +00:00
|
|
|
{
|
2006-07-26 15:09:06 +00:00
|
|
|
if(itemsView)
|
2006-07-24 22:12:25 +00:00
|
|
|
{
|
2006-07-26 15:09:06 +00:00
|
|
|
var items = new Array();
|
|
|
|
var start = new Object();
|
|
|
|
var end = new Object();
|
|
|
|
for (var i=0, len=itemsView.selection.getRangeCount(); i<len; i++)
|
|
|
|
{
|
|
|
|
itemsView.selection.getRangeAt(i,start,end);
|
|
|
|
for (var j=start.value; j<=end.value; j++)
|
|
|
|
items.push(itemsView._getItemAtRow(j).ref);
|
|
|
|
}
|
2006-07-24 22:12:25 +00:00
|
|
|
}
|
2006-07-26 15:09:06 +00:00
|
|
|
return items;
|
2006-07-24 22:12:25 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 15:00:13 +00:00
|
|
|
function buildCollectionContextMenu()
|
|
|
|
{
|
|
|
|
var menu = document.getElementById('scholar-collectionmenu');
|
|
|
|
|
2006-08-30 04:09:34 +00:00
|
|
|
// Collection
|
|
|
|
if (collectionsView.selection.count == 1 &&
|
|
|
|
collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isCollection())
|
|
|
|
{
|
|
|
|
var hide = [4,6,9,11,12];
|
|
|
|
var show = [3,5,7,8,10];
|
2006-08-30 17:16:33 +00:00
|
|
|
if (itemsView.rowCount>0)
|
|
|
|
{
|
|
|
|
var enable = [8,10];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var disable = [8,10];
|
|
|
|
}
|
|
|
|
|
2006-08-30 04:09:34 +00:00
|
|
|
}
|
|
|
|
// Saved Search
|
|
|
|
else if (collectionsView.selection.count == 1 &&
|
|
|
|
collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isSearch())
|
2006-06-19 15:00:13 +00:00
|
|
|
{
|
2006-08-30 04:09:34 +00:00
|
|
|
var hide = [3,5,8,10,12];
|
|
|
|
var show = [4,6,7,9,11];
|
2006-08-30 17:16:33 +00:00
|
|
|
if (itemsView.rowCount>0)
|
|
|
|
{
|
|
|
|
var enable = [9,11];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var disable = [9,11];
|
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
}
|
2006-08-30 04:09:34 +00:00
|
|
|
// Library
|
2006-06-19 15:00:13 +00:00
|
|
|
else
|
|
|
|
{
|
2006-08-30 04:09:34 +00:00
|
|
|
var hide = [3,4,5,6,7,8,9,10,11];
|
|
|
|
var show = [12];
|
|
|
|
}
|
|
|
|
|
2006-08-30 17:16:33 +00:00
|
|
|
for (var i in disable)
|
|
|
|
{
|
|
|
|
menu.childNodes[disable[i]].setAttribute('disabled', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i in enable)
|
|
|
|
{
|
|
|
|
menu.childNodes[enable[i]].setAttribute('disabled', false);
|
|
|
|
}
|
|
|
|
|
2006-08-30 04:09:34 +00:00
|
|
|
for (var i in hide)
|
|
|
|
{
|
|
|
|
menu.childNodes[hide[i]].setAttribute('hidden', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i in show)
|
|
|
|
{
|
|
|
|
menu.childNodes[show[i]].setAttribute('hidden', false);
|
2006-06-19 15:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildItemContextMenu()
|
|
|
|
{
|
|
|
|
var menu = document.getElementById('scholar-itemmenu');
|
|
|
|
|
|
|
|
if(itemsView && itemsView.selection.count > 0)
|
2006-07-26 15:28:31 +00:00
|
|
|
{
|
2006-06-19 15:00:13 +00:00
|
|
|
menu.childNodes[2].removeAttribute('disabled');
|
2006-07-26 15:28:31 +00:00
|
|
|
menu.childNodes[4].removeAttribute('disabled');
|
|
|
|
menu.childNodes[5].removeAttribute('disabled');
|
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
else
|
2006-07-26 15:28:31 +00:00
|
|
|
{
|
2006-06-19 15:00:13 +00:00
|
|
|
menu.childNodes[2].setAttribute('disabled', true);
|
2006-07-26 15:28:31 +00:00
|
|
|
menu.childNodes[4].setAttribute('disabled', true);
|
|
|
|
menu.childNodes[5].setAttribute('disabled', true);
|
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
|
|
|
|
if(itemsView && itemsView.selection.count > 1)
|
2006-07-26 15:28:31 +00:00
|
|
|
{
|
2006-06-21 23:22:37 +00:00
|
|
|
menu.childNodes[2].setAttribute('label', Scholar.getString('pane.items.menu.remove.multiple'));
|
2006-07-26 15:28:31 +00:00
|
|
|
menu.childNodes[4].setAttribute('label', Scholar.getString('pane.items.menu.export.multiple'));
|
|
|
|
menu.childNodes[5].setAttribute('label', Scholar.getString('pane.items.menu.createBib.multiple'));
|
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
else
|
2006-07-26 15:28:31 +00:00
|
|
|
{
|
|
|
|
menu.childNodes[2].setAttribute('label', Scholar.getString('pane.items.menu.remove'));
|
|
|
|
menu.childNodes[4].setAttribute('label', Scholar.getString('pane.items.menu.export'));
|
|
|
|
menu.childNodes[5].setAttribute('label', Scholar.getString('pane.items.menu.createBib'));
|
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
}
|
2006-06-27 22:47:17 +00:00
|
|
|
|
2006-08-02 16:08:19 +00:00
|
|
|
// Adapted from: http://www.xulplanet.com/references/elemref/ref_tree.html#cmnote-9
|
|
|
|
function onDoubleClick(event, tree)
|
|
|
|
{
|
|
|
|
if (event && tree && (event.type == "click" || event.type == "dblclick"))
|
|
|
|
{
|
|
|
|
var row = {}, col = {}, obj = {};
|
|
|
|
tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj);
|
2006-08-25 08:37:16 +00:00
|
|
|
// obj.value == cell/text/image
|
|
|
|
// TODO: handle collection double-click
|
2006-08-02 16:08:19 +00:00
|
|
|
if (obj.value && itemsView && itemsView.selection.currentIndex > -1)
|
|
|
|
{
|
|
|
|
var item = getSelectedItems()[0];
|
|
|
|
if(item && item.isNote())
|
|
|
|
{
|
|
|
|
document.getElementById('scholar-view-note-button').doCommand();
|
|
|
|
}
|
2006-08-12 00:18:20 +00:00
|
|
|
else if(item && item.isAttachment())
|
2006-08-11 15:48:26 +00:00
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
viewSelectedAttachment();
|
2006-08-11 15:48:26 +00:00
|
|
|
}
|
2006-08-02 16:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 14:30:38 +00:00
|
|
|
function newNote()
|
2006-06-27 22:47:17 +00:00
|
|
|
{
|
2006-07-26 14:30:38 +00:00
|
|
|
var c = getSelectedCollection();
|
|
|
|
if(c)
|
|
|
|
openNoteWindow(null, c.getID());
|
|
|
|
else
|
|
|
|
openNoteWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
function openNoteWindow(id, parent)
|
|
|
|
{
|
|
|
|
window.open('chrome://scholar/content/note.xul?v=1'+(id ? '&id='+id : '')+(parent ? '&coll='+parent : ''),'','chrome,resizable,centerscreen');
|
2006-06-27 22:47:17 +00:00
|
|
|
}
|
2006-07-31 16:58:14 +00:00
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
function addAttachmentFromDialog(link, id)
|
2006-07-31 16:58:14 +00:00
|
|
|
{
|
|
|
|
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
|
|
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
|
|
.createInstance(nsIFilePicker);
|
2006-08-12 00:18:20 +00:00
|
|
|
fp.init(window, Scholar.getString('pane.item.attachments.select'), nsIFilePicker.modeOpen);
|
2006-07-31 16:58:14 +00:00
|
|
|
|
|
|
|
if(fp.show() == nsIFilePicker.returnOK)
|
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
var attachmentID;
|
2006-07-31 16:58:14 +00:00
|
|
|
if(link)
|
2006-08-12 00:18:20 +00:00
|
|
|
attachmentID = Scholar.Attachments.linkFromFile(fp.file, id);
|
2006-07-31 16:58:14 +00:00
|
|
|
else
|
2006-08-12 00:18:20 +00:00
|
|
|
attachmentID = Scholar.Attachments.importFromFile(fp.file, id);
|
2006-07-31 19:14:06 +00:00
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
if(attachmentID && !id)
|
2006-07-31 19:14:06 +00:00
|
|
|
{
|
|
|
|
var c = getSelectedCollection();
|
|
|
|
if(c)
|
2006-08-12 00:18:20 +00:00
|
|
|
c.addItem(attachmentID);
|
2006-07-31 19:14:06 +00:00
|
|
|
}
|
2006-07-31 16:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
function addAttachmentFromPage(link, id)
|
2006-07-31 16:58:14 +00:00
|
|
|
{
|
2006-08-04 14:23:44 +00:00
|
|
|
var item;
|
|
|
|
if(id == null)
|
|
|
|
{
|
|
|
|
item = newItem(Scholar.ItemTypes.getID('website'));
|
|
|
|
if(item)
|
2006-08-11 15:48:26 +00:00
|
|
|
{
|
2006-08-04 14:23:44 +00:00
|
|
|
id = item.getID();
|
2006-08-11 15:48:26 +00:00
|
|
|
var c = getSelectedCollection();
|
|
|
|
if(c)
|
|
|
|
c.addItem(id);
|
|
|
|
}
|
2006-08-04 14:23:44 +00:00
|
|
|
}
|
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
var attachmentID;
|
2006-07-31 16:58:14 +00:00
|
|
|
if(link)
|
2006-08-12 00:18:20 +00:00
|
|
|
attachmentID = Scholar.Attachments.linkFromDocument(window.content.document, id);
|
2006-07-31 16:58:14 +00:00
|
|
|
else
|
2006-08-12 00:18:20 +00:00
|
|
|
attachmentID = Scholar.Attachments.importFromDocument(window.content.document, id);
|
2006-07-31 19:14:06 +00:00
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
if(attachmentID && item)
|
2006-08-11 15:48:26 +00:00
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
var attachment = Scholar.Items.get(attachmentID);
|
|
|
|
if(attachment)
|
2006-08-04 14:23:44 +00:00
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
item.setField('title',attachment.getField('title'));
|
2006-08-04 14:23:44 +00:00
|
|
|
item.save();
|
|
|
|
}
|
2006-07-31 19:14:06 +00:00
|
|
|
}
|
2006-07-31 16:58:14 +00:00
|
|
|
}
|
2006-08-11 15:48:26 +00:00
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
function viewSelectedAttachment()
|
2006-08-11 15:48:26 +00:00
|
|
|
{
|
|
|
|
if(itemsView && itemsView.selection.count == 1)
|
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
var attachment = getSelectedItems()[0];
|
2006-08-11 15:48:26 +00:00
|
|
|
|
2006-08-12 00:18:20 +00:00
|
|
|
if(attachment.getAttachmentLinkMode() != Scholar.Attachments.LINK_MODE_LINKED_URL)
|
2006-08-11 15:48:26 +00:00
|
|
|
{
|
- Added file.js to chnmIScholarService.js
- Fixed bug in File.hasInternalHandler() (no access to navigator from XPCOM)
- Changed "View Attachment" action to check File.hasInternalHandler() and use window.loadURI() for internally handled files and nsIFile.launch() for external -- this prevents the user from getting a helper app dialog when they try to view external files. I basically had to duplicate most of Mozilla's content detection logic and "guess" whether or not it will be able to handle the file internally, which seems a little silly, but, while I feel there are probably better ways to do various parts of this, what's here seems to do the trick. Let me know if you notice it guessing incorrectly (i.e. you get a helper app dialog rather than having a file just open or it launches a file that should've just been loaded into the window). Also look for text files that should be launched rather than opened, especially XML-based data files, as this is a chance for Scholar to be smarter than Firefox itself--for example, OmniGraffle files, which are actually just XML files, normally open up in Firefox as an XML tree, but Scholar will launch them instead. (I imagine the same will need to be done for OmniOutliner, among other things...)
2006-08-12 03:45:57 +00:00
|
|
|
var file = attachment.getFile();
|
2006-08-19 20:51:01 +00:00
|
|
|
if (Scholar.MIME.fileHasInternalHandler(file))
|
- Added file.js to chnmIScholarService.js
- Fixed bug in File.hasInternalHandler() (no access to navigator from XPCOM)
- Changed "View Attachment" action to check File.hasInternalHandler() and use window.loadURI() for internally handled files and nsIFile.launch() for external -- this prevents the user from getting a helper app dialog when they try to view external files. I basically had to duplicate most of Mozilla's content detection logic and "guess" whether or not it will be able to handle the file internally, which seems a little silly, but, while I feel there are probably better ways to do various parts of this, what's here seems to do the trick. Let me know if you notice it guessing incorrectly (i.e. you get a helper app dialog rather than having a file just open or it launches a file that should've just been loaded into the window). Also look for text files that should be launched rather than opened, especially XML-based data files, as this is a chance for Scholar to be smarter than Firefox itself--for example, OmniGraffle files, which are actually just XML files, normally open up in Firefox as an XML tree, but Scholar will launch them instead. (I imagine the same will need to be done for OmniOutliner, among other things...)
2006-08-12 03:45:57 +00:00
|
|
|
{
|
|
|
|
window.loadURI(attachment.getLocalFileURL());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
file.launch();
|
|
|
|
}
|
2006-08-11 15:48:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-12 00:18:20 +00:00
|
|
|
window.loadURI(attachment.getURL());
|
2006-08-11 15:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-06-02 12:59:58 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
window.addEventListener("load", function(e) { ScholarPane.onLoad(e); }, false);
|
|
|
|
window.addEventListener("unload", function(e) { ScholarPane.onUnload(e); }, false);
|