Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically load selected docset on keyboard selection without enter or click #749

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions src/libs/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,12 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :

createTab();

connect(ui->treeView, &QTreeView::clicked, this, &MainWindow::openDocset);
trollixx marked this conversation as resolved.
Show resolved Hide resolved
// Focus web view on any active interaction with tree (enter, clicking)
connect(ui->treeView, &QTreeView::clicked, this, &MainWindow::openAndFocusDocset);
connect(ui->treeView, &QTreeView::activated, this, &MainWindow::openAndFocusDocset);

// Handle selections in the table of contents list
connect(ui->tocListView, &QListView::clicked, this, &MainWindow::openDocset);
connect(ui->treeView, &QTreeView::activated, this, &MainWindow::openDocset);
connect(ui->tocListView, &QListView::activated, this, &MainWindow::openDocset);

connect(m_application->docsetRegistry(), &Registry::DocsetRegistry::searchCompleted,
Expand Down Expand Up @@ -386,9 +389,6 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :
return;

openDocset(index);
trollixx marked this conversation as resolved.
Show resolved Hide resolved

// Get focus back.
ui->lineEdit->setFocus(Qt::MouseFocusReason);
});

ui->actionNewTab->setShortcut(QKeySequence::AddTab);
Expand Down Expand Up @@ -463,13 +463,31 @@ void MainWindow::search(const Registry::SearchQuery &query)
emit ui->treeView->activated(ui->treeView->currentIndex());
}

// Open the docset at index immediately
void MainWindow::openDocset(const QModelIndex &index)
{
// Cancel any other pending docset open
m_openDocsetTimer->stop();

const QVariant url = index.data(Registry::ItemDataRole::UrlRole);
if (url.isNull())
return;

currentTab()->load(url.toUrl());
}

// Open the docset at index after a delay (for typing, keyboard selection, etc)
void MainWindow::openDocsetDelayed(const QModelIndex &index)
{
m_openDocsetTimer->stop();
m_openDocsetTimer->setProperty("index", index);
m_openDocsetTimer->start();
}

// Open the docset at index and move focus to the web view
void MainWindow::openAndFocusDocset(const QModelIndex &index)
{
openDocset(index);
currentTab()->focus();
}

Expand All @@ -493,8 +511,7 @@ void MainWindow::queryCompleted()

ui->treeView->setCurrentIndex(currentTabState()->searchModel->index(0, 0, QModelIndex()));

m_openDocsetTimer->setProperty("index", ui->treeView->currentIndex());
m_openDocsetTimer->start();
openDocsetDelayed(ui->treeView->currentIndex());
}

void MainWindow::closeTab(int index)
Expand Down Expand Up @@ -580,8 +597,20 @@ void MainWindow::syncTreeView()

// TODO: Remove once QTBUG-49966 is addressed.
QItemSelectionModel *newSelectionModel = ui->treeView->selectionModel();
if (oldSelectionModel && newSelectionModel != oldSelectionModel) {
oldSelectionModel->deleteLater();
if (newSelectionModel != oldSelectionModel) {
if (oldSelectionModel) {
oldSelectionModel->deleteLater();
}

// Connect to new selection model
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [this](const QItemSelection &selected) {
if (selected.isEmpty()) {
return;
}

openDocsetDelayed(selected.indexes().first());
});
}

trollixx marked this conversation as resolved.
Show resolved Hide resolved
ui->treeView->reset();
Expand Down
3 changes: 3 additions & 0 deletions src/libs/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

class QxtGlobalShortcut;

class QItemSelection;
class QModelIndex;
class QSystemTrayIcon;
class QTabBar;
Expand Down Expand Up @@ -79,6 +80,8 @@ public slots:
private slots:
void applySettings();
void openDocset(const QModelIndex &index);
void openAndFocusDocset(const QModelIndex &index);
trollixx marked this conversation as resolved.
Show resolved Hide resolved
void openDocsetDelayed(const QModelIndex &index);
void queryCompleted();
void closeTab(int index = -1);
void moveTab(int from, int to);
Expand Down