Skip to content

Commit

Permalink
Github Issue #129: Now the "Return" and "BackSpace" keys can focus th…
Browse files Browse the repository at this point in the history
…e textcursor between the result NavigationView ( QTreeView)and the QLineEdit
  • Loading branch information
AngryFender committed Feb 11, 2024
1 parent 2eadaa0 commit 7641055
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
2 changes: 2 additions & 0 deletions navigationview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void NavigationView::keyPressEvent(QKeyEvent *event)
{
this->expand(index);
}
}else if(event->key() == Qt::Key_Backspace){
emit sendFocusToSearch(this);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions navigationview.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class NavigationView : public QTreeView
void setVaultPath();
void expansionComplete();
void fileRenamed(const QString& newName,const QString& oldName, const QModelIndex& index);
void sendFocusToSearch(QWidget * view);
};

#endif // NAVIGATIONVIEW_H
51 changes: 34 additions & 17 deletions views_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ void ViewsHandler::initConnection()
QObject::connect(viewTree,&NavigationView::expansionComplete,
this,&ViewsHandler::navigationViewExpandedFilenameFilter);

QObject::connect(textSearchAllView, &SearchAllDialog::startSearch,
this,&ViewsHandler::doSearchWork);

QObject::connect(&searchThread,&QThread::started,
&textSearchWorker,&TextSearchWorker::doWork);

Expand All @@ -193,17 +190,30 @@ void ViewsHandler::initConnection()

QObject::connect(viewText, &MkEdit::checkIfCursorInBlock,
this, &ViewsHandler::checkIfCursorInBlockHandler);

QObject::connect(viewSearch, &QLineEdit::returnPressed,
this, &ViewsHandler::fileSearchReturnPressedHandler);

connectDocument();

QObject::connect(viewTextSearchEdit, &QLineEdit::textChanged,
this,&ViewsHandler::textSearchChangedHandler);

QObject::connect(viewTextSearchEdit, &QLineEdit::returnPressed,
this,&ViewsHandler::textSearchReturnPressedHandler);

QObject::connect(&textSearchWorker,&TextSearchWorker::updateTextSearchView,
this, &ViewsHandler::updateTextSearchViewHandler);

QObject::connect(viewTextSearchTree,&NavigationView::pressed,
this,&ViewsHandler::textSearchResultPositionSelected);

QObject::connect(viewTextSearchTree,&NavigationView::sendFocusToSearch,
this,&ViewsHandler::sendFocusToSearchHandler);

QObject::connect(viewTree,&NavigationView::sendFocusToSearch,
this,&ViewsHandler::sendFocusToSearchHandler);


}

Expand Down Expand Up @@ -637,6 +647,27 @@ void ViewsHandler::textSearchResultPositionSelected(const QModelIndex &index)
displayTextSearchedFilePosition(filePath, searchTextLength, blockNumber, positionInBlock);
}

void ViewsHandler::sendFocusToSearchHandler(QWidget *view)
{
if(view == viewTextSearchTree){
this->viewTextSearchEdit->setFocus();
}else if(view == viewTree){
this->viewSearch->setFocus();
}else if(view == viewTextSearchEdit){

}
}

void ViewsHandler::textSearchReturnPressedHandler()
{
this->viewTextSearchTree->setFocus();
}

void ViewsHandler::fileSearchReturnPressedHandler()
{
this->viewTree->setFocus();
}

void ViewsHandler::openRecentFilesDialogHandle(bool show)
{
if(show){
Expand Down Expand Up @@ -676,26 +707,12 @@ void ViewsHandler::openRecentFilesDialogHandle(bool show)

void ViewsHandler::startTextSearchInAllFilesHandle()
{
// if(textSearchAllView->isHidden()){
// proxyModel.createAllFilesList(viewTree->rootIndex(), textSearchWorker.getListPaths());

// QPoint pos = this->parent->mapToGlobal( viewLeftFrame->pos());
// pos.setY(pos.y()-QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight)-6);
// textSearchAllView->setGeometry(viewLeftFrame->geometry());
// textSearchAllView->move(pos);
// textSearchAllView->show();
// }else{
// textSearchAllView->activateWindow();
// textSearchAllView->setFocusAtSearch();
// }

frameSearchFileTree->hide();
frameSearchTextTree->show();

viewTextSearchEdit->show() ;
viewTextSearchTree->show() ;
viewTextSearchEdit->setFocus();

}

void ViewsHandler::startFileSearchHandle()
Expand Down
3 changes: 3 additions & 0 deletions views_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ private slots:
void textSearchChangedHandler(const QString &text);
void updateTextSearchViewHandler(QStandardItemModel *model, int matchCount);
void textSearchResultPositionSelected(const QModelIndex &index);
void sendFocusToSearchHandler(QWidget * view);
void textSearchReturnPressedHandler();
void fileSearchReturnPressedHandler();
};

#endif // VIEWS_HANDLER_H

0 comments on commit 7641055

Please sign in to comment.