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