Re: New version of TrashPlugin - now honours dontDelete tag

2012-02-19 Thread David Szego
One other way to do this:

In your !ViewTemplateToolbar slice from your theme, use:

span macro=hideWhenTagged dontDeletespan class='toolbar'
macro='toolbar [[ToolbarCommands::ViewToolbar]]'/span/span
span macro=showWhenTagged dontDeletespan class='toolbar'
macro='toolbar [[ToolbarCommands::NoDelViewToolbar]]'/span/span

and in your ToolbarCommands Tiddler, have a table row like:

|~NoDelViewToolbar|closeTiddler closeOthers attachFile +editTiddler
easyEdit jump  bookmarks +cloneTiddler fields syncing permalink
references newHere|

...where there's no delete command.

This also gets around Eric's well-founded objection of no user
feedback when clicking delete in the previous suggestion
(TrashPlugin update).

Cheers,
David Szego

-- 
You received this message because you are subscribed to the Google Groups GTD 
TiddlyWiki group.
To post to this group, send email to gtd-tiddlywiki@googlegroups.com.
To unsubscribe from this group, send email to 
gtd-tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/gtd-tiddlywiki?hl=en.



New version of TrashPlugin - now honours dontDelete tag

2012-02-12 Thread David Szego
Oddly, exactly 6 years after the last version, I've added a feature to
Ido Magal's TrashPlugin. Now the Delete button won't do anything on
Tiddlers tagged with dontDelete.

This is a great way to prevent critical Tiddlers (system, themes, css,
etc.) from getting accidentally wiped!

Enjoy,
David Szego


/***
|''Name:''|TrashPlugin|
|''Version:''|1.1.1 (Feb 12, 2012) |
|''Source:''|http://ido-xp.tiddlyspot.com/#TrashPlugin|
|''Author:''|Ido Magal (idoXatXidomagalXdotXcom)|
|''Licence:''|[[BSD open source license]]|
|''CoreVersion:''|2.1.0|
|''Browser:''|??|

!Description
This plugin provides trash bin functionality.  Instead of being
permanently removed, deleted tiddlers are tagged with Trash.  Empty
the trash by clicking on the emptyTrash button in the [[Trash]]
tiddler. Holding down CTRL while clicking on delete will bypass the
trash.

!Installation instructions
Create a new tiddler in your wiki and copy the contents of this
tiddler into it.  Name it the same and tag it with [[systemConfig]].
Save and reload your wiki.

!Uninstallation instructions
1. Empty the [[Trash]] ( emptyTrash )
2. Delete this tiddler.

!Revision history
* V1.1.1 (Feb. 12, 2012)
** Added dontDelete as an exception tag to prevent things from being
trashed
* V1.1.0 (Dec 12, 2006)
** added movedMsg (feedback when tiddler is tagged as Trash)
** make sure tiddler actually exists before tagging it with Trash
** fetch correct tiddler before checking for systemConfig tag
* V1.0.3TT.1 (TiddlyTools variant) (Dec 11, 2006)
** don't create Trash tiddler until needed
** remove Trash tiddler when no trash remains
** don't tag Trash tiddler with TrashPlugin
** moved all user-visible strings to variables so they can be
translated by 'lingo' plugins
** use displayMessage() instead of alert()
* v1.0.3 (Dec 11, 2006)
** Fixed broken reference to core deleteTiddler.
** Now storing reference to core deleteTiddler in emptyTrash macro.
** Reduced deleteTiddler hijacking to only the handler.
* v1.0.2 (Dec 11, 2006)
** EmptyTrash now uses removeTiddler instead of deleteTiddler.
** Supports trashing systemConfig tiddlers (adds systemConfigDisable
tag).
* v1.0.1 (Dec 10, 2006)
** Replaced TW version with proper Core reference.
** Now properly hijacking deleteTiddler command.
* v1.0.0 (Dec 10, 2006)
** First draft.

!To Do
* Make trash keep only n days worth of garbage.
* Add undo.
* rename deleted tiddlers?

!Code
***/
//{{{

config.macros.emptyTrash =
{
tag: Trash,
preventionTag: dontDelete,
movedMsg: '%0' has been tagged as '%1',
label: empty trash,
tooltip: Delete items tagged as %0 that are older than %1 days old,
emptyMsg: The trash is empty.,
noneToDeleteMsg: There are no items in the trash older than %0
days.,
confirmMsg: The following tiddlers will be deleted:\n\n'%0'\n\nIs it
OK to proceed?,
deletedMsg: Deleted '%0',

handler: function
( place,macroName,params,wikifier,paramString,tiddler )
{
var namedParams = (paramString.parseParams(daysOld))[0];
var daysOld = namedParams['daysOld'] ? 
namedParams['daysOld'][0] :
0; // default
var buttonTitle = namedParams['title'] ? 
namedParams['title'][0] :
this.label;
createTiddlyButton ( place, buttonTitle,
this.tooltip.format([ config.macros.emptyTrash.tag,daysOld ]),
this.emptyTrash( daysOld ));
},

emptyTrash: function( daysOld )
{
return function()
{
var collected = [];
var compareDate = new Date();
compareDate.setDate( compareDate.getDate() - daysOld );
store.forEachTiddler(function ( title,tiddler )
{
if ( tiddler.tags.contains( 
config.macros.emptyTrash.tag ) 
tiddler.modified  compareDate )
collected.push( title );
});

if ( collected.length == 0 )
{
if ( daysOld == 0 )
displayMessage( 
config.macros.emptyTrash.emptyMsg );
else

displayMessage( config.macros.emptyTrash.emptyMsg.format( [daysOld] ) );
}
else {
if (
confirm( config.macros.emptyTrash.confirmMsg.format( [collected.join( ',
' )] ) ) )
{
for ( var i=0;icollected.length;i++ )
{
store.removeTiddler( 
collected[i] );

displayMessage( config.macros.emptyTrash.deletedMsg.format( [collected[i]] ) );
}
}
}