void Gitarre::AddRepo (QString path, int i) { QDir dir (path); Repository *repo; if (dir.exists ()) { repo = Repository::open (path); if (!repo->IsValid ()) { QMessageBox::warning (this, "Open repository", "No .git directory could be found"); delete repo; return; } } else repo = new Repository (path); if (i == -1) { Repos.push_back (repo); i = Repos.size() - 1; } else Repos.insert (Repos.begin() + i, repo); DisplayRepo (i); if (Repos.size() == 1) RepoView->setCurrentItem(RepoView->topLevelItem (0)); QObject::connect (repo->GetIgnoreDocument(), &QTextDocument::modificationChanged, this, &Gitarre::UpdateIgnoreEditorTab); }
void Gitarre::onRepoViewItemChanged (QTreeWidgetItem * current, QTreeWidgetItem * previous) { PurgeRepoViewContextMenu (); int topLevelIndex = RepoView->indexOfTopLevelItem(current); if (topLevelIndex != -1) // item is a top level item { Repository *repo = Repos [topLevelIndex]; // create context menu for the specific item if (repo->GetGitRepo()) { RepoView->addAction(CommitRepoAction); RepoView->addAction(PushRepoAction); CommitAction->setEnabled(true); PushAction->setEnabled(true); } else { RepoView->addAction(FindRepoAction); CommitAction->setEnabled(false); PushAction->setEnabled(false); } RepoView->addAction(RemoveSeparator); RepoView->addAction(RemoveRepoAction); // refresh remotes menu if (current != previous) RefreshRemotesMenu (repo); } else // provide the corresponding top level index { QTreeWidgetItem *parent = current; // move all the way up the item hierarchy while (parent->parent()) // while item "parent" has a parent parent = parent->parent(); // set parent to its parent topLevelIndex = RepoView->indexOfTopLevelItem(parent); } Repository *repo = Repos [topLevelIndex]; QTextDocument *doc = repo->GetIgnoreDocument(); if (IgnoreEditor->document() != doc) { IgnoreEditor->setDocument(doc); UpdateIgnoreEditorTab (doc->isModified()); } }