forked from qt-creator/qt-creator
Git: Rework branch dialog
* Make adding new branches more discoverable * Make adding tracking branches more discoverable * Update UI Task-number: QTCREATORBUG-4943 Task-number: QTCREATORBUG-4944 Change-Id: Idcbf5f8321a3bd04c925e33d094bb479788a7d9b Reviewed-on: http://codereview.qt.nokia.com/588 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
@@ -38,105 +38,63 @@
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
namespace Internal {
|
||||
|
||||
class GitClient;
|
||||
|
||||
/* A read-only model to list git remote branches in a simple list of branch names.
|
||||
* The tooltip describes the latest commit (delayed creation).
|
||||
* Provides virtuals to be able to derive a local branch model with the notion
|
||||
* of a "current branch". */
|
||||
class BranchNode;
|
||||
|
||||
class RemoteBranchModel : public QAbstractListModel {
|
||||
// --------------------------------------------------------------------------
|
||||
// BranchModel:
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class BranchModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RemoteBranchModel(GitClient *client, QObject *parent = 0);
|
||||
explicit BranchModel(GitClient *client, QObject *parent = 0);
|
||||
~BranchModel();
|
||||
|
||||
virtual void clear();
|
||||
virtual bool refresh(const QString &workingDirectory, QString *errorMessage);
|
||||
// QAbstractItemModel
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
QString branchName(int row) const;
|
||||
void clear();
|
||||
bool refresh(const QString &workingDirectory, QString *errorMessage);
|
||||
|
||||
// QAbstractListModel
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
int branchCount() const;
|
||||
void renameBranch(const QString &oldName, const QString &newName);
|
||||
|
||||
QString workingDirectory() const;
|
||||
int findBranchByName(const QString &name) const;
|
||||
GitClient *client() const;
|
||||
|
||||
protected:
|
||||
struct Branch {
|
||||
bool parse(const QString &line, bool *isCurrent);
|
||||
QModelIndex currentBranch() const;
|
||||
QString branchName(const QModelIndex &idx) const;
|
||||
QStringList localBranchNames() const;
|
||||
QString sha(const QModelIndex &idx) const;
|
||||
bool isLocal(const QModelIndex &idx) const;
|
||||
bool isLeaf(const QModelIndex &idx) const;
|
||||
|
||||
QString name;
|
||||
QString currentSHA;
|
||||
mutable QString toolTip;
|
||||
};
|
||||
typedef QList<Branch> BranchList;
|
||||
|
||||
/* Parse git output and populate m_branches. */
|
||||
bool refreshBranches(const QString &workingDirectory, bool remoteBranches,
|
||||
int *currentBranch, QString *errorMessage);
|
||||
bool runGitBranchCommand(const QString &workingDirectory, const QStringList &additionalArgs, QString *output, QString *errorMessage);
|
||||
void removeBranch(const QModelIndex &idx);
|
||||
void checkoutBranch(const QModelIndex &idx);
|
||||
bool branchIsMerged(const QModelIndex &idx);
|
||||
QModelIndex addBranch(const QString &branchName, bool track, const QString &trackedBranch);
|
||||
|
||||
private:
|
||||
QString toolTip(const QString &sha) const;
|
||||
void parseOutputLine(const QString &line);
|
||||
|
||||
const Qt::ItemFlags m_flags;
|
||||
QString toolTip(const QString &sha) const;
|
||||
|
||||
GitClient *m_client;
|
||||
QString m_workingDirectory;
|
||||
BranchList m_branches;
|
||||
BranchNode *m_rootNode;
|
||||
};
|
||||
|
||||
/* LocalBranchModel: Extends RemoteBranchModel by a read-only
|
||||
* checkable column indicating the current branch. Provides an
|
||||
* editable "Type here" new-branch-row at the bottom to create
|
||||
* a new branch. */
|
||||
|
||||
class LocalBranchModel : public RemoteBranchModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit LocalBranchModel(GitClient *client,
|
||||
QObject *parent = 0);
|
||||
|
||||
virtual void clear();
|
||||
virtual bool refresh(const QString &workingDirectory, QString *errorMessage);
|
||||
|
||||
// is this the "type here" row?
|
||||
bool isNewBranchRow(int row) const;
|
||||
bool isNewBranchRow(const QModelIndex & index) const { return isNewBranchRow(index.row()); }
|
||||
|
||||
int currentBranch() const;
|
||||
|
||||
// QAbstractListModel
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
signals:
|
||||
void newBranchCreated(const QString &);
|
||||
void newBranchEntered(const QString &);
|
||||
|
||||
private slots:
|
||||
void slotNewBranchDelayedRefresh();
|
||||
|
||||
private:
|
||||
bool checkNewBranchName(const QString &name) const;
|
||||
|
||||
const QVariant m_typeHere;
|
||||
const QVariant m_typeHereToolTip;
|
||||
|
||||
int m_currentBranch;
|
||||
QString m_newBranch;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace Internal
|
||||
} // namespace Git
|
||||
|
||||
#endif // BRANCHMODEL_H
|
||||
|
||||
Reference in New Issue
Block a user