Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support markdown style link copying #241

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions addon/chrome/content/zutilo/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ keys.alts.copyItems_alt = {
}
}
}
// tab utilities
keys.categories.load_tabs_from_selected_item = 'attachments'
keys.shortcuts.load_tabs_from_selected_item = function(win) {
win.ZutiloChrome.zoteroOverlay.load_tabs_from_selected_item()
};
keys.categories.save_tabs_to_selected_item = 'itemediting'
keys.shortcuts.save_tabs_to_selected_item = function(win) {
win.ZutiloChrome.zoteroOverlay.save_tabs_to_selected_item()
};
keys.categories.save_tabs_to_selected_collection = 'other'
keys.shortcuts.save_tabs_to_selected_collection = function(win) {
win.ZutiloChrome.zoteroOverlay.save_tabs_to_selected_collection()
};
keys.categories.copyZoteroSelectPDFLink = 'copying'
keys.shortcuts.copyZoteroSelectPDFLink = function(win) {
win.ZutiloChrome.zoteroOverlay.copyZoteroSelectPDFLink()
};
keys.categories.copyZoteroSelectMDLink = 'copying'
keys.shortcuts.copyZoteroSelectMDLink = function(win) {
win.ZutiloChrome.zoteroOverlay.copyZoteroSelectMDLink()
};
keys.categories.copyZoteroSelectLink = 'copying'
keys.shortcuts.copyZoteroSelectLink = function(win) {
win.ZutiloChrome.zoteroOverlay.copyZoteroSelectLink()
Expand Down
146 changes: 146 additions & 0 deletions addon/chrome/content/zutilo/zoteroOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,152 @@ ZutiloChrome.zoteroOverlay = {
this._copyToClipboard(Zotero.URI.getCollectionURI(collection))
},

_save_tabs_to_item: async function (tab_store) {
let tabs = Zotero_Tabs._tabs
.filter(t => !!t['data'])
.map(t => ({
'type': t['type'],
'title': t['title'],
// itemID is not enough, as it is not unique across libraries
'data': Zotero.Items.getLibraryAndKeyFromID(t['data']['itemID']),
}));

let tab_content = JSON.stringify(tabs);

tab_store.setField("abstractNote", tabs.map(t => t['title']).join(', '))
tab_store.setField("extra", tab_content)
return await tab_store.saveTx()
},

load_tabs_from_selected_item: async function(){
let opened_items = Zotero_Tabs._tabs.filter(t => !!t['data']).map(t=>t['data']['itemID'])
let selectedItems = ZoteroPane.getSelectedItems();
if (!selectedItems.length) {
throw new Error("Please select an item first.");
}

for(let item of selectedItems)
{
if(item.itemType == "document" && item.getField("extra"))
{
let tabs = JSON.parse(item.getField("extra"))
for(let tab of tabs)
{
// open tab if not already opened
if(opened_items.indexOf(tab['data']['itemID']) > -1)
{
continue;
}
let tab_type = tab['type']
if(tab_type == 'reader')
tab_type = 'reader-unloaded' // force reload

let item_id = Zotero.Items.getIDFromLibraryAndKey(tab['data']['libraryID'], tab['data']['key'])
Zotero_Tabs.add({
type: tab_type,
title: tab['title'] || '',
data: {
itemID: item_id
}
});
}
}
}
},

save_tabs_to_selected_item: async function(){
let item = ZoteroPane.getSelectedItems()[0];
if (!item) {
throw new Error("Please select an item first.");
}
await this._save_tabs_to_item(item)
},

save_tabs_to_selected_collection: async function(){
let collection = ZoteroPane.getSelectedCollection();
if (!collection) {
throw new Error("Please select a collection first.");
}
let item = new Zotero.Item("document");
item.libraryID = collection.libraryID;
item.setField("title", "__tab_history_" + new Date().toISOString().replace(/:/g, "_"));

await this._save_tabs_to_item(item)
await Zotero.DB.executeTransaction(async () => { await collection.addItems([item.id]) })
},

copyZoteroSelectPDFLink: function(){
this._getZoteroActionLink('open-pdf', true)
},

copyZoteroSelectMDLink: function(){
this._getZoteroActionLink('select', true)
},

_getZoteroActionLink: function(action, is_markdown_style){
var zitems = this.getSelectedItems();
var links = [];

if (!this.checkItemNumber(zitems, 'regularNoteAttachment1')) {
return false;
}

var collection_uri = ""

var collection = ZutiloChrome.zoteroOverlay.Collection.selected()
if (collection){
if (collection.libraryID === Zotero.Libraries.userLibraryID) {
collection_uri = `zotero://${action}/library/collections/${collection.key}`
} else {
collection_uri = `zotero://${action}/groups/${Zotero.Groups.getGroupIDFromLibraryID(collection.libraryID)}/collections/${collection.key}`
}
}

if(action == 'open-pdf')
{
collection = false;
var files = this.getSelectedAttachments(/*Zotero.Attachments.LINK_MODE_LINKED_FILE*/);
if (!this.checkItemNumber(files, 'attachment1')) {
return false;
}

zitems = files;
}

var libraryType
var path
for (var ii = 0; ii < zitems.length; ii++) {
var item = zitems[ii]
var title = item.getField('title');
var cite_key = item.getField('citationKey');
if(cite_key)
cite_key = `[[${cite_key}]]`
libraryType = Zotero.Libraries.get(item.libraryID).libraryType;

switch (libraryType) {
case 'group':
path = Zotero.URI.getLibraryPath(item.libraryID)
break;
case 'user':
path = 'library'
break;
default:
// Feeds?
continue
}
if(collection)
links.push(`[${title}](${collection_uri}/items/${item.key})`)
else
links.push(`[${title}](zotero://${action}/${path}/items/${item.key})`)
}

var clipboardText = links.join('\r\n');

this._copyToClipboard(clipboardText)

return true;
},

copyZoteroSelectLink: function() {
var zitems = this.getSelectedItems();
var links = [];
Expand Down
7 changes: 4 additions & 3 deletions addon/chrome/content/zutilo/zutilo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ var Zutilo = {
// menu
_menuFunctions: {
item: [],
collection: ['copyZoteroCollectionSelectLink', 'copyZoteroCollectionURI']
collection: ['copyZoteroCollectionSelectLink', 'copyZoteroCollectionURI', 'save_tabs_to_selected_collection']
},
_itemMenuItems_static: ['copyTags', 'removeTags', 'pasteTags', 'relateItems',
'showAttachments', 'modifyAttachments', 'modifyURLAttachments',
'copyAttachmentPaths', 'copyCreators', 'copyItems',
'copyZoteroSelectLink', 'copyZoteroItemURI', 'createBookSection',
'copyZoteroSelectLink', 'copyZoteroSelectMDLink', 'copyZoteroSelectPDFLink', 'copyZoteroItemURI', 'createBookSection',
'createBookItem', 'copyChildIDs', 'relocateChildren', 'copyJSON',
'pasteJSONIntoEmptyFields', 'pasteJSONFromNonEmptyFields',
'pasteJSONAll', 'pasteJSONItemType', 'openZoteroItemURI'
'pasteJSONAll', 'pasteJSONItemType', 'openZoteroItemURI', 'load_tabs_from_selected_item',
'save_tabs_to_selected_item'
],

_bundle: Cc['@mozilla.org/intl/stringbundle;1'].
Expand Down
3 changes: 3 additions & 0 deletions addon/chrome/locale/de/zutilo/zutilo.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ zutilo.preferences.itemmenu.copyCreators = Autoren kopieren
zutilo.preferences.itemmenu.copyItems = Einträge mit Quick-Copy kopieren
zutilo.preferences.itemmenu.copyItems_alt = QuickCopy items (alt %S)
zutilo.preferences.itemmenu.copyZoteroSelectLink = Copy select item links
zutilo.preferences.itemmenu.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.preferences.itemmenu.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.preferences.itemmenu.copyZoteroItemURI = Copy Zotero URIs
zutilo.preferences.itemmenu.openZoteroItemURI = Open Zotero URIs
zutilo.preferences.itemmenu.createBookSection = Create book section
Expand Down Expand Up @@ -124,6 +126,7 @@ zutilo.shortcuts.name.copyAttachmentPaths = Copy attachment paths
zutilo.shortcuts.name.copyItems = Einträge mit Quick-Copy kopieren
zutilo.shortcuts.name.copyItems_alt = QuickCopy items (alt %S)
zutilo.shortcuts.name.copyZoteroSelectLink = Copy select item links
zutilo.shortcuts.name.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.shortcuts.name.copyZoteroItemURI = Copy Zotero URIs
zutilo.shortcuts.name.openZoteroItemURI = Open Zotero URIs
zutilo.shortcuts.name.createBookSection = Create book section
Expand Down
15 changes: 15 additions & 0 deletions addon/chrome/locale/en-US/zutilo/zutilo.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ zutilo.itemmenu.copyAttachmentPaths = Copy attachment paths
zutilo.itemmenu.copyItems = QuickCopy items to clipboard
zutilo.itemmenu.copyItems_alt = QuickCopy items to clipboard (alt. %S)
zutilo.itemmenu.copyZoteroSelectLink = Copy select item links
zutilo.itemmenu.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.itemmenu.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.itemmenu.copyZoteroItemURI = Copy Zotero URIs
zutilo.itemmenu.openZoteroItemURI = Open Zotero URIs
zutilo.itemmenu.createBookSection = Create book section
Expand All @@ -54,7 +56,10 @@ zutilo.itemmenu.pasteJSONIntoEmptyFields = Paste into empty item fields
zutilo.itemmenu.pasteJSONFromNonEmptyFields = Paste non-empty item fields
zutilo.itemmenu.pasteJSONAll = Paste all item fields
zutilo.itemmenu.pasteJSONItemType = Paste item type
zutilo.itemmenu.load_tabs_from_selected_item = Load tabs from selected item
zutilo.itemmenu.save_tabs_to_selected_item = Save tabs to selected item

zutilo.collectionmenu.save_tabs_to_selected_collection = Save tabs to selected collection
zutilo.collectionmenu.zutilo = Zutilo
zutilo.collectionmenu.copyZoteroCollectionSelectLink = Copy select collection link
zutilo.collectionmenu.copyZoteroCollectionURI = Copy Zotero URIs
Expand All @@ -74,6 +79,8 @@ zutilo.preferences.itemmenu.copyCreators = Copy creators
zutilo.preferences.itemmenu.copyItems = QuickCopy items
zutilo.preferences.itemmenu.copyItems_alt = QuickCopy items (alt %S)
zutilo.preferences.itemmenu.copyZoteroSelectLink = Copy select item links
zutilo.preferences.itemmenu.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.preferences.itemmenu.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.preferences.itemmenu.copyZoteroItemURI = Copy Zotero URIs
zutilo.preferences.itemmenu.openZoteroItemURI = Open Zotero URIs
zutilo.preferences.itemmenu.createBookSection = Create book section
Expand All @@ -85,7 +92,10 @@ zutilo.preferences.itemmenu.pasteJSONIntoEmptyFields = Paste into empty item fie
zutilo.preferences.itemmenu.pasteJSONFromNonEmptyFields = Paste non-empty item fields
zutilo.preferences.itemmenu.pasteJSONAll = Paste all item fields
zutilo.preferences.itemmenu.pasteJSONItemType = Paste item type
zutilo.preferences.itemmenu.load_tabs_from_selected_item = Load tabs from selected item
zutilo.preferences.itemmenu.save_tabs_to_selected_item = Save tabs to selected item

zutilo.preferences.collectionmenu.save_tabs_to_selected_collection = Save tabs to selected collection
zutilo.preferences.collectionmenu.Zotero = Zotero context menu
zutilo.preferences.collectionmenu.Zutilo = Zutilo context menu
zutilo.preferences.collectionmenu.Hide = Hide
Expand Down Expand Up @@ -124,6 +134,8 @@ zutilo.shortcuts.name.copyAttachmentPaths = Copy attachment paths
zutilo.shortcuts.name.copyItems = QuickCopy items
zutilo.shortcuts.name.copyItems_alt = QuickCopy items (alt %S)
zutilo.shortcuts.name.copyZoteroSelectLink = Copy select item links
zutilo.shortcuts.name.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.shortcuts.name.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.shortcuts.name.copyZoteroItemURI = Copy Zotero URIs
zutilo.shortcuts.name.openZoteroItemURI = Open Zotero URIs
zutilo.shortcuts.name.createBookSection = Create book section
Expand Down Expand Up @@ -157,7 +169,10 @@ zutilo.shortcuts.name.pasteJSONAll = Paste all item fields
zutilo.shortcuts.name.pasteJSONItemType = Paste item type
zutilo.shortcuts.name.copyZoteroCollectionSelectLink = Copy select collection link
zutilo.shortcuts.name.copyZoteroCollectionURI = Copy collection Zotero URI
zutilo.shortcuts.name.load_tabs_from_selected_item = Load tabs from selected item
zutilo.shortcuts.name.save_tabs_to_selected_item = Save tabs to selected item

zutilo.shortcuts.name.save_tabs_to_selected_collection = Save tabs to selected collection
zutilo.shortcuts.name.focusZoteroCollectionsTree = Collections pane: Focus
zutilo.shortcuts.name.focusZoteroItemsTree = Items pane: Focus
zutilo.shortcuts.name.advanceTabboxTab = Item pane: Next tab
Expand Down
15 changes: 15 additions & 0 deletions addon/chrome/locale/es/zutilo/zutilo.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ zutilo.itemmenu.copyAttachmentPaths = Copy attachment paths
zutilo.itemmenu.copyItems = Copiar ítems a portapapeles con la copia rápida
zutilo.itemmenu.copyItems_alt = QuickCopy items to clipboard (alt. %S)
zutilo.itemmenu.copyZoteroSelectLink = Copy select item links
zutilo.itemmenu.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.itemmenu.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.itemmenu.copyZoteroItemURI = Copy Zotero URIs
zutilo.itemmenu.openZoteroItemURI = Open Zotero URIs
zutilo.itemmenu.createBookSection = Create book section
Expand All @@ -54,7 +56,10 @@ zutilo.itemmenu.pasteJSONIntoEmptyFields = Paste into empty item fields
zutilo.itemmenu.pasteJSONFromNonEmptyFields = Paste non-empty item fields
zutilo.itemmenu.pasteJSONAll = Paste all item fields
zutilo.itemmenu.pasteJSONItemType = Paste item type
zutilo.itemmenu.load_tabs_from_selected_item = Load tabs from selected item
zutilo.itemmenu.save_tabs_to_selected_item = Save tabs to selected item

zutilo.collectionmenu.save_tabs_to_selected_collection = Save tabs to selected collection
zutilo.collectionmenu.zutilo = Zutilo
zutilo.collectionmenu.copyZoteroCollectionSelectLink = Copy select collection link
zutilo.collectionmenu.copyZoteroCollectionURI = Copy Zotero URIs
Expand All @@ -74,6 +79,8 @@ zutilo.preferences.itemmenu.copyCreators = Copiar creadores
zutilo.preferences.itemmenu.copyItems = Copiar ítems con copia rápida
zutilo.preferences.itemmenu.copyItems_alt = QuickCopy items (alt %S)
zutilo.preferences.itemmenu.copyZoteroSelectLink = Copy select item links
zutilo.preferences.itemmenu.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.preferences.itemmenu.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.preferences.itemmenu.copyZoteroItemURI = Copy Zotero URIs
zutilo.preferences.itemmenu.openZoteroItemURI = Open Zotero URIs
zutilo.preferences.itemmenu.createBookSection = Create book section
Expand All @@ -85,7 +92,10 @@ zutilo.preferences.itemmenu.pasteJSONIntoEmptyFields = Paste into empty item fie
zutilo.preferences.itemmenu.pasteJSONFromNonEmptyFields = Paste non-empty item fields
zutilo.preferences.itemmenu.pasteJSONAll = Paste all item fields
zutilo.preferences.itemmenu.pasteJSONItemType = Paste item type
zutilo.preferences.itemmenu.load_tabs_from_selected_item = Load tabs from selected item
zutilo.preferences.itemmenu.save_tabs_to_selected_item = Save tabs to selected item

zutilo.preferences.collectionmenu.save_tabs_to_selected_collection = Save tabs to selected collection
zutilo.preferences.collectionmenu.Zotero = Zotero context menu
zutilo.preferences.collectionmenu.Zutilo = Zutilo context menu
zutilo.preferences.collectionmenu.Hide = Hide
Expand Down Expand Up @@ -124,6 +134,8 @@ zutilo.shortcuts.name.copyAttachmentPaths = Copy attachment paths
zutilo.shortcuts.name.copyItems = Copiar ítems con copia rápida
zutilo.shortcuts.name.copyItems_alt = QuickCopy items (alt %S)
zutilo.shortcuts.name.copyZoteroSelectLink = Copy select item links
zutilo.shortcuts.name.copyZoteroSelectMDLink = Copy select item markdown links
zutilo.shortcuts.name.copyZoteroSelectPDFLink = Copy select item PDF links
zutilo.shortcuts.name.copyZoteroItemURI = Copy Zotero URIs
zutilo.shortcuts.name.openZoteroItemURI = Open Zotero URIs
zutilo.shortcuts.name.createBookSection = Create book section
Expand Down Expand Up @@ -157,7 +169,10 @@ zutilo.shortcuts.name.pasteJSONAll = Paste all item fields
zutilo.shortcuts.name.pasteJSONItemType = Paste item type
zutilo.shortcuts.name.copyZoteroCollectionSelectLink = Copy select collection link
zutilo.shortcuts.name.copyZoteroCollectionURI = Copy collection Zotero URI
zutilo.shortcuts.name.load_tabs_from_selected_item = Load tabs from selected item
zutilo.shortcuts.name.save_tabs_to_selected_item = Save tabs to selected item

zutilo.shortcuts.name.save_tabs_to_selected_collection = Save tabs to selected collection
zutilo.shortcuts.name.focusZoteroCollectionsTree = Enfocar el panel de colecciónes
zutilo.shortcuts.name.focusZoteroItemsTree = Enfocar el panel de ítems
zutilo.shortcuts.name.advanceTabboxTab = Enfocar ítem panel: pestaña siguiente
Expand Down
Loading