]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiTexinfo.cpp
shuffle some frontend stuff around. merge controller(base) and "Kernel". Make fronten...
[lyx.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
15 #include "ControlTexinfo.h"
16 #include "qt_helpers.h"
17
18 #include "support/filetools.h"
19
20 #include <QCloseEvent>
21 #include <QCheckBox>
22 #include <QListWidget>
23 #include <QPushButton>
24
25 using std::string;
26 using std::vector;
27
28
29 namespace lyx {
30 namespace frontend {
31
32 GuiTexinfoDialog::GuiTexinfoDialog(LyXView & lv)
33         : GuiDialog(lv, "texinfo")
34 {
35         setupUi(this);
36         setViewTitle(_("TeX Information"));
37         setController(new ControlTexinfo(*this));
38
39         warningPosted = false;
40         activeStyle = ControlTexinfo::cls;
41
42         connect(closePB, SIGNAL(clicked()), this, 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(updateView()));
48         connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(updateView()));
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         updateStyles(ControlTexinfo::cls);
57
58         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
59         bc().setCancel(closePB);
60 }
61
62
63 ControlTexinfo & GuiTexinfoDialog::controller() const
64 {
65         return static_cast<ControlTexinfo &>(GuiDialog::controller());
66 }
67
68
69 void GuiTexinfoDialog::change_adaptor()
70 {
71         changed();
72 }
73
74
75 void GuiTexinfoDialog::closeEvent(QCloseEvent * e)
76 {
77         slotWMHide();
78         e->accept();
79 }
80
81
82 void GuiTexinfoDialog::rescanClicked()
83 {
84         // build new *Files.lst
85         rescanTexStyles();
86         updateStyles();
87         enableViewPB();
88 }
89
90
91 void GuiTexinfoDialog::viewClicked()
92 {
93         size_t const fitem = fileListLW->currentRow();
94         vector<string> const & data = texdata_[activeStyle];
95         string file = data[fitem];
96         if (!pathCB->isChecked())
97                 file = getTexFileFromList(data[fitem],
98                         controller().getFileType(activeStyle));
99         controller().viewFile(file);
100 }
101
102
103 void GuiTexinfoDialog::updateView()
104 {
105         switch (whatStyleCO->currentIndex()) {
106                 case 0:
107                         updateStyles(ControlTexinfo::cls);
108                         break;
109                 case 1:
110                         updateStyles(ControlTexinfo::sty);
111                         break;
112                 case 2:
113                         updateStyles(ControlTexinfo::bst);
114                         break;
115                 default:
116                         break;
117         }
118
119         enableViewPB();
120 }
121
122
123 void GuiTexinfoDialog::enableViewPB()
124 {
125         viewPB->setEnabled(fileListLW->currentRow() > -1);
126 }
127
128
129 void GuiTexinfoDialog::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
130 {
131         ContentsType & data = texdata_[whichStyle];
132         bool const withFullPath = pathCB->isChecked();
133
134         getTexFileList(whichStyle, data, withFullPath);
135
136         fileListLW->clear();
137         ContentsType::const_iterator it  = data.begin();
138         ContentsType::const_iterator end = data.end();
139         for (; it != end; ++it)
140                 fileListLW->addItem(toqstr(*it));
141
142         activeStyle = whichStyle;
143 }
144
145
146 void GuiTexinfoDialog::updateStyles()
147 {
148         updateStyles(activeStyle);
149 }
150
151 } // namespace frontend
152 } // namespace lyx
153
154
155 #include "GuiTexinfo_moc.cpp"