]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiTexinfo.cpp
c9eea0043480eb000f7aa41e36c638dfe7d1ccae
[features.git] / src / frontends / qt4 / GuiTexinfo.cpp
1 /**
2  * \file GuiTexinfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiTexinfo.h"
14 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16
17 #include "support/filetools.h"
18
19 #include <QCloseEvent>
20 #include <QCheckBox>
21 #include <QListWidget>
22 #include <QPushButton>
23
24 using std::string;
25 using std::vector;
26
27 namespace lyx {
28 namespace frontend {
29
30 /////////////////////////////////////////////////////////////////////
31 //
32 // GuiTexinfoDialog
33 //
34 /////////////////////////////////////////////////////////////////////
35
36
37 GuiTexinfoDialog::GuiTexinfoDialog(GuiTexinfo * form)
38         : form_(form)
39 {
40         setupUi(this);
41
42         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
43
44         connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
45         connect(whatStyleCO, SIGNAL(activated(const QString &)),
46                 this, SLOT(enableViewPB()));
47         connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(update()));
48         connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(update()));
49         connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
50         connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
51         connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
52                 this, SLOT( enableViewPB() ) );
53         connect(fileListLW, SIGNAL(itemSelectionChanged()),
54                 this, SLOT(enableViewPB()));
55 }
56
57
58 void GuiTexinfoDialog::change_adaptor()
59 {
60         form_->changed();
61 }
62
63
64 void GuiTexinfoDialog::closeEvent(QCloseEvent * e)
65 {
66         form_->slotWMHide();
67         e->accept();
68 }
69
70
71 void GuiTexinfoDialog::rescanClicked()
72 {
73         // build new *Files.lst
74         rescanTexStyles();
75         form_->updateStyles();
76         enableViewPB();
77 }
78
79
80 void GuiTexinfoDialog::viewClicked()
81 {
82         size_t const fitem = fileListLW->currentRow();
83         vector<string> const & data = form_->texdata_[form_->activeStyle];
84         string file = data[fitem];
85         if (!pathCB->isChecked())
86                 file = getTexFileFromList(data[fitem],
87                         form_->controller().getFileType(form_->activeStyle));
88         form_->controller().viewFile(file);
89 }
90
91
92 void GuiTexinfoDialog::update()
93 {
94         switch (whatStyleCO->currentIndex()) {
95         case 0:
96                 form_->updateStyles(ControlTexinfo::cls);
97                 break;
98         case 1:
99                 form_->updateStyles(ControlTexinfo::sty);
100                 break;
101         case 2:
102                 form_->updateStyles(ControlTexinfo::bst);
103                 break;
104         default:
105                 break;
106         }
107
108         enableViewPB();
109 }
110
111
112 void GuiTexinfoDialog::enableViewPB()
113 {
114         viewPB->setEnabled(fileListLW->currentRow() > -1);
115 }
116
117
118 /////////////////////////////////////////////////////////////////////
119 //
120 // GuiTexinfo
121 //
122 /////////////////////////////////////////////////////////////////////
123
124
125 GuiTexinfo::GuiTexinfo(Dialog & parent)
126         : GuiView<GuiTexinfoDialog>(parent, _("TeX Information")),
127           warningPosted(false), activeStyle(ControlTexinfo::cls)
128 {
129 }
130
131
132 void GuiTexinfo::build_dialog()
133 {
134         dialog_.reset(new GuiTexinfoDialog(this));
135
136         updateStyles(ControlTexinfo::cls);
137
138         bcview().setCancel(dialog_->closePB);
139 }
140
141
142 void GuiTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
143 {
144         ContentsType & data = texdata_[whichStyle];
145         bool const withFullPath = dialog_->pathCB->isChecked();
146
147         getTexFileList(whichStyle, data, withFullPath);
148
149         dialog_->fileListLW->clear();
150         ContentsType::const_iterator it  = data.begin();
151         ContentsType::const_iterator end = data.end();
152         for (; it != end; ++it)
153                 dialog_->fileListLW->addItem(toqstr(*it));
154
155         activeStyle = whichStyle;
156 }
157
158
159 void GuiTexinfo::updateStyles()
160 {
161         updateStyles(activeStyle);
162 }
163
164 } // namespace frontend
165 } // namespace lyx
166
167
168 #include "GuiTexinfo_moc.cpp"