Bug 118835: add support for home page groups. r=law, sr=hewitt

This commit is contained in:
jaggernaut%netscape.com 2002-10-04 00:28:07 +00:00
Родитель f2acbeccf8
Коммит ce4d8afc85
7 изменённых файлов: 301 добавлений и 75 удалений

Просмотреть файл

@ -64,6 +64,7 @@ pref("backups.number_of_prefs_copies", 1);
// 0 = blank, 1 = home (browser.startup.homepage), 2 = last
pref("browser.startup.page", 1);
pref("browser.startup.homepage", "chrome://navigator-region/locale/region.properties");
pref("browser.startup.homepage.count", 1);
// "browser.startup.homepage_override" was for 4.x
pref("browser.startup.homepage_override.1", true);
pref("browser.startup.autoload_homepage", true);

Просмотреть файл

@ -124,9 +124,7 @@ const gHomepagePrefListener =
if (topic != "nsPref:changed")
return;
var homePage = getHomePage();
if (homePage)
setTooltipText("home-button", homePage);
updateHomeButtonTooltip();
}
};
@ -227,6 +225,22 @@ function contentAreaFrameFocus()
}
}
function updateHomeButtonTooltip()
{
const XUL_NAMESPACE = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var homePage = getHomePage();
var tooltip = document.getElementById("home-button-tooltip-inner");
while (tooltip.firstChild)
tooltip.removeChild(tooltip.firstChild);
for (var i in homePage) {
var label = document.createElementNS(XUL_NAMESPACE, "label");
label.setAttribute("value", homePage[i]);
tooltip.appendChild(label);
}
}
//////////////////////////////// BOOKMARKS ////////////////////////////////////
function UpdateBookmarksLastVisitedDate(event)
@ -290,18 +304,19 @@ function getBrowser()
function getHomePage()
{
var url;
var URIs = [];
try {
url = pref.getComplexValue("browser.startup.homepage",
Components.interfaces.nsIPrefLocalizedString).data;
} catch (e) {
URIs[0] = pref.getComplexValue("browser.startup.homepage",
Components.interfaces.nsIPrefLocalizedString).data;
var count = pref.getIntPref("browser.startup.homepage.count");
for (var i = 1; i < count; ++i) {
URIs[i] = pref.getComplexValue("browser.startup.homepage."+i,
Components.interfaces.nsIPrefLocalizedString).data;
}
} catch(e) {
}
// use this if we can't find the pref
if (!url)
url = gNavigatorRegionBundle.getString("homePageDefault");
return url;
return URIs;
}
function UpdateBackForwardButtons()
@ -401,9 +416,7 @@ function Startup()
// Do all UI building here:
// set home button tooltip text
var homePage = getHomePage();
if (homePage)
document.getElementById("home-button").setAttribute("tooltiptext", homePage);
updateHomeButtonTooltip();
// initialize observers and listeners
window.XULBrowserWindow = new nsBrowserStatusHandler();
@ -483,8 +496,12 @@ function Startup()
var uriToLoad;
// Check for window.arguments[0]. If present, use that for uriToLoad.
if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0])
uriToLoad = window.arguments[0];
if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
var uriArray = window.arguments[0].split('\n');
uriToLoad = uriArray.splice(0, 1);
if (uriArray.length > 0)
window.setTimeout(function(arg) { for (var i in arg) gBrowser.addTab(arg[i]); }, 0, uriArray);
}
if (uriToLoad && uriToLoad != "about:blank") {
gURLBar.value = uriToLoad;
@ -701,7 +718,12 @@ function BrowserReloadSkipCache()
function BrowserHome()
{
var homePage = getHomePage();
loadURI(homePage);
if (homePage.length == 1) {
loadURI(homePage[0]);
} else {
for (var i in homePage)
gBrowser.addTab(homePage[i]);
}
}
function OpenBookmarkGroup(element, datasource)

Просмотреть файл

@ -245,9 +245,13 @@ Contributor(s):
ondragexit="nsDragAndDrop.dragExit(event, personalToolbarDNDObserver); event.preventBubble()"
ondragover="nsDragAndDrop.dragOver(event, personalToolbarDNDObserver); event.preventBubble()">
<tooltip id="home-button-tooltip" noautohide="true">
<vbox id="home-button-tooltip-inner" flex="1"/>
</tooltip>
<toolbarbutton id="home-button" class="bookmark-item"
label="&homeButton.label;" persist="hidden"
oncommand="BrowserHome(); event.preventBubble()"
tooltip="home-button-tooltip"
ondraggesture="nsDragAndDrop.startDrag(event, homeButtonObserver)"
ondragdrop="nsDragAndDrop.drop(event, homeButtonObserver); event.preventBubble()"
ondragenter="event.preventBubble()"

Просмотреть файл

@ -719,6 +719,43 @@ PRBool nsBrowserContentHandler::NeedHomepageOverride(nsIPref *aPrefService)
return PR_FALSE;
}
nsresult GetHomePageGroup(nsIPref* aPref, PRUnichar** aResult)
{
nsresult rv;
nsXPIDLString uri;
rv = aPref->GetLocalizedUnicharPref(PREF_BROWSER_STARTUP_HOMEPAGE, getter_Copies(uri));
if (NS_FAILED(rv))
return rv;
PRInt32 count = 0;
rv = aPref->GetIntPref("browser.startup.homepage.count", &count);
// if we couldn't get the pref (unlikely) or only have one homepage
if (NS_FAILED(rv) || count <= 1) {
*aResult = ToNewUnicode(uri);
return NS_OK;
}
// The "homepage" is a group of pages, put them in uriList separated by '\n'
nsAutoString uriList(uri);
for (PRInt32 i = 1; i < count; ++i) {
nsCAutoString pref(NS_LITERAL_CSTRING("browser.startup.homepage."));
pref.AppendInt(i);
rv = aPref->GetLocalizedUnicharPref(pref.get(), getter_Copies(uri));
if (NS_FAILED(rv))
return rv;
uriList.Append(PRUnichar('\n'));
uriList.Append(uri);
}
*aResult = ToNewUnicode(uriList);
return NS_OK;
}
NS_IMETHODIMP nsBrowserContentHandler::GetDefaultArgs(PRUnichar **aDefaultArgs)
{
if (!aDefaultArgs)
@ -769,10 +806,8 @@ NS_IMETHODIMP nsBrowserContentHandler::GetDefaultArgs(PRUnichar **aDefaultArgs)
if (NS_SUCCEEDED(rv)) {
switch (choice) {
case 1: {
nsXPIDLString url;
rv = prefs->GetLocalizedUnicharPref(PREF_BROWSER_STARTUP_HOMEPAGE, getter_Copies(url));
args = url;
break;
// skip the code below
return GetHomePageGroup(prefs, aDefaultArgs);
}
case 2: {
nsCOMPtr<nsIBrowserHistory> history(do_GetService(kCGlobalHistoryCID));

Просмотреть файл

@ -49,6 +49,120 @@ const WINDOWMEDIATOR_CONTRACTID = "@mozilla.org/appshell/window-mediator;1";
const PREFSERVICE_CONTRACTID = "@mozilla.org/preferences-service;1";
var gDefaultPage;
var gData;
function setHomePageValue(value)
{
var homePageField = document.getElementById("browserStartupHomepage");
homePageField.value = value;
}
function getGroupIsSetMessage()
{
var prefUtilitiesBundle = document.getElementById("bundle_prefutilities");
return prefUtilitiesBundle.getString("groupIsSet");
}
function getMostRecentBrowser()
{
var windowManager = Components.classes[WINDOWMEDIATOR_CONTRACTID]
.getService(nsIWindowMediator);
var browserWindow = windowManager.getMostRecentWindow("navigator:browser");
if (browserWindow)
return browserWindow.document.getElementById("content");
return null;
}
function getCurrentPage()
{
var url;
var tabbrowser = getMostRecentBrowser();
if (tabbrowser)
url = tabbrowser.currentURI.spec;
return url;
}
function getCurrentPageGroup()
{
var URIs = [];
var tabbrowser = getMostRecentBrowser();
if (tabbrowser) {
var browsers = tabbrowser.browsers;
for (var i = 0; i < browsers.length; ++i)
URIs[i] = browsers[i].currentURI.spec;
}
return URIs;
}
function getDefaultPage()
{
var prefService = Components.classes[PREFSERVICE_CONTRACTID]
.getService(nsIPrefService);
var pref = prefService.getDefaultBranch(null);
return pref.getComplexValue("browser.startup.homepage",
nsIPrefLocalizedString).data;
}
function updateHomePageButtons()
{
var homepage = document.getElementById("browserStartupHomepage").value;
// disable the "current page" button if the current page
// is already the homepage
var currentPageButton = document.getElementById("browserUseCurrent");
currentPageButton.disabled = homepage == getCurrentPage();
// disable the "default page" button if the default page
// is already the homepage
var defaultPageButton = document.getElementById("browserUseDefault");
defaultPageButton.disabled = (homepage == gDefaultPage);
// homePages.length == 1 if:
// - we're called from startup and there's one homepage
// - we're called from "current page" or "choose file"
// - the user typed something in the location field
// in those cases we only want to enable the button if:
// - there's more than one tab in the most recent browser
// otherwise we have a group of homepages:
// - we're called from startup and there's a group of homepages
// - we're called from "current group"
// in those cases we only want to enable the button if:
// - there's more than one tab in the most recent browser and
// the current group doesn't match the group of homepages
var enabled = false;
var homePages = gData.navigatorData.homePages;
if (homePages.length == 1) {
var browser = getMostRecentBrowser();
enabled = browser && browser.browsers.length > 1;
} else {
var currentURIs = getCurrentPageGroup();
if (currentURIs.length == homePages.length) {
for (var i = 0; !enabled && i < homePages.length; ++i) {
if (homePages[i] != currentURIs[i])
enabled = true;
}
} else if (currentURIs.length > 1) {
enabled = true;
}
}
var currentPageGroupButton = document.getElementById("browserUseCurrentGroup");
currentPageGroupButton.disabled = !enabled;
}
function locationInputHandler()
{
var navigatorData = gData.navigatorData;
var homePage = document.getElementById("browserStartupHomepage");
navigatorData.homePages = [ homePage.value ];
updateHomePageButtons();
}
function selectFile()
{
@ -66,6 +180,10 @@ function selectFile()
if (ret == nsIFilePicker.returnOK) {
var folderField = document.getElementById("browserStartupHomepage");
folderField.value = fp.fileURL.spec;
var url = fp.fileURL.spec;
setHomePageValue(url);
gData.navigatorData.homePages = [ url ];
updateHomePageButtons();
}
}
@ -73,62 +191,105 @@ function setHomePageToCurrentPage()
{
var url = getCurrentPage();
if (url) {
var homePageField = document.getElementById("browserStartupHomepage");
homePageField.value = url;
setHomePageValue(url);
gData.navigatorData.homePages = [ url ];
updateHomePageButtons();
}
}
function setHomePageToCurrentGroup()
{
var URIs = getCurrentPageGroup();
if (URIs.length > 0) {
setHomePageValue(gData.navigatorData.groupIsSet);
gData.navigatorData.homePages = URIs;
updateHomePageButtons();
}
updateHomePageButtons();
}
function setHomePageToDefaultPage()
{
var homePageField = document.getElementById("browserStartupHomepage");
homePageField.value = gDefaultPage;
setHomePageValue(gDefaultPage);
gData.navigatorData.homePages = [ gDefaultPage ];
updateHomePageButtons();
}
function getCurrentPage()
function init()
{
var windowManager = Components.classes[WINDOWMEDIATOR_CONTRACTID]
.getService(nsIWindowMediator);
var browser, url;
var browserWindow = windowManager.getMostRecentWindow("navigator:browser");
if (browserWindow) {
browser = browserWindow.document.getElementById("content");
if (browser) {
url = browser.webNavigation.currentURI.spec;
var prefWindow = parent.hPrefWindow;
gData = prefWindow.wsm.dataManager
.pageData["chrome://communicator/content/pref/pref-navigator.xul"]
gDefaultPage = getDefaultPage();
if ("navigatorData" in gData)
return;
var navigatorData = {};
navigatorData.groupIsSet = getGroupIsSetMessage();
var URIs = [];
try {
URIs[0] = prefWindow.getPref("localizedstring",
"browser.startup.homepage");
var count = prefWindow.getPref("int",
"browser.startup.homepage.count");
for (var i = 1; i < count; ++i) {
URIs[i] = prefWindow.getPref("localizedstring",
"browser.startup.homepage."+i);
}
navigatorData.homePages = URIs;
} catch(e) {
}
return url;
}
gData.navigatorData = navigatorData;
function getDefaultPage()
{
var prefService = Components.classes[PREFSERVICE_CONTRACTID]
.getService(nsIPrefService);
var pref = prefService.getDefaultBranch(null);
return pref.getComplexValue("browser.startup.homepage",
nsIPrefLocalizedString).data;
}
function locationInputHandler()
{
updateHomePageButtons();
prefWindow.registerOKCallbackFunc(doOnOk);
}
function Startup()
{
init();
var navigatorData = gData.navigatorData;
var homePages = navigatorData.homePages;
if (homePages.length == 1)
setHomePageValue(homePages[0]);
else
setHomePageValue(navigatorData.groupIsSet);
updateHomePageButtons();
gDefaultPage = getDefaultPage();
}
function updateHomePageButtons()
function doOnOk()
{
var homepage = document.getElementById("browserStartupHomepage").value;
var currentPageButton = document.getElementById("browserUseCurrent");
var defaultPageButton = document.getElementById("browserUseDefault");
currentPageButton.disabled = (homepage == getCurrentPage());
defaultPageButton.disabled = (homepage == gDefaultPage);
var prefWindow = parent.hPrefWindow;
// OK could have been hit from another panel, so we need to
// get at navigatorData the long but safer way
var navigatorData = prefWindow.wsm.dataManager
.pageData["chrome://communicator/content/pref/pref-navigator.xul"]
.navigatorData;
var URIs = navigatorData.homePages;
prefWindow.setPref("string", "browser.startup.homepage", URIs[0]);
var i = 1;
for (; i < URIs.length; ++i)
prefWindow.setPref("string", "browser.startup.homepage."+i, URIs[i]);
const countPref = "browser.startup.homepage.count";
// remove the old user prefs values that we didn't overwrite
var oldCount = prefWindow.getPref("int", countPref);
for (; i < oldCount; ++i)
prefWindow.pref.ClearUserPref("browser.startup.homepage."+i);
prefWindow.setPref("int", countPref, URIs.length);
}

Просмотреть файл

@ -37,10 +37,9 @@
<script type="application/x-javascript">
<![CDATA[
var _elementIDs = ["startupPage", "browserStartupHomepage",
"bookmarksButton", "goButton",
"homeButton", "printButton",
"searchButton"];
var _elementIDs = ["startupPage", "bookmarksButton",
"goButton", "homeButton",
"printButton", "searchButton" ];
]]>
</script>
@ -66,19 +65,21 @@
<label value="&location.label;" accesskey="&location.accesskey;" control="browserStartupHomepage"/>
<textbox id="browserStartupHomepage" type="autocomplete" flex="1" class="uri-element"
searchSessions="history" timeout="50" maxrows="6"
oninput="locationInputHandler();" preftype="localizedstring"
prefstring="browser.startup.homepage"/> <!-- we may wish to change this to data
when we support fancy formatted local filenames -->
oninput="locationInputHandler();"/>
<button label="&browseFile.label;" accesskey="&browseFile.accesskey;"
oncommand="selectFile();"
id="browserChooseFile"
prefstring="pref.browser.homepage.disable_button.select_file"/>
</hbox>
<hbox align="center" pack="end">
<button label="&useCurrent.label;" accesskey="&useCurrent.accesskey;"
oncommand="setHomePageToCurrentPage();"
id="browserUseCurrent"
prefstring="pref.browser.homepage.disable_button.current_page"/>
<button label="&browseFile.label;" accesskey="&browseFile.accesskey;"
oncommand="selectFile();"
id="browserChooseFile"
prefstring="pref.browser.homepage.disable_button.select_file"/>
<button label="&useCurrentGroup.label;" accesskey="&useCurrentGroup.accesskey;"
oncommand="setHomePageToCurrentGroup();"
id="browserUseCurrentGroup"
prefstring="pref.browser.homepage.disable_button.current_group"/>
<button label="&useDefault.label;" accesskey="&useDefault.accesskey;"
oncommand="setHomePageToDefaultPage();"
id="browserUseDefault"

Просмотреть файл

@ -4,20 +4,22 @@
<!ENTITY blankPageRadio.label "Blank page">
<!ENTITY blankPageRadio.accesskey "n">
<!ENTITY homePageRadio.label "Home page">
<!ENTITY homePageRadio.accesskey "h">
<!ENTITY homePageRadio.accesskey "H">
<!ENTITY lastPageRadio.label "Last page visited">
<!ENTITY lastPageRadio.accesskey "l">
<!ENTITY lastPageRadio.accesskey "L">
<!ENTITY header2.label "Home Page">
<!ENTITY homePageIntro.label "Clicking the Home button takes you to this page.">
<!ENTITY homePageIntro.label "Clicking the Home button takes you to this page or group of pages.">
<!ENTITY location.label "Location:">
<!ENTITY location.accesskey "a">
<!ENTITY useCurrent.label "Use Current Page">
<!ENTITY useCurrent.accesskey "u">
<!ENTITY useCurrent.accesskey "U">
<!ENTITY useCurrentGroup.label "Use Current Group">
<!ENTITY useCurrentGroup.accesskey "G">
<!ENTITY browseFile.label "Choose File...">
<!ENTITY browseFile.accesskey "c">
<!ENTITY browseFile.accesskey "C">
<!ENTITY useDefault.label "Restore Default">
<!ENTITY useDefault.accesskey "r">
<!ENTITY useDefault.accesskey "R">
<!ENTITY toolbarIntro.label "Select the buttons you want to see in the toolbars">