Skip to content

Commit

Permalink
Can open pdf files with zotero or external reader now.
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Dec 13, 2022
1 parent 709884a commit 532e9f1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 20 deletions.
30 changes: 27 additions & 3 deletions chrome/content/zenotes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ var Zotero = Components.classes["@zotero.org/Zotero;1"]
var zp = Zotero.getActiveZoteroPane();
var document = zp.document;
var window = document.defaultView;
var alert = window.alert;

var znstr = function(name, params)
{
return Zotero.ZeNotes.ZNStr(name, params);
}

Zotero.ZeNotes.data = new function()
{
Expand Down Expand Up @@ -122,7 +126,19 @@ Zotero.ZeNotes.data = new function()
var path = attachment.attachmentPath;
filename = Zotero.Attachments.resolveRelativePath(path);
}
return filename
return filename;
}

this.filekey = function(item)
{
var attachmentIDs = item.getAttachments();
var key = "";
if(attachmentIDs.length>0)
{
var attachment = Zotero.Items.get(attachmentIDs[0]);
key = attachment.key;
}
return key;
}

this.pdfnotes = function(item)
Expand Down Expand Up @@ -178,7 +194,14 @@ Zotero.ZeNotes.data = new function()
var n = pdfnotes[j];
var authors = Zotero.ZeNotes.data.creatorshort(item);
var year = Zotero.ZeNotes.data.year(item);
var note = n["annotationComment"]+"<h1>Direct quote</h1><div style='background-color:"+n["annotationColor"]+";'>“"+n["annotationText"]+"”</div>("+authors+" "+year+", p. "+n["annotationPageLabel"]+")";
var contents = "“"+n["annotationText"]+"” ("+authors+" "+year+", p. "+n["annotationPageLabel"]+")";

if(n["annotationText"]==null)
{
contents = "(p. "+n["annotationPageLabel"]+")"
}

var note = n["annotationComment"]+"<div id='annotation-"+n["parentItem"].key+"-"+n["key"]+"' class='annotation' data-attachmentkey='"+n["parentItem"].key+"' data-page='"+n["annotationPageLabel"]+"' data-key='"+n["key"]+"' style='background-color:"+n["annotationColor"]+";'>"+contents+"</div>";

var tags = n.getTags();
for(let i in tags)
Expand Down Expand Up @@ -220,6 +243,7 @@ Zotero.ZeNotes.data = new function()
author: Zotero.ZeNotes.data.creatorshort(item)+" ("+Zotero.ZeNotes.data.year(item)+")",
creators: Zotero.ZeNotes.data.creators(item),
filename: Zotero.ZeNotes.data.filename(item),
filekey: Zotero.ZeNotes.data.filekey(item),
}
line = Object.assign({},line, tags);
if(Object.keys(tags).length>0)
Expand Down
62 changes: 52 additions & 10 deletions chrome/content/zenotes/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ var notes = new function()
vm.actions(key, options)
},
items: {
"edit": {name: "Edit", icon: "fa-edit"},
"showentry": {name: "Show entry", icon: "fa-file-lines"},
"showfile": {name: "Show attached file", icon: "fa-file-pdf"},
"edit": {name: "Edit note", icon: "fa-pencil-alt"},
"editpdfnote": {name: "Edit annotation", icon: "fa-edit"},
"sep0": "---------",
"showentry": {name: "Show entry", icon: "fa-file-lines"},
"showfile": {name: "Show attached file (External reader)", icon: "fa-file-pdf"},
"showfilezotero": {name: "Show attached file (Zotero reader)", icon: "fa-file-pdf"},
"sep2": "---------",
"hidecolumn": {name: "Hide column", icon: "fa-eye-slash"},
"deletenote": {name: "Delete note", icon: "fa-trash"},
"sep1": "---------",
"copycell": {name: "Copy cell", icon: "fa-eye-slash"},
"sep3": "---------",
"copycell": {name: "Copy entire cell", icon: "fa-clone"},
"copyquote": {name: "Copy direct quote", icon: "fa-copy"},
"copysel": {name: "Copy selection", icon: "fa-copy"},
// "quit": {name: "Exit", icon: "fa-xmark"},
}
});
Expand All @@ -65,7 +70,8 @@ var notes = new function()
"showfile": {name: "Show attached file", icon: "fa-file-pdf"},
"hidecolumn": {name: "Hide column", icon: "fa-eye-slash"},
"sep1": "---------",
"copycell": {name: "Copy cell", icon: "fa-eye-slash"},
"copycell": {name: "Copy entire cell", icon: "fa-clone"},
"copysel": {name: "Copy selection", icon: "fa-copy"},
// "quit": {name: "Exit", icon: "fa-xmark"},
}
});
Expand Down Expand Up @@ -161,6 +167,15 @@ var notes = new function()
td.dataset.itemid = v.itemid;
td.dataset.itemkey = v.key;
td.dataset.filename = v.filename;
td.dataset.filekey = v.filekey;
td.querySelectorAll(".annotation").forEach(a=>{
a.addEventListener("mouseover", function(e){
e.target.parentNode.dataset.attachmentkey = e.target.dataset.attachmentkey;
e.target.parentNode.dataset.attachmentpage = e.target.dataset.page;
e.target.parentNode.dataset.annotationkey = e.target.dataset.key;
e.target.parentNode.dataset.annotationdomid = e.target.id;
});
});
tr.appendChild(td);
});
});
Expand All @@ -173,10 +188,14 @@ var notes = new function()
var column = td.dataset.column;
var itemid = td.dataset.itemid;
var itemkey = td.dataset.itemkey;
var attachmentkey = td.dataset.attachmentkey
var annotationkey = td.dataset.annotationkey;
var annotationpage = td.dataset.annotationpage;
var annotationdomid = td.dataset.annotationdomid;
var filename = td.dataset.filename;
var filekey = td.dataset.filekey;
var notekey = td.dataset.notekey;


if(key=="showentry")
{
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
Expand All @@ -201,9 +220,15 @@ var notes = new function()
this.opennote(notekey);
}
}
else if(key=="editpdfnote")
{
var uri = "zotero://open-pdf/library/items/"+attachmentkey+"?page="+annotationpage+"&annotation="+annotationkey;
Zotero.launchURL(uri);
}
else if(key=="showfile")
{
filename = filename.replace("\\", "/");
filename = filename.replace("\\\\", "/");
if(filename=="false")
{
alert("File not found!");
Expand All @@ -212,7 +237,11 @@ var notes = new function()
{
window.openDialog("file:///"+filename);
}

}
else if(key=="showfilezotero")
{
var uri = "zotero://open-pdf/library/items/"+filekey;
Zotero.launchURL(uri);
}
else if(key=="hidecolumn")
{
Expand Down Expand Up @@ -257,7 +286,20 @@ var notes = new function()
{
this.copy(td);
}

else if(key=="copyquote")
{
var quote = document.getElementById(annotationdomid);
var range = document.createRange();
range.selectNode(quote);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
}
else if(key=="copysel")
{
document.execCommand('copy');
}
else if(key=="addrow")
{
this.addrow();
Expand Down Expand Up @@ -303,7 +345,7 @@ var notes = new function()

if(["note", "attachment"].includes(type))
{
alert("Cannot attach a not to '"+type+"'");
alert("Cannot attach a note to '"+type+"'");
return;
}
var show = Zotero.ZeNotes.settings.lists.show;
Expand Down
4 changes: 1 addition & 3 deletions chrome/content/zenotes/zenotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ Zotero.ZeNotes = new function()
var name = "zenotes-notes";
Zotero.ZeNotes.openwindow(url, name, io);
}




this.download = function(type)
{

Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>ZeNotes</em:name>
<em:version>0.2.4</em:version>
<em:version>0.2.5</em:version>
<em:type>2</em:type>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:creator>Fanantenana Rianasoa Andriariniaina</em:creator>
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<ns1:version>0.2.4</ns1:version>
<ns1:version>0.2.5</ns1:version>
<ns1:targetApplication>
<rdf:Description>
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>5.0.0</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.4/zenotes-v0.2.4.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.5/zenotes-v0.2.5.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand All @@ -20,7 +20,7 @@
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>4.999</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.4/zenotes-v0.2.4.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.2.5/zenotes-v0.2.5.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit 532e9f1

Please sign in to comment.