From: H.G. Muller Date: Sat, 9 Apr 2011 17:22:00 +0000 (+0200) Subject: Implement Copy Game List menu item for XBoard X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=ca63c52d91e298f2b7d70535b8e5a923e4f956ac;p=xboard.git Implement Copy Game List menu item for XBoard Some WinBoard code was cloned for this. --- diff --git a/gamelist.c b/gamelist.c index c200251..4e57cb3 100644 --- a/gamelist.c +++ b/gamelist.c @@ -496,7 +496,6 @@ char * GameListLineFull( int number, GameInfo * gameInfo ) return ret; } - // --------------------------------------- Game-List options dialog -------------------------------------- // back-end diff --git a/xboard.c b/xboard.c index 6584d2a..5b0d6b2 100644 --- a/xboard.c +++ b/xboard.c @@ -322,6 +322,7 @@ void CopyPositionProc P((Widget w, XEvent *event, String *prms, void PastePositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void CopyGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void CopyGameListProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void PasteGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void SaveGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void SavePositionProc P((Widget w, XEvent *event, @@ -618,6 +619,7 @@ MenuItem fileMenu[] = { MenuItem editMenu[] = { {N_("Copy Game Ctrl+C"), "Copy Game", CopyGameProc}, {N_("Copy Position Ctrl+Shift+C"), "Copy Position", CopyPositionProc}, + {N_("Copy Game List"), "Copy Game List", CopyGameListProc}, {"----", NULL, NothingProc}, {N_("Paste Game Ctrl+V"), "Paste Game", PasteGameProc}, {N_("Paste Position Ctrl+Shift+V"), "Paste Position", PastePositionProc}, @@ -913,6 +915,7 @@ XtActionsRec boardActions[] = { { "CopyPositionProc", CopyPositionProc }, { "PastePositionProc", PastePositionProc }, { "CopyGameProc", CopyGameProc }, + { "CopyGameListProc", CopyGameListProc }, { "PasteGameProc", PasteGameProc }, { "SaveGameProc", SaveGameProc }, { "SavePositionProc", SavePositionProc }, @@ -5581,20 +5584,10 @@ SendGameSelection(Widget w, Atom *selection, Atom *target, } } -/* note: when called from menu all parameters are NULL, so no clue what the - * Widget which was clicked on was, or what the click event was - */ -void CopyGameProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; +void CopySomething() { int ret; - ret = SaveGameToFile(gameCopyFilename, FALSE); - if (!ret) return; - /* * Set both PRIMARY (the selection) and CLIPBOARD, since we don't * have a notion of a game that is selected but not copied. @@ -5612,6 +5605,33 @@ void CopyGameProc(w, event, prms, nprms) NULL/* transfer_done_proc */); } +/* note: when called from menu all parameters are NULL, so no clue what the + * Widget which was clicked on was, or what the click event was + */ +void CopyGameProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + int ret; + + ret = SaveGameToFile(gameCopyFilename, FALSE); + if (!ret) return; + + CopySomething(); +} + +void CopyGameListProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + if(!SaveGameListAsText(fopen(gameCopyFilename, "w"))) return; + CopySomething(); +} + /* function called when the data to Paste is ready */ static void PasteGameCB(Widget w, XtPointer client_data, Atom *selection, diff --git a/xgamelist.c b/xgamelist.c index 793eeb5..d2cf8bd 100644 --- a/xgamelist.c +++ b/xgamelist.c @@ -618,6 +618,35 @@ GameListIsUp() return glc && glc->up; } +int SaveGameListAsText(FILE *f) +{ + ListGame * lg = (ListGame *) gameList.head; + int nItem; + + if( ((ListGame *) gameList.tailPred)->number <= 0 ) { + DisplayError("Game list not loaded or empty", 0); + return False; + } + + /* Copy the list into the global memory block */ + if( f != NULL ) { + + lg = (ListGame *) gameList.head; + + for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){ + char * st = GameListLineFull(lg->number, &lg->gameInfo); + char *line = GameListLine(lg->number, &lg->gameInfo); + if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) ) + fprintf( f, "%s\n", st ); + free(st); free(line); + lg = (ListGame *) lg->node.succ; + } + + fclose(f); + return True; + } + return False; +} //--------------------------------- Game-List options dialog ------------------------------------------ Widget gameListOptShell, listwidg;