From 47f57509e53216a1d2fc110f3c7c7dfb37135bec Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Fri, 11 Feb 2011 22:16:32 +0000 Subject: [PATCH] make column and position information persist between tab and overlay --- chrome/content/zotero/overlay.js | 2 ++ chrome/content/zotero/zoteroPane.js | 49 +++++++++++++++++++++++++++- chrome/content/zotero/zoteroPane.xul | 40 +++++++++++------------ defaults/preferences/zotero.js | 3 ++ 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 86e4707f61..f7fb6ac6d0 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -212,6 +212,8 @@ var ZoteroOverlay = new function() // Make sure tags splitter isn't missing for people upgrading from <2.0b7 document.getElementById('zotero-tags-splitter').collapsed = false; } else { + ZoteroPane.makeHidden(); + // Collapse pane zoteroPane.setAttribute('collapsed', true); zoteroPane.height = 0; diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 92ddb47972..05631a06d7 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -317,6 +317,8 @@ var ZoteroPane = new function() this.collectionsView.unregister(); if (this.itemsView) this.itemsView.unregister(); + + _serializePersist(); } /** @@ -344,6 +346,8 @@ var ZoteroPane = new function() return false; } + _unserializePersist(); + this.updateTagSelectorSize(); // Focus the quicksearch on pane open @@ -379,6 +383,12 @@ var ZoteroPane = new function() return true; } + /** + * Function to be called before ZoteroPane is hidden. Does not actually hide the Zotero pane. + */ + this.makeHidden = function() { + _serializePersist(); + } function isShowing() { var zoteroPane = document.getElementById('zotero-pane-stack'); @@ -3424,5 +3434,42 @@ var ZoteroPane = new function() } } } - + + /** + * Unserializes zotero-persist elements from preferences + */ + function _unserializePersist() { + var serializedValues = Zotero.Prefs.get("pane.persist"); + if(!serializedValues) return; + serializedValues = JSON.parse(serializedValues); + for(var id in serializedValues) { + var el = document.getElementById(id); + if(!el) return; + var elValues = serializedValues[id]; + for(var attr in elValues) { + el.setAttribute(attr, elValues[attr]); + } + } + + if(this.itemsView) this.itemsView.sort(); + } + + /** + * Serializes zotero-persist elements to preferences + */ + function _serializePersist() { + var serializedValues = {}; + for each(var el in document.getElementsByAttribute("zotero-persist", "*")) { + if(!el.getAttribute) continue; + var id = el.getAttribute("id"); + if(!id) continue; + var elValues = {}; + for each(var attr in el.getAttribute("zotero-persist").split(/[\s,]+/)) { + var attrValue = el.getAttribute(attr); + elValues[attr] = attrValue; + } + serializedValues[id] = elValues; + } + Zotero.Prefs.set("pane.persist", JSON.stringify(serializedValues)); + } } \ No newline at end of file diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul index 5a0396c683..ea460a961c 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -126,7 +126,7 @@ - + @@ -181,7 +181,7 @@ - @@ -190,7 +190,7 @@ - + @@ -246,82 +246,82 @@ + flex="4" zotero-persist="width ordinal hidden sortActive sortDirection"/> + flex="1" zotero-persist="width ordinal hidden sortActive sortDirection"/>