]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiShowFile.cpp
Factorize closeEvent() for GuiDialog based dialogs.
[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::updateContents()
43 {
44         setWindowTitle(toqstr(onlyFilename(filename_.absFilename())));
45
46         QString contents = toqstr(filename_.fileContents("UTF-8"));
47         if (contents.isEmpty())
48                 contents = qt_("Error -> Cannot load file!");
49
50         textTB->setPlainText(contents);
51 }
52
53
54 bool GuiShowFile::initialiseParams(string const & data)
55 {
56         filename_ = FileName(data);
57         return true;
58 }
59
60
61 void GuiShowFile::clearParams()
62 {
63         filename_.erase();
64 }
65
66
67 Dialog * createGuiShowFile(GuiView & lv) { return new GuiShowFile(lv); }
68
69
70 } // namespace frontend
71 } // namespace lyx
72
73 #include "GuiShowFile_moc.cpp"