Skip to content

Commit

Permalink
Improved annotation edition from table
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Dec 14, 2023
1 parent 05673e6 commit d695ff6
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 18 deletions.
54 changes: 45 additions & 9 deletions content/notes/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,37 @@ Menus = {

var items0 = {
"edit": {name: "Edit note", icon: "fa-pencil-alt"},
"editpdfnote": {name: "Edit annotation", icon: "fa-edit"},
"editannotation": {name: "Edit annotation", icon: "fa-edit"},
"showannotation": {name: "Show annotation", icon: "fa-edit"},
"sep": "---------",
}

var items_ai = {}

if(Zotero.ZeNotes.Prefs.getb("bard-api-key")!="google-translate-key")
var tlcode = Zotero.ZeNotes.Prefs.get("target-language");
var tl = "";
if(tlcode=="")
{
tl = "English";
}
else
{
var tlcode = Zotero.ZeNotes.Prefs.get("target-language");
var tl = "";
for(a of Languages.list())
{
if(tlcode.toUpperCase()==a.code.toUpperCase())
{
tl = a.name;
break;
}
}

items_ai["translate-google-en"] = {name: "Translate to "+tl+" (Google)", icon: "fa-language"};
items_ai["sep-ai-02"] = "---------";
}

items_ai["translate-google-en"] = {name: "Translate to "+tl+" (Google)", icon: "fa-google"};
items_ai["sep-ai-02"] = "---------";

if(Zotero.ZeNotes.Prefs.getb("bard-api-key")!="")
{
items_ai["paraphrase-bard"] = {name: "Paraphrase annotation (Bard)", icon: "fa-language"};
items_ai["paraphrase-bard"] = {name: "Paraphrase annotation (Bard)", icon: "fa-b"};
items_ai["sep-ai-01"] = "---------";
}

Expand Down Expand Up @@ -241,7 +247,37 @@ Menus = {
this.opennote(notekey);
}
}
else if(key=="editpdfnote")
else if(key=="editannotation")
{
if(!annotationkey)
{
alert("Annotation not found!");
return;
}

var annotation = Zotero.Items.get(annotationid);
var currentcomment = annotation.annotationComment;

var html = document.createElement("div");
html.style = "width:100%; padding: 0.5em;"
html.innerHTML = currentcomment.split("\n").join("<br/>");
html.contentEditable = true;
Dialog.open(html, function(){
var value = html.innerHTML.split("<br xmlns=\"http:https://www.w3.org/1999/xhtml\" />").join("\n");

value = value.split(" xmlns=\"http:https://www.w3.org/1999/xhtml\"").join("");
value = value.split("<div>").join("");
value = value.split("</div>").join("\n");
value = value.split("<br />").join("\n");
value = value.split("<br/>").join("\n");

annotation.annotationComment = value;
annotation.saveTx({skipSelect:true}).then(e=>{
Zotero.ZeNotes.Ui.reload();
});
}, "Edit annotation comment", "save");
}
else if(key=="showannotation")
{
var attachment = Zotero.Items.get(attachmentid);
if(!annotationkey)
Expand Down
6 changes: 6 additions & 0 deletions content/notes/notes.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ th {
text-transform: capitalize;
}


.notekey {
width: 100%;
padding: 0.1em;
Expand Down Expand Up @@ -128,6 +129,11 @@ body {
color: black;
}

.context-menu-separator
{
border: solid 1px #dfdfff!important;
}

.zn-menuitem:hover {
background-color: #d8e6f2;
border: solid 1px #c0dcf3;
Expand Down
18 changes: 17 additions & 1 deletion content/ui/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Dialog = {
document.body.appendChild(this.dialog);
this.dialog.appendChild(this.contents);
this.dialog.id = "main-dialog";
this.dialog.title = "Coding dialog";
this.dialog.title = "ZeNotes Dialog";
this.contents.style = "height: 100%; width: 100%;";
this.contents.innerHTML = ``;
},
Expand Down Expand Up @@ -83,6 +83,22 @@ Dialog = {
}
}
}
else if(buttons=="save")
{
buttons = {
Cancel: function()
{
$("#main-dialog").dialog( "close" );
},
Save: function(){
$("#main-dialog").dialog( "close" );
if(callback!=null)
{
callback();
}
}
}
}

$("#main-dialog").dialog({
height: "auto",
Expand Down
11 changes: 11 additions & 0 deletions core/ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ Ai={
return Promise.resolve(["Error: "+e]);
}
}
else if(mode=="bing")
{
try {
// Google translate without api key
return Promise.resolve(data.map(function(e){return e[0]}));
}
catch(e)
{
return Promise.resolve(["Error: "+e, JSON.stringify(data)]);
}
}

}).catch(e=>{
return Promise.reject(["Error: "+e]);
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.5.8</em:version>
<em:version>0.5.9</em:version>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:updateURL>https://raw.githubusercontent.com/frianasoa/zenotes/main/zenote-update.json</em:updateURL>
<em:homepageURL>https://github.com/frianasoa/zenotes</em:homepageURL>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ze Notes",
"version": "0.5.8",
"version": "0.5.9",
"description": "Advanced notes manager",
"homepage_url": "https://github.com/frianasoa/zenotes",
"author": "Fanantenana Rianasoa Andriariniaina",
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"[email protected]": {
"updates": [
{
"version": "0.5.8",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.5.8/zenotes-v0.5.8.xpi",
"update_hash": "sha256:0e3bb0d1b40a66a304969b96eac75ee2dd3985879912fe674bcff6854720da9a",
"version": "0.5.9",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.5.9/zenotes-v0.5.9.xpi",
"update_hash": "sha256:03f0e0fef1eda2a893fccb6a70fd55ab3f6565a8cb480f540fb257e3b11e9a65",
"applications": {
"gecko": {
"strict_min_version": "60.0"
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.5.8</ns1:version>
<ns1:version>0.5.9</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.5.8/zenotes-v0.5.8.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.5.9/zenotes-v0.5.9.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.5.8/zenotes-v0.5.8.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.5.9/zenotes-v0.5.9.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit d695ff6

Please sign in to comment.