Skip to content

Commit

Permalink
S/R Editor: There doesn't seem to be a difference between id and inde…
Browse files Browse the repository at this point in the history
…x, so remove id in favour of the index as encountered as N in the spawnargs like sr_class_N.

Also fix a bug in the S/R loader regex causing S/R indices with two digits to be parsed incorrectly.
  • Loading branch information
codereader committed Mar 27, 2020
1 parent 3d66cc4 commit 41c4134
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 136 deletions.
38 changes: 18 additions & 20 deletions plugins/dm.stimresponse/ClassEditor.cpp
Expand Up @@ -64,29 +64,27 @@ void ClassEditor::setEntity(const SREntityPtr& entity)
_entity = entity;
}

int ClassEditor::getIdFromSelection()
int ClassEditor::getIndexFromSelection()
{
wxDataViewItem item = _list->GetSelection();

if (item.IsOk() && _entity != NULL)
if (item.IsOk() && _entity != nullptr)
{
wxutil::TreeModel::Row row(item, *_list->GetModel());
return row[SREntity::getColumns().id].getInteger();
}
else
{
return -1;
return row[SREntity::getColumns().index].getInteger();
}

return -1;
}

void ClassEditor::setProperty(const std::string& key, const std::string& value)
{
int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
// Don't edit inherited stims/responses
_entity->setProperty(id, key, value);
_entity->setProperty(index, key, value);
}

// Call the method of the child class to update the widgets
Expand Down Expand Up @@ -156,22 +154,22 @@ void ClassEditor::reloadStimTypes()

void ClassEditor::removeSR()
{
// Get the selected stim ID
int id = getIdFromSelection();
// Get the selected stim index
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
_entity->remove(id);
_entity->remove(index);
}
}

void ClassEditor::selectId(int id)
void ClassEditor::selectIndex(int index)
{
// Setup the selectionfinder to search for the id
wxutil::TreeModel* model = dynamic_cast<wxutil::TreeModel*>(_list->GetModel());
assert(model != NULL);

wxDataViewItem item = model->FindInteger(id, SREntity::getColumns().id);
wxDataViewItem item = model->FindInteger(index, SREntity::getColumns().index);

if (item.IsOk())
{
Expand All @@ -184,13 +182,13 @@ void ClassEditor::selectId(int id)

void ClassEditor::duplicateStimResponse()
{
int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
int newId = _entity->duplicate(id);
int newIndex = _entity->duplicate(index);
// Select the newly created stim
selectId(newId);
selectIndex(newIndex);
}

// Call the method of the child class to update the widgets
Expand Down
8 changes: 4 additions & 4 deletions plugins/dm.stimresponse/ClassEditor.h
Expand Up @@ -118,13 +118,13 @@ class ClassEditor :

/** greebo: Returns the ID of the currently selected stim/response
*
* @returns: the id (number) of the selected stim or -1 on failure
* @returns: the index (number) of the selected stim or -1 on failure
*/
int getIdFromSelection();
int getIndexFromSelection();

/** greebo: Selects the given ID in the S/R list
/** greebo: Selects the given index in the S/R list
*/
void selectId(int id);
void selectIndex(int index);

/** greebo: Gets called when the list selection changes
*/
Expand Down
48 changes: 24 additions & 24 deletions plugins/dm.stimresponse/ResponseEditor.cpp
Expand Up @@ -64,13 +64,13 @@ void ResponseEditor::update()
wxPanel* mainPanel = findNamedObject<wxPanel>(_mainPanel, "SREditorResponsePanel");
auto removeButton = findNamedObject<wxButton>(_mainPanel, "RemoveResponseButton");

int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0 && _entity != NULL)
if (index > 0 && _entity != NULL)
{
mainPanel->Enable(true);

StimResponse& sr = _entity->get(id);
StimResponse& sr = _entity->get(index);

// Get the iter into the liststore pointing at the correct STIM_YYYY type
std::string typeToFind = sr.get("type");
Expand Down Expand Up @@ -305,13 +305,13 @@ void ResponseEditor::checkBoxToggled(wxCheckBox* toggleButton)

void ResponseEditor::addEffect()
{
if (_entity == NULL) return;
if (_entity == nullptr) return;

int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
StimResponse& sr = _entity->get(id);
StimResponse& sr = _entity->get(index);
int effectIndex = getEffectIdFromSelection();

// Make sure we have a response
Expand All @@ -325,13 +325,13 @@ void ResponseEditor::addEffect()

void ResponseEditor::removeEffect()
{
if (_entity == NULL) return;
if (_entity == nullptr) return;

int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
StimResponse& sr = _entity->get(id);
StimResponse& sr = _entity->get(index);
int effectIndex = getEffectIdFromSelection();

// Make sure we have a response and anything selected
Expand All @@ -346,13 +346,13 @@ void ResponseEditor::removeEffect()

void ResponseEditor::editEffect()
{
if (_entity == NULL) return;
if (_entity == nullptr) return;

int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
StimResponse& sr = _entity->get(id);
StimResponse& sr = _entity->get(index);
int effectIndex = getEffectIdFromSelection();

// Make sure we have a response and anything selected
Expand All @@ -371,11 +371,11 @@ void ResponseEditor::moveEffect(int direction)
{
if (_entity == NULL) return;

int id = getIdFromSelection();
int index = getIndexFromSelection();

if (id > 0)
if (index > 0)
{
StimResponse& sr = _entity->get(id);
StimResponse& sr = _entity->get(index);
int effectIndex = getEffectIdFromSelection();

if (sr.get("class") == "R" && effectIndex > 0)
Expand All @@ -397,11 +397,11 @@ void ResponseEditor::updateEffectContextMenu()

bool anythingSelected = curEffectIndex >= 0;

int srId = getIdFromSelection();
int index = getIndexFromSelection();

if (srId > 0)
if (index > 0)
{
StimResponse& sr = _entity->get(srId);
StimResponse& sr = _entity->get(index);
highestEffectIndex = sr.highestEffectIndex();
}

Expand Down Expand Up @@ -513,10 +513,10 @@ void ResponseEditor::addSR()
if (_entity == NULL) return;

// Create a new StimResponse object
int id = _entity->add();
int index = _entity->add();

// Get a reference to the newly allocated object
StimResponse& sr = _entity->get(id);
StimResponse& sr = _entity->get(index);
sr.set("class", "R");

// Get the selected stim type name from the combo box
Expand All @@ -529,7 +529,7 @@ void ResponseEditor::addSR()
_entity->updateListStores();

// Select the newly created response
selectId(id);
selectIndex(index);
}

void ResponseEditor::onEffectItemContextMenu(wxDataViewEvent& ev)
Expand Down

0 comments on commit 41c4134

Please sign in to comment.