Skip to content

Commit

Permalink
添加删除条目时如果文件在storage目录,同时删除目录
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed Mar 20, 2021
1 parent 6218ca8 commit 432517a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions chrome/content/scripts/delitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Zotero.DelItem = {
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.")
if (truthBeTold) {
Zotero.DelItem.DelItems(items)
Zotero.DelItem.DelItems(items);
}
},

Expand All @@ -16,22 +16,27 @@ Zotero.DelItem = {
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.")
if (truthBeTold) {
Zotero.DelItem.DelItems(items)
Zotero.DelItem.DelItems(items);
collection.deleted = true; //删除条目
await collection.saveTx();
}
},

DelItems: async function (items) { //删除条目被调用的执行具体删除任务的函数
Components.utils.import("resource://gre/modules/osfile.jsm");
var DelItems = ""; //删除的条目,主要用于换行
var num = 0;//计数
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';
// 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) //删除文件夹
}
await OS.File.remove(file); //删除文件
}
item.deleted = true; //删除条目
Expand Down
2 changes: 1 addition & 1 deletion chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!ENTITY zotero.delitem.delitem.label "Delete Item(s) with Attachment(s)">
<!ENTITY zotero.delitem.delitems.label "Delete Collections with Attachments">
<!ENTITY zotero.delitem.delitems.label "Delete Collection with Attachments">
4 changes: 2 additions & 2 deletions 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.1"
em:version="0.0.2"
em:type="2"
em:creator="Minyi Han"
em:description="Delete Item(s) With Attachment(s)"
Expand Down Expand Up @@ -40,7 +40,7 @@
<Description>
<em:locale>en-US</em:locale>
<em:name> delitem</em:name>
<em:description>Delete Item With Attachment.</em:description>
<em:description>Delete Item(s) With Attachment(s).</em:description>
</Description>
</em:localized>
<em:localized>
Expand Down

0 comments on commit 432517a

Please sign in to comment.