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