Skip to content

Commit

Permalink
#5537: Move double-click behaviour to base DeclarationSelectorDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 18, 2022
1 parent 77f9096 commit bfcafd5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
18 changes: 0 additions & 18 deletions libs/wxutil/EntityClassChooser.cpp
Expand Up @@ -260,8 +260,6 @@ EntityClassChooser::EntityClassChooser(Purpose purpose) :
[this]() { GlobalUserInterface().dispatch([this]() { loadEntityClasses(); }); }
);

Bind(wxEVT_CLOSE_WINDOW, &EntityClassChooser::onDeleteEvent, this);

SetSelector(setupSelector(this));

loadEntityClasses();
Expand Down Expand Up @@ -305,11 +303,6 @@ void EntityClassChooser::SetSelectedDeclName(const std::string& declName)
_restoreSelectionFromRegistry = false; // prevent this selection from being overwritten
}

void EntityClassChooser::onDeleteEvent(wxCloseEvent& ev)
{
EndModal(wxID_CANCEL); // break main loop
}

void EntityClassChooser::loadFromPath(const std::string& registryKey)
{
if (!_restoreSelectionFromRegistry) return;
Expand All @@ -330,18 +323,7 @@ void EntityClassChooser::saveToPath(const std::string& registryKey)
EntityClassSelector* EntityClassChooser::setupSelector(wxWindow* parent)
{
_selector = new EntityClassSelector(parent);

_selector->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &EntityClassChooser::_onItemActivated, this );

return _selector;
}

void EntityClassChooser::_onItemActivated( wxDataViewEvent& ev )
{
if (!_selector->GetSelectedDeclName().empty())
{
EndModal(wxID_OK);
}
}

} // namespace ui
5 changes: 0 additions & 5 deletions libs/wxutil/EntityClassChooser.h
Expand Up @@ -44,11 +44,6 @@ class EntityClassChooser final :

EntityClassSelector* setupSelector(wxWindow * parent);

// Button callbacks
void onDeleteEvent(wxCloseEvent& ev);

void _onItemActivated( wxDataViewEvent& ev );

public:
void loadFromPath(const std::string& registryKey) override;
void saveToPath(const std::string& registryKey) override;
Expand Down
14 changes: 12 additions & 2 deletions libs/wxutil/decl/DeclarationSelectorDialog.cpp
Expand Up @@ -39,7 +39,8 @@ void DeclarationSelectorDialog::SetSelector(DeclarationSelector* selector)
_mainSizer->Prepend(_selector, 1, wxEXPAND | wxBOTTOM, 12);

// Update the affirmative button's sensitivity based on the selection
_selector->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &DeclarationSelectorDialog::onTreeViewSelectionChanged, this);
_selector->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &DeclarationSelectorDialog::onDeclSelectionChanged, this);
_selector->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &DeclarationSelectorDialog::onDeclItemActivated, this);

// The selector state should be persisted on dialog close
RegisterPersistableObject(_selector);
Expand Down Expand Up @@ -79,9 +80,18 @@ void DeclarationSelectorDialog::HandleTreeViewSelectionChanged()
GetAffirmativeButton()->Enable(!_selector->GetSelectedDeclName().empty());
}

void DeclarationSelectorDialog::onTreeViewSelectionChanged(wxDataViewEvent&)
void DeclarationSelectorDialog::onDeclSelectionChanged(wxDataViewEvent&)
{
HandleTreeViewSelectionChanged();
}

void DeclarationSelectorDialog::onDeclItemActivated(wxDataViewEvent&)
{
// Double-clicking a valid decl item positively closes the dialog
if (!_selector->GetSelectedDeclName().empty())
{
EndModal(wxID_OK);
}
}

}
3 changes: 2 additions & 1 deletion libs/wxutil/decl/DeclarationSelectorDialog.h
Expand Up @@ -48,7 +48,8 @@ class DeclarationSelectorDialog :

private:
void HandleTreeViewSelectionChanged();
void onTreeViewSelectionChanged(wxDataViewEvent& ev);
void onDeclSelectionChanged(wxDataViewEvent& ev);
void onDeclItemActivated(wxDataViewEvent& ev);
};

}

0 comments on commit bfcafd5

Please sign in to comment.