📄 conflictsdlg.cpp
字号:
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 ecResolveConflictsDialog::OnAll(wxCommandEvent& event){ SetAll(TRUE);}void ecResolveConflictsDialog::OnNone(wxCommandEvent& event){ SetAll(FALSE);}void ecResolveConflictsDialog::SetAll(bool bOnOff){ long i; for ( i = m_solutionsCtrl->GetItemCount()-1; i >= 0; --i) { m_solutionsCtrl->SetChecked(i, bOnOff); }}// Update All buttonvoid ecResolveConflictsDialog::OnUpdateAll(wxUpdateUIEvent& event){ if (!m_solutionsCtrl) return; int nCheckCount=0; int nItemCount = m_solutionsCtrl->GetItemCount(); int i; for (i=nItemCount-1;i>=0;--i) { nCheckCount+=m_solutionsCtrl->IsChecked(i); } event.Enable(nItemCount>0 && nCheckCount<nItemCount);}// Update None buttonvoid ecResolveConflictsDialog::OnUpdateNone(wxUpdateUIEvent& event){ if (!m_solutionsCtrl) return; int nCheckCount=0; int nItemCount=m_solutionsCtrl->GetItemCount(); int i; for (i=nItemCount-1;i>=0;--i){ nCheckCount+=m_solutionsCtrl->IsChecked(i); } event.Enable(nItemCount>0 && nCheckCount>0);}// Currently there is no 'locate' button so this is not called from anywhere.// However, the intention in the MFC configtool must have been to use it,// although it wasn't in the Resolve Conflicts dialog.void ecResolveConflictsDialog::OnLocate(){ ecConfigItem *pItem = m_conflictsCtrl->AssociatedItem(m_nContextItem, m_nContextRow); if (pItem) { if (wxGetApp().GetTreeCtrl()) wxGetApp().GetTreeCtrl()->SelectItem(pItem->GetTreeItem()); }}void ecResolveConflictsDialog::RemoveConflictSolutions(CdlConflict conflict){ SolutionInfo &info=Info(conflict); int i, j, k; for ( i = 0; i < info.nCount; i++ ) { int nItem=info.arItem[i]; wxASSERT(nItem>=0); info.arItem[i] = (m_solutionsCtrl->IsChecked(nItem) ? SolutionInfo::CHECKED:SolutionInfo::UNCHECKED); int nRefs = m_solutionsCtrl->GetItemData(nItem); if (1 == nRefs) { m_solutionsCtrl->DeleteItem(nItem); for ( k = 0; k < m_conflictsCtrl->GetItemCount(); k++ ) { SolutionInfo &info2 = Info((CdlConflict)m_conflictsCtrl->GetItemData(k)); for ( j = 0; j < info2.nCount; j++) { if (info2.arItem[j] > nItem) { info2.arItem[j] --; } } } } else { m_solutionsCtrl->SetItemData(nItem, nRefs-1); } }}void ecResolveConflictsDialog::AddConflictSolutions(CdlConflict conflict){ // SolutionInfo allows each conflict to know which solutions have been found for it SolutionInfo &info=Info(conflict); const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution(); int i=0; for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin(); soln_i != Solution.end(); soln_i++) { CdlValuable valuable = soln_i->first; CdlValue value = soln_i->second; CdlValueFlavor flavor = valuable->get_flavor(); wxString strValue; switch(flavor) { case CdlValueFlavor_None : break; case CdlValueFlavor_Bool : strValue = value.is_enabled() ? _("Enabled") : _("Disabled"); break; case CdlValueFlavor_BoolData : strValue.Printf(wxT("%s, %s"), (const wxChar*) (value.is_enabled() ? _("Enabled") : _("Disabled")), (const wxChar*) value.get_value().c_str()); break; case CdlValueFlavor_Data : strValue = value.get_value().c_str(); break; } const wxString strName(soln_i->first->get_name().c_str()); long nIndex = m_solutionsCtrl->FindItem(0, strName); wxListItem listItem; listItem.m_mask = wxLIST_MASK_TEXT; listItem.m_itemId = nIndex; listItem.m_col = 1; if (nIndex != -1) m_solutionsCtrl->GetItem(listItem); if (-1 == nIndex || strValue != listItem.m_text) { // We don't have an existing solution that matches this one nIndex = m_solutionsCtrl->GetItemCount(); m_solutionsCtrl->InsertItem(nIndex, strName); m_solutionsCtrl->SetItemData(nIndex, 1); m_solutionsCtrl->SetItem(nIndex, 1, strValue); wxASSERT(info.arItem[i]<0); m_solutionsCtrl->SetChecked(nIndex, SolutionInfo::CHECKED==info.arItem[i]); } else { // We do - to avoid duplicates, increment the "ref count" m_solutionsCtrl->SetItemData(nIndex, m_solutionsCtrl->GetItemData(nIndex)+1); } info.arItem[i++]=nIndex; } wxStaticText* staticCtrl = (wxStaticText*) FindWindow(ecID_CONFLICTS_MSG); if(0==i){ staticCtrl->SetLabel(_("No solution is available for this conflict")); m_solutionsCtrl->Show(FALSE); } else { staticCtrl->SetLabel(_("Proposed solution:")); m_solutionsCtrl->Show(TRUE); // TODO (if necessary)#if 0 m_List.SetColumnWidth(0,LVSCW_AUTOSIZE); CRect rect; m_List.GetClientRect(rect); m_List.SetColumnWidth(1,rect.Width()-m_List.GetColumnWidth(0));#endif }}ecResolveConflictsDialog::SolutionInfo & ecResolveConflictsDialog::Info(const CdlConflict conflict){ SolutionInfo *pInfo = (SolutionInfo*) m_Map.Get((long) conflict); return * pInfo;}void ecResolveConflictsDialog::OnConflictSelected(wxListEvent& event) { CdlConflict conflict=(CdlConflict) m_conflictsCtrl->GetItemData(event.GetIndex()); if (1 == m_solutionsCtrl->GetSelectedItemCount()) { // TODO ?? // GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE); m_solutionsCtrl->Show(TRUE); } AddConflictSolutions(conflict);}void ecResolveConflictsDialog::OnConflictDeselected(wxListEvent& event) { CdlConflict conflict=(CdlConflict) m_conflictsCtrl->GetItemData(event.GetIndex()); RemoveConflictSolutions(conflict);}#if 0// TODO?// We need to use this because the OnItemChanged handler successive receives "not selected" followed by "selected"// notifications. The result is that the "Select one or more conflicts to display available solutions" message// would be seen briefly when clicking from one selection to another.BOOL ecResolveConflictsDialog::OnClick(UINT,LPNMLISTVIEW pnmv, LRESULT* pResult) { if(-1==pnmv->iItem && 0==m_List.GetSelectedCount()){ SetDlgItemText(IDC_STATIC1,_T("Select one or more conflicts to display available solutions")); m_List.ShowWindow(SW_HIDE); GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW); GetDlgItem(IDC_RESET)->EnableWindow(false); GetDlgItem(IDC_CONFLICTS_NONE)->EnableWindow(false); } *pResult = 0; return false; // not handled}// TODOBOOL ecResolveConflictsDialog::OnRClick(UINT, LPNMITEMACTIVATE pnmv, LRESULT* pResult) { DWORD dwPos=GetMessagePos(); CPoint pt(GET_X_LPARAM(dwPos),GET_Y_LPARAM(dwPos)); m_nContextItem=pnmv->iItem; m_nContextRow=pnmv->iSubItem; if(-1!=m_nContextItem){ //m_RulesList.SetItemState(m_nContextItem,LVIS_SELECTED,LVIS_SELECTED); Menu menu; menu.CreatePopupMenu(); menu.AppendMenu(1==m_RulesList.GetSelectedCount() && m_RulesList.AssociatedItem(m_nContextItem,m_nContextRow)?MF_STRING:(MF_STRING|MF_GRAYED),ID_LOCATE,_T("&Locate"));#ifndef PLUGIN SuppressNextContextMenuMessage();#endif menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pt.x,pt.y,this); } *pResult = 0; return TRUE; // handled}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -