diff options
Diffstat (limited to 'src/plugins/git')
-rw-r--r-- | src/plugins/git/branchdialog.cpp | 216 | ||||
-rw-r--r-- | src/plugins/git/branchdialog.ui | 242 | ||||
-rw-r--r-- | src/plugins/git/branchview.cpp | 266 | ||||
-rw-r--r-- | src/plugins/git/branchview.h (renamed from src/plugins/git/branchdialog.h) | 71 | ||||
-rw-r--r-- | src/plugins/git/git.pro | 9 | ||||
-rw-r--r-- | src/plugins/git/git.qbs | 5 | ||||
-rw-r--r-- | src/plugins/git/gitconstants.h | 1 | ||||
-rw-r--r-- | src/plugins/git/gitplugin.cpp | 14 | ||||
-rw-r--r-- | src/plugins/git/gitplugin.h | 3 |
9 files changed, 330 insertions, 497 deletions
diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp deleted file mode 100644 index c411da3e0a..0000000000 --- a/src/plugins/git/branchdialog.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "branchdialog.h" -#include "branchadddialog.h" -#include "branchcheckoutdialog.h" -#include "branchmodel.h" -#include "branchutils.h" -#include "gitclient.h" -#include "gitplugin.h" -#include "gitutils.h" -#include "gitconstants.h" -#include "ui_branchdialog.h" - -#include <vcsbase/vcsoutputwindow.h> -#include <coreplugin/documentmanager.h> - -#include <utils/execmenu.h> -#include <utils/qtcassert.h> - -#include <QAction> -#include <QItemSelectionModel> -#include <QMessageBox> -#include <QList> -#include <QMenu> - -#include <QDebug> - -using namespace VcsBase; - -namespace Git { -namespace Internal { - -BranchDialog::BranchDialog(QWidget *parent) : - QDialog(parent), - BranchUtils(this), - m_ui(new Ui::BranchDialog) -{ - setModal(false); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - setAttribute(Qt::WA_DeleteOnClose, true); // Do not update unnecessarily - - m_ui->setupUi(this); - setBranchView(m_ui->branchView); - m_ui->includeOldCheckBox->setToolTip( - tr("Include branches and tags that have not been active for %n days.", 0, - Constants::OBSOLETE_COMMIT_AGE_IN_DAYS)); - m_ui->includeTagsCheckBox->setChecked(GitPlugin::client()->settings().boolValue( - GitSettings::showTagsKey)); - - connect(m_ui->refreshButton, &QAbstractButton::clicked, this, &BranchDialog::refreshCurrentRepository); - connect(m_ui->addButton, &QAbstractButton::clicked, this, [this] { add(); }); - connect(m_ui->checkoutButton, &QAbstractButton::clicked, this, [this] { checkout(); }); - connect(m_ui->removeButton, &QAbstractButton::clicked, this, [this] { remove(); }); - connect(m_ui->renameButton, &QAbstractButton::clicked, this, &BranchDialog::rename); - connect(m_ui->diffButton, &QAbstractButton::clicked, this, &BranchDialog::diff); - connect(m_ui->logButton, &QAbstractButton::clicked, this, &BranchDialog::log); - connect(m_ui->resetButton, &QAbstractButton::clicked, this, [this] { reset(); }); - connect(m_ui->mergeButton, &QAbstractButton::clicked, this, &BranchDialog::merge); - connect(m_ui->rebaseButton, &QAbstractButton::clicked, this, [this] { rebase(); }); - connect(m_ui->cherryPickButton, &QAbstractButton::clicked, this, [this] { cherryPick(); }); - connect(m_ui->trackButton, &QAbstractButton::clicked, this, &BranchDialog::setRemoteTracking); - connect(m_ui->includeOldCheckBox, &QCheckBox::toggled, this, [this](bool value) { - m_model->setOldBranchesIncluded(value); - refreshCurrentRepository(); - }); - connect(m_ui->includeTagsCheckBox, &QCheckBox::toggled, this, [this](bool value) { - GitPlugin::client()->settings().setValue(GitSettings::showTagsKey, value); - refreshCurrentRepository(); - }); - - m_ui->branchView->setModel(m_model); - m_ui->branchView->setFocus(); - - connect(m_ui->branchView->selectionModel(), &QItemSelectionModel::selectionChanged, - this, &BranchDialog::enableButtons); - connect(m_model, &QAbstractItemModel::dataChanged, this, &BranchDialog::resizeColumns); - connect(m_model, &QAbstractItemModel::rowsInserted, this, &BranchDialog::resizeColumns); - connect(m_model, &QAbstractItemModel::rowsRemoved, this, &BranchDialog::resizeColumns); - connect(m_model, &QAbstractItemModel::modelReset, this, &BranchDialog::expandAndResize); - - m_ui->branchView->selectionModel()->clear(); - enableButtons(); -} - -BranchDialog::~BranchDialog() -{ - delete m_ui; -} - -void BranchDialog::refresh(const QString &repository, bool force) -{ - if (m_repository == repository && !force) - return; - - m_repository = repository; - m_ui->repositoryLabel->setText(GitPlugin::msgRepositoryLabel(m_repository)); - QString errorMessage; - if (!m_model->refresh(m_repository, &errorMessage)) - VcsOutputWindow::appendError(errorMessage); -} - -void BranchDialog::expandAndResize() -{ - m_ui->branchView->expandAll(); - resizeColumns(); -} - -void BranchDialog::refreshIfSame(const QString &repository) -{ - if (m_repository == repository) - refreshCurrentRepository(); -} - -void BranchDialog::resizeColumns() -{ - m_ui->branchView->resizeColumnToContents(0); - m_ui->branchView->resizeColumnToContents(1); -} - -void BranchDialog::enableButtons() -{ - QModelIndex idx = selectedIndex(); - QModelIndex currentBranch = m_model->currentBranch(); - const bool hasSelection = idx.isValid(); - const bool currentSelected = hasSelection && idx == currentBranch; - const bool isLocal = m_model->isLocal(idx); - const bool isLeaf = m_model->isLeaf(idx); - const bool isTag = m_model->isTag(idx); - const bool hasActions = hasSelection && isLeaf; - const bool currentLocal = m_model->isLocal(currentBranch); - - m_ui->removeButton->setEnabled(hasActions && !currentSelected && (isLocal || isTag)); - m_ui->renameButton->setEnabled(hasActions && (isLocal || isTag)); - m_ui->logButton->setEnabled(hasActions); - m_ui->diffButton->setEnabled(hasActions); - m_ui->checkoutButton->setEnabled(hasActions && !currentSelected); - m_ui->rebaseButton->setEnabled(hasActions && !currentSelected); - m_ui->resetButton->setEnabled(hasActions && currentLocal && !currentSelected); - m_ui->mergeButton->setEnabled(hasActions && !currentSelected); - m_ui->cherryPickButton->setEnabled(hasActions && !currentSelected); - m_ui->trackButton->setEnabled(hasActions && currentLocal && !currentSelected && !isTag); -} - -void BranchDialog::refreshCurrentRepository() -{ - refresh(m_repository, true); -} - -void BranchDialog::rename() -{ - if (BranchUtils::rename()) - refreshCurrentRepository(); -} - -void BranchDialog::diff() -{ - QString fullName = m_model->fullName(selectedIndex(), true); - if (fullName.isEmpty()) - return; - GitPlugin::client()->diffBranch(m_repository, fullName); -} - -void BranchDialog::log() -{ - QString branchName = m_model->fullName(selectedIndex(), true); - if (branchName.isEmpty()) - return; - GitPlugin::client()->log(m_repository, QString(), false, {branchName}); -} - -void BranchDialog::merge() -{ - bool allowFastForward = true; - if (isFastForwardMerge()) { - QMenu popup; - QAction *fastForward = popup.addAction(tr("Fast-Forward")); - popup.addAction(tr("No Fast-Forward")); - QAction *chosen = Utils::execMenuAtWidget(&popup, m_ui->mergeButton); - if (!chosen) - return; - allowFastForward = (chosen == fastForward); - } - - BranchUtils::merge(allowFastForward); -} - -void BranchDialog::setRemoteTracking() -{ - m_model->setRemoteTracking(selectedIndex()); -} - -} // namespace Internal -} // namespace Git diff --git a/src/plugins/git/branchdialog.ui b/src/plugins/git/branchdialog.ui deleted file mode 100644 index 5335fecedb..0000000000 --- a/src/plugins/git/branchdialog.ui +++ /dev/null @@ -1,242 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>Git::Internal::BranchDialog</class> - <widget class="QDialog" name="Git::Internal::BranchDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>514</width> - <height>527</height> - </rect> - </property> - <property name="windowTitle"> - <string>Branches</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="repositoryLabel"> - <property name="text"> - <string notr="true">Repository: Dummy</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="refreshButton"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Re&fresh</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QGroupBox" name="localBranchGroupBox"> - <property name="title"> - <string>Branches</string> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="topMargin"> - <number>4</number> - </property> - <property name="bottomMargin"> - <number>4</number> - </property> - <item> - <layout class="QVBoxLayout" name="verticalLayout_6"> - <item> - <widget class="QTreeView" name="branchView"> - <property name="rootIsDecorated"> - <bool>false</bool> - </property> - <property name="uniformRowHeights"> - <bool>true</bool> - </property> - <attribute name="headerVisible"> - <bool>false</bool> - </attribute> - </widget> - </item> - <item> - <widget class="QCheckBox" name="includeTagsCheckBox"> - <property name="text"> - <string>Include ta&gs</string> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="includeOldCheckBox"> - <property name="text"> - <string>&Include old entries</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="spacing"> - <number>15</number> - </property> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="spacing"> - <number>3</number> - </property> - <item> - <widget class="QPushButton" name="addButton"> - <property name="text"> - <string>&Add...</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="removeButton"> - <property name="text"> - <string>&Remove</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="renameButton"> - <property name="text"> - <string>Re&name</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="checkoutButton"> - <property name="text"> - <string>C&heckout</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <property name="spacing"> - <number>3</number> - </property> - <item> - <widget class="QPushButton" name="diffButton"> - <property name="text"> - <string>&Diff</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="logButton"> - <property name="text"> - <string>&Log</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout_5"> - <property name="spacing"> - <number>3</number> - </property> - <item> - <widget class="QPushButton" name="mergeButton"> - <property name="text"> - <string>&Merge</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="rebaseButton"> - <property name="text"> - <string>Re&base</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="resetButton"> - <property name="text"> - <string>Re&set</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QPushButton" name="cherryPickButton"> - <property name="toolTip"> - <string>Cherry pick top commit from selected branch.</string> - </property> - <property name="text"> - <string>Cherry &Pick</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="trackButton"> - <property name="toolTip"> - <string>Set current branch to track the selected one.</string> - </property> - <property name="text"> - <string>&Track</string> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Close</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>Git::Internal::BranchDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>466</x> - <y>614</y> - </hint> - <hint type="destinationlabel"> - <x>544</x> - <y>23</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/src/plugins/git/branchview.cpp b/src/plugins/git/branchview.cpp new file mode 100644 index 0000000000..180ecc8a4f --- /dev/null +++ b/src/plugins/git/branchview.cpp @@ -0,0 +1,266 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Andre Hartmann <aha_1980@gmx.de> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "branchview.h" + +#include "branchadddialog.h" +#include "branchcheckoutdialog.h" +#include "branchmodel.h" +#include "gitclient.h" +#include "gitconstants.h" +#include "gitplugin.h" +#include "gitutils.h" + +#include <coreplugin/actionmanager/command.h> +#include <coreplugin/documentmanager.h> +#include <coreplugin/inavigationwidgetfactory.h> +#include <utils/elidinglabel.h> +#include <utils/navigationtreeview.h> +#include <utils/qtcassert.h> +#include <utils/utilsicons.h> +#include <vcsbase/vcsoutputwindow.h> + +#include <QDir> +#include <QLabel> +#include <QKeySequence> +#include <QMenu> +#include <QMessageBox> +#include <QPoint> +#include <QTreeView> +#include <QToolButton> +#include <QVBoxLayout> + +using namespace Core; + +namespace Git { +namespace Internal { + +BranchView::BranchView() : + BranchUtils(this), + m_includeOldEntriesAction(new QAction(tr("Include Old Entries"), this)), + m_includeTagsAction(new QAction(tr("Include Tags"), this)), + m_addButton(new QToolButton(this)), + m_refreshButton(new QToolButton(this)), + m_repositoryLabel(new Utils::ElidingLabel(this)), + m_branchView(new Utils::NavigationTreeView(this)) +{ + setBranchView(m_branchView); + m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon()); + m_addButton->setToolTip(tr("Add Branch")); + m_addButton->setProperty("noArrow", true); + connect(m_addButton, &QToolButton::clicked, this, [this] { add(); }); + + m_refreshButton->setIcon(Utils::Icons::RESET_TOOLBAR.icon()); + m_refreshButton->setToolTip(tr("Refresh")); + m_refreshButton->setProperty("noArrow", true); + connect(m_refreshButton, &QToolButton::clicked, this, &BranchView::refreshCurrentRepository); + + m_branchView->setModel(m_model); + m_branchView->setHeaderHidden(true); + setFocus(); + + m_repositoryLabel->setElideMode(Qt::ElideLeft); + auto layout = new QVBoxLayout(this); + layout->addWidget(m_repositoryLabel); + layout->addWidget(m_branchView); + layout->setContentsMargins(0, 2, 0, 0); + setLayout(layout); + + m_includeOldEntriesAction->setCheckable(true); + m_includeOldEntriesAction->setToolTip( + tr("Include branches and tags that have not been active for %n days.", nullptr, + Constants::OBSOLETE_COMMIT_AGE_IN_DAYS)); + connect(m_includeOldEntriesAction, &QAction::toggled, + this, &BranchView::BranchView::setIncludeOldEntries); + m_includeTagsAction->setCheckable(true); + m_includeTagsAction->setChecked( + GitPlugin::client()->settings().boolValue(GitSettings::showTagsKey)); + connect(m_includeTagsAction, &QAction::toggled, + this, &BranchView::BranchView::setIncludeTags); + + m_branchView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_branchView, &QWidget::customContextMenuRequested, + this, &BranchView::slotCustomContextMenu); + connect(m_model, &QAbstractItemModel::modelReset, + this, &BranchView::expandAndResize); + + m_branchView->selectionModel()->clear(); + m_repository = GitPlugin::instance()->currentState().topLevel(); + refreshCurrentRepository(); +} + +void BranchView::refreshIfSame(const QString &repository) +{ + if (m_repository == repository) + refreshCurrentRepository(); +} + +void BranchView::refresh(const QString &repository, bool force) +{ + if (m_repository == repository && !force) + return; + + m_repository = repository; + m_repositoryLabel->setText(QDir::toNativeSeparators(m_repository)); + m_repositoryLabel->setToolTip(GitPlugin::msgRepositoryLabel(m_repository)); + QString errorMessage; + if (!m_model->refresh(m_repository, &errorMessage)) + VcsBase::VcsOutputWindow::appendError(errorMessage); +} + +QToolButton *BranchView::addButton() const +{ + return m_addButton; +} + +QToolButton *BranchView::refreshButton() const +{ + return m_refreshButton; +} + +void BranchView::refreshCurrentRepository() +{ + refresh(m_repository, true); +} + +void BranchView::resizeColumns() +{ + for (int column = 0, total = m_model->columnCount(); column < total; ++column) + m_branchView->resizeColumnToContents(column); +} + +void BranchView::slotCustomContextMenu(const QPoint &point) +{ + const QModelIndex index = m_branchView->indexAt(point); + if (!index.isValid()) + return; + + const QModelIndex currentBranch = m_model->currentBranch(); + const bool hasSelection = index.isValid(); + const bool currentSelected = hasSelection && index == currentBranch; + const bool isLocal = m_model->isLocal(index); + const bool isLeaf = m_model->isLeaf(index); + const bool isTag = m_model->isTag(index); + const bool hasActions = hasSelection && isLeaf; + const bool currentLocal = m_model->isLocal(currentBranch); + + QMenu contextMenu; + contextMenu.addAction(tr("Add..."), this, [this] { add(); }); + if (hasActions) { + if (!currentSelected && (isLocal || isTag)) + contextMenu.addAction(tr("Remove"), this, [this] { remove(); }); + if (isLocal || isTag) + contextMenu.addAction(tr("Rename"), this, [this] { rename(); }); + if (!currentSelected) { + contextMenu.addAction(tr("Checkout"), this, [this] { checkout(); }); + } + contextMenu.addSeparator(); + contextMenu.addAction(tr("Diff"), this, [this] { + const QString fullName = m_model->fullName(selectedIndex(), true); + if (!fullName.isEmpty()) + GitPlugin::client()->diffBranch(m_repository, fullName); + }); + contextMenu.addAction(tr("Log"), this, [this] { + const QString branchName = m_model->fullName(selectedIndex(), true); + if (!branchName.isEmpty()) + GitPlugin::client()->log(m_repository, QString(), false, {branchName}); + }); + contextMenu.addSeparator(); + if (!currentSelected) { + if (currentLocal) + contextMenu.addAction(tr("Reset"), this, [this] { reset(); }); + QString mergeTitle; + if (BranchUtils::isFastForwardMerge()) { + contextMenu.addAction(tr("Merge (Fast-Forward)"), this, [this] { merge(true); }); + mergeTitle = tr("Merge (No Fast-Forward)"); + } else { + mergeTitle = tr("Merge"); + } + + contextMenu.addAction(mergeTitle, this, [this] { merge(); }); + contextMenu.addAction(tr("Rebase"), this, [this] { rebase(); }); + contextMenu.addSeparator(); + contextMenu.addAction(tr("Cherry Pick"), this, [this] { cherryPick(); }); + } + if (currentLocal && !currentSelected && !isTag) { + contextMenu.addAction(tr("Track"), this, [this] { + m_model->setRemoteTracking(selectedIndex()); + }); + } + } + contextMenu.exec(m_branchView->viewport()->mapToGlobal(point)); +} + +void BranchView::expandAndResize() +{ + m_branchView->expandAll(); + resizeColumns(); +} + +void BranchView::setIncludeOldEntries(bool filter) +{ + m_model->setOldBranchesIncluded(filter); + refreshCurrentRepository(); +} + +void BranchView::setIncludeTags(bool includeTags) +{ + GitPlugin::client()->settings().setValue(GitSettings::showTagsKey, includeTags); + refreshCurrentRepository(); +} + +BranchViewFactory::BranchViewFactory() +{ + setDisplayName(tr("Git Branches")); + setPriority(500); + setId(Constants::GIT_BRANCH_VIEW_ID); +} + +NavigationView BranchViewFactory::createWidget() +{ + m_view = new BranchView; + Core::NavigationView navigationView(m_view); + + auto filter = new QToolButton; + filter->setIcon(Utils::Icons::FILTER.icon()); + filter->setToolTip(tr("Filter")); + filter->setPopupMode(QToolButton::InstantPopup); + filter->setProperty("noArrow", true); + auto filterMenu = new QMenu(filter); + filterMenu->addAction(m_view->m_includeOldEntriesAction); + filterMenu->addAction(m_view->m_includeTagsAction); + filter->setMenu(filterMenu); + + navigationView.dockToolBarWidgets << filter << m_view->addButton() << m_view->refreshButton(); + return navigationView; +} + +BranchView *BranchViewFactory::view() const +{ + return m_view; +} + +} // namespace Internal +} // namespace Git diff --git a/src/plugins/git/branchdialog.h b/src/plugins/git/branchview.h index 5e082cc98b..b3cf01c5f3 100644 --- a/src/plugins/git/branchdialog.h +++ b/src/plugins/git/branchview.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 Andre Hartmann <aha_1980@gmx.de> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -27,47 +27,70 @@ #include "branchutils.h" -#include <QDialog> +#include <coreplugin/inavigationwidgetfactory.h> + +#include <QPointer> +#include <QWidget> QT_BEGIN_NAMESPACE -class QModelIndex; -QT_END_NAMESPACE +class QPoint; +class QToolButton; +class QTreeView; +QT_END_NAMESPACE; + +namespace Utils { +class ElidingLabel; +class NavigationTreeView; +} namespace Git { namespace Internal { -namespace Ui { class BranchDialog; } - class BranchModel; -/** - * Branch dialog. Displays a list of local branches at the top and remote - * branches below. Offers to checkout/delete local branches. - * - */ -class BranchDialog : public QDialog, public BranchUtils +class BranchView : public QWidget, public BranchUtils { Q_OBJECT public: - explicit BranchDialog(QWidget *parent = 0); - ~BranchDialog() override; + explicit BranchView(); - void refresh(const QString &repository, bool force); void refreshIfSame(const QString &repository); + void refresh(const QString &repository, bool force); + + QToolButton *addButton() const; + QToolButton *refreshButton() const; + + QAction *m_includeOldEntriesAction = nullptr; + QAction *m_includeTagsAction = nullptr; private: - void expandAndResize(); - void resizeColumns(); - void enableButtons(); void refreshCurrentRepository(); - void rename(); - void diff(); - void log(); - void merge(); - void setRemoteTracking(); + void resizeColumns(); + void slotCustomContextMenu(const QPoint &point); + void expandAndResize(); + void setIncludeOldEntries(bool filter); + void setIncludeTags(bool includeTags); + + QToolButton *m_addButton = nullptr; + QToolButton *m_refreshButton = nullptr; + Utils::ElidingLabel *m_repositoryLabel = nullptr; + Utils::NavigationTreeView *m_branchView = nullptr; +}; + +class BranchViewFactory : public Core::INavigationWidgetFactory +{ + Q_OBJECT + +public: + BranchViewFactory(); + + BranchView *view() const; + +private: + Core::NavigationView createWidget() override; - Ui::BranchDialog *m_ui; + QPointer<BranchView> m_view; }; } // namespace Internal diff --git a/src/plugins/git/git.pro b/src/plugins/git/git.pro index d2aec99746..d7a7454c74 100644 --- a/src/plugins/git/git.pro +++ b/src/plugins/git/git.pro @@ -14,7 +14,6 @@ HEADERS += gitplugin.h \ gitsubmiteditor.h \ gitversioncontrol.h \ gitsettings.h \ - branchdialog.h \ branchmodel.h \ stashdialog.h \ gitutils.h \ @@ -26,7 +25,8 @@ HEADERS += gitplugin.h \ branchcheckoutdialog.h \ githighlighters.h \ gitgrep.h \ - branchutils.h + branchutils.h \ + branchview.h SOURCES += gitplugin.cpp \ gitclient.cpp \ @@ -39,7 +39,6 @@ SOURCES += gitplugin.cpp \ gitsubmiteditor.cpp \ gitversioncontrol.cpp \ gitsettings.cpp \ - branchdialog.cpp \ branchmodel.cpp \ stashdialog.cpp \ gitutils.cpp \ @@ -51,12 +50,12 @@ SOURCES += gitplugin.cpp \ branchcheckoutdialog.cpp \ githighlighters.cpp \ gitgrep.cpp \ - branchutils.cpp + branchutils.cpp \ + branchview.cpp FORMS += changeselectiondialog.ui \ settingspage.ui \ gitsubmitpanel.ui \ - branchdialog.ui \ stashdialog.ui \ remotedialog.ui \ remoteadditiondialog.ui \ diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index 29753a02ff..2de22a2cf1 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -22,13 +22,12 @@ QtcPlugin { "branchcheckoutdialog.cpp", "branchcheckoutdialog.h", "branchcheckoutdialog.ui", - "branchdialog.cpp", - "branchdialog.h", - "branchdialog.ui", "branchmodel.cpp", "branchmodel.h", "branchutils.cpp", "branchutils.h", + "branchview.cpp", + "branchview.h", "changeselectiondialog.cpp", "changeselectiondialog.h", "changeselectiondialog.ui", diff --git a/src/plugins/git/gitconstants.h b/src/plugins/git/gitconstants.h index 72cccd0501..fb97b16b1d 100644 --- a/src/plugins/git/gitconstants.h +++ b/src/plugins/git/gitconstants.h @@ -42,6 +42,7 @@ const char GIT_COMMIT_TEXT_EDITOR_ID[] = "Git Commit Editor"; const char GIT_COMMIT_TEXT_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "Git Commit Editor"); const char GIT_REBASE_EDITOR_ID[] = "Git Rebase Editor"; const char GIT_REBASE_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "Git Rebase Editor"); +const char GIT_BRANCH_VIEW_ID[] = "Git Branches"; const char GIT_CONTEXT[] = "Git Context"; const char GITSUBMITEDITOR_ID[] = "Git Submit Editor"; diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index af72beae45..a24adabc74 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -25,6 +25,7 @@ #include "gitplugin.h" +#include "branchview.h" #include "changeselectiondialog.h" #include "commitdata.h" #include "gitclient.h" @@ -32,7 +33,6 @@ #include "giteditor.h" #include "gitsubmiteditor.h" #include "gitversioncontrol.h" -#include "branchdialog.h" #include "remotedialog.h" #include "stashdialog.h" #include "settingspage.h" @@ -55,6 +55,7 @@ #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/locator/commandlocator.h> +#include <coreplugin/navigationwidget.h> #include <coreplugin/vcsmanager.h> #include <coreplugin/messagebox.h> @@ -303,6 +304,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) this, &GitPlugin::updateRepositoryBrowserAction); new GitGrep(this); + m_branchViewFactory = new BranchViewFactory; const auto describeFunc = [this](const QString &source, const QString &id) { m_gitClient->show(source, id); @@ -1307,7 +1309,7 @@ template <class NonModalDialog> void GitPlugin::branchList() { - showNonModalDialog(currentState().topLevel(), m_branchDialog); + Core::NavigationWidget::activateSubWidget(Constants::GIT_BRANCH_VIEW_ID, Core::Side::Right); } void GitPlugin::remoteList() @@ -1326,8 +1328,8 @@ void GitPlugin::updateActions(VcsBasePlugin::ActionState as) const bool repositoryEnabled = state.hasTopLevel(); if (m_stashDialog) m_stashDialog->refresh(state.topLevel(), false); - if (m_branchDialog) - m_branchDialog->refresh(state.topLevel(), false); + if (m_branchViewFactory && m_branchViewFactory->view()) + m_branchViewFactory->view()->refresh(state.topLevel(), false); if (m_remoteDialog) m_remoteDialog->refresh(state.topLevel(), false); @@ -1399,8 +1401,8 @@ void GitPlugin::delayedPushToGerrit() void GitPlugin::updateBranches(const QString &repository) { - if (m_branchDialog && m_branchDialog->isVisible()) - m_branchDialog->refreshIfSame(repository); + if (m_branchViewFactory && m_branchViewFactory->view()) + m_branchViewFactory->view()->refreshIfSame(repository); } QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory, diff --git a/src/plugins/git/gitplugin.h b/src/plugins/git/gitplugin.h index 999f2ae36b..a4474379e3 100644 --- a/src/plugins/git/gitplugin.h +++ b/src/plugins/git/gitplugin.h @@ -62,6 +62,7 @@ class GitClient; class CommitData; class StashDialog; class BranchDialog; +class BranchViewFactory; class RemoteDialog; typedef void (GitClient::*GitClientMemberFunc)(const QString &); @@ -209,7 +210,7 @@ private: GitClient *m_gitClient = nullptr; QPointer<StashDialog> m_stashDialog; - QPointer<BranchDialog> m_branchDialog; + QPointer<BranchViewFactory> m_branchViewFactory; QPointer<RemoteDialog> m_remoteDialog; QString m_submitRepository; QString m_commitMessageFileName; |