From bb594296643c50bc6ebc80272a9ba7cf2469d5a3 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 18 Aug 2019 16:22:39 -0400 Subject: [PATCH] =?UTF-8?q?Add=20"Convert=20Linked=20Files=20to=20Stored?= =?UTF-8?q?=20Files=E2=80=A6"=20menu=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In new File → Manage Attachments submenu Closes #1637 --- .../content/zotero/standalone/standalone.js | 135 +++++++++++++----- .../content/zotero/standalone/standalone.xul | 23 ++- chrome/content/zotero/xpcom/attachments.js | 82 +++++++++++ chrome/content/zotero/xpcom/data/item.js | 10 +- chrome/content/zotero/xpcom/data/relations.js | 29 ++++ chrome/content/zotero/xpcom/fulltext.js | 33 +++++ chrome/content/zotero/zoteroPane.js | 93 ++++++++++-- chrome/content/zotero/zoteroPane.xul | 1 + chrome/locale/en-US/zotero/standalone.dtd | 2 + chrome/locale/en-US/zotero/zotero.properties | 3 + test/tests/attachmentsTest.js | 67 +++++++++ 11 files changed, 417 insertions(+), 61 deletions(-) diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js index 3c4d4980f8..d53df4b4bf 100644 --- a/chrome/content/zotero/standalone/standalone.js +++ b/chrome/content/zotero/standalone/standalone.js @@ -91,6 +91,23 @@ const ZoteroStandalone = new function() { }); } + + this.onFileMenuOpen = function () { + var active = false; + try { + let zp = Zotero.getActiveZoteroPane(); + if (zp) { + active = !!zp.getSelectedItems().filter((item) => { + return item.isAttachment() + || (item.isRegularItem() && item.getAttachments().length); + }).length; + } + } + catch (e) {} + this.updateMenuItemEnabled('manage-attachments-menu', active); + }; + + /** * Builds new item menu */ @@ -138,6 +155,43 @@ const ZoteroStandalone = new function() { } + this.onManageAttachmentsMenuOpen = function () { + // Convert Linked Files to Stored Files + var active = false; + try { + let zp = Zotero.getActiveZoteroPane(); + if (zp) { + active = !!zp.getSelectedItems().filter((item) => { + return item.isLinkedFileAttachment() + || (item.isRegularItem() + && item.getAttachments() + .map(id => Zotero.Items.get(id)) + .some(att => att.isLinkedFileAttachment())); + }).length; + } + } + catch (e) {} + this.updateMenuItemEnabled('file-menuitem-convert-to-stored', active); + }; + + + this.onManageAttachmentsMenuItemClick = function (event) { + var menuitem = event.originalTarget; + var id = menuitem.id; + var prefix = 'file-menuitem-'; + if (menuitem.disabled || !id.startsWith(prefix)) { + return; + } + id = id.substr(prefix.length); + + switch (id) { + case 'convert-to-stored': + ZoteroPane.convertLinkedFilesToStoredFiles(); + break; + } + }; + + this.updateQuickCopyOptions = function () { var selected = false; try { @@ -181,28 +235,28 @@ const ZoteroStandalone = new function() { this.onViewMenuOpen = function () { // Layout mode var mode = Zotero.Prefs.get('layout'); - this.updateMenuItemCheckmark('standard', mode != 'stacked'); - this.updateMenuItemCheckmark('stacked', mode == 'stacked'); + this.updateMenuItemCheckmark('view-menuitem-standard', mode != 'stacked'); + this.updateMenuItemCheckmark('view-menuitem-stacked', mode == 'stacked'); // Panes this.updateMenuItemCheckmark( - 'collections-pane', + 'view-menuitem-collections-pane', document.getElementById('zotero-collections-pane').getAttribute('collapsed') != 'true' ); this.updateMenuItemCheckmark( - 'item-pane', + 'view-menuitem-item-pane', document.getElementById('zotero-item-pane').getAttribute('collapsed') != 'true' ); this.updateMenuItemCheckmark( - 'tag-selector', + 'view-menuitem-tag-selector', document.getElementById('zotero-tag-selector-container').getAttribute('collapsed') != 'true' ); // Font size var fontSize = Zotero.Prefs.get('fontSize'); - this.updateMenuItemDisabled('font-size-bigger', fontSize >= FONT_SIZES[FONT_SIZES.length - 1]); - this.updateMenuItemDisabled('font-size-smaller', fontSize <= FONT_SIZES[0]); - this.updateMenuItemDisabled('font-size-reset', fontSize == FONT_SIZES[0]); + this.updateMenuItemEnabled('view-menuitem-font-size-bigger', fontSize < FONT_SIZES[FONT_SIZES.length - 1]); + this.updateMenuItemEnabled('view-menuitem-font-size-smaller', fontSize > FONT_SIZES[0]); + this.updateMenuItemEnabled('view-menuitem-font-size-reset', fontSize != FONT_SIZES[0]); var noteFontSize = Zotero.Prefs.get('note.fontSize'); for (let menuitem of document.querySelectorAll(`#note-font-size-menu menuitem`)) { @@ -213,46 +267,27 @@ const ZoteroStandalone = new function() { menuitem.removeAttribute('checked'); } } - this.updateMenuItemDisabled('note-font-size-reset', noteFontSize == NOTE_FONT_SIZE_DEFAULT); + this.updateMenuItemEnabled( + 'view-menuitem-note-font-size-reset', + noteFontSize != NOTE_FONT_SIZE_DEFAULT + ); // Recursive collections - this.updateMenuItemCheckmark('recursive-collections', Zotero.Prefs.get('recursiveCollections')); + this.updateMenuItemCheckmark( + 'view-menuitem-recursive-collections', + Zotero.Prefs.get('recursiveCollections') + ); }; - this.updateMenuItemCheckmark = function (idSuffix, checked) { - var id = 'view-menuitem-' + idSuffix; - var menuitem = document.getElementById(id); - if (checked) { - menuitem.setAttribute('checked', true); - } - else { - menuitem.removeAttribute('checked'); - } - }; - - - this.updateMenuItemDisabled = function (idSuffix, disabled) { - var id = 'view-menuitem-' + idSuffix; - var menuitem = document.getElementById(id); - if (disabled) { - menuitem.setAttribute('disabled', true); - } - else { - menuitem.removeAttribute('disabled'); - } - }; - - - this.updateViewOption = function (event) { + this.onViewMenuItemClick = function (event) { var menuitem = event.originalTarget; var id = menuitem.id; - - if (menuitem.disabled || !id.startsWith('view-menuitem-')) { + var prefix = 'view-menuitem-'; + if (menuitem.disabled || !id.startsWith(prefix)) { return; } - - id = id.substr(14); + id = id.substr(prefix.length); switch (id) { case 'standard': @@ -328,6 +363,28 @@ const ZoteroStandalone = new function() { }; + this.updateMenuItemCheckmark = function (id, checked) { + var menuitem = document.getElementById(id); + if (checked) { + menuitem.setAttribute('checked', true); + } + else { + menuitem.removeAttribute('checked'); + } + }; + + + this.updateMenuItemEnabled = function (id, enabled) { + var menuitem = document.getElementById(id); + if (enabled) { + menuitem.removeAttribute('disabled'); + } + else { + menuitem.setAttribute('disabled', true); + } + }; + + this.toggleBooleanPref = function (pref) { Zotero.Prefs.set(pref, !Zotero.Prefs.get(pref)); }; diff --git a/chrome/content/zotero/standalone/standalone.xul b/chrome/content/zotero/standalone/standalone.xul index 5a36486ab0..7d435ceb5f 100644 --- a/chrome/content/zotero/standalone/standalone.xul +++ b/chrome/content/zotero/standalone/standalone.xul @@ -120,7 +120,8 @@ - + + + + + + + - + @@ -201,7 +212,7 @@ - + @@ -211,7 +222,7 @@ -