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"
15 #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)
27 static int ow = -1, oh;
29 // do this only if the command is empty
30 if (!fl_get_input(fd_form_sendto->input_cmd) &&
31 !lyxrc.custom_export_command.empty())
32 fl_set_input(fd_form_sendto->input_cmd,
33 lyxrc.custom_export_command.c_str());
34 if (fd_form_sendto->form_sendto->visible) {
35 fl_raise_form(fd_form_sendto->form_sendto);
37 fl_show_form(fd_form_sendto->form_sendto,
38 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
39 _("Send Document to Command"));
41 ow = fd_form_sendto->form_sendto->w;
42 oh = fd_form_sendto->form_sendto->h;
44 fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
49 void SendtoApplyCB(FL_OBJECT *, long)
51 if (!current_view->available())
54 string command = fl_get_input(fd_form_sendto->input_cmd);
57 Buffer * buffer = current_view->buffer();
58 if (fl_get_button(fd_form_sendto->radio_ftype_dvi) ||
59 fl_get_button(fd_form_sendto->radio_ftype_ps)) {
60 ProhibitInput(current_view);
61 // Generate dvi file and check if there are errors in the .lyx file
62 if (MakeLaTeXOutput(buffer) > 0) {
63 AllowInput(current_view);
66 AllowInput(current_view);
69 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
71 else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
73 else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
75 else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
79 if (!CreatePostscript(buffer, true)) {
84 string fname = OnlyFilename(ChangeExtension(buffer->getLatexName(), ftypeext));
85 if (!contains(command, "$$FName"))
86 command = "( " + command + " ) <$$FName";
87 command = subst(command, "$$FName", fname);
88 command += " &"; // execute in background
89 // push directorypath, if necessary
90 string path = OnlyPath(buffer->fileName());
91 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
92 path = buffer->tmppath;
95 // save the .lyx file in tmp_dir if this filetype is requested
96 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
97 buffer->writeFile(fname, true);
98 // if the .tex file is requested save it to the tempdir
99 // as now we don't do the MakeLaTeXOutput anymore
100 if (fl_get_button(fd_form_sendto->radio_ftype_latex))
101 buffer->makeLaTeXFile(fname, path, false);
102 // create the .txt file in tmp_dir if this filetype is requested
103 if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
104 buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
105 Systemcalls one(Systemcalls::System, command);
109 void SendtoCancelCB(FL_OBJECT *, long)
111 fl_hide_form(fd_form_sendto->form_sendto);
115 void SendtoOKCB(FL_OBJECT * ob, long data)
117 SendtoCancelCB(ob, data);
118 SendtoApplyCB(ob, data);