1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 18:27:58 +01:00

made initial setting of gui options faster

This commit is contained in:
Martin Stubenschrott
2007-10-22 12:41:14 +00:00
parent 93bd4513cb
commit 265f7e042f
4 changed files with 54 additions and 12 deletions

3
NEWS
View File

@@ -2,6 +2,9 @@
2007-xx-xx: 2007-xx-xx:
* version 0.6 * version 0.6
* THIS VERSION ONLY WORKS WITH FIREFOX 3.0 * THIS VERSION ONLY WORKS WITH FIREFOX 3.0
* IMPORTANT! options are no longer automatically stored - use the
~/.vimperatorrc file instead for persistent options
* added new :mkvimperatorrc command
* you can edit textfields with Ctrl-i now using an external editor (thanks to Joseph Xu) * you can edit textfields with Ctrl-i now using an external editor (thanks to Joseph Xu)
* :open, :bmarks, etc. filter on space separated tokens now, so you can * :open, :bmarks, etc. filter on space separated tokens now, so you can
search with :open linux windows <tab> all your bookmarks/history search with :open linux windows <tab> all your bookmarks/history

View File

@@ -1230,6 +1230,7 @@ vimperator.Commands = function() //{{{
for (var option in vimperator.options) for (var option in vimperator.options)
{ {
// TODO: options should be queried for this info // TODO: options should be queried for this info
// TODO: string/list options might need escaping in future
if (!/fullscreen|usermode/.test(option.name) && option.value != option.default_value) if (!/fullscreen|usermode/.test(option.name) && option.value != option.default_value)
{ {
if (option.type == "boolean") if (option.type == "boolean")
@@ -1248,7 +1249,7 @@ vimperator.Commands = function() //{{{
short_help: "Write current keymappings and changed options to [file]", short_help: "Write current keymappings and changed options to [file]",
help: "If no <code class=\"argument\">[file]</code> is specified then ~/.vimperatorrc is written unless this file already exists. " + help: "If no <code class=\"argument\">[file]</code> is specified then ~/.vimperatorrc is written unless this file already exists. " +
"The special version will overwrite <code class=\"argument\">[file]</code> if it exists.<br/>" + "The special version will overwrite <code class=\"argument\">[file]</code> if it exists.<br/>" +
"WARNING: this differs from Vim's behaviour which defaults to writing the file in the current directory." "WARNING: this differs from Vim's behavior which defaults to writing the file in the current directory."
} }
)); ));
addDefaultCommand(new vimperator.Command(["noh[lsearch]"], addDefaultCommand(new vimperator.Command(["noh[lsearch]"],
@@ -1577,17 +1578,16 @@ vimperator.Commands = function() //{{{
val = ""; val = "";
// reset a variable to its default value // reset a variable to its default value
// TODO: remove the value from about:config instead of setting it to the current default value
if (reset) if (reset)
{ {
if (all) if (all)
{ {
for (let opt in vimperator.options) for (let opt in vimperator.options)
opt.value = opt.default_value; opt.reset();
} }
else else
{ {
option.value = option.default_value; option.reset();
} }
} }
// read access // read access

View File

@@ -105,6 +105,11 @@ vimperator.Option = function(names, type, extra_info) //{{{
} }
return false; return false;
} }
this.reset = function()
{
this.value = this.default_value;
}
} //}}} } //}}}
vimperator.Options = function() //{{{ vimperator.Options = function() //{{{
@@ -112,12 +117,21 @@ vimperator.Options = function() //{{{
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var firefox_prefs = Components.classes["@mozilla.org/preferences-service;1"] var firefox_prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch); .getService(Components.interfaces.nsIPrefBranch);
var vimperator_prefs = firefox_prefs.getBranch("extensions.vimperator."); var vimperator_prefs = firefox_prefs.getBranch("extensions.vimperator.");
var options = []; var options = [];
// save if we already changed a GUI related option, used for setInitialGUI
var guioptions_done = false, showtabline_done = false, laststatus_done = false;
function addOption(option)
{
Options.prototype.__defineGetter__(option.name, function() { return option.value; });
Options.prototype.__defineSetter__(option.name, function(value) { option.value = value; });
options.push(option);
}
function optionsIterator() function optionsIterator()
{ {
for (var i = 0; i < options.length; i++) for (var i = 0; i < options.length; i++)
@@ -207,9 +221,11 @@ vimperator.Options = function() //{{{
// and bookmarks toolbar // and bookmarks toolbar
document.getElementById("PersonalToolbar").collapsed = value.indexOf("b") > -1 ? false : true; document.getElementById("PersonalToolbar").collapsed = value.indexOf("b") > -1 ? false : true;
document.getElementById("PersonalToolbar").hidden = value.indexOf("b") > -1 ? false : true; document.getElementById("PersonalToolbar").hidden = value.indexOf("b") > -1 ? false : true;
guioptions_done = true;
} }
function setStatusLine(value) function setLastStatus(value)
{ {
if (value == 0) if (value == 0)
{ {
@@ -225,6 +241,8 @@ vimperator.Options = function() //{{{
document.getElementById("status-bar").collapsed = false; document.getElementById("status-bar").collapsed = false;
document.getElementById("status-bar").hidden = false; document.getElementById("status-bar").hidden = false;
} }
laststatus_done = true;
} }
function setShowTabline(value) function setShowTabline(value)
@@ -247,6 +265,8 @@ vimperator.Options = function() //{{{
storePreference("browser.tabs.autoHide", false); storePreference("browser.tabs.autoHide", false);
tabs.collapsed = false; tabs.collapsed = false;
} }
showtabline_done = true;
} }
function setTitleString(value) function setTitleString(value)
@@ -361,6 +381,18 @@ vimperator.Options = function() //{{{
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
} }
// this hack is only needed, because we need to do asynchronous loading of the .vimperatorrc
this.setInitialGUI = function()
{
dump("initial GUI: ");// + guioptions_done + " - " + laststatus_done + " - " + tabline_done );
if (!guioptions_done)
this.get("guioptions").reset();
if (!laststatus_done)
this.get("laststatus").reset();
if (!showtabline_done)
this.get("showtabline").reset();
}
// TODO: separate Preferences from Options? Would these utility functions // TODO: separate Preferences from Options? Would these utility functions
// be better placed in the 'core' vimperator namespace somewhere? // be better placed in the 'core' vimperator namespace somewhere?
this.setPref = function(name, value) this.setPref = function(name, value)
@@ -546,7 +578,7 @@ vimperator.Options = function() //{{{
"</ul>" + "</ul>" +
"NOTE: laststatus=1 not implemented yet.", "NOTE: laststatus=1 not implemented yet.",
default_value: 2, default_value: 2,
setter: function(value) { setStatusLine(value); }, setter: function(value) { setLastStatus(value); },
validator: function (value) { if (value >= 0 && value <= 2) return true; else return false; } validator: function (value) { if (value >= 0 && value <= 2) return true; else return false; }
} }
)); ));
@@ -733,9 +765,13 @@ vimperator.Options = function() //{{{
)); ));
//}}} //}}}
setShowTabline(this.showtabline); // we start with an "empty" GUI so that no toolbars or tabbar is shown if the user
setGuiOptions(this.guioptions); // sets them to empty in the .vimperatorrc, which is sourced asynchronously
setStatusLine(this.laststatus); setShowTabline(0);
setGuiOptions("");
setLastStatus(0);
guioptions_done = showtabline_done = laststatus_done = false;
setTitleString(this.titlestring); setTitleString(this.titlestring);
setPopups(this.popups); setPopups(this.popups);
} //}}} } //}}}

View File

@@ -645,11 +645,9 @@ const vimperator = (function() //{{{
vimperator.log("No user RC file found", 3); vimperator.log("No user RC file found", 3);
// also source plugins in ~/.vimperator/plugin/ // also source plugins in ~/.vimperator/plugin/
var entries = [];
try try
{ {
var plugin_dir = vimperator.io.getPluginDir(); var plugin_dir = vimperator.io.getPluginDir();
if (plugin_dir) if (plugin_dir)
{ {
var files = vimperator.io.readDirectory(plugin_dir.path); var files = vimperator.io.readDirectory(plugin_dir.path);
@@ -669,6 +667,11 @@ const vimperator = (function() //{{{
// thrown if directory does not exist // thrown if directory does not exist
//vimperator.log("Error sourcing plugin directory: " + e); //vimperator.log("Error sourcing plugin directory: " + e);
} }
// after sourcing the initialization files, this function will set
// all gui options to their default values, if they have not been
// set before by any rc file
vimperator.options.setInitialGUI();
}, 0); }, 0);
vimperator.statusline.update(); vimperator.statusline.update();