]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiShowFile.cpp
Factorize out the way window titles are handled.
[lyx.git] / src / frontends / qt4 / GuiShowFile.cpp
1 /**
2  * \file GuiShowFile.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Herbert Voß
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiShowFile.h"
15
16 #include "qt_helpers.h"
17 #include "support/filetools.h"
18
19 #include <QTextBrowser>
20 #include <QPushButton>
21 #include <QCloseEvent>
22
23 using namespace std;
24 using namespace lyx::support;
25
26 namespace lyx {
27 namespace frontend {
28
29
30 GuiShowFile::GuiShowFile(GuiView & lv)
31         : GuiDialog(lv, "file", qt_("Show File"))
32 {
33         setupUi(this);
34
35         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
36
37         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
38         bc().setCancel(closePB);
39 }
40
41
42 void GuiShowFile::closeEvent(QCloseEvent * e)
43 {
44         slotClose();
45         e->accept();
46 }
47
48
49 void GuiShowFile::updateContents()
50 {
51         setWindowTitle(toqstr(onlyFilename(filename_.absFilename())));
52
53         QString contents = toqstr(filename_.fileContents("UTF-8"));
54         if (contents.isEmpty())
55                 contents = qt_("Error -> Cannot load file!");
56
57         textTB->setPlainText(contents);
58 }
59
60
61 bool GuiShowFile::initialiseParams(string const & data)
62 {
63         filename_ = FileName(data);
64         return true;
65 }
66
67
68 void GuiShowFile::clearParams()
69 {
70         filename_.erase();
71 }
72
73
74 Dialog * createGuiShowFile(GuiView & lv) { return new GuiShowFile(lv); }
75
76
77 } // namespace frontend
78 } // namespace lyx
79
80 #include "GuiShowFile_moc.cpp"