]> git.lyx.org Git - lyx.git/blob - src/LyXSendto.C
Remove the optional bool argument to ChangeExtension().
[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 "gettext.h"
14 //#include "lyx_cb.h"
15 #include "bufferview_funcs.h"
16
17 extern FD_form_sendto * fd_form_sendto;
18 extern BufferView * current_view;
19 extern int MakeLaTeXOutput(Buffer * buffer);
20 extern bool CreatePostscript(Buffer * buffer, bool wait);
21
22 // Whereas this feature is under the menu item File->Export->Custom,
23 // I kept the old name sendto in the code because I am lazy (JMarc)
24
25 void MenuSendto()
26 {
27     static int ow = -1, oh;
28
29     // do this only if the command is empty
30     if (!fl_get_input(fd_form_sendto->input_cmd) &&
31         !lyxrc.custom_export_command.empty())
32         fl_set_input(fd_form_sendto->input_cmd,
33                      lyxrc.custom_export_command.c_str());
34     if (fd_form_sendto->form_sendto->visible) {
35         fl_raise_form(fd_form_sendto->form_sendto);
36     } else {  
37         fl_show_form(fd_form_sendto->form_sendto,
38                      FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
39                      _("Send Document to Command"));
40         if (ow < 0) {
41                 ow = fd_form_sendto->form_sendto->w;
42                 oh = fd_form_sendto->form_sendto->h;
43         }
44         fl_set_form_minsize(fd_form_sendto->form_sendto, ow, oh);
45     }
46 }
47
48
49 void SendtoApplyCB(FL_OBJECT *, long)
50 {
51     if (!current_view->available())
52         return;
53
54     string command = fl_get_input(fd_form_sendto->input_cmd);
55     if (command.empty())
56         return;
57     Buffer * buffer = current_view->buffer();
58     if (fl_get_button(fd_form_sendto->radio_ftype_dvi) ||
59         fl_get_button(fd_form_sendto->radio_ftype_ps)) {
60         ProhibitInput(current_view);
61         // Generate dvi file and check if there are errors in the .lyx file
62         if (MakeLaTeXOutput(buffer) > 0) {
63             AllowInput(current_view);
64             return;
65         }
66         AllowInput(current_view);
67     }
68     string ftypeext;
69     if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
70         ftypeext = ".lyx";
71     else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
72         ftypeext = ".tex";
73     else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
74         ftypeext = ".dvi";
75     else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
76         ftypeext = ".txt";
77     else {
78         ftypeext = ".ps_tmp";
79         if (!CreatePostscript(buffer, true)) {
80             return;
81         }
82     }
83
84     string fname = OnlyFilename(ChangeExtension(buffer->getLatexName(), ftypeext));
85     if (!contains(command, "$$FName"))
86         command = "( " + command + " ) <$$FName";
87     command = subst(command, "$$FName", fname);
88     command += " &"; // execute in background
89     // push directorypath, if necessary 
90     string path = OnlyPath(buffer->fileName());
91     if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
92         path = buffer->tmppath;
93     }
94     Path p(path);
95     // save the .lyx file in tmp_dir if this filetype is requested
96     if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
97         buffer->writeFile(fname, true);
98     // if the .tex file is requested save it to the tempdir
99     // as now we don't do the MakeLaTeXOutput anymore
100     if (fl_get_button(fd_form_sendto->radio_ftype_latex))
101         buffer->makeLaTeXFile(fname, path, false);
102     // create the .txt file in tmp_dir if this filetype is requested
103     if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
104         buffer->writeFileAscii(fname, lyxrc.ascii_linelen);
105     Systemcalls one(Systemcalls::System, command);    
106 }
107
108
109 void SendtoCancelCB(FL_OBJECT *, long)
110 {
111     fl_hide_form(fd_form_sendto->form_sendto);
112 }
113
114
115 void SendtoOKCB(FL_OBJECT * ob, long data)
116 {
117     SendtoCancelCB(ob, data);
118     SendtoApplyCB(ob, data);
119 }