/** File gg_editpwin.c  => can be included in another file (gg_gtkutils.c ?)
 *  Transcripted from Motif to GTK+ by P. Vincent to
 *  Replace editpwin.c  777
 *
 *  We don'use Xbae to be able to run under MsWindows,
 *  thus, up to now, only and external editor is used
 *  
 */ 


#include <stdio.h>
#include <stdlib.h>
 
/*  unistd.h pour la fonction unlink */
#include <unistd.h>
#include <gtk/gtk.h>


#include "globals.h"
#include "utils.h"
#include "files.h"

#include "missing.h"
#include "noxprotos.h"

#include "gg_protos.h"


/*
 *  Replace do_ext_editor editpwinc  777
 */
void gg_do_ext_editor (int gno, int setno)
{
    char *fname, ebuf[256];
    FILE *cp;
    int save_autos;
    fname = copy_string (NULL ,"gracegtk_tmpXXXXXX");
    cp = gg_tmpfile (fname);
    if (cp == NULL) {
        return;
    }

    write_set (gno, setno, cp, sformat, FALSE);
    grace_close (cp);

    sprintf (ebuf, "%s %s", get_editor(), fname);
    system_wrap (ebuf);

    /* temporarily disable autoscale */
    save_autos = autoscale_onread;
    autoscale_onread = AUTOSCALE_NONE;
    if (is_set_active (gno, setno)) {
        curtype = dataset_type (gno, setno);
	killsetdata (gno, setno);	
    }
    getdata (gno, fname, SOURCE_DISK, LOAD_SINGLE);
    autoscale_onread = save_autos;
    unlink (fname);
    gg_update_all();
    gg_drawgraph();
}
