From b7d4687b8e179dbe277469115d897dd8bdf017c6 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 19 Jan 2016 18:38:18 -0500 Subject: [PATCH] Fix lazy-edit-device-switch context mismatch --- src/forms/SDRDevices/SDRDevices.cpp | 21 +++++++++++++++------ src/forms/SDRDevices/SDRDevices.fbp | 4 ++-- src/forms/SDRDevices/SDRDevices.h | 2 ++ src/forms/SDRDevices/SDRDevicesForm.cpp | 2 ++ src/forms/SDRDevices/SDRDevicesForm.h | 1 + 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/forms/SDRDevices/SDRDevices.cpp b/src/forms/SDRDevices/SDRDevices.cpp index 24c11dd..0e27895 100644 --- a/src/forms/SDRDevices/SDRDevices.cpp +++ b/src/forms/SDRDevices/SDRDevices.cpp @@ -12,7 +12,8 @@ SDRDevicesDialog::SDRDevicesDialog( wxWindow* parent ): devFrame( parent ) { m_addRemoteButton->Disable(); m_useSelectedButton->Disable(); m_deviceTimer.Start(250); - selId = 0; + selId = nullptr; + editId = nullptr; } void SDRDevicesDialog::OnClose( wxCloseEvent& event ) { @@ -177,7 +178,6 @@ SDRDeviceInfo *SDRDevicesDialog::getSelectedDevice(wxTreeItemId selId) { void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event ) { if (dev != NULL) { - int i = 0; SoapySDR::ArgInfoList::const_iterator args_i; SoapySDR::ArgInfoList args = dev->getSettingsArgInfo(); @@ -318,20 +318,25 @@ void SDRDevicesDialog::OnRefreshDevices( wxMouseEvent& event ) { m_addRemoteButton->Disable(); m_useSelectedButton->Disable(); wxGetApp().reEnumerateDevices(); - selId = 0; + selId = nullptr; + editId = nullptr; dev = nullptr; refresh = true; } void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) { - if (dev && event.GetProperty() == devSettings["name"]) { + if (!editId) { + return; + } + SDRDeviceInfo *dev = getSelectedDevice(editId); + if (editId && event.GetProperty() == devSettings["name"]) { DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId()); wxString devName = event.GetPropertyValue().GetString(); devConfig->setDeviceName(devName.ToStdString()); - if (selId) { - devTree->SetItemText(selId, devConfig->getDeviceName()); + if (editId) { + devTree->SetItemText(editId, devConfig->getDeviceName()); } if (devName == "") { event.GetProperty()->SetValueFromString(devConfig->getDeviceName()); @@ -345,3 +350,7 @@ void SDRDevicesDialog::OnPropGridChanged( wxPropertyGridEvent& event ) { devConfig->setOffset(offset); } } + +void SDRDevicesDialog::OnPropGridFocus( wxFocusEvent& event ) { + editId = selId; +} diff --git a/src/forms/SDRDevices/SDRDevices.fbp b/src/forms/SDRDevices/SDRDevices.fbp index 6e2ad7a..725a91a 100644 --- a/src/forms/SDRDevices/SDRDevices.fbp +++ b/src/forms/SDRDevices/SDRDevices.fbp @@ -1002,12 +1002,12 @@ - + OnPropGridChanged - + OnPropGridFocus diff --git a/src/forms/SDRDevices/SDRDevices.h b/src/forms/SDRDevices/SDRDevices.h index 02f68f9..c47b06e 100644 --- a/src/forms/SDRDevices/SDRDevices.h +++ b/src/forms/SDRDevices/SDRDevices.h @@ -20,6 +20,7 @@ public: void OnDeviceTimer( wxTimerEvent& event ); void OnRefreshDevices( wxMouseEvent& event ); void OnPropGridChanged( wxPropertyGridEvent& event ); + void OnPropGridFocus( wxFocusEvent& event ); private: SDRDeviceInfo *getSelectedDevice(wxTreeItemId selId); @@ -34,4 +35,5 @@ private: std::vector props; std::map devSettings; wxTreeItemId selId; + wxTreeItemId editId; }; \ No newline at end of file diff --git a/src/forms/SDRDevices/SDRDevicesForm.cpp b/src/forms/SDRDevices/SDRDevicesForm.cpp index 061cee1..32def2f 100644 --- a/src/forms/SDRDevices/SDRDevicesForm.cpp +++ b/src/forms/SDRDevices/SDRDevicesForm.cpp @@ -94,6 +94,7 @@ devFrame::devFrame( wxWindow* parent, wxWindowID id, const wxString& title, cons m_addRemoteButton->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnAddRemote ), NULL, this ); m_useSelectedButton->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnUseSelected ), NULL, this ); m_propertyGrid->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( devFrame::OnPropGridChanged ), NULL, this ); + m_propertyGrid->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( devFrame::OnPropGridFocus ), NULL, this ); this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( devFrame::OnDeviceTimer ) ); } @@ -108,6 +109,7 @@ devFrame::~devFrame() m_addRemoteButton->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnAddRemote ), NULL, this ); m_useSelectedButton->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( devFrame::OnUseSelected ), NULL, this ); m_propertyGrid->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( devFrame::OnPropGridChanged ), NULL, this ); + m_propertyGrid->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( devFrame::OnPropGridFocus ), NULL, this ); this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( devFrame::OnDeviceTimer ) ); } diff --git a/src/forms/SDRDevices/SDRDevicesForm.h b/src/forms/SDRDevices/SDRDevicesForm.h index 885677e..74d8d6c 100644 --- a/src/forms/SDRDevices/SDRDevicesForm.h +++ b/src/forms/SDRDevices/SDRDevicesForm.h @@ -62,6 +62,7 @@ class devFrame : public wxFrame virtual void OnAddRemote( wxMouseEvent& event ) { event.Skip(); } virtual void OnUseSelected( wxMouseEvent& event ) { event.Skip(); } virtual void OnPropGridChanged( wxPropertyGridEvent& event ) { event.Skip(); } + virtual void OnPropGridFocus( wxFocusEvent& event ) { event.Skip(); } virtual void OnDeviceTimer( wxTimerEvent& event ) { event.Skip(); }