3 #include FORMS_H_LOCATION
4 #include "print_form.h"
9 #include "lyx_gui_misc.h"
11 #include "bufferview_funcs.h"
13 #include "BufferView.h"
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/path.h"
18 #include "support/systemcall.h"
20 extern FD_form_sendto * fd_form_sendto;
21 extern BufferView * current_view;
22 extern int MakeLaTeXOutput(Buffer * buffer);
23 extern bool CreatePostscript(Buffer * buffer, bool wait);
25 // Whereas this feature is under the menu item File->Export->Custom,
26 // I kept the old name sendto in the code because I am lazy (JMarc)
33 // do this only if the command is empty
34 if (!fl_get_input(fd_form_sendto->input_cmd) &&
35 !lyxrc.custom_export_command.empty())
36 fl_set_input(fd_form_sendto->input_cmd,
37 lyxrc.custom_export_command.c_str());
38 if (fd_form_sendto->form_sendto->visible) {
39 fl_raise_form(fd_form_sendto->form_sendto);
41 fl_show_form(fd_form_sendto->form_sendto,
42 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
43 _("Send Document to Command"));
45 ow = fd_form_sendto->form_sendto->w;
46 oh = fd_form_sendto->form_sendto->h;
48 fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
53 void SendtoApplyCB(FL_OBJECT *, long)
55 if (!current_view->available())
58 string command = fl_get_input(fd_form_sendto->input_cmd);
61 Buffer * buffer = current_view->buffer();
63 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
65 else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
67 else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
69 else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
73 if (!Exporter::Export(buffer, "ps", true))
77 string const fname = OnlyFilename(ChangeExtension(buffer->getLatexName(),
79 if (!contains(command, "$$FName"))
80 command = "( " + command + " ) <$$FName";
81 command = subst(command, "$$FName", fname);
82 command += " &"; // execute in background
83 // push directorypath, if necessary
84 string path = buffer->filePath();
85 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
86 path = buffer->tmppath;
89 // save the .lyx file in tmp_dir if this filetype is requested
90 if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
91 buffer->writeFile(fname, true);
92 // if the .tex file is requested save it to the tempdir
93 // as now we don't do the MakeLaTeXOutput anymore
94 if (fl_get_button(fd_form_sendto->radio_ftype_latex))
95 buffer->makeLaTeXFile(fname, path, false);
96 // create the .txt file in tmp_dir if this filetype is requested
97 if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
98 buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
100 one.startscript(Systemcall::Wait, command);
104 void SendtoCancelCB(FL_OBJECT *, long)
106 fl_hide_form(fd_form_sendto->form_sendto);
110 void SendtoOKCB(FL_OBJECT * ob, long data)
112 SendtoCancelCB(ob, data);
113 SendtoApplyCB(ob, data);