1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "print_form.h"
|
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "LString.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
#include "support/path.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/syscall.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
2000-04-12 14:20:08 +00:00
|
|
|
#include "bufferview_funcs.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
#include "exporter.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
extern FD_form_sendto * fd_form_sendto;
|
|
|
|
extern BufferView * current_view;
|
2000-01-11 01:59:00 +00:00
|
|
|
extern int MakeLaTeXOutput(Buffer * buffer);
|
|
|
|
extern bool CreatePostscript(Buffer * buffer, bool wait);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Whereas this feature is under the menu item File->Export->Custom,
|
|
|
|
// I kept the old name sendto in the code because I am lazy (JMarc)
|
|
|
|
|
|
|
|
void MenuSendto()
|
|
|
|
{
|
2000-08-03 21:17:52 +00:00
|
|
|
static int ow = -1;
|
|
|
|
static int oh;
|
1999-10-25 14:50:26 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// do this only if the command is empty
|
|
|
|
if (!fl_get_input(fd_form_sendto->input_cmd) &&
|
2000-03-12 10:35:05 +00:00
|
|
|
!lyxrc.custom_export_command.empty())
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(fd_form_sendto->input_cmd,
|
2000-03-12 10:35:05 +00:00
|
|
|
lyxrc.custom_export_command.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
if (fd_form_sendto->form_sendto->visible) {
|
|
|
|
fl_raise_form(fd_form_sendto->form_sendto);
|
|
|
|
} else {
|
|
|
|
fl_show_form(fd_form_sendto->form_sendto,
|
2000-11-08 09:39:46 +00:00
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Send Document to Command"));
|
1999-10-25 14:50:26 +00:00
|
|
|
if (ow < 0) {
|
|
|
|
ow = fd_form_sendto->form_sendto->w;
|
|
|
|
oh = fd_form_sendto->form_sendto->h;
|
|
|
|
}
|
|
|
|
fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void SendtoApplyCB(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
if (!current_view->available())
|
|
|
|
return;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string command = fl_get_input(fd_form_sendto->input_cmd);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (command.empty())
|
|
|
|
return;
|
1999-11-09 23:52:04 +00:00
|
|
|
Buffer * buffer = current_view->buffer();
|
1999-10-02 16:21:10 +00:00
|
|
|
string ftypeext;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
|
|
|
|
ftypeext = ".lyx";
|
|
|
|
else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
|
|
|
|
ftypeext = ".tex";
|
|
|
|
else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
|
|
|
|
ftypeext = ".dvi";
|
|
|
|
else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
|
|
|
|
ftypeext = ".txt";
|
|
|
|
else {
|
2000-08-30 03:40:51 +00:00
|
|
|
ftypeext = ".ps";
|
|
|
|
if (!Exporter::Export(buffer, "ps", true))
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-12-03 13:51:01 +00:00
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
string const fname = OnlyFilename(ChangeExtension(buffer->getLatexName(),
|
|
|
|
ftypeext));
|
1999-10-02 16:21:10 +00:00
|
|
|
if (!contains(command, "$$FName"))
|
1999-09-27 18:44:28 +00:00
|
|
|
command = "( " + command + " ) <$$FName";
|
1999-11-04 01:40:20 +00:00
|
|
|
command = subst(command, "$$FName", fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
command += " &"; // execute in background
|
|
|
|
// push directorypath, if necessary
|
1999-12-10 00:07:59 +00:00
|
|
|
string path = OnlyPath(buffer->fileName());
|
2000-03-12 10:35:05 +00:00
|
|
|
if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
|
1999-09-27 18:44:28 +00:00
|
|
|
path = buffer->tmppath;
|
|
|
|
}
|
1999-10-13 17:32:46 +00:00
|
|
|
Path p(path);
|
1999-09-27 18:44:28 +00:00
|
|
|
// save the .lyx file in tmp_dir if this filetype is requested
|
|
|
|
if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
|
1999-11-15 12:01:38 +00:00
|
|
|
buffer->writeFile(fname, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
// if the .tex file is requested save it to the tempdir
|
2000-01-11 01:59:00 +00:00
|
|
|
// as now we don't do the MakeLaTeXOutput anymore
|
1999-09-27 18:44:28 +00:00
|
|
|
if (fl_get_button(fd_form_sendto->radio_ftype_latex))
|
1999-11-15 12:01:38 +00:00
|
|
|
buffer->makeLaTeXFile(fname, path, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
// create the .txt file in tmp_dir if this filetype is requested
|
|
|
|
if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
|
2000-03-12 10:35:05 +00:00
|
|
|
buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
|
1999-09-27 18:44:28 +00:00
|
|
|
Systemcalls one(Systemcalls::System, command);
|
|
|
|
}
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void SendtoCancelCB(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
fl_hide_form(fd_form_sendto->form_sendto);
|
|
|
|
}
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
|
|
|
|
void SendtoOKCB(FL_OBJECT * ob, long data)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
SendtoCancelCB(ob, data);
|
|
|
|
SendtoApplyCB(ob, data);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|