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());
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       if (!environment().agentWebKit())
00149         sourceView_->resize(WLength(100, WLength::Percentage), WLength());
00150 
00151       WVBoxLayout *topLayout = new WVBoxLayout();
00152       topLayout->addLayout(grid, 0, AlignTop | AlignLeft);
00153 
00154       WHBoxLayout *gitLayout = new WHBoxLayout();
00155       gitLayout->setLayoutHint("table-layout", "fixed");
00156       gitLayout->addWidget(gitView_, 0);
00157       gitLayout->addWidget(sourceView_, 1);
00158       topLayout->addLayout(gitLayout, 1);
00159 
00160       root()->setLayout(topLayout);
00161       root()->setStyleClass("maindiv");
00162     } else {
00163       /*
00164        * No JavaScript: let's make the best of the situation using regular
00165        * CSS-based layout
00166        */
00167       root()->setStyleClass("maindiv");
00168       WContainerWidget *top = new WContainerWidget();
00169       top->setLayout(grid, AlignTop | AlignLeft);
00170       root()->addWidget(top);
00171       root()->addWidget(gitView_);
00172       gitView_->setFloatSide(Left);
00173       gitView_->setMargin(6);
00174       root()->addWidget(sourceView_);
00175       sourceView_->setMargin(6);
00176     }
00177   }


Member Function Documentation

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

Change repository and/or revision.

Definition at line 188 of file GitView.C.

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

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

Displayed the currently selected file.

Definition at line 206 of file GitView.C.

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


Member Data Documentation

Definition at line 180 of file GitView.C.

Definition at line 180 of file GitView.C.

Definition at line 181 of file GitView.C.

Definition at line 181 of file GitView.C.

Definition at line 182 of file GitView.C.

Definition at line 183 of file GitView.C.

Definition at line 184 of file GitView.C.


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

Generated on Mon Jan 26 14:14:22 2009 for Wt by doxygen 1.5.6