[comp.sys.mac.hypercard] Deleting Cards Unintentionally

8hum190@violet.berkeley.edu (Elliot Wilen) (08/26/88)

Okay, I was asking for it. In a moment of boredom, I tried a bunch of
random command-key combinations just to see if I'd missed some shortcut.
It was my great misfortune to discover that command-backspace = "Delete Card".
I didn't realize this until I'd deleted several cards, including a unique
control card. (No, I didn't have a backup, and let that be a lesson for me.)
I think I can get everything back to normal without *too* much trouble,
but I was, needless to say, somewhat irked. A quick check in Danny Goodman's
book seemed to confirm my intuitive belief that there shouldn't be
a shortcut for "Delete" (see p. 62), but I guess he blew it: the feature
is documented in the Help Stack.

Two things: (1) Since HyperCard doesn't automatically ask for confirmation
when you delete a card (unless you've written a script to trap for the
menu command), I think it would be better for there *not* to be a keyboard
shortcut. I mean, even a knowledgeable person can easily be burned by
this feature.

(2) Is there any way to trap for the shortcut but not the menu command?
I'd rather not be asked for confirmation when I make the menu command, but
it would be nice if I could have a script which went something like:

on backspace
  if the commandKey is down
  then answer "Delete this card?" with "Okay" or "Cancel"
  if it is "Okay" then doMenu "Delete Card"
end backspace

In fact, if it were possible to detect backspace outside of a field,
then people could build a [command,option]-backspace shortcut for themselves,
and it wouldn't have to be built into HyperCard.

It occurs to me that I could do the following:

on doMenu command
 if command is "Delete Card" and the commandKey is down
 then
   answer "Delete this card?" with "Okay" or "Cancel"
   if it is "Okay" then send "doMenu "Delete Card"" to HyperCard
 else
   pass doMenu command
 end if
end doMenu
  
But it's rather unpleasant.

Oh, one last thing: could I just edit the menu using ResEdit?

--Elliot Wilen
------------------------------------------------------------------------------
     ucbvax!violet!8hum190           | Credo ut vos sanguinarius mendax estis.

8hum190@violet.berkeley.edu (Elliot Wilen) (08/26/88)

My apologies for not testing the second script; I thought of it while
typing my article. A version which works, and which currently resides
in the script of my Home Stack, is as follows:

on doMenu command
  if command is "Delete Card" and the commandKey is down then
    answer "Delete this card?" with "Okay or "Cancel"
    if it is "Cancel" then exit doMenu
  end if
  pass doMenu
end doMenu

This seems to be reasonably satisfactory. But it will ask for conformation
for a menu-issued "Delete Card" command if the command key happens to be
down at the time--no big deal. And it will be foiled if the shortcut is
typed very quickly, which could be a big deal. On the other hand, it
almost certainly would have prevented tonight's mini-calamity.

--Elliot
------------------------------------------------------------------------------
     ucbvax!violet!8hum190           | Credo ut vos sanguinarius mendax estis.

landman%hanami@Sun.COM (Howard A. Landman) (08/27/88)

In article <13631@agate.BERKELEY.EDU> 8hum190@violet.berkeley.edu (Elliot Wilen) writes:
>It was my great misfortune to discover that command-backspace = "Delete Card".
>I didn't realize this until I'd deleted several cards, including a unique
>control card. (No, I didn't have a backup, and let that be a lesson for me.)

Well, yes.  ALWAYS work on a copy.  But also, once you've gotten a background
more or less right, set the "Can't delete background" bit.  If you really
want to delete it later, you can always unset the bit.  This won't keep you
from losing cards, but it WILL keep you from deleting the last card of that
background, which I gather is what happened from the word "unique".

	Howard A. Landman
	landman@hanami.sun.com
	UUCP: sun!hanami!landman

dan@Apple.COM (Dan Allen) (08/28/88)

Deleting cards can be trapped by a handler in a stack such as

on doMenu what
	if what is "Delete Card" then ask...
	else pass doMenu
end doMenu

Starting with HC 1.1 or 1.2 (I can't remember which), HyperCard has also
supported UNDO of a Delete Card.  Editing the menus will not change the
command key shortcut.  The only way to override such things is to use a
doMenu handler, or put the stack in the browse mode.

Dan Allen
Apple Computer

P.S. - There are probably OTHER ways as well....

tgl@zog.cs.cmu.edu (Tom Lane) (08/28/88)

Another means of protection, which I use as much as possible, is to set the
"Can't delete card" bit on every card for which it makes sense (like the
unique control card that E.W. lost).  Even where it doesn't make sense (most
data cards), you should nearly always set the "Can't delete background" bit
to ensure that the background won't go away.

This discussion does bring up a couple of points that Dan Allen and cohorts
ought to think about:

1.  I agree with Elliot Wilen that there should NOT be a shortcut for a
command as destructive as Delete Card, *especially* when (a) no confirmation
is requested and (b) the shortcut is not marked on the menu.
Being able to Undo it is totally inadequate when there is only one level of
undo, because there is no immediate indication that you've deleted a card
rather than just moved to the next card.
I seriously doubt that removing the shortcut would inconvenience many users,
especially since one can easily make a button or otherwise make one's own
shortcut when really necessary.

2.  How come the "can't delete" bit for backgrounds and cards is not a
script-accessible property?  I can envision a background script reading
	on newCard
	  set the undeletable of this card to true
	...

-- 
				tom lane
Internet: tgl@zog.cs.cmu.edu
UUCP: <your favorite internet/arpanet gateway>!zog.cs.cmu.edu!tgl
BITNET: tgl%zog.cs.cmu.edu@cmuccvma

korn@eris.berkeley.edu (Peter "Arrgh" Korn) (08/29/88)

In <2815@pt.cs.cmu.edu>, tgl@zog.cs.cmu.edu (Tom Lane) said:  
>...
>2.  How come the "can't delete" bit for backgrounds and cards is not a
>script-accessible property?  I can envision a background script reading
>	on newCard
>	  set the undeletable of this card to true
>	...

Tom, it IS a script-accessible property.  It's called the "cantDelete" property,
and it is both a card and background property.

	on newCard
	  set cantDelete of this card to true
	...

works quite nicely.


In most all of my stacks I set all cards to be non-deletable, and then have
a handler in the stack script that goes through and flushes all of the data
cards.  It typically looks like this:

on flushDataCards
  put "Flushing cards in this stack..."
  go to first card
  set cursor to "busy"
  repeat
    go to next card			-- I never want to delete first card
    set cursor to "busy"
    put short name of this card into cardName
    if cardName = "name of template card" then exit repeat
    set cantDelete of this card to false
    doMenu "delete card"
  end repeat
end flushDataCards

It should be noted that this only works in HyperCard 1.2 or later...


Peter
--
Peter "Arrgh" Korn
korn@ucbvax.Berkeley.EDU
{decvax,hplabs,sdcsvax,ulysses,usenix}!ucbvax!korn

dan@Apple.COM (Dan Allen) (08/30/88)

In article <2815@pt.cs.cmu.edu> tgl@zog.cs.cmu.edu (Tom Lane) writes:
>2.  How come the "can't delete" bit for backgrounds and cards is not a
>    a scriptable property?

Good question.  Look for it in a future release.  A script should be
able to get and set the "can't delete" bit.

Dan Allen
Apple Computer

dan@Apple.COM (Dan Allen) (08/30/88)

In article <16309@apple.Apple.COM> dan@apple.com.UUCP (Dan Allen) writes:
>In article <2815@pt.cs.cmu.edu> tgl@zog.cs.cmu.edu (Tom Lane) writes:
>>2.  How come the "can't delete" bit for backgrounds and cards is not a
>>    a scriptable property?
>
>Good question.  Look for it in a future release.  A script should be
>able to get and set the "can't delete" bit.
>
>Dan Allen
>Apple Computer
>
>

I KNEW I WAS TIRED!  After answering this piece of mail I then read
Peter
"Arrgh" Korn's description of using the cantDelete property of cards,
backgrounds, and stacks.  The reason I FORGOT about this property was
that I came up against this problem in the early days of HC and I was
one (of many) that got it stuck into 1.2.  Therefore, ignore my response
and just get 1.2 and you'll have scriptable "can't delete" bits.

Using this new property is described in the 1.2 Release Notes Stack.

Dan Allen
Apple Computer

SEB@pucc.Princeton.EDU (Scott E Barron) (08/30/88)

In article <16309@apple.Apple.COM>, dan@Apple.COM (Dan Allen) writes:
 
>In article <2815@pt.cs.cmu.edu> tgl@zog.cs.cmu.edu (Tom Lane) writes:
>>2.  How come the "can't delete" bit for backgrounds and cards is not
>>    a scriptable property?
>
>Good question.  Look for it in a future release.  A script should be
>able to get and set the "can't delete" bit.
>
>Dan Allen
>Apple Computer
 
As I understand it, Hypercard 1.2.1 has a new property that allows the
"can't delete" bit of a card or background to be set from a script.  It
is the cantDelete property.  An example is:
 
set cantDelete of this cd to true
            or
set cantDelete of this bg to true
         or even
set cantDelete of this stack to true
 
 
I have used this property in several scripts and it works quite well.
Is this correct, Dan?
 
-------------------------------- SEB -----------------------------------