From dc00e584fbad22dc25f229f9dba80332c88323a8 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 3 Apr 2013 14:29:12 +0100 Subject: [PATCH] Add support for filtering shadow tiddlers --- core/modules/filters.js | 12 ++++++++++-- core/modules/tiddler.js | 11 ----------- core/modules/widgets/link.js | 10 ++++++++-- core/modules/widgets/transclude.js | 2 +- core/modules/wiki.js | 25 +++++++++++++++++++++++-- core/templates/MoreSideBar.tid | 5 ++++- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/core/modules/filters.js b/core/modules/filters.js index 01af4bb6f..f023a2cd6 100644 --- a/core/modules/filters.js +++ b/core/modules/filters.js @@ -106,7 +106,13 @@ exports.operators = { } break; case "system": - return "for(title in source) {if(" + op + "this.getTiddler(title).isSystem()) {$tw.utils.pushTop(subResults,title);}}"; + return "for(title in source) {if(" + op + "this.isSystemTiddler(title)) {$tw.utils.pushTop(subResults,title);}}"; + case "shadow": + if(operator.prefix === "!") { + return "for(title in source) {if(!this.isShadowTiddler(title)) {$tw.utils.pushTop(subResults,title);}}"; + } else { + return "for(title in this.shadowTiddlers) {$tw.utils.pushTop(subResults,title);}"; + } case "missing": if(operator.prefix === "!") { return "for(title in source) {$tw.utils.pushTop(subResults,title);}"; @@ -134,7 +140,9 @@ exports.operators = { } break; case "system": - return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.getTiddler(subResults[r]).isSystem()) {subResults.splice(r,1);}}"; + return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.isSystemTiddler(subResults[r])) {subResults.splice(r,1);}}"; + case "shadow": + return "for(r=subResults.length-1; r>=0; r--) {if(" + op + "this.isShadowTiddler(subResults[r])) {subResults.splice(r,1);}}"; case "missing": return "t = this.getMissingTitles(); for(r=subResults.length-1; r>=0; r--) {if(" + op + "!$tw.utils.hop(t,subResults[r])) {subResults.splice(r,1);}}"; case "orphan": diff --git a/core/modules/tiddler.js b/core/modules/tiddler.js index 5ff0c0d4b..e30b6fe05 100644 --- a/core/modules/tiddler.js +++ b/core/modules/tiddler.js @@ -16,17 +16,6 @@ exports.hasTag = function(tag) { return this.fields.tags && this.fields.tags.indexOf(tag) !== -1; }; -exports.isSystem = function() { - if(!$tw.utils.hop(this,"systemFlag")) { - this.systemFlag = this.fields.title.indexOf("$:/") === 0; - } - return this.systemFlag; -}; - -exports.isTemporary = function() { - return this.fields.title.indexOf("$:/temp/") === 0; -}; - exports.getFieldString = function(field) { var value = this.fields[field]; // Check for a missing field diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index 8b7e63490..4f0ffcdf9 100644 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -37,6 +37,7 @@ LinkWidget.prototype.generate = function() { this.isExternal = isLinkExternal(this.to); if(!this.isExternal) { this.isMissing = !this.renderer.renderTree.wiki.tiddlerExists(this.to); + this.isShadow = this.renderer.renderTree.wiki.isShadowTiddler(this.to); } // Compose the link var classes = ["tw-tiddlylink"] @@ -44,10 +45,15 @@ LinkWidget.prototype.generate = function() { $tw.utils.pushTop(classes,"tw-tiddlylink-external"); } else { $tw.utils.pushTop(classes,"tw-tiddlylink-internal"); - if(this.isMissing) { + if(this.isShadow) { + $tw.utils.pushTop(classes,"tw-tiddlylink-shadow"); + } + if(this.isMissing && !this.isShadow) { $tw.utils.pushTop(classes,"tw-tiddlylink-missing"); } else { - $tw.utils.pushTop(classes,"tw-tiddlylink-resolves"); + if(!this.isMissing) { + $tw.utils.pushTop(classes,"tw-tiddlylink-resolves"); + } } } var events = [{name: "click", handlerObject: this, handlerMethod: "handleClickEvent"}]; diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index 81fe70c00..345511429 100644 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -98,7 +98,7 @@ TranscludeWidget.prototype.generate = function() { if(this.renderer.hasAttribute("class")) { $tw.utils.pushTop(classes,this.renderer.getAttribute("class").split(" ")); } - if(!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle)) { + if(!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle) && !this.renderer.renderTree.wiki.isShadowTiddler(this.targetTitle)) { $tw.utils.pushTop(classes,"tw-tiddler-missing"); } // Create the renderers for the wrapper and the children diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 293cd2f74..75fc8f7e5 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -164,6 +164,18 @@ exports.tiddlerExists = function(title) { return !!this.tiddlers[title]; }; +exports.isSystemTiddler = function(title) { + return title.indexOf("$:/") === 0; +}; + +exports.isTemporaryTiddler = function(title) { + return title.indexOf("$:/temp/") === 0; +}; + +exports.isShadowTiddler = function(title) { + return $tw.utils.hop(this.shadowTiddlers,title); +}; + exports.addTiddler = function(tiddler) { // Check if we're passed a fields hashmap instead of a tiddler if(!(tiddler instanceof $tw.Tiddler)) { @@ -184,7 +196,7 @@ exports.getTiddlers = function(sortField,excludeTag) { sortField = sortField || "title"; var tiddlers = [], t, titles = []; for(t in this.tiddlers) { - if($tw.utils.hop(this.tiddlers,t) && !this.tiddlers[t].isSystem() && (!excludeTag || !this.tiddlers[t].hasTag(excludeTag))) { + if($tw.utils.hop(this.tiddlers,t) && !this.isSystemTiddler(t) && (!excludeTag || !this.tiddlers[t].hasTag(excludeTag))) { tiddlers.push(this.tiddlers[t]); } } @@ -344,7 +356,7 @@ exports.getOrphanTitles = function() { exports.getSystemTitles = function() { var titles = []; for(var title in this.tiddlers) { - if(this.tiddlers[title].isSystem()) { + if(this.isSystemTiddler(title)) { titles.push(title); } } @@ -352,6 +364,15 @@ exports.getSystemTitles = function() { return titles; }; +exports.getShadowTitles = function() { + var titles = []; + for(var title in this.shadowTiddlers) { + titles.push(title); + } + titles.sort(); + return titles; +}; + /* Retrieves a list of the tiddler titles that are tagged with a given tag */ diff --git a/core/templates/MoreSideBar.tid b/core/templates/MoreSideBar.tid index 2195e153d..74bd50218 100644 --- a/core/templates/MoreSideBar.tid +++ b/core/templates/MoreSideBar.tid @@ -1,7 +1,7 @@ title: $:/templates/MoreSideBar
-
<$button type="set" set="$:/state/moreSideBarTabSet" setTo="tagsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Tags<$button type="set" set="$:/state/moreSideBarTabSet" setTo="missingTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Missing<$button type="set" set="$:/state/moreSideBarTabSet" setTo="orphanTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Orphans<$button type="set" set="$:/state/moreSideBarTabSet" setTo="systemTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">System
+
<$button type="set" set="$:/state/moreSideBarTabSet" setTo="tagsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Tags<$button type="set" set="$:/state/moreSideBarTabSet" setTo="missingTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Missing<$button type="set" set="$:/state/moreSideBarTabSet" setTo="orphanTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Orphans<$button type="set" set="$:/state/moreSideBarTabSet" setTo="systemTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">System<$button type="set" set="$:/state/moreSideBarTabSet" setTo="shadowsTab" qualifyTiddlerTitles="yes" selectedClass="tw-tab-selected">Shadows
<$reveal type="match" state="$:/state/moreSideBarTabSet" text="tagsTab" qualifyTiddlerTitles="yes"> <$list filter="[tags[]sort[title]]" itemClass="tw-menu-list-item" template="$:/templates/TagTemplate"/> @@ -15,5 +15,8 @@ title: $:/templates/MoreSideBar <$reveal type="match" state="$:/state/moreSideBarTabSet" text="systemTab" qualifyTiddlerTitles="yes"> <$list filter="[is[system]sort[title]]" itemClass="tw-menu-list-item"/> +<$reveal type="match" state="$:/state/moreSideBarTabSet" text="shadowsTab" qualifyTiddlerTitles="yes"> +<$list filter="[is[shadow]sort[title]]" itemClass="tw-menu-list-item"/> +