]> git.lyx.org Git - lyx.git/blob - src/LyXSendto.C
Yet another tweak from J�rgen.
[lyx.git] / src / LyXSendto.C
1 #include <config.h>
2
3 #include FORMS_H_LOCATION
4 #include "print_form.h"
5 #include "lyx_main.h"
6 #include "lyxrc.h"
7 #include "LString.h"
8 #include "support/filetools.h"
9 #include "support/path.h"
10 #include "buffer.h"
11 #include "lyx_gui_misc.h"
12 #include "support/syscall.h"
13 #include "support/lstrings.h"
14 #include "gettext.h"
15 #include "bufferview_funcs.h"
16 #include "exporter.h"
17 #include "BufferView.h"
18
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);
23
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)
26
27 void MenuSendto()
28 {
29     static int ow = -1;
30     static int oh;
31
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);
39     } else {  
40         fl_show_form(fd_form_sendto->form_sendto,
41                      FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
42                      _("Send Document to Command"));
43         if (ow < 0) {
44                 ow = fd_form_sendto->form_sendto->w;
45                 oh = fd_form_sendto->form_sendto->h;
46         }
47         fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
48     }
49 }
50
51
52 void SendtoApplyCB(FL_OBJECT *, long)
53 {
54     if (!current_view->available())
55         return;
56
57     string command = fl_get_input(fd_form_sendto->input_cmd);
58     if (command.empty())
59         return;
60     Buffer * buffer = current_view->buffer();
61     string ftypeext;
62     if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
63         ftypeext = ".lyx";
64     else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
65         ftypeext = ".tex";
66     else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
67         ftypeext = ".dvi";
68     else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
69         ftypeext = ".txt";
70     else {
71         ftypeext = ".ps";
72         if (!Exporter::Export(buffer, "ps", true))
73                 return;
74     }
75
76     string const fname = OnlyFilename(ChangeExtension(buffer->getLatexName(),
77                                                       ftypeext));
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 = buffer->filePath();
84     if (lyxrc.use_tempdir || !IsDirWriteable(path)){
85         path = buffer->tmppath;
86     }
87     Path p(path);
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);    
99 }
100
101
102 void SendtoCancelCB(FL_OBJECT *, long)
103 {
104     fl_hide_form(fd_form_sendto->form_sendto);
105 }
106
107
108 void SendtoOKCB(FL_OBJECT * ob, long data)
109 {
110     SendtoCancelCB(ob, data);
111     SendtoApplyCB(ob, data);
112 }