<html><head><title>
POO lib: editable
</title></head><body><center>
<h3>POO Library</h3>
<h1>$pub.misc.editable</h1>
</center>

This object implements a simple editable object -- useful for making notes,
signs, letters, or anything where you (and possibly others) may want to
edit the text.

<hr>
<pre>@create $thing as editable
@set editable.editFailMsg = "%1D %1:(tries) to edit %2i, but to no avail."
@set editable.startEditMsg = "%1D %1:(begins) editing %2i."
@set editable.endEditMsg = "%1D %1:(puts) the finishing touches on %2i."
@set editable.abortEditMsg = "%1D %1:(quits) editing %2i."
@set editable.text to ["&lt;This space intentionally left blank.&gt;"]
@set editable.desc to None
@set editable.f to 1

@newfunc allowEdit(self,who) on editable
"""editable.allowEdit(self,who):
	Return 1 if 'who' can edit this, else return 0.
	In this version: if self.locked is true,
	then only owner can edit; else anyone can.
"""
if self.locked: return who == self.owner
return 1
.x

@newfunc postedit(self, who, whatobj, propname, saved) on editable
if saved: show( self.endEditMsg, {1:who, 2:self} )
else: show( self.abortEditMsg, {1:who, 2:self} )
.x

@newfunc edit(self) on editable
"""editable.edit(self): implements the "edit" command"""
# is user allowed to edit this?
if not self.allowEdit(user):
	show(self.editFailMsg, {1:user, 2:self})
	return
# make sure value is defined locally, not inherited
self.text = self.text
# ok, start editing!
show( self.startEditMsg, {1:user, 2:self} )
user.startEdit( self, "text", self.postedit )
.x
@set editable.edit.desc = "edit the text"
@setown editable.edit to None
@setperm editable.edit to rc
@cmd editable.edit &lt;this&gt; calls edit()

@newfunc editable.description(self,looker)
# first, get the standard desc, if any
if self.desc: desc = self.desc + '\n'
else: desc = ''
# then append the text, separated by carriage returns
for line in self.text:
	desc = desc + line + '\n'
# finally, if there is a "postdesc" property, append that
if self.postdesc: desc = desc + self.postdesc  + '\n'
return desc[:-1]
.x
@set editable.description.desc = "standard desc plus text"

@edit editable.help
To prepare an editable object, simply derive from $pub.misc.editable
and set the following properties:

    desc: description to appear before the text (if any)
    postdesc: description to appear after the text (if any)
    locked: if 1, only the owner can edit the text

To use an editable object, just say "edit foo" where "foo" is the
name or an alias of the object.
.x

beam editable to $pub.misc
</pre><hr>

<h3>Usage</h3>

Derive your object from $pub.misc.editable, then edit it.
If you want others to be able to edit it, do a command like "<tt>@setperm
myobj.text = rcw</tt>", where "myobj" is the name of your object.  If you
don't want others to be able to edit it, then <tt>@set myobj.locked =
1</tt>.

<p>I'd like to make it so that you don't have to muck with the permissions
of the text property.  Watch this space for a new, improved
<b>$pub.misc.editable</b> in the near future!

<p><hr>
<address>
http://www.strout.net/python/poo/lib/editable.html
<br>Last Updated:
6/07/97
. . . . . . <a href="http://www.strout.net/">Joe Strout</a>
</address>
</body></html>