Skip to content

Commit

Permalink
if FR:replace has focus when Find done then focus on CodeView (BeckyE…
Browse files Browse the repository at this point in the history
…book)
  • Loading branch information
kevinhendricks committed Apr 5, 2024
1 parent 0f95433 commit 12e1e54
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
37 changes: 28 additions & 9 deletions src/MainUI/FindReplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,34 @@ void FindReplace::SetUpFindText()

// Find text should be selected by default
ui.cbFind->lineEdit()->selectAll();
SetFocus();
SetFocusFind();
}


void FindReplace::SetFocus()
void FindReplace::SetFocusFind()
{
ui.cbFind->lineEdit()->setFocus(Qt::ShortcutFocusReason);
}


bool FindReplace::HasFocus()
void FindReplace::SetFocusReplace()
{
ui.cbReplace->lineEdit()->setFocus(Qt::ShortcutFocusReason);
}


bool FindReplace::HasFocusFind()
{
return ui.cbFind->lineEdit()->hasFocus();
}


bool FindReplace::HasFocusReplace()
{
return ui.cbReplace->lineEdit()->hasFocus();
}


QString FindReplace::GetControls()
{
QStringList controls;
Expand Down Expand Up @@ -909,12 +921,18 @@ bool FindReplace::ReplaceText(Searchable::Direction direction, bool replace_curr

void FindReplace::SetCodeViewIfNeeded()
{
bool has_focus = HasFocus();
if (has_focus) {
if (HasFocusFind()) {
// give the current tab CodeView Tab the focus
ui.cbFind->lineEdit()->clearFocus();
ContentTab * current_tab = m_MainWindow->GetCurrentContentTab();
if (current_tab) current_tab->setFocus();
return;
}
if (HasFocusReplace()) {
// give the current tab CodeView Tab the focus
ui.cbReplace->lineEdit()->clearFocus();
ContentTab * current_tab = m_MainWindow->GetCurrentContentTab();
if (current_tab) current_tab->setFocus();
}
}

Expand Down Expand Up @@ -1205,7 +1223,9 @@ bool FindReplace::FindInAllFiles(Searchable::Direction direction)
DBG qDebug() << " .. which is " << containing_resource->GetRelativePath();

// Save if editor or F&R has focus
bool has_focus = HasFocus();
bool has_focus_find = HasFocusFind();
bool has_focus_replace = HasFocusReplace();

// Save selected resources since opening tabs changes selection
QList<Resource *>selected_resources = m_MainWindow->GetBookBrowserSelectedResources();

Expand All @@ -1220,9 +1240,8 @@ bool FindReplace::FindInAllFiles(Searchable::Direction direction)
}

// Reset focus to F&R if it had it
if (has_focus) {
SetFocus();
}
if (has_focus_find) SetFocusFind();
if (has_focus_replace) SetFocusReplace();

searchable = GetAvailableSearchable();

Expand Down
6 changes: 4 additions & 2 deletions src/MainUI/FindReplace.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ private slots:
*/
void ConnectSignalsToSlots();

void SetFocus();
bool HasFocus();
void SetFocusFind();
void SetFocusReplace();
bool HasFocusFind();
bool HasFocusReplace();

///////////////////////////////
// PRIVATE MEMBER VARIABLES
Expand Down

0 comments on commit 12e1e54

Please sign in to comment.