diff --git a/xpfe/browser/src/navigator.js b/xpfe/browser/src/navigator.js index c9c69b692f93..10003ce5df22 100644 --- a/xpfe/browser/src/navigator.js +++ b/xpfe/browser/src/navigator.js @@ -665,8 +665,7 @@ { prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow); } - prefwindow.Init("navigator.js"); - prefwindow.ShowWindow(window); + prefwindow.showWindow("navigator.js", window, "chrome://pref/content/pref-appearance.xul"); } function BrowserViewSource() diff --git a/xpfe/components/prefwindow/public/nsIPrefWindow.idl b/xpfe/components/prefwindow/public/nsIPrefWindow.idl index a76026fc7257..a99aa881f16f 100644 --- a/xpfe/components/prefwindow/public/nsIPrefWindow.idl +++ b/xpfe/components/prefwindow/public/nsIPrefWindow.idl @@ -28,15 +28,14 @@ class nsIDOMWindow; [scriptable, uuid(55AF8384-E11E-11D2-915F-A053F05FF7BC)] interface nsIPrefWindow : nsISupports { - void Init(in wstring id); - void ShowWindow(in nsIDOMWindow currentFrontWin); + void showWindow(in wstring id, in nsIDOMWindow currentFrontWin, in wstring panelURL); - void ChangePanel(in wstring url); - void PanelLoaded(in nsIDOMWindow win); + void changePanel(in wstring url); // called by the pref-tree click handler + void panelLoaded(in nsIDOMWindow win); // callback notification. - void SavePrefs(); - void CancelPrefs(); - void SetSubstitutionVar(in unsigned long stringnum, in string val); + void savePrefs(); + void cancelPrefs(); + void setSubstitutionVar(in unsigned long stringnum, in string val); }; %{ C++ diff --git a/xpfe/components/prefwindow/resources/content/PrefsWindow.js b/xpfe/components/prefwindow/resources/content/PrefsWindow.js index bbfd75b6748a..f3e1ef109374 100644 --- a/xpfe/components/prefwindow/resources/content/PrefsWindow.js +++ b/xpfe/components/prefwindow/resources/content/PrefsWindow.js @@ -15,17 +15,6 @@ function StartUp(windowName) } if (prefwindow != null && windowName != "Top" && windowName != "Bottom") { - prefwindow.PanelLoaded(window); + prefwindow.panelLoaded(window); } } - -function DoSave() -{ - prefwindow.SavePrefs(); -} - -function DoCancel() -{ - prefwindow.CancelPrefs(); -} - diff --git a/xpfe/components/prefwindow/resources/content/PrefsWindow.xul b/xpfe/components/prefwindow/resources/content/PrefsWindow.xul index 32b92baedce9..311c37c3657f 100644 --- a/xpfe/components/prefwindow/resources/content/PrefsWindow.xul +++ b/xpfe/components/prefwindow/resources/content/PrefsWindow.xul @@ -30,8 +30,8 @@ - - + + diff --git a/xpfe/components/prefwindow/src/nsPrefWindow.cpp b/xpfe/components/prefwindow/src/nsPrefWindow.cpp index 438d709f23d5..380dbe90ede7 100644 --- a/xpfe/components/prefwindow/src/nsPrefWindow.cpp +++ b/xpfe/components/prefwindow/src/nsPrefWindow.cpp @@ -144,19 +144,32 @@ NS_IMPL_ISUPPORTS( nsPrefWindow, nsIPrefWindow::GetIID()) return (sPrefWindow != nsnull); } //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::Init(const PRUnichar* aID) +NS_IMETHODIMP nsPrefWindow::showWindow( + const PRUnichar *id, + nsIDOMWindow *currentFrontWin, + const PRUnichar* panelURL) // The ID is currently only used to display debugging text on the console. //---------------------------------------------------------------------------------------- { #ifdef NS_DEBUG - nsOutputConsoleStream stream; + nsOutputConsoleStream stream; char buf[512]; - stream << "Pref object initialized by " - << nsString(aID).ToCString(buf, sizeof(buf)) - << nsEndl; #endif - if (!mPrefs) + if (mPrefs) + { +#ifdef NS_DEBUG + stream << "Existing pref object reused by " + << nsString(id).ToCString(buf, sizeof(buf)) + << nsEndl; +#endif + } + else { +#ifdef NS_DEBUG + stream << "Pref object initialized by " + << nsString(id).ToCString(buf, sizeof(buf)) + << nsEndl; +#endif nsIPref* prefs = nsnull; nsresult rv = nsServiceManager::GetService( kPrefCID, nsIPref::GetIID(), (nsISupports**)&prefs); @@ -166,8 +179,42 @@ NS_IMETHODIMP nsPrefWindow::Init(const PRUnichar* aID) } if (!mPrefs) return NS_ERROR_FAILURE; - return NS_OK; -} // nsPrefWindow::Init() + + // (code adapted from nsToolkitCore::ShowModal. yeesh.) + if (mWindow) + return NS_OK; + nsIWebShellWindow* window = nsnull; + nsCOMPtr urlObj; + nsresult rv = NS_NewURL(getter_AddRefs(urlObj), "chrome://pref/content/"); + if (NS_FAILED(rv)) + return rv; + + NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) + return rv; + + nsIXULWindowCallbacks *cb = nsnull; + nsCOMPtr parent; + DOMWindowToWebShellWindow(currentFrontWin, &parent); + appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, window, + nsnull, cb, 504, 436); + if (window) + { + mWindow = window; + nsCOMPtr parentWindowWidgetThing; + nsresult gotParent + = parent ? parent->GetWidget(*getter_AddRefs(parentWindowWidgetThing)) : + NS_ERROR_FAILURE; + // Windows OS is the only one that needs the parent disabled, or cares + // arguably this should be done by the new window, within ShowModal... + if (NS_SUCCEEDED(gotParent)) + parentWindowWidgetThing->Enable(PR_FALSE); + window->ShowModal(); + if (NS_SUCCEEDED(gotParent)) + parentWindowWidgetThing->Enable(PR_TRUE); + } + return rv; +} // nsPrefWindow::showWindow() //---------------------------------------------------------------------------------------- static PRBool CheckAndStrip( @@ -566,47 +613,7 @@ nsresult nsPrefWindow::FinalizePrefWidgets() } // nsPrefWindow::FinalizePrefWidgets //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::ShowWindow(nsIDOMWindow* aCurrentFrontWin) -//---------------------------------------------------------------------------------------- -{ - // (code adapted from nsToolkitCore::ShowModal. yeesh.) - if (mWindow) - return NS_OK; - nsIWebShellWindow* window = nsnull; - nsCOMPtr urlObj; - nsresult rv = NS_NewURL(getter_AddRefs(urlObj), "chrome://pref/content/"); - if (NS_FAILED(rv)) - return rv; - - NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); - if (NS_FAILED(rv)) - return rv; - - nsIXULWindowCallbacks *cb = nsnull; - nsCOMPtr parent; - DOMWindowToWebShellWindow(aCurrentFrontWin, &parent); - appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, window, - nsnull, cb, 504, 436); - if (window) - { - mWindow = window; - nsCOMPtr parentWindowWidgetThing; - nsresult gotParent - = parent ? parent->GetWidget(*getter_AddRefs(parentWindowWidgetThing)) : - NS_ERROR_FAILURE; - // Windows OS is the only one that needs the parent disabled, or cares - // arguably this should be done by the new window, within ShowModal... - if (NS_SUCCEEDED(gotParent)) - parentWindowWidgetThing->Enable(PR_FALSE); - window->ShowModal(); - if (NS_SUCCEEDED(gotParent)) - parentWindowWidgetThing->Enable(PR_TRUE); - } - return rv; -} // nsPrefWindow::ShowWindow - -//---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::ChangePanel(const PRUnichar* aURL) +NS_IMETHODIMP nsPrefWindow::changePanel(const PRUnichar* aURL) // Start loading of a new prefs panel. //---------------------------------------------------------------------------------------- { @@ -630,7 +637,7 @@ NS_IMETHODIMP nsPrefWindow::ChangePanel(const PRUnichar* aURL) } //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::PanelLoaded(nsIDOMWindow* aWin) +NS_IMETHODIMP nsPrefWindow::panelLoaded(nsIDOMWindow* aWin) // Callback after loading of a new prefs panel. //---------------------------------------------------------------------------------------- { @@ -697,7 +704,7 @@ static nsresult Close(nsIDOMWindow*& dw) } //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::SavePrefs() +NS_IMETHODIMP nsPrefWindow::savePrefs() //---------------------------------------------------------------------------------------- { FinalizePrefWidgets(); @@ -714,7 +721,7 @@ NS_IMETHODIMP nsPrefWindow::SavePrefs() } // nsPrefWindow::SavePrefs //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::CancelPrefs() +NS_IMETHODIMP nsPrefWindow::cancelPrefs() //---------------------------------------------------------------------------------------- { // Do the prefs stuff... @@ -750,7 +757,7 @@ char* nsPrefWindow::GetSubstitution(nsString& formatstr) } // nsPrefWindow::GetSubstitution //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefWindow::SetSubstitutionVar( +NS_IMETHODIMP nsPrefWindow::setSubstitutionVar( PRUint32 aStringnum, const char* aVal) //---------------------------------------------------------------------------------------- diff --git a/xpfe/components/prefwindow/src/nsPrefWindow.h b/xpfe/components/prefwindow/src/nsPrefWindow.h index 72b01d51ef9e..cc44c2376ba2 100644 --- a/xpfe/components/prefwindow/src/nsPrefWindow.h +++ b/xpfe/components/prefwindow/src/nsPrefWindow.h @@ -30,13 +30,15 @@ class nsPrefWindow // NS_DECL_IAPPSHELLCOMPONENT // This class implements the nsIFindComponent interface functions. - NS_IMETHOD Init(const PRUnichar *id); - NS_IMETHOD ShowWindow(nsIDOMWindow *currentFrontWin); - NS_IMETHOD ChangePanel(const PRUnichar *url); - NS_IMETHOD PanelLoaded(nsIDOMWindow *win); - NS_IMETHOD SavePrefs(); - NS_IMETHOD CancelPrefs(); - NS_IMETHOD SetSubstitutionVar(PRUint32 stringnum, const char *val); + NS_IMETHOD showWindow( + const PRUnichar *id, + nsIDOMWindow *currentFrontWin, + const PRUnichar* panelURL); + NS_IMETHOD changePanel(const PRUnichar *url); + NS_IMETHOD panelLoaded(nsIDOMWindow *win); + NS_IMETHOD savePrefs(); + NS_IMETHOD cancelPrefs(); + NS_IMETHOD setSubstitutionVar(PRUint32 stringnum, const char *val); enum TypeOfPref {