10 #include <Wt/WApplication.h>
11 #include <Wt/WContainerWidget.h>
12 #include <Wt/WEnvironment.h>
13 #include <Wt/WLineEdit.h>
14 #include <Wt/WGridLayout.h>
15 #include <Wt/WHBoxLayout.h>
16 #include <Wt/WPushButton.h>
17 #include <Wt/WTable.h>
19 #include <Wt/WTreeView.h>
20 #include <Wt/WVBoxLayout.h>
24 #include "../wt-homepage/SourceView.h"
47 useStyleSheet(
"gitview.css");
48 setTitle(
"Git model example");
50 const char *gitRepo = getenv(
"GITVIEW_REPOSITORY_PATH");
53 = std::make_unique<WGridLayout>();
54 grid->addWidget(std::make_unique<WText>(
"Git repository path:"), 0, 0);
56 repositoryEdit_ = grid->addWidget(std::make_unique<WLineEdit>(gitRepo ? gitRepo :
""),
57 0, 1, AlignmentFlag::Left);
58 repositoryError_ = grid->addWidget(std::make_unique<WText>(), 0, 2);
60 grid->addWidget(std::make_unique<WText>(
"Revision:"), 1, 0);
62 revisionEdit_ = grid->addWidget(std::make_unique<WLineEdit>(
"master"),
63 1, 1, AlignmentFlag::Left);
64 revisionError_ = grid->addWidget(std::make_unique<WText>(), 1, 2);
66 repositoryEdit_->setTextSize(30);
67 revisionEdit_->setTextSize(20);
68 repositoryError_->setStyleClass(
"error-msg");
69 revisionError_->setStyleClass(
"error-msg");
71 repositoryEdit_->enterPressed()
73 revisionEdit_->enterPressed()
76 auto button = grid->addWidget(std::make_unique<WPushButton>(
"Load"),
77 2, 0, AlignmentFlag::Left);
80 auto gitView = std::make_unique<WTreeView>();
81 gitView_ = gitView.get();
82 gitView_->resize(300, WLength::Auto);
83 gitView_->setSortingEnabled(
false);
86 = std::make_shared<GitModel>();
87 gitView_->setModel(gitModel_);
88 gitView_->setSelectionMode(SelectionMode::Single);
92 = std::make_unique<SourceView>(ItemDataRole::Display,
94 sourceView_ = sourceView.get();
95 sourceView_->setStyleClass(
"source-view");
98 if (environment().javaScript()) {
103 auto topLayout = root()->setLayout(std::make_unique<WVBoxLayout>());
104 root()->setStyleClass(
"maindiv");
105 topLayout->addLayout(std::move(grid),0);
107 auto gitLayout = std::make_unique<WHBoxLayout>();
108 gitLayout->addWidget(std::move(gitView),0);
109 gitLayout->addWidget(std::move(sourceView),1);
110 topLayout->addLayout(std::move(gitLayout),1);
116 root()->setStyleClass(
"maindiv");
118 = std::make_unique<WContainerWidget>();
119 top->setLayout(std::move(grid));
120 root()->addWidget(std::move(top));
121 root()->addWidget(std::move(gitView));
122 gitView_->setFloatSide(Side::Left);
123 gitView_->setMargin(6);
124 root()->addWidget(std::move(sourceView));
125 sourceView_->setMargin(6);
139 sourceView_->
setIndex(WModelIndex());
140 repositoryError_->setText(
"");
141 revisionError_->setText(
"");
143 gitModel_->setRepositoryPath(repositoryEdit_->text().toUTF8());
145 gitModel_->loadRevision(revisionEdit_->text().toUTF8());
147 revisionError_->setText(e.what());
150 repositoryError_->setText(e.what());
157 if (gitView_->selectedIndexes().empty())
160 WModelIndex selected = *gitView_->selectedIndexes().begin();
167 return std::make_unique<GitViewApplication>(env);
170 int main(
int argc,
char **argv)
int main(int argc, char **argv)
std::unique_ptr< WApplication > createApplication(const WEnvironment &env)
static const ItemDataRole ContentsRole
The role which may be used on a file to retrieve its contents.
static const ItemDataRole FilePathRole
A simple application to navigate a git repository.
void loadGitModel()
Change repository and/or revision.
WLineEdit * repositoryEdit_
GitViewApplication(const WEnvironment &env)
Constructor.
std::shared_ptr< GitModel > gitModel_
void showFile()
Displayed the currently selected file.
View class for source code.
bool setIndex(const WModelIndex &index)
Sets the model index.