Wt examples  3.3.6
Public Member Functions | Private Member Functions | Private Attributes | List of all members
GitViewApplication Class Reference

A simple application to navigate a git repository. More...

Inheritance diagram for GitViewApplication:
Inheritance graph
[legend]

Public Member Functions

 GitViewApplication (const WEnvironment &env)
 Constructor. More...
 

Private Member Functions

void loadGitModel ()
 Change repository and/or revision. More...
 
void showFile ()
 Displayed the currently selected file. More...
 

Private Attributes

WLineEdit * repositoryEdit_
 
WLineEdit * revisionEdit_
 
WText * repositoryError_
 
WText * revisionError_
 
GitModelgitModel_
 
WTreeView * gitView_
 
SourceViewsourceView_
 

Detailed Description

A simple application to navigate a git repository.

This examples demonstrates how to use the custom model use GitModel with a WTreeView.

Definition at line 39 of file GitView.C.

Constructor & Destructor Documentation

◆ GitViewApplication()

GitViewApplication::GitViewApplication ( const WEnvironment &  env)
inline

Constructor.

Definition at line 44 of file GitView.C.

45  : WApplication(env)
46  {
47  useStyleSheet("gitview.css");
48  setTitle("Git model example");
49 
50  const char *gitRepo = getenv("GITVIEW_REPOSITORY_PATH");
51 
52  WGridLayout *grid = new WGridLayout();
53  grid->addWidget(new WText("Git repository path:"), 0, 0);
54  grid->addWidget(repositoryEdit_ = new WLineEdit(gitRepo ? gitRepo : "")
55  , 0, 1, AlignLeft);
56  grid->addWidget(repositoryError_ = new WText(), 0, 2);
57  grid->addWidget(new WText("Revision:"), 1, 0);
58  grid->addWidget(revisionEdit_ = new WLineEdit("master"), 1, 1, AlignLeft);
59  grid->addWidget(revisionError_ = new WText(), 1, 2);
60 
61  repositoryEdit_->setTextSize(30);
62  revisionEdit_->setTextSize(20);
63  repositoryError_->setStyleClass("error-msg");
64  revisionError_->setStyleClass("error-msg");
65 
66  repositoryEdit_->enterPressed()
67  .connect(this, &GitViewApplication::loadGitModel);
68  revisionEdit_->enterPressed()
69  .connect(this, &GitViewApplication::loadGitModel);
70 
71  WPushButton *b = new WPushButton("Load");
72  b->clicked().connect(this, &GitViewApplication::loadGitModel);
73  grid->addWidget(b, 2, 0, AlignLeft);
74 
75  gitView_ = new WTreeView();
76  gitView_->resize(300, WLength::Auto);
77  gitView_->setSortingEnabled(false);
78  gitView_->setModel(gitModel_ = new GitModel(this));
79  gitView_->setSelectionMode(SingleSelection);
80  gitView_->selectionChanged().connect(this, &GitViewApplication::showFile);
81 
82  sourceView_ = new SourceView(DisplayRole,
85  sourceView_->setStyleClass("source-view");
86 
87  if (environment().javaScript()) {
88  /*
89  * We have JavaScript: We can use layout managers so everything will
90  * always fit nicely in the window.
91  */
92  WVBoxLayout *topLayout = new WVBoxLayout();
93  topLayout->addLayout(grid, 0);
94 
95  WHBoxLayout *gitLayout = new WHBoxLayout();
96  gitLayout->addWidget(gitView_, 0);
97  gitLayout->addWidget(sourceView_, 1);
98  topLayout->addLayout(gitLayout, 1);
99 
100  root()->setLayout(topLayout);
101  root()->setStyleClass("maindiv");
102  } else {
103  /*
104  * No JavaScript: let's make the best of the situation using regular
105  * CSS-based layout
106  */
107  root()->setStyleClass("maindiv");
108  WContainerWidget *top = new WContainerWidget();
109  top->setLayout(grid);
110  root()->addWidget(top);
111  root()->addWidget(gitView_);
112  gitView_->setFloatSide(Left);
113  gitView_->setMargin(6);
114  root()->addWidget(sourceView_);
115  sourceView_->setMargin(6);
116  }
117  }
void loadGitModel()
Change repository and/or revision.
Definition: GitView.C:128
WText * repositoryError_
Definition: GitView.C:121
static const int ContentsRole
The role which may be used on a file to retrieve its contents.
Definition: GitModel.h:41
WTreeView * gitView_
Definition: GitView.C:123
void showFile()
Displayed the currently selected file.
Definition: GitView.C:146
WLineEdit * revisionEdit_
Definition: GitView.C:120
GitModel * gitModel_
Definition: GitView.C:122
WText * revisionError_
Definition: GitView.C:121
SourceView * sourceView_
Definition: GitView.C:124
View class for source code.
Definition: SourceView.h:26
WLineEdit * repositoryEdit_
Definition: GitView.C:120
static const int FilePathRole
Definition: GitModel.h:42
A model that retrieves revision trees from a git repository.
Definition: GitModel.h:36

Member Function Documentation

◆ loadGitModel()

void GitViewApplication::loadGitModel ( )
inlineprivate

Change repository and/or revision.

Definition at line 128 of file GitView.C.

128  {
129  sourceView_->setIndex(WModelIndex());
130  repositoryError_->setText("");
131  revisionError_->setText("");
132  try {
133  gitModel_->setRepositoryPath(repositoryEdit_->text().toUTF8());
134  try {
135  gitModel_->loadRevision(revisionEdit_->text().toUTF8());
136  } catch (const Git::Exception& e) {
137  revisionError_->setText(e.what());
138  }
139  } catch (const Git::Exception& e) {
140  repositoryError_->setText(e.what());
141  }
142  }
void setRepositoryPath(const std::string &repositoryPath)
Set the repository and load its 'master' revision.
Definition: GitModel.C:15
WText * repositoryError_
Definition: GitView.C:121
WLineEdit * revisionEdit_
Definition: GitView.C:120
GitModel * gitModel_
Definition: GitView.C:122
WText * revisionError_
Definition: GitView.C:121
SourceView * sourceView_
Definition: GitView.C:124
bool setIndex(const Wt::WModelIndex &index)
Sets the model index.
Definition: SourceView.C:30
WLineEdit * repositoryEdit_
Definition: GitView.C:120
void loadRevision(const std::string &revName)
Load a particular revision.
Definition: GitModel.C:21
Exception class.
Definition: Git.h:28

◆ showFile()

void GitViewApplication::showFile ( )
inlineprivate

Displayed the currently selected file.

Definition at line 146 of file GitView.C.

146  {
147  if (gitView_->selectedIndexes().empty())
148  return;
149 
150  WModelIndex selected = *gitView_->selectedIndexes().begin();
151  sourceView_->setIndex(selected);
152  }
WTreeView * gitView_
Definition: GitView.C:123
SourceView * sourceView_
Definition: GitView.C:124
bool setIndex(const Wt::WModelIndex &index)
Sets the model index.
Definition: SourceView.C:30

Member Data Documentation

◆ gitModel_

GitModel* GitViewApplication::gitModel_
private

Definition at line 122 of file GitView.C.

◆ gitView_

WTreeView* GitViewApplication::gitView_
private

Definition at line 123 of file GitView.C.

◆ repositoryEdit_

WLineEdit* GitViewApplication::repositoryEdit_
private

Definition at line 120 of file GitView.C.

◆ repositoryError_

WText* GitViewApplication::repositoryError_
private

Definition at line 121 of file GitView.C.

◆ revisionEdit_

WLineEdit * GitViewApplication::revisionEdit_
private

Definition at line 120 of file GitView.C.

◆ revisionError_

WText * GitViewApplication::revisionError_
private

Definition at line 121 of file GitView.C.

◆ sourceView_

SourceView* GitViewApplication::sourceView_
private

Definition at line 124 of file GitView.C.


The documentation for this class was generated from the following file:

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.13