settings.js

来自「在线编辑器」· JavaScript 代码 · 共 556 行 · 第 1/2 页

JS
556
字号
        var rs = this.db.run('select distinct value from settings where key = ?', [ key ]);        try {            if (rs && rs.isValidRow()) {              return rs.field(0);            }        } catch (e) {            console.log(e.message);        } finally {            rs.close();        }    },    unset: function(key) {        this.db.run('delete from settings where key = ?', [ key ]);    },    list: function() {        // TODO: Need to override with browser settings        return this.db.selectRows('settings', '1=1');    },    // -- Private-y    seed: function() {        this.db.run('delete from settings');        // TODO: loop through the settings        this.db.run('insert into settings (key, value, timestamp) values (?, ?, ?)', ['keybindings', 'emacs', 1183878000000]);        this.db.run('insert into settings (key, value, timestamp) values (?, ?, ?)', ['tabsize', '2', 1183878000000]);        this.db.run('insert into settings (key, value, timestamp) values (?, ?, ?)', ['fontsize', '10', 1183878000000]);        this.db.run('insert into settings (key, value, timestamp) values (?, ?, ?)', ['autocomplete', 'off', 1183878000000]);    }});*/// ** {{{ bespin.client.settings.URL }}} **//// Grab the setting from the URL, either via # or ?   dojo.declare("bespin.client.settings.URL", null, {    constructor: function(queryString) {                    this.results = dojo.queryToObject(this.stripHash(queryString || window.location.hash));    },    get: function(key) {        return this.results[key];    },    set: function(key, value) {        this.results[key] = value;    },        stripHash: function(url) {        var tobe = url.split('');        tobe.shift();        return tobe.join('');    }});// ** {{{ bespin.client.settings.Events }}} **//// Custom Event holder for the Settings work. // It deals with both settings themselves, and other events that// settings need to watch and look fordojo.declare("bespin.client.settings.Events", null, {    constructor: function(settings) {        this.settings = settings;        // ** {{{ Event: bespin:settings:set }}} **        //         // Watch for someone wanting to do a set operation        bespin.subscribe("bespin:settings:set", function(event) {            var key = event.key;            var value = event.value;            settings.set(key, value);        });        // ** {{{ Event: bespin:editor:openfile:opensuccess }}} **        //         // Change the session settings when a new file is opened        bespin.subscribe("bespin:editor:openfile:opensuccess", function(event) {            var file = event.file;            _editSession.path = file.name;            settings.set('_project',  _editSession.project);            settings.set('_path',     _editSession.path);            settings.set('_username', _editSession.username);            if (_editSession.syncHelper) _editSession.syncHelper.syncWithServer();        });        // ** {{{ Event: bespin:editor:openfile:opensuccess }}} **        //         // Change the syntax highlighter when a new file is opened        bespin.subscribe("bespin:editor:openfile:opensuccess", function(event) {            var file = event.file;            var split = file.name.split('.');            var type = split[split.length - 1];             if (type)                bespin.publish("bespin:settings:syntax", { language: type });        });        // ** {{{ Event: bespin:settings:set:syntax }}} **        //         // When the syntax setting is changed, tell the syntax system to change        bespin.subscribe("bespin:settings:set:syntax", function(event) {            var value = event.value;                        bespin.publish("bespin:settings:syntax", { language: value, fromCommand: true });        });        // ** {{{ Event: bespin:settings:syntax }}} **        //         // Given a new syntax command, change the editor.language                bespin.subscribe("bespin:settings:syntax", function(event) {            var language = event.language;            var fromCommand = event.fromCommand;            var syntaxSetting = settings.get('syntax') || "off";                  if (language == _editor.language) return; // already set to be that language            if (bespin.util.include(['auto', 'on'], language)) {                var split = window.location.hash.split('.');                var type = split[split.length - 1];                                if (type) _editor.language = type;            } else if (bespin.util.include(['auto', 'on'], syntaxSetting) || fromCommand) {                _editor.language = language;            } else if (syntaxSetting == 'off') {                _editor.language = 'off';            }         });        // ** {{{ Event: bespin:settings:set:collaborate }}} **        //         // Turn on the collaboration system if set to be on        bespin.subscribe("bespin:settings:set:collaborate", function(event) {            var value = event.value;            _editSession.collaborate = settings.isOn(value);        });        // ** {{{ Event: bespin:settings:set:fontsize }}} **        //         // Change the font size for the editor        bespin.subscribe("bespin:settings:set:fontsize", function(event) {            var value = event.value;            var fontsize = parseInt(value);            _editor.theme.lineNumberFont = fontsize + "pt Monaco, Lucida Console, monospace";        });        // ** {{{ Event: bespin:settings:set:theme }}} **        //         // Change the Theme object used by the editor        bespin.subscribe("bespin:settings:set:theme", function(event) {            var theme = event.value;            if (theme) {                var themeSettings = bespin.themes[theme];                if (themeSettings) {                    if (themeSettings != _editor.theme) {                          _editor.theme = themeSettings;                    }                } else {                    bespin.publish("bespin:cmdline:showinfo", {                        msg: "Sorry old chap. No theme called '" + theme + "'. Fancy making it?"                    });                }            }        });        // ** {{{ Event: bespin:settings:set:keybindings }}} **        //         // Add in emacs key bindings        bespin.subscribe("bespin:settings:set:keybindings", function(event) {            var value = event.value;            if (value == "emacs") {                bespin.publish("bespin:editor:bindkey", {                    modifiers: "ctrl",                    key: "b",                    action: "moveCursorLeft"                });                bespin.publish("bespin:editor:bindkey", {                    modifiers: "ctrl",                    key: "f",                    action: "moveCursorRight"                });                bespin.publish("bespin:editor:bindkey", {                    modifiers: "ctrl",                    key: "p",                    action: "moveCursorUp"                });                bespin.publish("bespin:editor:bindkey", {                    modifiers: "ctrl",                    key: "n",                    action: "moveCursorDown"                });                bespin.publish("bespin:editor:bindkey", {                    modifiers: "ctrl",                    key: "a",                    action: "moveToLineStart"                });                bespin.publish("bespin:editor:bindkey", {                    modifiers: "ctrl",                    key: "e",                    action: "moveToLineEnd"                });            }        });                // ** {{{ Event: bespin:settings:init }}} **        //         // If we are opening up a new file        bespin.subscribe("bespin:settings:init", function(event) {            var path    = event.path;            var project = event.project;            // TODO: use the action and don't run a command itself            var newfile = settings.fromURL.get('new');            if (!newfile) { // scratch file                if (project && (_editSession.project != project)) {                    bespin.publish("bespin:editor:project:set", { project: project });                }                if (path) {                    bespin.publish("bespin:editor:openfile", { filename: path });                }            }        });        // ** {{{ Event: bespin:settings:init }}} **        //         // Setup the theme        bespin.subscribe("bespin:settings:init", function(event) {            bespin.publish("bespin:settings:set:theme", {                value: settings.get('theme')            });        });        // ** {{{ Event: bespin:settings:init }}} **        //         // Setup the special keybindings        bespin.subscribe("bespin:settings:init", function(event) {            bespin.publish("bespin:settings:set:keybindings", {                value: settings.get('keybindings')            });        });        // ** {{{ Event: bespin:settings:init }}} **        //         // Check for auto load        bespin.subscribe("bespin:settings:init", function(event) {            if (settings.isOn(settings.get('autoconfig'))) {                bespin.publish("bespin:editor:config:run");            }        });        // ** {{{ Event: bespin:settings:init }}} **        //         // Setup the font size that the user has configured        bespin.subscribe("bespin:settings:init", function(event) {            var fontsize = settings.get('fontsize');            bespin.publish("bespin:settings:set:fontsize", {                value: fontsize            });        });            }});

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?