Git: Allow creating a new repository from branch view

... when clicking "Add Branch" in a project that is not
under git version control.

The "Add Branch" serves no purpose here, so re-use it
to call this (already existing) function.

Done-with: Orgad Shaneh <orgad.shaneh@audiocodes.com>
Change-Id: Ib23d2cbeec0598e0b6f00cbde265793cc25e6142
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2018-09-27 21:01:53 +02:00
committed by André Hartmann
parent 017f4d7c4d
commit 546956a302
3 changed files with 13 additions and 1 deletions

View File

@@ -67,7 +67,6 @@ BranchView::BranchView() :
m_model(new BranchModel(GitPlugin::client(), this)) m_model(new BranchModel(GitPlugin::client(), this))
{ {
m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon()); m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
m_addButton->setToolTip(tr("Add Branch"));
m_addButton->setProperty("noArrow", true); m_addButton->setProperty("noArrow", true);
connect(m_addButton, &QToolButton::clicked, this, &BranchView::add); connect(m_addButton, &QToolButton::clicked, this, &BranchView::add);
@@ -126,10 +125,12 @@ void BranchView::refresh(const QString &repository, bool force)
m_repository = repository; m_repository = repository;
if (m_repository.isEmpty()) { if (m_repository.isEmpty()) {
m_repositoryLabel->setText(tr("<No repository>")); m_repositoryLabel->setText(tr("<No repository>"));
m_addButton->setToolTip(tr("Create Git Repository..."));
m_branchView->setEnabled(false); m_branchView->setEnabled(false);
} else { } else {
m_repositoryLabel->setText(QDir::toNativeSeparators(m_repository)); m_repositoryLabel->setText(QDir::toNativeSeparators(m_repository));
m_repositoryLabel->setToolTip(GitPlugin::msgRepositoryLabel(m_repository)); m_repositoryLabel->setToolTip(GitPlugin::msgRepositoryLabel(m_repository));
m_addButton->setToolTip(tr("Add Branch..."));
m_branchView->setEnabled(true); m_branchView->setEnabled(true);
} }
QString errorMessage; QString errorMessage;
@@ -252,6 +253,11 @@ QModelIndex BranchView::selectedIndex()
bool BranchView::add() bool BranchView::add()
{ {
if (m_repository.isEmpty()) {
GitPlugin::instance()->initRepository();
return true;
}
QModelIndex trackedIndex = selectedIndex(); QModelIndex trackedIndex = selectedIndex();
QString trackedBranch = m_model->fullName(trackedIndex); QString trackedBranch = m_model->fullName(trackedIndex);
if (trackedBranch.isEmpty()) { if (trackedBranch.isEmpty()) {

View File

@@ -1319,6 +1319,11 @@ void GitPlugin::manageRemotes()
showNonModalDialog(currentState().topLevel(), m_remoteDialog); showNonModalDialog(currentState().topLevel(), m_remoteDialog);
} }
void GitPlugin::initRepository()
{
createRepository();
}
void GitPlugin::stashList() void GitPlugin::stashList()
{ {
showNonModalDialog(currentState().topLevel(), m_stashDialog); showNonModalDialog(currentState().topLevel(), m_stashDialog);

View File

@@ -93,6 +93,7 @@ public:
QObject *remoteCommand(const QStringList &options, const QString &workingDirectory, QObject *remoteCommand(const QStringList &options, const QString &workingDirectory,
const QStringList &args) override; const QStringList &args) override;
void manageRemotes(); void manageRemotes();
void initRepository();
protected: protected:
void updateActions(VcsBase::VcsBasePlugin::ActionState) override; void updateActions(VcsBase::VcsBasePlugin::ActionState) override;