Skip to content

Commit

Permalink
更新为0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
redleafnew committed May 4, 2021
1 parent ccf9781 commit f6cf24a
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 12 deletions.
14 changes: 14 additions & 0 deletions chrome/content/overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<menupopup id="zotero-itemmenu">
<menuseparator id="id-delitem-separator"/>
<!-- 删除条目和附件 -->
<menu id="zotero-itemmenu-delitem-namehandler"
label="&zotero.delitem.namehandler.label;">
<menupopup id="delitem">
Expand All @@ -29,5 +30,18 @@
<menuitem id="zotero-itemmenu-delsnap" label="&zotero.delitem.delsnap.label;" oncommand="Zotero.DelItem.DelSnap()"/> <!-- 仅删除快照 -->
</menupopup>
</menu>
<!-- 设置语言 -->
<!-- <menu id="zotero-itemmenu-chanlan-namehandler" -->
<!-- label="&zotero.chanlan.namehandler.label;" -->
<!-- oncommand="Zotero.DelItem.chanLanForSel()" -->
<!-- toolkeytip="Set the language field of the selcted item(s) to en">-->
<!-- <menupopup id="chanlan">-->
<menuitem id="zotero-chanlan-forsel" label="&zotero.chanlan-forsel.label;"
tooltiptext="&zotero.chanlan.Set.lan.to.en;"
oncommand="Zotero.DelItem.chanLanForSel()"/> <!-- 所选条目设为en -->
<!-- <menuitem id="zotero-chanlan-forempty" label="&zotero.chanlan-forempty.label;" oncommand="Zotero.DelItem.chanLanForEmpty()"/> 语言字段为空时设置 -->
<!-- </menupopup> -->
<!-- </menu>-->

</menupopup>
</overlay>
68 changes: 60 additions & 8 deletions chrome/content/scripts/delitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 linked attachment(s) could not be restored.")
var truthBeTold = window.confirm(Zotero.DelItem.diwaGetString("delete.item.and.attachment"))
if (truthBeTold) {
Zotero.DelItem.DelItems(items);

Expand All @@ -15,7 +15,7 @@ Zotero.DelItem = {

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? The linked attachment(s) could not be restored.")
var truthBeTold = window.confirm(Zotero.DelItem.diwaGetString("delete.collection.and.attachment"))
if (truthBeTold) {
Zotero.DelItem.DelItems(items);
collection.deleted = true; //删除条目
Expand All @@ -27,7 +27,7 @@ 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)? The linked attachment(s) could not be restored.")
var truthBeTold = window.confirm(Zotero.DelItem.diwaGetString("delete.attachment.only"))
if (truthBeTold) {
for (let item of items) {
if (item && !item.isNote()) { //2 if
Expand All @@ -40,7 +40,7 @@ Zotero.DelItem = {
if (file && ifLinks) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
try { await OS.File.remove (file); // 尝试删除文件
} catch (error) { // 弹出错误
alert ("The file can not be deleted. Please close the file if you have opened it and try again.");
alert (Zotero.DelItem.diwaGetString("file.is.open"));
return; // 弹出错误后终止执行
}
}
Expand All @@ -57,7 +57,7 @@ Zotero.DelItem = {
if (file && ifLinksAtt) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
try { await OS.File.remove (file); // 尝试删除文件
} catch (error) { // 弹出错误
alert ("The file can not be deleted. Please close the file if you have opened it and try again.");
alert (Zotero.DelItem.diwaGetString("file.is.open"));
return; // 弹出错误后终止执行
}
}
Expand All @@ -74,7 +74,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)?")
var truthBeTold = window.confirm(Zotero.DelItem.diwaGetString("delete.snapshot"))
if (truthBeTold) {
for (let item of items) {
if (item && !item.isNote()) { //2 if
Expand Down Expand Up @@ -125,7 +125,7 @@ Zotero.DelItem = {
if (file && ifLinks) { //如果文件存在(文件可能已经被删除)且为链接模式删除文件
try { await OS.File.remove (file); // 尝试删除文件
} catch (error) { // 弹出错误
alert ("The file can not be deleted. Please close the file if you have opened it and try again.");
alert (Zotero.DelItem.diwaGetString("file.is.open"));
return; // 弹出错误后终止执行
}
}
Expand All @@ -143,7 +143,7 @@ Zotero.DelItem = {
if (file && ifLinksAtt) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
try { await OS.File.remove (file); // 尝试删除文件
} catch (error) { // 弹出错误
alert ("The file can not be deleted. Please close the file if you have opened it and try again.");
alert (Zotero.DelItem.diwaGetString("file.is.open"));
return; // 弹出错误后终止执行
}
}
Expand All @@ -156,7 +156,59 @@ Zotero.DelItem = {

},

// 将所有所选条目语言字段设为en
chanLanForSel: async function () {
var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();

for (item of items) {
var la = item.getField("language");
//if (la=="") { //如果为空则替换
item.setField("language", "en");
await item.saveTx();
//}
}
},

// 将所选条目语言字段为空时设为en
chanLanForEmpty: async function () {
var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();

for (item of items) {
var la = item.getField("language");
if (la=="") { //如果为空则替换
item.setField("language", "en");
await item.saveTx();
}
}
},

// Localization (borrowed from ZotFile sourcecode)
// 提示语言本地化函数
diwaGetString: function (name, params){
var l10n = '';
stringsBundle = Components.classes['@mozilla.org/intl/stringbundle;1']
.getService(Components.interfaces.nsIStringBundleService)
.createBundle('chrome://delitem/locale/diwa.properties');
try {
if (params !== undefined){
if (typeof params != 'object'){
params = [params];
}
l10n = tringsBundle.formatStringFromName(name, params, params.length);
}
else {
l10n = stringsBundle.GetStringFromName(name);
}
}
catch (e){
throw ('Localized string not available for ' + name);
}
return l10n;
},


// 检查附件是否存在函数
checkItemAtt: function (item) {
if (item && !item.isNote()) {
Expand Down
7 changes: 7 additions & 0 deletions chrome/locale/en-US/diwa.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#delitem.js

delete.item.and.attachment = 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.
delete.collection.and.attachment = Are you sure you want to delete the selected collection including the attachments? The linked attachment(s) could not be restored.
delete.attachment.only = Are you sure you want to delete the attachment(s) of the item(s)? The linked attachment(s) could not be restored.
delete.snapshot = Are you sure you want to delete the snapshot(s) of the item(s)?
file.is.open = The file can not be deleted. Please close the file if you have opened it and try again.
6 changes: 6 additions & 0 deletions chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!-- 删除条目和附件 -->
<!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)">
<!-- 设置语言 -->
<!ENTITY zotero.chanlan-forempty.label "If the Language of Selected Item(s) Is Empty">
<!ENTITY zotero.chanlan-forsel.label "Set Language Field as en">
<!ENTITY zotero.chanlan.namehandler.label "Set Language as en">
<!ENTITY zotero.chanlan.Set.lan.to.en "Set Language Field of Selected Item(s) as en">
7 changes: 7 additions & 0 deletions chrome/locale/zh-CN/diwa.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#delitem.js

delete.item.and.attachment = 您确定将所选条目包括附件移动到回收站? 链接的附件不可恢复。
delete.collection.and.attachment = 您确定将所选分类包括附件移动到回收站? 链接的附件不可恢复。
delete.attachment.only = 您确定将所选条目的附件移动到回收站? 链接的附件不可恢复。
delete.snapshot = 您确定将所选条目的快照移动到回收站?
file.is.open = 无法删除文件。如果文件已经打开,请关闭后重试。
5 changes: 5 additions & 0 deletions chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
<!ENTITY zotero.delitem.delitems.label "删除分类条目包括附件">
<!ENTITY zotero.delitem.delsnap.label "仅删除快照">
<!ENTITY zotero.delitem.namehandler.label "删除附件">
<!-- 设置语言 -->
<!ENTITY zotero.chanlan-forempty.label "所选条目语言为空时设为en">
<!ENTITY zotero.chanlan-forsel.label "将语言字段设为en">
<!ENTITY zotero.chanlan.namehandler.label "将语言设为en">
<!ENTITY zotero.chanlan.Set.lan.to.en "将所选条目语言字段设为en">
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.8"
em:version="0.0.9"
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.8</em:version>
<em:version>0.0.9</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.8/delitemwithatt.xpi</em:updateLink>
<em:updateLink>https://github.com/redleafnew/delitemwithatt/releases/download/0.0.9/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.8/delitemwithatt.xpi</em:updateLink>
<em:updateLink>https://github.com/redleafnew/delitemwithatt/releases/download/0.0.9/delitemwithatt.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>

Expand Down

0 comments on commit f6cf24a

Please sign in to comment.