From bce50e8e9c3834f14902ce7deadc57f54304d4f2 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 26 Aug 2020 19:42:34 +0300 Subject: [PATCH] Add old note backup and preview --- .../content/zotero/bindings/oldnoteeditor.xml | 578 ++++++++++++++++++ .../noteEditor.xul => noteBackup.js} | 48 +- chrome/content/zotero/noteBackup.xul | 26 + chrome/content/zotero/xpcom/editorInstance.js | 1 + chrome/content/zotero/xpcom/noteBackups.js | 40 ++ chrome/content/zotero/xpcom/zotero.js | 1 + chrome/skin/default/zotero/zotero.css | 4 +- components/zotero-service.js | 1 + 8 files changed, 684 insertions(+), 15 deletions(-) create mode 100644 chrome/content/zotero/bindings/oldnoteeditor.xml rename chrome/content/zotero/{containers/noteEditor.xul => noteBackup.js} (53%) create mode 100644 chrome/content/zotero/noteBackup.xul create mode 100644 chrome/content/zotero/xpcom/noteBackups.js diff --git a/chrome/content/zotero/bindings/oldnoteeditor.xml b/chrome/content/zotero/bindings/oldnoteeditor.xml new file mode 100644 index 0000000000..35f8af0c3c --- /dev/null +++ b/chrome/content/zotero/bindings/oldnoteeditor.xml @@ -0,0 +1,578 @@ + + + + + + + + + + + + + + false + false + false + false + false + + + + + + + + + "view" + + + ed.setMode('readonly')); + } + break; + + case 'edit': + if (this.noteField) { + this.noteField.onInit(ed => ed.setMode('design')); + } + this.editable = true; + this.saveOnEdit = true; + this.parentClickHandler = this.selectParent; + this.keyDownHandler = this.handleKeyDown; + this.commandHandler = this.save; + this.displayTags = true; + this.displayRelated = true; + break; + + default: + throw ("Invalid mode '" + val + "' in noteeditor.xml"); + } + + this._mode = val; + document.getAnonymousNodes(this)[0].setAttribute('mode', val); + this._id('links-box').mode = val; + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + if (!noteField.hasFocus()) { + document.getElementById(id).focus(); + } + }, 0); + } + return; + } + + break; + } + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0) { + var x = this.boxObject.screenX; + var y = this.boxObject.screenY; + this.id('relatedPopup').openPopupAtScreen(x, y, false); + } + else { + this.id('related').add(); + } + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chrome/content/zotero/containers/noteEditor.xul b/chrome/content/zotero/noteBackup.js similarity index 53% rename from chrome/content/zotero/containers/noteEditor.xul rename to chrome/content/zotero/noteBackup.js index e0c0d45b35..e227a78457 100644 --- a/chrome/content/zotero/containers/noteEditor.xul +++ b/chrome/content/zotero/noteBackup.js @@ -1,8 +1,7 @@ - - - %globalDTD; - %zoteroDTD; - ]> +*/ - - - - - \ No newline at end of file +var noteEditor; + +async function onLoad() { + noteEditor = document.getElementById('zotero-note-editor'); + noteEditor.mode = 'view'; + + // Set font size from pref + Zotero.setFontSize(noteEditor); + + if (window.arguments) { + var io = window.arguments[0]; + } + + var itemID = parseInt(io.itemID); + + var item = await Zotero.Items.getAsync(itemID); + + let note = await Zotero.NoteBackups.getNote(item.id); + if (!note) { + note = item.getNote(); + } + + var tmpItem = new Zotero.Item('note'); + tmpItem.libraryID = item.libraryID; + tmpItem.setNote(note); + noteEditor.item = tmpItem; + document.title = 'BACKUP OF: ' + item.getNoteTitle(); + + noteEditor.focus(); +} + +addEventListener("load", function(e) { onLoad(e); }, false); diff --git a/chrome/content/zotero/noteBackup.xul b/chrome/content/zotero/noteBackup.xul new file mode 100644 index 0000000000..a757c294b1 --- /dev/null +++ b/chrome/content/zotero/noteBackup.xul @@ -0,0 +1,26 @@ + + + + + + + + +