Skip to content

Commit

Permalink
#6131: AI Editing Panel is no longer listening when deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 23, 2022
1 parent 5b959bd commit 3df9a7d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 50 deletions.
95 changes: 49 additions & 46 deletions plugins/dm.editing/AIEditingPanel.cpp
Expand Up @@ -6,9 +6,7 @@
#include "imap.h"
#include "itextstream.h"
#include "ui/ientityinspector.h"
#include "ui/imainframe.h"
#include "iundo.h"
#include "ui/igroupdialog.h"
#include "selectionlib.h"

#include "SpawnargLinkedCheckbox.h"
Expand All @@ -29,32 +27,54 @@ namespace ui
AIEditingPanel::AIEditingPanel(wxWindow* parent) :
DockablePanel(parent),
_mainPanel(new wxScrolledWindow(this, wxID_ANY)),
_queueUpdate(true),
_entity(nullptr)
{
SetSizer(new wxBoxSizer(wxVERTICAL));
GetSizer()->Add(_mainPanel, 1, wxEXPAND);

_mainPanel->Bind(wxEVT_PAINT, &AIEditingPanel::onPaint, this);

constructWidgets();
}

_selectionChangedSignal = GlobalSelectionSystem().signal_selectionChanged().connect(
sigc::mem_fun(*this, &AIEditingPanel::onSelectionChanged)
);
AIEditingPanel::~AIEditingPanel()
{
disconnectListeners();
}

void AIEditingPanel::onPanelActivated()
{
connectListeners();
rescanSelection();
}

void AIEditingPanel::onPanelDeactivated()
{
disconnectListeners();
}

void AIEditingPanel::connectListeners()
{
_selectionChangedSignal = GlobalSelectionSystem().signal_selectionChanged().connect(
sigc::mem_fun(*this, &AIEditingPanel::onSelectionChanged)
);

_undoHandler = GlobalMapModule().signal_postUndo().connect(
sigc::mem_fun(*this, &AIEditingPanel::updateWidgetsFromSelection));
_redoHandler = GlobalMapModule().signal_postRedo().connect(
sigc::mem_fun(*this, &AIEditingPanel::updateWidgetsFromSelection));
}

AIEditingPanel::~AIEditingPanel()
void AIEditingPanel::disconnectListeners()
{
_undoHandler.disconnect();
_redoHandler.disconnect();

_selectionChangedSignal.disconnect();

if (_entity != nullptr)
{
_entity->detachObserver(this);
_entity = nullptr;
}
}

void AIEditingPanel::constructWidgets()
Expand Down Expand Up @@ -335,57 +355,40 @@ void AIEditingPanel::updateWidgetsFromSelection()

void AIEditingPanel::rescanSelection()
{
_queueUpdate = false;

// Load the new entity from the selection
_entity = getEntityFromSelection();

if (_entity != nullptr)
{
_entity->attachObserver(this);
}
auto newEntity = getEntityFromSelection();

if (newEntity != _entity)
{
// Disconnect from any previous entity
if (_entity != nullptr)
{
_entity->detachObserver(this);
_entity = nullptr; // issue #4282
}

if (newEntity != nullptr)
{
_entity = newEntity;
_entity->attachObserver(this);
}
}

updatePanelSensitivity();
updateWidgetsFromSelection();
}

void AIEditingPanel::onSelectionChanged(const ISelectable& selectable)
{
// Immediately disconnect from the current entity in any case
if (_entity != nullptr)
{
_entity->detachObserver(this);
_entity = nullptr; // issue #4282
}

if (GlobalGroupDialog().getPage() == _mainPanel)
{
rescanSelection();
}
else
{
// We don't scan the selection if the page is not visible
_queueUpdate = true;
}
}

void AIEditingPanel::onPaint(wxPaintEvent& ev)
void AIEditingPanel::onSelectionChanged(const ISelectable&)
{
if (_queueUpdate)
{
// Wake up from sleep mode and inspect the current selection
rescanSelection();
}

ev.Skip();
rescanSelection();
}

void AIEditingPanel::onBrowseButton(wxCommandEvent& ev, const std::string& key)
{
if (_entity == nullptr) return;

// Look up the property editor dialog
IPropertyEditorDialog::Ptr dialog = GlobalEntityInspector().createDialog(key);
auto dialog = GlobalEntityInspector().createDialog(key);

if (dialog)
{
Expand Down
9 changes: 6 additions & 3 deletions plugins/dm.editing/AIEditingPanel.h
Expand Up @@ -34,8 +34,6 @@ class AIEditingPanel :

wxScrolledWindow* _mainPanel;

bool _queueUpdate;

typedef std::map<std::string, SpawnargLinkedCheckbox*> CheckboxMap;
CheckboxMap _checkboxes;

Expand All @@ -62,10 +60,15 @@ class AIEditingPanel :
void postRedo();

protected:
void onPaint(wxPaintEvent& ev);
void onBrowseButton(wxCommandEvent& ev, const std::string& key);

void onPanelActivated() override;
void onPanelDeactivated() override;

private:
void connectListeners();
void disconnectListeners();

void constructWidgets();
wxSizer* createSpinButtonHbox(SpawnargLinkedSpinButton* spinButton);
wxStaticText* createSectionLabel(const std::string& text);
Expand Down
1 change: 0 additions & 1 deletion radiant/ui/surfaceinspector/SurfaceInspector.h
@@ -1,7 +1,6 @@
#pragma once

#include <map>
#include "wxutil/window/TransientWindow.h"
#include "wxutil/FormLayout.h"
#include "messages/TextureChanged.h"

Expand Down

0 comments on commit 3df9a7d

Please sign in to comment.