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