From: H.G. Muller Date: Sat, 5 Mar 2011 22:27:48 +0000 (+0100) Subject: Make a kind of ICS text menu in XBoard as a dialog X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=3b0e14744af54a3d6e5c57d0dfe7030cd85ecb9a;p=xboard.git Make a kind of ICS text menu in XBoard as a dialog The dialog with buttons can be opened from the View menu. It is configured by the option -icsMenu; a default setting for this is included in the master settings file. The commands specified by the -icsMenu can now contain $name and $input keywords, which will be replaced by the current primary selection, or text the user types, respectively. Commands that contain $name will not be sent when the current selection is empty. Commands that do not contain $input will be sent to the ICS immediately; otherwise they will be placed in the ICS Input Box, with the cursor at the point of the $input, and input focus given to the Input Box, so the user can start typing. When a command is prefixed by "$add " it will be appended to the existing ICS Input Box contents, rather than replace it. The items now have to be separated by ";\n", and button text from command by ';' (with optional linefeed). This allows configuring of multi-line commands, as a single linefeed no longer has special sigificance. --- diff --git a/xboard.c b/xboard.c index 7b55b63..e967626 100644 --- a/xboard.c +++ b/xboard.c @@ -454,6 +454,7 @@ void UciMenuProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void TimeControlProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void OptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void NewVariantProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void IcsTextProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void FirstSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void SecondSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void GameListOptionsPopUp P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); @@ -646,6 +647,7 @@ MenuItem viewMenu[] = { {N_("Move History Alt+Shift+H"), "Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code {N_("Evaluation Graph Alt+Shift+E"), "Show Evaluation Graph", EvalGraphProc}, {N_("Game List Alt+Shift+G"), "Show Game List", ShowGameListProc}, + {N_("ICS text menu"), "ICStex", IcsTextProc}, {"----", NULL, NothingProc}, {N_("Tags"), "Show Tags", EditTagsProc}, {N_("Comments"), "Show Comments", EditCommentProc}, @@ -2793,6 +2795,7 @@ Enables ncpEnables[] = { { "menuMode.Two Machines", False }, { "menuMode.Machine Match", False }, { "menuMode.ICS Client", False }, + { "menuView.ICStex", False }, { "menuView.ICS Input Box", False }, { "Action", False }, { "menuEdit.Revert", False }, @@ -2801,10 +2804,10 @@ Enables ncpEnables[] = { { "menuEngine.Engine #2 Settings", False }, { "menuEngine.Move Now", False }, { "menuEngine.Retract Move", False }, + { "menuOptions.ICS", False }, #ifndef OPTIONSDIALOG { "menuOptions.Auto Flag", False }, { "menuOptions.Auto Flip View", False }, - { "menuOptions.ICS", False }, // { "menuOptions.ICS Alarm", False }, { "menuOptions.Move Sound", False }, { "menuOptions.Hide Thinking", False }, @@ -2818,6 +2821,7 @@ Enables ncpEnables[] = { Enables gnuEnables[] = { { "menuMode.ICS Client", False }, + { "menuView.ICStex", False }, { "menuView.ICS Input Box", False }, { "menuAction.Accept", False }, { "menuAction.Decline", False }, diff --git a/xboard.conf.in b/xboard.conf.in index 1c0b737..590f5a5 100644 --- a/xboard.conf.in +++ b/xboard.conf.in @@ -65,6 +65,34 @@ -materialDraws true -trivialDraws false ; +; Configure the ICS text menu +; +-icsMenu {Give me;ptell Please give me $input; +Avoid;ptell Please don't let him get $input; +Q;$add a Queen $input; +R;$add a Rook $input; +B;$add a Bishop $input; +N;$add a Knight $input; +P;$add a Pawn $input; +Dead;ptell I will be checkmated; +MultiLine; +set open 0 +set seek 0 +set tell 1; +Kill;ptell I will checkmate him!; +Who;who; +Finger (name);finger $name; +Players;players; +Vars (name);vars $name; +Games;games; +Observe (name);observe $name; +Sought;sought; +Match (name);match $name; +Tell (name);tell $name $input; +Play (name);play $name; +Message (name);message $name $input; +} +; ; Save user settings. ; Must be last in file to make user options prevail over system-wide settings! ; diff --git a/xoptions.c b/xoptions.c index 8dbf32a..b41f007 100644 --- a/xoptions.c +++ b/xoptions.c @@ -50,6 +50,7 @@ extern char *getenv(); #include #include #include +#include #include #include #include @@ -1665,6 +1666,87 @@ void MatchOptionsProc(w, event, prms, nprms) GenericPopUp(matchOptions, _("Match Options"), 0); } +Option textOptions[100]; +extern char *icsTextMenuString; +void PutText P((char *text, int pos)); + +SendString(char *p) +{ + char buf[MSG_SIZ], *q; + if(q = strstr(p, "$input")) { + if(!shellUp[4]) return; + strncpy(buf, p, MSG_SIZ); + strncpy(buf + (q-p), q+6, MSG_SIZ-(q-p)); + PutText(buf, q-p); + return; + } + snprintf(buf, MSG_SIZ, "%s\n", p); + SendToICS(buf); +} + +/* function called when the data to Paste is ready */ +static void +SendTextCB(Widget w, XtPointer client_data, Atom *selection, + Atom *type, XtPointer value, unsigned long *len, int *format) +{ + char buf[MSG_SIZ], *p = (char*) textOptions[(int) client_data].choice, *name = (char*) value, *q; + if (value==NULL || *len==0) return; /* nothing selected, abort */ + name[*len]='\0'; + strncpy(buf, p, MSG_SIZ); + q = strstr(p, "$name"); + snprintf(buf + (q-p), MSG_SIZ -(q-p), "%s%s", name, q+5); + SendString(buf); + XtFree(value); +} + +void SendText(int n) +{ + char *p = (char*) textOptions[n].choice; + if(strstr(p, "$name")) { + XtGetSelectionValue(menuBarWidget, + XA_PRIMARY, XA_STRING, + /* (XtSelectionCallbackProc) */ SendTextCB, + (XtPointer) n, /* client_data passed to PastePositionCB */ + CurrentTime + ); + } else SendString(p); +} + +void IcsTextProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + int i=0, j; + char *p, *q, *r; + if((p = icsTextMenuString) == NULL) return; + do { + q = r = p; while(*p && *p != ';') p++; + for(j=0; j