72 lines
2.0 KiB
C
72 lines
2.0 KiB
C
/* --------------------------------------------------------------------- *
|
|
* filesave.c *
|
|
* --------------------------------------------------------------------- *
|
|
* This file is part of the nebula irc client *
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/Text.h>
|
|
#include <Xm/SelectioB.h>
|
|
#include <Xm/FileSB.h>
|
|
|
|
#include "main.h"
|
|
|
|
extern Widget outputArea;
|
|
|
|
void saveFileCbk (Widget w, XtPointer clientData, XtPointer callData);
|
|
|
|
void saveFile(Widget parent)
|
|
{
|
|
Widget selDialog;
|
|
Widget remove;
|
|
XmString theXmString;
|
|
Arg args[1];
|
|
|
|
theXmString = XM_STRING_CREATE("Save As");
|
|
XtSetArg(args[0], XmNdialogTitle, theXmString);
|
|
selDialog = XmCreateFileSelectionDialog(parent, "select", args, 1);
|
|
XtAddCallback(selDialog, XmNokCallback, saveFileCbk, NULL);
|
|
XtAddCallback(selDialog, XmNcancelCallback, saveFileCbk, NULL);
|
|
remove = XmSelectionBoxGetChild(selDialog, XmDIALOG_HELP_BUTTON);
|
|
XtUnmanageChild(remove);
|
|
XtManageChild(selDialog);
|
|
}
|
|
|
|
void saveFileCbk (Widget w, XtPointer clientData, XtPointer callData)
|
|
{
|
|
char *fileName;
|
|
XmFileSelectionBoxCallbackStruct *cbStruct;
|
|
|
|
cbStruct = (XmFileSelectionBoxCallbackStruct *)callData;
|
|
|
|
if (cbStruct->reason == XmCR_OK)
|
|
{
|
|
FILE *outFile;
|
|
char *text;
|
|
size_t textLen;
|
|
|
|
|
|
/* ##### XmSTRING_DEFAULT_CHARSET is motif 1.1 ##### */
|
|
XmStringGetLtoR(cbStruct->value, XmSTRING_DEFAULT_CHARSET, &fileName);
|
|
outFile = fopen(fileName, "w");
|
|
XtFree(fileName);
|
|
if (outFile == NULL)
|
|
{
|
|
printf("error opening file for write.\n");
|
|
return;
|
|
}
|
|
text = XmTextGetString(outputArea);
|
|
textLen = strlen(text);
|
|
fwrite(text, textLen, sizeof(char), outFile);
|
|
fclose(outFile);
|
|
XtFree(text);
|
|
XtUnmanageChild(w);
|
|
} else if (cbStruct->reason == XmCR_CANCEL)
|
|
{
|
|
XtUnmanageChild(w);
|
|
}
|
|
}
|
|
#include "copyright.h"
|