mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 16:17:59 +01:00
Warn user when changing a pref that theyve changed. Dont open 14 error consoles when we break a module.
This commit is contained in:
@@ -64,6 +64,7 @@ const liberator = (function () //{{{
|
||||
observers.push([type, callback]);
|
||||
}
|
||||
|
||||
let nError = 0;
|
||||
function loadModule(name, func)
|
||||
{
|
||||
var message = "Loading module " + name + "...";
|
||||
@@ -76,7 +77,8 @@ const liberator = (function () //{{{
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
window.toJavaScriptConsole();
|
||||
if (nError++ == 0)
|
||||
window.toJavaScriptConsole();
|
||||
liberator.reportError(e);
|
||||
}
|
||||
}
|
||||
@@ -120,7 +122,7 @@ const liberator = (function () //{{{
|
||||
styles.addSheet("scrollbar", "*", class.join(", ") + " { visibility: collapse !important; }", true, true);
|
||||
else
|
||||
styles.removeSheet("scrollbar", null, null, null, true);
|
||||
options.setPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2);
|
||||
options.safeSetPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2);
|
||||
},
|
||||
validator: function (opts) (opts.indexOf("l") < 0 || opts.indexOf("r") < 0)
|
||||
},
|
||||
@@ -178,7 +180,7 @@ const liberator = (function () //{{{
|
||||
{
|
||||
setter: function (value)
|
||||
{
|
||||
options.setPref("accessibility.typeaheadfind.enablesound", !value);
|
||||
options.safeSetPref("accessibility.typeaheadfind.enablesound", !value);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
@@ -1122,6 +1124,7 @@ const liberator = (function () //{{{
|
||||
// quit liberator, no matter how many tabs/windows are open
|
||||
quit: function (saveSession, force)
|
||||
{
|
||||
// TODO: Use safeSetPref?
|
||||
if (saveSession)
|
||||
options.setPref("browser.startup.page", 3); // start with saved session
|
||||
else
|
||||
|
||||
@@ -299,8 +299,10 @@ function Options() //{{{
|
||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
const SAVED = "liberator.saved.";
|
||||
|
||||
const prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
var optionHash = {};
|
||||
|
||||
function optionObserver(key, event, option)
|
||||
@@ -382,32 +384,6 @@ function Options() //{{{
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// firefox preferences which need to be changed to work well with vimperator
|
||||
//
|
||||
|
||||
// work around firefox popup blocker
|
||||
var popupAllowedEvents = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
|
||||
if (!/keypress/.test(popupAllowedEvents))
|
||||
{
|
||||
storePreference("dom.popup_allowed_events", popupAllowedEvents + " keypress");
|
||||
liberator.registerObserver("shutdown", function ()
|
||||
{
|
||||
if (loadPreference("dom.popup_allowed_events", "")
|
||||
== popupAllowedEvents + " keypress")
|
||||
storePreference("dom.popup_allowed_events", popupAllowedEvents);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: maybe reset in .destroy()?
|
||||
// TODO: move to vim.js or buffer.js
|
||||
// we have our own typeahead find implementation
|
||||
storePreference("accessibility.typeaheadfind.autostart", false);
|
||||
storePreference("accessibility.typeaheadfind", false); // actually the above setting should do it, but has no effect in firefox
|
||||
|
||||
// start with saved session
|
||||
storePreference("browser.startup.page", 3);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
@@ -789,14 +765,14 @@ function Options() //{{{
|
||||
liberator.registerObserver("load_completion", function ()
|
||||
{
|
||||
completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]);
|
||||
completion.setFunctionCompleter([options.getPref, options.setPref, options.resetPref, options.invertPref],
|
||||
completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref],
|
||||
[function () Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch)
|
||||
.getChildList("", { value: 0 })
|
||||
.map(function (pref) [pref, ""])]);
|
||||
});
|
||||
|
||||
return {
|
||||
let options = {
|
||||
|
||||
OPTION_SCOPE_GLOBAL: 1,
|
||||
OPTION_SCOPE_LOCAL: 2,
|
||||
@@ -972,6 +948,19 @@ function Options() //{{{
|
||||
return loadPreference(name, forcedDefault);
|
||||
},
|
||||
|
||||
// Set a pref, but warn the user if it's changed from its default
|
||||
// value.
|
||||
safeSetPref: function (name, value)
|
||||
{
|
||||
let val = loadPreference(name, null, false);
|
||||
let def = loadPreference(name, null, true);
|
||||
let lib = loadPreference(SAVED + name);
|
||||
if (lib == null && val != def || val != lib)
|
||||
liberator.echomsg("Warning: setting preference " + name + ", but it's changed from its default value.");
|
||||
storePreference(name, value);
|
||||
storePreference(SAVED + name, value);
|
||||
},
|
||||
|
||||
setPref: function (name, value)
|
||||
{
|
||||
return storePreference(name, value);
|
||||
@@ -991,6 +980,38 @@ function Options() //{{{
|
||||
liberator.echoerr("E488: Trailing characters: " + name + "!");
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// firefox preferences which need to be changed to work well with vimperator
|
||||
//
|
||||
|
||||
// work around firefox popup blocker
|
||||
// TODO: Make this work like safeSetPref
|
||||
var popupAllowedEvents = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
|
||||
if (!/keypress/.test(popupAllowedEvents))
|
||||
{
|
||||
storePreference("dom.popup_allowed_events", popupAllowedEvents + " keypress");
|
||||
liberator.registerObserver("shutdown", function ()
|
||||
{
|
||||
if (loadPreference("dom.popup_allowed_events", "")
|
||||
== popupAllowedEvents + " keypress")
|
||||
storePreference("dom.popup_allowed_events", popupAllowedEvents);
|
||||
});
|
||||
}
|
||||
|
||||
// safeSetPref might try to echomsg. Need commandline.
|
||||
liberator.registerObserver("load_commandline", function () {
|
||||
// TODO: maybe reset in .destroy()?
|
||||
// TODO: move to vim.js or buffer.js
|
||||
// we have our own typeahead find implementation
|
||||
options.safeSetPref("accessibility.typeaheadfind.autostart", false);
|
||||
options.safeSetPref("accessibility.typeaheadfind", false); // actually the above setting should do it, but has no effect in firefox
|
||||
});
|
||||
|
||||
// start with saved session
|
||||
storePreference("browser.startup.page", 3);
|
||||
|
||||
return options;
|
||||
//}}}
|
||||
}; //}}}
|
||||
|
||||
|
||||
@@ -133,9 +133,9 @@ function Tabs() //{{{
|
||||
else
|
||||
{
|
||||
let pref = "browser.tabStrip.autoHide";
|
||||
if (options.getPref(pref) == null)
|
||||
if (options.getPref(pref) == null) // Try for FF 3.0 & 3.1
|
||||
pref = "browser.tabs.autoHide";
|
||||
options.setPref(pref, value == 1);
|
||||
options.safeSetPref(pref, value == 1);
|
||||
tabStrip.collapsed = false;
|
||||
}
|
||||
|
||||
@@ -200,8 +200,8 @@ function Tabs() //{{{
|
||||
[1, 2], // always in new window
|
||||
[2, 1]];// current tab unless it has specified sizes
|
||||
|
||||
options.setPref("browser.link.open_newwindow.restriction", values[value][0]);
|
||||
options.setPref("browser.link.open_newwindow", values[value][1]);
|
||||
options.safeSetPref("browser.link.open_newwindow.restriction", values[value][0]);
|
||||
options.safeSetPref("browser.link.open_newwindow", values[value][1]);
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user