Fixes #143, Scholar toolbar button to save current page as an independent file in the selected project.

This commit is contained in:
David Norton 2006-07-31 16:58:14 +00:00
parent 40ef9f669d
commit 4757d21b20
4 changed files with 43 additions and 16 deletions

View file

@ -138,6 +138,7 @@ ScholarItemPane = new function()
var label = document.createElement('label');
label.setAttribute('value',_noteToTitle(notes[i].getNote()));
label.setAttribute('flex','1'); //so that the long names will flex smaller
label.setAttribute('crop','end');
var box = document.createElement('box');
@ -177,6 +178,7 @@ ScholarItemPane = new function()
var label = document.createElement('label');
label.setAttribute('value',files[i].getField('title'));
label.setAttribute('flex','1'); //so that the long names will flex smaller
label.setAttribute('crop','end');
var box = document.createElement('box');
@ -442,26 +444,12 @@ ScholarItemPane = new function()
function addFileFromDialog(link)
{
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, "Select a File", nsIFilePicker.modeOpen);
if(fp.show() == nsIFilePicker.returnOK)
{
if(link)
Scholar.Files.linkFromFile(fp.file, _itemBeingEdited.getID());
else
Scholar.Files.importFromFile(fp.file, _itemBeingEdited.getID());
}
ScholarPane.addFileFromDialog(link, _itemBeingEdited.getID());
}
function addFileFromPage(link)
{
if(link)
Scholar.Files.linkFromDocument(window.content.document, _itemBeingEdited.getID());
else
Scholar.Files.importFromDocument(window.content.document, _itemBeingEdited.getID());
ScholarPane.addFileFromPage(link, _itemBeingEdited.getID());
}
}

View file

@ -27,6 +27,8 @@ var ScholarPane = new function()
this.buildItemContextMenu = buildItemContextMenu;
this.openNoteWindow = openNoteWindow;
this.newNote = newNote;
this.addFileFromDialog = addFileFromDialog;
this.addFileFromPage = addFileFromPage;
/*
* Called when the window is open
@ -346,6 +348,30 @@ var ScholarPane = new function()
{
window.open('chrome://scholar/content/note.xul?v=1'+(id ? '&id='+id : '')+(parent ? '&coll='+parent : ''),'','chrome,resizable,centerscreen');
}
function addFileFromDialog(link, id)
{
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, "Select a File", nsIFilePicker.modeOpen);
if(fp.show() == nsIFilePicker.returnOK)
{
if(link)
Scholar.Files.linkFromFile(fp.file, id);
else
Scholar.Files.importFromFile(fp.file, id);
}
}
function addFileFromPage(link, id)
{
if(link)
Scholar.Files.linkFromDocument(window.content.document, id);
else
Scholar.Files.importFromDocument(window.content.document, id);
}
}
window.addEventListener("load", function(e) { ScholarPane.onLoad(e); }, false);

View file

@ -81,6 +81,14 @@
<toolbarbutton id="tb-add" tooltiptext="&toolbar.newItem.label;" type="menu">
<menupopup/>
</toolbarbutton>
<toolbarbutton id="tb-file-add" type="menu" tooltiptext="New Standalone File">
<menupopup>
<menuitem label="Add File..." oncommand="ScholarPane.addFileFromDialog();"/>
<menuitem label="Add Linked File..." oncommand="ScholarPane.addFileFromDialog(true);"/>
<menuitem label="Snapshot Current Page" oncommand="ScholarPane.addFileFromPage();"/>
<menuitem label="Link to Current Page" oncommand="ScholarPane.addFileFromPage(true);"/>
</menupopup>
</toolbarbutton>
<toolbarbutton id="tb-note-add" tooltiptext="New Standalone Note" oncommand="ScholarPane.newNote();"/>
<spacer flex="1"/>
<label value="&toolbar.search.label;" control="tb-search"/>

View file

@ -89,6 +89,11 @@
list-style-image: url('chrome://scholar/skin/toolbar-note-add.png');
}
#tb-file-add
{
list-style-image: url('chrome://scholar/skin/item-files-add.png');
}
#tb-item-files-add
{
list-style-image: url('chrome://scholar/skin/item-files-add.png');