From 474420620ef3fc44b76f48b0f5bedd099fc37728 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 6 Sep 2016 17:59:55 -0400 Subject: [PATCH] =?UTF-8?q?Add=20"Manage=20Styles=E2=80=A6"=20link=20to=20?= =?UTF-8?q?Create=20Bib=20and=20Doc=20Prefs=20windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking it cancels the current window, opens the Cite pane of the prefs, and selects the Styles tab. (This will be more useful once we have inline style installation from that pane.) --- chrome/content/zotero/bibliography.js | 18 ++++++++ chrome/content/zotero/bibliography.xul | 4 ++ .../integration/integrationDocPrefs.xul | 4 ++ .../content/zotero/preferences/preferences.js | 1 + .../zotero/preferences/preferences_cite.xul | 4 +- chrome/locale/en-US/zotero/zotero.dtd | 1 + test/tests/bibliographyTest.js | 45 +++++++++++++++++++ 7 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/tests/bibliographyTest.js diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js index ff45ac177..1d7d4e9c5 100644 --- a/chrome/content/zotero/bibliography.js +++ b/chrome/content/zotero/bibliography.js @@ -39,6 +39,8 @@ var Zotero_File_Interface_Bibliography = new function() { var lastSelectedStyle, lastSelectedLocale; + var isDocPrefs = false; + /* * Initialize some variables and prepare event listeners for when chrome is done * loading @@ -104,6 +106,11 @@ var Zotero_File_Interface_Bibliography = new function() { window.setTimeout(function () { listbox.ensureIndexIsVisible(selectIndex); listbox.selectedIndex = selectIndex; + if (listbox.selectedIndex == -1) { + // This can happen in tests if styles aren't loaded + Zotero.debug("No styles to select", 2); + return; + } Zotero_File_Interface_Bibliography.styleChanged(); }, 0); @@ -131,6 +138,7 @@ var Zotero_File_Interface_Bibliography = new function() { // ONLY FOR integrationDocPrefs.xul: update status of displayAs, set // bookmarks text + isDocPrefs = !!document.getElementById("displayAs"); if(document.getElementById("displayAs")) { if(_io.useEndnotes && _io.useEndnotes == 1) document.getElementById("displayAs").selectedIndex = 1; } @@ -271,4 +279,14 @@ var Zotero_File_Interface_Bibliography = new function() { Zotero.Prefs.set("export.lastLocale", lastSelectedLocale); } }; + + + this.manageStyles = function () { + document.documentElement.getButton('cancel').click(); + var win = Zotero.Utilities.Internal.openPreferences('zotero-prefpane-cite', { tab: 'styles-tab' }); + if (isDocPrefs) { + // TODO: Move activate() code elsewhere + Zotero.Integration.activate(win); + } + }; } diff --git a/chrome/content/zotero/bibliography.xul b/chrome/content/zotero/bibliography.xul index 08e025e92..239ee89f7 100644 --- a/chrome/content/zotero/bibliography.xul +++ b/chrome/content/zotero/bibliography.xul @@ -15,6 +15,10 @@ + + + diff --git a/chrome/content/zotero/integration/integrationDocPrefs.xul b/chrome/content/zotero/integration/integrationDocPrefs.xul index e2a3a8ab3..a67dad658 100644 --- a/chrome/content/zotero/integration/integrationDocPrefs.xul +++ b/chrome/content/zotero/integration/integrationDocPrefs.xul @@ -46,6 +46,10 @@ + + + diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js index cd10717d5..d66793ab0 100644 --- a/chrome/content/zotero/preferences/preferences.js +++ b/chrome/content/zotero/preferences/preferences.js @@ -39,6 +39,7 @@ var Zotero_Preferences = { if(window.arguments) { var io = window.arguments[0]; + io = io.wrappedJSObject || io; if(io.pane) { let tabID = io.tab; diff --git a/chrome/content/zotero/preferences/preferences_cite.xul b/chrome/content/zotero/preferences/preferences_cite.xul index 0ee500f6c..f138166ce 100644 --- a/chrome/content/zotero/preferences/preferences_cite.xul +++ b/chrome/content/zotero/preferences/preferences_cite.xul @@ -39,8 +39,8 @@ - - + + diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd index f383415c1..ebe403009 100644 --- a/chrome/locale/en-US/zotero/zotero.dtd +++ b/chrome/locale/en-US/zotero/zotero.dtd @@ -176,6 +176,7 @@ + diff --git a/test/tests/bibliographyTest.js b/test/tests/bibliographyTest.js new file mode 100644 index 000000000..8e7b805ee --- /dev/null +++ b/test/tests/bibliographyTest.js @@ -0,0 +1,45 @@ +"use strict"; + +describe("Create Bibliography Dialog", function () { + var win, zp; + + before(function* () { + win = yield loadZoteroPane(); + zp = win.ZoteroPane; + }); + + after(function () { + win.close(); + }); + + it("should perform a search", function* () { + yield Zotero.Styles.init(); + var item = yield createDataObject('item'); + + var deferred = Zotero.Promise.defer(); + var called = false; + waitForWindow("chrome://zotero/content/bibliography.xul", function (dialog) { + waitForWindow("chrome://zotero/content/preferences/preferences.xul", function (window) { + // Wait for pane switch + Zotero.Promise.coroutine(function* () { + do { + Zotero.debug("Checking for pane"); + yield Zotero.Promise.delay(5); + } + while (window.document.documentElement.currentPane.id != 'zotero-prefpane-cite'); + let pane = window.document.documentElement.currentPane; + assert.equal(pane.getElementsByTagName('tabbox')[0].selectedTab.id, 'styles-tab'); + assert.equal(pane.getElementsByTagName('tabbox')[0].selectedPanel.id, 'styles'); + called = true; + window.close(); + deferred.resolve(); + })(); + }); + dialog.document.getElementById('manage-styles').click(); + }); + win.Zotero_File_Interface.bibliographyFromItems(); + yield deferred.promise; + + assert.ok(called); + }); +});