POO Library


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.
@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 ["<This space intentionally left blank.>"]
@set editable.desc to None
@set editable.f to 1

@newfunc allowEdit(self,who) on editable
	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

@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} )

@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})
# 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 )
@set editable.edit.desc = "edit the text"
@setown editable.edit to None
@setperm editable.edit to rc
@cmd editable.edit <this> 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]
@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.

beam editable to $pub.misc


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

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 $pub.misc.editable in the near future!

Last Updated: 6/07/97 . . . . . . Joe Strout