]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GTexinfo.C
more text cleanups from Michael
[lyx.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         if (choice >= 0 && choice <= data.size() - 1)
110                 controller().viewFile(data[choice]);
111 }
112
113
114 void GTexinfo::onTypeComboChanged()
115 {
116         int const typeindex =
117                 (*typecombo_->get_active())[listColIndex_];
118         activeStyle = static_cast<ControlTexinfo::texFileSuffix>(typeindex);
119         updateStyles();
120 }
121
122
123 void GTexinfo::onRefresh()
124 {
125         // makes sense only if the rights are set well for
126         // users (/var/lib/texmf/ls-R)
127         texhash();
128         rescanTexStyles();
129         updateStyles();
130 }
131
132
133 void GTexinfo::updateStyles()
134 {
135         ContentsType & data = texdata_[activeStyle];
136         getTexFileList(activeStyle, data);
137
138         bool const withFullPath = fullpathcheck_->get_active();
139
140         itemsstore_->clear();
141         ContentsType::const_iterator it  = data.begin();
142         ContentsType::const_iterator end = data.end();
143         for (int rowindex = 0; it != end; ++it, ++rowindex) {
144                 string const line = withFullPath ? *it : OnlyFilename(*it);
145                 Gtk::TreeModel::iterator row = itemsstore_->append();
146                 (*row)[listCol_] = line;
147                 (*row)[listColIndex_] = rowindex;
148         }
149 }
150
151 } // namespace frontend
152 } // namespace lyx