Skip to content

Commit

Permalink
#5537: DeclarationSelector creates a splitter window as soon as a pre…
Browse files Browse the repository at this point in the history
…view is added to the right panel
  • Loading branch information
codereader committed Sep 17, 2022
1 parent 8b9329a commit c37a0b3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
59 changes: 38 additions & 21 deletions libs/wxutil/decl/DeclarationSelector.cpp
@@ -1,6 +1,7 @@
#include "DeclarationSelector.h"

#include <wx/sizer.h>
#include <wx/splitter.h>
#include "../dataview/ResourceTreeViewToolbar.h"
#include "DeclFileInfo.h"

Expand All @@ -17,40 +18,57 @@ DeclarationSelector::DeclarationSelector(wxWindow* parent, decl::Type declType,
_declType(declType),
_columns(columns),
_treeView(nullptr),
_horizontalSizer(nullptr),
_treeViewSizerItem(nullptr)
_leftPanel(nullptr),
_rightPanel(nullptr)
{
SetSizer(new wxBoxSizer(wxVERTICAL));
createTreeView();

auto* toolbar = new ResourceTreeViewToolbar(this, _treeView);
_declFileInfo = new DeclFileInfo(this, _declType);
_leftPanel = new wxPanel(this);
_leftPanel->SetSizer(new wxBoxSizer(wxVERTICAL));

GetSizer()->Add(_leftPanel, 1, wxEXPAND);

createTreeView(_leftPanel);

auto* toolbar = new ResourceTreeViewToolbar(_leftPanel, _treeView);
_declFileInfo = new DeclFileInfo(_leftPanel, _declType);

_treeVbox = new wxBoxSizer(wxVERTICAL);
_treeVbox->Add(toolbar, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 6);
_treeVbox->Add(_treeView, 1, wxEXPAND);
_treeVbox->Add(_declFileInfo, 0, wxEXPAND | wxTOP | wxBOTTOM, 6);
// a preview widget can be appended to the vertical sizer => AddPreviewToBottom

_horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
_treeViewSizerItem = _horizontalSizer->Add(_treeVbox, 1, wxEXPAND);
// the horizontal sizer has room for a preview widget => AddPreviewToRightPane

GetSizer()->Add(_horizontalSizer, 1, wxEXPAND);
_leftPanel->GetSizer()->Add(_treeVbox, 1, wxEXPAND);
// the right panel has room for a preview widget => AddPreviewToRightPane
}

void DeclarationSelector::AddPreviewToRightPane(ui::IDeclarationPreview* preview, int sizerProportion)
{
auto widget = preview->GetPreviewWidget();

// Tree view no longer takes full proportion after a full-size preview has been added
if (sizerProportion == 1)
if (_rightPanel)
{
_treeViewSizerItem->SetProportion(0);
throw std::logic_error("A preview is already present in the right panel");
}

widget->Reparent(this);
_horizontalSizer->Add(widget, sizerProportion, wxEXPAND | wxLEFT, 6);
// Split the window
auto splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D | wxSP_LIVE_UPDATE);

// Remove items from sizer, then add the splitter
GetSizer()->Clear(false);
GetSizer()->Add(splitter, 1, wxEXPAND);

// Move the left panel as child to the splitter
_leftPanel->Reparent(splitter);
_rightPanel = new wxPanel(splitter);
_rightPanel->SetSizer(new wxBoxSizer(wxVERTICAL));

splitter->SetMinimumPaneSize(200); // no unsplitting
splitter->SplitVertically(_leftPanel, _rightPanel, 350);

auto widget = preview->GetPreviewWidget();

widget->Reparent(_rightPanel);
_rightPanel->GetSizer()->Add(widget, sizerProportion, wxEXPAND | wxLEFT, 6);

_previews.push_back(preview);
}
Expand All @@ -59,16 +77,15 @@ void DeclarationSelector::AddPreviewToBottom(ui::IDeclarationPreview* preview, i
{
auto widget = preview->GetPreviewWidget();

widget->Reparent(this);

widget->Reparent(_leftPanel);
_treeVbox->Add(widget, sizerProportion, wxEXPAND | wxTOP, 3);

_previews.push_back(preview);
}

void DeclarationSelector::createTreeView()
void DeclarationSelector::createTreeView(wxWindow* parent)
{
_treeView = new DeclarationTreeView(this, _declType, _columns, wxDV_NO_HEADER | wxDV_SINGLE);
_treeView = new DeclarationTreeView(parent, _declType, _columns, wxDV_NO_HEADER | wxDV_SINGLE);

// Single visible column, containing the directory/decl name and the icon
_treeView->AppendIconTextColumn(decl::getTypeName(_declType), _columns.iconAndName.getColumnIndex(),
Expand Down
25 changes: 13 additions & 12 deletions libs/wxutil/decl/DeclarationSelector.h
Expand Up @@ -24,24 +24,25 @@ class DeclarationSelector :
private:
decl::Type _declType;

const wxutil::DeclarationTreeView::Columns& _columns;
wxutil::DeclarationTreeView* _treeView;
const DeclarationTreeView::Columns& _columns;
DeclarationTreeView* _treeView;

wxPanel* _leftPanel;
wxPanel* _rightPanel;

wxSizer* _horizontalSizer;
wxSizer* _treeVbox;
wxSizerItem* _treeViewSizerItem;

// Optional preview widget attached to this selector
// The set of preview widgets attached to this selector
std::vector<ui::IDeclarationPreview*> _previews;

wxutil::DeclFileInfo* _declFileInfo;
DeclFileInfo* _declFileInfo;

public:
// Construct a selector widget with the default set of tree view columns
DeclarationSelector(wxWindow* parent, decl::Type declType);

// Construct a selector widget with the given set of tree view columns
DeclarationSelector(wxWindow* parent, decl::Type declType, const wxutil::DeclarationTreeView::Columns& columns);
DeclarationSelector(wxWindow* parent, decl::Type declType, const DeclarationTreeView::Columns& columns);

/**
* Return the declaration selected by the user, or an empty string if there
Expand All @@ -63,15 +64,15 @@ class DeclarationSelector :
void FocusTreeView();

protected:
wxutil::DeclarationTreeView* GetTreeView() const;
DeclarationTreeView* GetTreeView() const;

// Adds a preview widget to the right of the tree view
void AddPreviewToRightPane(ui::IDeclarationPreview* preview, int sizerProportion = 1);
void AddPreviewToBottom(ui::IDeclarationPreview* preview, int sizerProportion = 0);

const wxutil::DeclarationTreeView::Columns& GetColumns() const;
const DeclarationTreeView::Columns& GetColumns() const;

void PopulateTreeView(const wxutil::IResourceTreePopulator::Ptr& populator);
void PopulateTreeView(const IResourceTreePopulator::Ptr& populator);

// Event method invoked when the tree view selection has been changed
virtual void onTreeViewSelectionChanged()
Expand All @@ -82,10 +83,10 @@ class DeclarationSelector :
{}

// Default tree view columns. Subclasses can use a different set of columns if needed
static const wxutil::DeclarationTreeView::Columns& CreateDefaultColumns();
static const DeclarationTreeView::Columns& CreateDefaultColumns();

private:
void createTreeView();
void createTreeView(wxWindow* parent);
void onTreeViewSelectionChanged(wxDataViewEvent& ev);
void onTreeViewItemActivated(wxDataViewEvent& ev);
};
Expand Down

0 comments on commit c37a0b3

Please sign in to comment.