(FILECREATED "16-Jan-87 16:33:30" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH180.;5 22795  

      changes to:  (FNS NC.EditPropList NC.AddPropToPropList NC.DelPropFromList 
			NC.ClosePropListEditor)
		   (VARS RHTPATCH180COMS)

      previous date: "16-Jan-87 13:29:20" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH180.;1)


(* Copyright (c) 1987 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT RHTPATCH180COMS)

(RPAQQ RHTPATCH180COMS ((* * Fix to proplist editor bugs #343, 317, 304: problems with ordering 
			     props, deleting props, null values, and not noticing when no changes 
			     were made. Also no longer adding the same prop twice or adding a 
			     system-reserved property. No longer puts up stupid save/cancel menu when 
			     window is closed.)
			  (* * New stuff for NCCARDS)
			  (GLOBALVARS NC.SystemCardPropNames)
			  (VARS (NC.SystemCardPropNames (QUOTE (Updates))))
			  (* * Changes to NCCARDS)
			  (FNS NC.EditProperties NC.ProcessEditedPropList NC.ExtractPropList 
			       NC.ClosePropListEditor NC.AddPropToPropList NC.EditPropList 
			       NC.DelPropFromList)))
(* * Fix to proplist editor bugs #343, 317, 304: problems with ordering props, deleting props,
 null values, and not noticing when no changes were made. Also no longer adding the same prop 
twice or adding a system-reserved property. No longer puts up stupid save/cancel menu when 
window is closed.)

(* * New stuff for NCCARDS)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.SystemCardPropNames)
)

(RPAQQ NC.SystemCardPropNames (Updates))
(* * Changes to NCCARDS)

(DEFINEQ

(NC.EditProperties
  (LAMBDA (TextStream)                                       (* rht: "16-Jan-87 12:11")
                                                             (* Open a property list editor for the card 
							     corresponding to TextStream.
							     Called from Title bar menus.)

          (* * fgh 11/13/85 Updated to handle Card object.)



          (* * rht 4/11/86: No longer sticks dates and Updates in property list. Only user-defined stuff.)



          (* * kef 7/22/86: Added call to card's obtain write permission function for the PROPLIST.)



          (* * fgh 8/30/86 Converted APPLY* to NC.ApplyFn.)



          (* * rht 1/16/87: Now uses NC.SystemCardPropNames globalvar.)


    (DECLARE (GLOBALVARS NC.SystemCardPropNames))
    (LET ((Card (NC.CoerceToCard (WINDOW.FROM.TEDIT.THING TextStream)))
	  PropList PropEditorWindow)
         (SETQ PropList (NC.FetchPropList Card))
         (COND
	   ((NC.ApplyFn ObtainWritePermissionFn Card (QUOTE PROPLIST))
	     (WINDOWPROP (SETQ PropEditorWindow (NC.OpenPropListEditor
			       TextStream
			       (for SubList on PropList by (CDDR SubList)
				  when (NOT (FMEMB (CAR SubList)
							 NC.SystemCardPropNames))
				  join (LIST (CAR SubList)
						 (CADR SubList)))
			       "Edit Property List"))
			   (QUOTE ReleaseWritePermissionP)
			   T)
	     PropEditorWindow)
	   (T (NC.CardPartBusy Card (QUOTE PROPLIST)))))))

(NC.ProcessEditedPropList
  (LAMBDA (EditedPropList OldPropList Card)                  (* rht: "16-Jan-87 13:28")
                                                             (* Take an edited prop list and set the prop list of 
							     the card as required.)

          (* * rht 2/1/85: Removed call to NC.MarkCardDirty.)



          (* * fgh 11/13/85 Updated to handle Card object.)



          (* * rht 11/13/86: No longer "spreads" out prop values.)



          (* * rht 1/16/87: Revised wholesale to fix bugs with prop ordering and prop deletion.)


    (DECLARE (GLOBALVARS NC.SystemCardPropNames))
    (LET ((CurPropList (NC.FetchPropList Card)))
         (NC.SetPropList Card (NCONC (for PropName in NC.SystemCardPropNames
					    join (LIST PropName (LISTGET CurPropList PropName)))
					 (for Item in EditedPropList
					    join (LET* ((Prop (fetch (PropListItem PropertyName)
								   of Item))
							  (NewValue
							    (if (ZEROP (NCHARS (CADR Item)))
								then NIL
							      else (CADR Item))))
						         (LIST Prop (if (fetch (PropListItem
										       
										  OriginalListFlg)
									       of (FASSOC Prop 
										      OldPropList))
									  then (LIST NewValue)
									else NewValue))))))
         (NC.SetPropListDirtyFlg Card T))))

(NC.ExtractPropList
  (LAMBDA (editW)                                            (* rht: "16-Jan-87 12:29")
                                                             (* Exctract the prop list from the TextStream in prop 
							     list editor window editW)

          (* * rht 1/16/87: Now makes sure tobj isn't empty before searching for items.)


    (LET ((tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	  menuStream button propName (propValue T)
	  EOL
	  (CH# 1)
	  (propList (WINDOWPROP editW (QUOTE PROPERTYLIST.BEING.EDITED))))
                                                             (* Move through each field/value pair in menu.
							     Update each PROP in the list.)
                                                             (* For each property in the list, move to the next 
							     field, and drop its value into the field slot.)
         (SETQ menuStream (fetch STREAMHINT of tobj))
                                                             (* for each button in the menu do)
         (AND (GREATERP (fetch (TEXTOBJ TEXTLEN) of tobj)
			    1)
		(while (SETQ button (MBUTTON.FIND.NEXT.BUTTON tobj CH#))
		   collect                                 (* Convert the name of the button into the property 
							     name)
                                                             (* Set up the looks of the fields so that 
							     MBUTTON.NEXT.FIELD will work correctly -- Real kludge 
							     to get around limitations in TEditMenu stuff)
			     (TEDIT.LOOKS tobj (QUOTE (PROTECTED ON SELECTPOINT ON))
					    (IPLUS 4 (CDR button))
					    1)
			     (COND
			       ((SETQ EOL (MBUTTON.FIND.NEXT.BUTTON tobj (IPLUS 4 (CDR button)
										      )))
				 (SETQ EOL (IDIFFERENCE (CDR EOL)
							    2)))
			       (T (SETQ EOL (SUB1 (TEDIT.FIND tobj (CHARACTER 13)
								    (CDR button))))))
			     (TEDIT.LOOKS tobj (QUOTE (PROTECTED OFF))
					    (IPLUS 4 (CDR button))
					    (IDIFFERENCE EOL (IPLUS 4 (CDR button))))
                                                             (* Get the name of the property from the butrton)
			     (SETQ propName (IMAGEOBJPROP (CAR button)
							      (QUOTE MBTEXT)))
                                                             (* Now get its value by reading the next field)
			     (SETQ propValue (MBUTTON.NEXT.FIELD.AS.TEXT.OR.IMAGEOBJ
				 tobj
				 (CDR button)))
			     (COND
			       ((NULL propValue)
				 (SETQ propValue (fetch (PropListItem Value)
						      of (FASSOC propName propList))))
			       ((IMAGEOBJP propValue))
			       ((NC.StringIsListP propValue 0)
                                                             (* This string should really be interpreted as a LIST)
				 (SETQ propValue (READ propValue)))
			       (T                            (* This really is a string)
				  (SETQ propValue (MKATOM propValue))))
                                                             (* Keep track of where that property was in the menu 
							     stream)
			     (SETQ CH# (ADD1 (CDR button)))
			     (LIST propName propValue))))))

(NC.ClosePropListEditor
  (LAMBDA (Window SaveFlg)                                   (* rht: "16-Jan-87 16:25")

          (* Close the prop list editor, saving or not saving the edited prop list as specified by the SaveFlg or by the user
	  if SaveFlg is NIL)



          (* * fgh 11/13/85 Updated to handle Card object.)



          (* * fgh 6/8/86 Added call to RAPOSITIONATTACHEDWINDOWS)



          (* * rht 8/12/86 Now uses TEXTOBJ to get TextObj from window.)



          (* * kef 7/16/86: Added the call to release the write permission should the window property declare that it be 
	  necessary.)



          (* * kef 7/22/86: Now only releases the write permission if the card is inactive. The reason is that it was 
	  determined that a card being edited would update the property list upon being closed.)



          (* * fgh 8/30/86 Converted APPLY* to NC.ApplyFn. Added Card local var.)



          (* * rht 11/12/86: Now calls MAINWINDOW instead of WINDOWPROP to get Window's mainwindow and recovers card from a 
	  prop of Window.)



          (* * rht 1/16/87: Now checks that tedit stream has been modified before using user as to whether to save changes.
	  No longer puts up stupid save/cancel menu.)


    (DECLARE (GLOBALVARS NC.SavePropEditMenu))
    (PROG (TextObj Answered OldPropList NewPropList MainWindow Card)
	    (SETQ Card (WINDOWPROP Window (QUOTE SavedCardObject)))
	    (SETQ MainWindow (MAINWINDOW Window))
	    (DETACHWINDOW Window)
	    (SETQ TextObj (CAR (NLSETQ (TEXTOBJ Window))))
	    (SETQ OldPropList (WINDOWPROP Window (QUOTE PROPERTYLIST.BEING.EDITED)))
	    (AND TextObj (COND
		     ((EQ SaveFlg (QUOTE NoSave)))
		     ((EQ (WINDOWPROP Window (QUOTE PropListEditor))
			    (QUOTE ShowOnly)))
		     ((OR (EQ SaveFlg (QUOTE Save))
			    (TEDIT.STREAMCHANGEDP TextObj))
		       (SETQ NewPropList (NC.ExtractPropList Window))
		       (NC.ProcessEditedPropList NewPropList OldPropList Card))))
	    (WINDOWPROP Window (QUOTE TEDIT.MENU)
			  NIL)
	    (WINDOWPROP Window (QUOTE TEDIT.PROPS)
			  NIL)
	    (WINDOWPROP Window (QUOTE PropListEditor)
			  NIL)
	    (WINDOWDELPROP Window (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor))
	    (COND
	      ((AND (WINDOWPROP Window (QUOTE ReleaseWritePermissionP))
		      (NOT (NC.ActiveCardP Card)))
		(NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE PROPLIST))
		(WINDOWPROP Window (QUOTE ReleaseWritePermissionP)
			      NIL)))
	    (COND
	      (TextObj (replace (TEXTOBJ \DIRTY) of TextObj with NIL)
		       (\TEDIT.QUIT (CAR (MKLIST (fetch (TEXTOBJ \WINDOW) of TextObj))))
		       (until (fetch (TEXTOBJ EDITFINISHEDFLG) of TextObj) do (BLOCK))))
	    (ADD.PROCESS (BQUOTE (PROGN (until (NULL (OPENWP , Window)) do (BLOCK))
					      (REPOSITIONATTACHEDWINDOWS , MainWindow)))))))

(NC.AddPropToPropList
  (LAMBDA (editW)                                            (* rht: "16-Jan-87 16:06")
                                                             (* Add a new prop to the propList being edited in 
							     editW)

          (* * fgh 2/10/86 Fix problem with ClearMsg deleting editing window.)



          (* * rht 4/11/86: Fixed bug whereby it couldn't add property when none exist.)



          (* * rht 1/16/87: Now uses prop names on windowprop rather than number of props. Makes sure that propname doesn't 
	  already exist and that it's not system-reserved.)


    (PROG ((promptWindow (GETPROMPTWINDOW editW 5 NIL NIL))
	     selectedObject propName propValue insertPtr insertChars beginPtr
	     (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
	     (tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	     (PropNames (WINDOWPROP editW (QUOTE PROPERTYLIST.PROPNAMES))))
	    (SETQ propName (MKATOM (NC.AskUser "New Property Name is = " NIL NIL T promptWindow)
				       ))
	    (COND
	      ((FMEMB propName PropNames)
		(NC.PrintMsg promptWindow T (CONCAT "'" propName "' property already exists."
							(CHARACTER 13)))
		(RETURN))
	      ((FMEMB propName NC.SystemCardPropNames)
		(NC.PrintMsg promptWindow T (CONCAT "'" propName 
							"' is a system-reserved property name."
							(CHARACTER 13)))
		(RETURN)))
	    (SETQ propValue (NC.AskUser (CONCAT "Value for " propName " property = ")
					    NIL NIL T promptWindow))
                                                             (* Insert these values into the editW)
	    (if PropNames
		then                                       (* Position just before selected button)
		       (NC.PrintMsg promptWindow T 
			     "Please select a property before which to insert this new property."
				      (CHARACTER 13))
		       (SETQ selectedObject (NC.SelectProperty editW))
		       (NC.ClearMsg promptWindow T)
		       (AND (NULL selectedObject)
			      (RETURN NIL))
		       (SETQ insertPtr (TEDIT.FIND.OBJECT tobj selectedObject))
	      else                                         (* No properties to insert before.)
		     (SETQ insertPtr 1))
	    (SETQ beginPtr insertPtr)                      (* Insert a button with this property name)
	    (TEDIT.INSERT.OBJECT (MBUTTON.CREATE propName (FUNCTION NC.EditPropButtonFN)
						     (FONTCREATE (QUOTE HELVETICA)
								   10
								   (QUOTE BOLD)))
				   stream insertPtr)         (* Spacer between Prop and Value)
	    (add insertPtr 1)
	    (TEDIT.INSERT stream (CHARACTER 9)
			    insertPtr)
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED ON))
			   insertPtr 1)
	    (add insertPtr 1)                              (* Create a new field (Copied from JBS's 
							     \TEXTMENU.DOC.CREATE))
	    (TEDIT.INSERT stream (CONCAT "  {}" (CHARACTER 13))
			    insertPtr)
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED ON))
			   insertPtr 5)
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED ON SELECTPOINT ON))
			   (IPLUS insertPtr 2)
			   1)
	    (TEDIT.INSERT stream (MKSTRING propValue)
			    (IPLUS insertPtr 3))
	    (TEDIT.LOOKS (TEXTOBJ stream)
			   (QUOTE (PROTECTED OFF SELECTPOINT OFF))
			   (IPLUS insertPtr 3)
			   (NCHARS (MKSTRING propValue)))
	    (add insertPtr (NCHARS (MKSTRING propValue)))
	    (add insertPtr 5)
	    (WINDOWADDPROP editW (QUOTE PROPERTYLIST.PROPNAMES)
			     propName))))

(NC.EditPropList
  (LAMBDA (propList window showOnlyFlg)                      (* rht: "16-Jan-87 16:33")

          (* * propList is a list of RECORDS of type PropListItem)



          (* * Edit a property list using the TEDIT menu-based editor. The var window is the window to use.
	  If none supplied, get one from user.)



          (* * rht 4/11/86: Now stashes length of propList on WINDOWPROP.)



          (* * rht 8/12/86: Moved code to add NC.ClosePropListEditor on CLOSEFN from NC.OpenPropListEditor to here so that it
	  can before TEDIT.DEACTIVATE.WINDOW on the CLOSEFN list.)



          (* * rht 1/16/87: Now stashes prop names on windowprop rather than number of props.)


    (PROG (menuStream textObj editW button (font (FONTCREATE (QUOTE HELVETICA)
								 8))
			(CH# 1)
			(ENDCH# 1))                          (* Init the editList and the propFnsList)
                                                             (* Create a TEDITMenu that reflects the structure of 
							     the proplist)
	    (SETQ menuStream
	      (\TEXTMENU.DOC.CREATE
		(for X in propList
		   join (NCONC (LIST (LIST (QUOTE MB.BUTTON)
						   (MKSTRING (fetch (PropListItem PropertyName)
								  of X))
						   (OR (fetch (PropListItem ButtonFn)
							    of X)
							 (FUNCTION NC.EditPropButtonFN))))
				   (COND
				     ((NOT (IMAGEOBJP (fetch (PropListItem Value) of X)))
				       (COND
					 ((fetch (PropListItem AllowEditFlg) of X)
					   (LIST (LIST (QUOTE MB.TEXT)
							   (CONCAT (CHARACTER 9)
								     "  ["
								     (MKSTRING (fetch
										   (PropListItem
										     Value)
										    of X))
								     "]"
								     (CHARACTER 13))
							   font)))
					 (T (LIST (LIST (QUOTE MB.TEXT)
							    (CHARACTER 9)
							    font)
						    (LIST (QUOTE MB.INSERT)
							    (MKSTRING (fetch (PropListItem Value)
									   of X)))
						    (LIST (QUOTE MB.TEXT)
							    (CHARACTER 13)
							    font)))))
				     (T (LIST (LIST (QUOTE MB.TEXT)
							(CHARACTER 9)
							font)
						(LIST (QUOTE MB.INSERT))
						(LIST (QUOTE MB.TEXT)
							(CHARACTER 13)
							font))))))))
	    (SETQ textObj (TEXTOBJ menuStream))          (* Go back and insert the ImageObjects into their 
							     value fields.)
	    (SETQ CH# 0)
	    (for prop in propList when (OR (IMAGEOBJP (fetch (PropListItem Value)
								   of prop))
						   (NULL (fetch (PropListItem AllowEditFlg)
							      of prop)))
	       do (MBUTTON.FIND.NEXT.FIELD textObj (SETQ CH# (ADD1 CH#)))
		    (SETQ CH# (fetch CH# of (fetch SCRATCHSEL of textObj)))
		    (COND
		      ((IMAGEOBJP (CADR prop))
			(TEDIT.INSERT.OBJECT (fetch (PropListItem Value) of prop)
					       menuStream CH#))))
	    (SETQ CH# 0)
	    (for prop in propList
	       do (SETQ button (MBUTTON.FIND.NEXT.BUTTON textObj (ADD1 CH#)))
		    (SETQ CH# (CDR button))              (* If the buttonProtect flag is on, protect the 
							     button)
		    (AND (fetch (PropListItem AllowSelectFlg) of prop)
			   (IMAGEOBJPROP (CAR button)
					   (QUOTE EditPropListNoDelete)
					   T)))              (* Set up window and window title)
	    (SETQ editW (COND
		(window window)
		(T (CREATEW (GETREGION)
			      "Edit Property List"))))       (* Point to the proplist being edited so we can update
							     it when this menu is closed.
							     (See NC.CloseEditPropListWindow))
	    (WINDOWPROP editW (QUOTE PROPERTYLIST.BEING.EDITED)
			  propList)
	    (WINDOWPROP editW (QUOTE PROPERTYLIST.PROPNAMES)
			  (for Item in propList collect (CAR Item)))
                                                             (* Set the right margin to very-far-away.
							     Prevents stuff from wrapping around)
	    (TEDIT.PARALOOKS textObj (QUOTE (RIGHTMARGIN 1000 TABS (50 (80 . LEFT))))
			       1
			       (GETFILEINFO menuStream (QUOTE LENGTH)))
                                                             (* Set the first tab so the fields will line up 
							     correctly)
                                                             (* Set selection to the top -- make it look pretty)
	    (replace (SELECTION SET) of (fetch (TEXTOBJ SEL) of textObj) with NIL)
	    (TEDIT menuStream editW NIL (LIST
		       (QUOTE MENU)
		       (create MENU
				 ITEMS ←(COND
				   (showOnlyFlg (QUOTE (("Quit" (NC.ClosePropListEditor
								    W
								    (QUOTE NoSave))
								  "Quit from pointer list display.")))
						)
				   (T (QUOTE (("Add New Property" (NC.AddPropToPropList W)
								    
					       "Add a new property to this card's property list.")
						 ("Delete Selected Property" (NC.DelPropFromList
									       W)
									     
				       "Delete selected property from this card's property list.")
						 ("Quit w/o Saving Changes" (NC.ClosePropListEditor
									      W
									      (QUOTE NoSave))
									    
					   "Quit from property list edit. Changes are not saved.")
						 ("Quit - Saving Changes" (NC.ClosePropListEditor
									    W
									    (QUOTE Save))
									  
						  "Quit from property list editor. Save changes.")))))
				 )))
	    (WINDOWADDPROP editW (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor)
			     T))))

(NC.DelPropFromList
  (LAMBDA (editW)                                            (* rht: "16-Jan-87 15:52")

          (* * rht 4/11/86: Now decrements PROPERTYLIST.LENGTH windowprop.)



          (* * rht 1/16/87: Now uses prop names on windowprop rather than number of props.)


    (PROG ((promptWindow (GETPROMPTWINDOW editW 5 NIL NIL))
	     (tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	     (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
	     selectedObject CH#)
	    (if (NULL (WINDOWPROP editW (QUOTE PROPERTYLIST.PROPNAMES)))
		then (NC.PrintMsg promptWindow T "No properties to delete.")
		       (RETURN))
	    (NC.PrintMsg promptWindow T "Please select property to be deleted.")
	    (SETQ selectedObject (NC.SelectProperty editW))
	    (NC.ClearMsg promptWindow T)
	    (if (IMAGEOBJPROP selectedObject (QUOTE EditPropListNoDelete))
		then (NC.PrintMsg promptWindow T 
				      "Selected property:value pair cannot be deleted."
				      (CHARACTER 13))
	      else (SETQ CH# (TEDIT.FIND.OBJECT tobj selectedObject))
		     (MBUTTON.FIND.NEXT.FIELD tobj CH#)    (* Delete everything between the imageobj and the 
							     end-of-line.)
		     (TEDIT.LOOKS tobj (QUOTE (PROTECTED OFF))
				    CH#
				    (IPLUS 2 (IDIFFERENCE (fetch CHLIM
								 of (fetch SCRATCHSEL
									 of tobj))
							      CH#)))
		     (TEDIT.DELETE stream CH# (IPLUS 2 (IDIFFERENCE (fetch CHLIM
									     of (fetch SCRATCHSEL
										     of tobj))
									  CH#)))
		     (TEDIT.SETSEL stream (GETEOFPTR stream)
				     0
				     (QUOTE RIGHT))
		     (WINDOWDELPROP editW (QUOTE PROPERTYLIST.PROPNAMES)
				      (IMAGEOBJPROP selectedObject (QUOTE MBTEXT)))))))
)
(PUTPROPS RHTPATCH180 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1600 22713 (NC.EditProperties 1610 . 3163) (NC.ProcessEditedPropList 3165 . 4616) (
NC.ExtractPropList 4618 . 8016) (NC.ClosePropListEditor 8018 . 11185) (NC.AddPropToPropList 11187 . 
14961) (NC.EditPropList 14963 . 20817) (NC.DelPropFromList 20819 . 22711)))))
STOP