From 1ab1457f79404fa40f2a70754bd59f12d0e18cde Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Wed, 10 Jul 2002 23:34:52 +0000 Subject: [PATCH] Bug 30088. Fixed pref handling of typeaheadfind so that it has it's own default preferences file. No need to se prefs manually anymore. Touched up rdf files so that installing via xpi can work. Not part of build --- extensions/typeaheadfind/Makefile.in | 5 +++ extensions/typeaheadfind/install.js | 23 ++--------- extensions/typeaheadfind/jar.mn | 12 ++---- extensions/typeaheadfind/makefile.win | 3 ++ extensions/typeaheadfind/nsTypeAheadFind.cpp | 39 +++++++++--------- extensions/typeaheadfind/nsTypeAheadFind.h | 4 +- .../resources/content/prefs/MANIFEST | 0 .../resources/content/prefs/typeaheadfind.js | 41 +++++++++++++++++++ .../resources/locale/en-US/contents.rdf | 21 ++++++++++ .../locale/en-US/typeaheadfind.properties | 6 +++ 10 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 extensions/typeaheadfind/resources/content/prefs/MANIFEST create mode 100644 extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js create mode 100644 extensions/typeaheadfind/resources/locale/en-US/contents.rdf create mode 100644 extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties diff --git a/extensions/typeaheadfind/Makefile.in b/extensions/typeaheadfind/Makefile.in index 99a8481eeb4..77fd115cd4c 100644 --- a/extensions/typeaheadfind/Makefile.in +++ b/extensions/typeaheadfind/Makefile.in @@ -79,3 +79,8 @@ EXTRA_DSO_LDOPTS += \ $(MOZ_UNICHARUTIL_LIBS) \ $(MOZ_COMPONENT_LIBS) +libs:: + $(INSTALL) $(srcdir)/resources/content/prefs/typeaheadfind.js $(DIST)/bin/defaults/pref + +install:: + $(SYSINSTALL) $(IFLAGS1) $(srcdir)/resources/content/prefs/typeaheadfind.js $(DESTDIR)$(mozappdir)/defaults/pref diff --git a/extensions/typeaheadfind/install.js b/extensions/typeaheadfind/install.js index 99ed6304529..00963b45bb6 100644 --- a/extensions/typeaheadfind/install.js +++ b/extensions/typeaheadfind/install.js @@ -40,31 +40,16 @@ var gVersion = "0.1"; -var err = initInstall("Type Ahead Find", "/Netscape/Type Ahead Find", gVersion); +var err = initInstall("Type Ahead Find", "typeaheadfind", gVersion); logComment("initInstall: " + err); var fProgram = getFolder("Program"); -var fComponents = getFolder("Components"); -// var fChrome = getFolder("Chrome"); +logComment("fProgram: " + fProgram); -// addDirectory: blank, archive_dir, install_dir, subdir -err = addDirectory("", "bin", fProgram, ""); -if (err != SUCCESS) - cancelInstall(err); - -err = addDirectory("", "components", fComponents, ""); -if (err != SUCCESS) - cancelInstall(err); - -err = addDirectory("", "chrome", fChrome, ""); -if (err != SUCCESS) - cancelInstall(err); +err = addDirectory("", gVersion, "bin", fProgram, "", true); +logComment("addDirectory: " + err); // Register chrome -registerChrome(PACKAGE | DELAYED_CHROME, getFolder("Chrome","typeaheadfind.jar"), "content/typeaheadfind/"); - -registerChrome(SKIN | DELAYED_CHROME, getFolder("Chrome","typeaheadfind.jar"), "skin/modern/typeaheadfind/"); - registerChrome(LOCALE | DELAYED_CHROME, getFolder("Chrome","typeaheadfind.jar"), "locale/en-US/typeaheadfind/"); if (getLastError() == SUCCESS) { diff --git a/extensions/typeaheadfind/jar.mn b/extensions/typeaheadfind/jar.mn index 12f1fc48da1..ce563e84d16 100644 --- a/extensions/typeaheadfind/jar.mn +++ b/extensions/typeaheadfind/jar.mn @@ -1,9 +1,3 @@ -en-win.jar: - locale/en-US/global-platform/typeaheadfind.properties - -en-unix.jar: - locale/en-US/global-platform/typeaheadfind.properties - -en-mac.jar: - locale/en-US/global-platform/typeaheadfind.properties - +typeaheadfind.jar: + locale/en-US/typeaheadfind/contents.rdf (resources/locale/en-US/contents.rdf) + locale/en-US/typeaheadfind/typeaheadfind.properties (resources/locale/en-US/typeaheadfind.properties) diff --git a/extensions/typeaheadfind/makefile.win b/extensions/typeaheadfind/makefile.win index c88b9c5eeca..5f5936194ad 100644 --- a/extensions/typeaheadfind/makefile.win +++ b/extensions/typeaheadfind/makefile.win @@ -80,3 +80,6 @@ LINCS=\ include <$(DEPTH)\config\rules.mak> +libs:: + $(MAKE_INSTALL) resources\content\prefs\typeaheadfind.js $(DIST)\bin\defaults\pref + diff --git a/extensions/typeaheadfind/nsTypeAheadFind.cpp b/extensions/typeaheadfind/nsTypeAheadFind.cpp index de6c0326114..6a54dca6c29 100644 --- a/extensions/typeaheadfind/nsTypeAheadFind.cpp +++ b/extensions/typeaheadfind/nsTypeAheadFind.cpp @@ -137,15 +137,17 @@ nsTypeAheadFind::nsTypeAheadFind(): nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); if (mFind && prefs) { AddRef(); - // ----------- Listen to prefs - prefs->RegisterCallback("accessibility.typeaheadfind", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); - prefs->RegisterCallback("accessibility.typeaheadfind.linksonly", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); - prefs->RegisterCallback("accessibility.typeaheadfind.timeout", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); - prefs->RegisterCallback("accessibility.browsewithcaret", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); // ----------- Set search options --------------- mFind->SetFindBackwards(PR_FALSE); mFind->SetCaseSensitive(PR_FALSE); mFind->SetWordBreaker(nsnull); + + // ----------- Get initial preferences ---------- + nsTypeAheadFind::TypeAheadFindPrefsReset("", NS_STATIC_CAST(void*, this)); + + // ----------- Listen to prefs ------------------ + prefs->RegisterCallback("accessibility.typeaheadfind", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefsReset, NS_STATIC_CAST(void*, this)); + prefs->RegisterCallback("accessibility.browsewithcaret", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefsReset, NS_STATIC_CAST(void*, this)); } } @@ -159,10 +161,8 @@ nsTypeAheadFind::~nsTypeAheadFind() nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); if (prefs) { - prefs->UnregisterCallback("accessibility.typeaheadfind", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); - prefs->UnregisterCallback("accessibility.typeaheadfind.linksonly", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); - prefs->UnregisterCallback("accessibility.typeaheadfind.timeout", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); - prefs->UnregisterCallback("accessibility.browsewithcaret", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefCallback, (void*)this); + prefs->UnregisterCallback("accessibility.typeaheadfind", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefsReset, (void*)this); + prefs->UnregisterCallback("accessibility.browsewithcaret", (PrefChangedFunc)nsTypeAheadFind::TypeAheadFindPrefsReset, (void*)this); } } @@ -184,18 +184,20 @@ void nsTypeAheadFind::ReleaseInstance() // ------- Pref Callbacks (2) --------------- -int PR_CALLBACK nsTypeAheadFind::TypeAheadFindPrefCallback(const char* aPrefName, void* instance_data) +int PR_CALLBACK nsTypeAheadFind::TypeAheadFindPrefsReset(const char* aPrefName, void* instance_data) { nsTypeAheadFind* typeAheadFind= NS_STATIC_CAST(nsTypeAheadFind*, instance_data); NS_ASSERTION(typeAheadFind, "bad instance data"); nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); + if (!prefs) + return 0; - if (!nsCRT::strcasecmp(aPrefName,"accessibility.typeaheadfind")) { + PRBool wasTypeAheadOn = typeAheadFind->mIsTypeAheadOn; + prefs->GetBoolPref("accessibility.typeaheadfind", &typeAheadFind->mIsTypeAheadOn); + if (typeAheadFind->mIsTypeAheadOn != wasTypeAheadOn) { nsCOMPtr progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID)); if (progress) { - PRBool wasTypeAheadOn = typeAheadFind->mIsTypeAheadOn; - prefs->GetBoolPref("accessibility.typeaheadfind", &typeAheadFind->mIsTypeAheadOn); if (!typeAheadFind->mIsTypeAheadOn) { typeAheadFind->RemoveCurrentSelectionListener(); typeAheadFind->RemoveCurrentScrollPositionListener(); @@ -203,7 +205,7 @@ int PR_CALLBACK nsTypeAheadFind::TypeAheadFindPrefCallback(const char* aPrefName typeAheadFind->RemoveCurrentWindowFocusListener(); progress->RemoveProgressListener(NS_STATIC_CAST(nsIWebProgressListener*, typeAheadFind)); } - else if (typeAheadFind->mIsTypeAheadOn != wasTypeAheadOn) { + else { progress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*, typeAheadFind), nsIWebProgress::NOTIFY_STATE_DOCUMENT); // Initialize string bundle nsCOMPtr stringBundleService(do_GetService(kStringBundleServiceCID)); @@ -212,12 +214,9 @@ int PR_CALLBACK nsTypeAheadFind::TypeAheadFindPrefCallback(const char* aPrefName } } } - if (!nsCRT::strcasecmp(aPrefName,"accessibility.typeaheadfind.linksonly")) - prefs->GetBoolPref("accessibility.typeaheadfind.linksonly", &typeAheadFind->mLinksOnlyPref); - if (!nsCRT::strcasecmp(aPrefName,"accessibility.typeaheadfind.timeout")) - prefs->GetIntPref("accessibility.typeaheadfind.timeout", &typeAheadFind->mTimeoutLength); - if (!nsCRT::strcasecmp(aPrefName,"accessibility.browsewithcaret")) - prefs->GetBoolPref("accessibility.browsewithcaret", &typeAheadFind->mCaretBrowsingOn); + prefs->GetBoolPref("accessibility.typeaheadfind.linksonly", &typeAheadFind->mLinksOnlyPref); + prefs->GetIntPref("accessibility.typeaheadfind.timeout", &typeAheadFind->mTimeoutLength); + prefs->GetBoolPref("accessibility.browsewithcaret", &typeAheadFind->mCaretBrowsingOn); return 0; // PREF_OK } diff --git a/extensions/typeaheadfind/nsTypeAheadFind.h b/extensions/typeaheadfind/nsTypeAheadFind.h index bfc6a7bd572..03aecab7e0a 100644 --- a/extensions/typeaheadfind/nsTypeAheadFind.h +++ b/extensions/typeaheadfind/nsTypeAheadFind.h @@ -60,7 +60,7 @@ #include "nsITypeAheadFind.h" #include "nsIStringBundle.h" -#define TYPEAHEADFIND_BUNDLE_URL "chrome://global-platform/locale/typeaheadfind.properties" +#define TYPEAHEADFIND_BUNDLE_URL "chrome://typeaheadfind/locale/typeaheadfind.properties" class nsTypeAheadFind : public nsIDOMFocusListener, public nsIDOMKeyListener, @@ -112,7 +112,7 @@ public: static void ReleaseInstance(void); protected: - static int PR_CALLBACK TypeAheadFindPrefCallback(const char* aPrefName, void* instance_data); + static int PR_CALLBACK TypeAheadFindPrefsReset(const char* aPrefName, void* instance_data); // Helper methods void AttachNewSelectionListener(); diff --git a/extensions/typeaheadfind/resources/content/prefs/MANIFEST b/extensions/typeaheadfind/resources/content/prefs/MANIFEST new file mode 100644 index 00000000000..e69de29bb2d diff --git a/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js b/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js new file mode 100644 index 00000000000..6013d4703dd --- /dev/null +++ b/extensions/typeaheadfind/resources/content/prefs/typeaheadfind.js @@ -0,0 +1,41 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2001 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Aaron Leventhal (original author) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +pref("accessibility.typeaheadfind", true); +pref("accessibility.typeaheadfind.linksonly", true); +pref("accessibility.typeaheadfind.timeout", 2500); diff --git a/extensions/typeaheadfind/resources/locale/en-US/contents.rdf b/extensions/typeaheadfind/resources/locale/en-US/contents.rdf new file mode 100644 index 00000000000..ad5ce3f72cd --- /dev/null +++ b/extensions/typeaheadfind/resources/locale/en-US/contents.rdf @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties b/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties new file mode 100644 index 00000000000..33b193d4b83 --- /dev/null +++ b/extensions/typeaheadfind/resources/locale/en-US/typeaheadfind.properties @@ -0,0 +1,6 @@ +textfound = Text found: " +textnotfound = Text not found: " +linkfound = Link found: " +linknotfound = Link not found: " +closequote = " +stopfind = Type ahead find stopped.