Skip to content

Commit

Permalink
升级为0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed Apr 27, 2021
1 parent 7b70dc5 commit 6d80829
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 32 deletions.
1 change: 1 addition & 0 deletions chrome/content/overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


<menupopup id="zotero-collectionmenu">
<menuseparator id="id-delcoll-separator"/>
<menuitem
id="zotero-collectionmenu-delitem"
label="&zotero.delitem.delitems.label;"
Expand Down
110 changes: 86 additions & 24 deletions chrome/content/scripts/delitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ Zotero.DelItem = {

var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();
var truthBeTold = window.confirm("Are you sure you want to move the selected item(s) including the attachment(s) to the Trash? The attachment(s) could not be restored.")
var truthBeTold = window.confirm("Are you sure you want to move the selected item(s) including the attachment(s) to the Trash? The linked attachment(s) could not be restored.")
if (truthBeTold) {
Zotero.DelItem.DelItems(items);

}
},

DelColl: async function () {//右击时删除分类调用的函数

var collection = ZoteroPane.getSelectedCollection();
var items = collection.getChildItems();
var truthBeTold = window.confirm("Are you sure you want to delete the selected collection including the attachments? This action cannot be undone.")
var truthBeTold = window.confirm("Are you sure you want to delete the selected collection including the attachments? The linked attachment(s) could not be restored.")
if (truthBeTold) {
Zotero.DelItem.DelItems(items);
collection.deleted = true; //删除条目
Zotero.DelItem.DelItems(items);
collection.deleted = true; //删除条目
await collection.saveTx();
}
},
Expand All @@ -26,27 +27,29 @@ Zotero.DelItem = {

var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();
var truthBeTold = window.confirm("Are you sure you want to delete the attachment(s) of the item(s)? This action cannot be undone.")
var truthBeTold = window.confirm("Are you sure you want to delete the attachment(s) of the item(s)? The linked attachment(s) could not be restored.")
if (truthBeTold) {
for (let item of items) {
if (item && !item.isNote()) { //2 if
if (item.isRegularItem()) { // Regular Item 一般条目//3 if
let attachmentIDs = item.getAttachments();
for (let id of attachmentIDs) { //4 for
let attachment = Zotero.Items.get(id);
let ifLinks = (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); // 检测是否为链接模式
// if (attachment.attachmentContentType == 'text/html' ) { //可以筛选删除的附件类型
attachment.deleted = true; //删除附件(快照)
await attachment.saveTx();
// }
var file = await attachment.getFilePathAsync();
if (file) { //如果文件存在文件可能已经被删除
if (file && ifLinks) { //如果文件存在(文件可能已经被删除)且为链接模式删除文件
await OS.File.remove(file); //删除文件
}
} //4 for
} // 3 if
if (item.isAttachment()) { //附件条目 5 if
var ifLinksAtt = (item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); //检测是否为链接模式
var file = await item.getFilePathAsync();
if (file) { //如果文件存在文件可能已经被删除
if (file && ifLinksAtt) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
await OS.File.remove(file); //删除文件
}
item.deleted = true;
Expand All @@ -61,7 +64,7 @@ Zotero.DelItem = {

var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();
var truthBeTold = window.confirm("Are you sure you want to delete the snapshot(s) of the item(s)? This action cannot be undone.")
var truthBeTold = window.confirm("Are you sure you want to delete the snapshot(s) of the item(s)?")
if (truthBeTold) {
for (let item of items) {
if (item && !item.isNote()) { //2 if
Expand All @@ -72,21 +75,22 @@ Zotero.DelItem = {
if (attachment.attachmentContentType == 'text/html' ) { //筛选删除的附件类型
attachment.deleted = true; //删除附件(快照)
await attachment.saveTx();
var file = await attachment.getFilePathAsync();
if (file) { //如果文件存在,文件可能已经被删除
// 快照不处理文件
/* var file = await attachment.getFilePathAsync();
if (file) { //如果文件存在,文件可能已经被删除
await OS.File.remove(file); //删除文件
}
} */
}

} //4 for
} // 3 if
if (item.isAttachment()) { //附件条目 5 if
if (item.attachmentContentType == 'text/html' ) { //筛选删除的附件类型
var file = await item.getFilePathAsync();
// 快照不处理文件
/*var file = await item.getFilePathAsync();
if (file) { //如果文件存在,文件可能已经被删除
await OS.File.remove(file); //删除文件
}
//await OS.File.remove(file); //删除文件
} */
item.deleted = true;
await item.saveTx();
}
Expand All @@ -96,17 +100,17 @@ Zotero.DelItem = {
}
},

DelItems: async function (items) { //删除条目被调用的执行具体删除任务的函数
/*
DelItems: async function (items) { //删除条目和附件时被调用的执行具体删除任务的函数
Components.utils.import("resource://gre/modules/osfile.jsm");
var zfPath = Zotero.ZotFile.getPref("dest_dir"); //得到zotfile路径
//var DelItems = ""; //删除的条目,主要用于换行,当前无用
var num = 0;//计数,当前无用
for (let item of items) { // 1 for
title = item.getField('title');
// num += 1; //,当前无用
// DelItems += num + ': '+ title + '\n';
file = await getFilePath(item); //调用函数
if (file){
var filePath = OS.Path.dirname(file); //得到文件存放的文件夹
if (filePath != zfPath){ //如果两个文件夹不一致,文件可能存在storage中
await OS.File.removeDir(filePath) //删除文件夹
Expand All @@ -118,7 +122,7 @@ Zotero.DelItem = {
}// 1 for
// alert(DelItems + "\n " + num + "个条目(包括附件)已经被删除。") // 当前无用
async function getFilePath(item) { //1 函数 得到文件路径
Expand All @@ -140,6 +144,44 @@ Zotero.DelItem = {
} ;
},
*/

DelItems: async function (items) { //删除条目和附件时被调用的执行具体删除任务的函数


for (let item of items) {
if (item && !item.isNote()) { //2 if
if (item.isRegularItem()) { // Regular Item 一般条目//3 if
let attachmentIDs = item.getAttachments();
for (let id of attachmentIDs) { //4 for
let attachment = Zotero.Items.get(id);
let ifLinks = (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); // 检测是否为链接模式
// if (attachment.attachmentContentType == 'text/html' ) { //可以筛选删除的附件类型
attachment.deleted = true; //删除附件(快照)
await attachment.saveTx();
// }
var file = await attachment.getFilePathAsync();
if (file && ifLinks) { //如果文件存在(文件可能已经被删除)且为链接模式删除文件
await OS.File.remove(file); //删除文件
}
} //4 for

} // 3 if
if (item.isAttachment()) { //附件条目 5 if
var ifLinksAtt = (item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); //检测是否为链接模式
var file = await item.getFilePathAsync();
if (file && ifLinksAtt) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
await OS.File.remove(file); //删除文件
}

}//5if
} //2 if
item.deleted = true;
await item.saveTx();
}

},


// 检查附件是否存在函数
checkItemAtt: function (item) {
Expand All @@ -149,6 +191,8 @@ Zotero.DelItem = {
for (let id of attachmentIDs) {
let attachment = Zotero.Items.get(id);
var attType = attachment.attachmentContentType;
if (attType != undefined ) { //不等于undefined为有附件
return true;}
}
}
if (item.isAttachment()) {
Expand All @@ -170,15 +214,18 @@ Zotero.DelItem = {
for (let id of attachmentIDs) {
let attachment = Zotero.Items.get(id);
var attType = attachment.attachmentContentType;
// 如果是text;/html则为快照
if (attType == 'text/html' ) {
return true;}
}
}
if (item.isAttachment()) {
var attType = item.attachmentContentType;
}
}


if (attType == 'text/html' ) {
// 如果是text;/html则为快照
if (attType == 'text/html' ) {
return true;} else {
return false;}
},
Expand All @@ -187,11 +234,12 @@ Zotero.DelItem = {
displayMenuitem: function () { // 如果无附件则不显示菜单
var pane = Services.wm.getMostRecentWindow("navigator:browser")
.ZoteroPane;
var collection = ZoteroPane.getSelectedCollection();
var items = pane.getSelectedItems();
//Zotero.debug("**Jasminum selected item length: " + items.length);
var showMenuAtt = items.some((item) => Zotero.DelItem.checkItemAtt(item)); // 检查附件
var showMenuSnap = items.some((item) => Zotero.DelItem.checkItemSnap(item)); // 检查快照

var showMenuColl = (collection == false); // 非正常文件夹,如我的出版物、重复条目、未分类条目、回收站,为false,此时返回值为true,隐藏菜单
//pane.document.getElementById("id-delitem-separator").hidden = !( // 分隔条是否出现
// showMenuAtt ||
// showMenuSnap);
Expand All @@ -206,9 +254,17 @@ Zotero.DelItem = {
).disabled = !( // 删除条目和附件是否可用
showMenuAtt ||
showMenuSnap);*/


pane.document.getElementById( // 删除分类/文件夹菜单是否可见
"zotero-collectionmenu-delitem"
).hidden = showMenuColl; // 仅删除附件菜单是否可用
pane.document.getElementById( // 删除分类/文件夹分隔条是否可见
"id-delcoll-separator"
).hidden = showMenuColl; // 仅删除附件菜单是否可用
pane.document.getElementById( // 仅删除附件菜单
"zotero-itemmenu-delatt"
).disabled = (!showMenuAtt || showMenuSnap) ; // 仅删除附件菜单是否可用
).disabled = !showMenuAtt; // 仅删除附件菜单是否可用

pane.document.getElementById( // 仅删除快照菜单
"zotero-itemmenu-delsnap"
Expand All @@ -228,6 +284,12 @@ window.addEventListener(
Zotero.DelItem.displayMenuitem,
false
);
// add event listener for menu collections
doc.getElementById("zotero-collectionmenu").addEventListener(
"popupshowing",
Zotero.DelItem.displayMenuitem,
false
);
}
},
false
Expand Down
4 changes: 2 additions & 2 deletions chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!ENTITY zotero.delitem.delatt.label "Delete Attachment(s) Only">
<!ENTITY zotero.delitem.delitem.label "Delete Attachment(s)/Snapshot(s) and Item(s)">
<!ENTITY zotero.delitem.delatt.label "Delete All Attachment(s) Only">
<!ENTITY zotero.delitem.delitem.label "Delete Attachment(s) and Item(s)">
<!ENTITY zotero.delitem.delitems.label "Delete Collection with Attachments">
<!ENTITY zotero.delitem.delsnap.label "Delete Snapshot(s) Only">
<!ENTITY zotero.delitem.namehandler.label "Delete Attachment(s)">
4 changes: 2 additions & 2 deletions chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!ENTITY zotero.delitem.delatt.label "仅删除附件">
<!ENTITY zotero.delitem.delitem.label "删除附件(快照)和条目">
<!ENTITY zotero.delitem.delatt.label "仅删除所有附件">
<!ENTITY zotero.delitem.delitem.label "删除附件和条目">
<!ENTITY zotero.delitem.delitems.label "删除分类条目包括附件">
<!ENTITY zotero.delitem.delsnap.label "仅删除快照">
<!ENTITY zotero.delitem.namehandler.label "删除附件">
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RDF:about="urn:mozilla:install-manifest"
em:id="[email protected]"
em:name="Del Item With Att"
em:version="0.0.6"
em:version="0.0.7"
em:type="2"
em:creator="Minyi Han"
em:description="Delete Item(s) With Attachment(s)"
Expand Down
6 changes: 3 additions & 3 deletions update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<em:version>0.0.6</em:version>
<em:version>0.0.7</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
<em:minVersion>5.0.0</em:minVersion>
<em:maxVersion>5.*</em:maxVersion>
<em:updateLink>https://github.com/redleafnew/delitemwithatt/releases/download/0.0.6/delitemwithatt.xpi</em:updateLink>
<em:updateLink>https://github.com/redleafnew/delitemwithatt/releases/download/0.0.7/delitemwithatt.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>

Expand All @@ -21,7 +21,7 @@
<em:id>[email protected]</em:id>
<em:minVersion>4.999</em:minVersion>
<em:maxVersion>5.*</em:maxVersion>
<em:updateLink>https://github.com/redleafnew/delitemwithatt/releases/download/0.0.6/delitemwithatt.xpi</em:updateLink>
<em:updateLink>https://github.com/redleafnew/delitemwithatt/releases/download/0.0.7/delitemwithatt.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>

Expand Down

0 comments on commit 6d80829

Please sign in to comment.