Skip to content

Commit

Permalink
Add Remote operators and context menu copy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Mar 26, 2024
1 parent 0b4c349 commit 0696b6f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Git.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ class Git : QObject {
QString url;
QString purpose;
QString ssh_key;
bool operator == (Remote const &r) const
{
return url == r.url;
}
bool operator < (Remote const &r) const
{
return url < r.url;
}
};

QList<DiffRaw> diff_raw(CommitID const &old_id, CommitID const &new_id);
Expand Down
31 changes: 30 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4549,7 +4549,7 @@ void MainWindow::on_treeWidget_repos_customContextMenuRequested(const QPoint &po
if (!treeitem) return;

RepositoryData const *repo = repositoryItem(treeitem);

int index = indexOfRepository(treeitem);
if (isGroupItem(treeitem)) { // group item
QMenu menu;
Expand Down Expand Up @@ -4584,11 +4584,35 @@ void MainWindow::on_treeWidget_repos_customContextMenuRequested(const QPoint &po
}
}
} else if (repo) { // repository item
QStringList strings;
strings.push_back(repo->name);
strings.push_back(repo->local_dir);
{
QList<Git::Remote> remotes;
git(repo->local_dir, {}, {})->getRemoteURLs(&remotes);
std::sort(remotes.begin(), remotes.end());
auto it = std::unique(remotes.begin(), remotes.end());
remotes.resize(it - remotes.begin());
for (Git::Remote const &r : remotes) {
strings.push_back(r.url);
}
}

QString open_terminal = tr("Open &terminal");
QString open_commandprompt = tr("Open command promp&t");
QMenu menu;
QAction *a_open = menu.addAction(tr("&Open"));
menu.addSeparator();

std::map<QAction *, QString> copymap;
QMenu *a_copy = menu.addMenu(tr("&Copy"));
{
for (QString const &s : strings) {
QAction *a = a_copy->addAction(s);
copymap[a] = s;
}
}
menu.addSeparator();
#ifdef Q_OS_WIN
QAction *a_open_terminal = menu.addAction(open_commandprompt);
(void)open_terminal;
Expand Down Expand Up @@ -4633,6 +4657,11 @@ void MainWindow::on_treeWidget_repos_customContextMenuRequested(const QPoint &po
execRepositoryPropertyDialog(*repo);
return;
}
auto it = copymap.find(a);
if (it != copymap.end()) {
QApplication::clipboard()->setText(it->second);
return;
}
}
}
}
Expand Down

0 comments on commit 0696b6f

Please sign in to comment.