[dasher: 46/61] Fix for duplicate entry in alphabet combobox



commit 6aae7caaa758a1f89b49a8dc58578b31cea2a07a
Author: Ada Majorek <amajorek google com>
Date:   Mon Mar 13 21:33:17 2017 -0700

    Fix for duplicate entry in alphabet combobox
    
    fixes https://github.com/ipomoena/dasher/issues/104

 Src/DasherCore/DasherInterfaceBase.cpp |    9 +++++----
 Src/DasherCore/DasherInterfaceBase.h   |    4 ++--
 Src/DasherCore/Parameters.h            |   13 +++++++++++++
 Src/DasherCore/SettingsStore.cpp       |    6 +++---
 Src/DasherCore/SettingsStore.h         |    4 ++--
 5 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 3ee192f..7649265 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -204,13 +204,14 @@ CDasherInterfaceBase::~CDasherInterfaceBase() {
 
   delete m_pFramerate;
 }
-void CDasherInterfaceBase::CPreSetObserver::HandleEvent(int iParameter) {
-  switch(iParameter) {
+
+void CDasherInterfaceBase::CPreSetObserver::HandleEvent(CParameterChange d) {
+  switch(d.iParameter) {
   case SP_ALPHABET_ID:
-    string value = m_settingsStore.GetStringParameter(SP_ALPHABET_ID);
+    string value = d.string_value;
     // Cycle the alphabet history
     vector<string> newHistory;
-    newHistory.push_back(value);
+    newHistory.push_back(m_settingsStore.GetStringParameter(SP_ALPHABET_ID));
     string v;
     if ((v = m_settingsStore.GetStringParameter(SP_ALPHABET_1)) != value)
       newHistory.push_back(v);
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index b5c448a..38d185a 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -527,11 +527,11 @@ protected:
   /// (TODO _could_ move these into CSettingsUser, but that seems uglier given so few clients?)
   CSettingsStore * const m_pSettingsStore;
 
-  class CPreSetObserver : public Observer<int> {
+  class CPreSetObserver : public Observer<CParameterChange> {
     CSettingsStore& m_settingsStore;
   public:
     CPreSetObserver(CSettingsStore& settingsStore) : m_settingsStore(settingsStore) {};
-    void HandleEvent(int evt) override;
+    void HandleEvent(CParameterChange evt) override;
   };
 
   CPreSetObserver m_preSetObserver;
diff --git a/Src/DasherCore/Parameters.h b/Src/DasherCore/Parameters.h
index 4021ad5..de844ab 100644
--- a/Src/DasherCore/Parameters.h
+++ b/Src/DasherCore/Parameters.h
@@ -90,6 +90,19 @@ enum {
 
 enum class Persistence { PERSISTENT, EPHEMERAL };
 
+struct CParameterChange {
+    CParameterChange(int parameter, bool value)
+        :iParameter(parameter), bool_value(value) {}
+    CParameterChange(int parameter, long value)
+        :iParameter(parameter), long_value(value) {}
+    CParameterChange(int parameter, const char* value)
+        :iParameter(parameter),string_value(value){}
+    int iParameter;
+    bool bool_value = false;
+    long long_value = 0;
+    const char* string_value = "";
+};
+
 namespace Dasher {
   ///Namespace containing all static (i.e. fixed/constant) data about
   /// settings, that is _not_ dependent on the storage mechanism,
diff --git a/Src/DasherCore/SettingsStore.cpp b/Src/DasherCore/SettingsStore.cpp
index 2599aa0..23c184f 100644
--- a/Src/DasherCore/SettingsStore.cpp
+++ b/Src/DasherCore/SettingsStore.cpp
@@ -141,7 +141,7 @@ void CSettingsStore::SetBoolParameter(int iParameter, bool bValue) {
   if(bValue == GetBoolParameter(iParameter))
     return;
 
-  pre_set_observable_.DispatchEvent(iParameter);
+  pre_set_observable_.DispatchEvent(CParameterChange(iParameter,bValue));
 
   // Set the value
   p->second.bool_value = bValue;
@@ -162,7 +162,7 @@ void CSettingsStore::SetLongParameter(int iParameter, long lValue) {
   if(lValue == GetLongParameter(iParameter))
     return;
 
-  pre_set_observable_.DispatchEvent(iParameter);
+  pre_set_observable_.DispatchEvent(CParameterChange(iParameter, lValue));
 
   // Set the value
   p->second.long_value = lValue;
@@ -183,7 +183,7 @@ void CSettingsStore::SetStringParameter(int iParameter, const std::string sValue
   if(sValue == GetStringParameter(iParameter))
     return;
 
-  pre_set_observable_.DispatchEvent(iParameter);
+  pre_set_observable_.DispatchEvent(CParameterChange(iParameter, sValue.c_str()));
 
   // Set the value
   p->second.string_value = sValue;
diff --git a/Src/DasherCore/SettingsStore.h b/Src/DasherCore/SettingsStore.h
index 5707d1e..e705479 100644
--- a/Src/DasherCore/SettingsStore.h
+++ b/Src/DasherCore/SettingsStore.h
@@ -61,7 +61,7 @@ public:
   void AddParameters(const Settings::bp_table* table, size_t count);
   void AddParameters(const Settings::lp_table* table, size_t count);
   void AddParameters(const Settings::sp_table* table, size_t count);
-  Observable<int>& PreSetObservable() { return pre_set_observable_; }
+  Observable<CParameterChange>& PreSetObservable() { return pre_set_observable_; }
 
 protected:
     ///Loads all (persistent) prefs from disk, using+storing default values when no
@@ -125,7 +125,7 @@ private:
   };
 
   std::unordered_map<int, Parameter> parameters_;
-  Observable<int> pre_set_observable_;
+  Observable<CParameterChange> pre_set_observable_;
 };
   /// Superclass for anything that wants to use/access/store persistent settings.
   /// (The nearest thing remaining to the old CDasherComponent,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]