Skip to content

Commit

Permalink
Have sidebar folder selection return false if invalid folder position
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Dec 19, 2023
1 parent a4379cf commit c586d6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/ui/controls/sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,12 @@ void SideBar::EnsureFolderVisible(const size_t index)
}

//-------------------------------------------
void SideBar::SelectFolder(const size_t item, const bool setFocus /*= true*/,
bool SideBar::SelectFolder(const size_t item, const bool setFocus /*= true*/,
const bool sendEvent /*= true*/,
const bool collapseIfExpanded /*= false*/)
{
if (item >= GetFolderCount())
{ return; }
{ return false; }

EnsureFolderVisible(item);

Expand All @@ -951,7 +951,7 @@ void SideBar::SelectFolder(const size_t item, const bool setFocus /*= true*/,
RecalcSizes();
Refresh(true, &refreshRect);
Update();
return;
return true;
}
// See if we should fire a subitem selection event instead
// (in case this parent has subitems)
Expand All @@ -960,7 +960,7 @@ void SideBar::SelectFolder(const size_t item, const bool setFocus /*= true*/,
if (!m_folders[item].IsSubItemSelected())
{ m_folders[item].m_selectedItem = 0; }
SelectSubItem(item, m_folders[item].m_selectedItem.value(), setFocus, sendEvent);
return;
return true;
}

m_selectedFolder = item;
Expand All @@ -979,6 +979,8 @@ void SideBar::SelectFolder(const size_t item, const bool setFocus /*= true*/,
cevent.SetEventObject(this);
GetEventHandler()->ProcessEvent(cevent);
}

return true;
}

//-------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/ui/controls/sidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ namespace Wisteria::UI
@param sendEvent Whether to send a @c EVT_SIDEBAR_CLICK event.
@param collapseIfExpanded @c true to collapse the folder if already expanded.\n
If collapsing the folder, then @c sendEvent will be overridden
(i.e., the selection event will not be fired).*/
void SelectFolder(const size_t item, const bool setFocus = true,
(i.e., the selection event will not be fired).
@returns @c true if the folder was selected.*/
bool SelectFolder(const size_t item, const bool setFocus = true,
const bool sendEvent = true,
const bool collapseIfExpanded = false);
/** @brief Selects a subitem.
Expand Down

0 comments on commit c586d6b

Please sign in to comment.