Skip to content

Commit

Permalink
PatchInspector using UndoSystem's signals
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 1, 2017
1 parent da71861 commit 49ea998
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
26 changes: 12 additions & 14 deletions radiant/ui/patch/PatchInspector.cpp
Expand Up @@ -4,6 +4,7 @@
#include "itextstream.h"
#include "iuimanager.h"
#include "imainframe.h"
#include "iundo.h"

#include <wx/sizer.h>
#include <wx/panel.h>
Expand Down Expand Up @@ -78,18 +79,6 @@ void PatchInspector::onRadiantShutdown()
InstancePtr().reset();
}

void PatchInspector::postUndo()
{
// Update the PatchInspector after an undo operation
queueUpdate();
}

void PatchInspector::postRedo()
{
// Update the PatchInspector after a redo operation
queueUpdate();
}

PatchInspector& PatchInspector::Instance()
{
PatchInspectorPtr& instancePtr = InstancePtr();
Expand Down Expand Up @@ -267,7 +256,9 @@ void PatchInspector::_preHide()
setPatch(PatchNodePtr());

// A hidden PatchInspector doesn't need to listen for events
GlobalUndoSystem().removeObserver(this);
_undoHandler.disconnect();
_redoHandler.disconnect();

GlobalSelectionSystem().removeObserver(this);
}

Expand All @@ -276,9 +267,16 @@ void PatchInspector::_preShow()
{
TransientWindow::_preShow();

_undoHandler.disconnect();
_redoHandler.disconnect();

// Register self to the SelSystem to get notified upon selection changes.
GlobalSelectionSystem().addObserver(this);
GlobalUndoSystem().addObserver(this);

_undoHandler = GlobalUndoSystem().signal_postUndo().connect(
sigc::mem_fun(this, &PatchInspector::queueUpdate));
_redoHandler = GlobalUndoSystem().signal_postRedo().connect(
sigc::mem_fun(this, &PatchInspector::queueUpdate));

// Check for selection changes before showing the dialog again
rescanSelection();
Expand Down
23 changes: 12 additions & 11 deletions radiant/ui/patch/PatchInspector.h
Expand Up @@ -4,9 +4,11 @@
#include "icommandsystem.h"
#include "iselection.h"
#include "iradiant.h"
#include "iundo.h"
#include "ipatch.h"

#include <sigc++/connection.h>
#include <sigc++/trackable.h>

#include "wxutil/window/TransientWindow.h"
#include "wxutil/event/SingleIdleCallback.h"
#include "wxutil/XmlResourceBasedWidget.h"
Expand All @@ -29,12 +31,12 @@ namespace ui
class PatchInspector;
typedef std::shared_ptr<PatchInspector> PatchInspectorPtr;

class PatchInspector
: public wxutil::TransientWindow,
public SelectionSystem::Observer,
public UndoSystem::Observer,
public IPatch::Observer,
private wxutil::XmlResourceBasedWidget
class PatchInspector :
public wxutil::TransientWindow,
public SelectionSystem::Observer,
public IPatch::Observer,
private wxutil::XmlResourceBasedWidget,
public sigc::trackable
{
private:
wxChoice* _rowCombo;
Expand Down Expand Up @@ -64,6 +66,9 @@ class PatchInspector
bool _updateActive;
bool _updateNeeded;

sigc::connection _undoHandler;
sigc::connection _redoHandler;

private:

// TransientWindow callbacks
Expand Down Expand Up @@ -138,10 +143,6 @@ class PatchInspector
*/
void onRadiantShutdown();

// UndoSystem::Observer implementation
void postUndo();
void postRedo();

// Patch::Observer
void onPatchControlPointsChanged();
void onPatchTextureChanged();
Expand Down

0 comments on commit 49ea998

Please sign in to comment.