mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-11 02:35:41 +03:00
Merge pull request #721 from jensenr30/navigation-hotkeys
Add Hotkeys for Navigating CommitList
This commit is contained in:
commit
ec9980f699
@ -28,6 +28,7 @@
|
||||
#include "git/Signature.h"
|
||||
#include "git/TagRef.h"
|
||||
#include "git/Tree.h"
|
||||
#include "ui/HotkeyManager.h"
|
||||
#include <QAbstractListModel>
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
@ -1168,6 +1169,12 @@ public:
|
||||
|
||||
} // namespace
|
||||
|
||||
static Hotkey selectCommitDownHotKey = HotkeyManager::registerHotkey(
|
||||
"j", "commitList/selectCommitDown", "CommitList/Select Next Commit Down");
|
||||
|
||||
static Hotkey selectCommitUpHotKey = HotkeyManager::registerHotkey(
|
||||
"k", "commitList/selectCommitUp", "CommitList/Select Next Commit Up");
|
||||
|
||||
CommitList::CommitList(Index *index, QWidget *parent)
|
||||
: QListView(parent), mIndex(index) {
|
||||
Theme *theme = Application::theme();
|
||||
@ -1223,6 +1230,15 @@ CommitList::CommitList(Index *index, QWidget *parent)
|
||||
connect(this, &CommitList::entered,
|
||||
[this](const QModelIndex &index) { update(index); });
|
||||
|
||||
QShortcut *shortcut = new QShortcut(this);
|
||||
selectCommitDownHotKey.use(shortcut);
|
||||
connect(shortcut, &QShortcut::activated, [this] { selectCommitRelative(1); });
|
||||
|
||||
shortcut = new QShortcut(this);
|
||||
selectCommitUpHotKey.use(shortcut);
|
||||
connect(shortcut, &QShortcut::activated,
|
||||
[this] { selectCommitRelative(-1); });
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
QFont font = this->font();
|
||||
font.setPointSize(13);
|
||||
@ -1345,6 +1361,19 @@ void CommitList::selectFirstCommit(bool spontaneous) {
|
||||
}
|
||||
}
|
||||
|
||||
void CommitList::selectCommitRelative(int offset) {
|
||||
QModelIndexList indices = selectionModel()->selectedIndexes();
|
||||
QModelIndex index = indices[0];
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
QModelIndex new_index = model()->index(index.row() + offset, index.column());
|
||||
if (!new_index.isValid()) {
|
||||
return;
|
||||
}
|
||||
selectIndexes(QItemSelection(new_index, new_index), QString(), true);
|
||||
}
|
||||
|
||||
bool CommitList::selectRange(const QString &range, const QString &file,
|
||||
bool spontaneous) {
|
||||
// Try to select the "status" index.
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
void selectReference(const git::Reference &ref);
|
||||
void resetSelection(bool spontaneous = false);
|
||||
void selectFirstCommit(bool spontaneous = false);
|
||||
void selectCommitRelative(int offset);
|
||||
bool selectRange(const QString &range, const QString &file = QString(),
|
||||
bool spontaneous = false);
|
||||
void suppressResetWalker(bool suppress);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "CommentWidget.h"
|
||||
#include "ui/DiffTreeModel.h"
|
||||
#include "ui/DoubleTreeWidget.h"
|
||||
#include "ui/HotkeyManager.h"
|
||||
#include "git/Tree.h"
|
||||
#include <QScrollBar>
|
||||
#include <QPushButton>
|
||||
@ -47,6 +48,12 @@ bool copy(const QString &source, const QDir &targetDir) {
|
||||
|
||||
} // namespace
|
||||
|
||||
static Hotkey moveHalfPageDownHotKey = HotkeyManager::registerHotkey(
|
||||
"d", "diffView/moveHalfPageDownHotKey", "DiffView/Move Half Page Down");
|
||||
|
||||
static Hotkey moveHalfPageUpHotKey = HotkeyManager::registerHotkey(
|
||||
"u", "diffView/moveHalfPageUpHotKey", "DiffView/Move Half Page Up");
|
||||
|
||||
DiffView::DiffView(const git::Repository &repo, QWidget *parent)
|
||||
: QScrollArea(parent), mParent(parent) {
|
||||
setStyleSheet(DiffViewStyle::kStyleSheet);
|
||||
@ -84,6 +91,14 @@ DiffView::DiffView(const git::Repository &repo, QWidget *parent)
|
||||
fetchMore();
|
||||
});
|
||||
}
|
||||
|
||||
QShortcut *shortcut = new QShortcut(this);
|
||||
moveHalfPageDownHotKey.use(shortcut);
|
||||
connect(shortcut, &QShortcut::activated, [this] { moveHalfPageDown(); });
|
||||
|
||||
shortcut = new QShortcut(this);
|
||||
moveHalfPageUpHotKey.use(shortcut);
|
||||
connect(shortcut, &QShortcut::activated, [this] { moveHalfPageUp(); });
|
||||
}
|
||||
|
||||
DiffView::~DiffView() {}
|
||||
@ -513,3 +528,13 @@ void DiffView::indexChanged(const QStringList &paths) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void DiffView::moveHalfPageDown() { moveRelative(height() / 2); }
|
||||
|
||||
void DiffView::moveHalfPageUp() { moveRelative(-height() / 2); }
|
||||
|
||||
void DiffView::moveRelative(int pixelsDown) {
|
||||
int oldPosition = verticalScrollBar()->sliderPosition();
|
||||
int newPosition = oldPosition + pixelsDown;
|
||||
verticalScrollBar()->setSliderPosition(newPosition);
|
||||
}
|
||||
|
@ -103,6 +103,9 @@ public:
|
||||
void diffTreeModelDataChanged(const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles);
|
||||
void moveHalfPageDown();
|
||||
void moveHalfPageUp();
|
||||
void moveRelative(int pixelsDown);
|
||||
|
||||
signals:
|
||||
void diagnosticAdded(TextEditor::DiagnosticKind kind);
|
||||
|
Loading…
Reference in New Issue
Block a user