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"
18 extern FD_form_sendto * fd_form_sendto;
19 extern BufferView * current_view;
20 extern int MakeLaTeXOutput(Buffer * buffer);
21 extern bool CreatePostscript(Buffer * buffer, bool wait);
23 // Whereas this feature is under the menu item File->Export->Custom,
24 // I kept the old name sendto in the code because I am lazy (JMarc)
31 // do this only if the command is empty
32 if (!fl_get_input(fd_form_sendto->input_cmd) &&
33 !lyxrc.custom_export_command.empty())
34 fl_set_input(fd_form_sendto->input_cmd,
35 lyxrc.custom_export_command.c_str());
36 if (fd_form_sendto->form_sendto->visible) {
37 fl_raise_form(fd_form_sendto->form_sendto);
39 fl_show_form(fd_form_sendto->form_sendto,
40 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
41 _("Send Document to Command"));
43 ow = fd_form_sendto->form_sendto->w;
44 oh = fd_form_sendto->form_sendto->h;
46 fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
51 void SendtoApplyCB(FL_OBJECT *, long)
53 if (!current_view->available())
56 string command = fl_get_input(fd_form_sendto->input_cmd);
59 Buffer * buffer = current_view->buffer();
61 if (fl_get_button(fd_form_sendto->radio_ftype_dvi) ||
62 fl_get_button(fd_form_sendto->radio_ftype_ps)) {
63 ProhibitInput(current_view);
64 // Generate dvi file and check if there are errors in the .lyx file
65 if (MakeLaTeXOutput(buffer) > 0) {
66 AllowInput(current_view);
69 AllowInput(current_view);
73 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
75 else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
77 else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
79 else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
84 if (!Exporter::Export(buffer, "ps", true))
88 if (!CreatePostscript(buffer, true)) {
94 string fname = OnlyFilename(ChangeExtension(buffer->getLatexName(),
96 if (!contains(command, "$$FName"))
97 command = "( " + command + " ) <$$FName";
98 command = subst(command, "$$FName", fname);
99 command += " &"; // execute in background
100 // push directorypath, if necessary
101 string path = OnlyPath(buffer->fileName());
102 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
103 path = buffer->tmppath;
106 // save the .lyx file in tmp_dir if this filetype is requested
107 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
108 buffer->writeFile(fname, true);
109 // if the .tex file is requested save it to the tempdir
110 // as now we don't do the MakeLaTeXOutput anymore
111 if (fl_get_button(fd_form_sendto->radio_ftype_latex))
112 buffer->makeLaTeXFile(fname, path, false);
113 // create the .txt file in tmp_dir if this filetype is requested
114 if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
115 buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
116 Systemcalls one(Systemcalls::System, command);
120 void SendtoCancelCB(FL_OBJECT *, long)
122 fl_hide_form(fd_form_sendto->form_sendto);
126 void SendtoOKCB(FL_OBJECT * ob, long data)
128 SendtoCancelCB(ob, data);
129 SendtoApplyCB(ob, data);