GitViewApplication Class Reference
[Git model example]

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

Inheritance diagram for GitViewApplication:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 GitViewApplication (const WEnvironment &env)
 Constructor.

Private Member Functions

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

Private Attributes

WLineEditrepositoryEdit_
WLineEditrevisionEdit_
WTextrepositoryError_
WTextrevisionError_
GitModelgitModel_
WTreeViewgitView_
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 ( const WEnvironment env  )  [inline]

Constructor.

Definition at line 44 of file GitView.C.

00045     : WApplication(env)
00046   {
00047     useStyleSheet("gitview.css");
00048     setTitle("Git model example");
00049 
00050     const char *gitRepo = getenv("GITVIEW_REPOSITORY_PATH");
00051 
00052     WGridLayout *grid = new WGridLayout();
00053     grid->addWidget(new WText("Git repository path:"), 0, 0);
00054     grid->addWidget(repositoryEdit_ = new WLineEdit(gitRepo ? gitRepo : "")
00055                     , 0, 1, AlignLeft);
00056     grid->addWidget(repositoryError_ = new WText(), 0, 2);
00057     grid->addWidget(new WText("Revision:"), 1, 0);
00058     grid->addWidget(revisionEdit_ = new WLineEdit("master"), 1, 1, AlignLeft);
00059     grid->addWidget(revisionError_ = new WText(), 1, 2);
00060 
00061     repositoryEdit_->setTextSize(30);
00062     revisionEdit_->setTextSize(20);
00063     repositoryError_->setStyleClass("error-msg");
00064     revisionError_->setStyleClass("error-msg");
00065 
00066     repositoryEdit_->enterPressed()
00067       .connect(SLOT(this, GitViewApplication::loadGitModel));
00068     revisionEdit_->enterPressed()
00069       .connect(SLOT(this, GitViewApplication::loadGitModel));
00070 
00071     WPushButton *b = new WPushButton("Load");
00072     b->clicked().connect(SLOT(this, GitViewApplication::loadGitModel));
00073     grid->addWidget(b, 2, 0, AlignLeft);
00074 
00075     gitView_ = new WTreeView();
00076     gitView_->resize(300, WLength::Auto);
00077     gitView_->setSortingEnabled(false);
00078     gitView_->setModel(gitModel_ = new GitModel(this));
00079     gitView_->setSelectionMode(SingleSelection);
00080     gitView_->selectionChanged().connect
00081       (SLOT(this, GitViewApplication::showFile));
00082 
00083     sourceView_ = new SourceView(DisplayRole, 
00084                                  GitModel::ContentsRole, 
00085                                  GitModel::FilePathRole);
00086     sourceView_->setStyleClass("source-view");
00087 
00088     if (environment().javaScript()) {
00089       /*
00090        * We have JavaScript: We can use layout managers so everything will
00091        * always fit nicely in the window.
00092        */
00093       WVBoxLayout *topLayout = new WVBoxLayout();
00094       topLayout->addLayout(grid, 0, AlignTop | AlignLeft);
00095 
00096       WHBoxLayout *gitLayout = new WHBoxLayout();
00097       gitLayout->setLayoutHint("table-layout", "fixed");
00098       gitLayout->addWidget(gitView_, 0);
00099       gitLayout->addWidget(sourceView_, 1);
00100       topLayout->addLayout(gitLayout, 1);
00101 
00102       root()->setLayout(topLayout);
00103       root()->setStyleClass("maindiv");
00104     } else {
00105       /*
00106        * No JavaScript: let's make the best of the situation using regular
00107        * CSS-based layout
00108        */
00109       root()->setStyleClass("maindiv");
00110       WContainerWidget *top = new WContainerWidget();
00111       top->setLayout(grid, AlignTop | AlignLeft);
00112       root()->addWidget(top);
00113       root()->addWidget(gitView_);
00114       gitView_->setFloatSide(Left);
00115       gitView_->setMargin(6);
00116       root()->addWidget(sourceView_);
00117       sourceView_->setMargin(6);
00118     }
00119   }


Member Function Documentation

void GitViewApplication::loadGitModel (  )  [inline, private]

Change repository and/or revision.

Definition at line 130 of file GitView.C.

00130                       {
00131     sourceView_->setIndex(WModelIndex());
00132     repositoryError_->setText("");
00133     revisionError_->setText("");
00134     try {
00135       gitModel_->setRepositoryPath(repositoryEdit_->text().toUTF8());
00136       try {
00137         gitModel_->loadRevision(revisionEdit_->text().toUTF8());
00138       } catch (const Git::Exception& e) {
00139         revisionError_->setText(e.what());
00140       }
00141     } catch (const Git::Exception& e) {
00142       repositoryError_->setText(e.what());
00143     }
00144   }

void GitViewApplication::showFile (  )  [inline, private]

Displayed the currently selected file.

Definition at line 148 of file GitView.C.

00148                   {
00149     if (gitView_->selectedIndexes().empty())
00150       return;
00151 
00152     WModelIndex selected = *gitView_->selectedIndexes().begin();
00153     sourceView_->setIndex(selected);
00154   }


Member Data Documentation

Definition at line 122 of file GitView.C.

Definition at line 122 of file GitView.C.

Definition at line 123 of file GitView.C.

Definition at line 123 of file GitView.C.

Definition at line 124 of file GitView.C.

Definition at line 125 of file GitView.C.

Definition at line 126 of file GitView.C.


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

Generated on Thu May 20 18:14:57 2010 for Wt by doxygen 1.5.6