Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CF: Advise on map editor.



Peter Mardahl writes:
 > My main gripe now is that there are not "Hot keys" for commonly used
 > functions, like "save" "cut" "paste"....  Also, I'd like to see the
 > map editor 'autojoin' two maps seamlessly.  It is a pain to do it
 > oneself.
 > 
 > Does anyone know how to bind "Alt P" to paste, for example?

It is a bit complex (at least for me, since I haven't look at the code
for some years). Difficulty is that the CrEdit widget does not know
about the Edit and App structures, it just shows a map.

1) Add a callback defintions to CrEdit.h: 

#define XtNpasteCallback "pasteCallback"
#define XtCPasteCallback "PasteCallback"


2) Then to CrEditP.h:CrEditPart structure:
    XtCallbackList pasteCallbacks;


3) Then to CrEdit.c: resources table
    },{
	XtNpasteCallback,
	XtCPasteCallback,
	XtRCallback,
	sizeof(XtCallbackList),
	Offset(pasteCallbacks),
	XtRCallback,
	NULL

4) and add a prototype for "Action":
static void PasteAc ( Widget w, XEvent * e, 
		    String * argv, Cardinal * argc );


5) and an entry to actions table
  {"Paste", PasteAc},

6) and a translation:
        Alt<Key>P:        Paste() \n\


7) then the action function:
/*
 * action: paste from clibboard
 */
static void PasteAc(Widget w, XEvent * event, String * argv, Cardinal * argc)
{
    CrEditWidget self = (CrEditWidget)w;
    struct CrEditCall call; /* not really needed */
    XtCallCallbackList(w,self->crEdit.pasteCallbacks,(XtPointer)&call);
}


8) Then look for the actual function (App.c: PasteCb), note that "client"
is a pointer to App and PasteCb is a static function, so PasteCb should be
registered to CrEdit widget somewhere in App.c. Let's do it in end of
AppEditInsert:
    XtAddCallback (edit->w, XtNpasteCallback, PasteCb, (XtPointer)self);


9) recompile, and it should be there.


Edit specific functions (like SaveAs), should be registered in end of
Edit.c:Layout() :

    XtAddCallback (self->w, XtNsaveAsCallback, SaveAsCb, (XtPointer)self);

It may be possible to create more generic actions (using those
paramters), so that not all these steps are needed.

	- Jarkko

[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]


References: