]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTexinfo.C
Move the Texinfo dialog to the new Dialog scheme.
[lyx.git] / src / frontends / xforms / FormTexinfo.C
1 /**
2  * \file FormTexinfo.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Herbert Voss
7  *
8  * Full author contact details are available in file CREDITS
9  * \date 2001-10-01
10  */
11
12 #include <config.h>
13 #include <fstream>
14
15
16 #include "xformsBC.h"
17 #include "FormTexinfo.h"
18 #include "forms/form_texinfo.h"
19 #include "Tooltips.h"
20 #include "gettext.h"
21 #include "xforms_helpers.h"
22 #include "support/LAssert.h"
23 #include "support/lstrings.h"
24
25 #include "lyx_forms.h"
26
27 using std::vector;
28
29 typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
30
31 FormTexinfo::FormTexinfo(Dialog & parent)
32         : base_class(parent, _("LaTeX Information")),
33           activeStyle(ControlTexinfo::cls)
34 {}
35
36
37 void FormTexinfo::build() {
38         dialog_.reset(build_texinfo(this));
39
40         // callback for double click in browser to view the selected file
41         fl_set_browser_dblclick_callback(dialog_->browser,
42                                          C_FormDialogView_InputCB, 2);
43
44         string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
45         fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
46
47         updateStyles(activeStyle);
48
49         // set up the tooltips
50         string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
51                         "available only if the corresponding LyX layout file exists.");
52         tooltips().init(dialog_->choice_classes, str);
53
54         str = _("Show full path or only file name.");
55         tooltips().init(dialog_->check_fullpath, str);
56
57         str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
58         tooltips().init(dialog_->button_rescan, str);
59
60         str = _("Double click to view contents of file.");
61         tooltips().init(dialog_->browser, str);
62 #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
63         // Work-around xforms' bug; enable tooltips for browser widgets.
64         setPrehandler(dialog_->browser);
65 #endif
66
67         str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
68                 "Needed if you install a new TeX class or style. You need write "
69                 "permissions for the TeX-dirs, often /var/lib/texmf and others.");
70         tooltips().init(dialog_->button_texhash, str);
71 }
72
73
74 ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
75
76         if (ob == dialog_->button_texhash) {
77                 // makes only sense if the rights are set well for
78                 // users (/var/lib/texmf/ls-R)
79                 controller().runTexhash();
80                 // texhash requires a rescan and an update of the styles
81                 controller().rescanStyles();
82                 updateStyles(activeStyle);
83
84
85         } else if (ob == dialog_->browser && ob_value == 2) {
86                 // double click in browser: view selected file
87                 string selection = getString(dialog_->browser);
88                 if (!fl_get_button(dialog_->check_fullpath)) {
89                         // contents in browser has filenames without path
90                         // reconstruct path from controller getContents
91                         string const files = controller().getContents(activeStyle, true);
92                         vector<string> const vec = getVectorFromString(files, "\n");
93
94                         // find line in files vector
95                         vector<string>::const_iterator it = vec.begin();
96                         for (; it != vec.end(); ++it) {
97                                 if ((*it).find(selection) != string::npos) {
98                                         selection = *it;
99                                         break;
100                                 }
101                         }
102                 }
103                 if (!selection.empty()) {
104                         controller().viewFile(selection);
105                 }
106
107                 // reset the browser so that the following single-click callback doesn't do anything
108                 fl_deselect_browser(dialog_->browser);
109
110         } else if (ob == dialog_->button_rescan) {
111                 // build new *Files.lst
112                 controller().rescanStyles();
113                 updateStyles(activeStyle);
114
115         } else if (ob == dialog_->check_fullpath) {
116                 updateStyles(activeStyle);
117
118         } else if (ob == dialog_->choice_classes) {
119                 switch (fl_get_choice(dialog_->choice_classes)) {
120                 case 3:
121                         updateStyles(ControlTexinfo::bst);
122                         break;
123                 case 2:
124                         updateStyles(ControlTexinfo::sty);
125                         break;
126                 case 1:
127                 default:
128                         updateStyles(ControlTexinfo::cls);
129                 }
130         }
131
132         return ButtonPolicy::SMI_VALID;
133 }
134
135
136 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
137 {
138         fl_clear_browser(dialog_->browser);
139
140         bool const withFullPath = fl_get_button(dialog_->check_fullpath);
141
142         string const str =
143                 controller().getContents(whichStyle, withFullPath);
144         fl_add_browser_line(dialog_->browser, str.c_str());
145
146         activeStyle = whichStyle;
147 }