bool ecConfigItem::SetEnabled(bool bEnabled, CdlTransaction current_transaction/*=NULL*/) { const CdlValuable valuable = GetCdlValuable(); wxASSERT (valuable); // use a transaction object to ensure that all config items are changed together CdlTransaction transaction = current_transaction ? current_transaction : CdlTransactionBody::make (wxGetApp().GetConfigToolDoc ()->GetCdlConfig ()); if (HasRadio () && bEnabled) { // if a new radio button has been selected for (ecConfigItem *pItem = FirstRadio(); pItem; pItem = pItem->NextRadio ()) { // for each radio button in the group if (pItem != this) { // if not the newly selected radio button pItem->SetEnabled (FALSE, transaction); // disable the radio button } } } if (CdlValueFlavor_BoolData == valuable->get_flavor ()) { // set the user value to the current data value when enabling/disabling // a booldata item to avoid a possible change in the current data value CdlSimpleValue simple_value = valuable->get_simple_value (); valuable->set_enabled_and_value (transaction, bEnabled, simple_value, CdlValueSource_User); } else { // CdlValueFlavor_Bool valuable->set_enabled (transaction, bEnabled, CdlValueSource_User); } if (! current_transaction) { // if not a recursive call to disable a radio button transaction->body (); // commit the transaction delete transaction; transaction = NULL; } return TRUE; }
void ecResolveConflictsDialog::OnContinue(wxCommandEvent& event) { // Ensure we have the current conflict check array int i; for (i = 0; i < m_conflictsCtrl->GetItemCount(); i++) { if (m_conflictsCtrl->GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) RemoveConflictSolutions((CdlConflict) m_conflictsCtrl->GetItemData(i)); } // Dismiss the window EndModal(wxID_OK); std::list<CdlConflict>::const_iterator conf_i; for (conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) // for each conflict { CdlConflict conflict=*conf_i; //int nSolutions=conflict->get_solution().size(); SolutionInfo &info=Info(conflict); int nIndex=0; const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution(); for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();soln_i != Solution.end(); soln_i++) { if(SolutionInfo::CHECKED==info.arItem[nIndex++]){ CdlValuable valuable = soln_i->first; CdlValue value=soln_i->second; CdlValueFlavor flavor = valuable->get_flavor(); const wxString strName(valuable->get_name().c_str()); const wxString strValue(value.get_value().c_str()); bool rc = TRUE; wxString str; try { switch(flavor) { case CdlValueFlavor_None : str = wxT("set CdlValueFlavor_None"); rc = FALSE; break; case CdlValueFlavor_Bool : str.Printf(_("%s %s\n"), (const wxChar*) (value.is_enabled()?_("disable"):_("enable")), (const wxChar*) strName); valuable->set_enabled (m_Transaction, value.is_enabled(), CdlValueSource_User); break; case CdlValueFlavor_BoolData : { bool bEnabled=value.is_enabled(); str.Printf(_("%s %s and set value to %s\n"), (const wxChar*) (bEnabled? _("disable"):_("enable")), (const wxChar*) strName, (const wxChar*) strValue); // Surely this is wrong - we don't want to set the same value, we want to // set a NEW value. // CdlSimpleValue simple_value = valuable->get_simple_value (); //valuable->set_enabled_and_value (m_Transaction, bEnabled, simple_value, CdlValueSource_User); valuable->set_enabled_and_value (m_Transaction, bEnabled, ecUtils::UnicodeToStdStr (strValue), CdlValueSource_User); } break; case CdlValueFlavor_Data : str.Printf(_("set %s to %s\n"), (const wxChar*) strName, (const wxChar*) strValue); valuable->set_value (m_Transaction, ecUtils::UnicodeToStdStr (strValue), CdlValueSource_User); break; } } catch(...) { rc = FALSE; } if(rc) { wxGetApp().GetConfigToolDoc()->Modify(TRUE); } else { wxString msg; msg.Printf(_("Failed to %s\n"), (const wxChar*) str); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } } } } }
void CFailingRulesDialog::OnOK() { // Ensure we have the current conflict check array for(POSITION pos = m_RulesList.GetFirstSelectedItemPosition();pos;){ int nItem = m_RulesList.GetNextSelectedItem(pos); RemoveConflictSolutions((CdlConflict)m_RulesList.GetItemData(nItem)); } // Dismiss the window CeCosDialog::OnOK(); for (std::list<CdlConflict>::const_iterator conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) { // for each conflict CdlConflict conflict=*conf_i; //int nSolutions=conflict->get_solution().size(); SolutionInfo &info=Info(conflict); int nIndex=0; const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution(); for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();soln_i != Solution.end(); soln_i++) { if(SolutionInfo::CHECKED==info.arItem[nIndex++]){ CdlValuable valuable = soln_i->first; CdlValue value=soln_i->second; CdlValueFlavor flavor = valuable->get_flavor(); const CString strName(valuable->get_name().c_str()); const CString strValue(value.get_value().c_str()); bool rc=true; CString str; try { switch(flavor) { case CdlValueFlavor_None : str=_T("set CdlValueFlavor_None"); rc=false; break; case CdlValueFlavor_Bool : str.Format(_T("%s %s\n"),value.is_enabled()?_T("disable"):_T("enable"),strName); valuable->set_enabled (m_Transaction, value.is_enabled(), CdlValueSource_User); break; case CdlValueFlavor_BoolData : { bool bEnabled=value.is_enabled(); str.Format(_T("%s %s and set value to %s\n"),bEnabled?_T("disable"):_T("enable"),strName,strValue); // This is wrong: it should set the NEW value. This is the cause of a long-standing bug... // CdlSimpleValue simple_value = valuable->get_simple_value (); //valuable->set_enabled_and_value (m_Transaction, bEnabled, simple_value, CdlValueSource_User); valuable->set_enabled_and_value (m_Transaction, bEnabled, CUtils::UnicodeToStdStr (strValue), CdlValueSource_User); } break; case CdlValueFlavor_Data : str.Format(_T("set %s to %s\n"),strName,strValue); valuable->set_value (m_Transaction, CUtils::UnicodeToStdStr (strValue), CdlValueSource_User); break; } } catch(...){ rc=false; } if(rc){ CConfigTool::GetConfigToolDoc()->SetModifiedFlag(); } else { CUtils::MessageBoxF(_T("Failed to %s\n"),str); } } } } }