9#include <boost/algorithm/string.hpp>
10#include <boost/filesystem/operations.hpp>
11#include <boost/filesystem/convenience.hpp>
13#include <Wt/WApplication.h>
18namespace fs = boost::filesystem;
34 if (index !=
index_ && index.isValid()) {
35 std::string
fp = !cpp17::any_has_value(index.data(
filePathRole_)) ? std::string()
39 || (!
fp.empty() && !fs::is_directory(
fp))) {
62 return std::string(
spool);
67 if (boost::iends_with(fileName,
".h")
68 || boost::iends_with(fileName,
".C")
69 || boost::iends_with(fileName,
".cpp"))
71 else if (boost::iends_with(fileName,
".xml"))
73 else if (boost::iends_with(fileName,
".html"))
75 else if (boost::iends_with(fileName,
".java"))
77 else if (boost::iends_with(fileName,
".js"))
79 else if (boost::iends_with(fileName,
".css"))
88 std::fstream
file (fileName.c_str(), std::ios::in | std::ios::binary);
101 auto result = std::make_unique<WText>();
114 std::string fileName =
126 != std::string::npos)
139 std::ios::out | std::ios::binary);
170 if (!boost::iends_with(fileName,
".jar")
171 && !boost::iends_with(fileName,
".war")
172 && !boost::iends_with(fileName,
".class"))
175 std::unique_ptr<WWidget>
result;
178 std::unique_ptr<WImage> image(std::make_unique<WImage>());
184 result = std::move(image);
185 }
else if (
lang !=
"") {
186 auto text = std::make_unique<WText>();
187 text->setTextFormat(TextFormat::UnsafeXHTML);
191 auto text = std::make_unique<WText>();
192 text->setTextFormat(TextFormat::Plain);
198 WApplication::instance()
199 ->doJavaScript(
result->jsRef() +
".parentNode.scrollTop = 0;");
206 ".png",
".gif",
".jpg",
"jpeg",
".ico", 0
209 fs::path
p(fileName);
216 return std::string();
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
std::string readFileToString(const std::string &fileName)
std::string getLanguageFromFileExtension(const std::string &fileName)
std::string tempFileName()
virtual std::unique_ptr< WWidget > renderView()
Returns the widget that renders the view.
Wt::ItemDataRole filePathRole_
WModelIndex index_
The index that is currently displayed.
std::string imageExtension(const std::string &fileName)
bool setIndex(const WModelIndex &index)
Sets the model index.
Wt::ItemDataRole fileNameRole_
The role that is currently displayed.
std::shared_ptr< WMemoryResource > imageResource_
SourceView(ItemDataRole fileNameRole, ItemDataRole contentRole, ItemDataRole filePathRole)
Constructor.
Wt::ItemDataRole contentRole_
virtual ~SourceView()
Destructor.