Skip to content

Commit

Permalink
#3250: Move ResourceTreeViewToolbar implementation to .cpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 10, 2021
1 parent 3af5798 commit c6f0ddf
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 127 deletions.
1 change: 1 addition & 0 deletions libs/wxutil/CMakeLists.txt
Expand Up @@ -2,6 +2,7 @@ add_library(wxutil
ConsoleView.cpp
dataview/KeyValueTable.cpp
dataview/ResourceTreeView.cpp
dataview/ResourceTreeViewToolbar.cpp
dataview/ThreadedResourceTreePopulator.cpp
dataview/TreeModel.cpp
dataview/TreeModelFilter.cpp
Expand Down
140 changes: 140 additions & 0 deletions libs/wxutil/dataview/ResourceTreeViewToolbar.cpp
@@ -0,0 +1,140 @@
#include "ResourceTreeViewToolbar.h"

#include "i18n.h"
#include "iuimanager.h"

#include <wx/artprov.h>
#include <wx/sizer.h>
#include <wx/statbmp.h>
#include <wx/textctrl.h>

namespace wxutil
{

ResourceTreeViewToolbar::ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView) :
wxPanel(parent, wxID_ANY),
_treeView(nullptr),
_showAll(nullptr),
_showFavourites(nullptr)
{
auto* grid = new wxFlexGridSizer(2);
grid->AddGrowableCol(1);

SetSizer(grid);

// Hbox for the favourites selection widgets
auto* favourites = new wxBoxSizer(wxHORIZONTAL);
_showAll = new wxRadioButton(this, wxID_ANY, _("Show All"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
_showFavourites = new wxRadioButton(this, wxID_ANY, _("Show Favourites"));

_showAll->Bind(wxEVT_RADIOBUTTON, &ResourceTreeViewToolbar::_onFilterButtonToggled, this);
_showFavourites->Bind(wxEVT_RADIOBUTTON, &ResourceTreeViewToolbar::_onFilterButtonToggled, this);

favourites->Add(_showAll, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0);
favourites->Add(_showFavourites, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 6);

// Filter text entry box
auto* filterBox = new wxBoxSizer(wxHORIZONTAL);

auto* filterImage = new wxStaticBitmap(this, wxID_ANY, wxArtProvider::GetBitmap(wxART_FIND, wxART_TOOLBAR, wxSize(16, 16)));

auto* filterEntry = new wxTextCtrl(this, wxID_ANY);
filterEntry->SetMinSize(wxSize(100, -1));
filterEntry->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev)
{
if (_treeView != nullptr)
{
_treeView->SetFilterText(ev.GetString().ToStdString());
}
});
filterEntry->Bind(wxEVT_CHAR, &ResourceTreeViewToolbar::_onEntryChar, this);

auto nextImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_down.png");
_findNextButton = new wxBitmapButton(this, wxID_ANY, nextImg);

auto prevImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_up.png");
_findPrevButton = new wxBitmapButton(this, wxID_ANY, prevImg);

_findNextButton->SetSize(wxSize(16, 16));
_findPrevButton->SetSize(wxSize(16, 16));

_findNextButton->SetToolTip(_("Go to next match"));
_findPrevButton->SetToolTip(_("Go to previous match"));

_findNextButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
JumpToNextFilterMatch();
});
_findPrevButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
JumpToPrevFilterMatch();
});

filterBox->Add(filterImage, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
filterBox->Add(filterEntry, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
filterBox->Add(_findPrevButton, 0, wxEXPAND | wxRIGHT, 3);
filterBox->Add(_findNextButton, 0, wxEXPAND, 6);

grid->Add(favourites, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxRIGHT, 6);
grid->Add(filterBox, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 6);

AssociateToTreeView(treeView);
}

void ResourceTreeViewToolbar::AssociateToTreeView(ResourceTreeView* treeView)
{
_treeView = treeView;
UpdateFromTreeView();
}

void ResourceTreeViewToolbar::JumpToNextFilterMatch()
{
if (_treeView != nullptr)
{
_treeView->JumpToNextFilterMatch();
}
}

void ResourceTreeViewToolbar::JumpToPrevFilterMatch()
{
if (_treeView != nullptr)
{
_treeView->JumpToPrevFilterMatch();
}
}

void ResourceTreeViewToolbar::_onEntryChar(wxKeyEvent& ev)
{
if (ev.GetKeyCode() == WXK_UP)
{
JumpToPrevFilterMatch();
}
else if (ev.GetKeyCode() == WXK_DOWN)
{
JumpToNextFilterMatch();
}
else
{
ev.Skip();
}
}

void ResourceTreeViewToolbar::_onFilterButtonToggled(wxCommandEvent& ev)
{
if (_treeView == nullptr) return;

_treeView->SetTreeMode(_showAll->GetValue() ?
ResourceTreeView::TreeMode::ShowAll :
ResourceTreeView::TreeMode::ShowFavourites);
}

void ResourceTreeViewToolbar::UpdateFromTreeView()
{
if (_treeView == nullptr) return;

auto mode = _treeView->GetTreeMode();
_showAll->SetValue(mode == ResourceTreeView::TreeMode::ShowAll);
_showFavourites->SetValue(mode == ResourceTreeView::TreeMode::ShowFavourites);
}

}
136 changes: 9 additions & 127 deletions libs/wxutil/dataview/ResourceTreeViewToolbar.h
@@ -1,13 +1,9 @@
#pragma once

#include "i18n.h"
#include "iuimanager.h"
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/radiobut.h>
#include <wx/artprov.h>
#include <wx/statbmp.h>
#include <wx/textctrl.h>
#include <wx/bmpbuttn.h>

#include "ResourceTreeView.h"

namespace wxutil
Expand All @@ -29,132 +25,18 @@ class ResourceTreeViewToolbar :
wxBitmapButton* _findNextButton;

public:
ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView = nullptr) :
wxPanel(parent, wxID_ANY),
_treeView(nullptr),
_showAll(nullptr),
_showFavourites(nullptr)
{
auto* grid = new wxFlexGridSizer(2);
grid->AddGrowableCol(1);

SetSizer(grid);

// Hbox for the favourites selection widgets
auto* favourites = new wxBoxSizer(wxHORIZONTAL);
_showAll = new wxRadioButton(this, wxID_ANY, _("Show All"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
_showFavourites = new wxRadioButton(this, wxID_ANY, _("Show Favourites"));

_showAll->Bind(wxEVT_RADIOBUTTON, &ResourceTreeViewToolbar::_onFilterButtonToggled, this);
_showFavourites->Bind(wxEVT_RADIOBUTTON, &ResourceTreeViewToolbar::_onFilterButtonToggled, this);

favourites->Add(_showAll, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0);
favourites->Add(_showFavourites, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 6);

// Filter text entry box
auto* filterBox = new wxBoxSizer(wxHORIZONTAL);

auto* filterImage = new wxStaticBitmap(this, wxID_ANY, wxArtProvider::GetBitmap(wxART_FIND, wxART_TOOLBAR, wxSize(16, 16)));

auto* filterEntry = new wxTextCtrl(this, wxID_ANY);
filterEntry->SetMinSize(wxSize(100, -1));
filterEntry->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev)
{
if (_treeView != nullptr)
{
_treeView->SetFilterText(ev.GetString().ToStdString());
}
});
filterEntry->Bind(wxEVT_CHAR, &ResourceTreeViewToolbar::_onEntryChar, this);

auto nextImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_down.png");
_findNextButton = new wxBitmapButton(this, wxID_ANY, nextImg);

auto prevImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_up.png");
_findPrevButton = new wxBitmapButton(this, wxID_ANY, prevImg);
ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView = nullptr);

_findNextButton->SetSize(wxSize(16, 16));
_findPrevButton->SetSize(wxSize(16, 16));

_findNextButton->SetToolTip(_("Go to next match"));
_findPrevButton->SetToolTip(_("Go to previous match"));

_findNextButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
jumpToNextFilterMatch();
});
_findPrevButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
jumpToPrevFilterMatch();
});

filterBox->Add(filterImage, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
filterBox->Add(filterEntry, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6);
filterBox->Add(_findPrevButton, 0, wxEXPAND | wxRIGHT, 3);
filterBox->Add(_findNextButton, 0, wxEXPAND, 6);

grid->Add(favourites, 0, wxALIGN_CENTER_VERTICAL| wxALIGN_LEFT | wxRIGHT, 6);
grid->Add(filterBox, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 6);

AssociateToTreeView(treeView);
}

void AssociateToTreeView(ResourceTreeView* treeView)
{
_treeView = treeView;
UpdateFromTreeView();
}
void AssociateToTreeView(ResourceTreeView* treeView);

private:
void jumpToNextFilterMatch()
{
if (_treeView != nullptr)
{
_treeView->JumpToNextFilterMatch();
}
}

void jumpToPrevFilterMatch()
{
if (_treeView != nullptr)
{
_treeView->JumpToPrevFilterMatch();
}
}

void _onEntryChar(wxKeyEvent& ev)
{
if (ev.GetKeyCode() == WXK_UP)
{
jumpToPrevFilterMatch();
}
else if (ev.GetKeyCode() == WXK_DOWN)
{
jumpToNextFilterMatch();
}
else
{
ev.Skip();
}
}
void JumpToNextFilterMatch();
void JumpToPrevFilterMatch();

void _onFilterButtonToggled(wxCommandEvent& ev)
{
if (_treeView == nullptr) return;

_treeView->SetTreeMode(_showAll->GetValue() ?
ResourceTreeView::TreeMode::ShowAll :
ResourceTreeView::TreeMode::ShowFavourites);
}
void _onEntryChar(wxKeyEvent& ev);
void _onFilterButtonToggled(wxCommandEvent& ev);

void UpdateFromTreeView()
{
if (_treeView == nullptr) return;

auto mode = _treeView->GetTreeMode();
_showAll->SetValue(mode == ResourceTreeView::TreeMode::ShowAll);
_showFavourites->SetValue(mode == ResourceTreeView::TreeMode::ShowFavourites);
}
void UpdateFromTreeView();
};

}
1 change: 1 addition & 0 deletions tools/msvc/wxutillib.vcxproj
Expand Up @@ -199,6 +199,7 @@
<ClCompile Include="..\..\libs\wxutil\ConsoleView.cpp" />
<ClCompile Include="..\..\libs\wxutil\dataview\KeyValueTable.cpp" />
<ClCompile Include="..\..\libs\wxutil\dataview\ResourceTreeView.cpp" />
<ClCompile Include="..\..\libs\wxutil\dataview\ResourceTreeViewToolbar.cpp" />
<ClCompile Include="..\..\libs\wxutil\dataview\ThreadedResourceTreePopulator.cpp" />
<ClCompile Include="..\..\libs\wxutil\dataview\TreeModel.cpp" />
<ClCompile Include="..\..\libs\wxutil\dataview\TreeModelFilter.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/wxutillib.vcxproj.filters
Expand Up @@ -218,5 +218,8 @@
<ClCompile Include="..\..\libs\wxutil\dataview\ThreadedResourceTreePopulator.cpp">
<Filter>dataview</Filter>
</ClCompile>
<ClCompile Include="..\..\libs\wxutil\dataview\ResourceTreeViewToolbar.cpp">
<Filter>dataview</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit c6f0ddf

Please sign in to comment.