mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-10-21 10:47:39 +00:00
Introduce true global variables
The basic idea is that if we don't find a variable `foo` then we fallback to retrieving the value from the tiddler `$:/global/foo`, if it exists. This allows us to replace the usual importvariables-based mechanism for global definitions, avoiding cluttering up the variable namespace with every macro. In order to permit subprocedures to be overridden, we also introduce a mechanism for conditional definitions: preceding the word definition|procedure|function|widget with a + causes the definition only to occur if the specified variable doesn't already exist. In the next commit we'll apply this mechanism to the tabs macro
This commit is contained in:
@@ -47,17 +47,20 @@ SetWidget.prototype.execute = function() {
|
||||
this.setIndex = this.getAttribute("index");
|
||||
this.setValue = this.getAttribute("value");
|
||||
this.setEmptyValue = this.getAttribute("emptyValue");
|
||||
// Set context variable
|
||||
if(this.parseTreeNode.isMacroDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,true);
|
||||
} else if(this.parseTreeNode.isFunctionDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true});
|
||||
} else if(this.parseTreeNode.isProcedureDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace});
|
||||
} else if(this.parseTreeNode.isWidgetDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace});
|
||||
} else {
|
||||
this.setVariable(this.setName,this.getValue());
|
||||
this.setConditional = this.getAttribute("conditional","no") === "yes";
|
||||
// Set context variable, checking for a conditional assignment
|
||||
if(!this.setConditional || this.getVariableInfo(this.setName).text === undefined) {
|
||||
if(this.parseTreeNode.isMacroDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,true);
|
||||
} else if(this.parseTreeNode.isFunctionDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true});
|
||||
} else if(this.parseTreeNode.isProcedureDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace});
|
||||
} else if(this.parseTreeNode.isWidgetDefinition) {
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace});
|
||||
} else {
|
||||
this.setVariable(this.setName,this.getValue());
|
||||
}
|
||||
}
|
||||
// Construct the child widgets
|
||||
this.makeChildWidgets();
|
||||
@@ -111,7 +114,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
*/
|
||||
SetWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.name || changedAttributes.filter || changedAttributes.select || changedAttributes.tiddler || (this.setTiddler && changedTiddlers[this.setTiddler]) || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes.emptyValue ||
|
||||
if(changedAttributes.name || changedAttributes.filter || changedAttributes.select || changedAttributes.tiddler || (this.setTiddler && changedTiddlers[this.setTiddler]) || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes.emptyValue || changedAttributes.conditional ||
|
||||
(this.setFilter && this.getValue() != this.variables[this.setName].value)) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user