]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiShowFile.cpp
next one
[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
24 namespace lyx {
25 namespace frontend {
26
27 using support::FileName;
28 using support::onlyFilename;
29
30 GuiShowFile::GuiShowFile(LyXView & lv)
31         : GuiDialog(lv, "file"), Controller(this)
32 {
33         setupUi(this);
34         setViewTitle(_("Show File"));
35         setController(this, false);
36
37         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
38
39         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
40         bc().setCancel(closePB);
41 }
42
43
44 void GuiShowFile::closeEvent(QCloseEvent * e)
45 {
46         slotClose();
47         e->accept();
48 }
49
50
51 void GuiShowFile::updateContents()
52 {
53         setWindowTitle(toqstr(onlyFilename(filename_.absFilename())));
54
55         std::string contents = support::getFileContents(filename_);
56         if (contents.empty())
57                 contents = "Error -> Cannot load file!";
58
59         textTB->setPlainText(toqstr(contents));
60 }
61
62
63 bool GuiShowFile::initialiseParams(std::string const & data)
64 {
65         filename_ = FileName(data);
66         return true;
67 }
68
69
70 void GuiShowFile::clearParams()
71 {
72         filename_.erase();
73 }
74
75
76 Dialog * createGuiShowFile(LyXView & lv) { return new GuiShowFile(lv); }
77
78
79 } // namespace frontend
80 } // namespace lyx
81
82 #include "GuiShowFile_moc.cpp"