]> git.lyx.org Git - lyx.git/blob - src/LyXSendto.C
Synching my tree with cvs.
[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 "buffer.h"
9 #include "lyx_gui_misc.h"
10 #include "gettext.h"
11 #include "bufferview_funcs.h"
12 #include "exporter.h"
13 #include "BufferView.h"
14
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/path.h"
18 #include "support/systemcall.h"
19
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);
24
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)
27
28 void MenuSendto()
29 {
30     static int ow = -1;
31     static int oh;
32
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);
40     } else {  
41         fl_show_form(fd_form_sendto->form_sendto,
42                      FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
43                      _("Send Document to Command"));
44         if (ow < 0) {
45                 ow = fd_form_sendto->form_sendto->w;
46                 oh = fd_form_sendto->form_sendto->h;
47         }
48         fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
49     }
50 }
51
52
53 void SendtoApplyCB(FL_OBJECT *, long)
54 {
55     if (!current_view->available())
56         return;
57
58     string command = fl_get_input(fd_form_sendto->input_cmd);
59     if (command.empty())
60         return;
61     Buffer * buffer = current_view->buffer();
62     string ftypeext;
63     if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
64         ftypeext = ".lyx";
65     else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
66         ftypeext = ".tex";
67     else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
68         ftypeext = ".dvi";
69     else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
70         ftypeext = ".txt";
71     else {
72         ftypeext = ".ps";
73         if (!Exporter::Export(buffer, "ps", true))
74                 return;
75     }
76
77     string const fname = OnlyFilename(ChangeExtension(buffer->getLatexName(),
78                                                       ftypeext));
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;
87     }
88     Path p(path);
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);
99     Systemcall one;
100     one.startscript(Systemcall::Wait, command);    
101 }
102
103
104 void SendtoCancelCB(FL_OBJECT *, long)
105 {
106     fl_hide_form(fd_form_sendto->form_sendto);
107 }
108
109
110 void SendtoOKCB(FL_OBJECT * ob, long data)
111 {
112     SendtoCancelCB(ob, data);
113     SendtoApplyCB(ob, data);
114 }