Browse Source

Basic multi-repo implementation

Alexey Edelev 7 years ago
parent
commit
3a266f55e7
8 changed files with 112 additions and 19 deletions
  1. 18 0
      commitgraphpoint.cpp
  2. 30 12
      githandler.cpp
  3. 5 5
      githandler.h
  4. 1 1
      qml/MainView.qml
  5. 11 1
      qml/TopBar.qml
  6. 19 0
      repositorymodel.cpp
  7. 24 0
      repositorymodel.h
  8. 4 0
      universallistmodel.h

+ 18 - 0
commitgraphpoint.cpp

@@ -0,0 +1,18 @@
+#include "commitgraphpoint.h"
+
+CommitGraphPoint::CommitGraphPoint(const GitOid& commitOid, QObject* parent) : GraphPoint(parent)
+    ,m_commitOid(commitOid)
+{
+
+}
+
+CommitGraphPoint::CommitGraphPoint(const GitOid &commitOid, int x, int y, const QString &color, QObject *parent) : GraphPoint(x, y, color, parent)
+  ,m_commitOid(commitOid)
+{
+
+}
+
+CommitGraphPoint::~CommitGraphPoint()
+{
+
+}

+ 30 - 12
githandler.cpp

@@ -66,31 +66,49 @@ void GitHandler::open(const QString &path)
         return;
     }
 
-    if(m_activeRepo) {
-        m_activeRepoWatcher->removePath(m_activeRepo->root());
-    }
+    GitRepository* repo = new GitRepository(QString::fromUtf8(root.ptr, root.size));
+    setActiveRepo(repo);
+    m_repositories->addRepository(repo);
+}
 
-    m_activeRepo = new GitRepository(QString::fromUtf8(root.ptr, root.size));
-    if(!m_activeRepo->isValid()) {
+void GitHandler::activateRepository(int i)
+{
+    GitRepository* repo = m_repositories->at(i);
+    setActiveRepo(repo);
+    m_repositories->setActiveRepositoryIndex(i);
+}
+
+void GitHandler::setActiveRepo(GitRepository* repo)
+{
+    if(repo == nullptr || !repo->isValid()) {
         qDebug() << lastError();
         return;
     }
+
+    if(m_activeRepo) {
+        disconnect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, m_activeRepo, &GitRepository::readBranches);
+        disconnect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, m_activeRepo, &GitRepository::readRemotes);
+        disconnect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, m_activeRepo, &GitRepository::readTags);
+        disconnect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, this, &GitHandler::updateModels);
+        m_activeRepoWatcher->removePath(m_activeRepo->root());
+
+        disconnect(m_activeRepo, &GitRepository::branchesChanged, this, &GitHandler::updateModels);
+
+    }
+
+    m_activeRepo = repo;
+
     ColorHandler::instance().updateColors(m_activeRepo);
     m_constantHead = m_activeRepo->head();
     m_console->setRepository(m_activeRepo);
-
     connect(m_activeRepo, &GitRepository::branchesChanged, this, &GitHandler::updateModels);
     updateModels();
 
     m_activeRepoWatcher->addPath(m_activeRepo->root());
-    connect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, m_activeRepo, &GitRepository::readBranches);
-    connect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, m_activeRepo, &GitRepository::readRemotes);
-    connect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, m_activeRepo, &GitRepository::readTags);
-    connect(m_activeRepoWatcher, &QFileSystemWatcher::directoryChanged, this, &GitHandler::updateModels);
-    //TODO: opened repositories configuraion TBD
-    //    m_repositories->add(m_activeRepo);
+    activeRepoChanged(m_activeRepo);
 }
 
+
 QString GitHandler::lastError() const
 {
     const git_error *e = giterr_last();

+ 5 - 5
githandler.h

@@ -20,7 +20,7 @@ class GitHandler : public QObject
     Q_OBJECT
     Q_PROPERTY(RepositoryModel* repositories READ repositories NOTIFY repositoriesChanged)
     Q_PROPERTY(CommitGraph* graph READ graph NOTIFY graphChanged)
-    Q_PROPERTY(GitRepository* activeRepo READ activeRepo CONSTANT)
+    Q_PROPERTY(GitRepository* activeRepo READ activeRepo NOTIFY activeRepoChanged)
     Q_PROPERTY(GitDiff* activeDiff READ activeDiff WRITE setActiveDiff NOTIFY activeDiffChanged)
     Q_PROPERTY(CommitModel* commits READ commits WRITE setCommits NOTIFY commitsChanged)
     Q_PROPERTY(BranchListModel* branchList READ branchList CONSTANT)
@@ -33,6 +33,7 @@ public:
     virtual ~GitHandler();
     Q_INVOKABLE void open(const QString &path);
     Q_INVOKABLE void open(const QUrl &url);
+    Q_INVOKABLE void activateRepository(int i);
 
     Q_INVOKABLE void diff(GitCommit* a, GitCommit* b);
 
@@ -98,15 +99,14 @@ public slots:
         emit commitsChanged(commits);
     }
 
+    void setActiveRepo(GitRepository* repo);
+
 signals:
+    void activeRepoChanged(GitRepository* activeRepo);
     void repositoriesChanged(RepositoryModel* repositories);
-
     void graphChanged(CommitGraph* graph);
-
     void activeDiffChanged(GitDiff* activeDiff);
-
     void commitsChanged(CommitModel* commits);
-
     void isBusyChanged();
 
 protected:

+ 1 - 1
qml/MainView.qml

@@ -86,7 +86,7 @@ FocusScope {
 
     Rectangle {
         id: dimmingPlane
-        anchors.fill: parent
+        anchors.fill: commitList
         MouseArea {
             anchors.fill: parent
         }

+ 11 - 1
qml/TopBar.qml

@@ -12,6 +12,16 @@ Item {
     Row {
         spacing: 10
         height: 50
+        ComboBox {
+            id: repositories
+            width: 400
+            model: _handler.repositories
+            textRole: "name"
+            onActivated: {
+                _handler.activateRepository(index)
+            }
+        }
+
         Text {
             text: "Active repository" + repoOpenDialog.fileUrl
         }
@@ -30,7 +40,7 @@ Item {
             selectFolder: true
             selectMultiple: false
             onAccepted: {
-    //TODO: repo open is not available
+                //TODO: repo open is not available
                 _handler.open(repoOpenDialog.fileUrl)
             }
         }

+ 19 - 0
repositorymodel.cpp

@@ -1,6 +1,7 @@
 #include "repositorymodel.h"
 
 #include <QDebug>
+#include <QSettings>
 
 RepositoryModel::RepositoryModel(QObject* parent) : UniversalListModel(parent)
 {
@@ -9,3 +10,21 @@ RepositoryModel::RepositoryModel(QObject* parent) : UniversalListModel(parent)
 RepositoryModel::~RepositoryModel()
 {
 }
+
+void RepositoryModel::addRepository(GitRepository *repository)
+{
+    if(m_repolist.contains(repository->name())) {
+        qDebug() << "Repository is already opened";
+        return;
+    }
+
+    m_repolist.append(repository->name());
+    add(repository);
+    setActiveRepositoryIndex(m_repolist.count() - 1);
+}
+
+void RepositoryModel::removeRepository(GitRepository* repository)
+{
+    m_repolist.removeAll(repository->name());
+    remove(repository);
+}

+ 24 - 0
repositorymodel.h

@@ -9,9 +9,33 @@
 class RepositoryModel : public UniversalListModel<GitRepository>
 {
     Q_OBJECT
+    Q_PROPERTY(int activeRepositoryIndex READ activeRepositoryIndex NOTIFY activeRepositoryIndexChanged)
 public:
     RepositoryModel(QObject *parent = 0);
     ~RepositoryModel();
+    void addRepository(GitRepository* repository);
+    void removeRepository(GitRepository* repository);
+    int activeRepositoryIndex() const
+    {
+        return m_activeRepositoryIndex;
+    }
+
+public slots:
+    void setActiveRepositoryIndex(int activeRepositoryIndex)
+    {
+        if (m_activeRepositoryIndex == activeRepositoryIndex)
+            return;
+
+        m_activeRepositoryIndex = activeRepositoryIndex;
+        emit activeRepositoryIndexChanged(activeRepositoryIndex);
+    }
+
+signals:
+    void activeRepositoryIndexChanged(int activeRepositoryIndex);
+
+private:
+    QList<QString> m_repolist;
+    int m_activeRepositoryIndex;
 };
 
 

+ 4 - 0
universallistmodel.h

@@ -87,6 +87,10 @@ public:
         endResetModel();
     }
 
+    T* at(int i) {
+        return m_container.at(i);
+    }
+
 protected:
     void clear() {
 //TODO: need to verify if wee really should cleanup these commits.