3 #include FORMS_H_LOCATION
4 #include "print_form.h"
8 #include "support/filetools.h"
9 #include "support/path.h"
11 #include "lyx_gui_misc.h"
12 #include "support/syscall.h"
16 extern FD_form_sendto * fd_form_sendto;
17 extern BufferView * current_view;
18 extern int MakeDVIOutput(Buffer * buffer);
19 extern bool MenuRunDvips(Buffer * buffer, bool wait);
21 // Whereas this feature is under the menu item File->Export->Custom,
22 // I kept the old name sendto in the code because I am lazy (JMarc)
26 static int ow = -1, oh;
28 // do this only if the command is empty
29 if (!fl_get_input(fd_form_sendto->input_cmd) &&
30 !lyxrc->custom_export_command.empty())
31 fl_set_input(fd_form_sendto->input_cmd,
32 lyxrc->custom_export_command.c_str());
33 if (fd_form_sendto->form_sendto->visible) {
34 fl_raise_form(fd_form_sendto->form_sendto);
36 fl_show_form(fd_form_sendto->form_sendto,
37 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
38 _("Send Document to Command"));
40 ow = fd_form_sendto->form_sendto->w;
41 oh = fd_form_sendto->form_sendto->h;
43 fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
47 void SendtoApplyCB(FL_OBJECT *, long)
49 if (!current_view->available())
52 string command = fl_get_input(fd_form_sendto->input_cmd);
55 Buffer * buffer = current_view->buffer();
56 if (fl_get_button(fd_form_sendto->radio_ftype_dvi) ||
57 fl_get_button(fd_form_sendto->radio_ftype_ps)) {
59 // Generate dvi file and check if there are errors in the .lyx file
60 if (MakeDVIOutput(buffer) > 0) {
67 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
69 else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
71 else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
73 else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
77 if (!MenuRunDvips(buffer, true)) {
82 string fname = ChangeExtension(buffer->getLatexName(), ftypeext, true);
83 if (!contains(command, "$$FName"))
84 command = "( " + command + " ) <$$FName";
85 command = subst(command, "$$FName", fname);
86 command += " &"; // execute in background
87 // push directorypath, if necessary
88 string path = OnlyPath(buffer->fileName());
89 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
90 path = buffer->tmppath;
93 // save the .lyx file in tmp_dir if this filetype is requested
94 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
95 buffer->writeFile(fname, true);
96 // if the .tex file is requested save it to the tempdir
97 // as now we don't do the MakeDVIOutput anymore
98 if (fl_get_button(fd_form_sendto->radio_ftype_latex))
99 buffer->makeLaTeXFile(fname, path, false);
100 // create the .txt file in tmp_dir if this filetype is requested
101 if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
102 buffer->writeFileAscii(fname, lyxrc->ascii_linelen);
103 Systemcalls one(Systemcalls::System, command);
106 void SendtoCancelCB(FL_OBJECT *, long)
108 fl_hide_form(fd_form_sendto->form_sendto);
111 void SendtoOKCB(FL_OBJECT *ob, long data)
113 SendtoCancelCB(ob, data);
114 SendtoApplyCB(ob, data);