From e67c40abb13210481e672cad13050fa4d68d3aae Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 24 Mar 2010 17:21:47 +0100 Subject: [PATCH] Allow loading of PGN variations in XBoard Right-clicking variation comments in the comment-window was implemented through a translation. The right button is now bound to routines that set both the end and start of the selection, as setting a new start does not seem to work if the previous select-start was not completed by a select-end or extend-end. Finally the main handler uses the selection cursors to know what was clicked. --- backend.c | 1 + xboard.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-) diff --git a/backend.c b/backend.c index b2a6a01..a5e26db 100644 --- a/backend.c +++ b/backend.c @@ -15211,3 +15211,4 @@ LoadVariation(int index, char *text) CommentPopDown(); ToNrEvent(currentMove+1); } + diff --git a/xboard.c b/xboard.c index bc3a757..1d66ed2 100644 --- a/xboard.c +++ b/xboard.c @@ -274,6 +274,8 @@ void DrawPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void XDrawPosition P((Widget w, /*Boolean*/int repaint, Board board)); +void CommentClick P((Widget w, XEvent * event, + String * params, Cardinal * nParams)); void CommentPopUp P((char *title, char *label)); void CommentPopDown P((void)); void CommentCallback P((Widget w, XtPointer client_data, @@ -966,6 +968,7 @@ XtActionsRec boardActions[] = { { "AboutProc", AboutProc }, { "DebugProc", DebugProc }, { "NothingProc", NothingProc }, + { "CommentClick", (XtActionProc) CommentClick }, { "CommentPopDown", (XtActionProc) CommentPopDown }, { "EditCommentPopDown", (XtActionProc) EditCommentPopDown }, { "TagsPopDown", (XtActionProc) TagsPopDown }, @@ -1037,6 +1040,10 @@ char ICSInputTranslations[] = "Down: DownKeyProc() \n " "Return: EnterKeyProc() \n"; +// [HGM] vari: another hideous kludge: call extend-end first so we can be sure select-start works, +// as the widget is destroyed before the up-click can call extend-end +char commentTranslations[] = ": extend-end() select-start() CommentClick() \n"; + String xboardResources[] = { "*fileName*value.translations: #override\\n Return: FileNameAction()", "*question*value.translations: #override\\n Return: AskQuestionReplyAction()", @@ -4645,6 +4652,7 @@ Widget CommentCreate(name, text, mutable, callback, lines) XtSetArg(args[j], XtNwrap, XawtextWrapWord); j++; edit = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j); + XtOverrideTranslations(edit, XtParseTranslationTable(commentTranslations)); if (mutable) { j = 0; @@ -4853,6 +4861,20 @@ Widget MiscCreate(name, text, mutable, callback, lines) static int savedIndex; /* gross that this is global */ +void CommentClick (Widget w, XEvent * event, String * params, Cardinal * nParams) +{ + String val; + XawTextPosition index, dummy; + Arg arg; + + XawTextGetSelectionPos(w, &index, &dummy); + XtSetArg(arg, XtNstring, &val); + XtGetValues(w, &arg, 1); + ReplaceComment(savedIndex, val); + if(savedIndex != currentMove) ToNrEvent(savedIndex); + LoadVariation( index, val ); // [HGM] also does the actual moving to it, now +} + void EditCommentPopUp(index, title, text) int index; char *title, *text; @@ -5014,6 +5036,7 @@ void CommentPopUp(title, text) int j; Widget edit; + savedIndex = currentMove; // [HGM] vari if (commentShell == NULL) { commentShell = CommentCreate(title, text, False, CommentCallback, 4); -- 1.7.0.4