gecko-dev/suite/common/pref/pref-navigator.js

60 lines
2.2 KiB
JavaScript
Raw Normal View History

/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
*/
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
const nsIPrefService = Components.interfaces.nsIPrefService;
const nsIPrefLocalizedString = Components.interfaces.nsIPrefLocalizedString;
const FILEPICKER_CONTRACTID = "@mozilla.org/filepicker;1";
const WINDOWMEDIATOR_CONTRACTID = "@mozilla.org/appshell/window-mediator;1";
const PREFSERVICE_CONTRACTID = "@mozilla.org/preferences-service;1";
2006-05-17 02:24:52 +00:00
function selectFile()
2006-05-17 02:24:52 +00:00
{
var fp = Components.classes[FILEPICKER_CONTRACTID]
.createInstance(nsIFilePicker);
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
var title = prefutilitiesBundle.getString("choosehomepage");
fp.init(window, title, nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText |
nsIFilePicker.filterXML | nsIFilePicker.filterHTML |
nsIFilePicker.filterImages);
var ret = fp.show();
if (ret == nsIFilePicker.returnOK) {
var folderField = document.getElementById("browserStartupHomepage");
folderField.value = fp.fileURL.spec;
}
2006-05-17 02:24:52 +00:00
}
function setHomePageToCurrentPage()
2006-05-17 02:24:52 +00:00
{
var windowManager = Components.classes[WINDOWMEDIATOR_CONTRACTID]
.getService(nsIWindowMediator);
var browserWindow = windowManager.getMostRecentWindow("navigator:browser");
if (browserWindow) {
var browser = browserWindow.document.getElementById("content");
var url = browser.webNavigation.currentURI.spec;
if (url) {
var homePageField = document.getElementById("browserStartupHomepage");
homePageField.value = url;
}
}
2006-05-17 02:24:52 +00:00
}
function setHomePageToDefaultPage()
{
var prefService = Components.classes[PREFSERVICE_CONTRACTID]
.getService(nsIPrefService);
var pref = prefService.getDefaultBranch(null);
var url = pref.getComplexValue("browser.startup.homepage",
nsIPrefLocalizedString).data;
var homePageField = document.getElementById("browserStartupHomepage");
homePageField.value = url;
}