From f09def19f7639453f6268b76329e9523d9a1bf2f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 27 May 2006 00:20:27 +0000 Subject: [PATCH] - Implemented singleton XPCOM component to store core Scholar objects More details coming on Basecamp: http://chnm.grouphub.com/W161222 *** Important note: after checking out this code, be sure to delete the compreg.dat and xpti.dat files in your FF profile directory or else the extension will not load. They'll be regenerated when you start FF again, and you won't have to do it again unless we add interfaces or other components. Once I set up the XPI packaging system, this step won't be necessary. *** - Localization properties are now loaded directly via nsIStringBundleService and available via Scholar.getString(name) -- removed stringbundle from XUL - Updated status line in bottom right to reflect whether Scholar is loaded correctly or not (temporary, obviously) --- chrome/chromeFiles/content/scholar/include.js | 11 +- chrome/chromeFiles/content/scholar/overlay.js | 40 ++++-- .../chromeFiles/content/scholar/overlay.xul | 19 +-- chrome/chromeFiles/content/scholar/scholar.js | 2 +- .../chromeFiles/content/scholar/scholar.xul | 11 +- .../chromeFiles/content/scholar/test/test.xul | 6 +- .../locale/en-US/scholar/scholar.dtd | 2 - components/chnmIScholarService.js | 121 ++++++++++++++++++ 8 files changed, 171 insertions(+), 41 deletions(-) create mode 100644 components/chnmIScholarService.js diff --git a/chrome/chromeFiles/content/scholar/include.js b/chrome/chromeFiles/content/scholar/include.js index de0c6d71c..2ab295679 100644 --- a/chrome/chromeFiles/content/scholar/include.js +++ b/chrome/chromeFiles/content/scholar/include.js @@ -1,6 +1,5 @@ -var Scholar_browserWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator) - .getMostRecentWindow("navigator:browser"); - -const SCHOLAR_CONFIG = Scholar_browserWindow.SCHOLAR_CONFIG; -var Scholar = Scholar_browserWindow.Scholar; +var Scholar = Components.classes["@chnm.gmu.edu/Scholar;1"] + // Currently uses only nsISupports + //.getService(Components.interfaces.chnmIScholarService). + .getService(Components.interfaces.nsISupports) + .wrappedJSObject; diff --git a/chrome/chromeFiles/content/scholar/overlay.js b/chrome/chromeFiles/content/scholar/overlay.js index e76398220..14c71e519 100644 --- a/chrome/chromeFiles/content/scholar/overlay.js +++ b/chrome/chromeFiles/content/scholar/overlay.js @@ -11,29 +11,42 @@ const SCHOLAR_CONFIG = { * Core functions */ var Scholar = new function(){ - var _initialized = false + var _initialized = false; + var _localizedStringBundle; - this.testString = 'Sidebar is not registered'; - this.LocalizedStrings; + // Privileged (public) methods this.init = init; this.debug = debug; this.varDump = varDump; + this.getString = getString; this.flattenArguments = flattenArguments; this.join = join; + this.Hash = Hash; /* * Initialize the extension */ function init(){ - this.LocalizedStrings = document.getElementById('scholar-strings'); - - if (!_initialized){ - Scholar.DB.updateSchema(); - _initialized = true; - return true; + if (_initialized){ + return false; } - return false; + + Scholar.DB.updateSchema(); + + // Load in the localization stringbundle for use by getString(name) + var src = 'chrome://scholar/locale/scholar.properties'; + var localeService = + Components.classes["@mozilla.org/intl/nslocaleservice;1"] + .getService(Components.interfaces.nsILocaleService); + var appLocale = localeService.getApplicationLocale(); + var stringBundleService = + Components.classes["@mozilla.org/intl/stringbundle;1"] + .getService(Components.interfaces.nsIStringBundleService); + _localizedStringBundle = stringBundleService.createBundle(src, appLocale); + + _initialized = true; + return true; } @@ -117,6 +130,11 @@ var Scholar = new function(){ } + function getString(name){ + return _localizedStringBundle.GetStringFromName(name); + } + + /* * Flattens mixed arrays/values in a passed _arguments_ object and returns * an array of values -- allows for functions to accept both arrays of @@ -226,5 +244,3 @@ Scholar.Hash.prototype.remove = function(in_key){ Scholar.Hash.prototype.has = function(in_key){ return typeof(this.items[in_key]) != 'undefined'; } - -window.addEventListener("load", function(e) { Scholar.init(e); }, false); diff --git a/chrome/chromeFiles/content/scholar/overlay.xul b/chrome/chromeFiles/content/scholar/overlay.xul index b9eb20525..9d0a9b53f 100644 --- a/chrome/chromeFiles/content/scholar/overlay.xul +++ b/chrome/chromeFiles/content/scholar/overlay.xul @@ -5,18 +5,21 @@ - +