mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-17 13:37:18 +03:00
Referring repos with their git-dir instead of their work-tree.
Also sets up display routines to avoid displaying a repo as ".git".
This commit is contained in:
parent
cd952a7683
commit
f53493a7e6
@ -50,16 +50,16 @@ void RecentRepositories::remove(int index) {
|
||||
emit repositoryRemoved();
|
||||
}
|
||||
|
||||
void RecentRepositories::add(QString path) {
|
||||
void RecentRepositories::add(QString gitpath) {
|
||||
emit repositoryAboutToBeAdded();
|
||||
|
||||
auto end = mRepos.end();
|
||||
RecentRepository *repo = new RecentRepository(path, this);
|
||||
RecentRepository *repo = new RecentRepository(gitpath, this);
|
||||
auto it = std::remove_if(mRepos.begin(), end, [repo](RecentRepository *rhs) {
|
||||
#ifdef Q_OS_WIN
|
||||
return repo->path().compare(rhs->path(), Qt::CaseInsensitive) == 0;
|
||||
return repo-gitpath().compare(rhs->gitpath(), Qt::CaseInsensitive) == 0;
|
||||
#else
|
||||
return (repo->path() == rhs->path());
|
||||
return (repo->gitpath() == rhs->gitpath());
|
||||
#endif
|
||||
});
|
||||
|
||||
@ -82,7 +82,7 @@ RecentRepositories *RecentRepositories::instance() {
|
||||
void RecentRepositories::store() {
|
||||
QStringList paths;
|
||||
foreach (RecentRepository *repo, mRepos)
|
||||
paths.append(repo->path());
|
||||
paths.append(repo->gitpath());
|
||||
|
||||
QSettings().setValue(kRecentKey, paths);
|
||||
|
||||
|
@ -9,13 +9,16 @@
|
||||
|
||||
#include "RecentRepository.h"
|
||||
|
||||
RecentRepository::RecentRepository(const QString &path, QObject *parent)
|
||||
: QObject(parent), mPath(path) {}
|
||||
RecentRepository::RecentRepository(const QString &gitpath, QObject *parent)
|
||||
: QObject(parent), mPath(gitpath) {}
|
||||
|
||||
QString RecentRepository::path() const { return mPath; }
|
||||
QString RecentRepository::gitpath() const { return mPath; }
|
||||
|
||||
QString RecentRepository::name() const {
|
||||
return mPath.section('/', -mSections);
|
||||
if (mPath.endsWith("/.git"))
|
||||
return mPath.section('/', -mSections-1, -2);
|
||||
else
|
||||
return mPath.section('/', -mSections, -1);
|
||||
}
|
||||
|
||||
void RecentRepository::increment() { ++mSections; }
|
||||
|
@ -16,9 +16,9 @@ class RecentRepository : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RecentRepository(const QString &path, QObject *parent = nullptr);
|
||||
RecentRepository(const QString &gitpath, QObject *parent = nullptr);
|
||||
|
||||
QString path() const;
|
||||
QString gitpath() const;
|
||||
QString name() const;
|
||||
|
||||
private:
|
||||
|
@ -117,10 +117,10 @@ public:
|
||||
RecentRepository *repo = repos->repository(index.row());
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return mShowFullPath ? repo->path() : repo->name();
|
||||
return mShowFullPath ? repo->gitpath() : repo->name();
|
||||
|
||||
case Qt::UserRole:
|
||||
return repo->path();
|
||||
return repo->gitpath();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
@ -52,7 +52,7 @@ class TabName {
|
||||
public:
|
||||
TabName(const QString &path) : mPath(path) {}
|
||||
|
||||
QString name() const { return mPath.section('/', -mSections); }
|
||||
QString name() const { return mPath.endsWith("/.git") ? mPath.section('/', -mSections-1,-2) : mPath.section('/', -mSections); }
|
||||
|
||||
void increment() { ++mSections; }
|
||||
int sections() const { return mSections; }
|
||||
@ -218,7 +218,7 @@ RepoView *MainWindow::addTab(const QString &path) {
|
||||
TabWidget *tabs = tabWidget();
|
||||
for (int i = 0; i < tabs->count(); i++) {
|
||||
RepoView *view = static_cast<RepoView *>(tabs->widget(i));
|
||||
if (path == view->repo().workdir().path()) {
|
||||
if (path == view->repo().dir().path()) {
|
||||
tabs->setCurrentIndex(i);
|
||||
return view;
|
||||
}
|
||||
@ -235,13 +235,13 @@ RepoView *MainWindow::addTab(const QString &path) {
|
||||
|
||||
RepoView *MainWindow::addTab(const git::Repository &repo) {
|
||||
// Update recent repository settings.
|
||||
QDir dir = repo.workdir();
|
||||
QDir dir = repo.dir();
|
||||
RecentRepositories::instance()->add(dir.path());
|
||||
|
||||
TabWidget *tabs = tabWidget();
|
||||
for (int i = 0; i < tabs->count(); i++) {
|
||||
RepoView *view = static_cast<RepoView *>(tabs->widget(i));
|
||||
if (dir.path() == view->repo().workdir().path()) {
|
||||
if (dir.path() == view->repo().dir().path()) {
|
||||
tabs->setCurrentIndex(i);
|
||||
return view;
|
||||
}
|
||||
@ -256,7 +256,12 @@ RepoView *MainWindow::addTab(const git::Repository &repo) {
|
||||
[this] { updateWindowTitle(); });
|
||||
|
||||
emit tabs->tabAboutToBeInserted();
|
||||
tabs->setCurrentIndex(tabs->addTab(view, dir.dirName()));
|
||||
|
||||
// NB : this seems to be useless, because overwritten by MainWindow::updateTabNames
|
||||
QString tabTitle = dir.dirName();
|
||||
if (tabTitle == ".git")
|
||||
tabTitle = dir.path().section("/", -2, -2);
|
||||
tabs->setCurrentIndex(tabs->addTab(view, tabTitle));
|
||||
|
||||
Settings *settings = Settings::instance();
|
||||
bool enable =
|
||||
@ -381,7 +386,7 @@ MainWindow *MainWindow::open(const QString &path, bool warnOnInvalid) {
|
||||
MainWindow *MainWindow::open(const git::Repository &repo) {
|
||||
// Update recent repository settings.
|
||||
if (repo.isValid())
|
||||
RecentRepositories::instance()->add(repo.workdir().path());
|
||||
RecentRepositories::instance()->add(repo.dir().path());
|
||||
|
||||
// Create the window.
|
||||
MainWindow *window = new MainWindow(repo);
|
||||
@ -470,7 +475,7 @@ void MainWindow::updateTabNames() {
|
||||
QList<TabName> fullNames;
|
||||
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
TabName name(view(i)->repo().workdir().path());
|
||||
TabName name(view(i)->repo().dir().path());
|
||||
names[name.name()].append(i);
|
||||
fullNames.append(name);
|
||||
}
|
||||
@ -520,9 +525,15 @@ void MainWindow::updateWindowTitle(int ahead, int behind) {
|
||||
}
|
||||
|
||||
git::Repository repo = view->repo();
|
||||
QDir dir = repo.workdir();
|
||||
QDir dir = repo.dir();
|
||||
git::Reference head = repo.head();
|
||||
QString path = mFullPath ? dir.path() : dir.dirName();
|
||||
QString path;
|
||||
if (mFullPath)
|
||||
path = dir.path();
|
||||
else if (dir.dirName() == ".git")
|
||||
path = dir.path().section("/", -2, -2);
|
||||
else
|
||||
path = dir.dirName();
|
||||
QString name = head.isValid() ? head.name() : repo.unbornHeadName();
|
||||
QString title = tr("%1 - %2").arg(path, name);
|
||||
|
||||
@ -586,7 +597,7 @@ void MainWindow::updateWindowTitle(int ahead, int behind) {
|
||||
QStringList MainWindow::paths() const {
|
||||
QStringList paths;
|
||||
for (int i = 0; i < count(); ++i)
|
||||
paths.append(view(i)->repo().workdir().path());
|
||||
paths.append(view(i)->repo().dir().path());
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
RecentRepository *repo = repos->repository(i);
|
||||
QAction *action = openRecent->addAction(repo->name());
|
||||
connect(action, &QAction::triggered,
|
||||
[repo] { MainWindow::open(repo->path()); });
|
||||
[repo] { MainWindow::open(repo->gitpath()); });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -352,7 +352,7 @@ public:
|
||||
return mTabs->tabText(row);
|
||||
|
||||
RepoView *view = static_cast<RepoView *>(mTabs->widget(row));
|
||||
return view->repo().workdir().path();
|
||||
return view->repo().dir().path();
|
||||
}
|
||||
|
||||
return tr("none");
|
||||
@ -361,7 +361,7 @@ public:
|
||||
RecentRepositories *recent = RecentRepositories::instance();
|
||||
if (recent->count()) {
|
||||
RecentRepository *repo = repos->repository(row);
|
||||
return mShowFullPath ? repo->path() : repo->name();
|
||||
return mShowFullPath ? repo->gitpath() : repo->name();
|
||||
}
|
||||
|
||||
return tr("none");
|
||||
@ -446,13 +446,13 @@ public:
|
||||
return QVariant();
|
||||
QWidget *widget = mTabs->widget(row);
|
||||
RepoView *view = static_cast<RepoView *>(widget);
|
||||
return view->repo().workdir().path();
|
||||
return view->repo().dir().path();
|
||||
}
|
||||
|
||||
case Recent:
|
||||
if (!repos->count())
|
||||
return QVariant();
|
||||
return repos->repository(row)->path();
|
||||
return repos->repository(row)->gitpath();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
@ -493,7 +493,7 @@ public:
|
||||
case Repo:
|
||||
if (mTabs->count()) {
|
||||
RepoView *view = static_cast<RepoView *>(mTabs->widget(row));
|
||||
return view->repo().workdir().path();
|
||||
return view->repo().dir().path();
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -502,7 +502,7 @@ public:
|
||||
RecentRepositories *recent = RecentRepositories::instance();
|
||||
if (recent->count()) {
|
||||
RecentRepository *repo = repos->repository(row);
|
||||
return repo->path();
|
||||
return repo->gitpath();
|
||||
}
|
||||
|
||||
return "";
|
||||
|
Loading…
Reference in New Issue
Block a user