]> git.lyx.org Git - lyx.git/blob - src/LyXSendto.C
6c9058aee07bb5b23e83b81c8a2a58c6e3a3903b
[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 "filetools.h"
9 #include "pathstack.h"
10 #include "buffer.h"
11 #include "lyx_gui_misc.h"
12 #include "syscall.h"
13 #include "gettext.h"
14 #include "lyx_cb.h"
15
16 //      $Id: LyXSendto.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $ 
17
18 #if !defined(lint) && !defined(WITH_WARNINGS)
19 static char vcid[] = "$Id: LyXSendto.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
20 #endif /* lint */
21
22 /* Prototypes */
23 extern FD_form_sendto *fd_form_sendto;
24 extern BufferView *current_view;
25 extern int MakeDVIOutput(Buffer *buffer);
26 extern bool MenuRunDvips(Buffer *buffer, bool wait);
27
28 // Whereas this feature is under the menu item File->Export->Custom,
29 // I kept the old name sendto in the code because I am lazy (JMarc)
30
31 void MenuSendto()
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_FULLBORDER,
43                      _("Send Document to Command"));
44     }
45 }
46
47 void SendtoApplyCB(FL_OBJECT *, long)
48 {
49     if (!current_view->available())
50         return;
51
52     LString command = fl_get_input(fd_form_sendto->input_cmd);
53     if (command.empty())
54         return;
55     Buffer *buffer = current_view->currentBuffer();
56     if (fl_get_button(fd_form_sendto->radio_ftype_dvi) ||
57         fl_get_button(fd_form_sendto->radio_ftype_ps)) {
58         ProhibitInput();
59         // Generate dvi file and check if there are errors in the .lyx file
60         if (MakeDVIOutput(buffer) > 0) {
61             AllowInput();
62             return;
63         }
64         AllowInput();
65     }
66     LString ftypeext;
67     if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
68         ftypeext = ".lyx";
69     else if (fl_get_button(fd_form_sendto->radio_ftype_latex))
70         ftypeext = ".tex";
71     else if (fl_get_button(fd_form_sendto->radio_ftype_dvi))
72         ftypeext = ".dvi";
73     else if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
74         ftypeext = ".txt";
75     else {
76         ftypeext = ".ps_tmp";
77         if (!MenuRunDvips(buffer, true)) {
78             return;
79         }
80     }
81     LString fname = SpaceLess(ChangeExtension(buffer->getFileName(), 
82                                               ftypeext, true));
83     if (!command.contains("$$FName"))
84         command = "( " + command + " ) <$$FName";
85     command.subst("$$FName",fname);
86     command += " &"; // execute in background
87     // push directorypath, if necessary 
88     LString path = OnlyPath(buffer->getFileName());
89     if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
90         path = buffer->tmppath;
91     }
92     PathPush(path);
93     // save the .lyx file in tmp_dir if this filetype is requested
94     if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
95         buffer->writeFile(fname,true);
96     // if the .tex file is requested save it to the tempdir
97     // as now we don't do the MakeDVIOutput anymore
98     if (fl_get_button(fd_form_sendto->radio_ftype_latex))
99         buffer->makeLaTeXFile(fname,path,false);
100     // create the .txt file in tmp_dir if this filetype is requested
101     if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
102         buffer->writeFileAscii(fname, lyxrc->ascii_linelen);
103     Systemcalls one(Systemcalls::System, command);    
104     PathPop();
105 }
106
107 void SendtoCancelCB(FL_OBJECT *, long)
108 {
109     fl_hide_form(fd_form_sendto->form_sendto);
110 }
111
112 void SendtoOKCB(FL_OBJECT *ob, long data)
113 {
114     SendtoCancelCB(ob,data);
115     SendtoApplyCB(ob,data);
116 }