Commit 9a7bab2d authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Shift + Click = new tab always

parent 0de59ff5
Pipeline #138653 passed with stage
in 7 minutes and 50 seconds
......@@ -109,8 +109,7 @@ public:
l->setContentsMargins({});
l->addWidget(&m_list);
connect(&m_list, &QListView::clicked, this, &DirFilesList::onClicked);
m_list.viewport()->installEventFilter(this);
setFocusProxy(&m_list);
}
......@@ -140,7 +139,7 @@ public:
setFixedSize(qMin(w, 500), qMin(h, 600));
}
void onClicked(const QModelIndex &idx)
void onClicked(const QModelIndex &idx, Qt::KeyboardModifiers mod)
{
if (!idx.isValid()) {
return;
......@@ -151,14 +150,14 @@ public:
} else if (fi.isFile()) {
const QUrl url = QUrl::fromLocalFile(fi.absoluteFilePath());
hide();
Q_EMIT openUrl(url);
Q_EMIT openUrl(url, /*newtab=*/mod);
}
}
void keyPressEvent(QKeyEvent *ke) override
{
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) {
onClicked(m_list.currentIndex());
onClicked(m_list.currentIndex(), Qt::NoModifier);
return;
} else if (ke->key() == Qt::Key_Left || ke->key() == Qt::Key_Right) {
hide();
......@@ -176,8 +175,24 @@ public:
QMenu::keyPressEvent(ke);
}
bool eventFilter(QObject *o, QEvent *e) override
{
if (e->type() != QEvent::Type::MouseButtonPress) {
return QMenu::eventFilter(o, e);
}
QMouseEvent *me = static_cast<QMouseEvent *>(e);
if (me->button() == Qt::LeftButton) {
const QModelIndex idx = m_list.indexAt(m_list.viewport()->mapFromGlobal(me->globalPos()));
if (!idx.isValid()) {
return QMenu::eventFilter(o, me);
}
onClicked(idx, me->modifiers());
}
return QMenu::eventFilter(o, e);
}
Q_SIGNALS:
void openUrl(const QUrl &url);
void openUrl(const QUrl &url, Qt::KeyboardModifiers);
void navigateLeftRight(int key);
private:
......
......@@ -17,7 +17,7 @@ public:
explicit KateUrlBar(KateViewSpace *parent = nullptr);
Q_SIGNALS:
void openUrlRequested(const QUrl &url);
void openUrlRequested(const QUrl &url, Qt::KeyboardModifiers);
private:
void onViewChanged(KTextEditor::View *v);
......
......@@ -124,9 +124,10 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
m_urlBar = new KateUrlBar(this);
// like other editors, we try to re-use documents, of not modified
connect(m_urlBar, &KateUrlBar::openUrlRequested, this, [this](const QUrl &url) {
connect(m_urlBar, &KateUrlBar::openUrlRequested, this, [this](const QUrl &url, Qt::KeyboardModifiers mod) {
// try if reuse of view make sense
if (!KateApp::self()->documentManager()->findDocument(url)) {
const bool shiftPress = mod == Qt::ShiftModifier;
if (!shiftPress && !KateApp::self()->documentManager()->findDocument(url)) {
if (auto activeView = m_viewManager->activeView(); activeView) {
KateDocumentInfo *info = KateApp::self()->documentManager()->documentInfo(activeView->document());
if (info && !info->wasDocumentEverModified) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment