Ticket #756: bakedoptions.patch

File bakedoptions.patch, 8.6 KB (added by FND, 3 years ago)

Baked Options Patch by JeremyRuston?

  • shadows/split.recipe

     
    55shadow: StyleSheetLayout.tiddler 
    66shadow: StyleSheetLocale.tiddler 
    77shadow: StyleSheetPrint.tiddler 
     8shadow: SystemSettings.tiddler 
    89shadow: PageTemplate.tiddler 
    910shadow: ViewTemplate.tiddler 
    1011shadow: EditTemplate.tiddler 
  • shadows/SystemSettings.tiddler

     
     1<div title="SystemSettings"> 
     2<pre>chkRegExpSearch: false 
     3chkCaseSensitiveSearch: false 
     4chkIncrementalSearch: true 
     5chkAnimate_cookie: false 
     6chkSaveBackups: true 
     7chkAutoSave: false 
     8chkGenerateAnRssFeed: false 
     9chkSaveEmptyTemplate: false 
     10chkOpenInNewWindow: true 
     11chkToggleLinks: false 
     12chkHttpReadOnly: true 
     13chkForceMinorUpdate: false 
     14chkConfirmDelete: true 
     15chkInsertTabs: false 
     16chkUsePreForStorage: true 
     17chkDisplayInstrumentation: false 
     18txtBackupFolder:  
     19txtEditorFocus: text 
     20txtMainTab_cookie: More 
     21txtMoreTab_cookie: Missing 
     22txtMaxEditRows: 30 
     23txtFileSystemCharSet: UTF-8 
     24txtTheme:  
     25txtUserName: YourName 
     26chkSliderOptionsPanel_cookie: true 
     27chkBackstage_cookie: false 
     28chkSideBarTabs_cookie: true 
     29</pre> 
     30</div> 
     31 No newline at end of file 
  • js/TiddlyWiki.js

     
    151151        return textOut.join(""); 
    152152}; 
    153153 
    154 TiddlyWiki.prototype.slicesRE = /(?:^([\'\/]{0,2})~?([\.\w]+)\:\1\s*([^\n]+)\s*$)|(?:^\|([\'\/]{0,2})~?([\.\w]+)\:?\4\|\s*([^\|\n]+)\s*\|$)/gm; 
     154TiddlyWiki.prototype.slicesRE = /(?:^([\'\/]{0,2})~?([\.\w]+)\:\1[\t\x20]*([^\n]*)[\t\x20]*$)|(?:^\|([\'\/]{0,2})~?([\.\w]+)\:?\4\|[\t\x20]*([^\|\n]*)[\t\x20]*\|$)/gm; 
    155155 
    156156// @internal 
    157157TiddlyWiki.prototype.calcAllSlices = function(title) 
  • js/main.js

     
    3333        story = new Story("tiddlerDisplay","tiddler"); 
    3434        addEvent(document,"click",Popup.onDocumentClick); 
    3535        saveTest(); 
    36         loadOptionsCookie(); 
    3736        for(var s=0; s<config.notifyTiddlers.length; s++) 
    3837                store.addNotification(config.notifyTiddlers[s].name,config.notifyTiddlers[s].notify); 
    3938        t1 = new Date(); 
    4039        loadShadowTiddlers(); 
    4140        t2 = new Date(); 
    4241        store.loadFromDiv("storeArea","store",true); 
     42        loadOptionsCookie(); 
    4343        t3 = new Date(); 
    4444        invokeParamifier(params,"onload"); 
    4545        t4 = new Date(); 
  • js/Options.js

     
    44 
    55config.optionHandlers = { 
    66        'txt': { 
    7                 get: function(name) {return encodeCookie(config.options[name].toString());}, 
    8                 set: function(name,value) {config.options[name] = decodeCookie(value);} 
     7                get: function(name) {return config.options[name].toString();}, 
     8                set: function(name,value) {config.options[name] = value;} 
    99        }, 
    1010        'chk': { 
    1111                get: function(name) {return config.options[name] ? "true" : "false";}, 
     
    1313        } 
    1414}; 
    1515 
    16 function loadOptionsCookie() 
     16//# Loads up config.options from cookies and SystemSettings 
     17function initialiseOptions() 
    1718{ 
    1819        if(safeMode) 
    1920                return; 
     21        loadSystemSettings(); 
     22        loadCookies(); 
     23} 
     24// Deprecated name for backwards compatibility 
     25var loadOptionsCookie = initialiseOptions; 
     26 
     27function loadCookies() 
     28{ 
     29        var cookies = {}; 
    2030        var cookies = document.cookie.split(";"); 
    2131        for(var c=0; c<cookies.length; c++) { 
    2232                var p = cookies[c].indexOf("="); 
     
    2434                        var name = cookies[c].substr(0,p).trim(); 
    2535                        var value = cookies[c].substr(p+1).trim(); 
    2636                        var optType = name.substr(0,3); 
    27                         if(config.optionHandlers[optType] && config.optionHandlers[optType].set) 
    28                                 config.optionHandlers[optType].set(name,value); 
     37                        if(config.optionSource[name] == 'cookie' && config.optionHandlers[optType] && config.optionHandlers[optType].set) 
     38                                config.optionHandlers[optType].set(name,decodeCookie(value)); 
    2939                } 
    3040        } 
    3141} 
    3242 
    33 function saveOptionCookie(name) 
     43function loadSystemSettings() 
    3444{ 
     45        var settings = store.calcAllSlices("SystemSettings"); 
     46        for(var key in settings) { 
     47                var splitPos = key.indexOf('_'); 
     48                var name = key; 
     49                var source = "setting"; 
     50                if(splitPos !== -1) { 
     51                        source = key.substr(splitPos+1); 
     52                        name = key.substr(0,splitPos); 
     53                } 
     54                optType = name.substr(0,3); 
     55                if(config.optionHandlers[optType] && config.optionHandlers[optType].set) { 
     56                        config.optionHandlers[optType].set(name,settings[key]); 
     57                } 
     58                config.optionSource[name] = source; 
     59        } 
     60} 
     61 
     62function onSystemSettingsChange() 
     63{ 
     64        if(!startingUp) { 
     65                loadSystemSettings(); 
     66        } 
     67} 
     68 
     69// Saves the named option in a cookie or SystemSettings as appropriate 
     70function saveOption(name) 
     71{ 
    3572        if(safeMode) 
    3673                return; 
     74        if(config.optionSource[name] == 'cookie') 
     75                saveCookie(name); 
     76        else 
     77                saveSystemSetting(name); 
     78} 
     79// Deprecated names for backwards compatibility 
     80var saveOptionCookie = saveOption; 
     81 
     82function saveCookie(name) 
     83{ 
    3784        var c = name + "="; 
    3885        var optType = name.substr(0,3); 
    3986        if(config.optionHandlers[optType] && config.optionHandlers[optType].get) 
    40                 c += config.optionHandlers[optType].get(name); 
     87                c += encodeCookie(config.optionHandlers[optType].get(name)); 
    4188        c += "; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/"; 
    4289        document.cookie = c; 
    4390} 
    4491 
     92function saveSystemSetting(name) 
     93{ 
     94        var s = ""; 
     95        for(var key in config.options) { 
     96                s += key; 
     97                if(config.optionSource[key] && config.optionSource[key] != "setting") { 
     98                        s += "_" + config.optionSource[key]; 
     99                } 
     100                var optType = key.substr(0,3); 
     101                var value = ""; 
     102                if(config.optionHandlers[optType] && config.optionHandlers[optType].get) 
     103                        value = config.optionHandlers[optType].get(key); 
     104                s += ": " + value + "\n"; 
     105        } 
     106        store.saveTiddler("SystemSettings","SystemSettings",s,"System",new Date()); 
     107        autoSaveChanges(); 
     108} 
     109 
     110//# Flatten cookies to ANSI character set by substituting html character entities for non-ANSI characters 
    45111function encodeCookie(s) 
    46112{ 
    47113        return escape(convertUnicodeToHtmlEntities(s)); 
    48114} 
    49115 
     116//# Decode any html character entities to their unicode equivalent 
    50117function decodeCookie(s) 
    51118{ 
    52119        s = unescape(s); 
  • js/Config.js

     
    6363        }; 
    6464config.optionsDesc = {}; 
    6565 
     66//# config.optionSource["chkAnimate"] can be: 
     67//#     cookie: the option gets stored in a cookie, with the default value coming from SystemSettings 
     68//#             volatile: the option isn't persisted at all, and reverts to the default specified in SystemSettings when the document is reloaded 
     69//#             setting: the option is stored in the SystemSettings tiddler 
     70//#     The default is "setting" 
     71config.optionSource = {}; 
     72 
    6673// Default tiddler templates 
    6774var DEFAULT_VIEW_TEMPLATE = 1; 
    6875var DEFAULT_EDIT_TEMPLATE = 2; 
  • js/Lingo.js

     
    462462        StyleSheetLayout: "This shadow tiddler contains CSS definitions related to the layout of page elements. ''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler", 
    463463        StyleSheetLocale: "This shadow tiddler contains CSS definitions related to the translation locale", 
    464464        StyleSheetPrint: "This shadow tiddler contains CSS definitions for printing", 
     465        SystemSettings: "This tiddler is used to store configuration options for this TiddlyWiki document", 
    465466        TabAll: "This shadow tiddler contains the contents of the 'All' tab in the right-hand sidebar", 
    466467        TabMore: "This shadow tiddler contains the contents of the 'More' tab in the right-hand sidebar", 
    467468        TabMoreMissing: "This shadow tiddler contains the contents of the 'Missing' tab in the right-hand sidebar", 
     
    472473        ToolbarCommands: "This shadow tiddler determines which commands are shown in tiddler toolbars", 
    473474        ViewTemplate: "The HTML template in this shadow tiddler determines how tiddlers look" 
    474475        }); 
    475  
  • js/Refresh.js

     
    44 
    55//# List of notification functions to be called when certain tiddlers are changed or deleted 
    66config.notifyTiddlers = [ 
     7        {name: "SystemSettings", notify: onSystemSettingsChange}, 
    78        {name: "StyleSheetLayout", notify: refreshStyles}, 
    89        {name: "StyleSheetColors", notify: refreshStyles}, 
    910        {name: "StyleSheet", notify: refreshStyles},