Skip to content

Commit

Permalink
Rewrite context menu handlers in S/R editor to address #4454
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 2, 2017
1 parent cb4672a commit 526ec62
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
6 changes: 1 addition & 5 deletions plugins/dm.stimresponse/ClassEditor.cpp
Expand Up @@ -354,12 +354,8 @@ std::string ClassEditor::getStimTypeIdFromSelector(wxComboBox* comboBox)

void ClassEditor::onContextMenu(wxDataViewEvent& ev)
{
wxutil::TreeView* view = dynamic_cast<wxutil::TreeView*>(ev.GetEventObject());

assert(view != NULL);

// Call the subclass implementation
openContextMenu(view);
openSRListContextMenu();
}

void ClassEditor::onStimTypeSelect(wxCommandEvent& ev)
Expand Down
7 changes: 3 additions & 4 deletions plugins/dm.stimresponse/ClassEditor.h
Expand Up @@ -147,11 +147,10 @@ class ClassEditor :
*/
virtual void selectionChanged() = 0;

/** greebo: Opens the context menu. The treeview widget this event
* has been happening on gets passed so that the correct
* menu can be displayed (in the case of multiple possible treeviews).
/**
* greebo: Opens the context menu. Needs to be implemented by subclasses.
*/
virtual void openContextMenu(wxutil::TreeView* view) = 0;
virtual void openSRListContextMenu() = 0;

// Callback for Stim/Response selection changes
void onSRSelectionChange(wxDataViewEvent& ev);
Expand Down
28 changes: 13 additions & 15 deletions plugins/dm.stimresponse/ResponseEditor.cpp
Expand Up @@ -37,7 +37,7 @@ void ResponseEditor::setEntity(const SREntityPtr& entity)
// Pass the call to the base class
ClassEditor::setEntity(entity);

if (entity != NULL)
if (entity)
{
wxutil::TreeModel::Ptr responseStore = _entity->getResponseStore();
_list->AssociateModel(responseStore.get());
Expand Down Expand Up @@ -216,13 +216,13 @@ void ResponseEditor::createEffectWidgets()

// Connect the signals
_effectWidgets.view->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED,
wxDataViewEventHandler(ResponseEditor::onEffectSelectionChange), NULL, this);
wxDataViewEventHandler(ResponseEditor::onEffectSelectionChange), nullptr, this);

_effectWidgets.view->Connect(wxEVT_DATAVIEW_ITEM_ACTIVATED,
wxDataViewEventHandler(ResponseEditor::onEffectItemActivated), NULL, this);
wxDataViewEventHandler(ResponseEditor::onEffectItemActivated), nullptr, this);

_effectWidgets.view->Connect(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU,
wxDataViewEventHandler(ResponseEditor::onContextMenu), NULL, this);
wxDataViewEventHandler(ResponseEditor::onEffectItemContextMenu), nullptr, this);

// View Columns
_effectWidgets.view->AppendTextColumn("#", StimResponse::getColumns().index.getColumnIndex(),
Expand Down Expand Up @@ -461,18 +461,9 @@ int ResponseEditor::getEffectIdFromSelection()
}
}

void ResponseEditor::openContextMenu(wxutil::TreeView* view)
void ResponseEditor::openSRListContextMenu()
{
// Check the treeview this remove call is targeting
if (view == _list)
{
_list->PopupMenu(_contextMenu.menu.get());
}
else if (view == _effectWidgets.view)
{
updateEffectContextMenu();
_effectWidgets.view->PopupMenu(_effectWidgets.contextMenu.get());
}
_list->PopupMenu(_contextMenu.menu.get());
}

void ResponseEditor::selectionChanged()
Expand Down Expand Up @@ -504,6 +495,13 @@ void ResponseEditor::addSR()
selectId(id);
}

void ResponseEditor::onEffectItemContextMenu(wxDataViewEvent& ev)
{
updateEffectContextMenu();

_effectWidgets.view->PopupMenu(_effectWidgets.contextMenu.get());
}

// Button click events on TreeViews
void ResponseEditor::onEffectItemActivated(wxDataViewEvent& ev)
{
Expand Down
8 changes: 4 additions & 4 deletions plugins/dm.stimresponse/ResponseEditor.h
Expand Up @@ -108,7 +108,7 @@ class ResponseEditor :
*/
virtual void selectionChanged();

void openContextMenu(wxutil::TreeView* view);
void openSRListContextMenu() override;

/** greebo: Creates all the widgets
*/
Expand All @@ -117,9 +117,6 @@ class ResponseEditor :
// Context menu callbacks
void onContextMenuAdd(wxCommandEvent& ev);
void onContextMenuDelete(wxCommandEvent& ev);
void onContextMenuEffectUp(wxCommandEvent& ev);
void onContextMenuEffectDown(wxCommandEvent& ev);
void onContextMenuEdit(wxCommandEvent& ev);

void onEffectMenuDelete(wxCommandEvent& ev);
void onEffectMenuEdit(wxCommandEvent& ev);
Expand All @@ -130,6 +127,9 @@ class ResponseEditor :
// To catch double-clicks in the response effect list
void onEffectItemActivated(wxDataViewEvent& ev);

// Context menu handler for effects view
void onEffectItemContextMenu(wxDataViewEvent& ev);

// Callback for Stim/Response and effect selection changes
void onEffectSelectionChange(wxDataViewEvent& ev);
};
Expand Down
4 changes: 2 additions & 2 deletions plugins/dm.stimresponse/StimEditor.cpp
Expand Up @@ -358,9 +358,9 @@ void StimEditor::checkBoxToggled(wxCheckBox* toggleButton)
}
}

void StimEditor::openContextMenu(wxutil::TreeView* view)
void StimEditor::openSRListContextMenu()
{
view->PopupMenu(_contextMenu.menu.get());
_list->PopupMenu(_contextMenu.menu.get());
}

void StimEditor::addSR()
Expand Down
2 changes: 1 addition & 1 deletion plugins/dm.stimresponse/StimEditor.h
Expand Up @@ -125,7 +125,7 @@ class StimEditor :
*/
virtual void selectionChanged();

void openContextMenu(wxutil::TreeView* view);
void openSRListContextMenu() override;

/** greebo: Creates all the widgets
*/
Expand Down

0 comments on commit 526ec62

Please sign in to comment.