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"
14 #include "bufferview_funcs.h"
17 extern FD_form_sendto * fd_form_sendto;
18 extern BufferView * current_view;
19 extern int MakeLaTeXOutput(Buffer * buffer);
20 extern bool CreatePostscript(Buffer * buffer, bool wait);
22 // Whereas this feature is under the menu item File->Export->Custom,
23 // I kept the old name sendto in the code because I am lazy (JMarc)
30 // do this only if the command is empty
31 if (!fl_get_input(fd_form_sendto->input_cmd) &&
32 !lyxrc.custom_export_command.empty())
33 fl_set_input(fd_form_sendto->input_cmd,
34 lyxrc.custom_export_command.c_str());
35 if (fd_form_sendto->form_sendto->visible) {
36 fl_raise_form(fd_form_sendto->form_sendto);
38 fl_show_form(fd_form_sendto->form_sendto,
39 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
40 _("Send Document to Command"));
42 ow = fd_form_sendto->form_sendto->w;
43 oh = fd_form_sendto->form_sendto->h;
45 fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
50 void SendtoApplyCB(FL_OBJECT *, long)
52 if (!current_view->available())
55 string command = fl_get_input(fd_form_sendto->input_cmd);
58 Buffer * buffer = current_view->buffer();
60 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
62 else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
64 else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
66 else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
70 if (!Exporter::Export(buffer, "ps", true))
74 string const fname = OnlyFilename(ChangeExtension(buffer->getLatexName(),
76 if (!contains(command, "$$FName"))
77 command = "( " + command + " ) <$$FName";
78 command = subst(command, "$$FName", fname);
79 command += " &"; // execute in background
80 // push directorypath, if necessary
81 string path = OnlyPath(buffer->fileName());
82 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
83 path = buffer->tmppath;
86 // save the .lyx file in tmp_dir if this filetype is requested
87 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
88 buffer->writeFile(fname, true);
89 // if the .tex file is requested save it to the tempdir
90 // as now we don't do the MakeLaTeXOutput anymore
91 if (fl_get_button(fd_form_sendto->radio_ftype_latex))
92 buffer->makeLaTeXFile(fname, path, false);
93 // create the .txt file in tmp_dir if this filetype is requested
94 if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
95 buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
96 Systemcalls one(Systemcalls::System, command);
100 void SendtoCancelCB(FL_OBJECT *, long)
102 fl_hide_form(fd_form_sendto->form_sendto);
106 void SendtoOKCB(FL_OBJECT * ob, long data)
108 SendtoCancelCB(ob, data);
109 SendtoApplyCB(ob, data);