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 96 of file GitView.C.


Constructor & Destructor Documentation

GitViewApplication::GitViewApplication ( const WEnvironment env  )  [inline]

Constructor.

Definition at line 101 of file GitView.C.

00102     : WApplication(env)
00103   {
00104     useStyleSheet("gitview.css");
00105     setTitle("Git model example");
00106 
00107     const char *gitRepo = getenv("GITVIEW_REPOSITORY_PATH");
00108 
00109     WGridLayout *grid = new WGridLayout();
00110     grid->addWidget(new WText("Git repository path:"), 0, 0);
00111     grid->addWidget(repositoryEdit_ = new WLineEdit(gitRepo ? gitRepo : "")
00112                     , 0, 1, AlignLeft);
00113     grid->addWidget(repositoryError_ = new WText(), 0, 2);
00114     grid->addWidget(new WText("Revision:"), 1, 0);
00115     grid->addWidget(revisionEdit_ = new WLineEdit("master"), 1, 1, AlignLeft);
00116     grid->addWidget(revisionError_ = new WText(), 1, 2);
00117 
00118     repositoryEdit_->setTextSize(30);
00119     revisionEdit_->setTextSize(20);
00120     repositoryError_->setStyleClass("error-msg");
00121     revisionError_->setStyleClass("error-msg");
00122 
00123     repositoryEdit_->enterPressed()
00124       .connect(SLOT(this, GitViewApplication::loadGitModel));
00125     revisionEdit_->enterPressed()
00126       .connect(SLOT(this, GitViewApplication::loadGitModel));
00127 
00128     WPushButton *b = new WPushButton("Load");
00129     b->clicked().connect(SLOT(this, GitViewApplication::loadGitModel));
00130     grid->addWidget(b, 2, 0, AlignLeft);
00131 
00132     gitView_ = new WTreeView();
00133     gitView_->resize(300, WLength::Auto);
00134     gitView_->setSortingEnabled(false);
00135     gitView_->setModel(gitModel_ = new GitModel(this));
00136     gitView_->setSelectionMode(SingleSelection);
00137     gitView_->selectionChanged().connect
00138       (SLOT(this, GitViewApplication::showFile));
00139 
00140     sourceView_ = new SourceView(GitModel::ContentsRole);
00141     sourceView_->setStyleClass("source-view");
00142 
00143     if (environment().javaScript()) {
00144       /*
00145        * We have JavaScript: We can use layout managers so everything will
00146        * always fit nicely in the window.
00147        */
00148       WVBoxLayout *topLayout = new WVBoxLayout();
00149       topLayout->addLayout(grid, 0, AlignTop | AlignLeft);
00150 
00151       WHBoxLayout *gitLayout = new WHBoxLayout();
00152       gitLayout->setLayoutHint("table-layout", "fixed");
00153       gitLayout->addWidget(gitView_, 0);
00154       gitLayout->addWidget(sourceView_, 1);
00155       topLayout->addLayout(gitLayout, 1);
00156 
00157       root()->setLayout(topLayout);
00158       root()->setStyleClass("maindiv");
00159     } else {
00160       /*
00161        * No JavaScript: let's make the best of the situation using regular
00162        * CSS-based layout
00163        */
00164       root()->setStyleClass("maindiv");
00165       WContainerWidget *top = new WContainerWidget();
00166       top->setLayout(grid, AlignTop | AlignLeft);
00167       root()->addWidget(top);
00168       root()->addWidget(gitView_);
00169       gitView_->setFloatSide(Left);
00170       gitView_->setMargin(6);
00171       root()->addWidget(sourceView_);
00172       sourceView_->setMargin(6);
00173     }
00174   }


Member Function Documentation

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

Change repository and/or revision.

Definition at line 185 of file GitView.C.

00185                       {
00186     sourceView_->setIndex(WModelIndex());
00187     repositoryError_->setText("");
00188     revisionError_->setText("");
00189     try {
00190       gitModel_->setRepositoryPath(repositoryEdit_->text().toUTF8());
00191       try {
00192         gitModel_->loadRevision(revisionEdit_->text().toUTF8());
00193       } catch (const Git::Exception& e) {
00194         revisionError_->setText(e.what());
00195       }
00196     } catch (const Git::Exception& e) {
00197       repositoryError_->setText(e.what());
00198     }
00199   }

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

Displayed the currently selected file.

Definition at line 203 of file GitView.C.

00203                   {
00204     if (gitView_->selectedIndexes().empty())
00205       return;
00206 
00207     WModelIndex selected = *gitView_->selectedIndexes().begin();
00208     sourceView_->setIndex(selected);
00209   }


Member Data Documentation

Definition at line 177 of file GitView.C.

Definition at line 177 of file GitView.C.

Definition at line 178 of file GitView.C.

Definition at line 178 of file GitView.C.

Definition at line 179 of file GitView.C.

Definition at line 180 of file GitView.C.

Definition at line 181 of file GitView.C.


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

Generated on Mon Mar 9 08:28:56 2009 for Wt by doxygen 1.5.6