Skip to content

Commit

Permalink
add: shortcut feature
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Feb 20, 2021
1 parent 72f1f11 commit 74bbe83
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 60 deletions.
Binary file removed builds/zotero-tag-0.0.4.xpi
Binary file not shown.
Binary file added builds/zotero-tag-0.0.5.xpi
Binary file not shown.
115 changes: 64 additions & 51 deletions chrome/content/preferences.xul
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,70 @@
<preference id="pref-zoterotag-rules" name="extensions.zotero.zoterotag.rules" type="string"/>
</preferences>
<vbox flex="1">
<label value="&zotero.zoterotag.rules.title;" style="font-size: large"/>
<label value="&zotero.zoterotag.rules.info;"/>
<listbox id="zoterotag-rules-listbox" flex="1">
<listhead>
<listheader label="&zotero.zoterotag.rules.listheader.id;"/>
<listheader label="&zotero.zoterotag.rules.listheader.tags;"/>
<listheader label="&zotero.zoterotag.rules.listheader.group;"/>
<listheader label="&zotero.zoterotag.rules.listheader.autoadd;"/>
<listheader label="&zotero.zoterotag.rules.listheader.operation;"/>
<!-- <listheader label="&zotero.zoterotag.rules.listheader.delete;"/> -->
</listhead>
<listcols>
<listcol/>
<listcol width="250"/>
<listcol/>
<listcol/>
<listcol/>
<!-- <listcol width="80"/> -->
</listcols>
<!-- <listitem id="zoterotag-rules-#" allowevents="true">
<listcell>
<label id="zoterotag-rules-#-id" value="#"/>
</listcell>
<listcell>
<textbox id="zoterotag-rules-#-tags"/>
</listcell>
<listcell>
<menulist id="zoterotag-rules-#-group">
<menupopup>
<menuitem value="1" label="1(&zotero.zoterotag.rules.group.default;)"/>
<menuitem value="2" label="2"/>
<menuitem value="3" label="3"/>
<menuitem value="0" label="&zotero.zoterotag.rules.group.other;"/>
</menupopup>
</menulist>
</listcell>
<listcell>
<checkbox id="zoterotag-rules-#-autoadd"/>
</listcell>
<listcell>
<button label="&zotero.zoterotag.rules.add;" tooltiptext="&zotero.zoterotag.rules.addtext;" oncommand="addRule()"/>
</listcell>
<listcell>
<button label="&zotero.zoterotag.rules.remove;" tooltiptext="&zotero.zoterotag.rules.removetext;" oncommand="" disabled="true"/>
</listcell>
</listitem> -->
</listbox>
<hbox style="display: block">
<button label="&zotero.zoterotag.rules.reset;" tooltiptext="&zotero.zoterotag.rules.resettext;" oncommand="resetPreferences()"/>
<label value="&zotero.zoterotag.rules.warningtext;" style="color: red"/>
</hbox>
<groupbox>
<caption label="&zotero.zoterotag.rules.title;"/>
<label value="&zotero.zoterotag.rules.info.1;"/>
<label value="&zotero.zoterotag.rules.info.2;"/>
<label value="&zotero.zoterotag.rules.info.3;"/>
<label value="&zotero.zoterotag.rules.info.4;"/>
<listbox id="zoterotag-rules-listbox" flex="1">
<listhead>
<listheader label="&zotero.zoterotag.rules.listheader.id;"/>
<listheader label="&zotero.zoterotag.rules.listheader.tags;"/>
<listheader label="&zotero.zoterotag.rules.listheader.group;"/>
<listheader label="&zotero.zoterotag.rules.listheader.autoadd;"/>
<listheader label="&zotero.zoterotag.rules.listheader.operation;"/>
<!-- <listheader label="&zotero.zoterotag.rules.listheader.delete;"/> -->
</listhead>
<listcols>
<listcol/>
<listcol width="250"/>
<listcol/>
<listcol/>
<listcol/>
<!-- <listcol width="80"/> -->
</listcols>
<!-- <listitem id="zoterotag-rules-#" allowevents="true">
<listcell>
<label id="zoterotag-rules-#-id" value="#"/>
</listcell>
<listcell>
<textbox id="zoterotag-rules-#-tags"/>
</listcell>
<listcell>
<menulist id="zoterotag-rules-#-group">
<menupopup>
<menuitem value="1" label="1(&zotero.zoterotag.rules.group.default;)"/>
<menuitem value="2" label="2"/>
<menuitem value="3" label="3"/>
<menuitem value="0" label="&zotero.zoterotag.rules.group.other;"/>
</menupopup>
</menulist>
</listcell>
<listcell>
<checkbox id="zoterotag-rules-#-autoadd"/>
</listcell>
<listcell>
<button label="&zotero.zoterotag.rules.add;" tooltiptext="&zotero.zoterotag.rules.addtext;" oncommand="addRule()"/>
</listcell>
<listcell>
<button label="&zotero.zoterotag.rules.remove;" tooltiptext="&zotero.zoterotag.rules.removetext;" oncommand="" disabled="true"/>
</listcell>
</listitem> -->
</listbox>
<hbox style="display: block">
<button label="&zotero.zoterotag.rules.reset;" tooltiptext="&zotero.zoterotag.rules.resettext;" oncommand="resetPreferences()"/>
<label value="&zotero.zoterotag.rules.warningtext;" style="color: red"/>
</hbox>
</groupbox>
<groupbox>
<caption label="&zotero.zoterotag.help.title.label;"/>
<hbox style="display: block">
<label value="&zotero.zoterotag.help.shortcuts.add.label;"/>
<label value="&zotero.zoterotag.help.shortcuts.remove.label;"/>
<label value="&zotero.zoterotag.help.setcolor.label;" class="zotero-text-link" href="https://github.com/windingwind/zotero-tag/blob/master/docs/tag-color.md"/>
</hbox>
</groupbox>
</vbox>
</prefpane>
</prefwindow>
Expand Down
91 changes: 89 additions & 2 deletions chrome/content/scripts/zoterotag.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Zotero.ZoteroTag = {
window.addEventListener('unload', function(e) {
Zotero.Notifier.unregisterObserver(notifierID);
}, false);

Zotero.ZoteroTag.initKeys();
},
notifierCallback: {
// Adds pdfs when new item is added to zotero.
Expand Down Expand Up @@ -133,6 +135,91 @@ Zotero.ZoteroTag = {
// }
}
},
// keyset: {},

initKeys: function() {
let shortcuts = [
{
id: '1',
operation: 'add',
group: 1,
modifiers: 'control',
key: '1',
},
{
id: '2',
operation: 'add',
group: 2,
modifiers: 'control',
key: '2',
},
{
id: '3',
operation: 'add',
group: 3,
modifiers: 'control',
key: '3',
},
{
id: '4',
operation: 'remove',
group: 1,
modifiers: 'alt',
key: '1',
},
{
id: '5',
operation: 'remove',
group: 2,
modifiers: 'alt',
key: '2',
},
{
id: '6',
operation: 'remove',
group: 3,
modifiers: 'alt',
key: '3',
},
];
let keyset = document.createElement('keyset');
keyset.setAttribute('id', 'zoterotag-keyset');

for (let i in shortcuts) {
keyset.appendChild(Zotero.ZoteroTag.createKey(shortcuts[i]));
}
document.getElementById('mainKeyset').parentNode.appendChild(keyset);
},
createKey: function(keyObj) {
let key = document.createElement('key');
key.setAttribute('id', 'zoterotag-key-'+keyObj.id);
// Zotero.ZoteroTag.keyset.appendChild(key);
// Set label attribute so that keys show up nicely in keyconfig
// extension
// key.setAttribute('label', 'Zutilo: ' + Zutilo.keys.keyName(keyLabel));
// key.setAttribute('command', 'zutilo-keyset-command');
key.setAttribute('oncommand', '//');
key.addEventListener('command', function() {
try {
Zotero.ZoteroTag.updateSelectedItems(keyObj.operation, keyObj.group);
} catch (error) {
Zotero.ZoteroTag.showProgressWindow('ERROR', 'Zotero Tag: Fail to add/remove tags.', 'fail');
}
});

if (keyObj.modifiers) {
key.setAttribute('modifiers', keyObj.modifiers);
}
if (keyObj.key) {
key.setAttribute('key', keyObj.key);
} else if (keyObj.keycode) {
key.setAttribute('keycode', keyObj.keycode);
} else {
// No key or keycode. Set to empty string to disable.
key.setAttribute('key', '');
}
return key;
},
resetState: function() {
// Reset state for updating items.
Zotero.ZoteroTag.current = -1;
Expand All @@ -141,7 +228,7 @@ Zotero.ZoteroTag = {
Zotero.ZoteroTag.numberOfUpdatedItems = 0;
},
updateSelectedEntity: function(operation='add', group=1) {
Zotero.debug('ZoteroTag: Updating items in entity')
Zotero.debug('ZoteroTag: Updating items in entity');
if (!ZoteroPane.canEdit()) {
ZoteroPane.displayCannotEditLibraryMessage();
return;
Expand Down Expand Up @@ -201,7 +288,7 @@ Zotero.ZoteroTag = {
Zotero.debug(val);
Zotero.ZoteroTag.updateItem(val, operation, tags);
})
Zotero.ZoteroTag.showProgressWindow('SUCCESS', `${operation} ${tags.length} tags from ${items.length} items.`)
Zotero.ZoteroTag.showProgressWindow('SUCCESS', `${operation} ${tags.length} tags in ${items.length} items.`)
},
updateItem: function(item, operation, tags) {
Zotero.debug('ZoteroTag: Updating item: ' + JSON.stringify(item));
Expand Down
13 changes: 11 additions & 2 deletions chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
<!ENTITY zotero.zoterotag.submenu.label "Add/Remove tag by group...">
<!ENTITY zotero.zoterotag.updateAll.label "Update All Tags">
<!ENTITY zotero.zoterotag.updateCollection.label "Update Collection Tags">

<!ENTITY zotero.zoterotag.rules.title "Rules Management">
<!ENTITY zotero.zoterotag.rules.info "Rules in group 1, 2, and 3 can be added/removed in batches through the right-click menu; You can set automatic addition for different rules">
<!ENTITY zotero.zoterotag.rules.info.1 "Rules in group 1, 2, and 3 can be added/removed in batches through the right-click menu;">
<!ENTITY zotero.zoterotag.rules.info.2 "You can set automatic addition for different rules;">
<!ENTITY zotero.zoterotag.rules.info.3 "Split different tags by ','(comma) and manage them in one rule;">
<!ENTITY zotero.zoterotag.rules.info.4 "Example: rule 2 contains 'tag1, tag2, tag3', and all three tags can be managed in rule 2.">
<!ENTITY zotero.zoterotag.rules.listheader.id "ID">
<!ENTITY zotero.zoterotag.rules.listheader.tags "Tags">
<!ENTITY zotero.zoterotag.rules.listheader.autoadd "Automatic Add">
Expand All @@ -20,4 +24,9 @@
<!ENTITY zotero.zoterotag.rules.removetext "Remove Rule">
<!ENTITY zotero.zoterotag.rules.reset "⚠️Reset">
<!ENTITY zotero.zoterotag.rules.resettext "Reset Rules">
<!ENTITY zotero.zoterotag.rules.warningtext "The OK button will NOT save any rule modification. Please click ✅ to save modified rule.">
<!ENTITY zotero.zoterotag.rules.warningtext "The OK button will NOT save any rule modification. Please click ✅ to save modified rule.">

<!ENTITY zotero.zoterotag.help.title.label "Help">
<!ENTITY zotero.zoterotag.help.shortcuts.add.label "Add tag Group shortcuts: ctrl+1(Group 1), ctrl+2(Group 2), ctrl+3(Group 3).">
<!ENTITY zotero.zoterotag.help.shortcuts.remove.label "Remove tag Group shortcuts: alt+1(Group 1), alt+2(Group 2), alt+3(Group 3).">
<!ENTITY zotero.zoterotag.help.setcolor.label "How to colorize my tags?">
13 changes: 11 additions & 2 deletions chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
<!ENTITY zotero.zoterotag.submenu.label "更多添加/删除标签组选项...">
<!ENTITY zotero.zoterotag.updateAll.label "更新所有标签">
<!ENTITY zotero.zoterotag.updateCollection.label "更新分类下所有标签">

<!ENTITY zotero.zoterotag.rules.title "规则管理">
<!ENTITY zotero.zoterotag.rules.info "分组1,2,3中的规则可以通过右键菜单控制批量添加/移除;可以为不同规则分别设置自动添加">
<!ENTITY zotero.zoterotag.rules.info.1 "分组1,2,3中的规则可以通过右键菜单控制批量添加/移除;">
<!ENTITY zotero.zoterotag.rules.info.2 "可以为不同规则分别设置自动添加;">
<!ENTITY zotero.zoterotag.rules.info.3 "用半角逗号(,)分隔不同标签,并在一条规则中同时管理它们;">
<!ENTITY zotero.zoterotag.rules.info.4 "例如:规则2包含'tag1, tag2, tag3',则三个标签都将由规则2管理。">
<!ENTITY zotero.zoterotag.rules.listheader.id "序号">
<!ENTITY zotero.zoterotag.rules.listheader.tags "标签">
<!ENTITY zotero.zoterotag.rules.listheader.autoadd "自动添加">
Expand All @@ -20,4 +24,9 @@
<!ENTITY zotero.zoterotag.rules.removetext "移除规则">
<!ENTITY zotero.zoterotag.rules.reset "⚠️恢复默认设置">
<!ENTITY zotero.zoterotag.rules.resettext "恢复默认设置">
<!ENTITY zotero.zoterotag.rules.warningtext "OK按钮【不会】保存更改,请单击✅以保存对规则的修改。">
<!ENTITY zotero.zoterotag.rules.warningtext "OK按钮【不会】保存更改,请单击✅以保存对规则的修改。">

<!ENTITY zotero.zoterotag.help.title.label "帮助">
<!ENTITY zotero.zoterotag.help.shortcuts.add.label "为选中项添加标签组快捷键: ctrl+1(组 1), ctrl+2(组 2), ctrl+3(组 3)。">
<!ENTITY zotero.zoterotag.help.shortcuts.remove.label "从选中项删除标签组快捷键: alt+1(组 1), alt+2(组 2), alt+3(组 3)。">
<!ENTITY zotero.zoterotag.help.setcolor.label "如何为标签添加颜色?">
Binary file added docs/tag-color-img-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tag-color-img-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tag-color-img-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/tag-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tag Color Settings

## Result:
![item marked with tag color](./tag-color-img-0.png)

## Steps:
1. Right click tag in the 'Tag Selector' pane.
![select tag](./tag-color-img-1.png)
2. Click 'Assign Color'.
3. Set color.
![set color](./tag-color-img-2.png)
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="xy_wong@zju.edu.cn"
em:name="Zotero Tag"
em:version="0.0.4"
em:version="0.0.5"
em:type="2"
em:creator="windingwind"
em:description="Zotero plugin for automatically add tag for an added item."
Expand Down
4 changes: 2 additions & 2 deletions update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<em:id>zotero@chnm.gmu.edu</em:id>
<em:minVersion>5.0</em:minVersion>
<em:maxVersion>5.*</em:maxVersion>
<em:updateLink>https://github.com/windingwind/zotero-tag/releases/download/v0.0.4/zotero-tag-0.0.4.xpi</em:updateLink>
<em:updateLink>https://github.com/windingwind/zotero-tag/releases/download/v0.0.5/zotero-tag-0.0.5.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>
<em:targetApplication>
<rdf:Description>
<em:id>juris-m@juris-m.github.io</em:id>
<em:minVersion>5.0</em:minVersion>
<em:maxVersion>5.*</em:maxVersion>
<em:updateLink>https://github.com/windingwind/zotero-tag/releases/download/v0.0.4/zotero-tag-0.0.4.xpi</em:updateLink>
<em:updateLink>https://github.com/windingwind/zotero-tag/releases/download/v0.0.5/zotero-tag-0.0.5.xpi</em:updateLink>
</rdf:Description>
</em:targetApplication>
</rdf:Description>
Expand Down

0 comments on commit 74bbe83

Please sign in to comment.