From a4c09ed7019abe03ff15a1fb35fb9ea7ad765881 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Tue, 30 Jan 2024 12:02:32 -0500 Subject: [PATCH] Trigger inline editing from Rename Collection... --- chrome/content/zotero/collectionTree.jsx | 13 ++++++++++--- chrome/content/zotero/zoteroPane.js | 12 +----------- chrome/locale/en-US/zotero/zotero.properties | 1 - 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index 7cb501de3c..a9b422af89 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -221,9 +221,7 @@ var CollectionTree = class CollectionTree extends LibraryTree { let index = indices[0]; let treeRow = this.getRow(index); if (treeRow.isCollection() && this.editable && this.selection.focused == index) { - this._editing = treeRow; - treeRow.editingName = treeRow.ref.name; - this.tree.invalidateRow(index); + this.startEditing(treeRow); } else if (treeRow.isLibrary()) { let uri = Zotero.URI.getCurrentUserLibraryURI(); @@ -256,6 +254,15 @@ var CollectionTree = class CollectionTree extends LibraryTree { await treeRow.ref.saveTx(); } + startEditing = (treeRow) => { + if (!treeRow.isCollection()) { + throw new Error('Only collections can be edited inline'); + } + this._editing = treeRow; + treeRow.editingName = treeRow.ref.name; + this.tree.invalidateRow(this._rowMap[treeRow.id]); + }; + stopEditing = () => { this._editing = null; // Returning focus to the tree container diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 1fba8b7b15..2db008ba30 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -2642,17 +2642,7 @@ var ZoteroPane = new function() var row = this.getCollectionTreeRow(); if (row) { if (row.isCollection()) { - var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - - var newName = { value: row.getName() }; - var result = promptService.prompt(window, "", - Zotero.getString('pane.collections.rename'), newName, "", {}); - - if (result && newName.value) { - row.ref.name = newName.value; - row.ref.saveTx(); - } + this.collectionsView.startEditing(row); } else { let s = row.ref.clone(); diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 4a0ad1c0bd..6c67442603 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -262,7 +262,6 @@ pane.collections.deleteSearch = Are you sure you want to delete the selected pane.collections.emptyTrash = Are you sure you want to permanently remove items in the Trash? pane.collections.newSavedSeach = New Saved Search pane.collections.savedSearchName = Enter a name for this saved search: -pane.collections.rename = Rename collection: pane.collections.library = My Library pane.collections.publications = My Publications pane.collections.feeds = Feeds