@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 """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 <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] .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
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!