]> git.lyx.org Git - features.git/blob - src/frontends/gtk/GTexinfo.C
* remove various xforms relicts, in particular:
[features.git] / src / frontends / gtk / GTexinfo.C
1 /**
2  * \file GTexinfo.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GTexinfo.h"
22
23 #include "ghelpers.h"
24
25 #include "support/filetools.h"
26
27 using std::string;
28
29 namespace lyx {
30
31 using support::onlyFilename;
32
33 namespace frontend {
34
35
36 GTexinfo::GTexinfo(Dialog & parent)
37         : GViewCB<ControlTexinfo, GViewGladeB>(parent, _("TeX Information"), false),
38           activeStyle(ControlTexinfo::cls)
39 {}
40
41
42 void GTexinfo::doBuild() {
43         string const gladeName = findGladeFile("texinfo");
44         xml_ = Gnome::Glade::Xml::create(gladeName);
45
46         Gtk::Button * button;
47         xml_->get_widget("Close", button);
48         setCancel(button);
49
50         xml_->get_widget("Refresh", button);
51         button->signal_clicked().connect(
52                 sigc::mem_fun(*this, &GTexinfo::onRefresh));
53
54         xml_->get_widget("FullPath", fullpathcheck_);
55         fullpathcheck_->signal_toggled().connect(
56                 sigc::mem_fun(*this, &GTexinfo::updateStyles));
57
58         // For both liststores
59         listCols_.add(listCol_);
60         listCols_.add(listColIndex_);
61
62         // Items ListView
63         xml_->get_widget("Items", itemsview_);
64         itemsstore_ = Gtk::ListStore::create(listCols_);
65         itemsview_->set_model(itemsstore_);
66         itemsview_->append_column("Item", listCol_);
67         listSel_ = itemsview_->get_selection();
68
69         itemsview_->signal_row_activated().connect(
70                 sigc::mem_fun(*this, &GTexinfo::onItemActivate));
71
72         // Type Selection Combobox
73         xml_->get_widget("Type", typecombo_);
74         typestore_ = Gtk::ListStore::create(listCols_);
75         typecombo_->set_model(typestore_);
76         Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
77         typecombo_->pack_start(*cell, true);
78         typecombo_->add_attribute(*cell, "text", 0);
79         typecombo_->signal_changed().connect(
80                 sigc::mem_fun(*this, &GTexinfo::onTypeComboChanged));
81
82         Gtk::TreeModel::iterator row = typestore_->append();
83         (*row)[listCol_] = _("LaTeX classes");
84         (*row)[listColIndex_] = ControlTexinfo::cls;
85         // This is the default selection
86         typecombo_->set_active(row);
87         activeStyle = ControlTexinfo::cls;
88
89         row = typestore_->append();
90         (*row)[listCol_] = _("LaTeX styles");
91         (*row)[listColIndex_] = ControlTexinfo::sty;
92
93         row = typestore_->append();
94         (*row)[listCol_] = _("BibTeX styles");
95         (*row)[listColIndex_] = ControlTexinfo::bst;
96
97         updateStyles();
98 }
99
100
101 void GTexinfo::onItemActivate(
102         Gtk::TreeModel::Path const & path,
103         Gtk::TreeViewColumn * /* col */)
104 {
105         int const choice =
106                 (*itemsstore_->get_iter(path))[listColIndex_];
107
108         ContentsType const & data = texdata_[activeStyle];
109
110         string file = data[choice];
111         if (!fullpathcheck_->get_active())
112                 file = getTexFileFromList(data[choice],
113                                 controller().getFileType(activeStyle));
114
115         if (choice >= 0 && choice <= int(data.size() - 1))
116                 controller().viewFile(file);
117 }
118
119
120 void GTexinfo::onTypeComboChanged()
121 {
122         int const typeindex =
123                 (*typecombo_->get_active())[listColIndex_];
124         activeStyle = static_cast<ControlTexinfo::texFileSuffix>(typeindex);
125         updateStyles();
126 }
127
128
129 void GTexinfo::onRefresh()
130 {
131         // makes sense only if the rights are set well for
132         // users (/var/lib/texmf/ls-R)
133         texhash();
134         rescanTexStyles();
135         updateStyles();
136 }
137
138
139 void GTexinfo::updateStyles()
140 {
141         ContentsType & data = texdata_[activeStyle];
142         bool const withFullPath = fullpathcheck_->get_active();
143         getTexFileList(activeStyle, data, withFullPath);
144
145         itemsstore_->clear();
146         ContentsType::const_iterator it  = data.begin();
147         ContentsType::const_iterator end = data.end();
148         for (int rowindex = 0; it != end; ++it, ++rowindex) {
149                 Gtk::TreeModel::iterator row = itemsstore_->append();
150                 (*row)[listCol_] = *it;
151                 (*row)[listColIndex_] = rowindex;
152         }
153 }
154
155 } // namespace frontend
156 } // namespace lyx