Public Member Functions | Private Member Functions | Private Attributes

GitViewApplication Class Reference
[Git model example]

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

Inherits Wt::WApplication.

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.

    : WApplication(env)
  {
    useStyleSheet("gitview.css");
    setTitle("Git model example");

    const char *gitRepo = getenv("GITVIEW_REPOSITORY_PATH");

    WGridLayout *grid = new WGridLayout();
    grid->addWidget(new WText("Git repository path:"), 0, 0);
    grid->addWidget(repositoryEdit_ = new WLineEdit(gitRepo ? gitRepo : "")
                    , 0, 1, AlignLeft);
    grid->addWidget(repositoryError_ = new WText(), 0, 2);
    grid->addWidget(new WText("Revision:"), 1, 0);
    grid->addWidget(revisionEdit_ = new WLineEdit("master"), 1, 1, AlignLeft);
    grid->addWidget(revisionError_ = new WText(), 1, 2);

    repositoryEdit_->setTextSize(30);
    revisionEdit_->setTextSize(20);
    repositoryError_->setStyleClass("error-msg");
    revisionError_->setStyleClass("error-msg");

    repositoryEdit_->enterPressed()
      .connect(SLOT(this, GitViewApplication::loadGitModel));
    revisionEdit_->enterPressed()
      .connect(SLOT(this, GitViewApplication::loadGitModel));

    WPushButton *b = new WPushButton("Load");
    b->clicked().connect(SLOT(this, GitViewApplication::loadGitModel));
    grid->addWidget(b, 2, 0, AlignLeft);

    gitView_ = new WTreeView();
    gitView_->resize(300, WLength::Auto);
    gitView_->setSortingEnabled(false);
    gitView_->setModel(gitModel_ = new GitModel(this));
    gitView_->setSelectionMode(SingleSelection);
    gitView_->selectionChanged().connect
      (SLOT(this, GitViewApplication::showFile));

    sourceView_ = new SourceView(DisplayRole, 
                                 GitModel::ContentsRole, 
                                 GitModel::FilePathRole);
    sourceView_->setStyleClass("source-view");

    if (environment().javaScript()) {
      /*
       * We have JavaScript: We can use layout managers so everything will
       * always fit nicely in the window.
       */
      WVBoxLayout *topLayout = new WVBoxLayout();
      topLayout->addLayout(grid, 0, AlignTop | AlignLeft);

      WHBoxLayout *gitLayout = new WHBoxLayout();
      gitLayout->setLayoutHint("table-layout", "fixed");
      gitLayout->addWidget(gitView_, 0);
      gitLayout->addWidget(sourceView_, 1);
      topLayout->addLayout(gitLayout, 1);

      root()->setLayout(topLayout);
      root()->setStyleClass("maindiv");
    } else {
      /*
       * No JavaScript: let's make the best of the situation using regular
       * CSS-based layout
       */
      root()->setStyleClass("maindiv");
      WContainerWidget *top = new WContainerWidget();
      top->setLayout(grid, AlignTop | AlignLeft);
      root()->addWidget(top);
      root()->addWidget(gitView_);
      gitView_->setFloatSide(Left);
      gitView_->setMargin(6);
      root()->addWidget(sourceView_);
      sourceView_->setMargin(6);
    }
  }


Member Function Documentation

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

Change repository and/or revision.

Definition at line 130 of file GitView.C.

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

Displayed the currently selected file.

Definition at line 148 of file GitView.C.

                  {
    if (gitView_->selectedIndexes().empty())
      return;

    WModelIndex selected = *gitView_->selectedIndexes().begin();
    sourceView_->setIndex(selected);
  }


Member Data Documentation

Definition at line 124 of file GitView.C.

Definition at line 125 of file GitView.C.

Definition at line 122 of file GitView.C.

Definition at line 123 of file GitView.C.

Definition at line 122 of file GitView.C.

Definition at line 123 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 Mon Nov 29 2010 08:03:14 for Wt by doxygen 1.7.1